Wear curved titles

This commit is contained in:
Andries Smit 2021-12-08 15:20:34 +01:00
parent a83eb1c456
commit 0969d8339f
16 changed files with 189 additions and 292 deletions

View file

@ -53,7 +53,7 @@ def generateGitBuild = { ->
}
android {
compileSdkVersion 30
compileSdkVersion 31
defaultConfig {
applicationId "info.nightscout.androidaps"
@ -119,8 +119,6 @@ allprojects {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//implementation files("libs/hellocharts-library-1.5.5.jar")
//compile "com.ustwo.android:clockwise-wearable:1.0.2"
implementation "androidx.appcompat:appcompat:$appcompat_version"
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
@ -131,10 +129,12 @@ dependencies {
implementation(name: 'ustwo-clockwise-debug', ext: 'aar')
implementation(name: 'wearpreferenceactivity-0.5.0', ext: 'aar')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.percentlayout:percentlayout:1.0.0'
implementation 'androidx.wear:wear:1.1.0'
implementation 'androidx.wear:wear:1.2.0'
implementation('com.github.lecho:hellocharts-library:1.5.8@aar')
implementation "androidx.core:core-ktx:$coreVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testImplementation "junit:junit:$junit_version"
testImplementation 'org.json:json:20211205'
testImplementation("org.mockito:mockito-core:${mockitoVersion}") {
@ -157,8 +157,6 @@ dependencies {
}
testImplementation "org.skyscreamer:jsonassert:1.5.0"
testImplementation "org.hamcrest:hamcrest-all:1.3"
implementation "androidx.core:core-ktx:$coreVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
repositories {
mavenCentral()

View file

@ -1,16 +1,11 @@
package info.nightscout.androidaps.interaction.actions;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.SystemClock;
import android.os.Vibrator;
import androidx.core.app.NotificationManagerCompat;
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;
@ -24,10 +19,8 @@ import info.nightscout.androidaps.data.ListenerService;
* Created by adrian on 09/02/17.
*/
public class AcceptActivity extends ViewSelectorActivity {
String title = "";
String message = "";
String actionstring = "";
@ -45,30 +38,25 @@ public class AcceptActivity extends ViewSelectorActivity {
message = extras.getString("message", "");
actionstring = extras.getString("actionstring", "");
if ("".equals(message) || "".equals(actionstring) ){
finish(); return;
if ("".equals(message) || "".equals(actionstring)) {
finish();
return;
}
setContentView(R.layout.grid_layout);
final GridViewPager pager = findViewById(R.id.pager);
pager.setAdapter(new MyGridViewPagerAdapter());
DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator);
dotsPageIndicator.setPager(pager);
setAdapter(new MyGridViewPagerAdapter());
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long[] vibratePattern = new long[]{0, 100, 50, 100, 50};
v.vibrate(vibratePattern, -1);
}
@Override
protected void onPause() {
super.onPause();
finish();
}
private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override
public int getColumnCount(int arg0) {
@ -83,7 +71,7 @@ public class AcceptActivity extends ViewSelectorActivity {
@Override
public Object instantiateItem(ViewGroup container, int row, int col) {
if(col == 0){
if (col == 0) {
final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_confirm_text, container, false);
final TextView headingView = view.findViewById(R.id.title);
headingView.setText(title);
@ -110,29 +98,29 @@ public class AcceptActivity extends ViewSelectorActivity {
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);
container.removeView((View) view);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
return view == object;
}
}
@Override
public synchronized void onDestroy(){
public synchronized void onDestroy() {
super.onDestroy();
if(dismissThread != null){
if (dismissThread != null) {
dismissThread.invalidate();
}
}
private class DismissThread extends Thread{
private class DismissThread extends Thread {
private boolean valid = true;
public synchronized void invalidate(){
public synchronized void invalidate() {
valid = false;
}
@ -140,7 +128,7 @@ public class AcceptActivity extends ViewSelectorActivity {
public void run() {
SystemClock.sleep(60 * 1000);
synchronized (this) {
if(valid) {
if (valid) {
AcceptActivity.this.finish();
}
}
@ -150,11 +138,11 @@ public class AcceptActivity extends ViewSelectorActivity {
@Override
protected synchronized void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if(dismissThread != null) dismissThread.invalidate();
if (dismissThread != null) dismissThread.invalidate();
Bundle extras = intent.getExtras();
Intent msgIntent = new Intent(this, AcceptActivity.class);
msgIntent.putExtras(extras);
startActivity(msgIntent);
finish();
}
}
}

View file

@ -1,16 +1,11 @@
package info.nightscout.androidaps.interaction.actions;
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;
@ -23,7 +18,6 @@ import info.nightscout.androidaps.interaction.utils.SafeParse;
* Created by adrian on 09/02/17.
*/
public class BolusActivity extends ViewSelectorActivity {
PlusMinusEditText editCarbs;
@ -32,32 +26,7 @@ public class BolusActivity extends ViewSelectorActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_layout);
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);
}
});
setAdapter(new MyGridViewPagerAdapter());
}
@Override
@ -109,10 +78,8 @@ public class BolusActivity extends ViewSelectorActivity {
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 = "bolus " + SafeParse.stringToDouble(editInsulin.editText.getText().toString())
+ " " + SafeParse.stringToInt(editCarbs.editText.getText().toString());
ListenerService.initiateAction(BolusActivity.this, actionstring);
@ -136,6 +103,5 @@ public class BolusActivity extends ViewSelectorActivity {
return view == object;
}
}
}
}

View file

@ -1,16 +1,11 @@
package info.nightscout.androidaps.interaction.actions;
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;
@ -23,7 +18,6 @@ import info.nightscout.androidaps.interaction.utils.SafeParse;
* Created by adrian on 09/02/17.
*/
public class CPPActivity extends ViewSelectorActivity {
PlusMinusEditText editPercentage;
@ -47,42 +41,15 @@ public class CPPActivity extends ViewSelectorActivity {
if (timeshift < 0) timeshift += 24;
setContentView(R.layout.grid_layout);
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);
}
});
setAdapter(new MyGridViewPagerAdapter());
}
@Override
protected void onPause() {
super.onPause();
finish();
}
private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override
public int getColumnCount(int arg0) {
@ -152,6 +119,5 @@ public class CPPActivity extends ViewSelectorActivity {
return view == object;
}
}
}

View file

@ -1,16 +1,11 @@
package info.nightscout.androidaps.interaction.actions;
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;
@ -23,53 +18,24 @@ import info.nightscout.androidaps.interaction.utils.SafeParse;
* Created by adrian on 04/08/18.
*/
public class ECarbActivity extends ViewSelectorActivity {
PlusMinusEditText editCarbs;
PlusMinusEditText editStartTime;
PlusMinusEditText editDuration;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_layout);
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);
}
});
setAdapter(new MyGridViewPagerAdapter());
}
@Override
protected void onPause() {
super.onPause();
finish();
}
private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override
public int getColumnCount(int arg0) {
@ -84,10 +50,10 @@ public class ECarbActivity extends ViewSelectorActivity {
@Override
public Object instantiateItem(ViewGroup container, int row, int col) {
if(col == 0){
if (col == 0) {
final View view = getInflatedPlusMinusView(container);
double def = 0;
if (editCarbs != null){
if (editCarbs != null) {
def = SafeParse.stringToDouble(editCarbs.editText.getText().toString());
}
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 150d, 1d, new DecimalFormat("0"), true);
@ -95,20 +61,20 @@ public class ECarbActivity extends ViewSelectorActivity {
container.addView(view);
view.requestFocus();
return view;
} else if(col == 1){
} else if (col == 1) {
final View view = getInflatedPlusMinusView(container);
double def = 0;
if (editStartTime != null){
if (editStartTime != null) {
def = SafeParse.stringToDouble(editStartTime.editText.getText().toString());
}
editStartTime = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 300d, 15d, new DecimalFormat("0"), false);
setLabelToPlusMinusView(view, getString(R.string.action_start_min));
container.addView(view);
return view;
} else if(col == 2){
} else if (col == 2) {
final View view = getInflatedPlusMinusView(container);
double def = 0;
if (editDuration != null){
if (editDuration != null) {
def = SafeParse.stringToDouble(editDuration.editText.getText().toString());
}
editDuration = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 8d, 1d, new DecimalFormat("0"), false);
@ -126,7 +92,7 @@ public class ECarbActivity extends ViewSelectorActivity {
//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 = "ecarbs " +SafeParse.stringToInt(editCarbs.editText.getText().toString())
String actionstring = "ecarbs " + SafeParse.stringToInt(editCarbs.editText.getText().toString())
+ " " + SafeParse.stringToInt(editStartTime.editText.getText().toString())
+ " " + SafeParse.stringToInt(editDuration.editText.getText().toString());
ListenerService.initiateAction(ECarbActivity.this, actionstring);
@ -142,14 +108,13 @@ public class ECarbActivity extends ViewSelectorActivity {
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);
container.removeView((View) view);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
return view == object;
}
}
}
}

View file

@ -1,16 +1,11 @@
package info.nightscout.androidaps.interaction.actions;
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;
@ -23,7 +18,6 @@ import info.nightscout.androidaps.interaction.utils.SafeParse;
* Created by adrian on 09/02/17.
*/
public class FillActivity extends ViewSelectorActivity {
PlusMinusEditText editInsulin;
@ -31,25 +25,15 @@ public class FillActivity extends ViewSelectorActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_layout);
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);
setAdapter(new MyGridViewPagerAdapter());
}
@Override
protected void onPause() {
super.onPause();
finish();
}
private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override
public int getColumnCount(int arg0) {
@ -108,6 +92,5 @@ public class FillActivity extends ViewSelectorActivity {
return view == object;
}
}
}
}

