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 @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
// Log.d(TAG, logPrefix + "DataRequester: doInBack: " + params); // Log.d(TAG, logPrefix + "DataRequester: doInBack: " + params);
@ -158,8 +157,8 @@ public class ListenerService extends WearableListenerService implements GoogleAp
} }
Log.d(TAG, "doInBackground connected. CapabilityApi.GetCapabilityResult mPhoneNodeID=" Log.d(TAG, "doInBackground connected. CapabilityApi.GetCapabilityResult mPhoneNodeID="
+ (phoneNode != null ? phoneNode.getId() : "") + " count=" + count + " localnode=" + (phoneNode != null ? phoneNode.getId() : "") + " count=" + count + " localnode="
+ localnode);// KS + localnode);// KS
if (count > 0) { if (count > 0) {
@ -168,11 +167,11 @@ public class ListenerService extends WearableListenerService implements GoogleAp
// Log.d(TAG, "doInBackground path: " + path); // Log.d(TAG, "doInBackground path: " + path);
switch (path) { switch (path) {
// simple send as is payloads // simple send as is payloads
case WEARABLE_RESEND_PATH: case WEARABLE_RESEND_PATH:
Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), Wearable.MessageApi.sendMessage(googleApiClient, node.getId(),
WEARABLE_RESEND_PATH, null); WEARABLE_RESEND_PATH, null);
break; break;
case WEARABLE_DATA_PATH: case WEARABLE_DATA_PATH:
case WEARABLE_CANCELBOLUS_PATH: case WEARABLE_CANCELBOLUS_PATH:
@ -207,7 +206,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
} }
} else { } else {
Log.d(TAG, logPrefix + "Not connected for sending: api " Log.d(TAG, logPrefix + "Not connected for sending: api "
+ ((googleApiClient == null) ? "is NULL!" : "not null")); + ((googleApiClient == null) ? "is NULL!" : "not null"));
if (googleApiClient != null) { if (googleApiClient != null) {
googleApiClient.connect(); googleApiClient.connect();
} else { } else {
@ -227,12 +226,12 @@ public class ListenerService extends WearableListenerService implements GoogleAp
public CapabilityInfo getCapabilities() { public CapabilityInfo getCapabilities() {
CapabilityApi.GetCapabilityResult capabilityResult = Wearable.CapabilityApi.getCapability(googleApiClient, CapabilityApi.GetCapabilityResult capabilityResult = Wearable.CapabilityApi.getCapability(googleApiClient,
CAPABILITY_PHONE_APP, CapabilityApi.FILTER_REACHABLE).await(GET_CAPABILITIES_TIMEOUT_MS, CAPABILITY_PHONE_APP, CapabilityApi.FILTER_REACHABLE).await(GET_CAPABILITIES_TIMEOUT_MS,
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
if (!capabilityResult.getStatus().isSuccess()) { if (!capabilityResult.getStatus().isSuccess()) {
Log.e(TAG, logPrefix + "doInBackground Failed to get capabilities, status: " Log.e(TAG, logPrefix + "doInBackground Failed to get capabilities, status: "
+ capabilityResult.getStatus().getStatusMessage()); + capabilityResult.getStatus().getStatusMessage());
return null; return null;
} }
@ -364,7 +363,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
} }
Log.d(TAG, logPrefix + "sendData: execute lastRequest:" + WearUtil.dateTimeText(lastRequest)); 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); // executeTask(mDataRequester);
// if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
@ -402,7 +401,6 @@ public class ListenerService extends WearableListenerService implements GoogleAp
} }
private void forceGoogleApiConnect() { private void forceGoogleApiConnect() {
if (googleApiClient == null || (!googleApiClient.isConnected() && !googleApiClient.isConnecting())) { if (googleApiClient == null || (!googleApiClient.isConnected() && !googleApiClient.isConnecting())) {
try { try {
@ -424,7 +422,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
if (intent != null && ACTION_RESEND.equals(intent.getAction())) { if (intent != null && ACTION_RESEND.equals(intent.getAction())) {
googleApiConnect(); googleApiConnect();
requestData(); requestData();
} else if(intent != null && ACTION_CANCELBOLUS.equals(intent.getAction())){ } else if (intent != null && ACTION_CANCELBOLUS.equals(intent.getAction())) {
googleApiConnect(); googleApiConnect();
//dismiss notification //dismiss notification
@ -436,7 +434,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
cancelBolus(); cancelBolus();
} else if(intent != null && ACTION_CONFIRMATION.equals(intent.getAction())){ } else if (intent != null && ACTION_CONFIRMATION.equals(intent.getAction())) {
googleApiConnect(); googleApiConnect();
//dismiss notification //dismiss notification
@ -447,7 +445,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
String actionstring = intent.getStringExtra("actionstring"); String actionstring = intent.getStringExtra("actionstring");
sendConfirmActionstring(actionstring); sendConfirmActionstring(actionstring);
} else if(intent != null && ACTION_CONFIRMCHANGE.equals(intent.getAction())){ } else if (intent != null && ACTION_CONFIRMCHANGE.equals(intent.getAction())) {
googleApiConnect(); googleApiConnect();
//dismiss notification //dismiss notification
@ -458,7 +456,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
String actionstring = intent.getStringExtra("actionstring"); String actionstring = intent.getStringExtra("actionstring");
sendConfirmActionstring(actionstring); sendConfirmActionstring(actionstring);
} else if(intent != null && ACTION_INITIATE_ACTION.equals(intent.getAction())){ } else if (intent != null && ACTION_INITIATE_ACTION.equals(intent.getAction())) {
googleApiConnect(); googleApiConnect();
String actionstring = intent.getStringExtra("actionstring"); 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 message = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("message");
String actionstring = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("actionstring"); 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+"); String[] act = actionstring.split("\\s+");
Intent intent = new Intent(this, CPPActivity.class); Intent intent = new Intent(this, CPPActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@ -518,16 +516,16 @@ public class ListenerService extends WearableListenerService implements GoogleAp
messageIntent.putExtra("status", dataMap.toBundle()); messageIntent.putExtra("status", dataMap.toBundle());
Persistence.storeDataMap(RawDisplayData.STATUS_PERSISTENCE_KEY, dataMap); Persistence.storeDataMap(RawDisplayData.STATUS_PERSISTENCE_KEY, dataMap);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent); 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(); dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
Intent messageIntent = new Intent(); Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND); messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("basals", dataMap.toBundle()); messageIntent.putExtra("basals", dataMap.toBundle());
Persistence.storeDataMap(RawDisplayData.BASALS_PERSISTENCE_KEY, dataMap); Persistence.storeDataMap(RawDisplayData.BASALS_PERSISTENCE_KEY, dataMap);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent); 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(); dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
if(dataMap.containsKey("wearcontrol")) { if (dataMap.containsKey("wearcontrol")) {
boolean wearcontrol = dataMap.getBoolean("wearcontrol", false); boolean wearcontrol = dataMap.getBoolean("wearcontrol", false);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
@ -555,20 +553,20 @@ public class ListenerService extends WearableListenerService implements GoogleAp
} }
private void notifyChangeRequest(String title, String message, String actionstring) { private void notifyChangeRequest(String title, String message, String actionstring) {
// Create the NotificationChannel, but only on API 26+ because // Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library // the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "AAPS Open Loop"; CharSequence name = "AAPS Open Loop";
String description = "Open Loop request notiffication";//getString(R.string.channel_description); String description = "Open Loop request notiffication";//getString(R.string.channel_description);
NotificationChannel channel = new NotificationChannel(AAPS_NOTIFY_CHANNEL_ID_OPENLOOP, name, NotificationManager.IMPORTANCE_HIGH); NotificationChannel channel = new NotificationChannel(AAPS_NOTIFY_CHANNEL_ID_OPENLOOP, name, NotificationManager.IMPORTANCE_HIGH);
channel.setDescription(description); channel.setDescription(description);
channel.enableVibration(true); channel.enableVibration(true);
// Register the channel with the system; you can't change the importance // Register the channel with the system; you can't change the importance
// or other notification behaviors after this // or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class); NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel); notificationManager.createNotificationChannel(channel);
} }
NotificationCompat.Builder builder = NotificationCompat.Builder builder =
new NotificationCompat.Builder(this, AAPS_NOTIFY_CHANNEL_ID_OPENLOOP); new NotificationCompat.Builder(this, AAPS_NOTIFY_CHANNEL_ID_OPENLOOP);
@ -607,12 +605,22 @@ public class ListenerService extends WearableListenerService implements GoogleAp
private void showBolusProgress(int progresspercent, String progresstatus) { 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) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "AAPS Bolus Progress"; CharSequence name = "AAPS Bolus Progress";
String description = "Bolus progress and cancel"; String description = "Bolus progress and cancel";
NotificationChannel channel = new NotificationChannel(AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS, name, NotificationManager.IMPORTANCE_HIGH); NotificationChannel channel = new NotificationChannel(AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS, name, NotificationManager.IMPORTANCE_HIGH);
channel.setDescription(description); channel.setDescription(description);
channel.enableVibration(true); channel.enableVibration(true);
channel.setVibrationPattern(vibratePattern);
// Register the channel with the system; you can't change the importance // Register the channel with the system; you can't change the importance
// or other notification behaviors after this // or other notification behaviors after this
@ -624,16 +632,6 @@ public class ListenerService extends WearableListenerService implements GoogleAp
cancelIntent.setAction(ACTION_CANCELBOLUS); cancelIntent.setAction(ACTION_CANCELBOLUS);
PendingIntent cancelPendingIntent = PendingIntent.getService(this, 0, cancelIntent, 0); 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 = NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS) new NotificationCompat.Builder(this, AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS)
.setSmallIcon(R.drawable.ic_icon) .setSmallIcon(R.drawable.ic_icon)
@ -652,7 +650,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
notificationManager.cancel(CONFIRM_NOTIF_ID); // multiple watch setup notificationManager.cancel(CONFIRM_NOTIF_ID); // multiple watch setup
if (progresspercent == 100){ if (progresspercent == 100) {
scheduleDismissBolusprogress(5); 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 notificationID;
private final int seconds; private final int seconds;
private boolean valid = true; private boolean valid = true;
DismissThread(int notificationID, int seconds){ DismissThread(int notificationID, int seconds) {
this.notificationID = notificationID; this.notificationID = notificationID;
this.seconds = seconds; this.seconds = seconds;
} }
public synchronized void invalidate(){ public synchronized void invalidate() {
valid = false; valid = false;
} }
@ -694,7 +691,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
public void run() { public void run() {
SystemClock.sleep(seconds * 1000); SystemClock.sleep(seconds * 1000);
synchronized (this) { synchronized (this) {
if(valid) { if (valid) {
NotificationManagerCompat notificationManager = NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(ListenerService.this); NotificationManagerCompat.from(ListenerService.this);
notificationManager.cancel(notificationID); notificationManager.cancel(notificationID);
@ -738,7 +735,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
public void onCapabilityChanged(CapabilityInfo capabilityInfo) { public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
updatePhoneSyncBgsCapability(capabilityInfo); updatePhoneSyncBgsCapability(capabilityInfo);
Log.d(TAG, logPrefix + "onConnected onCapabilityChanged mPhoneNodeID:" + mPhoneNodeId Log.d(TAG, logPrefix + "onConnected onCapabilityChanged mPhoneNodeID:" + mPhoneNodeId
+ ", Capability: " + capabilityInfo); + ", Capability: " + capabilityInfo);
} }
}; };
@ -768,7 +765,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) { public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
if (!getLocalNodeResult.getStatus().isSuccess()) { if (!getLocalNodeResult.getStatus().isSuccess()) {
Log.e(TAG, "ERROR: failed to getLocalNode Status=" Log.e(TAG, "ERROR: failed to getLocalNode Status="
+ getLocalNodeResult.getStatus().getStatusMessage()); + getLocalNodeResult.getStatus().getStatusMessage());
} else { } else {
Log.d(TAG, "getLocalNode Status=: " + getLocalNodeResult.getStatus().getStatusMessage()); Log.d(TAG, "getLocalNode Status=: " + getLocalNodeResult.getStatus().getStatusMessage());
Node getnode = getLocalNodeResult.getNode(); Node getnode = getLocalNodeResult.getNode();
@ -791,5 +788,5 @@ public class ListenerService extends WearableListenerService implements GoogleAp
Wearable.MessageApi.removeListener(googleApiClient, this); Wearable.MessageApi.removeListener(googleApiClient, this);
Wearable.ChannelApi.removeListener(googleApiClient, this); Wearable.ChannelApi.removeListener(googleApiClient, this);
} }
} }
} }