From aad2b94c8ee78ebd52ec020860618eaff9161160 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 27 Jun 2018 08:04:57 +0200 Subject: [PATCH 1/7] first confirm activity --- wear/build.gradle | 5 +- wear/src/main/AndroidManifest.xml | 4 + .../androidaps/data/ListenerService.java | 7 ++ .../interaction/actions/AcceptActivity.java | 111 ++++++++++++++++++ .../interaction/menus/MainMenuActivity.java | 13 +- .../main/res/layout/action_confirm_text.xml | 27 +++++ 6 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java create mode 100644 wear/src/main/res/layout/action_confirm_text.xml diff --git a/wear/build.gradle b/wear/build.gradle index 584b9a769e..63858c7285 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -30,7 +30,7 @@ android { defaultConfig { applicationId "info.nightscout.androidaps" - minSdkVersion 21 + minSdkVersion 23 targetSdkVersion 23 versionCode 1 versionName "1.0.2" @@ -67,6 +67,7 @@ dependencies { implementation "com.google.android.support:wearable:${wearableVersion}" implementation "com.google.android.gms:play-services-wearable:7.3.0" implementation(name:"ustwo-clockwise-debug", ext:"aar") - implementation "com.android.support:support-v4:23.0.1" + implementation "com.android.support:support-v4:27.0.1" + implementation 'com.android.support:wear:27.0.1' implementation "me.denley.wearpreferenceactivity:wearpreferenceactivity:0.5.0" } diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index 01423985d0..b37a93507d 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -204,6 +204,10 @@ android:name=".interaction.actions.CPPActivity" android:label="CPP"> + + 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 a827890733..fc25ab6341 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -436,6 +436,13 @@ public class ListenerService extends WearableListenerService implements GoogleAp context.startService(intent); } + public static void confirmAction(Context context, String actionstring) { + Intent intent = new Intent(context, ListenerService.class); + intent.putExtra("actionstring", actionstring); + intent.setAction(ACTION_CONFIRMATION); + context.startService(intent); + } + @Override public void onConnected(Bundle bundle) { requestData(); diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java new file mode 100644 index 0000000000..c4b0436cc1 --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java @@ -0,0 +1,111 @@ +package info.nightscout.androidaps.interaction.actions; + + +import android.content.res.Resources; +import android.os.Bundle; +import android.support.wearable.view.DotsPageIndicator; +import android.support.wearable.view.GridPagerAdapter; +import android.support.wearable.view.GridViewPager; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import java.text.DecimalFormat; + +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.ListenerService; +import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; +import info.nightscout.androidaps.interaction.utils.SafeParse; + +/** + * Created by adrian on 09/02/17. + */ + + +public class AcceptActivity extends ViewSelectorActivity { + + + String text = ""; + String actionstring = ""; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Bundle extras = getIntent().getExtras(); + text = extras.getString("text", ""); + actionstring = extras.getString("actionstring", ""); + + if ("".equals(text) || "".equals(actionstring) ){ + finish(); return; + } + + setContentView(R.layout.grid_layout); + final Resources res = getResources(); + final GridViewPager pager = (GridViewPager) findViewById(R.id.pager); + + pager.setAdapter(new MyGridViewPagerAdapter()); + DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator); + dotsPageIndicator.setPager(pager); + } + + + @Override + protected void onPause() { + super.onPause(); + finish(); + } + + + private class MyGridViewPagerAdapter extends GridPagerAdapter { + @Override + public int getColumnCount(int arg0) { + return 2; + } + + @Override + public int getRowCount() { + return 1; + } + + @Override + public Object instantiateItem(ViewGroup container, int row, int col) { + + if(col == 0){ + final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_confirm_text, container, false); + final TextView textView = (TextView) view.findViewById(R.id.confirmtext); + textView.setText(text); + container.addView(view); + return view; + } else { + final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false); + final ImageView confirmbutton = (ImageView) view.findViewById(R.id.confirmbutton); + confirmbutton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ListenerService.confirmAction(AcceptActivity.this, actionstring); + finish(); + } + }); + container.addView(view); + return view; + } + } + + @Override + public void destroyItem(ViewGroup container, int row, int col, Object view) { + // Handle this to get the data before the view is destroyed? + // Object should still be kept by this, just setup for reinit? + container.removeView((View)view); + } + + @Override + public boolean isViewFromObject(View view, Object object) { + return view==object; + } + + + } +} \ No newline at end of file diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java index fb8bb61e20..490ed77c08 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java @@ -9,6 +9,7 @@ import java.util.Vector; import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.interaction.AAPSPreferences; +import info.nightscout.androidaps.interaction.actions.AcceptActivity; import info.nightscout.androidaps.interaction.actions.BolusActivity; import info.nightscout.androidaps.interaction.actions.ECarbActivity; import info.nightscout.androidaps.interaction.actions.TempTargetActivity; @@ -34,7 +35,7 @@ public class MainMenuActivity extends MenuListActivity { protected String[] getElements() { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - if(!sharedPreferences.getBoolean("wearcontrol", false)){ + if(false && !sharedPreferences.getBoolean("wearcontrol", false)){ return new String[] { "Settings", "Re-Sync"}; @@ -84,9 +85,17 @@ public class MainMenuActivity extends MenuListActivity { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); } else if ("Prime/Fill".equals(action)) { - intent = new Intent(this, FillMenuActivity.class); + /*intent = new Intent(this, FillMenuActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); + */ + intent = new Intent(this, AcceptActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + Bundle params = new Bundle(); + params.putString("text", "dies\nist ein\nhoffentlich\n langer text\n\ndies\nist ein\nhoffentlich\n langer text\n\ndies\nist ein\nhoffentlich\n langer text\n\ndies\nist ein\nhoffentlich\n langer text\n\n"); + params.putString("actionstring", "blablubb"); + intent.putExtras(params); + startActivity(intent); } else if ("eCarb".equals(action)) { intent = new Intent(this, ECarbActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/wear/src/main/res/layout/action_confirm_text.xml b/wear/src/main/res/layout/action_confirm_text.xml new file mode 100644 index 0000000000..23472260bd --- /dev/null +++ b/wear/src/main/res/layout/action_confirm_text.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + \ No newline at end of file From 0fe26fda2714a4d6a2767a9d1c5310d85942ef1e Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 27 Jun 2018 16:55:37 +0200 Subject: [PATCH 2/7] confirm activity working --- .../androidaps/data/ListenerService.java | 13 +++++++++++- .../interaction/actions/AcceptActivity.java | 18 ++++++++-------- .../interaction/menus/MainMenuActivity.java | 6 ++++-- .../main/res/layout/action_confirm_text.xml | 21 +++++++++++++++---- 4 files changed, 42 insertions(+), 16 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 fc25ab6341..ffb6db7d6e 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit; import info.nightscout.androidaps.interaction.AAPSPreferences; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interaction.actions.AcceptActivity; import info.nightscout.androidaps.interaction.actions.CPPActivity; import info.nightscout.androidaps.interaction.utils.SafeParse; @@ -345,6 +346,16 @@ public class ListenerService extends WearableListenerService implements GoogleAp private void showConfirmationDialog(String title, String message, String actionstring) { + Intent intent = new Intent(this, AcceptActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + Bundle params = new Bundle(); + params.putString("title", title); + params.putString("message", message); + params.putString("actionstring", actionstring); + intent.putExtras(params); + startActivity(intent); + + /* if(confirmThread != null){ confirmThread.invalidate(); } @@ -375,7 +386,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp // keep the confirmation dialog open for one minute. scheduleDismissConfirm(60); - + */ } private void scheduleDismissConfirm(final int seconds) { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java index c4b0436cc1..4562700ae7 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java @@ -12,12 +12,8 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; -import java.text.DecimalFormat; - import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ListenerService; -import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; -import info.nightscout.androidaps.interaction.utils.SafeParse; /** * Created by adrian on 09/02/17. @@ -27,7 +23,8 @@ import info.nightscout.androidaps.interaction.utils.SafeParse; public class AcceptActivity extends ViewSelectorActivity { - String text = ""; + String title = ""; + String message = ""; String actionstring = ""; @Override @@ -35,10 +32,11 @@ public class AcceptActivity extends ViewSelectorActivity { super.onCreate(savedInstanceState); Bundle extras = getIntent().getExtras(); - text = extras.getString("text", ""); + title = extras.getString("title", ""); + message = extras.getString("message", ""); actionstring = extras.getString("actionstring", ""); - if ("".equals(text) || "".equals(actionstring) ){ + if ("".equals(message) || "".equals(actionstring) ){ finish(); return; } @@ -75,8 +73,10 @@ public class AcceptActivity extends ViewSelectorActivity { if(col == 0){ final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_confirm_text, container, false); - final TextView textView = (TextView) view.findViewById(R.id.confirmtext); - textView.setText(text); + final TextView headingView = (TextView) view.findViewById(R.id.title); + headingView.setText(title); + final TextView textView = (TextView) view.findViewById(R.id.message); + textView.setText(message); container.addView(view); return view; } else { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java index 490ed77c08..6ffc826016 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java @@ -85,17 +85,19 @@ public class MainMenuActivity extends MenuListActivity { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); } else if ("Prime/Fill".equals(action)) { - /*intent = new Intent(this, FillMenuActivity.class); + intent = new Intent(this, FillMenuActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); - */ + /* intent = new Intent(this, AcceptActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Bundle params = new Bundle(); + params.putString("heading", "Confirm"); params.putString("text", "dies\nist ein\nhoffentlich\n langer text\n\ndies\nist ein\nhoffentlich\n langer text\n\ndies\nist ein\nhoffentlich\n langer text\n\ndies\nist ein\nhoffentlich\n langer text\n\n"); params.putString("actionstring", "blablubb"); intent.putExtras(params); startActivity(intent); + */ } else if ("eCarb".equals(action)) { intent = new Intent(this, ECarbActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/wear/src/main/res/layout/action_confirm_text.xml b/wear/src/main/res/layout/action_confirm_text.xml index 23472260bd..18c8933470 100644 --- a/wear/src/main/res/layout/action_confirm_text.xml +++ b/wear/src/main/res/layout/action_confirm_text.xml @@ -14,12 +14,25 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:orientation="vertical"> + + + From a283586a3ce3c58060faf7837e6a27a85b03e2dd Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 27 Jun 2018 18:02:10 +0200 Subject: [PATCH 3/7] autodismissing confirm activity. --- .../interaction/actions/AcceptActivity.java | 32 +++++++++++++++++++ .../interaction/menus/MainMenuActivity.java | 10 ------ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java index 4562700ae7..92efb36368 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.java @@ -3,6 +3,8 @@ package info.nightscout.androidaps.interaction.actions; import android.content.res.Resources; import android.os.Bundle; +import android.os.SystemClock; +import android.support.v4.app.NotificationManagerCompat; import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.GridPagerAdapter; import android.support.wearable.view.GridViewPager; @@ -26,11 +28,15 @@ public class AcceptActivity extends ViewSelectorActivity { String title = ""; String message = ""; String actionstring = ""; + private DismissThread dismissThread; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + this.dismissThread = new DismissThread(); + dismissThread.start(); + Bundle extras = getIntent().getExtras(); title = extras.getString("title", ""); message = extras.getString("message", ""); @@ -106,6 +112,32 @@ public class AcceptActivity extends ViewSelectorActivity { return view==object; } + } + + @Override + public synchronized void onDestroy(){ + super.onDestroy(); + if(dismissThread != null){ + dismissThread.invalidate(); + } } + + private class DismissThread extends Thread{ + private boolean valid = true; + + public synchronized void invalidate(){ + valid = false; + } + + @Override + public void run() { + SystemClock.sleep(60 * 1000); + synchronized (this) { + if(valid) { + AcceptActivity.this.finish(); + } + } + } + } } \ No newline at end of file diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java index 6ffc826016..3ebaef23fe 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java @@ -88,16 +88,6 @@ public class MainMenuActivity extends MenuListActivity { intent = new Intent(this, FillMenuActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); - /* - intent = new Intent(this, AcceptActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - Bundle params = new Bundle(); - params.putString("heading", "Confirm"); - params.putString("text", "dies\nist ein\nhoffentlich\n langer text\n\ndies\nist ein\nhoffentlich\n langer text\n\ndies\nist ein\nhoffentlich\n langer text\n\ndies\nist ein\nhoffentlich\n langer text\n\n"); - params.putString("actionstring", "blablubb"); - intent.putExtras(params); - startActivity(intent); - */ } else if ("eCarb".equals(action)) { intent = new Intent(this, ECarbActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); From 815c3c17a94edfeae1651dee7da1a50b9d65185b Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 27 Jun 2018 18:03:15 +0200 Subject: [PATCH 4/7] cleanup. --- .../androidaps/data/ListenerService.java | 41 ------------------- 1 file changed, 41 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 ffb6db7d6e..7297d51815 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -354,47 +354,6 @@ public class ListenerService extends WearableListenerService implements GoogleAp params.putString("actionstring", actionstring); intent.putExtras(params); startActivity(intent); - - /* - if(confirmThread != null){ - confirmThread.invalidate(); - } - - Intent actionIntent = new Intent(this, ListenerService.class); - actionIntent.setAction(ACTION_CONFIRMATION); - actionIntent.putExtra("actionstring", actionstring); - PendingIntent actionPendingIntent = PendingIntent.getService(this, 0, actionIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_UPDATE_CURRENT);; - - long[] vibratePattern = new long[]{0, 100, 50, 100, 50}; - - NotificationCompat.Builder notificationBuilder = - new NotificationCompat.Builder(this) - .setSmallIcon(R.drawable.ic_icon) - .setContentTitle(title) - .setContentText(message) - .setContentIntent(actionPendingIntent) - .setPriority(NotificationCompat.PRIORITY_MAX) - .setVibrate(vibratePattern) - .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) - .extend(new NotificationCompat.WearableExtender()) - .addAction(R.drawable.ic_confirm, title, actionPendingIntent); - - NotificationManagerCompat notificationManager = - NotificationManagerCompat.from(this); - - notificationManager.notify(CONFIRM_NOTIF_ID, notificationBuilder.build()); - - // keep the confirmation dialog open for one minute. - scheduleDismissConfirm(60); - */ - } - - 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) { From f160a49ef61fe1a2291e03229d5211d81e4882e3 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 27 Jun 2018 18:48:09 +0200 Subject: [PATCH 5/7] only start one confirm activity --- wear/src/main/AndroidManifest.xml | 3 ++- .../interaction/actions/AcceptActivity.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index b37a93507d..91a52878bd 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -206,7 +206,8 @@ + android:launchMode="singleInstance" + android:label="ACCEPT"> Date: Wed, 27 Jun 2018 19:03:29 +0200 Subject: [PATCH 6/7] vibrate again --- wear/src/main/AndroidManifest.xml | 2 ++ .../androidaps/interaction/actions/AcceptActivity.java | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index 91a52878bd..e6750c515d 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -6,6 +6,8 @@ + + Date: Wed, 27 Jun 2018 20:22:19 +0200 Subject: [PATCH 7/7] remove debug clause and smaller fonts --- .../androidaps/interaction/menus/MainMenuActivity.java | 2 +- wear/src/main/res/layout/action_confirm_text.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java index 3ebaef23fe..0692f273fb 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java @@ -35,7 +35,7 @@ public class MainMenuActivity extends MenuListActivity { protected String[] getElements() { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - if(false && !sharedPreferences.getBoolean("wearcontrol", false)){ + if(!sharedPreferences.getBoolean("wearcontrol", false)){ return new String[] { "Settings", "Re-Sync"}; diff --git a/wear/src/main/res/layout/action_confirm_text.xml b/wear/src/main/res/layout/action_confirm_text.xml index 18c8933470..291b05116d 100644 --- a/wear/src/main/res/layout/action_confirm_text.xml +++ b/wear/src/main/res/layout/action_confirm_text.xml @@ -23,14 +23,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:text="title" - android:textAppearance="@style/TextAppearance.Wearable.Large" + android:textAppearance="@style/TextAppearance.Wearable.Medium" android:textColor="@color/white" />