View file

@ -1,13 +1,9 @@
package info.nightscout.androidaps.interaction.actions;
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;
@ -25,7 +21,6 @@ import info.nightscout.androidaps.interaction.utils.SafeParse;
* Created by adrian on 09/02/17.
*/
public class TempTargetActivity extends ViewSelectorActivity {
PlusMinusEditText lowRange;
@ -37,46 +32,19 @@ public class TempTargetActivity extends ViewSelectorActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_layout);
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);
setAdapter(new MyGridViewPagerAdapter());
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);
}
});
}
@Override
protected void onPause() {
super.onPause();
finish();
}
private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override
public int getColumnCount(int arg0) {
@ -184,6 +152,5 @@ public class TempTargetActivity extends ViewSelectorActivity {
return view == object;
}
}
}
}

View file

@ -2,26 +2,83 @@ package info.nightscout.androidaps.interaction.actions;
import android.app.Activity;
import android.content.SharedPreferences;
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.TextView;
import androidx.wear.widget.CurvedTextView;
import info.nightscout.androidaps.R;
/**
* Created by adrian on 13/02/17.
*/
public class ViewSelectorActivity extends Activity {
private GridViewPager pager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_layout);
setTitleBasedOnScreenShape(String.valueOf(getTitle()));
pager = findViewById(R.id.pager);
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);
}
});
}
public void setAdapter(GridPagerAdapter adapter) {
pager.setAdapter(adapter);
}
private void setTitleBasedOnScreenShape(String title) {
CurvedTextView titleViewCurved = findViewById(R.id.title_curved);
TextView titleView = findViewById(R.id.title);
if (this.getResources().getConfiguration().isScreenRound()) {
titleViewCurved.setText(title);
titleViewCurved.setVisibility(View.VISIBLE);
titleView.setVisibility((View.GONE));
} else {
titleView.setText(title);
titleView.setVisibility(View.VISIBLE);
titleViewCurved.setVisibility((View.GONE));
}
}
View getInflatedPlusMinusView(ViewGroup container) {
SharedPreferences sharedPrefs = PreferenceManager
.getDefaultSharedPreferences(this);
int design = Integer.parseInt(sharedPrefs.getString("input_design", "1"));
if (design == 2){
if (design == 2) {
return LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_editplusminus_item_quickrighty, container, false);
} else if (design == 3) {
return LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_editplusminus_item_quicklefty, container, false);
@ -33,12 +90,12 @@ public class ViewSelectorActivity extends Activity {
return LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_editplusminus_item, container, false);
}
void setLabelToPlusMinusView(View view, String labelText){
void setLabelToPlusMinusView(View view, String labelText) {
SharedPreferences sharedPrefs = PreferenceManager
.getDefaultSharedPreferences(this);
int design = Integer.parseInt(sharedPrefs.getString("input_design", "1"));
if (design == 4){
if (design == 4) {
//@LadyViktoria: Here the label can be set differently, if you like.
final TextView textView = view.findViewById(R.id.label);
textView.setText(labelText);

View file

@ -1,18 +1,13 @@
package info.nightscout.androidaps.interaction.actions;
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;
@ -25,7 +20,6 @@ import info.nightscout.androidaps.interaction.utils.SafeParse;
* Created by adrian on 09/02/17.
*/
public class WizardActivity extends ViewSelectorActivity {
PlusMinusEditText editCarbs;
@ -33,48 +27,20 @@ public class WizardActivity extends ViewSelectorActivity {
boolean hasPercentage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_layout);
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);
setAdapter(new MyGridViewPagerAdapter());
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);
}
});
}
@Override
protected void onPause() {
super.onPause();
finish();
}
private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override
public int getColumnCount(int arg0) {
@ -96,7 +62,6 @@ public class WizardActivity extends ViewSelectorActivity {
} else {
double def = SafeParse.stringToDouble(editCarbs.editText.getText().toString());
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 150d, 1d, new DecimalFormat("0"), false);
}
setLabelToPlusMinusView(view, getString(R.string.action_carbs));
container.addView(view);
@ -152,6 +117,5 @@ public class WizardActivity extends ViewSelectorActivity {
return view == object;
}
}
}
}

