0

I create a new watchface for android wear.

I'd like to change visibility of some elements (textviews) on watchface, if indicators (lost connection, load battery) are shown on the screen.

Is there a way to recognize when those indicators get visible?

Here i set up the watchFaceStyle:

setWatchFaceStyle(new WatchFaceStyle.Builder(DigitalWatchFaceService.this)
                        .setAcceptsTapEvents(false)
                        .setCardPeekMode(WatchFaceStyle.PEEK_MODE_SHORT)
                        .setBackgroundVisibility(WatchFaceStyle.BACKGROUND_VISIBILITY_INTERRUPTIVE)
                        .setHotwordIndicatorGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL)
                        .setPeekOpacityMode(WatchFaceStyle.PEEK_OPACITY_MODE_TRANSLUCENT)
                        .setShowUnreadCountIndicator(false)
                        .setStatusBarGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL)
                        .setShowSystemUiTime(false)
                        .build());

Is there something like..:

isStatusBarVisible()

or

isHotwordIndicatorVisible()

or is there some methode in a listener? I can't find something like this..

erli2909
  • 1
  • 3

2 Answers2

0

You would need to do similar work to how these indicators are detecting if they should be displayed. For example, you would need to listen for battery events and from that infer if the device is on a charger. For the connection, you would need to listen for onPeerConnected on onPeerDisconnected.

But in general this doesn't seem like a good idea. You never have the guarantee that something new is not added. Instead you should use watch face api to position the indicators where it fits your watch face best and avoid that area altogether when displaying your content.

gruszczy
  • 40,948
  • 31
  • 128
  • 181
0

I know this isn't a good idea, but here is my solution:

Check connection: (Problem: This is much faster than the indicator)

Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
    @Override
    public void onResult(NodeApi.GetConnectedNodesResult getConnectedNodesResult) {
        if (!getConnectedNodesResult.getNodes().isEmpty()) {
            isConnected = true;
        } else {
                isConnected = false;
        }
    }
});

Check battery:

IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = getBaseContext().registerReceiver(null, intentFilter);
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
         status == BatteryManager.BATTERY_STATUS_FULL;

Indicators:

if (isCharging || !isConnected) {
    isIndicatorVisible = true;
} else {
    isIndicatorVisible = false;
}
erli2909
  • 1
  • 3