SiFliGUIBuilderSDK For android¶
1. 概述¶
SiFliGUIBuilderSDK 是思澈表盘工具SiFliGUIBuilder的移动端配套组件,客户App可以基于它对SiFliGUIBuilder编辑产生的表盘包.sif 文件进行编辑。目前它可以对表盘中设定为允许编辑的图片控件进行编辑,实现在手机App上更换表盘背景。 使用请参照
2. 集成¶
2.1 Gradle拉取配置¶
allprojects {
repositories {
maven {
url 'https://maven.aliyun.com/repository/public'
}
maven {
credentials {
username '65a890ad4f41789f56425965'
password 'Y-kxYEyTl5)['
}
url 'https://packages.aliyun.com/maven/repository/2457536-release-P0YgD8/'
}
}
}
2.2 sdk集成¶
implementation 'com.sifli:siflicore:1.2.12'
implementation 'com.sifli:sifliezipsdk:2.4.3'
implementation 'com.sifli:sifliguibuildersdk:1.0.2'
implementation 'com.google.code.gson:gson:2.10.1'
2.3 接口初始化¶
表盘编辑过程中涉及到的SDK类的初始化
//读取和解析表盘
private SGWorkSpaceManager workSpaceManager;
//拓展资源补丁制作
private SGResourceZIPMaker resourceZIPMaker;
//设备消息发送。切换页面,删除拓展资源补丁
private SGPushMessageManager pushMessageManager;
//拓展资源补丁传输
private SFOtaV3Manager otaV3Manager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_otav3);
...
this.workSpaceManager = new SGWorkSpaceManager();
this.workSpaceManager.init(this.getApplication());
this.resourceZIPMaker = SGResourceZIPMaker.getInstance();
this.resourceZIPMaker.setCallback(this);
this.pushMessageManager = SGPushMessageManager.getInstance();
this.pushMessageManager.init(this.getApplication());
this.pushMessageManager.setCallback(this);
this.otaV3Manager = SFOtaV3Manager.getInstance();
this.otaV3Manager.setCallback(this);
this.otaV3Manager.init(this.getApplication(), SFTransmissionMode.TRANSMISSION_MODE_BLE);
}
3. 接口调用¶
3.1 打开表盘¶
通过SGWorkSpaceManager来打开.sif表盘包,绘制预览图、查询可编辑项目、制作图像补丁、删除图像补丁、切换页面(样式)、切换语言。
它的接口定义如下
/**
* 打开工程(.sif)
* @param projectPath 表盘/应用文件路径
* */
public void openProject(String projectPath) throws SFException
/**
* 绘制当前页面预览效果图
* */
public Bitmap drawPreviewImage()
/**
* 切换样式/页面
* */
public void switchTheme(String themeId)
/**
* 获取当前页面可修改项目
* */
public List<SGWatchfaceEditItem> getEditItems() throws SFException
/**
* 制作图像补丁,将Bitmap对象保存到临时目录
*/
public void makeImagePatch(SGImageEditItem imageEditItem) throws SFException
/**
* 删除已经制作的本地资源补丁
* @param originImageName 原始图片资源名称 @see SGWatchfaceEditItem
* */
public boolean deletePatch(String originImageName)
SGWatchfaceEditItem
SGWatchfaceEditItem 是通过 getEditItems 查询获得的可修改项目,它包含如下属性
/*修改的控件id*/
private String controlId;
/**资源uid*/
private String hexUID;
/**控件uid*/
private String controlUID;
SGImageEditItem 是SGWatchfaceEditItem的子类,它包含如下属性
/**原始图像名称*/
private String originImageName;
/**原始图像 */
private Bitmap originImage;
/**是否是表盘背景*/
private boolean isBackground;
3.2 生成拓展资源补丁¶
拓展资源补丁是将用户对原始资源(比如图片)的修改,通过eZIPSDK针对特定的芯片进行二进制编码,然后再按GUIBuilder 拓展资源协议编码为固件可以识别的二进制文件。拓展资源补丁文件可以通过OTA V3 SDK传输到设备上显示。
/**
* 将表盘修改清单制作为拓展资源补丁zip
* @param context 制作上下文
* @param editItem 已经编辑,并需要打包发送的资源编辑项目
* */
public synchronized void startMakePathZip(SGAppResContext context,SGImageEditItem editItem)
调用SGResourceZIPMaker的startMakePatchZipWithContext需要构建SGAppResUserContext对象,它需要输入appId,watchPathTemp,SGWorkSpaceManager,ezip参数来构建。
appId 表盘工程中设定的ID
watchPathTemp 一个文件路径模版,它指定了拓展资源文件zip的内部层级,这决定了它被传输到设备后的存放位置
ezip参数 参照
eZIPSDK
3.3 消息发送¶
通过SGPushMessageManager来发送切换页面、删除拓展资源补丁、删除表盘命令。
/**
* 发送选择表盘样式命令
* */
public void sendSwitchThemeCmd(String mac,String appId, String themeId)
/**
* 发送删除资源补丁文件命令
* */
public void sendDeleteResPatchCmd(String mac,String appId, String patchFileName)
/**
* 发送删除表盘/app命令
* */
public void sendDeleteAppCmd(String mac,String appId)