mirror of
https://github.com/home-assistant/android
synced 2024-09-06 17:23:32 +00:00
Add a watchface complication for Assist (#3284)
This commit is contained in:
parent
d18ff2cf4e
commit
152d11147a
|
@ -162,6 +162,24 @@
|
|||
android:name="android.support.wearable.complications.PROVIDER_CONFIG_ACTION"
|
||||
android:value="io.homeassistant.companion.android.ENTITY_STATE_COMPLICATION_CONFIG" />
|
||||
</service>
|
||||
|
||||
<service android:name=".complications.AssistDataSourceService"
|
||||
android:exported="true"
|
||||
android:icon="@mipmap/ic_assist_launcher"
|
||||
android:label="@string/assist"
|
||||
android:permission="com.google.android.wearable.permission.BIND_COMPLICATION_PROVIDER">
|
||||
<intent-filter>
|
||||
<action android:name="android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.support.wearable.complications.SUPPORTED_TYPES"
|
||||
android:value="ICON" />
|
||||
<meta-data
|
||||
android:name="android.support.wearable.complications.UPDATE_PERIOD_SECONDS"
|
||||
android:value="0" />
|
||||
</service>
|
||||
|
||||
<receiver android:name=".complications.ComplicationReceiver" />
|
||||
|
||||
<service android:name=".phone.PhoneSettingsListener" android:exported="true">
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package io.homeassistant.companion.android.complications
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Icon
|
||||
import androidx.wear.watchface.complications.data.ComplicationData
|
||||
import androidx.wear.watchface.complications.data.ComplicationType
|
||||
import androidx.wear.watchface.complications.data.MonochromaticImage
|
||||
import androidx.wear.watchface.complications.data.MonochromaticImageComplicationData
|
||||
import androidx.wear.watchface.complications.data.PlainComplicationText
|
||||
import androidx.wear.watchface.complications.datasource.ComplicationDataSourceService
|
||||
import androidx.wear.watchface.complications.datasource.ComplicationRequest
|
||||
import com.mikepenz.iconics.IconicsDrawable
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||
import com.mikepenz.iconics.utils.colorInt
|
||||
import io.homeassistant.companion.android.common.R
|
||||
|
||||
class AssistDataSourceService : ComplicationDataSourceService() {
|
||||
|
||||
companion object {
|
||||
const val TAG = "AssistDataSourceService"
|
||||
}
|
||||
|
||||
override fun onComplicationRequest(request: ComplicationRequest, listener: ComplicationRequestListener) {
|
||||
if (request.complicationType != ComplicationType.MONOCHROMATIC_IMAGE)
|
||||
return
|
||||
|
||||
listener.onComplicationData(
|
||||
MonochromaticImageComplicationData.Builder(
|
||||
monochromaticImage = MonochromaticImage.Builder(Icon.createWithBitmap(getAssistIcon())).build(),
|
||||
contentDescription = PlainComplicationText.Builder(getText(R.string.assist))
|
||||
.build()
|
||||
)
|
||||
.setTapAction(ComplicationReceiver.getAssistIntent(this))
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
private fun getAssistIcon(): Bitmap {
|
||||
val icon = CommunityMaterial.Icon.cmd_comment_processing_outline
|
||||
return IconicsDrawable(this, icon).apply {
|
||||
colorInt = Color.WHITE
|
||||
}.toBitmap()
|
||||
}
|
||||
|
||||
override fun getPreviewData(type: ComplicationType): ComplicationData =
|
||||
MonochromaticImageComplicationData.Builder(
|
||||
monochromaticImage = MonochromaticImage.Builder(Icon.createWithBitmap(getAssistIcon())).build(),
|
||||
contentDescription = PlainComplicationText.Builder(getText(R.string.assist)).build()
|
||||
)
|
||||
.build()
|
||||
}
|
|
@ -8,6 +8,7 @@ import android.content.Intent
|
|||
import androidx.wear.watchface.complications.datasource.ComplicationDataSourceUpdateRequester
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.homeassistant.companion.android.common.data.integration.IntegrationRepository
|
||||
import io.homeassistant.companion.android.conversation.ConversationActivity
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
|
@ -92,5 +93,14 @@ class ComplicationReceiver : BroadcastReceiver() {
|
|||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
}
|
||||
|
||||
fun getAssistIntent(context: Context): PendingIntent {
|
||||
return PendingIntent.getActivity(
|
||||
context,
|
||||
0,
|
||||
Intent(context, ConversationActivity::class.java),
|
||||
PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue