I am curious to know about the wear type, whether it\'s round or square, because on the basis of device type I want to make different views for round and square. From This
Unofficial way (without using WatchViewStub) - but for me it was way way easier. https://github.com/tajchert/ShapeWear
Just copy ShapeWear.java class, and subscribe to screen shape detection event setOnShapeChangeListener()
or call method ShapeWear.isRound()
(can throw error is shape is not yet determined) or ShapeWear. getShape()
- which can result in ShapeWear.SHAPE_UNSURE
in same situation.
Use WatchViewStub to inflate the view.Later in the layout file you may specify the layout for each watch type as below.It will automatically pick the correct layout as required by the device.
<android.support.wearable.view.WatchViewStub
.
.
.
app:rectLayout="@layout/rect_activity_my_wear"
app:roundLayout="@layout/round_activity_my_wear"
.
.
.
>
If you need to get this information programmatically, you are correct in adding add a listener for setOnApplyWindowInsetsListener()
. However, in order to trigger that, you must also call requestApplyInsets().
In any case, if you only want to know this to switch between two alternative layouts, you can use the WatchViewStub
class which does this automatically (docs here).
API 23 introduced:
isScreenRound()