• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 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 Constants from '../../common/constants'
18import ViewModel from '../../vm/shortcutViewModel'
19import power from '@ohos.power'
20
21const TAG = 'ScreenLock-Shortcut'
22
23@Component
24export default struct Shortcut {
25  private viewModel: ViewModel = new ViewModel()
26  private shutdownIcon: Resource = $r("app.media.shutdown")
27  private shutdownLabel: Resource = $r("app.string.shutdown")
28  private rebootIcon: Resource = $r("app.media.reboot")
29  private rebootLabel: Resource = $r("app.string.reboot")
30
31  aboutToAppear() {
32    Log.showInfo(TAG, `aboutToAppear`)
33  }
34
35  build() {
36    Row({ space: Constants.SHORTCUT_SPACE }) {
37      ShortcutComponent({
38        mTag: 'ScreenLock-Shutdown',
39        mIcon: this.shutdownIcon,
40        mLabel: this.shutdownLabel,
41        mClickEvent: () => this.viewModel.onShortcutClick(Constants.CLICK_TYPE_SHUTDOWN)
42      })
43
44      ShortcutComponent({
45        mTag: 'ScreenLock-Reboot',
46        mIcon: this.rebootIcon,
47        mLabel: this.rebootLabel,
48        mClickEvent: () => this.viewModel.onShortcutClick(Constants.CLICK_TYPE_REBOOT)
49      })
50    }
51    .margin({ left: '50px' })
52  }
53}
54
55@Component
56struct ShortcutComponent {
57  private mTag: string
58  private mIcon: Resource
59  private mLabel: Resource
60  private mClickEvent: Function
61
62  aboutToAppear() {
63    Log.showInfo(this.mTag, `aboutToAppear Start`)
64  }
65
66  aboutToDisappear() {
67    Log.showInfo(this.mTag, `aboutToDisAppear`)
68  }
69
70  build() {
71    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
72      Stack() {
73        Flex()
74          .backgroundColor($r('app.color.shortcut_icon_color'))
75          .clip(new Circle({ width: Constants.SHORTCUT_CIRCLE_WIDTH, height: Constants.SHORTCUT_CIRCLE_HEIGHT }))
76          .width(Constants.SHORTCUT_CIRCLE_WIDTH)
77          .height(Constants.SHORTCUT_CIRCLE_HEIGHT)
78        Image(this.mIcon)
79          .size({ width: Constants.SHORTCUT_CIRCLE_WIDTH, height: Constants.SHORTCUT_CIRCLE_HEIGHT })
80          .objectFit(ImageFit.Contain)
81      }
82
83      Text(this.mLabel)
84        .fontSize(Constants.SHORTCUT_TEXT_SIZE)
85        .fontColor($r('app.color.shortcut_text_color'))
86        .margin({ top: $r("app.float.shortcut_block") })
87    }
88    .onClick(this.onItemClick.bind(this))
89  }
90
91  onItemClick(event: ClickEvent) {
92    Log.showInfo(TAG, `onItemClick`)
93    if (this.mClickEvent) {
94      this.mClickEvent()
95    }
96  }
97}
98
99
100