diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index 7bee0811ec..b16b04f6d1 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -10,7 +10,7 @@ 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); + return Aaps.context; } public static Boolean areComplicationsUnicode() { diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.java b/wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.java index 00a7f915b5..4e998e20f8 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.java +++ b/wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.java @@ -19,7 +19,7 @@ import java.util.Set; import androidx.localbroadcastmanager.content.LocalBroadcastManager; 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.ListenerService; import info.nightscout.androidaps.interaction.utils.Constants; @@ -94,11 +94,11 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid } break; 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) { - 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 { - builder.setLongText(ComplicationText.plainText(aaps.gs(R.string.label_warning_sync_aaps))); + builder.setLongText(ComplicationText.plainText(getString(R.string.label_warning_sync_aaps))); } break; case ComplicationData.TYPE_LARGE_IMAGE: @@ -143,11 +143,11 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid } break; 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) { - 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 { - builder.setLongText(ComplicationText.plainText(aaps.gs(R.string.label_warning_sync_aaps))); + builder.setLongText(ComplicationText.plainText(getString(R.string.label_warning_sync_aaps))); } break; 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. final PendingIntent complicationPendingIntent = ComplicationTapBroadcastReceiver.getTapActionIntent( - aaps.getAppContext(), thisProvider, complicationId, getComplicationAction()); + Aaps.getAppContext(), thisProvider, complicationId, getComplicationAction()); final Persistence persistence = new Persistence(); @@ -242,12 +242,12 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid if (WearUtil.msSince(persistence.whenDataUpdated()) > Constants.STALE_MS) { // no new data arrived - probably configuration or connection error 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()); } else if (WearUtil.msSince(raw.datetime) > Constants.STALE_MS) { // data arriving from phone AAPS, but it is outdated (uploader/NS/xDrip/Sensor error) 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); } else { // 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, () -> { if (WearUtil.isBelowRateLimit("update-req-"+provider, 2)) { Log.d(TAG, "Requesting update of "+provider); - final ComponentName componentName = new ComponentName(aaps.getAppContext(), provider); - final ProviderUpdateRequester providerUpdateRequester = new ProviderUpdateRequester(aaps.getAppContext(), componentName); + final ComponentName componentName = new ComponentName(Aaps.getAppContext(), provider); + final ProviderUpdateRequester providerUpdateRequester = new ProviderUpdateRequester(Aaps.getAppContext(), componentName); providerUpdateRequester.requestUpdateAll(); } }); diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/ComplicationTapBroadcastReceiver.java b/wear/src/main/java/info/nightscout/androidaps/complications/ComplicationTapBroadcastReceiver.java index 61dc8d4dde..33d302dd6f 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/ComplicationTapBroadcastReceiver.java +++ b/wear/src/main/java/info/nightscout/androidaps/complications/ComplicationTapBroadcastReceiver.java @@ -13,7 +13,7 @@ import android.widget.Toast; import androidx.annotation.StringRes; 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.ECarbActivity; import info.nightscout.androidaps.interaction.actions.WizardActivity; @@ -67,16 +67,16 @@ public class ComplicationTapBroadcastReceiver extends BroadcastReceiver { // do nothing return; case WIZARD: - intentOpen = new Intent(aaps.getAppContext(), WizardActivity.class); + intentOpen = new Intent(Aaps.getAppContext(), WizardActivity.class); break; case BOLUS: - intentOpen = new Intent(aaps.getAppContext(), BolusActivity.class); + intentOpen = new Intent(Aaps.getAppContext(), BolusActivity.class); break; case ECARB: - intentOpen = new Intent(aaps.getAppContext(), ECarbActivity.class); + intentOpen = new Intent(Aaps.getAppContext(), ECarbActivity.class); break; case STATUS: - intentOpen = new Intent(aaps.getAppContext(), StatusMenuActivity.class); + intentOpen = new Intent(Aaps.getAppContext(), StatusMenuActivity.class); break; case WARNING_OLD: case WARNING_SYNC: @@ -84,23 +84,23 @@ public class ComplicationTapBroadcastReceiver extends BroadcastReceiver { long since = extras.getLong(EXTRA_COMPLICATION_SINCE, oneAndHalfMinuteAgo); @StringRes int labelId = (action == ComplicationAction.WARNING_SYNC) ? R.string.msg_warning_sync : R.string.msg_warning_old; - String msg = String.format(aaps.gs(labelId), DisplayFormat.shortTimeSince(since)); - Toast.makeText(aaps.getAppContext(), msg, Toast.LENGTH_LONG).show(); + String msg = String.format(context.getString(labelId), DisplayFormat.shortTimeSince(since)); + Toast.makeText(Aaps.getAppContext(), msg, Toast.LENGTH_LONG).show(); break; case MENU: default: - intentOpen = new Intent(aaps.getAppContext(), MainMenuActivity.class); + intentOpen = new Intent(Aaps.getAppContext(), MainMenuActivity.class); } if (intentOpen != null) { // Perform intent - open dialog intentOpen.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - aaps.getAppContext().startActivity(intentOpen); + Aaps.getAppContext().startActivity(intentOpen); } } private ComplicationAction remapActionWithUserPreferences(ComplicationAction originalAction) { - final String userPrefAction = aaps.getComplicationTapAction(); + final String userPrefAction = Aaps.getComplicationTapAction(); switch (originalAction) { case WARNING_OLD: case WARNING_SYNC: diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/WallpaperComplication.java b/wear/src/main/java/info/nightscout/androidaps/complications/WallpaperComplication.java index 293b1331ca..a2c20cea6d 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/WallpaperComplication.java +++ b/wear/src/main/java/info/nightscout/androidaps/complications/WallpaperComplication.java @@ -14,7 +14,7 @@ import android.view.WindowManager; import java.io.IOException; import java.io.InputStream; -import info.nightscout.androidaps.aaps; +import info.nightscout.androidaps.Aaps; import info.nightscout.androidaps.data.RawDisplayData; /* @@ -33,7 +33,7 @@ public abstract class WallpaperComplication extends BaseComplicationProviderServ if (dataType == ComplicationData.TYPE_LARGE_IMAGE) { DisplayMetrics metrics = new DisplayMetrics(); - WindowManager windowManager = (WindowManager) aaps.getAppContext() + WindowManager windowManager = (WindowManager) Aaps.getAppContext() .getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); int width = metrics.widthPixels; diff --git a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java index ef32aecde9..13f7663415 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -1,5 +1,6 @@ package info.nightscout.androidaps.data; +import android.annotation.TargetApi; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -37,7 +38,6 @@ import com.google.android.gms.wearable.WearableListenerService; import java.util.Set; import java.util.concurrent.TimeUnit; -import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interaction.AAPSPreferences; 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 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; @@ -616,17 +617,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - CharSequence name = "AAPS Bolus Progress"; - 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); + createBolusProgressChannels(); } 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); 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) - .setContentTitle(aaps.gs(R.string.bolus_progress)) + .setContentTitle(getString(R.string.bolus_progress)) .setContentText(progresspercent + "% - " + progresstatus) - .setSubText(aaps.gs(R.string.press_to_cancel)) + .setSubText(getString(R.string.press_to_cancel)) .setContentIntent(cancelPendingIntent) .setPriority(NotificationCompat.PRIORITY_MAX) .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.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) { Intent intent = new Intent(this, AcceptActivity.class); diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.java index 1b38bc8a9e..dad9a46df9 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.java @@ -1,7 +1,6 @@ package info.nightscout.androidaps.interaction.actions; -import android.app.Activity; import android.content.res.Resources; import android.os.Bundle; import android.support.wearable.view.DotsPageIndicator; @@ -11,12 +10,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.TextView; -import info.nightscout.androidaps.R; + import java.text.DecimalFormat; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.SafeParse; @@ -65,24 +62,24 @@ public class BolusActivity extends ViewSelectorActivity { @Override public Object instantiateItem(ViewGroup container, int row, int col) { - if(col == 0){ + if (col == 0) { final View view = getInflatedPlusMinusView(container); double def = 0; - if (editInsulin != null){ + if (editInsulin != null) { 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); - setLabelToPlusMinusView(view, aaps.gs(R.string.action_insulin)); + setLabelToPlusMinusView(view, getString(R.string.action_insulin)); container.addView(view); return view; - } else if(col == 1){ + } else if (col == 1) { final View view = getInflatedPlusMinusView(container); double def = 0; - if (editCarbs != null){ + if (editCarbs != null) { def = SafeParse.stringToDouble(editCarbs.editText.getText().toString()); } editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 150d, 1d, new DecimalFormat("0"), false); - setLabelToPlusMinusView(view, aaps.gs(R.string.action_carbs)); + setLabelToPlusMinusView(view, getString(R.string.action_carbs)); container.addView(view); return view; } else { @@ -96,7 +93,7 @@ public class BolusActivity extends ViewSelectorActivity { //check if it can happen that the fagment is never created that hold data? // (you have to swipe past them anyways - but still) - String actionstring = "bolus " +SafeParse.stringToDouble(editInsulin.editText.getText().toString()) + String actionstring = "bolus " + SafeParse.stringToDouble(editInsulin.editText.getText().toString()) + " " + SafeParse.stringToInt(editCarbs.editText.getText().toString()); ListenerService.initiateAction(BolusActivity.this, actionstring); finish(); @@ -111,12 +108,12 @@ public class BolusActivity extends ViewSelectorActivity { public void destroyItem(ViewGroup container, int row, int col, Object view) { // Handle this to get the data before the view is destroyed? // Object should still be kept by this, just setup for reinit? - container.removeView((View)view); + container.removeView((View) view); } @Override public boolean isViewFromObject(View view, Object object) { - return view==object; + return view == object; } diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CPPActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CPPActivity.java index dee9ab3aef..e47b40293c 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CPPActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CPPActivity.java @@ -14,7 +14,6 @@ import android.widget.ImageView; import java.text.DecimalFormat; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.SafeParse; @@ -40,11 +39,12 @@ public class CPPActivity extends ViewSelectorActivity { percentage = extras.getInt("percentage", -1); timeshift = extras.getInt("timeshift", -1); - if (percentage ==-1 || timeshift ==-25){ - finish(); return; + if (percentage == -1 || timeshift == -25) { + finish(); + return; } - if(timeshift < 0) timeshift += 24; + if (timeshift < 0) timeshift += 24; setContentView(R.layout.grid_layout); final Resources res = getResources(); @@ -77,24 +77,24 @@ public class CPPActivity extends ViewSelectorActivity { @Override public Object instantiateItem(ViewGroup container, int row, int col) { - if(col == 0){ + if (col == 0) { final View view = getInflatedPlusMinusView(container); double def = timeshift; - if (editTimeshift != null){ + if (editTimeshift != null) { 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); - setLabelToPlusMinusView(view, aaps.gs(R.string.action_timeshift)); + setLabelToPlusMinusView(view, getString(R.string.action_timeshift)); container.addView(view); return view; - } else if(col == 1){ + } else if (col == 1) { final View view = getInflatedPlusMinusView(container); double def = percentage; - if (editPercentage != null){ + if (editPercentage != null) { 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); - setLabelToPlusMinusView(view, aaps.gs(R.string.action_percentage)); + setLabelToPlusMinusView(view, getString(R.string.action_percentage)); container.addView(view); return view; } else { @@ -108,7 +108,7 @@ public class CPPActivity extends ViewSelectorActivity { //check if it can happen that the fagment is never created that hold data? // (you have to swipe past them anyways - but still) - String actionstring = "cppset " +SafeParse.stringToInt(editTimeshift.editText.getText().toString()) + String actionstring = "cppset " + SafeParse.stringToInt(editTimeshift.editText.getText().toString()) + " " + SafeParse.stringToInt(editPercentage.editText.getText().toString()); ListenerService.initiateAction(CPPActivity.this, actionstring); finish(); @@ -123,12 +123,12 @@ public class CPPActivity extends ViewSelectorActivity { public void destroyItem(ViewGroup container, int row, int col, Object view) { // Handle this to get the data before the view is destroyed? // Object should still be kept by this, just setup for reinit? - container.removeView((View)view); + container.removeView((View) view); } @Override public boolean isViewFromObject(View view, Object object) { - return view==object; + return view == object; } diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.java index 994557e307..09b68ed704 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.java @@ -14,7 +14,6 @@ import android.widget.ImageView; import java.text.DecimalFormat; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.SafeParse; @@ -72,7 +71,7 @@ public class ECarbActivity extends ViewSelectorActivity { 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); - setLabelToPlusMinusView(view, aaps.gs(R.string.action_carbs)); + setLabelToPlusMinusView(view, getString(R.string.action_carbs)); container.addView(view); return view; } else if(col == 1){ @@ -82,7 +81,7 @@ public class ECarbActivity extends ViewSelectorActivity { def = SafeParse.stringToDouble(editStartTime.editText.getText().toString()); } editStartTime = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 300d, 15d, new DecimalFormat("0"), false); - setLabelToPlusMinusView(view, aaps.gs(R.string.action_start_min)); + setLabelToPlusMinusView(view, getString(R.string.action_start_min)); container.addView(view); return view; } else if(col == 2){ @@ -92,7 +91,7 @@ public class ECarbActivity extends ViewSelectorActivity { 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); - setLabelToPlusMinusView(view, aaps.gs(R.string.action_duration_h)); + setLabelToPlusMinusView(view, getString(R.string.action_duration_h)); container.addView(view); return view; } else { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.java index b9269f3829..2f3770f464 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.java @@ -1,7 +1,6 @@ package info.nightscout.androidaps.interaction.actions; -import android.app.Activity; import android.content.res.Resources; import android.os.Bundle; import android.support.wearable.view.DotsPageIndicator; @@ -11,12 +10,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.TextView; import java.text.DecimalFormat; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.SafeParse; @@ -64,14 +61,14 @@ public class FillActivity extends ViewSelectorActivity { @Override public Object instantiateItem(ViewGroup container, int row, int col) { - if(col == 0){ + if (col == 0) { final View view = getInflatedPlusMinusView(container); double def = 0d; - if (editInsulin != null){ + if (editInsulin != null) { 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); - setLabelToPlusMinusView(view, aaps.gs(R.string.action_insulin)); + setLabelToPlusMinusView(view, getString(R.string.action_insulin)); container.addView(view); return view; } else { @@ -85,7 +82,7 @@ public class FillActivity extends ViewSelectorActivity { //check if it can happen that the fagment is never created that hold data? // (you have to swipe past them anyways - but still) - String actionstring = "fill " +SafeParse.stringToDouble(editInsulin.editText.getText().toString()); + String actionstring = "fill " + SafeParse.stringToDouble(editInsulin.editText.getText().toString()); ListenerService.initiateAction(FillActivity.this, actionstring); finish(); } @@ -99,12 +96,12 @@ public class FillActivity extends ViewSelectorActivity { public void destroyItem(ViewGroup container, int row, int col, Object view) { // Handle this to get the data before the view is destroyed? // Object should still be kept by this, just setup for reinit? - container.removeView((View)view); + container.removeView((View) view); } @Override public boolean isViewFromObject(View view, Object object) { - return view==object; + return view == object; } diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.java index fcb4bd2b92..6bc562c139 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.java @@ -17,7 +17,6 @@ import android.widget.TextView; import java.text.DecimalFormat; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.SafeParse; @@ -48,7 +47,7 @@ public class TempTargetActivity extends ViewSelectorActivity { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); isMGDL = sp.getBoolean("units_mgdl", true); - isSingleTarget = sp.getBoolean("singletarget", true); + isSingleTarget = sp.getBoolean("singletarget", true); } @@ -62,7 +61,7 @@ public class TempTargetActivity extends ViewSelectorActivity { private class MyGridViewPagerAdapter extends GridPagerAdapter { @Override public int getColumnCount(int arg0) { - return isSingleTarget?3:4; + return isSingleTarget ? 3 : 4; } @Override @@ -73,7 +72,7 @@ public class TempTargetActivity extends ViewSelectorActivity { @Override public Object instantiateItem(ViewGroup container, int row, int col) { - if(col == 0){ + if (col == 0) { final View view = getInflatedPlusMinusView(container); final TextView textView = view.findViewById(R.id.label); textView.setText("duration"); @@ -83,51 +82,51 @@ public class TempTargetActivity extends ViewSelectorActivity { 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); } - setLabelToPlusMinusView(view, aaps.gs(R.string.action_duration)); - container.addView(view); + setLabelToPlusMinusView(view, getString(R.string.action_duration)); + container.addView(view); return view; - } else if(col == 1){ - final View view = getInflatedPlusMinusView(container); - if (isMGDL){ - double def = 100; - if (lowRange != null){ - 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); - } else { - double def = 5.5; - if (lowRange != null){ - 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); - } - if(isSingleTarget){ - setLabelToPlusMinusView(view, aaps.gs(R.string.action_target)); - } else { - setLabelToPlusMinusView(view, aaps.gs(R.string.action_low)); - } - container.addView(view); - return view; - } else if(col == 2 && ! isSingleTarget){ - final View view = getInflatedPlusMinusView(container); - if (isMGDL){ - double def = 100; - if (highRange != null){ - 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); - } else { - double def = 5.5; - if (highRange != null){ - 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); - } - setLabelToPlusMinusView(view, aaps.gs(R.string.action_high)); - container.addView(view); - return view; - }else { + } else if (col == 1) { + final View view = getInflatedPlusMinusView(container); + if (isMGDL) { + double def = 100; + if (lowRange != null) { + 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); + } else { + double def = 5.5; + if (lowRange != null) { + 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); + } + if (isSingleTarget) { + setLabelToPlusMinusView(view, getString(R.string.action_target)); + } else { + setLabelToPlusMinusView(view, getString(R.string.action_low)); + } + container.addView(view); + return view; + } else if (col == 2 && !isSingleTarget) { + final View view = getInflatedPlusMinusView(container); + if (isMGDL) { + double def = 100; + if (highRange != null) { + 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); + } else { + double def = 5.5; + if (highRange != null) { + 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); + } + setLabelToPlusMinusView(view, getString(R.string.action_high)); + container.addView(view); + return view; + } else { final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false); final ImageView confirmbutton = view.findViewById(R.id.confirmbutton); @@ -142,8 +141,7 @@ public class TempTargetActivity extends ViewSelectorActivity { + " " + isMGDL + " " + SafeParse.stringToInt(time.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); finish(); @@ -158,12 +156,12 @@ public class TempTargetActivity extends ViewSelectorActivity { public void destroyItem(ViewGroup container, int row, int col, Object view) { // Handle this to get the data before the view is destroyed? // Object should still be kept by this, just setup for reinit? - container.removeView((View)view); + container.removeView((View) view); } @Override public boolean isViewFromObject(View view, Object object) { - return view==object; + return view == object; } diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.java index c47ba6f5b3..265eec49bb 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.java @@ -1,7 +1,6 @@ package info.nightscout.androidaps.interaction.actions; -import android.app.Activity; import android.content.SharedPreferences; import android.content.res.Resources; import android.os.Bundle; @@ -13,13 +12,11 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.TextView; import java.text.DecimalFormat; -import info.nightscout.androidaps.aaps; -import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; import info.nightscout.androidaps.interaction.utils.SafeParse; @@ -47,7 +44,7 @@ public class WizardActivity extends ViewSelectorActivity { DotsPageIndicator dotsPageIndicator = findViewById(R.id.page_indicator); dotsPageIndicator.setPager(pager); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); - hasPercentage = sp.getBoolean("wizardpercentage", false); + hasPercentage = sp.getBoolean("wizardpercentage", false); } @@ -61,7 +58,7 @@ public class WizardActivity extends ViewSelectorActivity { private class MyGridViewPagerAdapter extends GridPagerAdapter { @Override public int getColumnCount(int arg0) { - return hasPercentage?3:2; + return hasPercentage ? 3 : 2; } @Override @@ -72,7 +69,7 @@ public class WizardActivity extends ViewSelectorActivity { @Override public Object instantiateItem(ViewGroup container, int row, int col) { - if(col == 0){ + if (col == 0) { final View view = getInflatedPlusMinusView(container); if (editCarbs == null) { 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); } - setLabelToPlusMinusView(view, aaps.gs(R.string.action_carbs)); + setLabelToPlusMinusView(view, getString(R.string.action_carbs)); container.addView(view); return view; - } else if(col == 1 && hasPercentage){ + } else if (col == 1 && hasPercentage) { final View view = getInflatedPlusMinusView(container); if (editPercentage == null) { 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()); 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); return view; } else { @@ -108,7 +105,8 @@ public class WizardActivity extends ViewSelectorActivity { 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()) + " " + percentage; @@ -125,12 +123,12 @@ public class WizardActivity extends ViewSelectorActivity { public void destroyItem(ViewGroup container, int row, int col, Object view) { // Handle this to get the data before the view is destroyed? // Object should still be kept by this, just setup for reinit? - container.removeView((View)view); + container.removeView((View) view); } @Override public boolean isViewFromObject(View view, Object object) { - return view==object; + return view == object; } diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.java index 77dc2b903b..68368e4b48 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.java @@ -3,7 +3,6 @@ package info.nightscout.androidaps.interaction.menus; import android.content.Intent; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.interaction.actions.FillActivity; import info.nightscout.androidaps.interaction.utils.MenuListActivity; @@ -17,22 +16,22 @@ public class FillMenuActivity extends MenuListActivity { @Override protected String[] getElements() { return new String[]{ - aaps.gs(R.string.action_preset_1), - aaps.gs(R.string.action_preset_2), - aaps.gs(R.string.action_preset_3), - aaps.gs(R.string.action_free_amount) + getString(R.string.action_preset_1), + getString(R.string.action_preset_2), + getString(R.string.action_preset_3), + getString(R.string.action_free_amount) }; } @Override 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"); - } 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"); - } 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"); - } 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.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java index d7029fafbf..2697bd8092 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.java @@ -8,10 +8,8 @@ import android.preference.PreferenceManager; import java.util.Vector; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.data.ListenerService; 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.ECarbActivity; import info.nightscout.androidaps.interaction.actions.TempTargetActivity; @@ -39,8 +37,8 @@ public class MainMenuActivity extends MenuListActivity { if(!sharedPreferences.getBoolean("wearcontrol", false)){ return new String[] { - aaps.gs(R.string.menu_settings), - aaps.gs(R.string.menu_resync)}; + getString(R.string.menu_settings), + getString(R.string.menu_resync)}; } @@ -48,13 +46,13 @@ public class MainMenuActivity extends MenuListActivity { boolean showWizard = sp.getBoolean("showWizard", true); Vector menuitems = new Vector(); - menuitems.add(aaps.gs(R.string.menu_tempt)); - if(showWizard) menuitems.add(aaps.gs(R.string.menu_wizard)); - menuitems.add(aaps.gs(R.string.menu_ecarb)); - menuitems.add(aaps.gs(R.string.menu_bolus)); - menuitems.add(aaps.gs(R.string.menu_settings)); - menuitems.add(aaps.gs(R.string.menu_status)); - if (showPrimeFill) menuitems.add(aaps.gs(R.string.menu_prime_fill)); + menuitems.add(getString(R.string.menu_tempt)); + if(showWizard) menuitems.add(getString(R.string.menu_wizard)); + menuitems.add(getString(R.string.menu_ecarb)); + menuitems.add(getString(R.string.menu_bolus)); + menuitems.add(getString(R.string.menu_settings)); + menuitems.add(getString(R.string.menu_status)); + if (showPrimeFill) menuitems.add(getString(R.string.menu_prime_fill)); return menuitems.toArray(new String[menuitems.size()]); } @@ -64,33 +62,33 @@ public class MainMenuActivity extends MenuListActivity { 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.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); } else if ("Re-Sync".equals(action)) { 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.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 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.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 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.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 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.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 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.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 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.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.java index 8d9a78ec5e..1133392a9a 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.java @@ -1,7 +1,6 @@ package info.nightscout.androidaps.interaction.menus; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.aaps; import info.nightscout.androidaps.data.ListenerService; import info.nightscout.androidaps.interaction.utils.MenuListActivity; @@ -14,23 +13,23 @@ public class StatusMenuActivity extends MenuListActivity { @Override protected String[] getElements() { return new String[] { - aaps.gs(R.string.status_pump), - aaps.gs(R.string.status_loop), - aaps.gs(R.string.status_cpp), - aaps.gs(R.string.status_tdd)}; + getString(R.string.status_pump), + getString(R.string.status_loop), + getString(R.string.status_cpp), + getString(R.string.status_tdd)}; } @Override 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"); - } else if (aaps.gs(R.string.status_loop).equals(action)) { + } else if (getString(R.string.status_loop).equals(action)) { 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"); - } else if (aaps.gs(R.string.status_tdd).equals(action)) { + } else if (getString(R.string.status_tdd).equals(action)) { ListenerService.initiateAction(this, "tddstats"); } } diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/DisplayFormat.java b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/DisplayFormat.java index f2cf06671e..95d0ff8aaa 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/DisplayFormat.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/DisplayFormat.java @@ -1,6 +1,6 @@ package info.nightscout.androidaps.interaction.utils; -import info.nightscout.androidaps.aaps; +import info.nightscout.androidaps.Aaps; import info.nightscout.androidaps.data.RawDisplayData; 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 String deltaSymbol() { - return aaps.areComplicationsUnicode() ? "\u0394" : ""; + return Aaps.areComplicationsUnicode() ? "\u0394" : ""; } public static String verticalSeparatorSymbol() { - return aaps.areComplicationsUnicode() ? "\u205E" : "|"; + return Aaps.areComplicationsUnicode() ? "\u205E" : "|"; } public static String basalRateSymbol() { - return aaps.areComplicationsUnicode() ? "\u238D\u2006" : ""; + return Aaps.areComplicationsUnicode() ? "\u238D\u2006" : ""; } public static String shortTimeSince(final long refTime) { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.java b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.java index 36c0ae76ee..3c8ee90d7b 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.java @@ -9,7 +9,7 @@ import com.google.android.gms.wearable.DataMap; import java.util.Set; -import info.nightscout.androidaps.aaps; +import info.nightscout.androidaps.Aaps; /** * Created by dlvoy on 2019-11-12 @@ -21,7 +21,7 @@ public class Persistence { "info.nightscout.androidaps.complications.COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY"; public Persistence() { - preferences = aaps.getAppContext().getSharedPreferences(COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY, 0); + preferences = Aaps.getAppContext().getSharedPreferences(COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY, 0); } @Nullable diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.java b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.java index f8415bdd4a..4f4d3d4ff5 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.java @@ -4,7 +4,6 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.PowerManager; -import android.os.SystemClock; import android.util.Log; import com.google.android.gms.wearable.DataMap; @@ -15,7 +14,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import info.nightscout.androidaps.aaps; +import info.nightscout.androidaps.Aaps; /** * Created by andy on 3/5/19. @@ -66,7 +65,7 @@ public class WearUtil { } 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); wl.acquire(millis); if (debug_wakelocks) Log.d(TAG, "getWakeLock: " + name + " " + wl.toString()); @@ -80,11 +79,11 @@ public class WearUtil { } public static void startActivity(Class c) { - aaps.getAppContext().startActivity(getStartActivityIntent(c)); + Aaps.getAppContext().startActivity(getStartActivityIntent(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) { diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java index 4255263e02..210a8a0846 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java @@ -13,7 +13,6 @@ import android.graphics.Rect; import android.os.PowerManager; import android.os.Vibrator; import android.preference.PreferenceManager; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; import android.support.wearable.view.WatchViewStub; import android.text.format.DateFormat; import android.util.Log; @@ -26,20 +25,21 @@ import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; + 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.WatchMode; import com.ustwo.clockwise.common.WatchShape; +import com.ustwo.clockwise.wearable.WatchFace; import java.text.SimpleDateFormat; 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.complications.BaseComplicationProviderService; +import info.nightscout.androidaps.data.ListenerService; +import info.nightscout.androidaps.data.RawDisplayData; import lecho.lib.hellocharts.view.LineChartView; /** @@ -48,10 +48,19 @@ import lecho.lib.hellocharts.view.LineChartView; * Refactored by dlvoy on 2019-11-2019 */ -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 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; + public static final long[] vibratePattern = {0, 400, 300, 400, 300, 400}; + + 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 RelativeLayout mRelativeLayout; public LinearLayout mLinearLayout, mLinearLayout2, mDate, mChartTap, mMainMenuTap; @@ -71,23 +80,17 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen public int pointSize = 2; public BgGraphBuilder bgGraphBuilder; public LineChartView chart; - - public RawDisplayData rawData = new RawDisplayData(); - public PowerManager.WakeLock wakeLock; // related endTime manual layout public View layoutView; - public final Point displaySize = new Point(); 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 String sMinute = "0"; public String sHour = "0"; + protected SharedPreferences sharedPrefs; + private LocalBroadcastManager localBroadcastManager; + private MessageReceiver messageReceiver; @Override public void onCreate() { @@ -124,55 +127,55 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen localBroadcastManager.registerReceiver(messageReceiver, messageFilter); stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { - @Override - public void onLayoutInflated(WatchViewStub stub) { - mTime = stub.findViewById(R.id.watch_time); - mHour = stub.findViewById(R.id.hour); - mMinute = stub.findViewById(R.id.minute); - mDay = stub.findViewById(R.id.day); - mDayName= stub.findViewById(R.id.dayname); - mMonth = stub.findViewById(R.id.month); - mDate = stub.findViewById(R.id.date_time); - mLoop = stub.findViewById(R.id.loop); - mSgv = stub.findViewById(R.id.sgv); - mDirection = stub.findViewById(R.id.direction); - mTimestamp = stub.findViewById(R.id.timestamp); - mIOB1 = stub.findViewById(R.id.iob_text); - mIOB2 = stub.findViewById(R.id.iobView); - mCOB1 = stub.findViewById(R.id.cob_text); - mCOB2 = stub.findViewById(R.id.cobView); - mBgi = stub.findViewById(R.id.bgiView); - mStatus = stub.findViewById(R.id.externaltstatus); - mBasalRate = stub.findViewById(R.id.tmpBasal); - mUploaderBattery = stub.findViewById(R.id.uploader_battery); - mRigBattery = stub.findViewById(R.id.rig_battery); - mDelta = stub.findViewById(R.id.delta); - mAvgDelta = stub.findViewById(R.id.avgdelta); - isAAPSv2 = stub.findViewById(R.id.AAPSv2); - mHighLight = stub.findViewById(R.id.highLight); - mLowLight = stub.findViewById(R.id.lowLight); - mRelativeLayout = stub.findViewById(R.id.main_layout); - mLinearLayout = stub.findViewById(R.id.secondary_layout); - mLinearLayout2 = stub.findViewById(R.id.tertiary_layout); - mGlucoseDial = stub.findViewById(R.id.glucose_dial); - mDeltaGauge = stub.findViewById(R.id.delta_pointer); - mHourHand = stub.findViewById(R.id.hour_hand); - mMinuteHand = stub.findViewById(R.id.minute_hand); - mChartTap = stub.findViewById(R.id.chart_zoom_tap); - mMainMenuTap = stub.findViewById(R.id.main_menu_tap); - chart = stub.findViewById(R.id.chart); - layoutSet = true; + @Override + public void onLayoutInflated(WatchViewStub stub) { + mTime = stub.findViewById(R.id.watch_time); + mHour = stub.findViewById(R.id.hour); + mMinute = stub.findViewById(R.id.minute); + mDay = stub.findViewById(R.id.day); + mDayName = stub.findViewById(R.id.dayname); + mMonth = stub.findViewById(R.id.month); + mDate = stub.findViewById(R.id.date_time); + mLoop = stub.findViewById(R.id.loop); + mSgv = stub.findViewById(R.id.sgv); + mDirection = stub.findViewById(R.id.direction); + mTimestamp = stub.findViewById(R.id.timestamp); + mIOB1 = stub.findViewById(R.id.iob_text); + mIOB2 = stub.findViewById(R.id.iobView); + mCOB1 = stub.findViewById(R.id.cob_text); + mCOB2 = stub.findViewById(R.id.cobView); + mBgi = stub.findViewById(R.id.bgiView); + mStatus = stub.findViewById(R.id.externaltstatus); + mBasalRate = stub.findViewById(R.id.tmpBasal); + mUploaderBattery = stub.findViewById(R.id.uploader_battery); + mRigBattery = stub.findViewById(R.id.rig_battery); + mDelta = stub.findViewById(R.id.delta); + mAvgDelta = stub.findViewById(R.id.avgdelta); + isAAPSv2 = stub.findViewById(R.id.AAPSv2); + mHighLight = stub.findViewById(R.id.highLight); + mLowLight = stub.findViewById(R.id.lowLight); + mRelativeLayout = stub.findViewById(R.id.main_layout); + mLinearLayout = stub.findViewById(R.id.secondary_layout); + mLinearLayout2 = stub.findViewById(R.id.tertiary_layout); + mGlucoseDial = stub.findViewById(R.id.glucose_dial); + mDeltaGauge = stub.findViewById(R.id.delta_pointer); + mHourHand = stub.findViewById(R.id.hour_hand); + mMinuteHand = stub.findViewById(R.id.minute_hand); + mChartTap = stub.findViewById(R.id.chart_zoom_tap); + mMainMenuTap = stub.findViewById(R.id.main_menu_tap); + chart = stub.findViewById(R.id.chart); + layoutSet = true; - setDataFields(); - setColor(); - } - } + setDataFields(); + setColor(); + } + } ); wakeLock.acquire(50); } public int ageLevel() { - if(timeSince() <= (1000 * 60 * 12)) { + if (timeSince() <= (1000 * 60 * 12)) { return 1; } else { return 0; @@ -184,12 +187,14 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen } public String readingAge(boolean shortString) { - if (rawData.datetime == 0) { return shortString?"--'":"-- Minute ago"; } - int minutesAgo = (int) Math.floor(timeSince()/(1000*60)); - if (minutesAgo == 1) { - return minutesAgo + (shortString?"'":" Minute ago"); + if (rawData.datetime == 0) { + return 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 @@ -203,13 +208,6 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen 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 protected void onDraw(Canvas canvas) { if (layoutSet) { @@ -234,7 +232,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen setDataFields(); setColor(); missedReadingAlert(); - checkVibrateHourly(oldTime,newTime); + checkVibrateHourly(oldTime, newTime); mRelativeLayout.measure(specW, specH); 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); if (hourlyVibratePref && layoutSet && newTime.hasHourChanged(oldTime)) { 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() { setDateAndTime(); @@ -339,7 +307,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen mCOB1.setVisibility(View.GONE); mCOB2.setVisibility(View.GONE); } - //deal with cases where there is only the value shown for COB, and not the label + //deal with cases where there is only the value shown for COB, and not the label } else if (mCOB2 != null) { mCOB2.setText(rawData.sCOB2); if (sharedPrefs.getBoolean("show_cob", true)) { @@ -357,14 +325,14 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen mIOB1.setText(rawData.sIOB1); mIOB2.setText(rawData.sIOB2); } else { - mIOB1.setText(aaps.gs(R.string.activity_IOB)); + mIOB1.setText(getString(R.string.activity_IOB)); mIOB2.setText(rawData.sIOB1); } } else { mIOB1.setVisibility(View.GONE); mIOB2.setVisibility(View.GONE); } - //deal with cases where there is only the value shown for IOB, and not the label + //deal with cases where there is only the value shown for IOB, and not the label } else if (mIOB2 != null) { if (sharedPrefs.getBoolean("show_iob", true)) { mIOB2.setVisibility(View.VISIBLE); @@ -398,8 +366,8 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen if (mUploaderBattery != null) { if (sharedPrefs.getBoolean("show_uploader_battery", true)) { if (isAAPSv2 != null) { - mUploaderBattery.setText(rawData.sUploaderBattery + "%"); - mUploaderBattery.setVisibility(View.VISIBLE); + mUploaderBattery.setText(rawData.sUploaderBattery + "%"); + mUploaderBattery.setVisibility(View.VISIBLE); } else { if (sharedPrefs.getBoolean("showExternalStatus", true)) { mUploaderBattery.setText("U: " + rawData.sUploaderBattery + "%"); @@ -438,7 +406,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen mBgi.setVisibility(View.GONE); } } - + if (mStatus != null) { if (sharedPrefs.getBoolean("showExternalStatus", true)) { mStatus.setText(rawData.externalStatusString); @@ -483,14 +451,14 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen sHour = sdfHour.format(now); sMinute = sdfMinute.format(now); - if (mHour != null && mMinute != null ) { + if (mHour != null && mMinute != null) { mHour.setText(sHour); mMinute.setText(sMinute); } if (mDate != null && mDay != null && mMonth != null) { if (sharedPrefs.getBoolean("show_date", false)) { - if (mDayName != null ) { + if (mDayName != null) { SimpleDateFormat sdfDayName = new SimpleDateFormat("E"); mDayName.setText(sdfDayName.format(now)); } @@ -508,7 +476,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen public void setColor() { dividerMatchesBg = sharedPrefs.getBoolean("match_divider", false); - if(lowResMode){ + if (lowResMode) { setColorLowRes(); } else if (sharedPrefs.getBoolean("dark", true)) { setColorDark(); @@ -518,7 +486,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen } public void strikeThroughSgvIfNeeded() { - if (mSgv !=null) { + if (mSgv != null) { if (sharedPrefs.getBoolean("showBG", true)) { if (ageLevel() <= 0) { 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) { - 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); setColor(); - } else if (! sharedPrefs.getBoolean("dark", true)){ + } else if (!sharedPrefs.getBoolean("dark", true)) { //in bright mode: different colours if active: setColor(); } @@ -545,13 +513,13 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen } @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); } - - if(layoutSet){ + + if (layoutSet) { setDataFields(); setColor(); } @@ -559,18 +527,20 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen } protected abstract void setColorDark(); + protected abstract void setColorBright(); + protected abstract void setColorLowRes(); public void missedReadingAlert() { - int minutes_since = (int) Math.floor(timeSince()/(1000*60)); - if(minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) { + int minutes_since = (int) Math.floor(timeSince() / (1000 * 60)); + if (minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) { ListenerService.requestData(this); // attempt endTime recover missing data } } 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")); if (lowResMode) { 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(); + } + } + } diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml index 715bda4d95..9c4bca91da 100644 --- a/wear/src/main/res/values/strings.xml +++ b/wear/src/main/res/values/strings.xml @@ -150,7 +150,10 @@ Your color: Your color saturation: Your color opacity: - + AAPS Bolus Progress + AAPS Bolus Progress Silent + Bolus progress and cancel + Bolus progress and cancel with less vibrations diff --git a/wear/src/test/java/info/nightscout/androidaps/data/RawDataSgvDisplayDataTest.java b/wear/src/test/java/info/nightscout/androidaps/data/RawDataSgvDisplayDataTest.java index fa73a0272e..0fa4e971e0 100644 --- a/wear/src/test/java/info/nightscout/androidaps/data/RawDataSgvDisplayDataTest.java +++ b/wear/src/test/java/info/nightscout/androidaps/data/RawDataSgvDisplayDataTest.java @@ -14,7 +14,7 @@ import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; 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.Persistence; import info.nightscout.androidaps.interaction.utils.WearUtil; @@ -28,7 +28,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @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 { @Before diff --git a/wear/src/test/java/info/nightscout/androidaps/data/RawDisplayDataBasalsTest.java b/wear/src/test/java/info/nightscout/androidaps/data/RawDisplayDataBasalsTest.java index 1245d0fbcb..e6abc02e4a 100644 --- a/wear/src/test/java/info/nightscout/androidaps/data/RawDisplayDataBasalsTest.java +++ b/wear/src/test/java/info/nightscout/androidaps/data/RawDisplayDataBasalsTest.java @@ -16,7 +16,7 @@ import org.powermock.modules.junit4.PowerMockRunner; 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.Persistence; import info.nightscout.androidaps.interaction.utils.WearUtil; @@ -34,7 +34,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @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 { @Before diff --git a/wear/src/test/java/info/nightscout/androidaps/data/RawDisplayDataStatusTest.java b/wear/src/test/java/info/nightscout/androidaps/data/RawDisplayDataStatusTest.java index da0daea608..8c0372fca1 100644 --- a/wear/src/test/java/info/nightscout/androidaps/data/RawDisplayDataStatusTest.java +++ b/wear/src/test/java/info/nightscout/androidaps/data/RawDisplayDataStatusTest.java @@ -14,7 +14,7 @@ import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; 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.Persistence; import info.nightscout.androidaps.interaction.utils.WearUtil; @@ -30,7 +30,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @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 { @Before diff --git a/wear/src/test/java/info/nightscout/androidaps/interaction/utils/DisplayFormatTest.java b/wear/src/test/java/info/nightscout/androidaps/interaction/utils/DisplayFormatTest.java index 98fb4fd11b..e0da2f4f55 100644 --- a/wear/src/test/java/info/nightscout/androidaps/interaction/utils/DisplayFormatTest.java +++ b/wear/src/test/java/info/nightscout/androidaps/interaction/utils/DisplayFormatTest.java @@ -10,7 +10,7 @@ import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; 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.testing.mockers.AAPSMocker; import info.nightscout.androidaps.testing.mockers.WearUtilMocker; @@ -30,7 +30,7 @@ import static org.junit.Assert.assertThat; */ @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 { @Before diff --git a/wear/src/test/java/info/nightscout/androidaps/interaction/utils/PersistenceTest.java b/wear/src/test/java/info/nightscout/androidaps/interaction/utils/PersistenceTest.java index 1faa4ddfe7..bb3f778f20 100644 --- a/wear/src/test/java/info/nightscout/androidaps/interaction/utils/PersistenceTest.java +++ b/wear/src/test/java/info/nightscout/androidaps/interaction/utils/PersistenceTest.java @@ -14,7 +14,7 @@ import org.powermock.modules.junit4.PowerMockRunner; 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.AndroidMocker; import info.nightscout.androidaps.testing.mockers.LogMocker; @@ -29,7 +29,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @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 { @Before diff --git a/wear/src/test/java/info/nightscout/androidaps/testing/mockers/AAPSMocker.java b/wear/src/test/java/info/nightscout/androidaps/testing/mockers/AAPSMocker.java index 7684d169f1..3c52ca721d 100644 --- a/wear/src/test/java/info/nightscout/androidaps/testing/mockers/AAPSMocker.java +++ b/wear/src/test/java/info/nightscout/androidaps/testing/mockers/AAPSMocker.java @@ -3,7 +3,6 @@ package info.nightscout.androidaps.testing.mockers; import android.content.Context; import android.content.SharedPreferences; -import org.junit.Assert; import org.mockito.ArgumentMatchers; import org.mockito.invocation.InvocationOnMock; import org.powermock.api.mockito.PowerMockito; @@ -11,7 +10,7 @@ import org.powermock.api.mockito.PowerMockito; import java.util.HashMap; import java.util.Map; -import info.nightscout.androidaps.aaps; +import info.nightscout.androidaps.Aaps; import info.nightscout.androidaps.testing.mocks.SharedPreferencesMock; import static org.mockito.Mockito.mock; @@ -24,9 +23,9 @@ public class AAPSMocker { public static void prepareMock() throws Exception { 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 -> { final String key = invocation.getArgument(0); @@ -38,7 +37,7 @@ public class AAPSMocker { return newPrefs; } }); - PowerMockito.when(aaps.class, "areComplicationsUnicode").thenAnswer(invocation -> unicodeComplicationsOn); + PowerMockito.when(Aaps.class, "areComplicationsUnicode").thenAnswer(invocation -> unicodeComplicationsOn); setMockedUnicodeComplicationsOn(true); resetMockedSharedPrefs();