View file

@ -44,7 +44,6 @@ public class MainMenuActivity extends MenuListActivity {
return menuItems;
}
boolean showPrimeFill = sp.getBoolean("primefill", false);
boolean showWizard = sp.getBoolean("showWizard", true);

View file

@ -10,6 +10,7 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import androidx.wear.widget.CurvedTextView;
import androidx.wear.widget.WearableLinearLayoutManager;
import androidx.wear.widget.WearableRecyclerView;
@ -23,10 +24,12 @@ import info.nightscout.androidaps.R;
public abstract class MenuListActivity extends Activity {
List<MenuItem> elements;
protected abstract List<MenuItem> getElements();
protected abstract void doAction(String position);
public interface AdapterCallback{
public interface AdapterCallback {
void onItemClicked(MenuAdapter.ItemViewHolder v);
}
@ -34,18 +37,22 @@ public abstract class MenuListActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.actions_list_activity);
TextView titleView = findViewById(R.id.title);
titleView.setText(getTitle());
setTitleBasedOnScreenShape(String.valueOf(getTitle()));
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);
boolean isScreenRound = this.getResources().getConfiguration().isScreenRound();
if (isScreenRound) {
layoutManager.setLayoutCallback(customScrollingLayoutCallback);
listView.setEdgeItemsCenteringEnabled(true);
} else {
// Bug in androidx.wear:wear:1.2.0
// WearableRecyclerView setEdgeItemsCenteringEnabled requires fix for square screen
listView.setPadding(0, 50, 0, 0);
}
listView.setHasFixedSize(true);
listView.setEdgeItemsCenteringEnabled(true);
listView.setLayoutManager(layoutManager);
listView.setAdapter(new MenuAdapter(elements, v -> {
String tag = (String) v.itemView.getTag();
@ -53,16 +60,30 @@ public abstract class MenuListActivity extends Activity {
}));
}
private class MenuAdapter extends RecyclerView.Adapter<MenuAdapter.ItemViewHolder> {
private void setTitleBasedOnScreenShape(String title) {
CurvedTextView titleViewCurved = findViewById(R.id.title_curved);
TextView titleView = findViewById(R.id.title);
if (this.getResources().getConfiguration().isScreenRound()) {
titleViewCurved.setText(title);
titleViewCurved.setVisibility(View.VISIBLE);
titleView.setVisibility((View.GONE));
} else {
titleView.setText(title);
titleView.setVisibility(View.VISIBLE);
titleViewCurved.setVisibility((View.GONE));
}
}
private static class MenuAdapter extends RecyclerView.Adapter<MenuAdapter.ItemViewHolder> {
private final List<MenuItem> mDataset;
private AdapterCallback callback;
private final AdapterCallback callback;
public MenuAdapter(List<MenuItem> dataset, AdapterCallback callback) {
mDataset = dataset;
this.callback = callback;
}
public class ItemViewHolder extends RecyclerView.ViewHolder {
public static class ItemViewHolder extends RecyclerView.ViewHolder {
protected final RelativeLayout menuContainer;
protected final TextView actionItem;
protected final ImageView actionIcon;
@ -78,9 +99,8 @@ public abstract class MenuListActivity extends Activity {
@Override
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;
return new ItemViewHolder(view);
}
@Override
@ -89,9 +109,7 @@ public abstract class MenuListActivity extends Activity {
holder.actionItem.setText(item.actionItem);
holder.actionIcon.setImageResource(item.actionIcon);
holder.itemView.setTag(item.actionItem);
holder.menuContainer.setOnClickListener(v -> {
callback.onItemClicked(holder);
});
holder.menuContainer.setOnClickListener(v -> callback.onItemClicked(holder));
}
@Override
@ -100,19 +118,19 @@ public abstract class MenuListActivity extends Activity {
}
}
protected class MenuItem {
protected static class MenuItem {
public MenuItem(int actionIcon, String actionItem) {
this.actionIcon = actionIcon;
this.actionItem = actionItem;
}
public int actionIcon;
public String actionItem;
}
public class CustomScrollingLayoutCallback extends WearableLinearLayoutManager.LayoutCallback {
public static 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) {
@ -121,7 +139,7 @@ public abstract class MenuListActivity extends Activity {
float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset;
// Normalize for center
progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);
float progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);
// Adjust to the maximum scale
progressToCenter = Math.min(progressToCenter, MAX_ICON_PROGRESS);

View file

@ -1,11 +1,11 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu_container"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/menu_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:background="@drawable/menu_item_layout_bg"
android:paddingTop="8dp"
android:background="@drawable/menu_item_layout_bg">
android:paddingBottom="8dp">
<ImageView
android:id="@+id/menuItemIcon"
@ -25,13 +25,13 @@
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/menuItemIcon"
android:layout_toRightOf="@+id/menuItemIcon"
android:autoSizeMaxTextSize="32sp"
android:autoSizeMinTextSize="12sp"
android:autoSizeStepGranularity="2sp"
android:autoSizeTextType="uniform"
android:text="action item"
android:textColor="@color/dark_statusView"
android:textSize="20sp"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="32sp"
android:autoSizeStepGranularity="2sp"
android:textStyle="bold" />
</RelativeLayout>

View file

@ -1,27 +1,41 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">
<androidx.wear.widget.WearableRecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.wear.widget.WearableRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/action_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
android:scrollbars="vertical">
<requestFocus />
</androidx.wear.widget.WearableRecyclerView>
<TextView
android:id="@+id/title"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="26dp"
android:gravity="center"
android:layout_height="28dp"
android:background="@color/titleHeader">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="26dp"
android:autoSizeMaxTextSize="18sp"
android:autoSizeMinTextSize="12sp"
android:autoSizeTextType="uniform"
android:gravity="center"
android:text="Title"
android:textSize="18sp" />
</LinearLayout>
<androidx.wear.widget.CurvedTextView
android:id="@+id/title_curved"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="18sp"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="18sp"
android:background="#D9000000"/>
android:visibility="gone" />
</FrameLayout>

View file

@ -1,14 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">
<androidx.wear.widget.CurvedTextView
android:id="@+id/title_curved"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="18sp"
android:visibility="gone" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="26dp"
android:autoSizeMaxTextSize="18sp"
android:autoSizeMinTextSize="12sp"
android:autoSizeTextType="uniform"
android:gravity="center"
android:textSize="18sp"/>
android:text="Title"
android:textSize="18sp" />
<android.support.wearable.view.GridViewPager
android:id="@+id/pager"
@ -20,7 +32,6 @@
android:id="@+id/page_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom">
</android.support.wearable.view.DotsPageIndicator>
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
</FrameLayout>

View file

@ -1,11 +1,11 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu_container"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/menu_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:background="@drawable/menu_item_layout_bg"
android:paddingTop="8dp"
android:background="@drawable/menu_item_layout_bg">
android:paddingBottom="8dp">
<ImageView
android:id="@+id/menuItemIcon"

View file

@ -2,6 +2,7 @@
<resources>
<color name="cardObjectiveText">#779ECB</color>
<color name="titleHeader">#D9000000</color>
<!-- light colors -->