From 51a88cff6cf5fc474a35203d4e4023f9fd4a1f0a Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Tue, 21 Dec 2021 21:38:23 +0100 Subject: [PATCH] Wear: add battery receiver home2 --- wear/src/main/AndroidManifest.xml | 4 ++++ .../androidaps/watchfaces/Home2.java | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index b16b04f6d1..04b178307d 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -100,6 +100,9 @@ + + + @@ -544,6 +547,7 @@ + diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/Home2.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/Home2.java index 458fa048cd..180b1dd935 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/Home2.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/Home2.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.watchfaces; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.graphics.Color; @@ -29,9 +31,28 @@ public class Home2 extends BaseWatchFace { super.onCreate(); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); layoutView = inflater.inflate(R.layout.activity_home_2, null); + + IntentFilter intentBatteryFilter = new IntentFilter(); + intentBatteryFilter.addAction(BatteryManager.ACTION_CHARGING); + intentBatteryFilter.addAction(BatteryManager.ACTION_DISCHARGING); + registerReceiver(batteryReceiver, intentBatteryFilter); performViewSetup(); } + private BroadcastReceiver batteryReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + setDataFields(); + invalidate(); + } + }; + + @Override + public void onDestroy() { + unregisterReceiver(batteryReceiver); + super.onDestroy(); + } + @Override protected void onTapCommand(int tapType, int x, int y, long eventTime) {