android-wear-2.0android-wear-complication

How can I draw a complication slot on my watch face?


I'm developing my own Android watch face and everything works well until now. Now, I trying to create my first complication in order to show the seconds. I know that I need to create my own Data Provider for this complication. I already have seen some videos on YouTube and read some documentation. My questions are:


Solution

  • How can I create a complication slot to be displayed on my what face?

    The easiest way is to use a ComplicaitonDrawable. It will handle all the logic of what to display (tilte, text, icon, etc) for you. It can also be styled to blend in with your watch face. Make sure to populate it with complication data whenever your watch face receives a callback:

    @Override
    public void onComplicationDataUpdate(int id, ComplicationData data) {
        mComplicationDrawable.setComplicationData(data);
    }
    

    How can I set its position on the watch face?

    The ComplicationDrawable can easily be drawn anywhere on a canvas:

    mComplicationDrawable.setBounds(myComplicationBounds);
    mComplicationDrawable.draw(canvas, currentTimeMillis);
    

    Will I have to create an activity for that?

    You don't need an activity to set the position of the complication slot (unless you want the user to be able to select/change the position).

    You do need a settings activity to let the user select a data provider for your complication slot. Google has been kind enough to provide a sample watch face that shows the recommended way to do this. It's available on GitHub.