wear confirmation timeout and larger text for editplusminus

This commit is contained in:
AdrianLxM 2017-02-10 21:20:47 +01:00
parent 384e36a1f3
commit 108095ad77
3 changed files with 68 additions and 28 deletions

View file

@ -57,6 +57,8 @@ public class ListenerService extends WearableListenerService implements GoogleAp
private static final String ACTION_RESEND_BULK = "com.dexdrip.stephenblack.nightwatch.RESEND_BULK_DATA";
GoogleApiClient googleApiClient;
private long lastRequest = 0;
private DismissThread confirmThread;
private DismissThread bolusprogressThread;
public class DataRequester extends AsyncTask<Void, Void, Void> {
@ -289,17 +291,24 @@ public class ListenerService extends WearableListenerService implements GoogleAp
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this);
if(confirmThread != null){
confirmThread.invalidate();
}
notificationManager.notify(BOLUS_PROGRESS_NOTIF_ID, notificationBuilder.build());
notificationManager.cancel(CONFIRM_NOTIF_ID); // multiple watch setup
if (progresspercent == 100){
scheduleDismiss(BOLUS_PROGRESS_NOTIF_ID, 5);
scheduleDismissBolusprogress(5);
}
}
private void showConfirmationDialog(String title, String message, String actionstring) {
if(confirmThread != null){
confirmThread.invalidate();
}
Intent actionIntent = new Intent(this, ListenerService.class);
actionIntent.setAction(ACTION_CONFIRMATION);
actionIntent.putExtra("actionstring", actionstring);
@ -323,29 +332,59 @@ public class ListenerService extends WearableListenerService implements GoogleAp
notificationManager.notify(CONFIRM_NOTIF_ID, notificationBuilder.build());
// keep the confirmation dialog open for one minute.
scheduleDismiss(CONFIRM_NOTIF_ID, 60);
scheduleDismissConfirm(60);
}
private void scheduleDismiss(final int notificationId, final int seconds) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(seconds * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(ListenerService.this);
notificationManager.cancel(notificationId);
private void scheduleDismissConfirm(final int seconds) {
if(confirmThread != null){
confirmThread.invalidate();
}
confirmThread = new DismissThread(CONFIRM_NOTIF_ID, seconds);
confirmThread.start();
}
private void scheduleDismissBolusprogress(final int seconds) {
if(confirmThread != null){
confirmThread.invalidate();
}
bolusprogressThread = new DismissThread(BOLUS_PROGRESS_NOTIF_ID, seconds);
bolusprogressThread.start();
}
private class DismissThread extends Thread{
private final int notificationID;
private final int seconds;
private boolean valid = true;
DismissThread(int notificationID, int seconds){
this.notificationID = notificationID;
this.seconds = seconds;
}
public synchronized void invalidate(){
valid = false;
}
@Override
public void run() {
try {
Thread.sleep(seconds * 1000);
} catch (InterruptedException e) {
//e.printStackTrace();
}
});
t.start();
synchronized (this) {
if(valid) {
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(ListenerService.this);
notificationManager.cancel(notificationID);
}
}
}
}
public static void requestData(Context context) {
Intent intent = new Intent(context, ListenerService.class);
intent.setAction(ACTION_RESEND);

View file

@ -35,8 +35,8 @@
android:minWidth="50dp"
android:padding="10dp"
android:text="112"
android:textSize="45sp"
android:cursorVisible="false"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_horizontal" />
<TextView
@ -46,7 +46,8 @@
android:layout_gravity="center"
android:text="label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center" />
android:gravity="center"
android:textSize="25sp" />
</LinearLayout>
<ImageView
android:id="@+id/plusbutton"

View file

@ -66,14 +66,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/full/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/full/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/full/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/assets" type="java-test-resource" />
@ -82,6 +74,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFull/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />