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

View file

@ -1,16 +1,11 @@
package info.nightscout.androidaps.interaction.actions; package info.nightscout.androidaps.interaction.actions;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.Vibrator; 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.GridPagerAdapter;
import android.support.wearable.view.GridViewPager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -24,10 +19,8 @@ import info.nightscout.androidaps.data.ListenerService;
* Created by adrian on 09/02/17. * Created by adrian on 09/02/17.
*/ */
public class AcceptActivity extends ViewSelectorActivity { public class AcceptActivity extends ViewSelectorActivity {
String title = ""; String title = "";
String message = ""; String message = "";
String actionstring = ""; String actionstring = "";
@ -46,29 +39,24 @@ public class AcceptActivity extends ViewSelectorActivity {
actionstring = extras.getString("actionstring", ""); actionstring = extras.getString("actionstring", "");
if ("".equals(message) || "".equals(actionstring)) { if ("".equals(message) || "".equals(actionstring)) {
finish(); return; finish();
return;
} }
setContentView(R.layout.grid_layout); setContentView(R.layout.grid_layout);
setAdapter(new MyGridViewPagerAdapter());
final GridViewPager pager = findViewById(R.id.pager);
pager.setAdapter(new MyGridViewPagerAdapter());
DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator);
dotsPageIndicator.setPager(pager);
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long[] vibratePattern = new long[]{0, 100, 50, 100, 50}; long[] vibratePattern = new long[]{0, 100, 50, 100, 50};
v.vibrate(vibratePattern, -1); v.vibrate(vibratePattern, -1);
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
finish(); finish();
} }
private class MyGridViewPagerAdapter extends GridPagerAdapter { private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override @Override
public int getColumnCount(int arg0) { public int getColumnCount(int arg0) {

View file

@ -1,16 +1,11 @@
package info.nightscout.androidaps.interaction.actions; package info.nightscout.androidaps.interaction.actions;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
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.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 android.widget.TextView;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@ -23,7 +18,6 @@ import info.nightscout.androidaps.interaction.utils.SafeParse;
* Created by adrian on 09/02/17. * Created by adrian on 09/02/17.
*/ */
public class BolusActivity extends ViewSelectorActivity { public class BolusActivity extends ViewSelectorActivity {
PlusMinusEditText editCarbs; PlusMinusEditText editCarbs;
@ -32,32 +26,7 @@ public class BolusActivity extends ViewSelectorActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.grid_layout); setAdapter(new MyGridViewPagerAdapter());
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 @Override
@ -109,10 +78,8 @@ public class BolusActivity extends ViewSelectorActivity {
confirmbutton.setOnClickListener(new View.OnClickListener() { confirmbutton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
//check if it can happen that the fagment is never created that hold data? //check if it can happen that the fagment is never created that hold data?
// (you have to swipe past them anyways - but still) // (you have to swipe past them anyways - but still)
String actionstring = "bolus " + SafeParse.stringToDouble(editInsulin.editText.getText().toString()) String actionstring = "bolus " + SafeParse.stringToDouble(editInsulin.editText.getText().toString())
+ " " + SafeParse.stringToInt(editCarbs.editText.getText().toString()); + " " + SafeParse.stringToInt(editCarbs.editText.getText().toString());
ListenerService.initiateAction(BolusActivity.this, actionstring); ListenerService.initiateAction(BolusActivity.this, actionstring);
@ -136,6 +103,5 @@ public class BolusActivity extends ViewSelectorActivity {
return view == object; return view == object;
} }
} }
} }

View file

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

View file

@ -1,16 +1,11 @@
package info.nightscout.androidaps.interaction.actions; package info.nightscout.androidaps.interaction.actions;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
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.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 android.widget.TextView;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@ -23,45 +18,17 @@ import info.nightscout.androidaps.interaction.utils.SafeParse;
* Created by adrian on 04/08/18. * Created by adrian on 04/08/18.
*/ */
public class ECarbActivity extends ViewSelectorActivity { public class ECarbActivity extends ViewSelectorActivity {
PlusMinusEditText editCarbs; PlusMinusEditText editCarbs;
PlusMinusEditText editStartTime; PlusMinusEditText editStartTime;
PlusMinusEditText editDuration; PlusMinusEditText editDuration;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.grid_layout); setAdapter(new MyGridViewPagerAdapter());
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);
}
});
}
@Override @Override
protected void onPause() { protected void onPause() {
@ -69,7 +36,6 @@ public class ECarbActivity extends ViewSelectorActivity {
finish(); finish();
} }
private class MyGridViewPagerAdapter extends GridPagerAdapter { private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override @Override
public int getColumnCount(int arg0) { public int getColumnCount(int arg0) {
@ -150,6 +116,5 @@ public class ECarbActivity extends ViewSelectorActivity {
return view == object; return view == object;
} }
} }
} }

