How can you detect what kind of screen the smartwatch has on Android Wear of the three existing types?
- Rectangular
square
- Circular
round
- Circular with lower strip (Moto360)
chin
According to the official documentation .
private class Engine extends CanvasWatchFaceService.Engine {
boolean mIsRound;
int mChinSize;
@Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
mIsRound = insets.isRound();
mChinSize = insets.getSystemWindowInsetBottom();
}
...
}
There is also an unofficial form link
In this second method, simply copy the file ShapeWear.java
to your project and initialize it in onCreate
of mainActivity
like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
ShapeWear.initShapeWear(this);
}
Specify listener
as follows:
ShapeWear.setOnShapeChangeListener(new ShapeWear.OnShapeChangeListener() {
@Override
public void shapeDetected(ShapeWear.ScreenShape screenShape) {
//Do your stuff here for example:
switch (screenShape){
case RECTANGLE:
break;
case ROUND:
break;
case MOTO_ROUND:
//as it is special case of ROUND - cut at the bottom.
break;
}
}
});
ShapeWear.setOnSizeChangeListener(new ShapeWear.OnSizeChangeListener() {
@Override
public void sizeDetected(int widthPx, int heightPx) {
//Do your stuff here
}
});