From dc476a660034b2059be980bc0072d74f6365d2f1 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 9 Feb 2017 17:40:26 +0100 Subject: [PATCH] wear menu restructuring and status --- .../plugins/Wear/ActionStringHandler.java | 22 ++++++ wear/src/main/AndroidManifest.xml | 17 ++--- .../info/nightscout/androidaps/BIGChart.java | 4 +- .../androidaps/CircleWatchface.java | 4 +- .../java/info/nightscout/androidaps/Home.java | 4 +- .../info/nightscout/androidaps/LargeHome.java | 4 +- .../actions/ActionsDefinitions.java | 67 ------------------- .../androidaps/actions/FillMenuActivity.java | 39 +++++++++++ .../androidaps/actions/MainMenuActivity.java | 60 +++++++++++++++++ .../actions/StatusMenuActivity.java | 39 +++++++++++ .../MenuListActivity.java} | 12 ++-- 11 files changed, 185 insertions(+), 87 deletions(-) delete mode 100644 wear/src/main/java/info/nightscout/androidaps/actions/ActionsDefinitions.java create mode 100644 wear/src/main/java/info/nightscout/androidaps/actions/FillMenuActivity.java create mode 100644 wear/src/main/java/info/nightscout/androidaps/actions/MainMenuActivity.java create mode 100644 wear/src/main/java/info/nightscout/androidaps/actions/StatusMenuActivity.java rename wear/src/main/java/info/nightscout/androidaps/actions/{ActionsListActivity.java => utils/MenuListActivity.java} (92%) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index bc6f470229..56afc45f0c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -57,6 +57,7 @@ public class ActionStringHandler { String[] act = actionstring.split("\\s+"); if ("fillpreset".equals(act[0])) { + ///////////////////////////////////// PRIME/FILL double amount = 0d; if ("1".equals(act[1])) { amount = SafeParse.stringToDouble(DecimalFormatter.to2Decimal(SafeParse.stringToDouble(sp.getString("fill_button1", "0.3")))); @@ -74,6 +75,27 @@ public class ActionStringHandler { rAction += "fill " + insulinAfterConstraints; + } else if ("status".equals(act[0])) { + ///////////////////////////////////// STATUS + rTitle = "STATUS"; + rAction = "statusmessage"; + //TODO: add meaningfull status + + if("general".equals(act[1])){ + rMessage = "Today is going to be a good day!"; + } else if("pump".equals(act[1])){ + rTitle += " PUMP"; + rMessage = "I'm feeling pumped!"; + } else if("loop".equals(act[1])){ + rTitle += " LOOP"; + rMessage = "A loop di loop di loop!"; + + } else if("targets".equals(act[1])){ + rTitle += " TARGETS"; + rMessage = "Always on target!"; + } + rMessage += "\n\n\nTODO:\nAdd some meaningful status."; + } else if ("wizard".equals(act[0])) { Integer carbsBeforeConstraints = SafeParse.stringToInt(act[1]); Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(carbsBeforeConstraints); diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index a530067e91..b8856d4818 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -99,27 +99,28 @@ android:label="@string/label_xdrip_activity"> - - - - - - - + + + + \ No newline at end of file diff --git a/wear/src/main/java/info/nightscout/androidaps/BIGChart.java b/wear/src/main/java/info/nightscout/androidaps/BIGChart.java index af69c8f546..9ead9cecfd 100644 --- a/wear/src/main/java/info/nightscout/androidaps/BIGChart.java +++ b/wear/src/main/java/info/nightscout/androidaps/BIGChart.java @@ -39,7 +39,7 @@ import com.ustwo.clockwise.common.WatchShape; import java.util.ArrayList; import java.util.Date; -import info.nightscout.androidaps.actions.ActionsListActivity; +import info.nightscout.androidaps.actions.MainMenuActivity; import lecho.lib.hellocharts.view.LineChartView; /** @@ -162,7 +162,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre y >= mSgv.getTop() && y <= mSgv.getBottom()){ if (eventTime - sgvTapTime < 800){ - Intent intent = new Intent(this, ActionsListActivity.class); + Intent intent = new Intent(this, MainMenuActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } diff --git a/wear/src/main/java/info/nightscout/androidaps/CircleWatchface.java b/wear/src/main/java/info/nightscout/androidaps/CircleWatchface.java index 968e29e7bc..6bf669283e 100644 --- a/wear/src/main/java/info/nightscout/androidaps/CircleWatchface.java +++ b/wear/src/main/java/info/nightscout/androidaps/CircleWatchface.java @@ -36,7 +36,7 @@ import java.util.Date; import java.util.HashSet; import java.util.TreeSet; -import info.nightscout.androidaps.actions.ActionsListActivity; +import info.nightscout.androidaps.actions.MainMenuActivity; public class CircleWatchface extends WatchFace implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -717,7 +717,7 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh y >= mSgv.getTop() && y <= mSgv.getBottom()){ if (eventTime - sgvTapTime < 800){ - Intent intent = new Intent(this, ActionsListActivity.class); + Intent intent = new Intent(this, MainMenuActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } diff --git a/wear/src/main/java/info/nightscout/androidaps/Home.java b/wear/src/main/java/info/nightscout/androidaps/Home.java index 45803e8b47..2d73ef0661 100644 --- a/wear/src/main/java/info/nightscout/androidaps/Home.java +++ b/wear/src/main/java/info/nightscout/androidaps/Home.java @@ -8,7 +8,7 @@ import android.view.LayoutInflater; import com.ustwo.clockwise.common.WatchMode; -import info.nightscout.androidaps.actions.ActionsListActivity; +import info.nightscout.androidaps.actions.MainMenuActivity; public class Home extends BaseWatchFace { @@ -43,7 +43,7 @@ public class Home extends BaseWatchFace { y >= mSgv.getTop() && y <= mSgv.getBottom()){ if (eventTime - sgvTapTime < 800){ - Intent intent = new Intent(this, ActionsListActivity.class); + Intent intent = new Intent(this, MainMenuActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } diff --git a/wear/src/main/java/info/nightscout/androidaps/LargeHome.java b/wear/src/main/java/info/nightscout/androidaps/LargeHome.java index b3a342f2d8..ecb0735af3 100644 --- a/wear/src/main/java/info/nightscout/androidaps/LargeHome.java +++ b/wear/src/main/java/info/nightscout/androidaps/LargeHome.java @@ -8,7 +8,7 @@ import android.view.LayoutInflater; import com.ustwo.clockwise.common.WatchMode; -import info.nightscout.androidaps.actions.ActionsListActivity; +import info.nightscout.androidaps.actions.MainMenuActivity; public class LargeHome extends BaseWatchFace { @@ -33,7 +33,7 @@ public class LargeHome extends BaseWatchFace { y >= mSgv.getTop() && y <= mSgv.getBottom()){ if (eventTime - sgvTapTime < 800){ - Intent intent = new Intent(this, ActionsListActivity.class); + Intent intent = new Intent(this, MainMenuActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } diff --git a/wear/src/main/java/info/nightscout/androidaps/actions/ActionsDefinitions.java b/wear/src/main/java/info/nightscout/androidaps/actions/ActionsDefinitions.java deleted file mode 100644 index 7b814bf48d..0000000000 --- a/wear/src/main/java/info/nightscout/androidaps/actions/ActionsDefinitions.java +++ /dev/null @@ -1,67 +0,0 @@ -package info.nightscout.androidaps.actions; - -import android.content.Context; -import android.content.Intent; - -import info.nightscout.androidaps.ListenerService; -import info.nightscout.androidaps.NWPreferences; -import info.nightscout.androidaps.actions.wizard.WizardActivity; - -/** - * Created by adrian on 08/02/17. - */ - -final class ActionsDefinitions { - - private static final String[] ACTION_NAMES = { - "Temp Target", - "Wizard", - "Settings", - "Resend Data", - "Fillpreset 1", - "Fillpreset 2", - "Fillpreset 3", - "009"}; - - - public static void doAction(int position, Context ctx) { - - Intent intent; - switch (position) { - case 0: - break; - case 1: - intent = new Intent(ctx, WizardActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - ctx.startActivity(intent); - break; - case 2: - intent = new Intent(ctx, NWPreferences.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - ctx.startActivity(intent); - break; - case 3: - ListenerService.requestData(ctx); - break; - case 4: - ListenerService.initiateAction(ctx, "fillpreset 1"); - break; - case 5: - ListenerService.initiateAction(ctx, "fillpreset 2"); - break; - case 6: - ListenerService.initiateAction(ctx, "fillpreset 3"); - break; - case 7: - break; - } - - } - - - public static String[] getActionNames() { - //posibility for later i18n - return ACTION_NAMES; - } - -} diff --git a/wear/src/main/java/info/nightscout/androidaps/actions/FillMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/actions/FillMenuActivity.java new file mode 100644 index 0000000000..b1ee084ec7 --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/actions/FillMenuActivity.java @@ -0,0 +1,39 @@ +package info.nightscout.androidaps.actions; + +import android.content.Intent; + +import info.nightscout.androidaps.ListenerService; +import info.nightscout.androidaps.NWPreferences; +import info.nightscout.androidaps.actions.utils.MenuListActivity; +import info.nightscout.androidaps.actions.wizard.WizardActivity; + +/** + * Created by adrian on 09/02/17. + */ + +public class FillMenuActivity extends MenuListActivity { + + @Override + protected String[] getElements() { + return new String[] { + "Preset 1", + "Preset 2", + "Preset 3"}; + } + + @Override + protected void doAction(int position) { + switch (position) { + case 0: + ListenerService.initiateAction(this, "fillpreset 1"); + break; + case 1: + ListenerService.initiateAction(this, "fillpreset 2"); + break; + case 2: + ListenerService.initiateAction(this, "fillpreset 3"); + break; + } + + } +} diff --git a/wear/src/main/java/info/nightscout/androidaps/actions/MainMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/actions/MainMenuActivity.java new file mode 100644 index 0000000000..ab73ad769b --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/actions/MainMenuActivity.java @@ -0,0 +1,60 @@ +package info.nightscout.androidaps.actions; + +import android.content.Intent; + +import info.nightscout.androidaps.ListenerService; +import info.nightscout.androidaps.NWPreferences; +import info.nightscout.androidaps.actions.utils.MenuListActivity; +import info.nightscout.androidaps.actions.wizard.WizardActivity; + +/** + * Created by adrian on 09/02/17. + */ + +public class MainMenuActivity extends MenuListActivity { + + @Override + protected String[] getElements() { + return new String[] { + "TTarget", + "Wizard", + "Settings", + "Re-Sync", + "Status", + "Prime/Fill"}; + } + + @Override + protected void doAction(int position) { + + Intent intent; + switch (position) { + case 0: + break; + case 1: + intent = new Intent(this, WizardActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + this.startActivity(intent); + break; + case 2: + intent = new Intent(this, NWPreferences.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + this.startActivity(intent); + break; + case 3: + ListenerService.requestData(this); + break; + case 4: + intent = new Intent(this, StatusMenuActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + this.startActivity(intent); + break; + case 5: + intent = new Intent(this, FillMenuActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + this.startActivity(intent); + break; + } + + } +} diff --git a/wear/src/main/java/info/nightscout/androidaps/actions/StatusMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/actions/StatusMenuActivity.java new file mode 100644 index 0000000000..fa18b3f2d8 --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/actions/StatusMenuActivity.java @@ -0,0 +1,39 @@ +package info.nightscout.androidaps.actions; + +import info.nightscout.androidaps.ListenerService; +import info.nightscout.androidaps.actions.utils.MenuListActivity; + +/** + * Created by adrian on 09/02/17. + */ + +public class StatusMenuActivity extends MenuListActivity { + + @Override + protected String[] getElements() { + return new String[] { + "General", + "Pump", + "Loop", + "Targets"}; + } + + @Override + protected void doAction(int position) { + switch (position) { + case 0: + ListenerService.initiateAction(this, "status general"); + break; + case 1: + ListenerService.initiateAction(this, "status pump"); + break; + case 2: + ListenerService.initiateAction(this, "status loop"); + break; + case 3: + ListenerService.initiateAction(this, "status targets"); + break; + } + + } +} diff --git a/wear/src/main/java/info/nightscout/androidaps/actions/ActionsListActivity.java b/wear/src/main/java/info/nightscout/androidaps/actions/utils/MenuListActivity.java similarity index 92% rename from wear/src/main/java/info/nightscout/androidaps/actions/ActionsListActivity.java rename to wear/src/main/java/info/nightscout/androidaps/actions/utils/MenuListActivity.java index f1202797d4..21898e155d 100644 --- a/wear/src/main/java/info/nightscout/androidaps/actions/ActionsListActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/actions/utils/MenuListActivity.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.actions; +package info.nightscout.androidaps.actions.utils; import android.app.Activity; import android.content.Context; @@ -15,10 +15,14 @@ import info.nightscout.androidaps.R; * Created by adrian on 08/02/17. */ -public class ActionsListActivity extends Activity +public abstract class MenuListActivity extends Activity implements WearableListView.ClickListener { - String[] elements = ActionsDefinitions.getActionNames(); + String[] elements = getElements(); + + protected abstract String[] getElements(); + + protected abstract void doAction(int position); @Override protected void onCreate(Bundle savedInstanceState) { @@ -40,7 +44,7 @@ public class ActionsListActivity extends Activity @Override public void onClick(WearableListView.ViewHolder v) { Integer tag = (Integer) v.itemView.getTag(); - ActionsDefinitions.doAction(tag, this); + doAction(tag); //ActionsDefinitions.doAction(v.getAdapterPosition(), this); finish(); }