HarmonyOS原子化服务卡片开发image and information模板体验 原创

鸿蒙时代
发布于 2021-7-14 10:32
1.2w浏览
1收藏

一、项目总述
1.技术相关
项目名称: image_information
项目语言: JAVA
体验模板:image and information
工具:deveco studio
2. 体验素材
天气信息与图片展示
3. 效果如下
图片
HarmonyOS原子化服务卡片开发image and information模板体验-鸿蒙开发者社区
二、开发步骤
新建一个java的应用项目
然后构建完成项目后在jltf_template下new->module
HarmonyOS原子化服务卡片开发image and information模板体验-鸿蒙开发者社区

HarmonyOS原子化服务卡片开发image and information模板体验-鸿蒙开发者社区
选择空的java模板
HarmonyOS原子化服务卡片开发image and information模板体验-鸿蒙开发者社区
选择项目的empty,新建Service Widget
HarmonyOS原子化服务卡片开发image and information模板体验-鸿蒙开发者社区
选择image and information模板,点击下一步
HarmonyOS原子化服务卡片开发image and information模板体验-鸿蒙开发者社区
选择卡片类型,点击finish
HarmonyOS原子化服务卡片开发image and information模板体验-鸿蒙开发者社区
登录你的账号然后启动模拟器即可实现效果
三、项目结构介绍
HarmonyOS原子化服务卡片开发image and information模板体验-鸿蒙开发者社区
四 关键代码(MainAbility)与体验图片信息实现
public class MainAbility extends Ability {

public static final int DEFAULT_DIMENSION_2X2 = 2;
public static final int DIMENSION_1X2 = 1;
public static final int DIMENSION_2X4 = 3;
public static final int DIMENSION_4X4 = 4;
private static final int INVALID_FORM_ID = -1;
private static final HiLogLabel TAG = new HiLogLabel(HiLog.debug, 0x0, MainAbility.class.getName());
private String topWidgetSlice;

@Override
public void onStart(Intent intent) {
    super.onStart(intent);
    super.setMainRoute(MainAbilitySlice.class.getName());
    if (intentFromWidget(intent)) {
        topWidgetSlice = getRoutePageSlice(intent);
        if (topWidgetSlice != null) {
            setMainRoute(topWidgetSlice);
        }
    }
    stopAbility(intent);
}

@Override
protected ProvideRFormInfo onCreateForm(Intent intent) {
    HiLog.info(TAG, "onCreateForm");
    long formId = intent.getLongParam(AbilitySlice.PARAM_FORM_IDENTITY_KEY, INVALID_FORM_ID);
    String formName = intent.getStringParam(AbilitySlice.PARAM_FORM_NAME_KEY);
    int dimension = intent.getIntParam(AbilitySlice.PARAM_FORM_DIMENSION_KEY, DEFAULT_DIMENSION_2X2);
    HiLog.info(TAG, "onCreateForm: formId=" + formId + ",formName=" + formName);
    FormControllerManager formControllerManager = FormControllerManager.getInstance(this);
    FormController formController = formControllerManager.getController(formId);
    formController = (formController == null) ? formControllerManager.createFormController(formId,
            formName, dimension) : formController;
    if (formController == null) {
        HiLog.error(TAG, "Get null controller. formId: " + formId + ", formName: " + formName);
        return null;
    }
    return formController.bindFormData();
}

@Override
protected void onUpdateForm(long formId) {
    HiLog.info(TAG, "onUpdateForm");
    super.onUpdateForm(formId);
    FormControllerManager formControllerManager = FormControllerManager.getInstance(this);
    FormController formController = formControllerManager.getController(formId);
    formController.updateFormData(formId);
}

@Override
protected void onDeleteForm(long formId) {
    HiLog.info(TAG, "onDeleteForm: formId=" + formId);
    super.onDeleteForm(formId);
    FormControllerManager formControllerManager = FormControllerManager.getInstance(this);
    formControllerManager.deleteFormController(formId);
}

@Override
protected void ontriggerFormEvent(long formId, String message) {
    HiLog.info(TAG, "onTriggerFormEvent: " + message);
    super.onTriggerFormEvent(formId, message);
    FormControllerManager formControllerManager = FormControllerManager.getInstance(this);
    FormController formController = formControllerManager.getController(formId);
    formController.onTriggerFormEvent(formId, message);
}

@Override
public void onNewIntent(Intent intent) {
    if (intentFromWidget(intent)) { // Only response to it when starting from a service widget.
        String newWidgetSlice = getRoutePageSlice(intent);
        if (topWidgetSlice == null || !topWidgetSlice.equals(newWidgetSlice)) {
            topWidgetSlice = newWidgetSlice;
            restart();
        }
    }
}

private boolean intentFromWidget(Intent intent) {
    long formId = intent.getLongParam(AbilitySlice.PARAM_FORM_IDENTITY_KEY, INVALID_FORM_ID);
    return formId != INVALID_FORM_ID;
}

private String getRoutePageSlice(Intent intent) {
    long formId = intent.getLongParam(AbilitySlice.PARAM_FORM_IDENTITY_KEY, INVALID_FORM_ID);
    if (formId == INVALID_FORM_ID) {
        return null;
    }
    FormControllerManager formControllerManager = FormControllerManager.getInstance(this);
    FormController formController = formControllerManager.getController(formId);
    if (formController == null) {
        return null;
    }
    Class<? extends AbilitySlice> clazz = formController.getRoutePageSlice(intent);
    if (clazz == null) {
        return null;
    }
    return clazz.getName();
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.

}
五、完整代码地址:
https://gitee.com/jltfcloudcn/jump_to/tree/master/image_information

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
标签
蛟龙腾飞 海龙 imag and information 卡片 .docx 727.54K 9次下载
已于2021-7-14 11:03:26修改
2
收藏 1
回复
举报
2
1


回复
    相关推荐