Detect Android watch screen shape when creating a watch face

I'm banging my head for few days now and I can make sense of any of the information I found. I'm developing a play watch face for Android Wear. I have 2 classes - 1 service for the watch face and one class which extends WearableListenerService for retrieving the phone battery.

I'm trying to detect the shape of the screen so I can populate the respective background of the watch - either circular or square. I've tried all of the solution I've found but non of them is working with Service class. All of them need Activity - this includes the WatchViewStub, onApplyWindowInsets. Those also require a layout while I don't need this since I don't have a real UI to inflate. Moreover I'm adjusting the Bitmap size according to the watch screen dimensions. I've tried also ShapeWear class but it does not seem to work for me either.

Is there any easy and convenient way to apply the respective background to the respective shape for pure watch faces? I don't want to go with a companion app as I want to keep it simple and clean.

Thanks!

Upvotes: 1

Views: 623

Answers (1)

Amir Alagic
Amir Alagic

Reputation: 1790

I think that the service class you have is CanvasWatchFaceService. In that case just override onApplyWindowInsets method and you will get info whether screen is round or square.

@Override  
public void onApplyWindowInsets(WindowInsets insets) {  
        super.onApplyWindowInsets(insets);
        mIsRound = insets.isRound();
}

Upvotes: 3

Related Questions