From dc7a27b018dff8c38db26397eb8934ab59a5ca2e Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Tue, 30 Nov 2021 21:02:10 +0100 Subject: [PATCH] Wear set focus for rotary input --- .../interaction/AAPSPreferences.java | 1 + .../interaction/ConfigurationActivity.java | 1 + .../interaction/actions/BolusActivity.java | 20 ++++++++++++++++++- .../interaction/actions/CPPActivity.java | 16 +++++++++++++++ .../interaction/actions/ECarbActivity.java | 16 +++++++++++++++ .../interaction/actions/FillActivity.java | 1 + .../actions/TempTargetActivity.java | 16 +++++++++++++++ .../interaction/actions/WizardActivity.java | 16 +++++++++++++++ .../interaction/menus/FillMenuActivity.java | 18 ++++++++++------- .../interaction/utils/PlusMinusEditText.java | 18 ++++++++++++++++- .../main/res/layout/actions_list_activity.xml | 1 + 11 files changed, 115 insertions(+), 9 deletions(-) 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/BolusActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.java index dad9a46df9..4b4986b5e2 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 @@ -6,12 +6,15 @@ import android.os.Bundle; import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.GridPagerAdapter; import android.support.wearable.view.GridViewPager; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ListenerService; @@ -38,8 +41,22 @@ public class BolusActivity extends ViewSelectorActivity { 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) { + } + @Override + public void onPageSelected(int row, int column) { + View view = pager.getChildAt(column); + view.requestFocus(); + } + + @Override + public void onPageScrollStateChanged(int state) { + } + }); + } @Override protected void onPause() { @@ -71,6 +88,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); 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..e1da75e567 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 @@ -53,6 +53,21 @@ public class CPPActivity extends ViewSelectorActivity { 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) { + } + + @Override + public void onPageSelected(int row, int column) { + View view = pager.getChildAt(column); + view.requestFocus(); + } + + @Override + public void onPageScrollStateChanged(int state) { + } + }); } @@ -86,6 +101,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); 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..3d2ff7d3f8 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 @@ -40,6 +40,21 @@ public class ECarbActivity extends ViewSelectorActivity { 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) { + } + + @Override + public void onPageSelected(int row, int column) { + View view = pager.getChildAt(column); + view.requestFocus(); + } + + @Override + public void onPageScrollStateChanged(int state) { + } + }); } @@ -73,6 +88,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); 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..e17c8bb724 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 @@ -70,6 +70,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 { 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..430b82fd5d 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 @@ -48,6 +48,21 @@ 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) { + } + + @Override + public void onPageSelected(int row, int column) { + View view = pager.getChildAt(column); + view.requestFocus(); + } + + @Override + public void onPageScrollStateChanged(int state) { + } + }); } @@ -84,6 +99,7 @@ public class TempTargetActivity extends ViewSelectorActivity { } setLabelToPlusMinusView(view, getString(R.string.action_duration)); container.addView(view); + view.requestFocus(); return view; } else if (col == 1) { 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..f376bb954a 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 @@ -45,6 +45,21 @@ public class WizardActivity extends ViewSelectorActivity { 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) { + } + + @Override + public void onPageSelected(int row, int column) { + View view = pager.getChildAt(column); + view.requestFocus(); + } + + @Override + public void onPageScrollStateChanged(int state) { + } + }); } @@ -80,6 +95,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); 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..fc3613c227 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 @@ -2,6 +2,9 @@ package info.nightscout.androidaps.interaction.menus; import android.content.Intent; +import java.util.ArrayList; +import java.util.List; + import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.interaction.actions.FillActivity; @@ -14,13 +17,14 @@ 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 List getElements() { + List menuitems = new ArrayList<>(); + menuitems.add(new MenuElement(R.drawable.ic_canula, getString(R.string.action_preset_1))); + menuitems.add(new MenuElement(R.drawable.ic_canula, getString(R.string.action_preset_2))); + menuitems.add(new MenuElement(R.drawable.ic_canula, getString(R.string.action_preset_3))); + menuitems.add(new MenuElement(R.drawable.ic_canula, getString(R.string.action_free_amount))); + + return menuitems; } @Override 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/res/layout/actions_list_activity.xml b/wear/src/main/res/layout/actions_list_activity.xml index 1779f1b4ab..d9086a813c 100644 --- a/wear/src/main/res/layout/actions_list_activity.xml +++ b/wear/src/main/res/layout/actions_list_activity.xml @@ -15,6 +15,7 @@ android:id="@+id/wearable_list" android:layout_height="match_parent" android:layout_width="match_parent"> +