Wear set focus for rotary input
This commit is contained in:
parent
85140a9c2e
commit
dc7a27b018
11 changed files with 115 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<MenuElement> getElements() {
|
||||
List<MenuElement> 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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
android:id="@+id/wearable_list"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent">
|
||||
<requestFocus />
|
||||
</android.support.wearable.view.WearableListView>
|
||||
</FrameLayout>
|
||||
</android.support.wearable.view.BoxInsetLayout>
|
||||
|
|
Loading…
Reference in a new issue