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 0db70ad7e1..c7648bed92 100644 --- a/wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.java +++ b/wear/src/main/java/info/nightscout/androidaps/complications/BaseComplicationProviderService.java @@ -13,6 +13,8 @@ import android.support.wearable.complications.ComplicationProviderService; import android.support.wearable.complications.ComplicationText; import android.support.wearable.complications.ProviderUpdateRequester; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import java.util.HashSet; @@ -67,9 +69,9 @@ public abstract class BaseComplicationProviderService extends ComplicationProvid // ABSTRACT COMPLICATION INTERFACE //============================================================================================== - public abstract ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent); + public abstract @Nullable ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent); - public abstract String getProviderCanonicalName(); + public abstract @NonNull String getProviderCanonicalName(); public ComplicationAction getComplicationAction() { return ComplicationAction.MENU; diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/SgvComplication.java b/wear/src/main/java/info/nightscout/androidaps/complications/SgvComplication.java deleted file mode 100644 index 8934a8df2d..0000000000 --- a/wear/src/main/java/info/nightscout/androidaps/complications/SgvComplication.java +++ /dev/null @@ -1,58 +0,0 @@ -package info.nightscout.androidaps.complications; - -import android.app.PendingIntent; -import android.support.wearable.complications.ComplicationData; -import android.support.wearable.complications.ComplicationText; - -import javax.inject.Inject; - -import dagger.android.AndroidInjection; -import info.nightscout.androidaps.data.RawDisplayData; -import info.nightscout.androidaps.interaction.utils.DisplayFormat; -import info.nightscout.shared.logging.LTag; - -/* - * Created by dlvoy on 2019-11-12 - */ -@SuppressWarnings("deprecation") -public class SgvComplication extends BaseComplicationProviderService { - - @Inject DisplayFormat displayFormat; - - // Not derived from DaggerService, do injection here - @Override - public void onCreate() { - AndroidInjection.inject(this); - super.onCreate(); - } - - public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) { - - ComplicationData complicationData = null; - - switch (dataType) { - case ComplicationData.TYPE_SHORT_TEXT: - final ComplicationData.Builder builder = new ComplicationData.Builder(ComplicationData.TYPE_SHORT_TEXT) - .setShortText(ComplicationText.plainText(raw.getSingleBg().getSgvString() + raw.getSingleBg().getSlopeArrow() + - "\uFE0E")) - .setShortTitle(ComplicationText.plainText(displayFormat.shortTrend(raw))) - .setTapAction(complicationPendingIntent); - - complicationData = builder.build(); - break; - default: - aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType); - } - return complicationData; - } - - @Override - public String getProviderCanonicalName() { - return SgvComplication.class.getCanonicalName(); - } - - @Override - protected boolean usesSinceField() { - return true; - } -} diff --git a/wear/src/main/java/info/nightscout/androidaps/complications/SgvComplication.kt b/wear/src/main/java/info/nightscout/androidaps/complications/SgvComplication.kt new file mode 100644 index 0000000000..b692eeb17d --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/complications/SgvComplication.kt @@ -0,0 +1,41 @@ +@file:Suppress("DEPRECATION") + +package info.nightscout.androidaps.complications + +import android.app.PendingIntent +import android.support.wearable.complications.ComplicationData +import android.support.wearable.complications.ComplicationText +import dagger.android.AndroidInjection +import info.nightscout.androidaps.data.RawDisplayData +import info.nightscout.shared.logging.LTag + +/* + * Created by dlvoy on 2019-11-12 + */ +class SgvComplication : BaseComplicationProviderService() { + + // Not derived from DaggerService, do injection here + override fun onCreate() { + AndroidInjection.inject(this) + super.onCreate() + } + + override fun buildComplicationData(dataType: Int, raw: RawDisplayData, complicationPendingIntent: PendingIntent): ComplicationData? { + var complicationData: ComplicationData? = null + when (dataType) { + ComplicationData.TYPE_SHORT_TEXT -> { + val builder = ComplicationData.Builder(ComplicationData.TYPE_SHORT_TEXT) + .setShortText(ComplicationText.plainText(raw.singleBg.sgvString + raw.singleBg.slopeArrow + "\uFE0E")) + .setShortTitle(ComplicationText.plainText(displayFormat.shortTrend(raw))) + .setTapAction(complicationPendingIntent) + complicationData = builder.build() + } + + else -> aapsLogger.warn(LTag.WEAR, "Unexpected complication type $dataType") + } + return complicationData + } + + override fun getProviderCanonicalName(): String = SgvComplication::class.java.canonicalName!! + override fun usesSinceField(): Boolean = true +} \ No newline at end of file