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