LongStatusComplication -> kt
This commit is contained in:
parent
205775e9c7
commit
a427c290f4
2 changed files with 43 additions and 61 deletions
|
@ -1,61 +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 LongStatusComplication 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_LONG_TEXT:
|
|
||||||
|
|
||||||
final String glucoseLine = displayFormat.longGlucoseLine(raw);
|
|
||||||
final String detailsLine = displayFormat.longDetailsLine(raw);
|
|
||||||
|
|
||||||
final ComplicationData.Builder builderLong = new ComplicationData.Builder(ComplicationData.TYPE_LONG_TEXT)
|
|
||||||
.setLongTitle(ComplicationText.plainText(glucoseLine))
|
|
||||||
.setLongText(ComplicationText.plainText(detailsLine))
|
|
||||||
.setTapAction(complicationPendingIntent);
|
|
||||||
complicationData = builderLong.build();
|
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
|
|
||||||
}
|
|
||||||
return complicationData;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getProviderCanonicalName() {
|
|
||||||
return LongStatusComplication.class.getCanonicalName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean usesSinceField() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
@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 LongStatusComplication : 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_LONG_TEXT -> {
|
||||||
|
val glucoseLine = displayFormat.longGlucoseLine(raw)
|
||||||
|
val detailsLine = displayFormat.longDetailsLine(raw)
|
||||||
|
val builderLong = ComplicationData.Builder(ComplicationData.TYPE_LONG_TEXT)
|
||||||
|
.setLongTitle(ComplicationText.plainText(glucoseLine))
|
||||||
|
.setLongText(ComplicationText.plainText(detailsLine))
|
||||||
|
.setTapAction(complicationPendingIntent)
|
||||||
|
complicationData = builderLong.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> aapsLogger.warn(LTag.WEAR, "Unexpected complication type $dataType")
|
||||||
|
}
|
||||||
|
return complicationData
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getProviderCanonicalName(): String = LongStatusComplication::class.java.canonicalName!!
|
||||||
|
override fun usesSinceField(): Boolean = true
|
||||||
|
}
|
Loading…
Reference in a new issue