SgvComplication -> kt
This commit is contained in:
parent
8ce4a7d716
commit
f350fa1ed5
3 changed files with 45 additions and 60 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
Loading…
Reference in a new issue