How set complication on watch face of ICON,RANGED_VALUE,SMALL_IMAGE on android wear

帅比萌擦擦* 提交于 2019-12-13 07:58:05

问题


I tried to draw icon on android watch face but did not see on watch face. I already check this link.Ref I set text on watchface for complication TYPE text but it does not set for other type like ICON,RANGED_VALUE,SMALL_IMAGE so please suggest.

I need this type icon where red mark complication. I used this code for draw text.

if (COMPLICATION_IDS[i] == RIGHT_DIAL_COMPLICATION) {
                        // RIGHT_DIAL_COMPLICATION calculations
                        int offset = (int) ((mWidth / 2) - textWidth) / 2;
                        complicationsX = (mWidth / 2) + offset;
                        canvas.drawText(
                                complicationMessage,
                                0,
                                complicationMessage.length(),
                                complicationsX,
                                mComplicationsY,
                                mComplicationPaint);
                        Log.e("log", "offset==" + offset + "==complicationsX==" + complicationsX);
                        Log.e("log", "mComplicationsY==" + mComplicationsY);

                    }

and use this code for image but not getting any thing.

if (COMPLICATION_IDS[i] == LEFT_DIAL_COMPLICATION) {
                        complicationsX = (int) ((mWidth / 2) - textWidth) / 2;

                        Icon icon = complicationData.getIcon();
                        Drawable drawable = icon.loadDrawable(getApplicationContext());
                        if (drawable instanceof BitmapDrawable) {
                            Bitmap bitmap;
                            bitmap = ((BitmapDrawable) drawable).getBitmap();
                            canvas.drawBitmap(bitmap, complicationsX, mComplicationsY, null);
                        }
                    } 

回答1:


No need to create a bitmap instance, just set the drawable bounds use it's draw method:

Icon icon = complicationData.getIcon();
if(icon != null) {
    Drawable drawable = icon.loadDrawable(getApplicationContext());
    if(drawable != null) {
        drawable.setBounds(20, 20, 50, 50); //left, top, right, bottom
        drawable.draw(canvas);
    }
}


来源:https://stackoverflow.com/questions/43538447/how-set-complication-on-watch-face-of-icon-ranged-value-small-image-on-android-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!