diff --git a/UI/JsTimer/README_zh.md b/UI/JsTimer/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..9fafa9c686f833e7579d9138dccb1e47c3d7e8e1 --- /dev/null +++ b/UI/JsTimer/README_zh.md @@ -0,0 +1,16 @@ +# 定时器与系统时间设置 + +### 简介 + +本示例通过 systemTime 接口来实现设置系统时间,通过 setTimeout() 等函数来设置定时器。 + +### 使用说明 + +点击时间框,选择时间日期,点击相应按钮来设置系统时间; + +点击倒计时框,选择定时器的时长,点击按钮来启动定时器,若想中途放弃定时任务,点击取消按钮。 + +### 约束与限制 + +本示例仅支持在标准系统上运行。 + diff --git a/UI/JsTimer/build.gradle b/UI/JsTimer/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..1b3e0fec17de0c99cac160a912d7914d4b49214d --- /dev/null +++ b/UI/JsTimer/build.gradle @@ -0,0 +1,33 @@ +apply plugin: 'com.huawei.ohos.app' + +ohos { + compileSdkVersion 6 + defaultConfig { + compatibleSdkVersion 6 + } +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } + dependencies { + classpath 'com.huawei.ohos:hap:2.4.4.3-RC' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } +} \ No newline at end of file diff --git a/UI/JsTimer/entry/build.gradle b/UI/JsTimer/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..bdd062a7561aa5eb7aff41d19322ee21d13a72a5 --- /dev/null +++ b/UI/JsTimer/entry/build.gradle @@ -0,0 +1,17 @@ +apply plugin: 'com.huawei.ohos.hap' + +ohos { + compileSdkVersion 6 + defaultConfig { + compatibleSdkVersion 6 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + supportSystem "standard" +} \ No newline at end of file diff --git a/UI/JsTimer/entry/src/main/config.json b/UI/JsTimer/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..7f7c9265ff98ada04e38fef5e0dcb69282351bed --- /dev/null +++ b/UI/JsTimer/entry/src/main/config.json @@ -0,0 +1,57 @@ +{ + "app": { + "bundleName": "ohos.samples.jstimer", + "vendor": "samples", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.jstimer", + "name": ".MyApplication", + "mainAbility": "ohos.samples.jstimer.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.samples.jstimer.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + } + ] + } +} \ No newline at end of file diff --git a/UI/JsTimer/entry/src/main/js/default/app.js b/UI/JsTimer/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..d7e076f8bc1c94876554011c7dc9cef4385e1593 --- /dev/null +++ b/UI/JsTimer/entry/src/main/js/default/app.js @@ -0,0 +1,24 @@ +'@file function' +/* + * 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. + */ + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/UI/JsTimer/entry/src/main/js/default/i18n/en-US.json b/UI/JsTimer/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..f3a4507be4004695d2ddd89d0c4c712277ebe103 --- /dev/null +++ b/UI/JsTimer/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,12 @@ +{ + "strings": { + "time-text": "time", + "countdown": "countdown", + "setTimer": "set timer", + "success": "start the time", + "failure": "cancel setting timer", + "setSystemTime": "set system time", + "setup": "set up the success", + "shutdown": "end of the timing" + } +} \ No newline at end of file diff --git a/UI/JsTimer/entry/src/main/js/default/i18n/zh-CN.json b/UI/JsTimer/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..eae462447449fc0e815b869d88a8adddad6a61f7 --- /dev/null +++ b/UI/JsTimer/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,12 @@ +{ + "strings": { + "time-text": "时间", + "countdown": "倒计时", + "setTimer": "设置定时器", + "success": "开始计时", + "failure": "取消定时器", + "setSystemTime": "设置系统时间", + "setup": "设置成功", + "shutdown": "计时结束" + } +} \ No newline at end of file diff --git a/UI/JsTimer/entry/src/main/js/default/pages/index/index.css b/UI/JsTimer/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..f1e4221778765cff445ebcb72ccbcb569266bdd6 --- /dev/null +++ b/UI/JsTimer/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,52 @@ +/* + * 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 { + width: 100%; + height: 100%; + flex-direction: column; + justify-content: center; + align-items: center; +} + +.picker { + width: 200px; + height: 30px; + font-size: 16px; + margin-left: 20px; + text-align: center; + border-width: 1px; + border-style: solid; + border-color: #000; +} + +.text { + height: 30px; + font-size: 16px; +} + +.picker-text { + width: 100%; + height: 50px; + align-items: center; + justify-content: center; +} + +.btn { + width: 60%; + height: 48px; + font-size: 16px; + margin-top: 20px; +} \ No newline at end of file diff --git a/UI/JsTimer/entry/src/main/js/default/pages/index/index.hml b/UI/JsTimer/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..34c2c01deee4b59d3a4907fc6d18db1e989ec8e6 --- /dev/null +++ b/UI/JsTimer/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,30 @@ + + +
+
+ {{ $t('strings.time-text') }} + {{ dataDateTime }} + +
+ +
+ {{ $t('strings.countdown') }} + {{ + dataTime }} +
+ + +
diff --git a/UI/JsTimer/entry/src/main/js/default/pages/index/index.js b/UI/JsTimer/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..e1f4be779edaa163440106198cd8321bc2aeae74 --- /dev/null +++ b/UI/JsTimer/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,64 @@ +`@file`; +/* + * 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. + */ + +import prompt from '@system.prompt'; +import systemTime from '@ohos.systemTime'; + +export default { + data: { + dataDateTime: '2021-8-23-12-00', + dataTime: '00:00:00', + timeoutID: '0', + milliSecond: 0, + time: 0 + }, + dateTimeChange(e) { + this.dataDateTime = 'e.year + "-" + e.month + "-" + e.day + "-" + e.hour + "-" + e.minute'; + var date = new Date(this.dataDateTime); + this.time = date.getTime(); + }, + timeChange(e) { + this.dataTime = 'e.hour + ":" + e.minute + ":" + e.second'; + this.milliSecond = Number(e.hour) * 3600 * 1000 + Number(e.minute) * 60 * 1000 + Number(e.second) * 1000; + }, + setTimer() { + prompt.showToast({ + message: this.$t('strings.success'), + }); + var message = this.$t('strings.shutdown'); + this.timeoutID = setTimeout(function () { + prompt.showToast({ + message: message, + duration: 2000 + }); + }, this.milliSecond); + }, + clearTimer() { + clearTimeout(this.timeoutID); + prompt.showToast({ + message: this.$t('strings.failure'), + duration: 2000 + }); + }, + setTime() { + systemTime.setTime(this.time) + .then((value) => { + console.log(`success to systemTime.setTime: ${value}`); + }).catch((err) => { + console.error(`failed to systemTime.setTime because ${err.message}`); + }); + } +}; diff --git a/UI/JsTimer/entry/src/main/resources/base/element/string.json b/UI/JsTimer/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0bae6bd40f7360d5d818998221b199d3ec0f69c0 --- /dev/null +++ b/UI/JsTimer/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "JS_Empty Ability" + } + ] +} \ No newline at end of file diff --git a/UI/JsTimer/entry/src/main/resources/base/media/icon.png b/UI/JsTimer/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/UI/JsTimer/entry/src/main/resources/base/media/icon.png differ diff --git a/UI/JsTimer/screenshots/device/main.jpg b/UI/JsTimer/screenshots/device/main.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e698ee080536fad228712d042db279b56145edd4 Binary files /dev/null and b/UI/JsTimer/screenshots/device/main.jpg differ diff --git a/UI/JsTimer/screenshots/device/setTime.jpg b/UI/JsTimer/screenshots/device/setTime.jpg new file mode 100644 index 0000000000000000000000000000000000000000..fc42ad40aa9d12508f7910f2dbed9bc722830900 Binary files /dev/null and b/UI/JsTimer/screenshots/device/setTime.jpg differ diff --git a/UI/JsTimer/settings.gradle b/UI/JsTimer/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..4773db73233a570c2d0c01a22e75321acfbf7a07 --- /dev/null +++ b/UI/JsTimer/settings.gradle @@ -0,0 +1 @@ +include ':entry'