vibrate less on bolus

This commit is contained in:
AdrianLxM 2021-01-13 00:23:35 +01:00
parent a3cbb663b9
commit 30689c38aa

View file

@ -115,7 +115,6 @@ public class ListenerService extends WearableListenerService implements GoogleAp
}
@Override
protected Void doInBackground(Void... params) {
// Log.d(TAG, logPrefix + "DataRequester: doInBack: " + params);
@ -364,7 +363,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
}
Log.d(TAG, logPrefix + "sendData: execute lastRequest:" + WearUtil.dateTimeText(lastRequest));
mDataRequester = (DataRequester)new DataRequester(this, path, payload).execute();
mDataRequester = (DataRequester) new DataRequester(this, path, payload).execute();
// executeTask(mDataRequester);
// if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
@ -402,7 +401,6 @@ public class ListenerService extends WearableListenerService implements GoogleAp
}
private void forceGoogleApiConnect() {
if (googleApiClient == null || (!googleApiClient.isConnected() && !googleApiClient.isConnecting())) {
try {
@ -424,7 +422,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
if (intent != null && ACTION_RESEND.equals(intent.getAction())) {
googleApiConnect();
requestData();
} else if(intent != null && ACTION_CANCELBOLUS.equals(intent.getAction())){
} else if (intent != null && ACTION_CANCELBOLUS.equals(intent.getAction())) {
googleApiConnect();
//dismiss notification
@ -436,7 +434,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
cancelBolus();
} else if(intent != null && ACTION_CONFIRMATION.equals(intent.getAction())){
} else if (intent != null && ACTION_CONFIRMATION.equals(intent.getAction())) {
googleApiConnect();
//dismiss notification
@ -447,7 +445,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
String actionstring = intent.getStringExtra("actionstring");
sendConfirmActionstring(actionstring);
} else if(intent != null && ACTION_CONFIRMCHANGE.equals(intent.getAction())){
} else if (intent != null && ACTION_CONFIRMCHANGE.equals(intent.getAction())) {
googleApiConnect();
//dismiss notification
@ -458,7 +456,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
String actionstring = intent.getStringExtra("actionstring");
sendConfirmActionstring(actionstring);
} else if(intent != null && ACTION_INITIATE_ACTION.equals(intent.getAction())){
} else if (intent != null && ACTION_INITIATE_ACTION.equals(intent.getAction())) {
googleApiConnect();
String actionstring = intent.getStringExtra("actionstring");
@ -497,7 +495,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
String message = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("message");
String actionstring = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("actionstring");
if("opencpp".equals(title) && actionstring.startsWith("opencpp")){
if ("opencpp".equals(title) && actionstring.startsWith("opencpp")) {
String[] act = actionstring.split("\\s+");
Intent intent = new Intent(this, CPPActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@ -518,16 +516,16 @@ public class ListenerService extends WearableListenerService implements GoogleAp
messageIntent.putExtra("status", dataMap.toBundle());
Persistence.storeDataMap(RawDisplayData.STATUS_PERSISTENCE_KEY, dataMap);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
} else if (path.equals(BASAL_DATA_PATH)){
} else if (path.equals(BASAL_DATA_PATH)) {
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("basals", dataMap.toBundle());
Persistence.storeDataMap(RawDisplayData.BASALS_PERSISTENCE_KEY, dataMap);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
} else if (path.equals(NEW_PREFERENCES_PATH)){
} else if (path.equals(NEW_PREFERENCES_PATH)) {
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
if(dataMap.containsKey("wearcontrol")) {
if (dataMap.containsKey("wearcontrol")) {
boolean wearcontrol = dataMap.getBoolean("wearcontrol", false);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();
@ -607,12 +605,22 @@ public class ListenerService extends WearableListenerService implements GoogleAp
private void showBolusProgress(int progresspercent, String progresstatus) {
long[] vibratePattern;
boolean vibrate = PreferenceManager
.getDefaultSharedPreferences(this).getBoolean("vibrateOnBolus", true);
if (vibrate) {
vibratePattern = new long[]{0, 50, 1000};
} else {
vibratePattern = new long[]{0, 1, 1000};
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "AAPS Bolus Progress";
String description = "Bolus progress and cancel";
NotificationChannel channel = new NotificationChannel(AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS, name, NotificationManager.IMPORTANCE_HIGH);
channel.setDescription(description);
channel.enableVibration(true);
channel.setVibrationPattern(vibratePattern);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
@ -624,16 +632,6 @@ public class ListenerService extends WearableListenerService implements GoogleAp
cancelIntent.setAction(ACTION_CANCELBOLUS);
PendingIntent cancelPendingIntent = PendingIntent.getService(this, 0, cancelIntent, 0);
long[] vibratePattern;
boolean vibreate = PreferenceManager
.getDefaultSharedPreferences(this).getBoolean("vibrateOnBolus", true);
if(vibreate){
vibratePattern = new long[]{0, 50, 1000};
} else {
vibratePattern = new long[]{0, 1, 1000};
}
// TODO: proper channel. Does cancel work?
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS)
.setSmallIcon(R.drawable.ic_icon)
@ -652,7 +650,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
notificationManager.cancel(CONFIRM_NOTIF_ID); // multiple watch setup
if (progresspercent == 100){
if (progresspercent == 100) {
scheduleDismissBolusprogress(5);
}
}
@ -675,18 +673,17 @@ public class ListenerService extends WearableListenerService implements GoogleAp
}
private class DismissThread extends Thread{
private class DismissThread extends Thread {
private final int notificationID;
private final int seconds;
private boolean valid = true;
DismissThread(int notificationID, int seconds){
DismissThread(int notificationID, int seconds) {
this.notificationID = notificationID;
this.seconds = seconds;
}
public synchronized void invalidate(){
public synchronized void invalidate() {
valid = false;
}
@ -694,7 +691,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
public void run() {
SystemClock.sleep(seconds * 1000);
synchronized (this) {
if(valid) {
if (valid) {
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(ListenerService.this);
notificationManager.cancel(notificationID);