mirror of
https://gitee.com/openharmony/applications_app_samples
synced 2024-11-23 08:30:06 +00:00
FlipClock应用设置屏幕常亮接口替换
Signed-off-by: yanhuan <yanhuan15@huawei.com>
This commit is contained in:
parent
bca90dd3c9
commit
4728e72508
@ -24,7 +24,7 @@
|
||||
|
||||
3.倒计时功能。
|
||||
|
||||
4.设置相关功能需安装[Brightness](/lib/Brightness-1.0.0.hap)应用,设置里边实现的功能有全屏、调节屏幕亮度和不熄屏。
|
||||
4.设置相关功能需安装[Brightness](./lib/Brightness-1.0.0.hap)应用,设置里边实现的功能有全屏、调节屏幕亮度和不熄屏。
|
||||
|
||||
### 工程目录
|
||||
```
|
||||
|
@ -13,15 +13,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import lock from '@ohos.runningLock'
|
||||
import Logger from '../model/Logger'
|
||||
|
||||
const HIDE_TIME = 86400000
|
||||
import Logger from '../model/Logger';
|
||||
import window from '@ohos.window';
|
||||
|
||||
@Component
|
||||
export struct LockSwitch {
|
||||
private isLock: boolean = false
|
||||
@Link isComTime: boolean
|
||||
@Link isComTime: boolean;
|
||||
private isKeepScreenOn: boolean = false;
|
||||
|
||||
build() {
|
||||
Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
|
||||
@ -31,20 +30,34 @@ export struct LockSwitch {
|
||||
.id('screenLight')
|
||||
.onChange(() => {
|
||||
this.isLock = !(this.isLock)
|
||||
lock.createRunningLock('running_lock_test', lock.RunningLockType.PROXIMITY_SCREEN_CONTROL)
|
||||
.then(lock => {
|
||||
lock.isHolding()
|
||||
if (this.isLock === true) {
|
||||
this.isComTime = false
|
||||
lock.hold(HIDE_TIME)
|
||||
} else {
|
||||
lock.unhold()
|
||||
this.isComTime = true
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
Logger.info(`create runningLock test error: ${error}`)
|
||||
})
|
||||
let windowClass: window.Window | undefined = AppStorage.Get('windowClass');
|
||||
if (this.isLock === true) {
|
||||
// 打开常亮
|
||||
this.isKeepScreenOn = true;
|
||||
try {
|
||||
let promise = windowClass.setWindowKeepScreenOn(this.isKeepScreenOn);
|
||||
promise.then(() => {
|
||||
Logger.info('Succeeded in setting the screen to be always on.');
|
||||
}).catch((err) => {
|
||||
Logger.info(`Failed to set the screen to be always on. Cause code: ${err.code}, message: ${err.message}`);
|
||||
});
|
||||
} catch (exception) {
|
||||
Logger.error(`Failed to set the screen to be always on. Cause code: ${exception.code}, message: ${exception.message}`);
|
||||
}
|
||||
} else {
|
||||
// 关闭常亮
|
||||
this.isKeepScreenOn = false;
|
||||
try {
|
||||
let promise = windowClass.setWindowKeepScreenOn(this.isKeepScreenOn);
|
||||
promise.then(() => {
|
||||
Logger.info('Succeeded in setting the screen to be always off.');
|
||||
}).catch((err) => {
|
||||
Logger.info(`Failed to set the screen to be always off. Cause code: ${err.code}, message: ${err.message}`);
|
||||
});
|
||||
} catch (exception) {
|
||||
Logger.error(`Failed to set the screen to be always off. Cause code: ${exception.code}, message: ${exception.message}`);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
|
@ -32,5 +32,20 @@ export default class EntryAbility extends UIAbility {
|
||||
}
|
||||
Logger.info(`loadContent success`)
|
||||
})
|
||||
let windowClass: Window.Window | undefined = undefined;
|
||||
try {
|
||||
Window.getLastWindow(this.context, (err, data) => {
|
||||
const errCode: number = err.code;
|
||||
if (errCode) {
|
||||
console.error(`Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
windowClass = data;
|
||||
console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
|
||||
AppStorage.SetOrCreate('windowClass', windowClass);
|
||||
});
|
||||
} catch (exception) {
|
||||
console.error(`Failed to obtain the top window. Cause code: ${exception.code}, message: ${exception.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
BIN
code/Solutions/Tools/FlipClock/lib/Brightness-1.0.0.tgz
(Stored with Git LFS)
BIN
code/Solutions/Tools/FlipClock/lib/Brightness-1.0.0.tgz
(Stored with Git LFS)
Binary file not shown.
Loading…
Reference in New Issue
Block a user