¿Cómo se puede detectar que tipo de pantalla tiene el smartwatch en Android Wear de los tres tipos existentes?
- Rectangular
square
- Circular
round
- Circular con franja inferior (Moto360)
chin
Stack Overflow en español es un sitio de preguntas y respuestas para programadores y profesionales de la informática. Solo te toma un minuto registrarte.
Regístrate para unirte a esta comunidad¿Cómo se puede detectar que tipo de pantalla tiene el smartwatch en Android Wear de los tres tipos existentes?
square
round
chin
Según la documentación oficial.
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();
}
...
}
También hay una forma no oficial https://github.com/tajchert/ShapeWear
En este segundo método, simplemente copia el fichero ShapeWear.java
a tu proyecto e inicializalo en el onCreate
del mainActivity
así:
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
ShapeWear.initShapeWear(this);
}
Especifica el listener
de la siguiente manera:
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
}
});