Wear set focus for rotary input

This commit is contained in:
Andries Smit 2021-11-30 21:02:10 +01:00
parent 85140a9c2e
commit dc7a27b018
11 changed files with 115 additions and 9 deletions

View file

@ -17,6 +17,7 @@ public class AAPSPreferences extends WearPreferenceActivity {
ViewGroup view = (ViewGroup)getWindow().getDecorView(); ViewGroup view = (ViewGroup)getWindow().getDecorView();
removeBackgroundRecursively(view); removeBackgroundRecursively(view);
view.setBackground(getResources().getDrawable(R.drawable.settings_background)); view.setBackground(getResources().getDrawable(R.drawable.settings_background));
view.requestFocus();
} }
@Override @Override

View file

@ -22,6 +22,7 @@ public class ConfigurationActivity extends WearPreferenceActivity {
ViewGroup view = (ViewGroup) getWindow().getDecorView(); ViewGroup view = (ViewGroup) getWindow().getDecorView();
removeBackgroundRecursively(view); removeBackgroundRecursively(view);
view.setBackground(getResources().getDrawable(R.drawable.settings_background)); view.setBackground(getResources().getDrawable(R.drawable.settings_background));
view.requestFocus();
} }
@Override @Override

View file

@ -6,12 +6,15 @@ import android.os.Bundle;
import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.DotsPageIndicator;
import android.support.wearable.view.GridPagerAdapter; import android.support.wearable.view.GridPagerAdapter;
import android.support.wearable.view.GridViewPager; import android.support.wearable.view.GridViewPager;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
@ -38,8 +41,22 @@ public class BolusActivity extends ViewSelectorActivity {
pager.setAdapter(new MyGridViewPagerAdapter()); pager.setAdapter(new MyGridViewPagerAdapter());
DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator); DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator);
dotsPageIndicator.setPager(pager); 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 @Override
protected void onPause() { 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); 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)); setLabelToPlusMinusView(view, getString(R.string.action_insulin));
container.addView(view); container.addView(view);
view.requestFocus();
return view; return view;
} else if (col == 1) { } else if (col == 1) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);

View file

@ -53,6 +53,21 @@ public class CPPActivity extends ViewSelectorActivity {
pager.setAdapter(new MyGridViewPagerAdapter()); pager.setAdapter(new MyGridViewPagerAdapter());
DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator); DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator);
dotsPageIndicator.setPager(pager); 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); 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)); setLabelToPlusMinusView(view, getString(R.string.action_timeshift));
container.addView(view); container.addView(view);
view.requestFocus();
return view; return view;
} else if (col == 1) { } else if (col == 1) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);

View file

@ -40,6 +40,21 @@ public class ECarbActivity extends ViewSelectorActivity {
pager.setAdapter(new MyGridViewPagerAdapter()); pager.setAdapter(new MyGridViewPagerAdapter());
DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator); DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator);
dotsPageIndicator.setPager(pager); 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); 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)); setLabelToPlusMinusView(view, getString(R.string.action_carbs));
container.addView(view); container.addView(view);
view.requestFocus();
return view; return view;
} else if(col == 1){ } else if(col == 1){
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);

View file

@ -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); 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)); setLabelToPlusMinusView(view, getString(R.string.action_insulin));
container.addView(view); container.addView(view);
view.requestFocus();
return view; return view;
} else { } else {

View file

@ -48,6 +48,21 @@ public class TempTargetActivity extends ViewSelectorActivity {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
isMGDL = sp.getBoolean("units_mgdl", true); isMGDL = sp.getBoolean("units_mgdl", true);
isSingleTarget = sp.getBoolean("singletarget", 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)); setLabelToPlusMinusView(view, getString(R.string.action_duration));
container.addView(view); container.addView(view);
view.requestFocus();
return view; return view;
} else if (col == 1) { } else if (col == 1) {

View file

@ -45,6 +45,21 @@ public class WizardActivity extends ViewSelectorActivity {
dotsPageIndicator.setPager(pager); dotsPageIndicator.setPager(pager);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
hasPercentage = sp.getBoolean("wizardpercentage", false); 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)); setLabelToPlusMinusView(view, getString(R.string.action_carbs));
container.addView(view); container.addView(view);
view.requestFocus();
return view; return view;
} else if (col == 1 && hasPercentage) { } else if (col == 1 && hasPercentage) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);

View file

@ -2,6 +2,9 @@ package info.nightscout.androidaps.interaction.menus;
import android.content.Intent; import android.content.Intent;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.actions.FillActivity; import info.nightscout.androidaps.interaction.actions.FillActivity;
@ -14,13 +17,14 @@ import info.nightscout.androidaps.interaction.utils.MenuListActivity;
public class FillMenuActivity extends MenuListActivity { public class FillMenuActivity extends MenuListActivity {
@Override @Override
protected String[] getElements() { protected List<MenuElement> getElements() {
return new String[]{ List<MenuElement> menuitems = new ArrayList<>();
getString(R.string.action_preset_1), menuitems.add(new MenuElement(R.drawable.ic_canula, getString(R.string.action_preset_1)));
getString(R.string.action_preset_2), menuitems.add(new MenuElement(R.drawable.ic_canula, getString(R.string.action_preset_2)));
getString(R.string.action_preset_3), menuitems.add(new MenuElement(R.drawable.ic_canula, getString(R.string.action_preset_3)));
getString(R.string.action_free_amount) menuitems.add(new MenuElement(R.drawable.ic_canula, getString(R.string.action_free_amount)));
};
return menuitems;
} }
@Override @Override

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.interaction.utils;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.support.wearable.input.RotaryEncoder;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -19,7 +20,7 @@ import java.util.concurrent.TimeUnit;
* Created by mike on 28.06.2016. * Created by mike on 28.06.2016.
*/ */
public class PlusMinusEditText implements View.OnKeyListener, public class PlusMinusEditText implements View.OnKeyListener,
View.OnTouchListener, View.OnClickListener { View.OnTouchListener, View.OnClickListener, View.OnGenericMotionListener {
Integer editTextID; Integer editTextID;
public TextView editText; public TextView editText;
@ -104,6 +105,7 @@ public class PlusMinusEditText implements View.OnKeyListener,
plusImage.setOnTouchListener(this); plusImage.setOnTouchListener(this);
plusImage.setOnKeyListener(this); plusImage.setOnKeyListener(this);
plusImage.setOnClickListener(this); plusImage.setOnClickListener(this);
editText.setOnGenericMotionListener(this);
updateEditText(); updateEditText();
} }
@ -207,4 +209,18 @@ public class PlusMinusEditText implements View.OnKeyListener,
return false; 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;
}
} }

View file

@ -15,6 +15,7 @@
android:id="@+id/wearable_list" android:id="@+id/wearable_list"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_width="match_parent"> android:layout_width="match_parent">
<requestFocus />
</android.support.wearable.view.WearableListView> </android.support.wearable.view.WearableListView>
</FrameLayout> </FrameLayout>
</android.support.wearable.view.BoxInsetLayout> </android.support.wearable.view.BoxInsetLayout>