mirror of
https://gitee.com/openharmony/applications_settings
synced 2024-11-23 14:30:06 +00:00
add ScreenModeSetting function
Signed-off-by: xuchangzhou <xuzhangzhou@huawei.com>
This commit is contained in:
parent
a5534c6a1e
commit
13cc58dd8f
@ -32,7 +32,7 @@ export class BrightnessSettingModel extends BaseModel{
|
||||
private settingsDataKey:string = ConfigData.SETTINGSDATA_BRIGHTNESS;
|
||||
private brightness:number = 5;
|
||||
private defaultBrightnessStr = '5';
|
||||
private TAG = ConfigData.TAG + 'BrightnessSettingModel ';
|
||||
private TAG = `${ConfigData.TAG} BrightnessSettingModel `;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@ -55,7 +55,7 @@ export class BrightnessSettingModel extends BaseModel{
|
||||
@Log
|
||||
public setValue(brightness:number, sliderChangeMode:number){
|
||||
if(sliderChangeMode === ConfigData.SLIDER_CHANG_MODE_END){
|
||||
LogUtil.info(this.TAG + `setValue [brightness:${brightness}, sliderChangeMode:${sliderChangeMode}]`);
|
||||
LogUtil.info(`${this.TAG} setValue [brightness:${brightness}, sliderChangeMode:${sliderChangeMode}]`);
|
||||
this.setSettingsData(brightness);
|
||||
}else{
|
||||
this.setSystemBrightness(brightness);
|
||||
@ -68,10 +68,10 @@ export class BrightnessSettingModel extends BaseModel{
|
||||
*/
|
||||
@Log
|
||||
private setSettingsData(brightness:number){
|
||||
LogUtil.info(this.TAG + `setSettingsData [brightness:${brightness}]`);
|
||||
LogUtil.info(`${this.TAG} setSettingsData [brightness:${brightness}]`);
|
||||
this.brightness = brightness;
|
||||
settings.setValue(this.dataAbilityHelper, this.settingsDataKey, brightness.toString());
|
||||
LogUtil.info(this.TAG + `setSettingsData success`);
|
||||
LogUtil.info(`${this.TAG} setSettingsData success`);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,9 +89,9 @@ export class BrightnessSettingModel extends BaseModel{
|
||||
*/
|
||||
@Log
|
||||
private updateValue(){
|
||||
LogUtil.info(this.TAG + 'updateValue');
|
||||
LogUtil.info(`${this.TAG} updateValue`);
|
||||
this.brightness = parseInt(settings.getValue(this.dataAbilityHelper, this.settingsDataKey, this.defaultBrightnessStr));
|
||||
LogUtil.info(this.TAG + `updateValue success, [brightness:${this.brightness}]`);
|
||||
LogUtil.info(`${this.TAG} updateValue success, [brightness:${this.brightness}]`);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -100,11 +100,11 @@ export class BrightnessSettingModel extends BaseModel{
|
||||
*/
|
||||
@Log
|
||||
public registerObserver(){
|
||||
LogUtil.info(this.TAG + 'registerObserver');
|
||||
LogUtil.info(`${this.TAG} registerObserver`);
|
||||
this.dataAbilityHelper.on("dataChange", this.urivar, (err)=>{
|
||||
this.updateValue();
|
||||
})
|
||||
LogUtil.info(this.TAG + 'registerObserver success');
|
||||
LogUtil.info(`${this.TAG} registerObserver success`);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -113,9 +113,9 @@ export class BrightnessSettingModel extends BaseModel{
|
||||
*/
|
||||
@Log
|
||||
public unregisterObserver() {
|
||||
LogUtil.info(this.TAG + 'unregisterObserver');
|
||||
LogUtil.info(`${this.TAG} unregisterObserver`);
|
||||
this.dataAbilityHelper.off("dataChange", this.urivar, (err)=>{
|
||||
LogUtil.info(this.TAG + 'unregisterObserver success');
|
||||
LogUtil.info(`${this.TAG} unregisterObserver success`);
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
//@ts-nocheck
|
||||
/**
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,14 +18,14 @@ import BaseModel from '../../../../../../../../../common/utils/src/main/ets/defa
|
||||
import ConfigData from '../../../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
import LogUtil from '../../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import Log from '../../../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
import Screen from "@ohos.screen";
|
||||
import ScreenManager from '@ohos.screen';
|
||||
|
||||
/**
|
||||
* Screen Mode setting
|
||||
*/
|
||||
export class ScreenModeModel extends BaseModel{
|
||||
private supportedScreenModes: Array<Screen.ScreenModeInfo> = [{width:3120, height:1440}];
|
||||
private sysScreenMode: Screen.ScreenModeInfo;
|
||||
private supportedScreenModes;
|
||||
private sysScreenMode;
|
||||
private TAG = ConfigData.TAG + ' ScreenModeModel ';
|
||||
private screenLevel: string;
|
||||
|
||||
@ -38,7 +39,14 @@ export class ScreenModeModel extends BaseModel{
|
||||
*/
|
||||
@Log
|
||||
public init(): void{
|
||||
this.sysScreenMode = this.supportedScreenModes[0]//Screen.supportedModeInfo[0];//because the array only has one element
|
||||
ScreenManager.getAllScreen().then((screens) => {
|
||||
LogUtil.info(`${this.TAG} sysScreenMode AllScreen: ${JSON.stringify(screens)}.`)
|
||||
this.supportedScreenModes = screens[0].supportedModeInfo;
|
||||
this.sysScreenMode = screens[0].supportedModeInfo[screens[0].activeModeIndex]
|
||||
LogUtil.info(`${this.TAG} sysScreenMode: ${JSON.stringify(this.sysScreenMode)}.`)
|
||||
}, (err) => {
|
||||
LogUtil.info(`${this.TAG} setScreenActiveMode error: ${JSON.stringify(err)}.`)
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
@ -46,7 +54,7 @@ export class ScreenModeModel extends BaseModel{
|
||||
* get supported screenModes
|
||||
*/
|
||||
@Log
|
||||
public getSupportedScreenModes(): Array<Screen.ScreenModeInfo>{
|
||||
public getSupportedScreenModes(){
|
||||
return this.supportedScreenModes;
|
||||
}
|
||||
|
||||
@ -54,17 +62,24 @@ export class ScreenModeModel extends BaseModel{
|
||||
* get sysScreenMode
|
||||
*/
|
||||
@Log
|
||||
public getSysScreenMode(): Screen.ScreenModeInfo{
|
||||
public getSysScreenMode(){
|
||||
return this.sysScreenMode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set sysScreenMode
|
||||
*/
|
||||
@Log
|
||||
public setSysScreenMode(index:number): void{
|
||||
Screen.setScreenActiveMode(index).then((ret) => {
|
||||
LogUtil.info(`${this.TAG} setScreenActiveMode ret: ${JSON.stringify(ret)}.`);
|
||||
ScreenManager.getAllScreen().then((screens) => {
|
||||
screens[0].setScreenActiveMode(index).then((ret) => {
|
||||
if (ret) {
|
||||
LogUtil.info(`${this.TAG} setScreenActiveMode ret: ${JSON.stringify(ret)}.`)
|
||||
}
|
||||
})
|
||||
}, (err) => {
|
||||
LogUtil.info(`${this.TAG} setScreenActiveMode error: ${JSON.stringify(err)}.`)
|
||||
})
|
||||
return;
|
||||
}
|
||||
@ -98,7 +113,7 @@ export class ScreenModeModel extends BaseModel{
|
||||
*/
|
||||
@Log
|
||||
public getScreenLevel(screenModeInfo): string{
|
||||
return '高';
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,7 +122,7 @@ export class ScreenModeModel extends BaseModel{
|
||||
@Log
|
||||
public registerObserver(){
|
||||
LogUtil.info(`${this.TAG} registerObserver.`);
|
||||
Screen.on('screenChangeEvent', (ScreenEvent) => {
|
||||
ScreenManager.on('screenChangeEvent', (ScreenEvent) => {
|
||||
this.init();
|
||||
})
|
||||
LogUtil.info(`${this.TAG} registerObserver success.`);
|
||||
@ -120,7 +135,7 @@ export class ScreenModeModel extends BaseModel{
|
||||
@Log
|
||||
public unregisterObserver() {
|
||||
LogUtil.info(`${this.TAG} unregisterObserver.`);
|
||||
Screen.off('screenChangeEvent', (ScreenEvent) => {
|
||||
ScreenManager.off('screenChangeEvent', (ScreenEvent) => {
|
||||
LogUtil.info(`${this.TAG} unregisterObserver success.`);
|
||||
})
|
||||
return;
|
||||
|
@ -14,18 +14,18 @@
|
||||
*/
|
||||
import LogUtil from '../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil.ets';
|
||||
import Log from '../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator.ets';
|
||||
//import {ScreenModeModel} from '../model/displayAndBrightnessImpl/display/ScreenMode.ets';
|
||||
import {ScreenModeModel} from '../model/displayAndBrightnessImpl/display/ScreenMode.ets';
|
||||
import HeadComponent from '../../../../../../../common/component/src/main/ets/default/headComponent.ets';
|
||||
import ConfigData from '../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData.ets';
|
||||
|
||||
|
||||
/**
|
||||
* brightness setting
|
||||
* ScreenMode setting
|
||||
*/
|
||||
@Entry
|
||||
@Component
|
||||
struct ScreenMode {
|
||||
//@State screenModeModel:ScreenModeModel = new ScreenModeModel();
|
||||
@State screenModeModel:ScreenModeModel = new ScreenModeModel();
|
||||
private TAG = ConfigData.TAG + 'ScreenMode ';
|
||||
|
||||
build() {
|
||||
@ -39,7 +39,7 @@ struct ScreenMode {
|
||||
.width(ConfigData.WH_100_100)
|
||||
|
||||
List(){
|
||||
ForEach([0], (item) => {
|
||||
ForEach(this.screenModeModel.getSupportedScreenModes(), (item) => {
|
||||
ListItem(){
|
||||
Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }){
|
||||
Column(){
|
||||
@ -48,7 +48,7 @@ struct ScreenMode {
|
||||
.margin({top:$r('app.float.distance_16'), bottom:$r('app.float.distance_4')})
|
||||
.textAlign(TextAlign.Start);
|
||||
|
||||
Text($r('app.string.highText', '3120 x 1440'))
|
||||
Text($r('app.string.highText', `${this.screenModeModel.getScreenModeWidth(item)} x ${this.screenModeModel.getScreenModeHeight(item)}`))
|
||||
.fontSize($r('app.float.font_18'))
|
||||
.margin({bottom:$r('app.float.distance_16')})
|
||||
.textAlign(TextAlign.Start);
|
||||
@ -61,10 +61,10 @@ struct ScreenMode {
|
||||
.margin({ right: $r('app.float.radio_component_margin_bottom_right') })
|
||||
.align(Alignment.End)
|
||||
.enabled(false)
|
||||
.checked(true)
|
||||
.onChange(() => {
|
||||
.checked(this.screenModeModel.isSysScreenMode(item))
|
||||
.onClick(() => {
|
||||
LogUtil.info('settings RadioListComponent : onChange: settingValue = ' + item.settingValue)
|
||||
//this.screenModeModel.setSysScreenMode(0);
|
||||
this.screenModeModel.setSysScreenMode(0);
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -89,14 +89,14 @@ struct ScreenMode {
|
||||
@Log
|
||||
private aboutToAppear(): void{
|
||||
LogUtil.info(this.TAG + 'aboutToAppear in');
|
||||
//this.screenModeModel.registerObserver();
|
||||
this.screenModeModel.registerObserver();
|
||||
LogUtil.info(this.TAG + 'aboutToAppear out');
|
||||
}
|
||||
|
||||
@Log
|
||||
private aboutToDisappear(): void{
|
||||
LogUtil.info(this.TAG + 'aboutToDisappear in');
|
||||
//this.screenModeModel.unregisterObserver();
|
||||
this.screenModeModel.unregisterObserver();
|
||||
LogUtil.info(this.TAG + 'aboutToDisappear out');
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@
|
||||
},
|
||||
{
|
||||
"name": "brightnessTab",
|
||||
"value": "亮度"
|
||||
"value": "显示与亮度"
|
||||
},
|
||||
{
|
||||
"name": "applyTab",
|
||||
@ -674,7 +674,7 @@
|
||||
},
|
||||
{
|
||||
"name": "brightness",
|
||||
"value": "显示与亮度"
|
||||
"value": "亮度"
|
||||
},
|
||||
{
|
||||
"name": "screen",
|
||||
|
Loading…
Reference in New Issue
Block a user