View file

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

View file

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

View file

@ -2,19 +2,76 @@ package info.nightscout.androidaps.interaction.actions;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager; 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.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import androidx.wear.widget.CurvedTextView;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
/** /**
* Created by adrian on 13/02/17. * Created by adrian on 13/02/17.
*/ */
public class ViewSelectorActivity extends Activity { 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) { View getInflatedPlusMinusView(ViewGroup container) {
SharedPreferences sharedPrefs = PreferenceManager SharedPreferences sharedPrefs = PreferenceManager

View file

@ -1,18 +1,13 @@
package info.nightscout.androidaps.interaction.actions; package info.nightscout.androidaps.interaction.actions;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
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.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 android.widget.TextView;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@ -25,7 +20,6 @@ import info.nightscout.androidaps.interaction.utils.SafeParse;
* Created by adrian on 09/02/17. * Created by adrian on 09/02/17.
*/ */
public class WizardActivity extends ViewSelectorActivity { public class WizardActivity extends ViewSelectorActivity {
PlusMinusEditText editCarbs; PlusMinusEditText editCarbs;
@ -33,40 +27,13 @@ public class WizardActivity extends ViewSelectorActivity {
boolean hasPercentage; boolean hasPercentage;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.grid_layout); setAdapter(new MyGridViewPagerAdapter());
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); 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) {
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 @Override
protected void onPause() { protected void onPause() {
@ -74,7 +41,6 @@ public class WizardActivity extends ViewSelectorActivity {
finish(); finish();
} }
private class MyGridViewPagerAdapter extends GridPagerAdapter { private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override @Override
public int getColumnCount(int arg0) { public int getColumnCount(int arg0) {
@ -96,7 +62,6 @@ public class WizardActivity extends ViewSelectorActivity {
} else { } else {
double def = SafeParse.stringToDouble(editCarbs.editText.getText().toString()); 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); 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)); setLabelToPlusMinusView(view, getString(R.string.action_carbs));
container.addView(view); container.addView(view);
@ -152,6 +117,5 @@ public class WizardActivity extends ViewSelectorActivity {
return view == object; return view == object;
} }
} }
} }

View file

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

View file

