Detect if the Android Wear screen is square, circular or fringed

3

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

    
asked by Webserveis 25.11.2016 в 09:42
source

1 answer

3

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
    }
});
    
answered by 25.11.2016 / 10:10
source