How can I draw icons on the watch face from an Android service provider?

An icon appears using the Complications API, but when it comes to drawing an icon, I'm not sure how to do it.

When I draw the actual face for the clock, there seems to be no drawIcon method. For instance. something like canvas.drawIcon (icon). I can only see how to draw a bitmap.

In my drawComplications method, I have the following:

} else if (complicationData.getType() == ComplicationData.TYPE_ICON) {
                Icon icon = complicationData.getIcon();

How can I then draw an icon on the canvas?

The code lab here does not tell us how to draw icons: https://codelabs.developers.google.com/codelabs/complications/index.html?index=..%2F..%2Findex#3

Instead, I could just copy all the drawings into a local wearable module and bypass the type of icon by passing a line, and from there just draw the corresponding bitmap. But there must be a way to extract from the icon otherwise, why is it?

I also could not learn from Googling how to convert the icon to a bitmap, but it also seems dumb, because I had to convert the bitmap to an icon, primarily because the API wants the icon.

Any help was appreciated.

Thank.

+4
source share
1 answer

Okay, so I don’t know how I missed this, but as simple as

Drawable drawable = icon.loadDrawable(getApplicationContext());

Then just do it, which you probably already knew:

if (drawable instanceof BitmapDrawable) {
    Bitmap bitmap;
    bitmap = ((BitmapDrawable) drawable).getBitmap();
    canvas.drawBitmap(bitmap, complicationsX, mTopComplicationY, null);
}

I looked here

https://developer.android.com/reference/android/graphics/drawable/Icon.html#loadDrawable(android.content.Context)

, .

: VectorDrawable, .

+5

Source: https://habr.com/ru/post/1666430/


All Articles