From 85ee3519fd578372739943d38ce63e02fba5d305 Mon Sep 17 00:00:00 2001 From: Dominik Dzienia Date: Wed, 4 Dec 2019 01:38:01 +0100 Subject: [PATCH 1/3] (#2240) Fixed open loop notifications on wear os - support for Android O channel config --- .../androidaps/data/ListenerService.java | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java index 9e018516ba..67c743c38b 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -1,24 +1,22 @@ package info.nightscout.androidaps.data; -import java.util.Set; -import java.util.concurrent.TimeUnit; - import android.app.Notification; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.os.SystemClock; import android.preference.PreferenceManager; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import androidx.core.app.NotificationCompat; -import androidx.core.app.NotificationManagerCompat; - import android.util.Log; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; @@ -36,8 +34,11 @@ import com.google.android.gms.wearable.NodeApi; import com.google.android.gms.wearable.Wearable; import com.google.android.gms.wearable.WearableListenerService; -import info.nightscout.androidaps.interaction.AAPSPreferences; +import java.util.Set; +import java.util.concurrent.TimeUnit; + import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interaction.AAPSPreferences; import info.nightscout.androidaps.interaction.actions.AcceptActivity; import info.nightscout.androidaps.interaction.actions.CPPActivity; import info.nightscout.androidaps.interaction.utils.Persistence; @@ -79,6 +80,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp private static final String ACTION_RESEND_BULK = "com.dexdrip.stephenblack.nightwatch.RESEND_BULK_DATA"; + private static final String AAPS_NOTIFY_CHANNEL_ID = "AndroidAPS-Openloop"; GoogleApiClient googleApiClient; private long lastRequest = 0; @@ -552,13 +554,29 @@ public class ListenerService extends WearableListenerService implements GoogleAp } private void notifyChangeRequest(String title, String message, String actionstring) { + // Create the NotificationChannel, but only on API 26+ because + // the NotificationChannel class is new and not in the support library + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + CharSequence name = "AAPS Open Loop"; + String description = "Open Loop request notiffication";//getString(R.string.channel_description); + NotificationChannel channel = new NotificationChannel(AAPS_NOTIFY_CHANNEL_ID, name, NotificationManager.IMPORTANCE_HIGH); + channel.setDescription(description); + channel.enableVibration(true); - Notification.Builder builder = - new Notification.Builder(this); //,"AndroidAPS-Openloop"); - builder.setSmallIcon(R.drawable.notif_icon) + // Register the channel with the system; you can't change the importance + // or other notification behaviors after this + NotificationManager notificationManager = getSystemService(NotificationManager.class); + notificationManager.createNotificationChannel(channel); + } + + NotificationCompat.Builder builder = + new NotificationCompat.Builder(this, AAPS_NOTIFY_CHANNEL_ID); + + builder = builder.setSmallIcon(R.drawable.notif_icon) .setContentTitle(title) .setContentText(message) - .setPriority(Notification.PRIORITY_HIGH); + .setPriority(Notification.PRIORITY_HIGH) + .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000}); // Creates an explicit intent for an Activity in your app Intent intent = new Intent(this, AcceptActivity.class); @@ -571,8 +589,8 @@ public class ListenerService extends WearableListenerService implements GoogleAp PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); - builder.setContentIntent(resultPendingIntent); - builder.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000}); + + builder = builder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); From d9651d0d474655c10a34c69ef888fbf1e46dfd7c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 5 Dec 2019 16:34:01 +0100 Subject: [PATCH 2/3] Update Crowdin configuration file --- crowdin.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crowdin.yml b/crowdin.yml index 7d92dfb8bc..d80aef25d9 100644 --- a/crowdin.yml +++ b/crowdin.yml @@ -7,3 +7,5 @@ files: translation: /app/src/main/res/values-%android_code%/%original_file_name% - source: /app/src/main/res/values/objectives.xml translation: /app/src/main/res/values-%android_code%/%original_file_name% + - source: /wear/src/main/res/values/strings.xml + translation: /wear/src/main/res/values-%android_code%/strings.xml From 48581a0ac6cda4a02a417235552c658ccbad27d6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 5 Dec 2019 16:39:34 +0100 Subject: [PATCH 3/3] move wear arrays to extra resources file --- wear/src/main/res/values/arrays.xml | 66 ++++++++++++++++++++++++++++ wear/src/main/res/values/strings.xml | 61 ------------------------- 2 files changed, 66 insertions(+), 61 deletions(-) create mode 100644 wear/src/main/res/values/arrays.xml diff --git a/wear/src/main/res/values/arrays.xml b/wear/src/main/res/values/arrays.xml new file mode 100644 index 0000000000..9985ab6e7d --- /dev/null +++ b/wear/src/main/res/values/arrays.xml @@ -0,0 +1,66 @@ + + + + + 1 hour + 2 hours + 3 hours + 4 hours + 5 hours + + + + 1 + 2 + 3 + 4 + 5 + + + + Low + Medium + High + + + + 1 + 2 + 3 + + + + Default + Quick righty + Quick lefty + Modern Sparse + + + + 1 + 2 + 3 + 4 + + + + Default + Menu + Wizard + Bolus + eCarb + Status + None + + + + default + menu + wizard + bolus + ecarb + status + none + + + diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml index ca24978853..87ca25e0b9 100644 --- a/wear/src/main/res/values/strings.xml +++ b/wear/src/main/res/values/strings.xml @@ -4,67 +4,6 @@ AAPS AAPS - - 1 hour - 2 hours - 3 hours - 4 hours - 5 hours - - - - 1 - 2 - 3 - 4 - 5 - - - - Low - Medium - High - - - - 1 - 2 - 3 - - - - Default - Quick righty - Quick lefty - Modern Sparse - - - - 1 - 2 - 3 - 4 - - - - Default - Menu - Wizard - Bolus - eCarb - Status - None - - - - default - menu - wizard - bolus - ecarb - status - none - AAPS AAPS(Large)