使用dataApi更新复杂性

时间:2017-05-11 14:44:15

标签: android wear-os android-wear-data-api android-wear-2.0

可以这样做吗?我无法使用onDataChanged工作是complicationService,如果我在WearableListener类中执行它,我如何将数据传递给complicationService并强制更新? 非常感谢!

此代码在掌上电脑中,以便在更改时更新数据项:

my_icon

这是手表上的DataListener:

// looping through all item nodes <item>
                    for (int i = 0; i < nl.getLength(); i++) {
                        Element e = (Element) nl.item(i);

                        String my_icon = parser.getValue(e, "my_icon"); // my_icon child value
                        int my_count = Integer.parseInt(parser.getValue(e, "my_count")); // my_count child value
                        String my_text = parser.getValue(e, "my_text"); // my_text child value

                        //Create Child-Views
                        LinearLayout tempLinearLayout = new LinearLayout(AnleitungActivity.this);
                        linearLayout.addView(tempLinearLayout);
                            tempLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
                            ViewGroup.LayoutParams params = tempLinearLayout.getLayoutParams();
                            params.width = ViewGroup.LayoutParams.MATCH_PARENT;
                            params.height = 240;
                            tempLinearLayout.setBackgroundColor(ContextCompat.getColor(AnleitungActivity.this, R.color.anleitung_kachel_hintergrundfarbe));

                            ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) tempLinearLayout.getLayoutParams();
                            marginParams.setMargins(0,5,0,0); //für die Margin-Werte brauchen wir extra MarginLayoutParams...
                            tempLinearLayout.setLayoutParams(params); //layoutParams setzen
                            tempLinearLayout.setLayoutParams(marginParams); //MarginLayoutParams setzen

                        TextView tv = new TextView(AnleitungActivity.this);
                        tempLinearLayout.addView(tv);
                            LinearLayout.LayoutParams tvParams  = new LinearLayout.LayoutParams(70, ViewGroup.LayoutParams.MATCH_PARENT,1f);
                            tv.setLayoutParams(tvParams);
                            tv.setText(transformText(my_text));
                            tv.setTextSize(17);
                            tv.setPadding(5,0,0,0);
                            tv.setTextColor(ContextCompat.getColor(AnleitungActivity.this, R.color.anleitung_text_farbe));

                        ImageView imageView = new ImageView(AnleitungActivity.this);
                        tempLinearLayout.addView(imageView);
                            imageView.getLayoutParams().height = dp2px(getResources(), 60);
                            imageView.getLayoutParams().width = dp2px(getResources(), 60);
                            imageView.setImageResource(getDrawableRessorceIdByName(AnleitungActivity.this, removeFileExtensionFromString(my_icon)));



                    }

}

这是complicationService(Google示例只提供一个随机数):

    public String removeFileExtensionFromString(String str){
    return str.substring(0, str.indexOf("."));
}

0 个答案:

没有答案