0

I would like to update the text in the two TextViews on the Watch simultaneously.

main_layout.xml

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <TextView
        android:id="@+id/text1"
        android:layout_width="220px"
        android:layout_height="50px"
        />
    <TextView
        android:id="@+id/text2"
        android:layout_width="220px"
        android:layout_height="50px"
        />
</LinearLayout>

Now I'm doing it this way:

sendText(R.id.text1, "Hello world 1");
sendText(R.id.text2, "Hello world 2");

The problem is, that I can see on the Watch, that the first text is set earlier, then the second one. And I would like to avoid that.

Generally, Sony-SDK supports the data-updates in bundles, for example when showing a layout:

Bundle b1 = new Bundle();
b1.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.text1);
b1.putString(Control.Intents.EXTRA_TEXT, "Hello world 1");

Bundle b2 = new Bundle();
b2.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.text2);
b2.putString(Control.Intents.EXTRA_DATA_URI, "Hello world 2");

Bundle[] layoutData = new Bundle[] { b1, b2 };

showLayout(R.layout.main_layout, layoutData);

but in this case the layout is re-set, which is not so good in my case, because some other views on the screen may already have been changed.

I hoped, it could be possible to achieve this through something like:

Bundle bundle = new Bundle();
bundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.text2);
bundle.putString(Control.Intents.EXTRA_TEXT, "Hello world 2");

Intent intent = new Intent(Control.Intents.CONTROL_SEND_TEXT_INTENT);

intent.putExtra(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.text1);
intent.putExtra(Control.Intents.EXTRA_TEXT, "Hello world 1");

intent.putExtra(Control.Intents.EXTRA_LAYOUT_DATA, new Bundle[] { bundle });

sendToHostApp(intent);

but unfortunately the Watch seems to ignore the EXTRA_LAYOUT_DATA for the CONTROL_SEND_TEXT_INTENT intent.

So my question is: is there any possibility to send text updates as a bundle without re-setting the layout?

Oleg Skr
  • 386
  • 2
  • 9

1 Answers1

0

You're doing it right. Updating the whole screen would be the best way, just update all other fields that might have changed in meantime also.

Eir
  • 1,003
  • 9
  • 24
  • Thank you! But updating the whole screen is the thing, that I'm trying to avoid through setting only the text value for the TextView. – Oleg Skr Oct 24 '13 at 11:38
  • 1
    @OlegSkrypnyuk ok, you can actually achieve that, you just need to "draw" on exactly those portions of the screen you want to update. By "drawing" I mean something like: `Canvas textCanvas = new Canvas(bitmap); TextView textView = new TextView(mContext); textView.setTextSize(12); textView.setGravity(Gravity.CENTER | Gravity.BOTTOM); textView.layout(0, 0, width, height / 4); textView.setText("updated text"); textView.draw(textCanvas); showBitmap(toast, 0, height / 3);` I'm already doing exactly this in my apps (the code is copied from there) and it works perfectly. – Eir Oct 24 '13 at 17:16
  • Cool! Thanks! Somehow I have overlooked the method "showBitmap" with x/y-offsets. It's good to know, that there is a possibility to update only a part of the screen. But it won't help much if I have two TextViews one at the top of the screen and another at the bottom, that have to change their text **simultaneously**. So I assume, that the answer to my question is "it's not possible now", but I hope that the Sony guys would add this useful feature in some later release. – Oleg Skr Oct 25 '13 at 09:21
  • ? Why don't you just draw two textViews in the same bitmap your sending, just place them exactly where you need them. In the code above just add another textView and place them both wherever you want, but of course, make the background bitmap as large as the screen and make sure the background is transparent. So, all will happen in one call to `showBitmap`. At the end, don't forget to accept my answer :-) – Eir Oct 25 '13 at 18:08
  • If you want - I'll accept your answer, although it's nor really what I was looking for. Thanks anyway for your readiness to help me! :-) – Oleg Skr Oct 29 '13 at 10:10
  • Ok, I just wanted to say that it is possible to *simultaneously* update any few portions of the screen you want (you mentioned at least 2 times that was not possible, while it actually is, and I actually showed you how). It's not through the `sendText` method, so in case you're using layouts, it's not what you'd want, but it's doable. I still say that (in most cases) updating the whole screen is the best way to go. – Eir Oct 29 '13 at 17:46