6

Unfortunately Moto360 is not avail to Europe yet...

I'm running a Round Android Wear Emulator and this is working fine.

However when I run my Android Wear Activity (which uses a WatchViewStub) the layout being used is the rect_activy_layout and not the round layout

Anyone else have this issue or resolved when running Round Emulator?

Thanks

Java Guy
  • 1,005
  • 14
  • 20
  • I actually faced the same issue on my Moto 360. I'm interested in knowing what someone else did to solve this. – gatlingxyz Sep 21 '14 at 20:14
  • subscribing for this question. As an ugly workaround, you may temporally set your round layout like this `app:rectLayout="@layout/round_activity_my`" And it would run your round layout thinking that it is provided as a rect one... – Vladyslav Matviienko Sep 23 '14 at 10:11
  • I've been doing working around this extremely "cheaply". My code is all good for for rect, so after I've committed, I'm just overwriting my rect layouts with round layout style code, and once I'm happy, I copy and paste my round layout code into the actual round_layout_activity and revert the modified rect_layout file. Blah... – Java Guy Sep 25 '14 at 10:21
  • The AVD setup wizard is buggy in the SDK for round watch emulation. Your problem is, most likely, that it is using a square device under the hood. To fix that, see [this answer](http://stackoverflow.com/a/24642918/269876) – Lo-Tan Sep 29 '14 at 20:58
  • 1
    @kentarosu The WatchViewStub class should work fine in conjunction with a Moto 360 unit. There is a case where AndroidWear on a round watch inflates both square and round layouts when using a real device, which may be causing your problem. There is a [bug opened in AOSP](https://code.google.com/p/android/issues/detail?id=76663) for this, and in that ticket there is a link to a StackOverflow post that has a workaround for the issue. – Lo-Tan Sep 29 '14 at 21:12
  • @Lo-Tan thanks for the SO post but no, I corrected that long before. That issue is obvious by the screenshot the OP posted; can't miss it. What's happening is I've "forced" my AVD to Round like the post you suggested, and the rect borders and shape are no longer overlaying like the screenshot. However, when you debug a GridViewPager esp on the WindowInsetListener, the AVD runtime still returns !round even though visually there is no rect overlaying the circle. I'll send a screenshot when I get a chance. – Java Guy Oct 02 '14 at 06:39
  • @JavaGuy I haven't tried this, but have you deployed the WatchViewStub sample project to the emulator and seen if it works? – Lo-Tan Oct 02 '14 at 22:40

2 Answers2

1

There are many problems with inflating layouts that are caused by not correctly using WatchViewStub. I don't see any code to know exactly, but one common issue is when you register a listener for watch insets so you can check if it is round or square inside your onApplyWindowInsets handler:

    final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
    stub.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
            // Need to also call the original insets since we have overridden the original                                                  
            // https://developer.android.com/reference/android/view/View.OnApplyWindowInsetsListener.html                                   
            stub.onApplyWindowInsets(windowInsets);

            // this is where you would check the WindowInsets for isRound()

            return windowInsets;
        }
    });

I see cases where people forget to return the windowInsets, or forget to call stub.onApplyWindowInsets(). This has the effect of giving a square layout instead of a round layout.

Also, there was a bug with the AndroidWearRound emulator built into the SDK. There were three of them, and if you created the wrong one, it would actually create a square emulator. Make sure if you have three emulators, that you pick the second one. This bug has been fixed in the latest Android SDK Tools 23.0.4, but it might be that you have an older version.

Can you show us the code you are doing around the WatchViewStub?

Wayne Piekarski
  • 3,203
  • 18
  • 19
0

One easy fix is to upgrade the Wear Round emulator to API level 22, which is out now. I have in general found the Wear Round emulator at API level 21 to have some buggy behaviour, while so far have not found any problems with the Round emulator at API level 22. I think this will fix the issue, as I had the same problem myself at some point (and it was NOT a setup problem of the emulator).

zaifrun
  • 931
  • 9
  • 21