• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import Log from '../../../../../../../../common/src/main/ets/default/Log';
17import {AutoRotateData} from '../common/Constants';
18import ViewModel from '../viewmodel/AutoRotateVM';
19import SimpleToggleBase from '../../../../../../../../common/src/main/ets/template/SimpleToggleBase';
20
21const TAG = 'autorotate-ControlCenterSimpleToggleAutoRotateComponent';
22
23@Component
24export default struct ControlCenterSimpleToggleAutoRotateComponent {
25  private keyId: string;
26  private mEditMode: boolean = false;
27  private mDragMode: boolean = false;
28  @State mIcon: Resource = $r("app.media.ic_controlcenter_auto_rotate_off");
29  @State mLabel: Resource = $r("app.string.control_center_complex_toggle_auto_rotate_title");
30  @State mAutoRotateSwitch : boolean = false
31  @State @Watch('onAutoRotateDataChange') mAutoRotateData: AutoRotateData = ViewModel.getAutoRotateData();
32
33  aboutToAppear() {
34    Log.showInfo(TAG, 'aboutToAppear');
35    this.onAutoRotateDataChange('mAutoRotateData');
36  }
37
38  aboutToDisappear() {
39    Log.showInfo(TAG, 'aboutToDisappear')
40  }
41
42  onAutoRotateDataChange(propName: string): void {
43    Log.showDebug(TAG, `onAutoRotateDataChange, propName: ${propName}`);
44    this.mIcon = this.mAutoRotateData.switchStatus ? $r("app.media.ic_controlcenter_auto_rotate_on") : $r("app.media.ic_controlcenter_auto_rotate_off");
45    this.mAutoRotateSwitch = this.mAutoRotateData.switchStatus
46  }
47
48  build() {
49    SimpleToggleBase({
50      mToggleId: this.keyId,
51      mIcon: $mIcon,
52      mChangeSwitch:$mAutoRotateSwitch,
53      mLabel: $mLabel,
54      mEditMode: this.mEditMode,
55      mDragMode: this.mDragMode,
56      mClickEvent: () => this.mClickEvent()
57    })
58  }
59
60  mClickEvent() {
61    Log.showDebug(TAG, `mClickEvent, status: ${this.mAutoRotateData.switchStatus}`);
62    let newStatus = !this.mAutoRotateData.switchStatus;
63    ViewModel.processAutoRotateSwitchStatusChange(newStatus);
64  }
65}