你如何使并发症适应?

时间:2017-06-12 14:28:58

标签: android wear-os android-wear-complication

I was following this tutorial了解如何使用ComplicationDrawable为表盘添加复杂功能。我无法弄清楚的是如何使ComplicationDrawable对内容做出响应?例如,如果底层并发症的数据类型为ComplicationData.TYPE_LONG_TEXT,如何让ComplicationDrawable更宽以调整文本?

Here is my code for how I'm drawing the bounds for the complications

我无法在任何地方找到这样的例子,所以也许这是不可能的。

1 个答案:

答案 0 :(得分:1)

您已经在代码中获得了所需的一切。唯一缺少的是根据复杂类型设置边界。我就是这样做的:

// Create a ComplicationDrawable object, and give it a Context.
ComplicationDrawable complicationDrawable = new ComplicationDrawable();
complicationDrawable.setContext(context);

// Set the ComplicationData from the onComplicationDataUpdate(int id, ComplicationData data) callback in your WatchFaceService.Engine class.
complicationDrawable.setComplicationData(data); 

// Set the bounds based on the current complication type.
Rect bounds = new Rect();
if (data.getType() == ComplicationData.TYPE_LONG_TEXT) {
    bounds.set(getLongTextBounds());
} else {
    bounds.set(getShortTextBounds());
}
complicationDrawable.setBounds(bounds);

// Set all other customization options, and draw the ComplicationDrawable to your canvas.