Andrea Baccega
Andrea Baccega

Reputation: 27633

Detect Moto 360/circlular shape and onApplyWindowInsetListener not being called

It looks like common ways to detect the screen shape of the Moto 360 do not work properly.

I know there are reports saying that windowInset.isRound() returns false in the Moto 360.

Currently my code is the following

WatchViewStub viewStub = new WatchViewStub(this);
viewStub.setRoundLayout(com.pizzaentertainment.weatherwatchface.R.layout.bau);
viewStub.setRectLayout(com.pizzaentertainment.weatherwatchface.R.layout.bau_rect);
viewStub.setOnApplyWindowInsetsListener( new View.OnApplyWindowInsetsListener() {
    @Override
    public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
        Log.d("ISWHAT?", "ASD" +windowInsets.isRound());
        return windowInsets;
    }
});
addContentView(viewStub, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
viewStub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
    @Override
    public void onLayoutInflated(WatchViewStub watchViewStub) {
        Log.d("INFLATED", "INFLATED");
    }
});

My main problem is that the onApplyWindowInsets never gets called on both my LG G watch and the Samsung Galaxy Gear Live. I made a test with a 360 user and, according to the test, that method doesn't get called on his device either.

  1. Why is OnApplyWindowInsetListener not being called?
  2. Why do people who got the callback working report that windowInset.isRound() returns false on the Moto 360?
  3. How are we supposed to recognize the Moto 360 (and future ones with the circular shape)? From the Build.MODEL?

Upvotes: 5

Views: 848

Answers (2)

mcp
mcp

Reputation: 2076

You may not be having this problem still, but I noticed that my round layout was not being inflated on my Moto 360. Instead my rectangular one was. I fixed this by changing the theme in the manifest file to DeviceDefault.

Upvotes: 0

Rossen Varbanov
Rossen Varbanov

Reputation: 53

I found too that setOnApplyWindowInsetsListener is not called on the real devices. It is checked on LG G Watch and Gear Live. Looks this is true for Moto 360 as well. I did the following workaround:

    WatchViewStub stub = (WatchViewStub) findViewById(R.id.stub);
    stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
        @Override
        public void onLayoutInflated(WatchViewStub stub) {
            Log.d(TAG, "onLayoutInflated()");
            m_pager = (GridViewPager) findViewById(R.id.pager_square);
            m_roundScreen = false;
            if (m_pager == null) {
                m_pager = (GridViewPager) findViewById(R.id.pager_round);
                m_roundScreen = true;
            }
            // ... do other pager initializations
        }
    });

Set in your round and square layouts different ID for one of the components and check which one is loaded because I didn't find any other way. In the example I set for my GridViewPager pager_square in the square layout and pager_round in the round layout. Not very pretty but works well as a workaround.

Upvotes: 3

Related Questions