@ -10,6 +10,7 @@ import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.wear.widget.CurvedTextView;
import androidx.wear.widget.WearableLinearLayoutManager; import androidx.wear.widget.WearableLinearLayoutManager;
import androidx.wear.widget.WearableRecyclerView; import androidx.wear.widget.WearableRecyclerView;
@ -23,7 +24,9 @@ import info.nightscout.androidaps.R;
public abstract class MenuListActivity extends Activity { public abstract class MenuListActivity extends Activity {
List<MenuItem> elements; List<MenuItem> elements;
protected abstract List<MenuItem> getElements(); protected abstract List<MenuItem> getElements();
protected abstract void doAction(String position); protected abstract void doAction(String position);
public interface AdapterCallback { public interface AdapterCallback {
@ -34,18 +37,22 @@ public abstract class MenuListActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.actions_list_activity); setContentView(R.layout.actions_list_activity);
TextView titleView = findViewById(R.id.title); setTitleBasedOnScreenShape(String.valueOf(getTitle()));
titleView.setText(getTitle());
elements = getElements(); elements = getElements();
CustomScrollingLayoutCallback customScrollingLayoutCallback = new CustomScrollingLayoutCallback(); CustomScrollingLayoutCallback customScrollingLayoutCallback = new CustomScrollingLayoutCallback();
WearableLinearLayoutManager layoutManager = new WearableLinearLayoutManager(this); WearableLinearLayoutManager layoutManager = new WearableLinearLayoutManager(this);
if (this.getResources().getConfiguration().isScreenRound()) {
layoutManager.setLayoutCallback(customScrollingLayoutCallback);
}
WearableRecyclerView listView = findViewById(R.id.action_list); WearableRecyclerView listView = findViewById(R.id.action_list);
listView.setHasFixedSize(true); boolean isScreenRound = this.getResources().getConfiguration().isScreenRound();
if (isScreenRound) {
layoutManager.setLayoutCallback(customScrollingLayoutCallback);
listView.setEdgeItemsCenteringEnabled(true); 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.setLayoutManager(layoutManager); listView.setLayoutManager(layoutManager);
listView.setAdapter(new MenuAdapter(elements, v -> { listView.setAdapter(new MenuAdapter(elements, v -> {
String tag = (String) v.itemView.getTag(); 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 final List<MenuItem> mDataset;
private AdapterCallback callback; private final AdapterCallback callback;
public MenuAdapter(List<MenuItem> dataset, AdapterCallback callback) { public MenuAdapter(List<MenuItem> dataset, AdapterCallback callback) {
mDataset = dataset; mDataset = dataset;
this.callback = callback; this.callback = callback;
} }
public class ItemViewHolder extends RecyclerView.ViewHolder { public static class ItemViewHolder extends RecyclerView.ViewHolder {
protected final RelativeLayout menuContainer; protected final RelativeLayout menuContainer;
protected final TextView actionItem; protected final TextView actionItem;
protected final ImageView actionIcon; protected final ImageView actionIcon;
@ -78,9 +99,8 @@ public abstract class MenuListActivity extends Activity {
@Override @Override
public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false); 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 @Override
@ -89,9 +109,7 @@ public abstract class MenuListActivity extends Activity {
holder.actionItem.setText(item.actionItem); holder.actionItem.setText(item.actionItem);
holder.actionIcon.setImageResource(item.actionIcon); holder.actionIcon.setImageResource(item.actionIcon);
holder.itemView.setTag(item.actionItem); holder.itemView.setTag(item.actionItem);
holder.menuContainer.setOnClickListener(v -> { holder.menuContainer.setOnClickListener(v -> callback.onItemClicked(holder));
callback.onItemClicked(holder);
});
} }
@Override @Override
@ -100,19 +118,19 @@ public abstract class MenuListActivity extends Activity {
} }
} }
protected class MenuItem { protected static class MenuItem {
public MenuItem(int actionIcon, String actionItem) { public MenuItem(int actionIcon, String actionItem) {
this.actionIcon = actionIcon; this.actionIcon = actionIcon;
this.actionItem = actionItem; this.actionItem = actionItem;
} }
public int actionIcon; public int actionIcon;
public String actionItem; 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. // How much should we scale the icon at most.
private static final float MAX_ICON_PROGRESS = 0.65f; private static final float MAX_ICON_PROGRESS = 0.65f;
private float progressToCenter;
@Override @Override
public void onLayoutFinished(View child, RecyclerView parent) { public void onLayoutFinished(View child, RecyclerView parent) {
@ -121,7 +139,7 @@ public abstract class MenuListActivity extends Activity {
float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset; float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset;
// Normalize for center // Normalize for center
progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset); float progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);
// Adjust to the maximum scale // Adjust to the maximum scale
progressToCenter = Math.min(progressToCenter, MAX_ICON_PROGRESS); progressToCenter = Math.min(progressToCenter, MAX_ICON_PROGRESS);

View file

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

View file

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

View file

@ -3,11 +3,23 @@
android:layout_width="match_parent" 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 <TextView
android:id="@+id/title" android:id="@+id/title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="26dp" android:layout_height="26dp"
android:autoSizeMaxTextSize="18sp"
android:autoSizeMinTextSize="12sp"
android:autoSizeTextType="uniform"
android:gravity="center" android:gravity="center"
android:text="Title"
android:textSize="18sp" /> android:textSize="18sp" />
<android.support.wearable.view.GridViewPager <android.support.wearable.view.GridViewPager
@ -20,7 +32,6 @@
android:id="@+id/page_indicator" android:id="@+id/page_indicator"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"> android:layout_gravity="center_horizontal|bottom" />
</android.support.wearable.view.DotsPageIndicator>
</FrameLayout> </FrameLayout>

View file

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

View file

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