Detect Moto 360 / circlular shape and onApplyWindowInsetListener not to be called

It seems that the usual Moto 360 screen shape detection methods do not work properly.

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

Currently my code is as follows

 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 onApplyWindowInsets will never be called on both my LG G watch and Samsung Galaxy Gear Live. I did a test with 360 users and, according to the test, this method is also not called on its device.

  • Why OnApplyWindowInsetListener n't OnApplyWindowInsetListener called?
  • Why do people who get a working callback report that windowInset.isRound() returns false on the Moto 360?
  • How should we recognize the Moto 360 (and future ones with a circular shape)? From Build.MODEL ?
+5
source share
2 answers

I also found that setOnApplyWindowInsetsListener is not being called on real devices. It is tested on the LG G Watch and Gear Live. This seems to be true for the Moto 360. I made 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 different identifiers for one of the components in your round and square layouts and check which one is loaded, because I did not find another way. In the example, I set the square layout and pager_round in the round layout for my GridViewPager pager_square. Not very pretty, but works well as a workaround.

+3
source

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

0
source

Source: https://habr.com/ru/post/1202473/


All Articles