-1

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 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);
                        }
                    } 
TofferJ
  • 4,678
  • 1
  • 37
  • 49
Sachin Suthar
  • 692
  • 10
  • 28
  • How did you try to draw it? It's hard to see where you're going wrong from the question. Can you please include some more info/code? Where is it failing? Do you have the icon but can't draw it? Maybe you're not getting the icon at all? – Michael Vescovo Apr 21 '17 at 10:52
  • I add image so you can getting my point. – Sachin Suthar Apr 24 '17 at 05:11
  • What did you tried so far? Do you even have any code to show us? – Maveňツ Apr 24 '17 at 05:18
  • I get that you want to draw an icon, but I have no idea what you've tried so far. What part specifically is not working or do you want to know? If you can send an display text then you've probably looked at the documentation. If not maybe check there first. – Michael Vescovo Apr 24 '17 at 05:32
  • So you don't get any errors? The icon is not null for example? Does it enter the if statement proving it's actually a BitmapDrawable that you passed in? Maybe you passed something else? Maybe check that you are actually sending a bitmap at the other end. – Michael Vescovo Apr 25 '17 at 01:00
  • I used this to create the Bitmap at the other end: complicationData = new ComplicationData.Builder(ComplicationData.TYPE_ICON) .setIcon(Icon.createWithBitmap(mIcon)) .build(); – Michael Vescovo Apr 25 '17 at 01:01
  • @MichaelVescovo : What type of "complicationData" and where it set? – Sachin Suthar Apr 25 '17 at 04:22
  • This is going to take a long time if we just talk here. It's not good practice but I'm just going to post a link to my open source project and you can see for yourself. https://github.com/mvescovo/sunshine-watchface – Michael Vescovo Apr 25 '17 at 04:52
  • If you find the problem after comparing with my project then answer your own question with what you did to fix it so the post is still helpful to others. – Michael Vescovo Apr 25 '17 at 04:54
  • 1
    ok thnx for this link. – Sachin Suthar Apr 25 '17 at 04:57
  • @MichaelVescovo : Its fine for weather but when you want to add contact on complication then how set its icon ? i don't know how to add. – Sachin Suthar Apr 25 '17 at 05:55
  • you mean like the icon of the contact? I haven't done it but you will still need to pass the icon through the same way as with the weather icons. it doesn't really matter where you get the icon from. but I think if that's your issue then maybe that's for a different post (about how to get the icon for a contact - nothing to do with android wear). then when you have it maybe it will work. – Michael Vescovo Apr 25 '17 at 05:59
  • @MichaelVescovo : I don't think that proper solution to pass fix image for contact and then if getting another complication then also we have to pass fix image .so it long process i think. – Sachin Suthar Apr 25 '17 at 06:20
  • there might be another solution, but what I'm suggesting is at least one solution if you have no better ideas. – Michael Vescovo Apr 25 '17 at 06:24
  • also, in android wear 2.0 things are bit different. you can get data without going through the phone. there may be an api to get at the contacts data including icons. however when it comes to displaying it, you know how to do it once you have the icon. – Michael Vescovo Apr 25 '17 at 06:26
  • ok i will see this. – Sachin Suthar Apr 25 '17 at 06:44

1 Answers1

0

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);
    }
}
seahorsepip
  • 4,519
  • 1
  • 19
  • 30