From eb96cf6713f6225c67f002bc72360e4eff0b9b7d Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 9 Feb 2017 21:40:00 +0100 Subject: [PATCH] wear temp target activity --- wear/src/main/AndroidManifest.xml | 12 +- .../androidaps/data/ListenerService.java | 4 +- ...WPreferences.java => AAPSPreferences.java} | 8 +- .../interaction/actions/FillActivity.java | 108 +++++++++++++ .../actions/TempTargetActivity.java | 149 ++++++++++++++++++ .../interaction/menus/FillMenuActivity.java | 12 +- .../interaction/menus/MainMenuActivity.java | 8 +- .../interaction/utils/MenuListActivity.java | 6 + 8 files changed, 299 insertions(+), 8 deletions(-) rename wear/src/main/java/info/nightscout/androidaps/interaction/{NWPreferences.java => AAPSPreferences.java} (71%) create mode 100644 wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.java create mode 100644 wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.java diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index 283e78e897..8909f8a3f8 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -103,8 +103,8 @@ + android:name=".interaction.AAPSPreferences" + android:label="SETTINGS"> + + + + \ No newline at end of file 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 7ed19e513e..d16f0d4324 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -24,7 +24,7 @@ import com.google.android.gms.wearable.WearableListenerService; import java.util.concurrent.TimeUnit; -import info.nightscout.androidaps.interaction.NWPreferences; +import info.nightscout.androidaps.interaction.AAPSPreferences; import info.nightscout.androidaps.R; /** @@ -227,7 +227,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp String path = event.getDataItem().getUri().getPath(); if (path.equals(OPEN_SETTINGS)) { - Intent intent = new Intent(this, NWPreferences.class); + Intent intent = new Intent(this, AAPSPreferences.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } else if (path.equals(BOLUS_PROGRESS_PATH)) { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/NWPreferences.java b/wear/src/main/java/info/nightscout/androidaps/interaction/AAPSPreferences.java similarity index 71% rename from wear/src/main/java/info/nightscout/androidaps/interaction/NWPreferences.java rename to wear/src/main/java/info/nightscout/androidaps/interaction/AAPSPreferences.java index 40f7b08c8f..6142937206 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/NWPreferences.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/AAPSPreferences.java @@ -7,7 +7,7 @@ import android.preference.PreferenceActivity; import info.nightscout.androidaps.R; import preference.WearPreferenceActivity; -public class NWPreferences extends WearPreferenceActivity { +public class AAPSPreferences extends WearPreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { @@ -15,4 +15,10 @@ public class NWPreferences extends WearPreferenceActivity { addPreferencesFromResource(R.xml.preferences); } + @Override + protected void onPause(){ + super.onPause(); + finish(); + } + } \ No newline at end of file diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.java new file mode 100644 index 0000000000..9f88cc318d --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.java @@ -0,0 +1,108 @@ +package info.nightscout.androidaps.interaction.actions; + + +import android.app.Activity; +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 FillActivity extends Activity { + + PlusMinusEditText editInsulin; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + 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 3; + } + + @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_editplusminus_item, container, false); + final TextView textView = (TextView) view.findViewById(R.id.label); + textView.setText("insulin"); + editInsulin = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 0d, 0d, 30d, 0.1d, new DecimalFormat("#0.0"), false); + 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) { + + //check if it can happen that the fagment is never created that hold data? + // (you have to swipe past them anyways - but still) + + String actionstring = "fill " +SafeParse.stringToDouble(editInsulin.editText.getText().toString()); + ListenerService.initiateAction(FillActivity.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/actions/TempTargetActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.java new file mode 100644 index 0000000000..5598893eaf --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.java @@ -0,0 +1,149 @@ +package info.nightscout.androidaps.interaction.actions; + + +import android.app.Activity; +import android.content.SharedPreferences; +import android.content.res.Resources; +import android.os.Bundle; +import android.preference.PreferenceManager; +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; + +import static android.preference.PreferenceManager.getDefaultSharedPreferences; + +/** + * Created by adrian on 09/02/17. + */ + + +public class TempTargetActivity extends Activity { + + PlusMinusEditText lowRange; + PlusMinusEditText highRange; + PlusMinusEditText time; + boolean isMGDL; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + 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); + + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); + isMGDL = sp.getBoolean("units_mgdl", true); + } + + + @Override + protected void onPause() { + super.onPause(); + finish(); + } + + + private class MyGridViewPagerAdapter extends GridPagerAdapter { + @Override + public int getColumnCount(int arg0) { + return 4; + } + + @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_editplusminus_item, container, false); + final TextView textView = (TextView) view.findViewById(R.id.label); + textView.setText("duration"); + time = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 0d, 0d, 24*60d, 1d, new DecimalFormat("0"), false); + container.addView(view); + return view; + + } else if(col == 1){ + final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_editplusminus_item, container, false); + final TextView textView = (TextView) view.findViewById(R.id.label); + textView.setText("low"); + if (isMGDL){ + lowRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 100d, 72d, 180d, 1d, new DecimalFormat("0"), false); + } else { + lowRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 5.5, 4d, 10d, 0.1d, new DecimalFormat("#0.0"), false); + } + + container.addView(view); + return view; + } else if(col == 2){ + final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_editplusminus_item, container, false); + final TextView textView = (TextView) view.findViewById(R.id.label); + textView.setText("high"); + if (isMGDL){ + highRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 100d, 72d, 180d, 1d, new DecimalFormat("0"), false); + } else { + highRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 5.5, 4d, 10d, 0.1d, new DecimalFormat("#0.0"), false); + } + + 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) { + + //check if it can happen that the fagment is never created that hold data? + // (you have to swipe past them anyways - but still) + + String actionstring = "temptarget " + + SafeParse.stringToInt(time.editText.getText().toString()) + + " " + isMGDL + + " " + SafeParse.stringToDouble(lowRange.editText.getText().toString()) + + " " + SafeParse.stringToDouble(highRange.editText.getText().toString()) + ; + + ListenerService.initiateAction(TempTargetActivity.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/FillMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.java index fddefda3d3..da8daa80cb 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.java @@ -1,6 +1,9 @@ package info.nightscout.androidaps.interaction.menus; +import android.content.Intent; + import info.nightscout.androidaps.data.ListenerService; +import info.nightscout.androidaps.interaction.actions.FillActivity; import info.nightscout.androidaps.interaction.utils.MenuListActivity; /** @@ -14,7 +17,9 @@ public class FillMenuActivity extends MenuListActivity { return new String[] { "Preset 1", "Preset 2", - "Preset 3"}; + "Preset 3", + "Free amount" + }; } @Override @@ -29,6 +34,11 @@ public class FillMenuActivity extends MenuListActivity { case 2: ListenerService.initiateAction(this, "fillpreset 3"); break; + case 3: + Intent intent = new Intent(this, FillActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + this.startActivity(intent); + break; } } 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 ff3d7348f4..a6ef6666db 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 @@ -3,8 +3,9 @@ package info.nightscout.androidaps.interaction.menus; import android.content.Intent; import info.nightscout.androidaps.data.ListenerService; -import info.nightscout.androidaps.interaction.NWPreferences; +import info.nightscout.androidaps.interaction.AAPSPreferences; import info.nightscout.androidaps.interaction.actions.BolusActivity; +import info.nightscout.androidaps.interaction.actions.TempTargetActivity; import info.nightscout.androidaps.interaction.utils.MenuListActivity; import info.nightscout.androidaps.interaction.actions.WizardActivity; @@ -32,6 +33,9 @@ public class MainMenuActivity extends MenuListActivity { Intent intent; switch (position) { case 0: + intent = new Intent(this, TempTargetActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + this.startActivity(intent); break; case 1: intent = new Intent(this, BolusActivity.class); @@ -44,7 +48,7 @@ public class MainMenuActivity extends MenuListActivity { this.startActivity(intent); break; case 3: - intent = new Intent(this, NWPreferences.class); + intent = new Intent(this, AAPSPreferences.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); break; diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/MenuListActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/MenuListActivity.java index 6855505c0a..681ceb134a 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/MenuListActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/MenuListActivity.java @@ -24,6 +24,12 @@ public abstract class MenuListActivity extends Activity protected abstract void doAction(int position); + @Override + protected void onPause(){ + super.onPause(); + finish(); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);