Wear: fix Complication injection

This commit is contained in:
Milos Kozak 2022-01-07 17:57:04 +01:00
parent c165c91d1d
commit fd814baa60
13 changed files with 127 additions and 127 deletions

View file

@ -12,7 +12,6 @@ import android.support.wearable.complications.ComplicationManager;
import android.support.wearable.complications.ComplicationProviderService; import android.support.wearable.complications.ComplicationProviderService;
import android.support.wearable.complications.ComplicationText; import android.support.wearable.complications.ComplicationText;
import android.support.wearable.complications.ProviderUpdateRequester; import android.support.wearable.complications.ProviderUpdateRequester;
import android.util.Log;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -30,6 +29,8 @@ import info.nightscout.androidaps.interaction.utils.DisplayFormat;
import info.nightscout.androidaps.interaction.utils.Inevitable; import info.nightscout.androidaps.interaction.utils.Inevitable;
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;
import info.nightscout.shared.logging.AAPSLogger;
import info.nightscout.shared.logging.LTag;
/** /**
* Base class for all complications * Base class for all complications
@ -42,6 +43,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
@Inject WearUtil wearUtil; @Inject WearUtil wearUtil;
@Inject DisplayFormat displayFormat; @Inject DisplayFormat displayFormat;
@Inject Persistence persistence; @Inject Persistence persistence;
@Inject AAPSLogger aapsLogger;
// Not derived from DaggerService, do injection here // Not derived from DaggerService, do injection here
@Override @Override
@ -50,8 +52,6 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
super.onCreate(); super.onCreate();
} }
private static final String TAG = BaseComplicationProviderService.class.getSimpleName();
public static final String KEY_COMPLICATIONS = "complications"; public static final String KEY_COMPLICATIONS = "complications";
private static final String KEY_LAST_SHOWN_SINCE_VALUE = "lastSince"; private static final String KEY_LAST_SHOWN_SINCE_VALUE = "lastSince";
private static final String KEY_STALE_REPORTED = "staleReported"; private static final String KEY_STALE_REPORTED = "staleReported";
@ -116,9 +116,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
case ComplicationData.TYPE_LARGE_IMAGE: case ComplicationData.TYPE_LARGE_IMAGE:
return buildComplicationData(dataType, raw, complicationPendingIntent); return buildComplicationData(dataType, raw, complicationPendingIntent);
default: default:
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
break; break;
} }
@ -165,9 +163,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
case ComplicationData.TYPE_LARGE_IMAGE: case ComplicationData.TYPE_LARGE_IMAGE:
return buildComplicationData(dataType, raw, complicationPendingIntent); return buildComplicationData(dataType, raw, complicationPendingIntent);
default: default:
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
break; break;
} }
@ -197,7 +193,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
@Override @Override
public void onComplicationActivated( public void onComplicationActivated(
int complicationId, int dataType, ComplicationManager complicationManager) { int complicationId, int dataType, ComplicationManager complicationManager) {
Log.d(TAG, "onComplicationActivated(): " + complicationId + " of kind: " + getProviderCanonicalName()); aapsLogger.warn(LTag.WEAR, "onComplicationActivated(): " + complicationId + " of kind: " + getProviderCanonicalName());
persistence.putString("complication_" + complicationId, getProviderCanonicalName()); persistence.putString("complication_" + complicationId, getProviderCanonicalName());
persistence.putBoolean("complication_" + complicationId + "_since", usesSinceField()); persistence.putBoolean("complication_" + complicationId + "_since", usesSinceField());
@ -226,7 +222,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
@Override @Override
public void onComplicationUpdate( public void onComplicationUpdate(
int complicationId, int dataType, ComplicationManager complicationManager) { int complicationId, int dataType, ComplicationManager complicationManager) {
Log.d(TAG, "onComplicationUpdate() id: " + complicationId + " of class: " + getProviderCanonicalName()); aapsLogger.warn(LTag.WEAR, "onComplicationUpdate() id: " + complicationId + " of class: " + getProviderCanonicalName());
// Create Tap Action so that the user can checkIfUpdateNeeded an update by tapping the complication. // Create Tap Action so that the user can checkIfUpdateNeeded an update by tapping the complication.
final ComponentName thisProvider = new ComponentName(this, getProviderCanonicalName()); final ComponentName thisProvider = new ComponentName(this, getProviderCanonicalName());
@ -238,7 +234,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
final RawDisplayData raw = new RawDisplayData(wearUtil); final RawDisplayData raw = new RawDisplayData(wearUtil);
raw.updateForComplicationsFromPersistence(persistence); raw.updateForComplicationsFromPersistence(persistence);
Log.d(TAG, "Complication data: " + raw.toDebugString()); aapsLogger.warn(LTag.WEAR, "Complication data: " + raw.toDebugString());
// store what is currently rendered in 'SGV since' field, to detect if it was changed and need update // store what is currently rendered in 'SGV since' field, to detect if it was changed and need update
persistence.putString(KEY_LAST_SHOWN_SINCE_VALUE, displayFormat.shortTimeSince(raw.datetime)); persistence.putString(KEY_LAST_SHOWN_SINCE_VALUE, displayFormat.shortTimeSince(raw.datetime));
@ -277,7 +273,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
*/ */
@Override @Override
public void onComplicationDeactivated(int complicationId) { public void onComplicationDeactivated(int complicationId) {
Log.d(TAG, "onComplicationDeactivated(): " + complicationId); aapsLogger.warn(LTag.WEAR, "onComplicationDeactivated(): " + complicationId);
persistence.removeFromSet(KEY_COMPLICATIONS, "complication_" + complicationId); persistence.removeFromSet(KEY_COMPLICATIONS, "complication_" + complicationId);
@ -296,11 +292,11 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
*/ */
public void checkIfUpdateNeeded() { public void checkIfUpdateNeeded() {
Log.d(TAG, "Pending check if update needed - " + persistence.getString(KEY_COMPLICATIONS, "")); aapsLogger.warn(LTag.WEAR, "Pending check if update needed - " + persistence.getString(KEY_COMPLICATIONS, ""));
inevitable.task(TASK_ID_REFRESH_COMPLICATION, 15 * Constants.SECOND_IN_MS, () -> { inevitable.task(TASK_ID_REFRESH_COMPLICATION, 15 * Constants.SECOND_IN_MS, () -> {
if (wearUtil.isBelowRateLimit("complication-checkIfUpdateNeeded", 5)) { if (wearUtil.isBelowRateLimit("complication-checkIfUpdateNeeded", 5)) {
Log.d(TAG, "Checking if update needed"); aapsLogger.warn(LTag.WEAR, "Checking if update needed");
requestUpdateIfSinceChanged(); requestUpdateIfSinceChanged();
// We reschedule need for check - to make sure next check will Inevitable go in next 15s // We reschedule need for check - to make sure next check will Inevitable go in next 15s
checkIfUpdateNeeded(); checkIfUpdateNeeded();
@ -329,7 +325,7 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
persistence.putString(KEY_LAST_SHOWN_SINCE_VALUE, calcSince); persistence.putString(KEY_LAST_SHOWN_SINCE_VALUE, calcSince);
persistence.putBoolean(KEY_STALE_REPORTED, isStale); persistence.putBoolean(KEY_STALE_REPORTED, isStale);
Log.d(TAG, "Detected refresh of time needed! Reason: " aapsLogger.warn(LTag.WEAR, "Detected refresh of time needed! Reason: "
+ (isStale ? "- stale detected" : "") + (isStale ? "- stale detected" : "")
+ (sinceWasChanged ? "- since changed from: " + lastSince + " to: " + calcSince : "")); + (sinceWasChanged ? "- since changed from: " + lastSince + " to: " + calcSince : ""));
@ -348,11 +344,11 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid
*/ */
private void requestUpdate(Set<String> providers) { private void requestUpdate(Set<String> providers) {
for (String provider : providers) { for (String provider : providers) {
Log.d(TAG, "Pending update of " + provider); aapsLogger.warn(LTag.WEAR, "Pending update of " + provider);
// We wait with updating allowing all request, from various sources, to arrive // We wait with updating allowing all request, from various sources, to arrive
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); aapsLogger.warn(LTag.WEAR, "Requesting update of " + provider);
final ComponentName componentName = new ComponentName(getApplicationContext(), provider); final ComponentName componentName = new ComponentName(getApplicationContext(), provider);
final ProviderUpdateRequester providerUpdateRequester = new ProviderUpdateRequester(getApplicationContext(), componentName); final ProviderUpdateRequester providerUpdateRequester = new ProviderUpdateRequester(getApplicationContext(), componentName);
providerUpdateRequester.requestUpdateAll(); providerUpdateRequester.requestUpdateAll();

View file

@ -11,6 +11,7 @@ import dagger.android.AndroidInjection;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.interaction.utils.DisplayFormat; import info.nightscout.androidaps.interaction.utils.DisplayFormat;
import info.nightscout.androidaps.interaction.utils.SmallestDoubleString; import info.nightscout.androidaps.interaction.utils.SmallestDoubleString;
import info.nightscout.shared.logging.LTag;
/* /*
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
@ -26,26 +27,22 @@ public class BrCobIobComplication extends BaseComplicationProviderService {
super.onCreate(); super.onCreate();
} }
private static final String TAG = BrCobIobComplication.class.getSimpleName();
public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) { public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) {
ComplicationData complicationData = null; ComplicationData complicationData = null;
if (dataType == ComplicationData.TYPE_SHORT_TEXT) { if (dataType == ComplicationData.TYPE_SHORT_TEXT) {
final String cob = new SmallestDoubleString(raw.sCOB2, SmallestDoubleString.Units.USE).minimise(displayFormat.MIN_FIELD_LEN_COB); final String cob = new SmallestDoubleString(raw.sCOB2, SmallestDoubleString.Units.USE).minimise(displayFormat.MIN_FIELD_LEN_COB);
final String iob = new SmallestDoubleString(raw.sIOB1, SmallestDoubleString.Units.USE).minimise(Math.max(displayFormat.MIN_FIELD_LEN_IOB, (displayFormat.MAX_FIELD_LEN_SHORT -1) - cob.length())); final String iob = new SmallestDoubleString(raw.sIOB1, SmallestDoubleString.Units.USE).minimise(Math.max(displayFormat.MIN_FIELD_LEN_IOB, (displayFormat.MAX_FIELD_LEN_SHORT - 1) - cob.length()));
final ComplicationData.Builder builder = new ComplicationData.Builder(ComplicationData.TYPE_SHORT_TEXT) final ComplicationData.Builder builder = new ComplicationData.Builder(ComplicationData.TYPE_SHORT_TEXT)
.setShortText(ComplicationText.plainText(displayFormat.basalRateSymbol()+raw.sBasalRate)) .setShortText(ComplicationText.plainText(displayFormat.basalRateSymbol() + raw.sBasalRate))
.setShortTitle(ComplicationText.plainText(cob + " " + iob)) .setShortTitle(ComplicationText.plainText(cob + " " + iob))
.setTapAction(complicationPendingIntent); .setTapAction(complicationPendingIntent);
complicationData = builder.build(); complicationData = builder.build();
} else { } else {
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
} }
return complicationData; return complicationData;
} }

View file

@ -3,19 +3,16 @@ package info.nightscout.androidaps.complications;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.support.wearable.complications.ComplicationData; import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationText; import android.support.wearable.complications.ComplicationText;
import android.util.Log;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.interaction.utils.DisplayFormat;
import info.nightscout.androidaps.interaction.utils.Pair; import info.nightscout.androidaps.interaction.utils.Pair;
import info.nightscout.shared.logging.LTag;
/* /*
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
*/ */
public class CobDetailedComplication extends BaseComplicationProviderService { public class CobDetailedComplication extends BaseComplicationProviderService {
private static final String TAG = CobDetailedComplication.class.getSimpleName();
public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) { public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) {
ComplicationData complicationData = null; ComplicationData complicationData = null;
@ -33,9 +30,7 @@ public class CobDetailedComplication extends BaseComplicationProviderService {
complicationData = builder.build(); complicationData = builder.build();
} else { } else {
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
} }
return complicationData; return complicationData;
} }

View file

@ -4,18 +4,16 @@ import android.app.PendingIntent;
import android.graphics.drawable.Icon; import android.graphics.drawable.Icon;
import android.support.wearable.complications.ComplicationData; import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationText; import android.support.wearable.complications.ComplicationText;
import android.util.Log;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.shared.logging.LTag;
/* /*
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
*/ */
public class CobIconComplication extends BaseComplicationProviderService { public class CobIconComplication extends BaseComplicationProviderService {
private static final String TAG = CobIconComplication.class.getSimpleName();
public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) { public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) {
ComplicationData complicationData = null; ComplicationData complicationData = null;
@ -33,9 +31,7 @@ public class CobIconComplication extends BaseComplicationProviderService {
complicationData = builder.build(); complicationData = builder.build();
} else { } else {
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
} }
return complicationData; return complicationData;
} }

View file

@ -3,19 +3,16 @@ package info.nightscout.androidaps.complications;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.support.wearable.complications.ComplicationData; import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationText; import android.support.wearable.complications.ComplicationText;
import android.util.Log;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.interaction.utils.DisplayFormat;
import info.nightscout.androidaps.interaction.utils.SmallestDoubleString; import info.nightscout.androidaps.interaction.utils.SmallestDoubleString;
import info.nightscout.shared.logging.LTag;
/* /*
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
*/ */
public class CobIobComplication extends BaseComplicationProviderService { public class CobIobComplication extends BaseComplicationProviderService {
private static final String TAG = CobIobComplication.class.getSimpleName();
public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) { public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) {
ComplicationData complicationData = null; ComplicationData complicationData = null;
@ -31,9 +28,7 @@ public class CobIobComplication extends BaseComplicationProviderService {
complicationData = builder.build(); complicationData = builder.build();
} else { } else {
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
} }
return complicationData; return complicationData;
} }

View file

@ -3,19 +3,16 @@ package info.nightscout.androidaps.complications;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.support.wearable.complications.ComplicationData; import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationText; import android.support.wearable.complications.ComplicationText;
import android.util.Log;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.interaction.utils.DisplayFormat;
import info.nightscout.androidaps.interaction.utils.Pair; import info.nightscout.androidaps.interaction.utils.Pair;
import info.nightscout.shared.logging.LTag;
/* /*
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
*/ */
public class IobDetailedComplication extends BaseComplicationProviderService { public class IobDetailedComplication extends BaseComplicationProviderService {
private static final String TAG = IobDetailedComplication.class.getSimpleName();
public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) { public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) {
ComplicationData complicationData = null; ComplicationData complicationData = null;
@ -33,9 +30,7 @@ public class IobDetailedComplication extends BaseComplicationProviderService {
complicationData = builder.build(); complicationData = builder.build();
} else { } else {
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
} }
return complicationData; return complicationData;
} }

View file

@ -4,20 +4,17 @@ import android.app.PendingIntent;
import android.graphics.drawable.Icon; import android.graphics.drawable.Icon;
import android.support.wearable.complications.ComplicationData; import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationText; import android.support.wearable.complications.ComplicationText;
import android.util.Log;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.interaction.utils.DisplayFormat;
import info.nightscout.androidaps.interaction.utils.SmallestDoubleString; import info.nightscout.androidaps.interaction.utils.SmallestDoubleString;
import info.nightscout.shared.logging.LTag;
/* /*
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
*/ */
public class IobIconComplication extends BaseComplicationProviderService { public class IobIconComplication extends BaseComplicationProviderService {
private static final String TAG = IobIconComplication.class.getSimpleName();
public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) { public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) {
ComplicationData complicationData = null; ComplicationData complicationData = null;
@ -36,9 +33,7 @@ public class IobIconComplication extends BaseComplicationProviderService {
complicationData = builder.build(); complicationData = builder.build();
} else { } else {
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
} }
return complicationData; return complicationData;
} }

View file

@ -3,13 +3,13 @@ package info.nightscout.androidaps.complications;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.support.wearable.complications.ComplicationData; import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationText; import android.support.wearable.complications.ComplicationText;
import android.util.Log;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.android.AndroidInjection; import dagger.android.AndroidInjection;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.interaction.utils.DisplayFormat; import info.nightscout.androidaps.interaction.utils.DisplayFormat;
import info.nightscout.shared.logging.LTag;
/* /*
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
@ -25,8 +25,6 @@ public class LongStatusComplication extends BaseComplicationProviderService {
super.onCreate(); super.onCreate();
} }
private static final String TAG = LongStatusComplication.class.getSimpleName();
public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) { public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) {
ComplicationData complicationData = null; ComplicationData complicationData = null;
@ -45,9 +43,7 @@ public class LongStatusComplication extends BaseComplicationProviderService {
break; break;
default: default:
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
} }
return complicationData; return complicationData;
} }

View file

@ -3,13 +3,13 @@ package info.nightscout.androidaps.complications;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.support.wearable.complications.ComplicationData; import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationText; import android.support.wearable.complications.ComplicationText;
import android.util.Log;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.android.AndroidInjection; import dagger.android.AndroidInjection;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.interaction.utils.DisplayFormat; import info.nightscout.androidaps.interaction.utils.DisplayFormat;
import info.nightscout.shared.logging.LTag;
/* /*
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
@ -25,8 +25,6 @@ public class LongStatusFlippedComplication extends BaseComplicationProviderServi
super.onCreate(); super.onCreate();
} }
private static final String TAG = LongStatusFlippedComplication.class.getSimpleName();
public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) { public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) {
ComplicationData complicationData = null; ComplicationData complicationData = null;
@ -45,9 +43,7 @@ public class LongStatusFlippedComplication extends BaseComplicationProviderServi
break; break;
default: default:
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
} }
return complicationData; return complicationData;
} }

View file

@ -3,13 +3,13 @@ package info.nightscout.androidaps.complications;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.support.wearable.complications.ComplicationData; import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationText; import android.support.wearable.complications.ComplicationText;
import android.util.Log;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.android.AndroidInjection; import dagger.android.AndroidInjection;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.interaction.utils.DisplayFormat; import info.nightscout.androidaps.interaction.utils.DisplayFormat;
import info.nightscout.shared.logging.LTag;
/* /*
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
@ -25,8 +25,6 @@ public class SgvComplication extends BaseComplicationProviderService {
super.onCreate(); super.onCreate();
} }
private static final String TAG = SgvComplication.class.getSimpleName();
public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) { public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) {
ComplicationData complicationData = null; ComplicationData complicationData = null;
@ -41,9 +39,7 @@ public class SgvComplication extends BaseComplicationProviderService {
complicationData = builder.build(); complicationData = builder.build();
break; break;
default: default:
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
} }
return complicationData; return complicationData;
} }

View file

@ -4,19 +4,18 @@ import android.app.PendingIntent;
import android.graphics.drawable.Icon; import android.graphics.drawable.Icon;
import android.support.wearable.complications.ComplicationData; import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationText; import android.support.wearable.complications.ComplicationText;
import android.util.Log;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.shared.logging.LTag;
/* /*
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
*/ */
public class UploaderBattery extends BaseComplicationProviderService { public class UploaderBattery extends BaseComplicationProviderService {
private static final String TAG = UploaderBattery.class.getSimpleName();
public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) { public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) {
ComplicationData complicationData = null; ComplicationData complicationData = null;
@ -31,43 +30,89 @@ public class UploaderBattery extends BaseComplicationProviderService {
level = Integer.parseInt(raw.sUploaderBattery); level = Integer.parseInt(raw.sUploaderBattery);
level = Math.max(Math.min(level, 100), 0); level = Math.max(Math.min(level, 100), 0);
levelStr = level + "%"; levelStr = level + "%";
int iconNo = (int)Math.floor(level / 10.0); int iconNo = (int) Math.floor(level / 10.0);
if (level > 95) { if (level > 95) {
iconNo = 10; iconNo = 10;
} }
switch (iconNo) { switch (iconNo) {
case 10: batteryIcon = R.drawable.ic_battery_charging_wireless; break; case 10:
case 9: batteryIcon = R.drawable.ic_battery_charging_wireless_90; break; batteryIcon = R.drawable.ic_battery_charging_wireless;
case 8: batteryIcon = R.drawable.ic_battery_charging_wireless_80; break; break;
case 7: batteryIcon = R.drawable.ic_battery_charging_wireless_70; break; case 9:
case 6: batteryIcon = R.drawable.ic_battery_charging_wireless_60; break; batteryIcon = R.drawable.ic_battery_charging_wireless_90;
case 5: batteryIcon = R.drawable.ic_battery_charging_wireless_50; break; break;
case 4: batteryIcon = R.drawable.ic_battery_charging_wireless_40; break; case 8:
case 3: batteryIcon = R.drawable.ic_battery_charging_wireless_30; break; batteryIcon = R.drawable.ic_battery_charging_wireless_80;
case 2: batteryIcon = R.drawable.ic_battery_charging_wireless_20; break; break;
case 1: batteryIcon = R.drawable.ic_battery_charging_wireless_10; break; case 7:
case 0: batteryIcon = R.drawable.ic_battery_alert_variant_outline; break; batteryIcon = R.drawable.ic_battery_charging_wireless_70;
default: batteryIcon = R.drawable.ic_battery_charging_wireless_outline; break;
case 6:
batteryIcon = R.drawable.ic_battery_charging_wireless_60;
break;
case 5:
batteryIcon = R.drawable.ic_battery_charging_wireless_50;
break;
case 4:
batteryIcon = R.drawable.ic_battery_charging_wireless_40;
break;
case 3:
batteryIcon = R.drawable.ic_battery_charging_wireless_30;
break;
case 2:
batteryIcon = R.drawable.ic_battery_charging_wireless_20;
break;
case 1:
batteryIcon = R.drawable.ic_battery_charging_wireless_10;
break;
case 0:
batteryIcon = R.drawable.ic_battery_alert_variant_outline;
break;
default:
batteryIcon = R.drawable.ic_battery_charging_wireless_outline;
} }
switch (iconNo) { switch (iconNo) {
case 10: burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_burnin; break; case 10:
case 9: burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_90_burnin; break; burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_burnin;
case 8: burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_80_burnin; break; break;
case 7: burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_70_burnin; break; case 9:
case 6: burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_60_burnin; break; burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_90_burnin;
case 5: burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_50_burnin; break; break;
case 4: burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_40_burnin; break; case 8:
case 3: burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_30_burnin; break; burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_80_burnin;
case 2: burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_20_burnin; break; break;
case 1: burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_10_burnin; break; case 7:
case 0: burnInBatteryIcon = R.drawable.ic_battery_alert_variant_outline; break; burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_70_burnin;
default: burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_outline; break;
case 6:
burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_60_burnin;
break;
case 5:
burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_50_burnin;
break;
case 4:
burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_40_burnin;
break;
case 3:
burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_30_burnin;
break;
case 2:
burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_20_burnin;
break;
case 1:
burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_10_burnin;
break;
case 0:
burnInBatteryIcon = R.drawable.ic_battery_alert_variant_outline;
break;
default:
burnInBatteryIcon = R.drawable.ic_battery_charging_wireless_outline;
} }
} catch (NumberFormatException ex){ } catch (NumberFormatException ex) {
Log.e(TAG, "Cannot parse battery level of: " + raw.sUploaderBattery); aapsLogger.error(LTag.WEAR, "Cannot parse battery level of: " + raw.sUploaderBattery);
} }
} }
@ -95,9 +140,7 @@ public class UploaderBattery extends BaseComplicationProviderService {
.setTapAction(complicationPendingIntent); .setTapAction(complicationPendingIntent);
complicationData = builder.build(); complicationData = builder.build();
} else { } else {
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
} }
return complicationData; return complicationData;
} }

View file

@ -8,14 +8,13 @@ import android.graphics.BitmapFactory;
import android.graphics.drawable.Icon; import android.graphics.drawable.Icon;
import android.support.wearable.complications.ComplicationData; import android.support.wearable.complications.ComplicationData;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager; 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.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.shared.logging.LTag;
/* /*
* Created by dlvoy on 2019-11-12 * Created by dlvoy on 2019-11-12
@ -24,8 +23,6 @@ public abstract class WallpaperComplication extends BaseComplicationProviderServ
public abstract String getWallpaperAssetsFileName(); public abstract String getWallpaperAssetsFileName();
private static final String TAG = WallpaperComplication.class.getSimpleName();
public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) { public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) {
ComplicationData complicationData = null; ComplicationData complicationData = null;
@ -42,19 +39,17 @@ public abstract class WallpaperComplication extends BaseComplicationProviderServ
final ComplicationData.Builder builder = new ComplicationData.Builder(ComplicationData.TYPE_LARGE_IMAGE); final ComplicationData.Builder builder = new ComplicationData.Builder(ComplicationData.TYPE_LARGE_IMAGE);
AssetManager assetManager = getAssets(); AssetManager assetManager = getAssets();
try (InputStream istr = assetManager.open(getWallpaperAssetsFileName())) { try (InputStream iStr = assetManager.open(getWallpaperAssetsFileName())) {
Bitmap bitmap = BitmapFactory.decodeStream(istr); Bitmap bitmap = BitmapFactory.decodeStream(iStr);
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, width, height, true); Bitmap scaled = Bitmap.createScaledBitmap(bitmap, width, height, true);
builder.setLargeImage(Icon.createWithBitmap(scaled)); builder.setLargeImage(Icon.createWithBitmap(scaled));
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Cannot read wallpaper asset: "+e.getMessage(), e); aapsLogger.error(LTag.WEAR, "Cannot read wallpaper asset: " + e.getMessage(), e);
} }
complicationData = builder.build(); complicationData = builder.build();
} else { } else {
if (Log.isLoggable(TAG, Log.WARN)) { aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
Log.w(TAG, "Unexpected complication type " + dataType);
}
} }
return complicationData; return complicationData;
} }

View file

@ -2,11 +2,7 @@ package info.nightscout.androidaps.di
import dagger.Module import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.complications.BaseComplicationProviderService import info.nightscout.androidaps.complications.*
import info.nightscout.androidaps.complications.BrCobIobComplication
import info.nightscout.androidaps.complications.LongStatusComplication
import info.nightscout.androidaps.complications.LongStatusFlippedComplication
import info.nightscout.androidaps.complications.SgvComplication
import info.nightscout.androidaps.data.ListenerService import info.nightscout.androidaps.data.ListenerService
import info.nightscout.androidaps.watchfaces.* import info.nightscout.androidaps.watchfaces.*
@ -15,11 +11,20 @@ import info.nightscout.androidaps.watchfaces.*
abstract class ServicesModule { abstract class ServicesModule {
@ContributesAndroidInjector abstract fun contributesListenerService(): ListenerService @ContributesAndroidInjector abstract fun contributesListenerService(): ListenerService
@ContributesAndroidInjector abstract fun contributesBaseComplicationProviderService(): BaseComplicationProviderService @ContributesAndroidInjector abstract fun contributesBaseComplicationProviderService(): BaseComplicationProviderService
@ContributesAndroidInjector abstract fun contributesBrCobIobComplication(): BrCobIobComplication @ContributesAndroidInjector abstract fun contributesBrCobIobComplication(): BrCobIobComplication
@ContributesAndroidInjector abstract fun contributesCobDetailedComplication(): CobDetailedComplication
@ContributesAndroidInjector abstract fun contributesCobIconComplication(): CobIconComplication
@ContributesAndroidInjector abstract fun contributesCobIobComplication(): CobIobComplication
@ContributesAndroidInjector abstract fun contributesIobDetailedComplication(): IobDetailedComplication
@ContributesAndroidInjector abstract fun contributesIobIconComplication(): IobIconComplication
@ContributesAndroidInjector abstract fun contributesLongStatusComplication(): LongStatusComplication @ContributesAndroidInjector abstract fun contributesLongStatusComplication(): LongStatusComplication
@ContributesAndroidInjector abstract fun contributesLongStatusFlippedComplication(): LongStatusFlippedComplication @ContributesAndroidInjector abstract fun contributesLongStatusFlippedComplication(): LongStatusFlippedComplication
@ContributesAndroidInjector abstract fun contributesSgvComplication(): SgvComplication @ContributesAndroidInjector abstract fun contributesSgvComplication(): SgvComplication
@ContributesAndroidInjector abstract fun contributesUploaderBattery(): UploaderBattery
@ContributesAndroidInjector abstract fun contributesWallpaperComplication(): WallpaperComplication
@ContributesAndroidInjector abstract fun contributesBaseWatchFace(): BaseWatchFace @ContributesAndroidInjector abstract fun contributesBaseWatchFace(): BaseWatchFace
@ContributesAndroidInjector abstract fun contributesHome(): Home @ContributesAndroidInjector abstract fun contributesHome(): Home
@ContributesAndroidInjector abstract fun contributesHome2(): Home2 @ContributesAndroidInjector abstract fun contributesHome2(): Home2