• 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 Mission from '../modle/Mission'
17import missionManager from '@ohos.application.missionManager'
18import Logger from '../modle/Logger'
19import image from '@ohos.multimedia.image'
20
21const TAG: string = 'MissionInfoComponent'
22
23@Component
24export struct MissionInfoComponent {
25  @State missionSnapshot: image.PixelMap | undefined = undefined
26  @State isOn: boolean = undefined
27  @State translateLeft: number = 0
28  @State panDirection: PanDirection = PanDirection.Left
29  private mission: Mission
30  private handlerRefresh: () => void
31
32  onClickLockMission(missionId: number) {
33    this.isOn = true
34    missionManager.lockMission(missionId).then(() => {
35      Logger.info(TAG, 'lockMission is called')
36      this.handlerRefresh()
37    })
38  }
39
40  onClickUnlockMission(missionId: number) {
41    this.isOn = false
42    missionManager.unlockMission(missionId).then(() => {
43      Logger.info(TAG, 'UnlockMission is called')
44      this.handlerRefresh()
45    })
46  }
47
48  onClickClearMission(missionId: number) {
49    missionManager.clearMission(missionId).then(() => {
50      Logger.info(TAG, 'ClearMission is called')
51      this.handlerRefresh()
52    })
53  }
54
55  onClickMoveMissionToFront(missionId: number) {
56    missionManager.moveMissionToFront(missionId).then(() => {
57      Logger.info(TAG, 'moveMissionToFront is called')
58    })
59  }
60
61  @Builder RowOfSquareTexts(resourceText: Resource, stringText: string | Resource) {
62    Row() {
63      Text(resourceText)
64        .fontSize(20)
65        .fontWeight(10)
66      Text(stringText)
67        .height(40)
68        .fontSize(16)
69        .textAlign(TextAlign.Center)
70        .maxLines(1)
71        .textOverflow({ overflow: TextOverflow.Ellipsis })
72    }
73  }
74
75  @Builder RowOfSquareButtons(button: Resource, color, handlerClick) {
76    Text(button)
77      .width(100)
78      .height(200)
79      .fontSize(30)
80      .textAlign(TextAlign.Center)
81      .margin({ top: 10 })
82      .backgroundColor(color)
83      .onClick(handlerClick)
84  }
85
86  async getSnapshot() {
87    Logger.info(TAG, `mission= ${JSON.stringify(this.mission)}`)
88    let missionSnapshot = await missionManager.getMissionSnapShot('', this.mission.missionId)
89    this.missionSnapshot = missionSnapshot.snapshot
90    Logger.info(TAG, `getMissionSnapShot missionSnapshot = ${JSON.stringify(missionSnapshot)}`)
91  }
92
93  onRunningState(runningState: number) {
94    return runningState === 0 ? $r('app.string.is') : $r('app.string.no')
95  }
96
97  onLockedState(lockedState: boolean) {
98    return lockedState ? $r('app.string.is') : $r('app.string.no')
99  }
100
101  onContinuable(continuable: boolean) {
102    return continuable ? $r('app.string.is') : $r('app.string.no')
103  }
104
105  aboutToAppear() {
106    this.getSnapshot()
107    this.isOn = this.mission.lockedState
108  }
109
110  build() {
111    Row() {
112      Row() {
113        Image(this.missionSnapshot)
114          .objectFit(ImageFit.Contain)
115          .size({ width: 100, height: 200 })
116          .margin({ left: 20, right: 10 })
117        Column() {
118          this.RowOfSquareTexts($r('app.string.bundle_name'), this.mission.want.bundleName)
119          this.RowOfSquareTexts($r('app.string.running_state'), this.onRunningState(this.mission.runningState))
120          this.RowOfSquareTexts($r('app.string.locked_state'), this.onLockedState(this.mission.lockedState))
121          this.RowOfSquareTexts($r('app.string.continuable'), this.onContinuable(this.mission.continuable))
122        }
123        .width('50%')
124        .height(200)
125        .alignItems(HorizontalAlign.Start)
126        .justifyContent(FlexAlign.Center)
127      }
128      .width('100%')
129      .padding(10)
130      .backgroundColor('#f5f5f5')
131      .borderRadius(20)
132
133      Row() {
134        if (this.isOn) {
135          this.RowOfSquareButtons($r('app.string.unlocked_mission'), '#0D9FFB', () => {
136            this.onClickUnlockMission(this.mission.missionId)
137          })
138        } else {
139          this.RowOfSquareButtons($r('app.string.locked_mission'), '#0D9FFB', () => {
140            this.onClickLockMission(this.mission.missionId)
141          })
142        }
143        this.RowOfSquareButtons($r('app.string.move_mission'), Color.Orange, () => {
144          this.onClickMoveMissionToFront(this.mission.missionId)
145        })
146        this.RowOfSquareButtons($r('app.string.clear_mission'), '#ffea0606', () => {
147          this.onClickClearMission(this.mission.missionId)
148        })
149      }
150      .margin({ left: 20 })
151    }
152    .width('100%')
153    .padding({ left: 10, right: 10 })
154    .margin({ left: this.translateLeft })
155    .gesture(
156    PanGesture({ fingers: 1, direction: this.panDirection, distance: 20 })
157      .onActionStart(() => {
158        Logger.info(TAG, `PanGesture onActionStart`)
159        if (this.panDirection === PanDirection.Left) {
160          this.panDirection = PanDirection.Right
161          this.translateLeft = -380
162        } else {
163          this.panDirection = PanDirection.Left
164          this.translateLeft = 0
165        }
166      })
167    )
168  }
169}