Reputation: 27633
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.
OnApplyWindowInsetListener
not being called?windowInset.isRound()
returns false on the Moto 360?Build.MODEL
?Upvotes: 5
Views: 848
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
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