second channel for bolus progress and wear cleanups

This commit is contained in:
AdrianLxM 2021-01-22 15:59:13 +01:00
parent cd4bed2d1a
commit 0e48db2096
26 changed files with 332 additions and 351 deletions

View file

@ -10,7 +10,7 @@
<application <application
android:name=".aaps" android:name=".Aaps"
android:allowBackup="true" android:allowBackup="true"
android:icon="@drawable/ic_icon" android:icon="@drawable/ic_icon"
android:label="@string/app_name" android:label="@string/app_name"

View file

@ -5,19 +5,16 @@ import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import androidx.annotation.StringRes;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import info.nightscout.androidaps.interaction.utils.Persistence;
/** /**
* Created for xDrip+ by Emma Black on 3/21/15. * Created for xDrip+ by Emma Black on 3/21/15.
* Adapted for AAPS by dlvoy 2019-11-06. * Adapted for AAPS by dlvoy 2019-11-06.
*/ */
public class aaps extends Application implements SharedPreferences.OnSharedPreferenceChangeListener { public class Aaps extends Application implements SharedPreferences.OnSharedPreferenceChangeListener {
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
private static Context context; private static Context context;
@ -26,7 +23,7 @@ public class aaps extends Application implements SharedPreferences.OnSharedPrefe
@Override @Override
public void onCreate() { public void onCreate() {
aaps.context = getApplicationContext(); Aaps.context = getApplicationContext();
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
sharedPrefs.registerOnSharedPreferenceChangeListener(this); sharedPrefs.registerOnSharedPreferenceChangeListener(this);
updatePrefs(sharedPrefs); updatePrefs(sharedPrefs);
@ -39,19 +36,7 @@ public class aaps extends Application implements SharedPreferences.OnSharedPrefe
} }
public static Context getAppContext() { public static Context getAppContext() {
return aaps.context; return Aaps.context;
}
private static boolean isWear2OrAbove() {
return Build.VERSION.SDK_INT > 23;
}
public static String gs(@StringRes final int id) {
return getAppContext().getString(id);
}
public static String gs(@StringRes final int id, String... args) {
return getAppContext().getString(id, (Object[]) args);
} }
public static Boolean areComplicationsUnicode() { public static Boolean areComplicationsUnicode() {

View file

@ -19,7 +19,7 @@ import java.util.Set;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.Aaps;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.Constants; import info.nightscout.androidaps.interaction.utils.Constants;
@ -94,11 +94,11 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
} }
break; break;
case ComplicationData.TYPE_LONG_TEXT: case ComplicationData.TYPE_LONG_TEXT:
builder.setLongTitle(ComplicationText.plainText(aaps.gs(R.string.label_warning_sync))); builder.setLongTitle(ComplicationText.plainText(getString(R.string.label_warning_sync)));
if (since > 0) { if (since > 0) {
builder.setLongText(ComplicationText.plainText(String.format(aaps.gs(R.string.label_warning_since), DisplayFormat.shortTimeSince(since)))); builder.setLongText(ComplicationText.plainText(String.format(getString(R.string.label_warning_since), DisplayFormat.shortTimeSince(since))));
} else { } else {
builder.setLongText(ComplicationText.plainText(aaps.gs(R.string.label_warning_sync_aaps))); builder.setLongText(ComplicationText.plainText(getString(R.string.label_warning_sync_aaps)));
} }
break; break;
case ComplicationData.TYPE_LARGE_IMAGE: case ComplicationData.TYPE_LARGE_IMAGE:
@ -143,11 +143,11 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
} }
break; break;
case ComplicationData.TYPE_LONG_TEXT: case ComplicationData.TYPE_LONG_TEXT:
builder.setLongTitle(ComplicationText.plainText(aaps.gs(R.string.label_warning_old))); builder.setLongTitle(ComplicationText.plainText(getString(R.string.label_warning_old)));
if (since > 0) { if (since > 0) {
builder.setLongText(ComplicationText.plainText(String.format(aaps.gs(R.string.label_warning_since), DisplayFormat.shortTimeSince(since)))); builder.setLongText(ComplicationText.plainText(String.format(getString(R.string.label_warning_since), DisplayFormat.shortTimeSince(since))));
} else { } else {
builder.setLongText(ComplicationText.plainText(aaps.gs(R.string.label_warning_sync_aaps))); builder.setLongText(ComplicationText.plainText(getString(R.string.label_warning_sync_aaps)));
} }
break; break;
case ComplicationData.TYPE_LARGE_IMAGE: case ComplicationData.TYPE_LARGE_IMAGE:
@ -223,7 +223,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
// We pass the complication id, so we can only update the specific complication tapped. // We pass the complication id, so we can only update the specific complication tapped.
final PendingIntent complicationPendingIntent = final PendingIntent complicationPendingIntent =
ComplicationTapBroadcastReceiver.getTapActionIntent( ComplicationTapBroadcastReceiver.getTapActionIntent(
aaps.getAppContext(), thisProvider, complicationId, getComplicationAction()); Aaps.getAppContext(), thisProvider, complicationId, getComplicationAction());
final Persistence persistence = new Persistence(); final Persistence persistence = new Persistence();
@ -242,12 +242,12 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
if (WearUtil.msSince(persistence.whenDataUpdated()) > Constants.STALE_MS) { if (WearUtil.msSince(persistence.whenDataUpdated()) > Constants.STALE_MS) {
// no new data arrived - probably configuration or connection error // no new data arrived - probably configuration or connection error
final PendingIntent infoToast = ComplicationTapBroadcastReceiver.getTapWarningSinceIntent( final PendingIntent infoToast = ComplicationTapBroadcastReceiver.getTapWarningSinceIntent(
aaps.getAppContext(), thisProvider, complicationId, ComplicationAction.WARNING_SYNC, persistence.whenDataUpdated()); Aaps.getAppContext(), thisProvider, complicationId, ComplicationAction.WARNING_SYNC, persistence.whenDataUpdated());
complicationData = buildNoSyncComplicationData(dataType, raw, complicationPendingIntent, infoToast, persistence.whenDataUpdated()); complicationData = buildNoSyncComplicationData(dataType, raw, complicationPendingIntent, infoToast, persistence.whenDataUpdated());
} else if (WearUtil.msSince(raw.datetime) > Constants.STALE_MS) { } else if (WearUtil.msSince(raw.datetime) > Constants.STALE_MS) {
// data arriving from phone AAPS, but it is outdated (uploader/NS/xDrip/Sensor error) // data arriving from phone AAPS, but it is outdated (uploader/NS/xDrip/Sensor error)
final PendingIntent infoToast = ComplicationTapBroadcastReceiver.getTapWarningSinceIntent( final PendingIntent infoToast = ComplicationTapBroadcastReceiver.getTapWarningSinceIntent(
aaps.getAppContext(), thisProvider, complicationId, ComplicationAction.WARNING_OLD, raw.datetime); Aaps.getAppContext(), thisProvider, complicationId, ComplicationAction.WARNING_OLD, raw.datetime);
complicationData = buildOutdatedComplicationData(dataType, raw, complicationPendingIntent, infoToast, raw.datetime); complicationData = buildOutdatedComplicationData(dataType, raw, complicationPendingIntent, infoToast, raw.datetime);
} else { } else {
// data is up-to-date, we can render standard complication // data is up-to-date, we can render standard complication
@ -349,8 +349,8 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
Inevitable.task("update-req-"+provider, 700, () -> { Inevitable.task("update-req-"+provider, 700, () -> {
if (WearUtil.isBelowRateLimit("update-req-"+provider, 2)) { if (WearUtil.isBelowRateLimit("update-req-"+provider, 2)) {
Log.d(TAG, "Requesting update of "+provider); Log.d(TAG, "Requesting update of "+provider);
final ComponentName componentName = new ComponentName(aaps.getAppContext(), provider); final ComponentName componentName = new ComponentName(Aaps.getAppContext(), provider);
final ProviderUpdateRequester providerUpdateRequester = new ProviderUpdateRequester(aaps.getAppContext(), componentName); final ProviderUpdateRequester providerUpdateRequester = new ProviderUpdateRequester(Aaps.getAppContext(), componentName);
providerUpdateRequester.requestUpdateAll(); providerUpdateRequester.requestUpdateAll();
} }
}); });

View file

@ -13,7 +13,7 @@ import android.widget.Toast;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.Aaps;
import info.nightscout.androidaps.interaction.actions.BolusActivity; import info.nightscout.androidaps.interaction.actions.BolusActivity;
import info.nightscout.androidaps.interaction.actions.ECarbActivity; import info.nightscout.androidaps.interaction.actions.ECarbActivity;
import info.nightscout.androidaps.interaction.actions.WizardActivity; import info.nightscout.androidaps.interaction.actions.WizardActivity;
@ -67,16 +67,16 @@ public class ComplicationTapBroadcastReceiver extends BroadcastReceiver {
// do nothing // do nothing
return; return;
case WIZARD: case WIZARD:
intentOpen = new Intent(aaps.getAppContext(), WizardActivity.class); intentOpen = new Intent(Aaps.getAppContext(), WizardActivity.class);
break; break;
case BOLUS: case BOLUS:
intentOpen = new Intent(aaps.getAppContext(), BolusActivity.class); intentOpen = new Intent(Aaps.getAppContext(), BolusActivity.class);
break; break;
case ECARB: case ECARB:
intentOpen = new Intent(aaps.getAppContext(), ECarbActivity.class); intentOpen = new Intent(Aaps.getAppContext(), ECarbActivity.class);
break; break;
case STATUS: case STATUS:
intentOpen = new Intent(aaps.getAppContext(), StatusMenuActivity.class); intentOpen = new Intent(Aaps.getAppContext(), StatusMenuActivity.class);
break; break;
case WARNING_OLD: case WARNING_OLD:
case WARNING_SYNC: case WARNING_SYNC:
@ -84,23 +84,23 @@ public class ComplicationTapBroadcastReceiver extends BroadcastReceiver {
long since = extras.getLong(EXTRA_COMPLICATION_SINCE, oneAndHalfMinuteAgo); long since = extras.getLong(EXTRA_COMPLICATION_SINCE, oneAndHalfMinuteAgo);
@StringRes int labelId = (action == ComplicationAction.WARNING_SYNC) ? @StringRes int labelId = (action == ComplicationAction.WARNING_SYNC) ?
R.string.msg_warning_sync : R.string.msg_warning_old; R.string.msg_warning_sync : R.string.msg_warning_old;
String msg = String.format(aaps.gs(labelId), DisplayFormat.shortTimeSince(since)); String msg = String.format(context.getString(labelId), DisplayFormat.shortTimeSince(since));
Toast.makeText(aaps.getAppContext(), msg, Toast.LENGTH_LONG).show(); Toast.makeText(Aaps.getAppContext(), msg, Toast.LENGTH_LONG).show();
break; break;
case MENU: case MENU:
default: default:
intentOpen = new Intent(aaps.getAppContext(), MainMenuActivity.class); intentOpen = new Intent(Aaps.getAppContext(), MainMenuActivity.class);
} }
if (intentOpen != null) { if (intentOpen != null) {
// Perform intent - open dialog // Perform intent - open dialog
intentOpen.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intentOpen.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
aaps.getAppContext().startActivity(intentOpen); Aaps.getAppContext().startActivity(intentOpen);
} }
} }
private ComplicationAction remapActionWithUserPreferences(ComplicationAction originalAction) { private ComplicationAction remapActionWithUserPreferences(ComplicationAction originalAction) {
final String userPrefAction = aaps.getComplicationTapAction(); final String userPrefAction = Aaps.getComplicationTapAction();
switch (originalAction) { switch (originalAction) {
case WARNING_OLD: case WARNING_OLD:
case WARNING_SYNC: case WARNING_SYNC:

View file

@ -14,7 +14,7 @@ import android.view.WindowManager;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.Aaps;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
/* /*
@ -33,7 +33,7 @@ public abstract class WallpaperComplication extends BaseComplicationProviderServ
if (dataType == ComplicationData.TYPE_LARGE_IMAGE) { if (dataType == ComplicationData.TYPE_LARGE_IMAGE) {
DisplayMetrics metrics = new DisplayMetrics(); DisplayMetrics metrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) aaps.getAppContext() WindowManager windowManager = (WindowManager) Aaps.getAppContext()
.getSystemService(Context.WINDOW_SERVICE); .getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(metrics); windowManager.getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels; int width = metrics.widthPixels;

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.data; package info.nightscout.androidaps.data;
import android.annotation.TargetApi;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
@ -37,7 +38,6 @@ import com.google.android.gms.wearable.WearableListenerService;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.aaps;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interaction.AAPSPreferences; import info.nightscout.androidaps.interaction.AAPSPreferences;
import info.nightscout.androidaps.interaction.actions.AcceptActivity; import info.nightscout.androidaps.interaction.actions.AcceptActivity;
@ -82,7 +82,8 @@ public class ListenerService extends WearableListenerService implements GoogleAp
private static final String ACTION_RESEND_BULK = "com.dexdrip.stephenblack.nightwatch.RESEND_BULK_DATA"; private static final String ACTION_RESEND_BULK = "com.dexdrip.stephenblack.nightwatch.RESEND_BULK_DATA";
private static final String AAPS_NOTIFY_CHANNEL_ID_OPENLOOP = "AndroidAPS-Openloop"; private static final String AAPS_NOTIFY_CHANNEL_ID_OPENLOOP = "AndroidAPS-Openloop";
private static final String AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS = "AndroidAPS-bolus-progress"; private static final String AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS = "bolus progress vibration";
private static final String AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS_SILENT = "bolus progress silent";
GoogleApiClient googleApiClient; GoogleApiClient googleApiClient;
@ -616,17 +617,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "AAPS Bolus Progress"; createBolusProgressChannels();
String description = "Bolus progress and cancel";
NotificationChannel channel = new NotificationChannel(AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS, name, NotificationManager.IMPORTANCE_HIGH);
channel.setDescription(description);
channel.enableVibration(true);
channel.setVibrationPattern(vibratePattern);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
} }
Intent cancelIntent = new Intent(this, ListenerService.class); Intent cancelIntent = new Intent(this, ListenerService.class);
@ -634,15 +625,15 @@ public class ListenerService extends WearableListenerService implements GoogleAp
PendingIntent cancelPendingIntent = PendingIntent.getService(this, 0, cancelIntent, 0); PendingIntent cancelPendingIntent = PendingIntent.getService(this, 0, cancelIntent, 0);
NotificationCompat.Builder notificationBuilder = NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS) new NotificationCompat.Builder(this, vibrate ? AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS: AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS_SILENT)
.setSmallIcon(R.drawable.ic_icon) .setSmallIcon(R.drawable.ic_icon)
.setContentTitle(aaps.gs(R.string.bolus_progress)) .setContentTitle(getString(R.string.bolus_progress))
.setContentText(progresspercent + "% - " + progresstatus) .setContentText(progresspercent + "% - " + progresstatus)
.setSubText(aaps.gs(R.string.press_to_cancel)) .setSubText(getString(R.string.press_to_cancel))
.setContentIntent(cancelPendingIntent) .setContentIntent(cancelPendingIntent)
.setPriority(NotificationCompat.PRIORITY_MAX) .setPriority(NotificationCompat.PRIORITY_MAX)
.setVibrate(vibratePattern) .setVibrate(vibratePattern)
.addAction(R.drawable.ic_cancel, aaps.gs(R.string.cancel_bolus), cancelPendingIntent); .addAction(R.drawable.ic_cancel, getString(R.string.cancel_bolus), cancelPendingIntent);
NotificationManagerCompat notificationManager = NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this); NotificationManagerCompat.from(this);
@ -656,6 +647,25 @@ public class ListenerService extends WearableListenerService implements GoogleAp
} }
} }
@TargetApi(value = 26)
private void createBolusProgressChannels() {
createNotificationChannel(new long[]{0, 50, 1000}, AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS, getString(R.string.bolus_progress_channel_name), getString(R.string.bolus_progress_channel_description));
createNotificationChannel(new long[]{0, 1, 1000}, AAPS_NOTIFY_CHANNEL_ID_BOLUSPROGRESS_SILENT, getString(R.string.bolus_progress_silent_channel_name), getString(R.string.bolus_progress_silent_channel_description));
}
@TargetApi(value = 26)
private void createNotificationChannel(long[] vibratePattern, String channelID, CharSequence name, String description) {
NotificationChannel channel = new NotificationChannel(channelID, name, NotificationManager.IMPORTANCE_HIGH);
channel.setDescription(description);
channel.enableVibration(true);
channel.setVibrationPattern(vibratePattern);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
private void showConfirmationDialog(String title, String message, String actionstring) { private void showConfirmationDialog(String title, String message, String actionstring) {
Intent intent = new Intent(this, AcceptActivity.class); Intent intent = new Intent(this, AcceptActivity.class);

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.interaction.actions; package info.nightscout.androidaps.interaction.actions;
import android.app.Activity;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.DotsPageIndicator;
@ -11,12 +10,10 @@ 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 info.nightscout.androidaps.R;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.aaps;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.androidaps.interaction.utils.SafeParse;
@ -65,24 +62,24 @@ public class BolusActivity extends ViewSelectorActivity {
@Override @Override
public Object instantiateItem(ViewGroup container, int row, int col) { public Object instantiateItem(ViewGroup container, int row, int col) {
if(col == 0){ if (col == 0) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);
double def = 0; double def = 0;
if (editInsulin != null){ if (editInsulin != null) {
def = SafeParse.stringToDouble(editInsulin.editText.getText().toString()); def = SafeParse.stringToDouble(editInsulin.editText.getText().toString());
} }
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, aaps.gs(R.string.action_insulin)); setLabelToPlusMinusView(view, getString(R.string.action_insulin));
container.addView(view); container.addView(view);
return view; return view;
} else if(col == 1){ } else if (col == 1) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);
double def = 0; double def = 0;
if (editCarbs != null){ if (editCarbs != null) {
def = SafeParse.stringToDouble(editCarbs.editText.getText().toString()); 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, aaps.gs(R.string.action_carbs)); setLabelToPlusMinusView(view, getString(R.string.action_carbs));
container.addView(view); container.addView(view);
return view; return view;
} else { } else {
@ -96,7 +93,7 @@ public class BolusActivity extends ViewSelectorActivity {
//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);
finish(); finish();
@ -111,12 +108,12 @@ public class BolusActivity extends ViewSelectorActivity {
public void destroyItem(ViewGroup container, int row, int col, Object view) { public void destroyItem(ViewGroup container, int row, int col, Object view) {
// Handle this to get the data before the view is destroyed? // Handle this to get the data before the view is destroyed?
// Object should still be kept by this, just setup for reinit? // Object should still be kept by this, just setup for reinit?
container.removeView((View)view); container.removeView((View) view);
} }
@Override @Override
public boolean isViewFromObject(View view, Object object) { public boolean isViewFromObject(View view, Object object) {
return view==object; return view == object;
} }

View file

@ -14,7 +14,6 @@ import android.widget.ImageView;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.aaps;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.androidaps.interaction.utils.SafeParse;
@ -40,11 +39,12 @@ public class CPPActivity extends ViewSelectorActivity {
percentage = extras.getInt("percentage", -1); percentage = extras.getInt("percentage", -1);
timeshift = extras.getInt("timeshift", -1); timeshift = extras.getInt("timeshift", -1);
if (percentage ==-1 || timeshift ==-25){ if (percentage == -1 || timeshift == -25) {
finish(); return; finish();
return;
} }
if(timeshift < 0) timeshift += 24; if (timeshift < 0) timeshift += 24;
setContentView(R.layout.grid_layout); setContentView(R.layout.grid_layout);
final Resources res = getResources(); final Resources res = getResources();
@ -77,24 +77,24 @@ public class CPPActivity extends ViewSelectorActivity {
@Override @Override
public Object instantiateItem(ViewGroup container, int row, int col) { public Object instantiateItem(ViewGroup container, int row, int col) {
if(col == 0){ if (col == 0) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);
double def = timeshift; double def = timeshift;
if (editTimeshift != null){ if (editTimeshift != null) {
def = SafeParse.stringToDouble(editTimeshift.editText.getText().toString()); def = SafeParse.stringToDouble(editTimeshift.editText.getText().toString());
} }
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, aaps.gs(R.string.action_timeshift)); setLabelToPlusMinusView(view, getString(R.string.action_timeshift));
container.addView(view); container.addView(view);
return view; return view;
} else if(col == 1){ } else if (col == 1) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);
double def = percentage; double def = percentage;
if (editPercentage != null){ if (editPercentage != null) {
def = SafeParse.stringToDouble(editPercentage.editText.getText().toString()); def = SafeParse.stringToDouble(editPercentage.editText.getText().toString());
} }
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 30d, 250d, 1d, new DecimalFormat("0"), false); editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 30d, 250d, 1d, new DecimalFormat("0"), false);
setLabelToPlusMinusView(view, aaps.gs(R.string.action_percentage)); setLabelToPlusMinusView(view, getString(R.string.action_percentage));
container.addView(view); container.addView(view);
return view; return view;
} else { } else {
@ -108,7 +108,7 @@ public class CPPActivity extends ViewSelectorActivity {
//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 = "cppset " +SafeParse.stringToInt(editTimeshift.editText.getText().toString()) String actionstring = "cppset " + SafeParse.stringToInt(editTimeshift.editText.getText().toString())
+ " " + SafeParse.stringToInt(editPercentage.editText.getText().toString()); + " " + SafeParse.stringToInt(editPercentage.editText.getText().toString());
ListenerService.initiateAction(CPPActivity.this, actionstring); ListenerService.initiateAction(CPPActivity.this, actionstring);
finish(); finish();
@ -123,12 +123,12 @@ public class CPPActivity extends ViewSelectorActivity {
public void destroyItem(ViewGroup container, int row, int col, Object view) { public void destroyItem(ViewGroup container, int row, int col, Object view) {
// Handle this to get the data before the view is destroyed? // Handle this to get the data before the view is destroyed?
// Object should still be kept by this, just setup for reinit? // Object should still be kept by this, just setup for reinit?
container.removeView((View)view); container.removeView((View) view);
} }
@Override @Override
public boolean isViewFromObject(View view, Object object) { public boolean isViewFromObject(View view, Object object) {
return view==object; return view == object;
} }

View file

@ -14,7 +14,6 @@ import android.widget.ImageView;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.aaps;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.androidaps.interaction.utils.SafeParse;
@ -72,7 +71,7 @@ public class ECarbActivity extends ViewSelectorActivity {
def = SafeParse.stringToDouble(editCarbs.editText.getText().toString()); 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); editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 150d, 1d, new DecimalFormat("0"), true);
setLabelToPlusMinusView(view, aaps.gs(R.string.action_carbs)); setLabelToPlusMinusView(view, getString(R.string.action_carbs));
container.addView(view); container.addView(view);
return view; return view;
} else if(col == 1){ } else if(col == 1){
@ -82,7 +81,7 @@ public class ECarbActivity extends ViewSelectorActivity {
def = SafeParse.stringToDouble(editStartTime.editText.getText().toString()); 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); editStartTime = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 300d, 15d, new DecimalFormat("0"), false);
setLabelToPlusMinusView(view, aaps.gs(R.string.action_start_min)); setLabelToPlusMinusView(view, getString(R.string.action_start_min));
container.addView(view); container.addView(view);
return view; return view;
} else if(col == 2){ } else if(col == 2){
@ -92,7 +91,7 @@ public class ECarbActivity extends ViewSelectorActivity {
def = SafeParse.stringToDouble(editDuration.editText.getText().toString()); 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); editDuration = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 8d, 1d, new DecimalFormat("0"), false);
setLabelToPlusMinusView(view, aaps.gs(R.string.action_duration_h)); setLabelToPlusMinusView(view, getString(R.string.action_duration_h));
container.addView(view); container.addView(view);
return view; return view;
} else { } else {

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.interaction.actions; package info.nightscout.androidaps.interaction.actions;
import android.app.Activity;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.DotsPageIndicator;
@ -11,12 +10,10 @@ 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;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.aaps;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.androidaps.interaction.utils.SafeParse;
@ -64,14 +61,14 @@ public class FillActivity extends ViewSelectorActivity {
@Override @Override
public Object instantiateItem(ViewGroup container, int row, int col) { public Object instantiateItem(ViewGroup container, int row, int col) {
if(col == 0){ if (col == 0) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);
double def = 0d; double def = 0d;
if (editInsulin != null){ if (editInsulin != null) {
def = SafeParse.stringToDouble(editInsulin.editText.getText().toString()); def = SafeParse.stringToDouble(editInsulin.editText.getText().toString());
} }
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, aaps.gs(R.string.action_insulin)); setLabelToPlusMinusView(view, getString(R.string.action_insulin));
container.addView(view); container.addView(view);
return view; return view;
} else { } else {
@ -85,7 +82,7 @@ public class FillActivity extends ViewSelectorActivity {
//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 = "fill " +SafeParse.stringToDouble(editInsulin.editText.getText().toString()); String actionstring = "fill " + SafeParse.stringToDouble(editInsulin.editText.getText().toString());
ListenerService.initiateAction(FillActivity.this, actionstring); ListenerService.initiateAction(FillActivity.this, actionstring);
finish(); finish();
} }
@ -99,12 +96,12 @@ public class FillActivity extends ViewSelectorActivity {
public void destroyItem(ViewGroup container, int row, int col, Object view) { public void destroyItem(ViewGroup container, int row, int col, Object view) {
// Handle this to get the data before the view is destroyed? // Handle this to get the data before the view is destroyed?
// Object should still be kept by this, just setup for reinit? // Object should still be kept by this, just setup for reinit?
container.removeView((View)view); container.removeView((View) view);
} }
@Override @Override
public boolean isViewFromObject(View view, Object object) { public boolean isViewFromObject(View view, Object object) {
return view==object; return view == object;
} }

View file

@ -17,7 +17,6 @@ import android.widget.TextView;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.aaps;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.androidaps.interaction.utils.SafeParse;
@ -62,7 +61,7 @@ public class TempTargetActivity extends ViewSelectorActivity {
private class MyGridViewPagerAdapter extends GridPagerAdapter { private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override @Override
public int getColumnCount(int arg0) { public int getColumnCount(int arg0) {
return isSingleTarget?3:4; return isSingleTarget ? 3 : 4;
} }
@Override @Override
@ -73,7 +72,7 @@ public class TempTargetActivity extends ViewSelectorActivity {
@Override @Override
public Object instantiateItem(ViewGroup container, int row, int col) { public Object instantiateItem(ViewGroup container, int row, int col) {
if(col == 0){ if (col == 0) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);
final TextView textView = view.findViewById(R.id.label); final TextView textView = view.findViewById(R.id.label);
textView.setText("duration"); textView.setText("duration");
@ -83,51 +82,51 @@ public class TempTargetActivity extends ViewSelectorActivity {
double def = SafeParse.stringToDouble(time.editText.getText().toString()); double def = SafeParse.stringToDouble(time.editText.getText().toString());
time = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 24 * 60d, 5d, new DecimalFormat("0"), false); time = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 24 * 60d, 5d, new DecimalFormat("0"), false);
} }
setLabelToPlusMinusView(view, aaps.gs(R.string.action_duration)); setLabelToPlusMinusView(view, getString(R.string.action_duration));
container.addView(view); container.addView(view);
return view; return view;
} else if(col == 1){ } else if (col == 1) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);
if (isMGDL){ if (isMGDL) {
double def = 100; double def = 100;
if (lowRange != null){ if (lowRange != null) {
def = SafeParse.stringToDouble(lowRange.editText.getText().toString()); def = SafeParse.stringToDouble(lowRange.editText.getText().toString());
} }
lowRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 72d, 180d, 1d, new DecimalFormat("0"), false); lowRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 72d, 180d, 1d, new DecimalFormat("0"), false);
} else { } else {
double def = 5.5; double def = 5.5;
if (lowRange != null){ if (lowRange != null) {
def = SafeParse.stringToDouble(lowRange.editText.getText().toString()); def = SafeParse.stringToDouble(lowRange.editText.getText().toString());
} }
lowRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 4d, 10d, 0.1d, new DecimalFormat("#0.0"), false); lowRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 4d, 10d, 0.1d, new DecimalFormat("#0.0"), false);
} }
if(isSingleTarget){ if (isSingleTarget) {
setLabelToPlusMinusView(view, aaps.gs(R.string.action_target)); setLabelToPlusMinusView(view, getString(R.string.action_target));
} else { } else {
setLabelToPlusMinusView(view, aaps.gs(R.string.action_low)); setLabelToPlusMinusView(view, getString(R.string.action_low));
} }
container.addView(view); container.addView(view);
return view; return view;
} else if(col == 2 && ! isSingleTarget){ } else if (col == 2 && !isSingleTarget) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);
if (isMGDL){ if (isMGDL) {
double def = 100; double def = 100;
if (highRange != null){ if (highRange != null) {
def = SafeParse.stringToDouble(highRange.editText.getText().toString()); def = SafeParse.stringToDouble(highRange.editText.getText().toString());
} }
highRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 72d, 180d, 1d, new DecimalFormat("0"), false); highRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 72d, 180d, 1d, new DecimalFormat("0"), false);
} else { } else {
double def = 5.5; double def = 5.5;
if (highRange != null){ if (highRange != null) {
def = SafeParse.stringToDouble(highRange.editText.getText().toString()); def = SafeParse.stringToDouble(highRange.editText.getText().toString());
} }
highRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 4d, 10d, 0.1d, new DecimalFormat("#0.0"), false); highRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 4d, 10d, 0.1d, new DecimalFormat("#0.0"), false);
} }
setLabelToPlusMinusView(view, aaps.gs(R.string.action_high)); setLabelToPlusMinusView(view, getString(R.string.action_high));
container.addView(view); container.addView(view);
return view; return view;
}else { } else {
final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false); final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false);
final ImageView confirmbutton = view.findViewById(R.id.confirmbutton); final ImageView confirmbutton = view.findViewById(R.id.confirmbutton);
@ -142,8 +141,7 @@ public class TempTargetActivity extends ViewSelectorActivity {
+ " " + isMGDL + " " + isMGDL
+ " " + SafeParse.stringToInt(time.editText.getText().toString()) + " " + SafeParse.stringToInt(time.editText.getText().toString())
+ " " + SafeParse.stringToDouble(lowRange.editText.getText().toString()) + " " + SafeParse.stringToDouble(lowRange.editText.getText().toString())
+ " " + (isSingleTarget?SafeParse.stringToDouble(lowRange.editText.getText().toString()):SafeParse.stringToDouble(highRange.editText.getText().toString())) + " " + (isSingleTarget ? SafeParse.stringToDouble(lowRange.editText.getText().toString()) : SafeParse.stringToDouble(highRange.editText.getText().toString()));
;
ListenerService.initiateAction(TempTargetActivity.this, actionstring); ListenerService.initiateAction(TempTargetActivity.this, actionstring);
finish(); finish();
@ -158,12 +156,12 @@ public class TempTargetActivity extends ViewSelectorActivity {
public void destroyItem(ViewGroup container, int row, int col, Object view) { public void destroyItem(ViewGroup container, int row, int col, Object view) {
// Handle this to get the data before the view is destroyed? // Handle this to get the data before the view is destroyed?
// Object should still be kept by this, just setup for reinit? // Object should still be kept by this, just setup for reinit?
container.removeView((View)view); container.removeView((View) view);
} }
@Override @Override
public boolean isViewFromObject(View view, Object object) { public boolean isViewFromObject(View view, Object object) {
return view==object; return view == object;
} }

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.interaction.actions; package info.nightscout.androidaps.interaction.actions;
import android.app.Activity;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
@ -13,13 +12,11 @@ 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;
import info.nightscout.androidaps.aaps;
import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
import info.nightscout.androidaps.interaction.utils.SafeParse; import info.nightscout.androidaps.interaction.utils.SafeParse;
@ -61,7 +58,7 @@ public class WizardActivity extends ViewSelectorActivity {
private class MyGridViewPagerAdapter extends GridPagerAdapter { private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override @Override
public int getColumnCount(int arg0) { public int getColumnCount(int arg0) {
return hasPercentage?3:2; return hasPercentage ? 3 : 2;
} }
@Override @Override
@ -72,7 +69,7 @@ public class WizardActivity extends ViewSelectorActivity {
@Override @Override
public Object instantiateItem(ViewGroup container, int row, int col) { public Object instantiateItem(ViewGroup container, int row, int col) {
if(col == 0){ if (col == 0) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);
if (editCarbs == null) { if (editCarbs == null) {
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 0d, 0d, 150d, 1d, new DecimalFormat("0"), false); editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 0d, 0d, 150d, 1d, new DecimalFormat("0"), false);
@ -81,10 +78,10 @@ public class WizardActivity extends ViewSelectorActivity {
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, aaps.gs(R.string.action_carbs)); setLabelToPlusMinusView(view, getString(R.string.action_carbs));
container.addView(view); container.addView(view);
return view; return view;
} else if(col == 1 && hasPercentage){ } else if (col == 1 && hasPercentage) {
final View view = getInflatedPlusMinusView(container); final View view = getInflatedPlusMinusView(container);
if (editPercentage == null) { if (editPercentage == null) {
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 100d, 50d, 150d, 1d, new DecimalFormat("0"), false); editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 100d, 50d, 150d, 1d, new DecimalFormat("0"), false);
@ -92,7 +89,7 @@ public class WizardActivity extends ViewSelectorActivity {
double def = SafeParse.stringToDouble(editPercentage.editText.getText().toString()); double def = SafeParse.stringToDouble(editPercentage.editText.getText().toString());
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 50d, 150d, 1d, new DecimalFormat("0"), false); editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 50d, 150d, 1d, new DecimalFormat("0"), false);
} }
setLabelToPlusMinusView(view, aaps.gs(R.string.action_percentage)); setLabelToPlusMinusView(view, getString(R.string.action_percentage));
container.addView(view); container.addView(view);
return view; return view;
} else { } else {
@ -108,7 +105,8 @@ public class WizardActivity extends ViewSelectorActivity {
int percentage = 100; int percentage = 100;
if (editPercentage != null) percentage = SafeParse.stringToInt(editPercentage.editText.getText().toString()); if (editPercentage != null)
percentage = SafeParse.stringToInt(editPercentage.editText.getText().toString());
String actionstring = "wizard2 " + SafeParse.stringToInt(editCarbs.editText.getText().toString()) String actionstring = "wizard2 " + SafeParse.stringToInt(editCarbs.editText.getText().toString())
+ " " + percentage; + " " + percentage;
@ -125,12 +123,12 @@ public class WizardActivity extends ViewSelectorActivity {
public void destroyItem(ViewGroup container, int row, int col, Object view) { public void destroyItem(ViewGroup container, int row, int col, Object view) {
// Handle this to get the data before the view is destroyed? // Handle this to get the data before the view is destroyed?
// Object should still be kept by this, just setup for reinit? // Object should still be kept by this, just setup for reinit?
container.removeView((View)view); container.removeView((View) view);
} }
@Override @Override
public boolean isViewFromObject(View view, Object object) { public boolean isViewFromObject(View view, Object object) {
return view==object; return view == object;
} }

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.interaction.menus;
import android.content.Intent; import android.content.Intent;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.aaps;
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;
import info.nightscout.androidaps.interaction.utils.MenuListActivity; import info.nightscout.androidaps.interaction.utils.MenuListActivity;
@ -17,22 +16,22 @@ public class FillMenuActivity extends MenuListActivity {
@Override @Override
protected String[] getElements() { protected String[] getElements() {
return new String[]{ return new String[]{
aaps.gs(R.string.action_preset_1), getString(R.string.action_preset_1),
aaps.gs(R.string.action_preset_2), getString(R.string.action_preset_2),
aaps.gs(R.string.action_preset_3), getString(R.string.action_preset_3),
aaps.gs(R.string.action_free_amount) getString(R.string.action_free_amount)
}; };
} }
@Override @Override
protected void doAction(String action) { protected void doAction(String action) {
if (aaps.gs(R.string.action_preset_1).equals(action)) { if (getString(R.string.action_preset_1).equals(action)) {
ListenerService.initiateAction(this, "fillpreset 1"); ListenerService.initiateAction(this, "fillpreset 1");
} else if (aaps.gs(R.string.action_preset_2).equals(action)) { } else if (getString(R.string.action_preset_2).equals(action)) {
ListenerService.initiateAction(this, "fillpreset 2"); ListenerService.initiateAction(this, "fillpreset 2");
} else if (aaps.gs(R.string.action_preset_3).equals(action)) { } else if (getString(R.string.action_preset_3).equals(action)) {
ListenerService.initiateAction(this, "fillpreset 3"); ListenerService.initiateAction(this, "fillpreset 3");
} else if (aaps.gs(R.string.action_free_amount).equals(action)) { } else if (getString(R.string.action_free_amount).equals(action)) {
Intent intent = new Intent(this, FillActivity.class); Intent intent = new Intent(this, FillActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent); this.startActivity(intent);

View file

@ -8,10 +8,8 @@ import android.preference.PreferenceManager;
import java.util.Vector; import java.util.Vector;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.aaps;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.AAPSPreferences; import info.nightscout.androidaps.interaction.AAPSPreferences;
import info.nightscout.androidaps.interaction.actions.AcceptActivity;
import info.nightscout.androidaps.interaction.actions.BolusActivity; import info.nightscout.androidaps.interaction.actions.BolusActivity;
import info.nightscout.androidaps.interaction.actions.ECarbActivity; import info.nightscout.androidaps.interaction.actions.ECarbActivity;
import info.nightscout.androidaps.interaction.actions.TempTargetActivity; import info.nightscout.androidaps.interaction.actions.TempTargetActivity;
@ -39,8 +37,8 @@ public class MainMenuActivity extends MenuListActivity {
if(!sharedPreferences.getBoolean("wearcontrol", false)){ if(!sharedPreferences.getBoolean("wearcontrol", false)){
return new String[] { return new String[] {
aaps.gs(R.string.menu_settings), getString(R.string.menu_settings),
aaps.gs(R.string.menu_resync)}; getString(R.string.menu_resync)};
} }
@ -48,13 +46,13 @@ public class MainMenuActivity extends MenuListActivity {
boolean showWizard = sp.getBoolean("showWizard", true); boolean showWizard = sp.getBoolean("showWizard", true);
Vector<String> menuitems = new Vector<String>(); Vector<String> menuitems = new Vector<String>();
menuitems.add(aaps.gs(R.string.menu_tempt)); menuitems.add(getString(R.string.menu_tempt));
if(showWizard) menuitems.add(aaps.gs(R.string.menu_wizard)); if(showWizard) menuitems.add(getString(R.string.menu_wizard));
menuitems.add(aaps.gs(R.string.menu_ecarb)); menuitems.add(getString(R.string.menu_ecarb));
menuitems.add(aaps.gs(R.string.menu_bolus)); menuitems.add(getString(R.string.menu_bolus));
menuitems.add(aaps.gs(R.string.menu_settings)); menuitems.add(getString(R.string.menu_settings));
menuitems.add(aaps.gs(R.string.menu_status)); menuitems.add(getString(R.string.menu_status));
if (showPrimeFill) menuitems.add(aaps.gs(R.string.menu_prime_fill)); if (showPrimeFill) menuitems.add(getString(R.string.menu_prime_fill));
return menuitems.toArray(new String[menuitems.size()]); return menuitems.toArray(new String[menuitems.size()]);
} }
@ -64,33 +62,33 @@ public class MainMenuActivity extends MenuListActivity {
Intent intent; Intent intent;
if (aaps.gs(R.string.menu_settings).equals(action)) { if (getString(R.string.menu_settings).equals(action)) {
intent = new Intent(this, AAPSPreferences.class); intent = new Intent(this, AAPSPreferences.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent); this.startActivity(intent);
} else if ("Re-Sync".equals(action)) { } else if ("Re-Sync".equals(action)) {
ListenerService.requestData(this); ListenerService.requestData(this);
} else if (aaps.gs(R.string.menu_tempt).equals(action)) { } else if (getString(R.string.menu_tempt).equals(action)) {
intent = new Intent(this, TempTargetActivity.class); intent = new Intent(this, TempTargetActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent); this.startActivity(intent);
} else if (aaps.gs(R.string.menu_bolus).equals(action)) { } else if (getString(R.string.menu_bolus).equals(action)) {
intent = new Intent(this, BolusActivity.class); intent = new Intent(this, BolusActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent); this.startActivity(intent);
} else if (aaps.gs(R.string.menu_wizard).equals(action)) { } else if (getString(R.string.menu_wizard).equals(action)) {
intent = new Intent(this, WizardActivity.class); intent = new Intent(this, WizardActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent); this.startActivity(intent);
} else if (aaps.gs(R.string.menu_status).equals(action)) { } else if (getString(R.string.menu_status).equals(action)) {
intent = new Intent(this, StatusMenuActivity.class); intent = new Intent(this, StatusMenuActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent); this.startActivity(intent);
} else if (aaps.gs(R.string.menu_prime_fill).equals(action)) { } else if (getString(R.string.menu_prime_fill).equals(action)) {
intent = new Intent(this, FillMenuActivity.class); intent = new Intent(this, FillMenuActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent); this.startActivity(intent);
} else if (aaps.gs(R.string.menu_ecarb).equals(action)) { } else if (getString(R.string.menu_ecarb).equals(action)) {
intent = new Intent(this, ECarbActivity.class); intent = new Intent(this, ECarbActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent); this.startActivity(intent);

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.interaction.menus; package info.nightscout.androidaps.interaction.menus;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.aaps;
import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.MenuListActivity; import info.nightscout.androidaps.interaction.utils.MenuListActivity;
@ -14,23 +13,23 @@ public class StatusMenuActivity extends MenuListActivity {
@Override @Override
protected String[] getElements() { protected String[] getElements() {
return new String[] { return new String[] {
aaps.gs(R.string.status_pump), getString(R.string.status_pump),
aaps.gs(R.string.status_loop), getString(R.string.status_loop),
aaps.gs(R.string.status_cpp), getString(R.string.status_cpp),
aaps.gs(R.string.status_tdd)}; getString(R.string.status_tdd)};
} }
@Override @Override
protected void doAction(String action) { protected void doAction(String action) {
if (aaps.gs(R.string.status_pump).equals(action)) { if (getString(R.string.status_pump).equals(action)) {
ListenerService.initiateAction(this, "status pump"); ListenerService.initiateAction(this, "status pump");
} else if (aaps.gs(R.string.status_loop).equals(action)) { } else if (getString(R.string.status_loop).equals(action)) {
ListenerService.initiateAction(this, "status loop"); ListenerService.initiateAction(this, "status loop");
} else if (aaps.gs(R.string.status_cpp).equals(action)) { } else if (getString(R.string.status_cpp).equals(action)) {
ListenerService.initiateAction(this, "opencpp"); ListenerService.initiateAction(this, "opencpp");
} else if (aaps.gs(R.string.status_tdd).equals(action)) { } else if (getString(R.string.status_tdd).equals(action)) {
ListenerService.initiateAction(this, "tddstats"); ListenerService.initiateAction(this, "tddstats");
} }
} }

View file

@ -1,6 +1,6 @@
package info.nightscout.androidaps.interaction.utils; package info.nightscout.androidaps.interaction.utils;
import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.Aaps;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
public class DisplayFormat { public class DisplayFormat {
@ -16,15 +16,15 @@ public class DisplayFormat {
public static final int MIN_FIELD_LEN_IOB = 3; // IoB can range from like .1U to 99U public static final int MIN_FIELD_LEN_IOB = 3; // IoB can range from like .1U to 99U
public static String deltaSymbol() { public static String deltaSymbol() {
return aaps.areComplicationsUnicode() ? "\u0394" : ""; return Aaps.areComplicationsUnicode() ? "\u0394" : "";
} }
public static String verticalSeparatorSymbol() { public static String verticalSeparatorSymbol() {
return aaps.areComplicationsUnicode() ? "\u205E" : "|"; return Aaps.areComplicationsUnicode() ? "\u205E" : "|";
} }
public static String basalRateSymbol() { public static String basalRateSymbol() {
return aaps.areComplicationsUnicode() ? "\u238D\u2006" : ""; return Aaps.areComplicationsUnicode() ? "\u238D\u2006" : "";
} }
public static String shortTimeSince(final long refTime) { public static String shortTimeSince(final long refTime) {

View file

@ -9,7 +9,7 @@ import com.google.android.gms.wearable.DataMap;
import java.util.Set; import java.util.Set;
import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.Aaps;
/** /**
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
@ -21,7 +21,7 @@ public class Persistence {
"info.nightscout.androidaps.complications.COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY"; "info.nightscout.androidaps.complications.COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY";
public Persistence() { public Persistence() {
preferences = aaps.getAppContext().getSharedPreferences(COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY, 0); preferences = Aaps.getAppContext().getSharedPreferences(COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY, 0);
} }
@Nullable @Nullable

View file

@ -4,7 +4,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.SystemClock;
import android.util.Log; import android.util.Log;
import com.google.android.gms.wearable.DataMap; import com.google.android.gms.wearable.DataMap;
@ -15,7 +14,7 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.Aaps;
/** /**
* Created by andy on 3/5/19. * Created by andy on 3/5/19.
@ -66,7 +65,7 @@ public class WearUtil {
} }
public static PowerManager.WakeLock getWakeLock(final String name, int millis) { public static PowerManager.WakeLock getWakeLock(final String name, int millis) {
final PowerManager pm = (PowerManager) aaps.getAppContext().getSystemService(Context.POWER_SERVICE); final PowerManager pm = (PowerManager) Aaps.getAppContext().getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AAPS::"+name); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AAPS::"+name);
wl.acquire(millis); wl.acquire(millis);
if (debug_wakelocks) Log.d(TAG, "getWakeLock: " + name + " " + wl.toString()); if (debug_wakelocks) Log.d(TAG, "getWakeLock: " + name + " " + wl.toString());
@ -80,11 +79,11 @@ public class WearUtil {
} }
public static void startActivity(Class c) { public static void startActivity(Class c) {
aaps.getAppContext().startActivity(getStartActivityIntent(c)); Aaps.getAppContext().startActivity(getStartActivityIntent(c));
} }
public static Intent getStartActivityIntent(Class c) { public static Intent getStartActivityIntent(Class c) {
return new Intent(aaps.getAppContext(), c).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return new Intent(Aaps.getAppContext(), c).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} }
public static void threadSleep(long millis) { public static void threadSleep(long millis) {

View file

@ -13,7 +13,6 @@ import android.graphics.Rect;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.Vibrator; import android.os.Vibrator;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import android.support.wearable.view.WatchViewStub; import android.support.wearable.view.WatchViewStub;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import android.util.Log; import android.util.Log;
@ -26,20 +25,21 @@ import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.google.android.gms.wearable.DataMap; import com.google.android.gms.wearable.DataMap;
import com.ustwo.clockwise.common.WatchMode;
import com.ustwo.clockwise.wearable.WatchFace;
import com.ustwo.clockwise.common.WatchFaceTime; import com.ustwo.clockwise.common.WatchFaceTime;
import com.ustwo.clockwise.common.WatchMode;
import com.ustwo.clockwise.common.WatchShape; import com.ustwo.clockwise.common.WatchShape;
import com.ustwo.clockwise.wearable.WatchFace;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.aaps;
import info.nightscout.androidaps.complications.BaseComplicationProviderService;
import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.complications.BaseComplicationProviderService;
import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.data.RawDisplayData;
import lecho.lib.hellocharts.view.LineChartView; import lecho.lib.hellocharts.view.LineChartView;
/** /**
@ -50,8 +50,17 @@ import lecho.lib.hellocharts.view.LineChartView;
public abstract class BaseWatchFace extends WatchFace implements SharedPreferences.OnSharedPreferenceChangeListener { public abstract class BaseWatchFace extends WatchFace implements SharedPreferences.OnSharedPreferenceChangeListener {
public final static IntentFilter INTENT_FILTER; public final static IntentFilter INTENT_FILTER;
public static final long[] vibratePattern = {0,400,300,400,300,400}; public static final long[] vibratePattern = {0, 400, 300, 400, 300, 400};
public TextView mTime, mHour, mMinute,mSgv, mDirection, mTimestamp, mUploaderBattery, mRigBattery, mDelta, mAvgDelta, mStatus, mBasalRate, mIOB1, mIOB2, mCOB1, mCOB2, mBgi, mLoop, mDay, mDayName, mMonth, isAAPSv2, mHighLight, mLowLight;
static {
INTENT_FILTER = new IntentFilter();
INTENT_FILTER.addAction(Intent.ACTION_TIME_TICK);
INTENT_FILTER.addAction(Intent.ACTION_TIMEZONE_CHANGED);
INTENT_FILTER.addAction(Intent.ACTION_TIME_CHANGED);
}
public final Point displaySize = new Point();
public TextView mTime, mHour, mMinute, mSgv, mDirection, mTimestamp, mUploaderBattery, mRigBattery, mDelta, mAvgDelta, mStatus, mBasalRate, mIOB1, mIOB2, mCOB1, mCOB2, mBgi, mLoop, mDay, mDayName, mMonth, isAAPSv2, mHighLight, mLowLight;
public ImageView mGlucoseDial, mDeltaGauge, mHourHand, mMinuteHand; public ImageView mGlucoseDial, mDeltaGauge, mHourHand, mMinuteHand;
public RelativeLayout mRelativeLayout; public RelativeLayout mRelativeLayout;
public LinearLayout mLinearLayout, mLinearLayout2, mDate, mChartTap, mMainMenuTap; public LinearLayout mLinearLayout, mLinearLayout2, mDate, mChartTap, mMainMenuTap;
@ -71,23 +80,17 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
public int pointSize = 2; public int pointSize = 2;
public BgGraphBuilder bgGraphBuilder; public BgGraphBuilder bgGraphBuilder;
public LineChartView chart; public LineChartView chart;
public RawDisplayData rawData = new RawDisplayData(); public RawDisplayData rawData = new RawDisplayData();
public PowerManager.WakeLock wakeLock; public PowerManager.WakeLock wakeLock;
// related endTime manual layout // related endTime manual layout
public View layoutView; public View layoutView;
public final Point displaySize = new Point();
public int specW, specH; public int specW, specH;
private LocalBroadcastManager localBroadcastManager;
private MessageReceiver messageReceiver;
protected SharedPreferences sharedPrefs;
public boolean forceSquareCanvas = false; //set to true by the Steampunk watch face. public boolean forceSquareCanvas = false; //set to true by the Steampunk watch face.
public String sMinute = "0"; public String sMinute = "0";
public String sHour = "0"; public String sHour = "0";
protected SharedPreferences sharedPrefs;
private LocalBroadcastManager localBroadcastManager;
private MessageReceiver messageReceiver;
@Override @Override
public void onCreate() { public void onCreate() {
@ -130,7 +133,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
mHour = stub.findViewById(R.id.hour); mHour = stub.findViewById(R.id.hour);
mMinute = stub.findViewById(R.id.minute); mMinute = stub.findViewById(R.id.minute);
mDay = stub.findViewById(R.id.day); mDay = stub.findViewById(R.id.day);
mDayName= stub.findViewById(R.id.dayname); mDayName = stub.findViewById(R.id.dayname);
mMonth = stub.findViewById(R.id.month); mMonth = stub.findViewById(R.id.month);
mDate = stub.findViewById(R.id.date_time); mDate = stub.findViewById(R.id.date_time);
mLoop = stub.findViewById(R.id.loop); mLoop = stub.findViewById(R.id.loop);
@ -172,7 +175,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
} }
public int ageLevel() { public int ageLevel() {
if(timeSince() <= (1000 * 60 * 12)) { if (timeSince() <= (1000 * 60 * 12)) {
return 1; return 1;
} else { } else {
return 0; return 0;
@ -184,12 +187,14 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
} }
public String readingAge(boolean shortString) { public String readingAge(boolean shortString) {
if (rawData.datetime == 0) { return shortString?"--'":"-- Minute ago"; } if (rawData.datetime == 0) {
int minutesAgo = (int) Math.floor(timeSince()/(1000*60)); return shortString ? "--'" : "-- Minute ago";
if (minutesAgo == 1) {
return minutesAgo + (shortString?"'":" Minute ago");
} }
return minutesAgo + (shortString?"'":" Minutes ago"); int minutesAgo = (int) Math.floor(timeSince() / (1000 * 60));
if (minutesAgo == 1) {
return minutesAgo + (shortString ? "'" : " Minute ago");
}
return minutesAgo + (shortString ? "'" : " Minutes ago");
} }
@Override @Override
@ -203,13 +208,6 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
super.onDestroy(); super.onDestroy();
} }
static {
INTENT_FILTER = new IntentFilter();
INTENT_FILTER.addAction(Intent.ACTION_TIME_TICK);
INTENT_FILTER.addAction(Intent.ACTION_TIMEZONE_CHANGED);
INTENT_FILTER.addAction(Intent.ACTION_TIME_CHANGED);
}
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
if (layoutSet) { if (layoutSet) {
@ -234,7 +232,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
setDataFields(); setDataFields();
setColor(); setColor();
missedReadingAlert(); missedReadingAlert();
checkVibrateHourly(oldTime,newTime); checkVibrateHourly(oldTime, newTime);
mRelativeLayout.measure(specW, specH); mRelativeLayout.measure(specW, specH);
if (forceSquareCanvas) { if (forceSquareCanvas) {
@ -246,7 +244,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
} }
} }
private void checkVibrateHourly(WatchFaceTime oldTime, WatchFaceTime newTime){ private void checkVibrateHourly(WatchFaceTime oldTime, WatchFaceTime newTime) {
Boolean hourlyVibratePref = sharedPrefs.getBoolean("vibrate_Hourly", false); Boolean hourlyVibratePref = sharedPrefs.getBoolean("vibrate_Hourly", false);
if (hourlyVibratePref && layoutSet && newTime.hasHourChanged(oldTime)) { if (hourlyVibratePref && layoutSet && newTime.hasHourChanged(oldTime)) {
Log.i("hourlyVibratePref", "true --> " + newTime.toString()); Log.i("hourlyVibratePref", "true --> " + newTime.toString());
@ -256,36 +254,6 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
} }
} }
public class MessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (layoutSet) {
final DataMap dataMap = rawData.updateDataFromMessage(intent, wakeLock);
if (chart != null && dataMap != null) {
rawData.addToWatchSet(dataMap);
setupCharts();
}
rawData.updateStatusFromMessage(intent, wakeLock);
}
setDataFields();
setColor();
if (layoutSet) {
rawData.updateBasalsFromMessage(intent, wakeLock);
}
mRelativeLayout.measure(specW, specH);
if (forceSquareCanvas) {
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.x); //force a square for Steampunk watch face.
} else {
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.y);
}
invalidate();
}
}
public void setDataFields() { public void setDataFields() {
setDateAndTime(); setDateAndTime();
@ -357,7 +325,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
mIOB1.setText(rawData.sIOB1); mIOB1.setText(rawData.sIOB1);
mIOB2.setText(rawData.sIOB2); mIOB2.setText(rawData.sIOB2);
} else { } else {
mIOB1.setText(aaps.gs(R.string.activity_IOB)); mIOB1.setText(getString(R.string.activity_IOB));
mIOB2.setText(rawData.sIOB1); mIOB2.setText(rawData.sIOB1);
} }
} else { } else {
@ -483,14 +451,14 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
sHour = sdfHour.format(now); sHour = sdfHour.format(now);
sMinute = sdfMinute.format(now); sMinute = sdfMinute.format(now);
if (mHour != null && mMinute != null ) { if (mHour != null && mMinute != null) {
mHour.setText(sHour); mHour.setText(sHour);
mMinute.setText(sMinute); mMinute.setText(sMinute);
} }
if (mDate != null && mDay != null && mMonth != null) { if (mDate != null && mDay != null && mMonth != null) {
if (sharedPrefs.getBoolean("show_date", false)) { if (sharedPrefs.getBoolean("show_date", false)) {
if (mDayName != null ) { if (mDayName != null) {
SimpleDateFormat sdfDayName = new SimpleDateFormat("E"); SimpleDateFormat sdfDayName = new SimpleDateFormat("E");
mDayName.setText(sdfDayName.format(now)); mDayName.setText(sdfDayName.format(now));
} }
@ -508,7 +476,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
public void setColor() { public void setColor() {
dividerMatchesBg = sharedPrefs.getBoolean("match_divider", false); dividerMatchesBg = sharedPrefs.getBoolean("match_divider", false);
if(lowResMode){ if (lowResMode) {
setColorLowRes(); setColorLowRes();
} else if (sharedPrefs.getBoolean("dark", true)) { } else if (sharedPrefs.getBoolean("dark", true)) {
setColorDark(); setColorDark();
@ -518,7 +486,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
} }
public void strikeThroughSgvIfNeeded() { public void strikeThroughSgvIfNeeded() {
if (mSgv !=null) { if (mSgv != null) {
if (sharedPrefs.getBoolean("showBG", true)) { if (sharedPrefs.getBoolean("showBG", true)) {
if (ageLevel() <= 0) { if (ageLevel() <= 0) {
mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
@ -531,10 +499,10 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
protected void onWatchModeChanged(WatchMode watchMode) { protected void onWatchModeChanged(WatchMode watchMode) {
if(lowResMode ^ isLowRes(watchMode)){ //if there was a change in lowResMode if (lowResMode ^ isLowRes(watchMode)) { //if there was a change in lowResMode
lowResMode = isLowRes(watchMode); lowResMode = isLowRes(watchMode);
setColor(); setColor();
} else if (! sharedPrefs.getBoolean("dark", true)){ } else if (!sharedPrefs.getBoolean("dark", true)) {
//in bright mode: different colours if active: //in bright mode: different colours if active:
setColor(); setColor();
} }
@ -545,13 +513,13 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
} }
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key){ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if("delta_granularity".equals(key)){ if ("delta_granularity".equals(key)) {
ListenerService.requestData(this); ListenerService.requestData(this);
} }
if(layoutSet){ if (layoutSet) {
setDataFields(); setDataFields();
setColor(); setColor();
} }
@ -559,18 +527,20 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
} }
protected abstract void setColorDark(); protected abstract void setColorDark();
protected abstract void setColorBright(); protected abstract void setColorBright();
protected abstract void setColorLowRes(); protected abstract void setColorLowRes();
public void missedReadingAlert() { public void missedReadingAlert() {
int minutes_since = (int) Math.floor(timeSince()/(1000*60)); int minutes_since = (int) Math.floor(timeSince() / (1000 * 60));
if(minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) { if (minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) {
ListenerService.requestData(this); // attempt endTime recover missing data ListenerService.requestData(this); // attempt endTime recover missing data
} }
} }
public void setupCharts() { public void setupCharts() {
if(rawData.bgDataList.size() > 0) { //Dont crash things just because we dont have values, people dont like crashy things if (rawData.bgDataList.size() > 0) { //Dont crash things just because we dont have values, people dont like crashy things
int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "3")); int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "3"));
if (lowResMode) { if (lowResMode) {
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), rawData, pointSize, midColor, gridColor, basalBackgroundColor, basalCenterColor, bolusColor, Color.GREEN, timeframe); bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), rawData, pointSize, midColor, gridColor, basalBackgroundColor, basalCenterColor, bolusColor, Color.GREEN, timeframe);
@ -584,4 +554,34 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
} }
} }
public class MessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (layoutSet) {
final DataMap dataMap = rawData.updateDataFromMessage(intent, wakeLock);
if (chart != null && dataMap != null) {
rawData.addToWatchSet(dataMap);
setupCharts();
}
rawData.updateStatusFromMessage(intent, wakeLock);
}
setDataFields();
setColor();
if (layoutSet) {
rawData.updateBasalsFromMessage(intent, wakeLock);
}
mRelativeLayout.measure(specW, specH);
if (forceSquareCanvas) {
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.x); //force a square for Steampunk watch face.
} else {
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.y);
}
invalidate();
}
}
} }

View file

@ -150,7 +150,10 @@
<string name="digitalstyle_pref_your_color">Your color:</string> <string name="digitalstyle_pref_your_color">Your color:</string>
<string name="digitalstyle_pref_your_color_saturation">Your color saturation:</string> <string name="digitalstyle_pref_your_color_saturation">Your color saturation:</string>
<string name="digitalstyle_pref_your_color_opacity">Your color opacity:</string> <string name="digitalstyle_pref_your_color_opacity">Your color opacity:</string>
<string name="bolus_progress_channel_name">AAPS Bolus Progress</string>
<string name="bolus_progress_silent_channel_name">AAPS Bolus Progress Silent</string>
<string name="bolus_progress_channel_description">Bolus progress and cancel</string>
<string name="bolus_progress_silent_channel_description">Bolus progress and cancel with less vibrations</string>
</resources> </resources>

View file

@ -14,7 +14,7 @@ import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.Aaps;
import info.nightscout.androidaps.interaction.utils.Constants; import info.nightscout.androidaps.interaction.utils.Constants;
import info.nightscout.androidaps.interaction.utils.Persistence; import info.nightscout.androidaps.interaction.utils.Persistence;
import info.nightscout.androidaps.interaction.utils.WearUtil; import info.nightscout.androidaps.interaction.utils.WearUtil;
@ -28,7 +28,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, aaps.class, android.util.Base64.class, Intent.class } ) @PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, Aaps.class, android.util.Base64.class, Intent.class } )
public class RawDataSgvDisplayDataTest { public class RawDataSgvDisplayDataTest {
@Before @Before

View file

@ -16,7 +16,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList; import java.util.ArrayList;
import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.Aaps;
import info.nightscout.androidaps.interaction.utils.Constants; import info.nightscout.androidaps.interaction.utils.Constants;
import info.nightscout.androidaps.interaction.utils.Persistence; import info.nightscout.androidaps.interaction.utils.Persistence;
import info.nightscout.androidaps.interaction.utils.WearUtil; import info.nightscout.androidaps.interaction.utils.WearUtil;
@ -34,7 +34,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, aaps.class, android.util.Base64.class, Intent.class } ) @PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, Aaps.class, android.util.Base64.class, Intent.class } )
public class RawDisplayDataBasalsTest { public class RawDisplayDataBasalsTest {
@Before @Before

View file

@ -14,7 +14,7 @@ import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.Aaps;
import info.nightscout.androidaps.interaction.utils.Constants; import info.nightscout.androidaps.interaction.utils.Constants;
import info.nightscout.androidaps.interaction.utils.Persistence; import info.nightscout.androidaps.interaction.utils.Persistence;
import info.nightscout.androidaps.interaction.utils.WearUtil; import info.nightscout.androidaps.interaction.utils.WearUtil;
@ -30,7 +30,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, aaps.class, android.util.Base64.class, Intent.class } ) @PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, Aaps.class, android.util.Base64.class, Intent.class } )
public class RawDisplayDataStatusTest { public class RawDisplayDataStatusTest {
@Before @Before

View file

@ -10,7 +10,7 @@ import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.Aaps;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.testing.mockers.AAPSMocker; import info.nightscout.androidaps.testing.mockers.AAPSMocker;
import info.nightscout.androidaps.testing.mockers.WearUtilMocker; import info.nightscout.androidaps.testing.mockers.WearUtilMocker;
@ -30,7 +30,7 @@ import static org.junit.Assert.assertThat;
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, aaps.class } ) @PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, Aaps.class } )
public class DisplayFormatTest { public class DisplayFormatTest {
@Before @Before

View file

@ -14,7 +14,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import java.util.Set; import java.util.Set;
import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.Aaps;
import info.nightscout.androidaps.testing.mockers.AAPSMocker; import info.nightscout.androidaps.testing.mockers.AAPSMocker;
import info.nightscout.androidaps.testing.mockers.AndroidMocker; import info.nightscout.androidaps.testing.mockers.AndroidMocker;
import info.nightscout.androidaps.testing.mockers.LogMocker; import info.nightscout.androidaps.testing.mockers.LogMocker;
@ -29,7 +29,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, aaps.class, android.util.Base64.class} ) @PrepareForTest( { WearUtil.class, Log.class, SharedPreferences.class, Context.class, Aaps.class, android.util.Base64.class} )
public class PersistenceTest { public class PersistenceTest {
@Before @Before

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.testing.mockers;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import org.junit.Assert;
import org.mockito.ArgumentMatchers; import org.mockito.ArgumentMatchers;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
@ -11,7 +10,7 @@ import org.powermock.api.mockito.PowerMockito;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.Aaps;
import info.nightscout.androidaps.testing.mocks.SharedPreferencesMock; import info.nightscout.androidaps.testing.mocks.SharedPreferencesMock;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -24,9 +23,9 @@ public class AAPSMocker {
public static void prepareMock() throws Exception { public static void prepareMock() throws Exception {
Context mockedContext = mock(Context.class); Context mockedContext = mock(Context.class);
mockStatic(aaps.class, InvocationOnMock::callRealMethod); mockStatic(Aaps.class, InvocationOnMock::callRealMethod);
PowerMockito.when(aaps.class, "getAppContext").thenReturn(mockedContext); PowerMockito.when(Aaps.class, "getAppContext").thenReturn(mockedContext);
PowerMockito.when(mockedContext, "getSharedPreferences", ArgumentMatchers.anyString(), ArgumentMatchers.anyInt()).thenAnswer(invocation -> { PowerMockito.when(mockedContext, "getSharedPreferences", ArgumentMatchers.anyString(), ArgumentMatchers.anyInt()).thenAnswer(invocation -> {
final String key = invocation.getArgument(0); final String key = invocation.getArgument(0);
@ -38,7 +37,7 @@ public class AAPSMocker {
return newPrefs; return newPrefs;
} }
}); });
PowerMockito.when(aaps.class, "areComplicationsUnicode").thenAnswer(invocation -> unicodeComplicationsOn); PowerMockito.when(Aaps.class, "areComplicationsUnicode").thenAnswer(invocation -> unicodeComplicationsOn);
setMockedUnicodeComplicationsOn(true); setMockedUnicodeComplicationsOn(true);
resetMockedSharedPrefs(); resetMockedSharedPrefs();