diff --git a/UI/JsFACard/entry/build.gradle b/UI/JsFACard/entry/build.gradle index 83f59debbd68242b503a22270f4378d7843ca204..7321aa676e8d1768815335fe0813207cbda5f160 100644 --- a/UI/JsFACard/entry/build.gradle +++ b/UI/JsFACard/entry/build.gradle @@ -12,6 +12,7 @@ ohos { } } } + compileOptions { annotationEnabled true } } dependencies { diff --git a/UI/JsFACard/entry/src/main/config.json b/UI/JsFACard/entry/src/main/config.json index f6163e9afae65a1c22c1191cdad206fb8aa3a0de..0c7d85a3fdad8fae247593e0cee967f73d7846a0 100644 --- a/UI/JsFACard/entry/src/main/config.json +++ b/UI/JsFACard/entry/src/main/config.json @@ -6,11 +6,15 @@ "name": "1.0.0" } }, - "deviceConfig": {}, + "deviceConfig": { + "default": { + "keepAlive": true + } + }, "module": { "package": "ohos.samples.jsfacard", - "name": ".MainAbility", - "mainAbility": "ohos.samples.jsfacard.MainAbility", + "name": ".MyApplication", + "mainAbility": "ohos.samples.jsfacard.ClockAbility", "deviceType": [ "phone" ], @@ -20,6 +24,18 @@ "moduleType": "entry", "installationFree": false }, + "reqPermissions": [ + { + "name": "ohos.permission.KEEP_BACKGROUND_RUNNING", + "reason": "keep service ability backgroud running", + "usedScene": { + "ability": [ + "ohos.samples.jsfacard.TimerAbility" + ], + "when": "always" + } + } + ], "abilities": [ { "skills": [ @@ -32,36 +48,46 @@ ] } ], - "name": ".MainAbility", + "name": ".ClockAbility", "icon": "$media:icon", - "description": "$string:mainability_description", + "description": "$string:clockability_description", "formsEnabled": true, - "label": "$string:entry_MainAbility", + "label": "$string:app_name", "type": "page", + "launchType": "singleton", "forms": [ { - "jsComponentName": "jsmusictemplate", + "jsComponentName": "clock1x2", "isDefault": true, - "formConfigAbility": "ability://ohos.samples.jsfacard.MainAbility", "scheduledUpdateTime": "10:30", - "defaultDimension": "2*4", - "name": "jsmusictemplate", + "defaultDimension": "1*2", + "name": "clock1x2", "description": "This is a service widget", "colorMode": "auto", "type": "JS", "supportDimensions": [ - "2*4" + "1*2" ], "updateEnabled": true, "updateDuration": 1 - }, + } + ] + }, + { + "name": "ohos.samples.jsfacard.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "formsEnabled": true, + "launchType": "standard", + "forms": [ { - "jsComponentName": "card", + "jsComponentName": "jsmusictemplate", "isDefault": false, - "formConfigAbility": "ability://ohos.samples.jsfacard.MainAbility", "scheduledUpdateTime": "10:30", "defaultDimension": "2*4", - "name": "card", + "name": "jsmusictemplate", "description": "This is a service widget", "colorMode": "auto", "type": "JS", @@ -74,7 +100,6 @@ { "jsComponentName": "jscardtemplate", "isDefault": false, - "formConfigAbility": "ability://ohos.samples.jsfacard.MainAbility", "scheduledUpdateTime": "10:30", "defaultDimension": "4*4", "name": "jscardtemplate", @@ -86,9 +111,34 @@ ], "updateEnabled": true, "updateDuration": 1 + }, + { + "jsComponentName": "card", + "isDefault": true, + "scheduledUpdateTime": "10:30", + "defaultDimension": "2*4", + "name": "card", + "description": "This is a service widget", + "colorMode": "auto", + "type": "JS", + "supportDimensions": [ + "2*4" + ], + "updateEnabled": true, + "updateDuration": 1 } - ], - "launchType": "standard" + ] + }, + { + "name": "ohos.samples.jsfacard.TimerAbility", + "icon": "$media:icon", + "description": "$string:timerability_description", + "type": "service", + "visible": true, + "backgroundModes": [ + "dataTransfer", + "location" + ] } ], "js": [ @@ -134,6 +184,17 @@ "autoDesignWidth": true }, "type": "form" + }, + { + "pages": [ + "pages/index/index" + ], + "name": "clock1x2", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "type": "form" } ] } diff --git a/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/ClockAbility.java b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/ClockAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..105bc8e5bd96debb13f2663c4cee86568b7331e7 --- /dev/null +++ b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/ClockAbility.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.jsfacard; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.ability.FormBindingData; +import ohos.aafwk.ability.ProviderFormInfo; +import ohos.aafwk.content.Intent; +import ohos.aafwk.content.Operation; +import ohos.data.DatabaseHelper; +import ohos.data.orm.OrmContext; +import ohos.samples.jsfacard.database.Form; +import ohos.samples.jsfacard.database.FormDatabase; +import ohos.samples.jsfacard.slice.ClockAbilitySlice; +import ohos.samples.jsfacard.utils.DatabaseUtils; +import ohos.samples.jsfacard.utils.DateUtils; +import ohos.samples.jsfacard.utils.LogUtils; +import ohos.utils.zson.ZSONObject; + +/** + * ClockAbility + * + * @since 2021-08-20 + */ +public class ClockAbility extends Ability { + private static final String TAG = ClockAbility.class.getName(); + + private static final int INVALID_FORM_ID = -1; + + private static final String EMPTY_STRING = ""; + + private static final int DEFAULT_DIMENSION_1x2 = 1; + + private OrmContext connect; + + private DatabaseHelper helper = new DatabaseHelper(this); + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + startTimerAbility(); + connect = helper.getOrmContext("FormDatabase", "FormDatabase.db", FormDatabase.class); + super.setMainRoute(ClockAbilitySlice.class.getName()); + } + + private void startTimerAbility(){ + Intent intentService = new Intent(); + Operation operation = new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName(getBundleName()) + .withAbilityName(TimerAbility.class.getName()) + .build(); + intentService.setOperation(operation); + startAbility(intentService); + } + + @Override + protected ProviderFormInfo onCreateForm(Intent intent) { + startTimerAbility(); + ProviderFormInfo providerFormInfo = new ProviderFormInfo(); + LogUtils.info(TAG, "onCreateForm()"); + if (intent == null) { + return providerFormInfo; + } + + long formId = INVALID_FORM_ID; + if (intent.hasParameter(AbilitySlice.PARAM_FORM_IDENTITY_KEY)) { + formId = intent.getLongParam(AbilitySlice.PARAM_FORM_IDENTITY_KEY, INVALID_FORM_ID); + } else { + return providerFormInfo; + } + + String formName = EMPTY_STRING; + if (intent.hasParameter(AbilitySlice.PARAM_FORM_NAME_KEY)) { + formName = intent.getStringParam(AbilitySlice.PARAM_FORM_NAME_KEY); + } + + int dimension = DEFAULT_DIMENSION_1x2; + if (intent.hasParameter(AbilitySlice.PARAM_FORM_DIMENSION_KEY)) { + dimension = intent.getIntParam(AbilitySlice.PARAM_FORM_DIMENSION_KEY, DEFAULT_DIMENSION_1x2); + } + + if (connect == null) { + connect = helper.getOrmContext("FormDatabase", "FormDatabase.db", FormDatabase.class); + } + Form form = new Form(formId, formName, dimension); + DatabaseUtils.insertForm(form, connect); + + ZSONObject zsonObject = DateUtils.getZsonObject(); + LogUtils.info(TAG, "onCreateForm()" + zsonObject); + providerFormInfo.setJsBindingData(new FormBindingData(zsonObject)); + return providerFormInfo; + } + + @Override + protected void onDeleteForm(long formId) { + LogUtils.info(TAG, "onDeleteForm():formId=" + formId); + super.onDeleteForm(formId); + DatabaseUtils.deleteFormData(formId, connect); + } +} diff --git a/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/MainAbility.java b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/MainAbility.java index a8e10f50492567523db1dc80a1b6c31a4061ad22..a958415834ebe1713182a90cdcf6a6a52e16165d 100644 --- a/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/MainAbility.java +++ b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/MainAbility.java @@ -20,17 +20,16 @@ import ohos.aafwk.ability.FormException; import ohos.aafwk.ability.ProviderFormInfo; import ohos.aafwk.content.Intent; import ohos.ace.ability.AceAbility; -import ohos.hiviewdfx.HiLog; -import ohos.hiviewdfx.HiLogLabel; +import ohos.samples.jsfacard.utils.LogUtils; import ohos.utils.zson.ZSONObject; /** * Main ability * - * @since 2021-07-05 + * @since 2021-08-20 */ public class MainAbility extends AceAbility { - private static final HiLogLabel TAG = new HiLogLabel(HiLog.DEBUG, 0x0, MainAbility.class.getName()); + private static final String TAG = MainAbility.class.getName(); private static final String STATUS = "status"; @@ -42,30 +41,31 @@ public class MainAbility extends AceAbility { @Override public void onStart(Intent intent) { - HiLog.info(TAG, "onStart"); + LogUtils.info(TAG, "onStart"); super.onStart(intent); } @Override protected ProviderFormInfo onCreateForm(Intent intent) { - HiLog.info(TAG, "onCreateForm"); + LogUtils.info(TAG, "onCreateForm"); return super.onCreateForm(intent); } @Override protected void onUpdateForm(long formId) { - HiLog.info(TAG, "onUpdateForm"); + LogUtils.info(TAG, "onUpdateForm"); super.onUpdateForm(formId); } @Override protected void onDeleteForm(long formId) { - HiLog.info(TAG, "onDeleteForm: formId=" + formId); + LogUtils.info(TAG, "onDeleteForm: formId=" + formId); super.onDeleteForm(formId); } @Override protected void onTriggerFormEvent(long formId, String message) { + LogUtils.info(TAG, "onTriggerFormEvent: formId=" + formId); super.onTriggerFormEvent(formId, message); ZSONObject zsonObject = new ZSONObject(); if (isStatus) { @@ -79,7 +79,7 @@ public class MainAbility extends AceAbility { try { updateForm(formId, formBindingData); } catch (FormException e) { - HiLog.info(TAG, "onTriggerFormEvent:" + e.getMessage()); + LogUtils.info(TAG, "onTriggerFormEvent:" + e.getMessage()); } } -} +} \ No newline at end of file diff --git a/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/MyApplication.java b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/MyApplication.java index 1fe528672f947fce0311e030dda7099e7f8c3ff2..0f5104439f69ae48a093735a838e5c0a3dca725b 100644 --- a/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/MyApplication.java +++ b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/MyApplication.java @@ -20,7 +20,7 @@ import ohos.aafwk.ability.AbilityPackage; /** * MyApplication * - * @since 2021-07-05 + * @since 2021-08-20 */ public class MyApplication extends AbilityPackage { @Override diff --git a/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/TimerAbility.java b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/TimerAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..d8c0d21fead07733a1b7346a0dcbf04949ec3405 --- /dev/null +++ b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/TimerAbility.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.jsfacard; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.FormBindingData; +import ohos.aafwk.ability.FormException; +import ohos.aafwk.content.Intent; +import ohos.data.DatabaseHelper; +import ohos.data.orm.OrmContext; +import ohos.data.orm.OrmPredicates; +import ohos.event.notification.NotificationRequest; +import ohos.samples.jsfacard.database.Form; +import ohos.samples.jsfacard.database.FormDatabase; +import ohos.samples.jsfacard.utils.DatabaseUtils; +import ohos.samples.jsfacard.utils.DateUtils; +import ohos.samples.jsfacard.utils.LogUtils; +import ohos.utils.zson.ZSONObject; + +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +/** + * TimerAbility + * + * @since 2021-08-20 + */ +public class TimerAbility extends Ability { + private static final String TAG = TimerAbility.class.getName(); + + private static final long UPDATE_PERIOD = 1000L; + + private static final int NOTICE_ID = 1005; + + private OrmContext connect; + + private DatabaseHelper helper = new DatabaseHelper(this); + + @Override + public void onStart(Intent intent) { + LogUtils.info(TAG, "TimerAbility::onStart"); + connect = helper.getOrmContext("FormDatabase", "FormDatabase.db", FormDatabase.class); + startTimer(); + super.onStart(intent); + } + + private void startTimer() { + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + updateForms(); + notice(); + } + }, 0, UPDATE_PERIOD); + } + + private void updateForms() { + OrmPredicates ormPredicates = new OrmPredicates(Form.class); + List
formList = connect.query(ormPredicates); + if (formList.size() <= 0) { + return; + } + for (Form form : formList) { + Long updateFormId = form.getFormId(); + ZSONObject zsonObject = DateUtils.getZsonObject(); + LogUtils.info(TAG, "updateForm FormException " + zsonObject); + try { + updateForm(updateFormId, new FormBindingData(zsonObject)); + } catch (FormException e) { + DatabaseUtils.deleteFormData(form.getFormId(), connect); + LogUtils.info(TAG, "updateForm FormException " + e.getMessage()); + } + } + } + + private void notice() { + NotificationRequest request = new NotificationRequest(NOTICE_ID); + request.setAlertOneTime(true); + NotificationRequest.NotificationNormalContent content = new NotificationRequest.NotificationNormalContent(); + content.setText(DateUtils.getCurrentDate("yyyy-MM-dd HH:mm:ss")); + NotificationRequest.NotificationContent notificationContent = new NotificationRequest.NotificationContent(content); + request.setContent(notificationContent); + keepBackgroundRunning(NOTICE_ID, request); + } + + @Override + public void onBackground() { + LogUtils.info(TAG, "TimerAbility::onBackground"); + super.onBackground(); + } + + @Override + public void onStop() { + LogUtils.info(TAG, "TimerAbility::onStop"); + super.onStop(); + } +} \ No newline at end of file diff --git a/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/database/Form.java b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/database/Form.java new file mode 100644 index 0000000000000000000000000000000000000000..d03f6fc968645b62b0f0c3809e8b202864f16bdc --- /dev/null +++ b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/database/Form.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.jsfacard.database; + +import ohos.data.orm.OrmObject; +import ohos.data.orm.annotation.Entity; +import ohos.data.orm.annotation.PrimaryKey; + +/** + * Card Table + * + * @since 2021-08-20 + */ +@Entity(tableName = "form") +public class Form extends OrmObject { + @PrimaryKey() + private Long formId; + + private String formName; + + private Integer dimension; + + public Form(Long formId, String formName, Integer dimension) { + this.formId = formId; + this.formName = formName; + this.dimension = dimension; + } + + public Form() { } + + public Integer getDimension() { + return dimension; + } + + public void setDimension(Integer dimension) { + this.dimension = dimension; + } + + public Long getFormId() { + return formId; + } + + public void setFormId(Long formId) { + this.formId = formId; + } + + public String getFormName() { + return formName; + } + + public void setFormName(String formName) { + this.formName = formName; + } +} diff --git a/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/database/FormDatabase.java b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/database/FormDatabase.java new file mode 100644 index 0000000000000000000000000000000000000000..10703e7a066345dc186434e0fe7837e34164f9ca --- /dev/null +++ b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/database/FormDatabase.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.jsfacard.database; + +import ohos.data.orm.OrmDatabase; +import ohos.data.orm.annotation.Database; + +/** + * Card Database + * + * @since 2021-08-20 + */ +@Database( + entities = {Form.class}, + version = 1) +public abstract class FormDatabase extends OrmDatabase { } diff --git a/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/slice/ClockAbilitySlice.java b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/slice/ClockAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..fb3abe9cda635e5eb652be5aa0f0f0dbd63abcc1 --- /dev/null +++ b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/slice/ClockAbilitySlice.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.jsfacard.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import ohos.agp.components.Text; +import ohos.eventhandler.EventHandler; +import ohos.eventhandler.EventRunner; +import ohos.eventhandler.InnerEvent; +import ohos.samples.jsfacard.ResourceTable; +import ohos.samples.jsfacard.utils.DateUtils; +import ohos.samples.jsfacard.utils.LogUtils; + +import java.util.Calendar; +import java.util.Timer; +import java.util.TimerTask; + +/** + * ClockAbilitySlice + * + * @since 2021-08-20 + */ +public class ClockAbilitySlice extends AbilitySlice { + private static final String TAG = ClockAbilitySlice.class.getName(); + + private static final long SEND_PERIOD = 1000L; + + private Timer timer; + + private EventRunner eventRunner; + + private MyEventHandler myEventHandler; + + private Runnable runnable = new Runnable() { + @Override + public void run() { + initHandler(); + } + + private void initHandler() { + eventRunner = EventRunner.getMainEventRunner(); + if (eventRunner == null) { + return; + } + myEventHandler = new MyEventHandler(eventRunner); + } + }; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_timer_progress_clock_1x2); + initComponent(); + startTimer(); + } + + private void initComponent() { + Calendar now = Calendar.getInstance(); + Component hourComponent = findComponentById(ResourceTable.Id_hour); + if (hourComponent instanceof Text) { + Text hourText = (Text) hourComponent; + int hour = now.get(Calendar.HOUR_OF_DAY); + hourText.setText(DateUtils.setTextValue(hour)); + } + Component minComponent = findComponentById(ResourceTable.Id_min); + if (minComponent instanceof Text) { + Text minText = (Text) minComponent; + int min = now.get(Calendar.MINUTE); + minText.setText(DateUtils.setTextValue(min)); + } + Component secComponent = findComponentById(ResourceTable.Id_sec); + if (secComponent instanceof Text) { + Text secText = (Text) secComponent; + int sec = now.get(Calendar.SECOND); + secText.setText(DateUtils.setTextValue(sec)); + } + } + + private void startTimer() { + timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + runnable.run(); + myEventHandler.sendEvent(1); + } + }, 0, SEND_PERIOD); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } + + @Override + protected void onStop() { + LogUtils.info(TAG, " start to destroy slice"); + timer.cancel(); + } + + private class MyEventHandler extends EventHandler { + MyEventHandler(EventRunner runner) throws IllegalArgumentException { + super(runner); + } + + @Override + protected void processEvent(InnerEvent event) { + super.processEvent(event); + int eventId = event.eventId; + if (eventId == 1) { + initComponent(); + } + } + } +} \ No newline at end of file diff --git a/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/utils/DatabaseUtils.java b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/utils/DatabaseUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..ff8435e51af17713998a5c56f723040f48c4164a --- /dev/null +++ b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/utils/DatabaseUtils.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.jsfacard.utils; + +import ohos.data.orm.OrmContext; +import ohos.data.orm.OrmPredicates; +import ohos.samples.jsfacard.database.Form; + +import java.util.List; + +/** + * Card Database Operations + * + * @since 2021-08-20 + */ +public class DatabaseUtils { + /** + * delete form data + * + * @param formId form id + * @param connect data connection + */ + public static void deleteFormData(long formId, OrmContext connect) { + OrmPredicates where = connect.where(Form.class); + where.equalTo("formId", formId); + List query = connect.query(where); + if (!query.isEmpty()) { + connect.delete(query.get(0)); + connect.flush(); + } + } + + /** + * insert card info + * + * @param form card object + * @param connect data connection + */ + public static void insertForm(Form form, OrmContext connect) { + connect.insert(form); + connect.flush(); + } +} diff --git a/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/utils/DateUtils.java b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/utils/DateUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..eed2e895fde45190a87b7cc4f70365e18d2c03be --- /dev/null +++ b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/utils/DateUtils.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.jsfacard.utils; + +import ohos.utils.zson.ZSONObject; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +/** + * Date time util + * + * @since 2021-08-20 + */ +public class DateUtils { + private static final int TIME_LENGTH = 2; + + /** + * current time + * + * @param format format + * @return corresponding format string + */ + public static String getCurrentDate(String format) { + DateFormat dateFormat = new SimpleDateFormat(format); + Date date = new Date(); + String formatDate = dateFormat.format(date); + return formatDate; + } + + /** + * get the data that the page needs + * + * @return corresponding data + */ + public static ZSONObject getZsonObject() { + ZSONObject result = new ZSONObject(); + Calendar now = Calendar.getInstance(); + int hour = now.get(Calendar.HOUR_OF_DAY); + result.put("hour", setTextValue(hour)); + int min = now.get(Calendar.MINUTE); + result.put("min", setTextValue(min)); + int sec = now.get(Calendar.SECOND); + result.put("sec", setTextValue(sec)); + return result; + } + + /** + * set text value + * + * @param now current time + * @return corresponding format string + */ + public static String setTextValue(int now) { + String text = String.valueOf(now); + if (text.length() < TIME_LENGTH) { + text = "0" + text; + } else { + text = text + ""; + } + return text; + } +} diff --git a/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/utils/LogUtils.java b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/utils/LogUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..bd158aceee966f64615617e65da8c76811907592 --- /dev/null +++ b/UI/JsFACard/entry/src/main/java/ohos/samples/jsfacard/utils/LogUtils.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.jsfacard.utils; + +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +/** + * LogUtils + * + * @since 2021-08-20 + */ +public class LogUtils { + private static final String TAG_LOG = "LogUtil"; + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(0, 0, LogUtils.TAG_LOG); + + private static final String LOG_FORMAT = "%{public}s: %{public}s"; + + private LogUtils() { } + + /** + * Print debug log + * + * @param tag log tag + * @param msg log message + */ + public static void debug(String tag, String msg) { + HiLog.debug(LABEL_LOG, LOG_FORMAT, tag, msg); + } + + /** + * Print info log + * + * @param tag log tag + * @param msg log message + */ + public static void info(String tag, String msg) { + HiLog.info(LABEL_LOG, LOG_FORMAT, tag, msg); + } + + /** + * Print warn log + * + * @param tag log tag + * @param msg log message + */ + public static void warn(String tag, String msg) { + HiLog.warn(LABEL_LOG, LOG_FORMAT, tag, msg); + } + + /** + * Print error log + * + * @param tag log tag + * @param msg log message + */ + public static void error(String tag, String msg) { + HiLog.error(LABEL_LOG, LOG_FORMAT, tag, msg); + } +} diff --git a/UI/JsFACard/entry/src/main/js/card/pages/index/index.hml b/UI/JsFACard/entry/src/main/js/card/pages/index/index.hml index 748b13d2201fb4647e94ec3daf9dcd168424ce0d..5195841dfddc6a310cbceb79cb575b365572b8f2 100644 --- a/UI/JsFACard/entry/src/main/js/card/pages/index/index.hml +++ b/UI/JsFACard/entry/src/main/js/card/pages/index/index.hml @@ -15,16 +15,15 @@
-
{{ $t('strings.music') }} - {{ $t('strings.singer') }} + {{ $t('strings.singer') }} +
-
diff --git a/UI/JsFACard/entry/src/main/js/card/pages/index/index.json b/UI/JsFACard/entry/src/main/js/card/pages/index/index.json index cf44ac53309b8d5b3e43847b13d51013a7c54c9a..69786201ed9dd37013d27b52935d1850e3959eb6 100644 --- a/UI/JsFACard/entry/src/main/js/card/pages/index/index.json +++ b/UI/JsFACard/entry/src/main/js/card/pages/index/index.json @@ -1,5 +1,6 @@ { - "data": {}, + "data": { + }, "actions": { "activeEvent": { "action": "router", diff --git a/UI/JsFACard/entry/src/main/js/clock1x2/pages/index/index.css b/UI/JsFACard/entry/src/main/js/clock1x2/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..cd48aac893dde1ca72ee45feaa217eb0b7c8e033 --- /dev/null +++ b/UI/JsFACard/entry/src/main/js/clock1x2/pages/index/index.css @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +.container { + flex-direction: column; + align-content: center; + align-items: center; + justify-content: center; + background-color: #A4D7E5; +} + +.title { + flex-direction: row; + align-items: center; + align-content: center; + justify-content: center; +} + +.title-text { + margin-right: 7px; + margin-bottom: 3px; + font-size: 10px; + opacity: 0.6; +} + +.time-text { + padding: 1px; + font-size: 16px; + opacity: 1.2; +} \ No newline at end of file diff --git a/UI/JsFACard/entry/src/main/js/clock1x2/pages/index/index.hml b/UI/JsFACard/entry/src/main/js/clock1x2/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f1b3d06517af2b54a8b9e43b261ed2c636b7b2c2 --- /dev/null +++ b/UI/JsFACard/entry/src/main/js/clock1x2/pages/index/index.hml @@ -0,0 +1,29 @@ + + +
+
+
+ {{ $item.title }} +
+
+
+ {{hour}} + : + {{min}} + : + {{sec}} +
+
\ No newline at end of file diff --git a/UI/JsFACard/entry/src/main/js/clock1x2/pages/index/index.json b/UI/JsFACard/entry/src/main/js/clock1x2/pages/index/index.json new file mode 100644 index 0000000000000000000000000000000000000000..b5cc755c701ce7a37986915f108f237c3519ae04 --- /dev/null +++ b/UI/JsFACard/entry/src/main/js/clock1x2/pages/index/index.json @@ -0,0 +1,31 @@ +{ + "data": { + "titleList": [ + { + "id": 1, + "title": "HOUR" + }, + { + "id": 2, + "title": "MIN" + }, + { + "id": 3, + "title": "SEC" + } + ], + "hour": "", + "min": "", + "sec": "" + }, + "actions": { + "routerEvent": { + "action": "router", + "bundleName": "ohos.samples.jsfacard", + "abilityName": ".ClockAbility", + "params": { + "message": "add detail" + } + } + } +} \ No newline at end of file diff --git a/UI/JsFACard/entry/src/main/resources/base/element/string.json b/UI/JsFACard/entry/src/main/resources/base/element/string.json index cc629eb54781858d04e70e3a3f6b1ce836ea21bf..1bc16f7a67d1342f8c6947ff2772e3e8faf76984 100644 --- a/UI/JsFACard/entry/src/main/resources/base/element/string.json +++ b/UI/JsFACard/entry/src/main/resources/base/element/string.json @@ -4,9 +4,45 @@ "name": "entry_MainAbility", "value": "JsFACard" }, + { + "name": "app_name", + "value": "JsFACard" + }, { "name": "mainability_description", - "value": "JS card example" + "value": "Java_Empty Ability" + }, + { + "name": "clockability_description", + "value": "Java_Empty Ability" + }, + { + "name": "hour", + "value": "HOUR" + }, + { + "name": "min", + "value": "MIN" + }, + { + "name": "sec", + "value": "SEC" + }, + { + "name": "time", + "value": "00" + }, + { + "name": "symbol", + "value": ":" + }, + { + "name": "text_font", + "value": "HwChinese-medium" + }, + { + "name": "timerability_description", + "value": "hap sample empty service" } ] } \ No newline at end of file diff --git a/UI/JsFACard/entry/src/main/resources/base/layout/immersion_widget.xml b/UI/JsFACard/entry/src/main/resources/base/graphic/background_ability_clock.xml similarity index 62% rename from UI/JsFACard/entry/src/main/resources/base/layout/immersion_widget.xml rename to UI/JsFACard/entry/src/main/resources/base/graphic/background_ability_clock.xml index 949296d69eccefed016d5bcb8941553e55e310b9..e5413eb29c94f089b8f5e88196566a1d623c09cb 100644 --- a/UI/JsFACard/entry/src/main/resources/base/layout/immersion_widget.xml +++ b/UI/JsFACard/entry/src/main/resources/base/graphic/background_ability_clock.xml @@ -1,4 +1,4 @@ - + - + ohos:shape="rectangle"> - - \ No newline at end of file + + \ No newline at end of file diff --git a/UI/JsFACard/entry/src/main/resources/base/layout/timer_progress_clock_1x2.xml b/UI/JsFACard/entry/src/main/resources/base/layout/timer_progress_clock_1x2.xml new file mode 100644 index 0000000000000000000000000000000000000000..a6788d5aed592776fab373758051a00584a9eef6 --- /dev/null +++ b/UI/JsFACard/entry/src/main/resources/base/layout/timer_progress_clock_1x2.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/UI/JsFACard/entry/src/main/resources/en/element/string.json b/UI/JsFACard/entry/src/main/resources/en/element/string.json index 7c414e340c665376d623e255c141f00c5bb95137..03fe01d7df836107537ae7b46fa88e150185381e 100644 --- a/UI/JsFACard/entry/src/main/resources/en/element/string.json +++ b/UI/JsFACard/entry/src/main/resources/en/element/string.json @@ -5,8 +5,12 @@ "value": "JsFACard" }, { - "name": "mainability_description", - "value": "JS card example" + "name": "app_name", + "value": "JsFACard" + }, + { + "name": "clockability_description", + "value": "Java_Empty Ability" } ] -} +} \ No newline at end of file diff --git a/UI/JsFACard/entry/src/main/resources/zh/element/string.json b/UI/JsFACard/entry/src/main/resources/zh/element/string.json index 1ac418b8183186082fff4465f96c80acb26337bb..6afa3dd6f3f01ef976c52e47c20b409d94d4c05a 100644 --- a/UI/JsFACard/entry/src/main/resources/zh/element/string.json +++ b/UI/JsFACard/entry/src/main/resources/zh/element/string.json @@ -5,8 +5,12 @@ "value": "Js卡片" }, { - "name": "mainability_description", - "value": "JS卡片示例" + "name": "clockability_description", + "value": "Java_Empty Ability" + }, + { + "name": "app_name", + "value": "Js卡片" } ] } \ No newline at end of file diff --git a/UI/JsFACard/screenshots/device/Card.png b/UI/JsFACard/screenshots/device/Card.png index cb083b0528a2ef53f0a34f8ebca66e458d782d89..601edc117dd7831b030649c9d5fc2f61367dbd04 100644 Binary files a/UI/JsFACard/screenshots/device/Card.png and b/UI/JsFACard/screenshots/device/Card.png differ diff --git "a/UI/JsFACard/screenshots/device/Clock1\303\2272.png" "b/UI/JsFACard/screenshots/device/Clock1\303\2272.png" new file mode 100644 index 0000000000000000000000000000000000000000..442aff8184581a774d54d04678d1682c14aaed69 Binary files /dev/null and "b/UI/JsFACard/screenshots/device/Clock1\303\2272.png" differ