diff --git a/ETSUI/eTSRunninglock/README.md b/ETSUI/eTSRunninglock/README.md new file mode 100644 index 0000000000000000000000000000000000000000..35e47cc8a47d5547c0938a2856c90482f52e2007 --- /dev/null +++ b/ETSUI/eTSRunninglock/README.md @@ -0,0 +1,21 @@ +# Ets运行锁 + +### 简介 + +本示例展示了阻止系统休眠的运行锁功能,通过黑白色壁纸模拟息屏、亮屏状态,来展示系统的休眠状态,从而对运行锁的功能进行测试,使得该运行锁在打开后可以阻止系统休眠。 + +### 使用说明 + +1.先点击**查询支持**按钮,查询系统是否支持该锁。 + +2.点击**定时息屏**按钮,系统在5秒后可定时灭屏(黑色背景模拟)。 + +2.打开锁开关,系统被阻止进入休眠状态,5秒后将会一直亮屏(白色背景模拟)。 + +3.关闭锁开关,系统被禁止休眠状态解除,5秒后将会到点灭屏(黑色背景模拟)。 + +4.待灭屏后,点击屏幕任意一处即可亮屏(白色背景模拟) + +### 约束与限制 + +本示例仅支持在标准系统上运行。 \ No newline at end of file diff --git a/ETSUI/eTSRunninglock/build.gradle b/ETSUI/eTSRunninglock/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..c2c8bbaed13747b913f19cef893f515bc32d02a7 --- /dev/null +++ b/ETSUI/eTSRunninglock/build.gradle @@ -0,0 +1,34 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 +ohos { + compileSdkVersion 7 + supportSystem "standard" +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } + dependencies { + classpath 'com.huawei.ohos:hap:3.0.3.4' + classpath 'com.huawei.ohos:decctest:1.2.6.0' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } +} diff --git a/ETSUI/eTSRunninglock/entry/build.gradle b/ETSUI/eTSRunninglock/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..1587dd1948941f3eaaf092ae6cae7969cb6895ff --- /dev/null +++ b/ETSUI/eTSRunninglock/entry/build.gradle @@ -0,0 +1,21 @@ +apply plugin: 'com.huawei.ohos.hap' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 +ohos { + compileSdkVersion 7 + defaultConfig { + compatibleSdkVersion 7 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13.1' +} diff --git a/ETSUI/eTSRunninglock/entry/src/main/config.json b/ETSUI/eTSRunninglock/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..9a85e60929df931df668f8f69fccce6a67df35da --- /dev/null +++ b/ETSUI/eTSRunninglock/entry/src/main/config.json @@ -0,0 +1,71 @@ +{ + "app": { + "bundleName": "ohos.samples.runninglock", + "vendor": "samples", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.runninglock", + "name": ".MyApplication", + "mainAbility": ".MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.RUNNING_LOCK" + } + ] + } +} \ No newline at end of file diff --git a/ETSUI/eTSRunninglock/entry/src/main/ets/MainAbility/app.ets b/ETSUI/eTSRunninglock/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..5c326ea7c484400721d4a4902d23df79f693fe1f --- /dev/null +++ b/ETSUI/eTSRunninglock/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,24 @@ +/* + * 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('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/ETSUI/eTSRunninglock/entry/src/main/ets/MainAbility/pages/index.ets b/ETSUI/eTSRunninglock/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..ce99aa60d6f42251b94dd51b7f9163ed22dc377f --- /dev/null +++ b/ETSUI/eTSRunninglock/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,148 @@ +/* + * 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 lock from '@ohos.runninglock'; + +@Entry +@Component +struct Index { + @State OutPut:string='休眠锁关闭,可定时息屏' + @State timeOut:number=5000 + @State islock:boolean = false + @State backgroundColor:Color = Color.White + @State isComTime:boolean=true + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { + Text($r("app.string.entry_MainAbility")) + .width('100%') + .height(50) + .textAlign(TextAlign.Start) + .fontColor(Color.White) + .padding({left:10}) + .fontSize(30) + .backgroundColor('#0D9FFB') + Row(){ + Scroll(){ + Text(this.OutPut) + .fontSize(15) + .maxLines(10) + .margin({left:10}) + .fontWeight(FontWeight.Bold) + } + } + .width('95%') + .height('20%') + .margin({ top: 10 }) + .border({ width: 2, radius: 5, color: Color.Gray }) + + Text($r("app.string.control_sleepLock")) + .width('100%') + .fontSize(20) + .fontColor(Color.White) + .margin({ top: 20 }) + .textAlign(TextAlign.Center) + .backgroundColor('#0D9FFB') + + Row() { + Button() { + Text($r("app.string.search_support")) + .fontSize(15) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + } + .type(ButtonType.Capsule) + .layoutWeight(1) + .margin({ left: 10, right: 5 }) + .flexBasis(1) + .backgroundColor('#0D9FFB') + .onClick(() => { + lock.isRunningLockTypeSupported(lock.RunningLockType.BACKGROUND, (error, supported) => { + if (typeof error === "undefined") { + console.info('BACKGROUND support status is ' + supported); + this.OutPut += "\n本系统支持阻止系统休眠的锁" + lock.done(); + } else { + console.log('error: ' + error); + this.OutPut = "\n本系统不支持组织系统休眠的锁" + lock.done(); + } + }) + }) + + Button() { + Text($r("app.string.timingout_screen")) + .fontSize(15) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + } + .layoutWeight(1) + .flexBasis(1) + .backgroundColor('#0D9FFB') + .margin({ left: 5, right: 10 }) + .onClick(() => { + if (this.isComTime===true ) { + setTimeout(()=>{ + this.backgroundColor = Color.Black + },this.timeOut) + } + }) + } + .width('100%') + .margin({ + top: 20 + }) + + Row() { + Text($r("app.string.sleepLockSwitch")).fontSize(20).width('70%').margin({ left: 10 }).fontWeight(FontWeight.Bold) + Toggle({ type: ToggleType.Switch, isOn: this.islock }) + .width(70) + .height(30) + .onChange(()=>{ + this.islock = !(this.islock) + lock.createRunningLock("running_lock_test", lock.RunningLockType.BACKGROUND) + .then(lock=>{ + lock.isUsed() + if(this.islock===true){ + this.OutPut += "\n休眠锁已打开,无法定时熄屏" + this.isComTime = false + lock.lock(1000); + } + else{ + lock.unlock() + this.OutPut += "\n该锁已被解除,5s后可定时熄屏" + this.isComTime = true + lock.done(); + } + }) + .catch(error => { + console.log('create runningLock test error: ' + error); + lock.done(); + }) + }) + } + .width('100%') + .height(50) + .margin({ top: 10 }) + .backgroundColor(Color.Gray) + } + .backgroundColor(this.backgroundColor) + .onTouch((event:TouchEvent)=>{ + if (event.type===TouchType.Down){ + this.backgroundColor = Color.White + } + }) + } +} \ No newline at end of file diff --git a/ETSUI/eTSRunninglock/entry/src/main/resources/base/element/string.json b/ETSUI/eTSRunninglock/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8ce2a2677ec19e8b50081da661f453bf5584e238 --- /dev/null +++ b/ETSUI/eTSRunninglock/entry/src/main/resources/base/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSRunningLock" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "init_output", + "value": "休眠锁关闭,可定时息屏" + }, + { + "name": "control_sleepLock", + "value": "控制系统休眠的锁" + }, + { + "name": "search_support", + "value": "查询支持" + }, + { + "name": "sleepLockSwitch", + "value": "休眠锁开关" + }, + { + "name": "timingout_screen", + "value": "定时熄屏" + } + ] +} \ No newline at end of file diff --git a/ETSUI/eTSRunninglock/entry/src/main/resources/base/media/icon.png b/ETSUI/eTSRunninglock/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ETSUI/eTSRunninglock/entry/src/main/resources/base/media/icon.png differ diff --git a/ETSUI/eTSRunninglock/entry/src/main/resources/en/element/string.json b/ETSUI/eTSRunninglock/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6c2eef48eaf221d2c775f84518a744b5e104bde2 --- /dev/null +++ b/ETSUI/eTSRunninglock/entry/src/main/resources/en/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSRunningLock" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "init_output", + "value": "The sleep lock is off, and the screen can be off periodically" + }, + { + "name": "control_sleepLock", + "value": "System sleep control lock" + }, + { + "name": "search_support", + "value": "Query suppor" + }, + { + "name": "sleepLockSwitch", + "value": "Sleep lock switch" + }, + { + "name": "timingout_screen", + "value": "Timing out screen" + } + ] +} \ No newline at end of file diff --git a/ETSUI/eTSRunninglock/entry/src/main/resources/zh/element/string.json b/ETSUI/eTSRunninglock/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8ce2a2677ec19e8b50081da661f453bf5584e238 --- /dev/null +++ b/ETSUI/eTSRunninglock/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSRunningLock" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "init_output", + "value": "休眠锁关闭,可定时息屏" + }, + { + "name": "control_sleepLock", + "value": "控制系统休眠的锁" + }, + { + "name": "search_support", + "value": "查询支持" + }, + { + "name": "sleepLockSwitch", + "value": "休眠锁开关" + }, + { + "name": "timingout_screen", + "value": "定时熄屏" + } + ] +} \ No newline at end of file diff --git a/ETSUI/eTSRunninglock/screenshot/device/lockoff.png b/ETSUI/eTSRunninglock/screenshot/device/lockoff.png new file mode 100644 index 0000000000000000000000000000000000000000..33492808be8d388c265e0be96486ed07780c6b3a Binary files /dev/null and b/ETSUI/eTSRunninglock/screenshot/device/lockoff.png differ diff --git a/ETSUI/eTSRunninglock/screenshot/device/lockturn.png b/ETSUI/eTSRunninglock/screenshot/device/lockturn.png new file mode 100644 index 0000000000000000000000000000000000000000..5a9c00181903de2de0e648a7d45d48f15eadd235 Binary files /dev/null and b/ETSUI/eTSRunninglock/screenshot/device/lockturn.png differ diff --git a/ETSUI/eTSRunninglock/settings.gradle b/ETSUI/eTSRunninglock/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..4773db73233a570c2d0c01a22e75321acfbf7a07 --- /dev/null +++ b/ETSUI/eTSRunninglock/settings.gradle @@ -0,0 +1 @@ +include ':entry'