SDK 包含一些示例 - 查看名为 BandTileEvent 的示例以了解完整的实现。快速版本是您的图块创建代码应在创建时创建一系列布局(包含具有 ID 的元素)和图标,然后更新您将选择布局并为元素的 ID 分配值。示例中的关键元素如下所示(为便于阅读而进行了修改):
private PageLayout createButtonLayout() {
return new PageLayout(
new FlowPanel(15, 0, 260, 105, FlowPanelOrientation.VERTICAL)
.addElements(new FilledButton(0, 5, 210, 45).setMargins(0, 5, 0 ,0).setId(12).setBackgroundColor(Color.RED))
.addElements(new TextButton(0, 0, 210, 45).setMargins(0, 5, 0 ,0).setId(21).setPressedColor(Color.BLUE))
);
}
这将创建一个用于平铺创建过程的 PageLayout 对象。这个方法应该这样使用:
BandTile tile = new BandTile.Builder(YOUR_TILE_UUID, "Tile Title", tileIconBitmap)
.setPageLayouts(createButtonLayout())
.setPageIcons(getIconsToUse())
.build();
client.getTileManager().addTile(context, tile);
一旦磁贴在乐队上,您需要发送更新 - 它应该看起来像这样:
private void updatePages() throws BandIOException {
client.getTileManager().setPages(tileId,
new PageData(pageId1, 0)
.update(new FilledButtonData(12, Color.YELLOW))
.update(new TextButtonData(21, "Text Button")));
}
一旦磁贴在您的频段上,您就可以注册一个返回这些事件的意图过滤器。检查 SDK 示例以了解所使用的确切意图 - 当磁贴打开、关闭以及按下其上的按钮时,您会收到通知。