diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/AAPSPreferences.java b/wear/src/main/java/info/nightscout/androidaps/interaction/AAPSPreferences.java index 39dda741fd..ccdaeff7dc 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/AAPSPreferences.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/AAPSPreferences.java @@ -17,6 +17,7 @@ public class AAPSPreferences extends WearPreferenceActivity { ViewGroup view = (ViewGroup)getWindow().getDecorView(); removeBackgroundRecursively(view); view.setBackground(getResources().getDrawable(R.drawable.settings_background)); + view.requestFocus(); } @Override diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/ConfigurationActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/ConfigurationActivity.java index d1d8d71cc5..8348dfcb22 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/ConfigurationActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/ConfigurationActivity.java @@ -22,6 +22,7 @@ public class ConfigurationActivity extends WearPreferenceActivity { ViewGroup view = (ViewGroup) getWindow().getDecorView(); removeBackgroundRecursively(view); view.setBackground(getResources().getDrawable(R.drawable.settings_background)); + view.requestFocus(); } @Override 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 6a5b9b5f9a..91cffa4b3e 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 @@ -50,9 +50,8 @@ public class AcceptActivity extends ViewSelectorActivity { } setContentView(R.layout.grid_layout); - final Resources res = getResources(); - final GridViewPager pager = findViewById(R.id.pager); + final GridViewPager pager = findViewById(R.id.pager); pager.setAdapter(new MyGridViewPagerAdapter()); DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator); dotsPageIndicator.setPager(pager); @@ -99,7 +98,7 @@ public class AcceptActivity extends ViewSelectorActivity { @Override public void onClick(View v) { ListenerService.confirmAction(AcceptActivity.this, actionstring); - finish(); + finishAffinity(); } }); container.addView(view); diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.java index dad9a46df9..6faec96119 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.java @@ -10,6 +10,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.TextView; import java.text.DecimalFormat; @@ -32,15 +33,33 @@ public class BolusActivity extends ViewSelectorActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.grid_layout); - final Resources res = getResources(); - final GridViewPager pager = findViewById(R.id.pager); + final TextView title = findViewById(R.id.title); + title.setText(getString(R.string.menu_bolus)); + + final GridViewPager pager = findViewById(R.id.pager); pager.setAdapter(new MyGridViewPagerAdapter()); DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator); dotsPageIndicator.setPager(pager); + pager.setOnPageChangeListener(new GridViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int row, int column, float rowOffset, float columnOffset, int rowOffsetPixels, int columnOffsetPixels) { + dotsPageIndicator.onPageScrolled(row, column, rowOffset, columnOffset, rowOffsetPixels, + columnOffsetPixels); + } + @Override + public void onPageSelected(int row, int column) { + dotsPageIndicator.onPageSelected(row, column); + View view = pager.getChildAt(column); + view.requestFocus(); + } + @Override + public void onPageScrollStateChanged(int state) { + dotsPageIndicator.onPageScrollStateChanged(state); + } + }); } - @Override protected void onPause() { super.onPause(); @@ -71,6 +90,7 @@ public class BolusActivity extends ViewSelectorActivity { editInsulin = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 30d, 0.1d, new DecimalFormat("#0.0"), false); setLabelToPlusMinusView(view, getString(R.string.action_insulin)); container.addView(view); + view.requestFocus(); return view; } else if (col == 1) { final View view = getInflatedPlusMinusView(container); @@ -96,7 +116,7 @@ public class BolusActivity extends ViewSelectorActivity { String actionstring = "bolus " + SafeParse.stringToDouble(editInsulin.editText.getText().toString()) + " " + SafeParse.stringToInt(editCarbs.editText.getText().toString()); ListenerService.initiateAction(BolusActivity.this, actionstring); - finish(); + finishAffinity(); } }); container.addView(view); diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CPPActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CPPActivity.java index e47b40293c..3851843b16 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CPPActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CPPActivity.java @@ -10,6 +10,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.TextView; import java.text.DecimalFormat; @@ -47,12 +48,31 @@ public class CPPActivity extends ViewSelectorActivity { if (timeshift < 0) timeshift += 24; setContentView(R.layout.grid_layout); - final Resources res = getResources(); - final GridViewPager pager = findViewById(R.id.pager); + + final TextView title = findViewById(R.id.title); + title.setText(getString(R.string.status_cpp)); + final GridViewPager pager = findViewById(R.id.pager); pager.setAdapter(new MyGridViewPagerAdapter()); DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator); dotsPageIndicator.setPager(pager); + pager.setOnPageChangeListener(new GridViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int row, int column, float rowOffset, float columnOffset, int rowOffsetPixels, int columnOffsetPixels) { + dotsPageIndicator.onPageScrolled(row, column, rowOffset, columnOffset, rowOffsetPixels, + columnOffsetPixels); + } + @Override + public void onPageSelected(int row, int column) { + dotsPageIndicator.onPageSelected(row, column); + View view = pager.getChildAt(column); + view.requestFocus(); + } + @Override + public void onPageScrollStateChanged(int state) { + dotsPageIndicator.onPageScrollStateChanged(state); + } + }); } @@ -86,6 +106,7 @@ public class CPPActivity extends ViewSelectorActivity { editTimeshift = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 23d, 1d, new DecimalFormat("0"), true, true); setLabelToPlusMinusView(view, getString(R.string.action_timeshift)); container.addView(view); + view.requestFocus(); return view; } else if (col == 1) { final View view = getInflatedPlusMinusView(container); @@ -111,7 +132,7 @@ public class CPPActivity extends ViewSelectorActivity { String actionstring = "cppset " + SafeParse.stringToInt(editTimeshift.editText.getText().toString()) + " " + SafeParse.stringToInt(editPercentage.editText.getText().toString()); ListenerService.initiateAction(CPPActivity.this, actionstring); - finish(); + finishAffinity(); } }); container.addView(view); diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.java index 09b68ed704..1495624bac 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.java @@ -10,6 +10,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.TextView; import java.text.DecimalFormat; @@ -34,12 +35,31 @@ public class ECarbActivity extends ViewSelectorActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.grid_layout); - final Resources res = getResources(); - final GridViewPager pager = findViewById(R.id.pager); + final TextView title = findViewById(R.id.title); + title.setText(getString(R.string.menu_ecarb)); + + final GridViewPager pager = findViewById(R.id.pager); pager.setAdapter(new MyGridViewPagerAdapter()); DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator); dotsPageIndicator.setPager(pager); + pager.setOnPageChangeListener(new GridViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int row, int column, float rowOffset, float columnOffset, int rowOffsetPixels, int columnOffsetPixels) { + dotsPageIndicator.onPageScrolled(row, column, rowOffset, columnOffset, rowOffsetPixels, + columnOffsetPixels); + } + @Override + public void onPageSelected(int row, int column) { + dotsPageIndicator.onPageSelected(row, column); + View view = pager.getChildAt(column); + view.requestFocus(); + } + @Override + public void onPageScrollStateChanged(int state) { + dotsPageIndicator.onPageScrollStateChanged(state); + } + }); } @@ -73,6 +93,7 @@ public class ECarbActivity extends ViewSelectorActivity { editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 150d, 1d, new DecimalFormat("0"), true); setLabelToPlusMinusView(view, getString(R.string.action_carbs)); container.addView(view); + view.requestFocus(); return view; } else if(col == 1){ final View view = getInflatedPlusMinusView(container); @@ -109,7 +130,7 @@ public class ECarbActivity extends ViewSelectorActivity { + " " + SafeParse.stringToInt(editStartTime.editText.getText().toString()) + " " + SafeParse.stringToInt(editDuration.editText.getText().toString()); ListenerService.initiateAction(ECarbActivity.this, actionstring); - finish(); + finishAffinity(); } }); container.addView(view); 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 index 2f3770f464..b141cd053a 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.java @@ -10,6 +10,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.TextView; import java.text.DecimalFormat; @@ -31,9 +32,11 @@ public class FillActivity extends ViewSelectorActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.grid_layout); - final Resources res = getResources(); - final GridViewPager pager = findViewById(R.id.pager); + final TextView title = findViewById(R.id.title); + title.setText(getString(R.string.menu_prime_fill)); + + final GridViewPager pager = findViewById(R.id.pager); pager.setAdapter(new MyGridViewPagerAdapter()); DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator); dotsPageIndicator.setPager(pager); @@ -70,6 +73,7 @@ public class FillActivity extends ViewSelectorActivity { editInsulin = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 30d, 0.1d, new DecimalFormat("#0.0"), false); setLabelToPlusMinusView(view, getString(R.string.action_insulin)); container.addView(view); + view.requestFocus(); return view; } else { @@ -84,7 +88,7 @@ public class FillActivity extends ViewSelectorActivity { String actionstring = "fill " + SafeParse.stringToDouble(editInsulin.editText.getText().toString()); ListenerService.initiateAction(FillActivity.this, actionstring); - finish(); + finishAffinity(); } }); container.addView(view); 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 index 6bc562c139..6893b0af32 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.java @@ -38,9 +38,11 @@ public class TempTargetActivity extends ViewSelectorActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.grid_layout); - final Resources res = getResources(); - final GridViewPager pager = findViewById(R.id.pager); + final TextView title = findViewById(R.id.title); + title.setText(getString(R.string.menu_tempt)); + + final GridViewPager pager = findViewById(R.id.pager); pager.setAdapter(new MyGridViewPagerAdapter()); DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator); dotsPageIndicator.setPager(pager); @@ -48,6 +50,23 @@ public class TempTargetActivity extends ViewSelectorActivity { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); isMGDL = sp.getBoolean("units_mgdl", true); isSingleTarget = sp.getBoolean("singletarget", true); + pager.setOnPageChangeListener(new GridViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int row, int column, float rowOffset, float columnOffset, int rowOffsetPixels, int columnOffsetPixels) { + dotsPageIndicator.onPageScrolled(row, column, rowOffset, columnOffset, rowOffsetPixels, + columnOffsetPixels); + } + @Override + public void onPageSelected(int row, int column) { + dotsPageIndicator.onPageSelected(row, column); + View view = pager.getChildAt(column); + view.requestFocus(); + } + @Override + public void onPageScrollStateChanged(int state) { + dotsPageIndicator.onPageScrollStateChanged(state); + } + }); } @@ -84,6 +103,7 @@ public class TempTargetActivity extends ViewSelectorActivity { } setLabelToPlusMinusView(view, getString(R.string.action_duration)); container.addView(view); + view.requestFocus(); return view; } else if (col == 1) { @@ -144,7 +164,7 @@ public class TempTargetActivity extends ViewSelectorActivity { + " " + (isSingleTarget ? SafeParse.stringToDouble(lowRange.editText.getText().toString()) : SafeParse.stringToDouble(highRange.editText.getText().toString())); ListenerService.initiateAction(TempTargetActivity.this, actionstring); - finish(); + finishAffinity(); } }); container.addView(view); diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.java index 265eec49bb..80ea09f64f 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.java @@ -12,6 +12,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.TextView; import java.text.DecimalFormat; @@ -37,14 +38,33 @@ public class WizardActivity extends ViewSelectorActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.grid_layout); - final Resources res = getResources(); - final GridViewPager pager = findViewById(R.id.pager); + final TextView title = findViewById(R.id.title); + title.setText(getString(R.string.menu_wizard)); + + final GridViewPager pager = findViewById(R.id.pager); pager.setAdapter(new MyGridViewPagerAdapter()); DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator); dotsPageIndicator.setPager(pager); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); hasPercentage = sp.getBoolean("wizardpercentage", false); + pager.setOnPageChangeListener(new GridViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int row, int column, float rowOffset, float columnOffset, int rowOffsetPixels, int columnOffsetPixels) { + dotsPageIndicator.onPageScrolled(row, column, rowOffset, columnOffset, rowOffsetPixels, + columnOffsetPixels); + } + @Override + public void onPageSelected(int row, int column) { + dotsPageIndicator.onPageSelected(row, column); + View view = pager.getChildAt(column); + view.requestFocus(); + } + @Override + public void onPageScrollStateChanged(int state) { + dotsPageIndicator.onPageScrollStateChanged(state); + } + }); } @@ -80,6 +100,7 @@ public class WizardActivity extends ViewSelectorActivity { } setLabelToPlusMinusView(view, getString(R.string.action_carbs)); container.addView(view); + view.requestFocus(); return view; } else if (col == 1 && hasPercentage) { final View view = getInflatedPlusMinusView(container); @@ -111,7 +132,7 @@ public class WizardActivity extends ViewSelectorActivity { String actionstring = "wizard2 " + SafeParse.stringToInt(editCarbs.editText.getText().toString()) + " " + percentage; ListenerService.initiateAction(WizardActivity.this, actionstring); - finish(); + finishAffinity(); } }); container.addView(view); 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 68368e4b48..92f557268f 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,10 @@ package info.nightscout.androidaps.interaction.menus; import android.content.Intent; +import android.os.Bundle; + +import java.util.ArrayList; +import java.util.List; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ListenerService; @@ -14,13 +18,20 @@ import info.nightscout.androidaps.interaction.utils.MenuListActivity; public class FillMenuActivity extends MenuListActivity { @Override - protected String[] getElements() { - return new String[]{ - getString(R.string.action_preset_1), - getString(R.string.action_preset_2), - getString(R.string.action_preset_3), - getString(R.string.action_free_amount) - }; + protected void onCreate(Bundle savedInstanceState) { + setTitle(R.string.menu_prime_fill); + super.onCreate(savedInstanceState); + } + + @Override + protected List getElements() { + List menuItems = new ArrayList<>(); + menuItems.add(new MenuItem(R.drawable.ic_canula, getString(R.string.action_preset_1))); + menuItems.add(new MenuItem(R.drawable.ic_canula, getString(R.string.action_preset_2))); + menuItems.add(new MenuItem(R.drawable.ic_canula, getString(R.string.action_preset_3))); + menuItems.add(new MenuItem(R.drawable.ic_canula, getString(R.string.action_free_amount))); + + return menuItems; } @Override 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 f72887b54e..b0180cf017 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 @@ -5,7 +5,8 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import java.util.Vector; +import java.util.ArrayList; +import java.util.List; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ListenerService; @@ -27,34 +28,35 @@ public class MainMenuActivity extends MenuListActivity { @Override protected void onCreate(Bundle savedInstanceState) { sp = PreferenceManager.getDefaultSharedPreferences(this); + setTitle(R.string.label_actions_activity); super.onCreate(savedInstanceState); ListenerService.requestData(this); } @Override - protected String[] getElements() { - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); + protected List getElements() { - if (!sharedPreferences.getBoolean("wearcontrol", false)) { - return new String[]{ - getString(R.string.menu_settings), - getString(R.string.menu_resync)}; + List menuItems = new ArrayList<>(); + if (!sp.getBoolean("wearcontrol", false)) { + menuItems.add(new MenuItem(R.drawable.ic_settings, getString(R.string.menu_settings))); + menuItems.add(new MenuItem(R.drawable.ic_sync, getString(R.string.menu_resync))); + + return menuItems; } boolean showPrimeFill = sp.getBoolean("primefill", false); boolean showWizard = sp.getBoolean("showWizard", true); - Vector menuitems = new Vector(); - menuitems.add(getString(R.string.menu_tempt)); - if (showWizard) menuitems.add(getString(R.string.menu_wizard)); - menuitems.add(getString(R.string.menu_ecarb)); - menuitems.add(getString(R.string.menu_bolus)); - menuitems.add(getString(R.string.menu_settings)); - menuitems.add(getString(R.string.menu_status)); - if (showPrimeFill) menuitems.add(getString(R.string.menu_prime_fill)); + if (showWizard) menuItems.add(new MenuItem(R.drawable.ic_calculator, getString(R.string.menu_wizard))); + menuItems.add(new MenuItem(R.drawable.ic_e_carbs, getString(R.string.menu_ecarb))); + menuItems.add(new MenuItem(R.drawable.ic_bolus, getString(R.string.menu_bolus))); + menuItems.add(new MenuItem(R.drawable.ic_temptarget, getString(R.string.menu_tempt))); + menuItems.add(new MenuItem(R.drawable.ic_settings, getString(R.string.menu_settings))); + menuItems.add(new MenuItem(R.drawable.ic_status, getString(R.string.menu_status))); + if (showPrimeFill) menuItems.add(new MenuItem(R.drawable.ic_canula, getString(R.string.menu_prime_fill))); - return menuitems.toArray(new String[menuitems.size()]); + return menuItems; } @Override diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.java index 1133392a9a..8861e45ed6 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.java @@ -1,5 +1,10 @@ package info.nightscout.androidaps.interaction.menus; +import android.os.Bundle; + +import java.util.ArrayList; +import java.util.List; + import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.interaction.utils.MenuListActivity; @@ -11,14 +16,20 @@ import info.nightscout.androidaps.interaction.utils.MenuListActivity; public class StatusMenuActivity extends MenuListActivity { @Override - protected String[] getElements() { - return new String[] { - getString(R.string.status_pump), - getString(R.string.status_loop), - getString(R.string.status_cpp), - getString(R.string.status_tdd)}; + protected void onCreate(Bundle savedInstanceState) { + setTitle(R.string.menu_status); + super.onCreate(savedInstanceState); + } + @Override + protected List getElements() { + List menuitems = new ArrayList<>(); + menuitems.add(new MenuItem(R.drawable.ic_status, getString(R.string.status_pump))); + menuitems.add(new MenuItem(R.drawable.ic_loop_closed, getString(R.string.status_loop))); + menuitems.add(new MenuItem(R.drawable.ic_status, getString(R.string.status_cpp))); + menuitems.add(new MenuItem(R.drawable.ic_tdd, getString(R.string.status_tdd))); + return menuitems; } @Override 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 af606db583..c9184a61f0 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 @@ -1,120 +1,133 @@ package info.nightscout.androidaps.interaction.utils; import android.app.Activity; -import android.content.Context; import android.os.Bundle; -import android.support.wearable.view.WearableListView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.TextView; +import androidx.recyclerview.widget.RecyclerView; +import androidx.wear.widget.WearableLinearLayoutManager; +import androidx.wear.widget.WearableRecyclerView; + +import java.util.List; + import info.nightscout.androidaps.R; /** * Created by adrian on 08/02/17. */ -public abstract class MenuListActivity extends Activity - implements WearableListView.ClickListener { - - String[] elements; - - protected abstract String[] getElements(); - +public abstract class MenuListActivity extends Activity { + List elements; + protected abstract List getElements(); protected abstract void doAction(String position); - @Override - protected void onPause(){ - super.onPause(); - finish(); + public interface AdapterCallback{ + void onItemClicked(MenuAdapter.ItemViewHolder v); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - elements = getElements(); setContentView(R.layout.actions_list_activity); + TextView titleView = findViewById(R.id.title); + titleView.setText(getTitle()); - // Get the list component from the layout of the activity - WearableListView listView = - findViewById(R.id.wearable_list); - - // Assign an adapter to the list - listView.setAdapter(new Adapter(this, elements)); - - // Set a click listener - listView.setClickListener(this); + elements = getElements(); + CustomScrollingLayoutCallback customScrollingLayoutCallback = new CustomScrollingLayoutCallback(); + WearableLinearLayoutManager layoutManager = new WearableLinearLayoutManager(this); + if (this.getResources().getConfiguration().isScreenRound()) { + layoutManager.setLayoutCallback(customScrollingLayoutCallback); + } + WearableRecyclerView listView = findViewById(R.id.action_list); + listView.setHasFixedSize(true); + listView.setEdgeItemsCenteringEnabled(true); + listView.setLayoutManager(layoutManager); + listView.setAdapter(new MenuAdapter(elements, v -> { + String tag = (String) v.itemView.getTag(); + doAction(tag); + })); } - // WearableListView click listener - @Override - public void onClick(WearableListView.ViewHolder v) { - String tag = (String) v.itemView.getTag(); - doAction(tag); - //ActionsDefinitions.doAction(v.getAdapterPosition(), this); - finish(); - } + private class MenuAdapter extends RecyclerView.Adapter { + private final List mDataset; + private AdapterCallback callback; - @Override - public void onTopEmptyRegionClick() { - } - - - private static final class Adapter extends WearableListView.Adapter { - private final String[] mDataset; - private final Context mContext; - private final LayoutInflater mInflater; - - // Provide a suitable constructor (depends on the kind of dataset) - public Adapter(Context context, String[] dataset) { - mContext = context; - mInflater = LayoutInflater.from(context); + public MenuAdapter(List dataset, AdapterCallback callback) { mDataset = dataset; + this.callback = callback; } - // Provide a reference to the type of views you're using - public static class ItemViewHolder extends WearableListView.ViewHolder { - private final TextView textView; + public class ItemViewHolder extends RecyclerView.ViewHolder { + protected final RelativeLayout menuContainer; + protected final TextView actionItem; + protected final ImageView actionIcon; public ItemViewHolder(View itemView) { super(itemView); - // find the text view within the custom item's layout - textView = itemView.findViewById(R.id.actionitem); + menuContainer = itemView.findViewById(R.id.menu_container); + actionItem = itemView.findViewById(R.id.menuItemText); + actionIcon = itemView.findViewById(R.id.menuItemIcon); } } - // Create new views for list items - // (invoked by the WearableListView's layout manager) @Override - public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent, - int viewType) { - // Inflate our custom layout for list items - return new ItemViewHolder(mInflater.inflate(R.layout.list_item, null)); + public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false); + ItemViewHolder recyclerViewHolder = new ItemViewHolder(view); + + return recyclerViewHolder; } - // Replace the contents of a list item - // Instead of creating new views, the list tries to recycle existing ones - // (invoked by the WearableListView's layout manager) @Override - public void onBindViewHolder(WearableListView.ViewHolder holder, - int position) { - // retrieve the text view - ItemViewHolder itemHolder = (ItemViewHolder) holder; - TextView view = itemHolder.textView; - // replace text contents - view.setText(mDataset[position]); - // replace list item's metadata - holder.itemView.setTag(mDataset[position]); + public void onBindViewHolder(ItemViewHolder holder, final int position) { + MenuItem item = mDataset.get(position); + holder.actionItem.setText(item.actionItem); + holder.actionIcon.setImageResource(item.actionIcon); + holder.itemView.setTag(item.actionItem); + holder.menuContainer.setOnClickListener(v -> { + callback.onItemClicked(holder); + }); } - // Return the size of your dataset - // (invoked by the WearableListView's layout manager) @Override public int getItemCount() { - return mDataset.length; + return mDataset.size(); } } + protected class MenuItem { + public MenuItem(int actionIcon, String actionItem) { + this.actionIcon = actionIcon; + this.actionItem = actionItem; + } + public int actionIcon; + public String actionItem; + } -} \ No newline at end of file + public class CustomScrollingLayoutCallback extends WearableLinearLayoutManager.LayoutCallback { + // How much should we scale the icon at most. + private static final float MAX_ICON_PROGRESS = 0.65f; + private float progressToCenter; + + @Override + public void onLayoutFinished(View child, RecyclerView parent) { + // Figure out % progress from top to bottom + float centerOffset = ((float) child.getHeight() / 2.0f) / (float) parent.getHeight(); + float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset; + + // Normalize for center + progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset); + // Adjust to the maximum scale + progressToCenter = Math.min(progressToCenter, MAX_ICON_PROGRESS); + + child.setScaleX(1 - progressToCenter); + child.setScaleY(1 - progressToCenter); + } + } + +} diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.java b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.java index f6c4046488..54780c83ac 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.interaction.utils; import android.os.Handler; import android.os.Looper; import android.os.Message; +import android.support.wearable.input.RotaryEncoder; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; @@ -19,7 +20,7 @@ import java.util.concurrent.TimeUnit; * Created by mike on 28.06.2016. */ public class PlusMinusEditText implements View.OnKeyListener, - View.OnTouchListener, View.OnClickListener { + View.OnTouchListener, View.OnClickListener, View.OnGenericMotionListener { Integer editTextID; public TextView editText; @@ -104,6 +105,7 @@ public class PlusMinusEditText implements View.OnKeyListener, plusImage.setOnTouchListener(this); plusImage.setOnKeyListener(this); plusImage.setOnClickListener(this); + editText.setOnGenericMotionListener(this); updateEditText(); } @@ -207,4 +209,18 @@ public class PlusMinusEditText implements View.OnKeyListener, return false; } + @Override + public boolean onGenericMotion(View v, MotionEvent ev) { + if (ev.getAction() == MotionEvent.ACTION_SCROLL && RotaryEncoder.isFromRotaryEncoder(ev)) { + float delta = -RotaryEncoder.getRotaryAxisValue(ev); + if (delta > 0) { + inc(1); + } else { + dec(1); + } + return true; + } + return false; + } + } diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearableListItemLayout.java b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearableListItemLayout.java deleted file mode 100644 index d135536e22..0000000000 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearableListItemLayout.java +++ /dev/null @@ -1,54 +0,0 @@ -package info.nightscout.androidaps.interaction.utils; - -import android.content.Context; -import android.support.wearable.view.WearableListView; -import android.util.AttributeSet; -import android.widget.LinearLayout; -import android.widget.TextView; - -import info.nightscout.androidaps.R; - -/** - * Created by adrian on 08/02/17. - */ - -public class WearableListItemLayout extends LinearLayout - implements WearableListView.OnCenterProximityListener { - - //private ImageView mCircle; - private TextView mName; - - private final float mFadedTextAlpha; - - public WearableListItemLayout(Context context) { - this(context, null); - } - - public WearableListItemLayout(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public WearableListItemLayout(Context context, AttributeSet attrs, - int defStyle) { - super(context, attrs, defStyle); - - mFadedTextAlpha = 40 / 100f; - } - - // Get references to the icon and text in the item layout definition - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - mName = findViewById(R.id.actionitem); - } - - @Override - public void onCenterPosition(boolean animate) { - mName.setAlpha(1f); - } - - @Override - public void onNonCenterPosition(boolean animate) { - mName.setAlpha(mFadedTextAlpha); - } -} diff --git a/wear/src/main/res/drawable/ic_bolus.xml b/wear/src/main/res/drawable/ic_bolus.xml new file mode 100644 index 0000000000..1daf871f0c --- /dev/null +++ b/wear/src/main/res/drawable/ic_bolus.xml @@ -0,0 +1,13 @@ + + + + diff --git a/wear/src/main/res/drawable/ic_calculator.xml b/wear/src/main/res/drawable/ic_calculator.xml new file mode 100644 index 0000000000..a147eaac56 --- /dev/null +++ b/wear/src/main/res/drawable/ic_calculator.xml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/wear/src/main/res/drawable/ic_canula.xml b/wear/src/main/res/drawable/ic_canula.xml new file mode 100644 index 0000000000..29e1e43d9b --- /dev/null +++ b/wear/src/main/res/drawable/ic_canula.xml @@ -0,0 +1,12 @@ + + + + diff --git a/wear/src/main/res/drawable/ic_e_carbs.xml b/wear/src/main/res/drawable/ic_e_carbs.xml new file mode 100644 index 0000000000..047623e21e --- /dev/null +++ b/wear/src/main/res/drawable/ic_e_carbs.xml @@ -0,0 +1,13 @@ + + + + diff --git a/wear/src/main/res/drawable/ic_loop_closed.xml b/wear/src/main/res/drawable/ic_loop_closed.xml new file mode 100644 index 0000000000..68d6690445 --- /dev/null +++ b/wear/src/main/res/drawable/ic_loop_closed.xml @@ -0,0 +1,12 @@ + + + + diff --git a/wear/src/main/res/drawable/ic_loop_closed_white.xml b/wear/src/main/res/drawable/ic_loop_closed_white.xml new file mode 100644 index 0000000000..586e889a8d --- /dev/null +++ b/wear/src/main/res/drawable/ic_loop_closed_white.xml @@ -0,0 +1,9 @@ + + + diff --git a/wear/src/main/res/drawable/ic_settings.xml b/wear/src/main/res/drawable/ic_settings.xml new file mode 100644 index 0000000000..30858cc88a --- /dev/null +++ b/wear/src/main/res/drawable/ic_settings.xml @@ -0,0 +1,12 @@ + + + + diff --git a/wear/src/main/res/drawable/ic_status.xml b/wear/src/main/res/drawable/ic_status.xml new file mode 100644 index 0000000000..53cfc991f7 --- /dev/null +++ b/wear/src/main/res/drawable/ic_status.xml @@ -0,0 +1,9 @@ + + + diff --git a/wear/src/main/res/drawable/ic_sync.xml b/wear/src/main/res/drawable/ic_sync.xml new file mode 100644 index 0000000000..5eacdb9105 --- /dev/null +++ b/wear/src/main/res/drawable/ic_sync.xml @@ -0,0 +1,12 @@ + + + + diff --git a/wear/src/main/res/drawable/ic_tdd.xml b/wear/src/main/res/drawable/ic_tdd.xml new file mode 100644 index 0000000000..02d751c7bb --- /dev/null +++ b/wear/src/main/res/drawable/ic_tdd.xml @@ -0,0 +1,13 @@ + + + + diff --git a/wear/src/main/res/drawable/ic_temptarget.xml b/wear/src/main/res/drawable/ic_temptarget.xml new file mode 100644 index 0000000000..d1078f4d92 --- /dev/null +++ b/wear/src/main/res/drawable/ic_temptarget.xml @@ -0,0 +1,12 @@ + + + + diff --git a/wear/src/main/res/drawable/menu_item_layout_bg.xml b/wear/src/main/res/drawable/menu_item_layout_bg.xml new file mode 100644 index 0000000000..9421db0f25 --- /dev/null +++ b/wear/src/main/res/drawable/menu_item_layout_bg.xml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/wear/src/main/res/layout-v26/list_item.xml b/wear/src/main/res/layout-v26/list_item.xml index 8084d832e6..b40327f8a2 100644 --- a/wear/src/main/res/layout-v26/list_item.xml +++ b/wear/src/main/res/layout-v26/list_item.xml @@ -1,23 +1,37 @@ - + android:layout_height="wrap_content" + android:paddingBottom="8dp" + android:paddingTop="8dp" + android:background="@drawable/menu_item_layout_bg"> + + + - + android:textStyle="bold" /> + diff --git a/wear/src/main/res/layout/actions_list_activity.xml b/wear/src/main/res/layout/actions_list_activity.xml index 1779f1b4ab..c989dbbf33 100644 --- a/wear/src/main/res/layout/actions_list_activity.xml +++ b/wear/src/main/res/layout/actions_list_activity.xml @@ -1,21 +1,27 @@ - + - + android:layout_height="match_parent" + android:scrollbars="vertical" > + + - - - - + + diff --git a/wear/src/main/res/layout/grid_layout.xml b/wear/src/main/res/layout/grid_layout.xml index 2b37f71cae..7d0c41d95d 100644 --- a/wear/src/main/res/layout/grid_layout.xml +++ b/wear/src/main/res/layout/grid_layout.xml @@ -3,6 +3,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" > + + - - - + android:layout_height="wrap_content" + android:paddingBottom="8dp" + android:paddingTop="8dp" + android:background="@drawable/menu_item_layout_bg"> + + + + +