• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2023 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 */
15import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
16import ability from '@ohos.ability.ability';
17import { Constants, Log } from '@ohos/common';
18
19const TAG: string = 'DeleteUIExtensionPage';
20const FOREGROUND_PHOTO_WIDTH: number = 576;
21const BACKGROUND_PHOTO_WIDTH: number = 512;
22const FOREGROUND_PHOTO_HEIGHT: number = 344;
23const BACKGROUND_PHOTO_HEIGHT: number = 360;
24
25let storage = LocalStorage.getShared();
26
27@Entry(storage)
28@Component
29export struct DeleteUIExtensionPage {
30  private uris: Array<string> = [];
31  private thirdAppName: string = '';
32  private session: UIExtensionContentSession =
33    storage.get<UIExtensionContentSession>('session') as UIExtensionContentSession;
34  private phoneAlignRule: Record<string, Record<string, string | VerticalAlign | HorizontalAlign>> = {
35    'bottom': { 'anchor': '__container__', 'align': VerticalAlign.Bottom },
36    'middle': { 'anchor': '__container__', 'align': HorizontalAlign.Center }
37  };
38
39  onPageShow() {
40    this.session.setWindowBackgroundColor('#00000000');
41  }
42
43  aboutToAppear() {
44    this.uris = AppStorage.get('uris') as string[];
45    Log.info(TAG, 'aboutToAppear uris:' + JSON.stringify(this.uris));
46    this.thirdAppName = AppStorage.get('appName') as string;
47    Log.info(TAG, 'aboutToAppear appName:' + this.thirdAppName);
48  }
49
50  private setDeleteResult(isDelete: boolean): void {
51    let abilityResult: ability.AbilityResult = {
52      resultCode: isDelete ? 0 : -1
53    }
54    Log.info(TAG, 'terminateSelfWithResult start, isDelete:' + isDelete);
55    this.session.terminateSelfWithResult(abilityResult)
56  }
57
58  private getThumbnail(isForeground: boolean): string {
59    if (this.uris.length == 0) {
60      return '';
61    }
62    if (this.uris.length == 1) {
63      return `${this.uris[0]}?oper=thumbnail&width=${FOREGROUND_PHOTO_WIDTH}&height=${BACKGROUND_PHOTO_HEIGHT}`;
64    } else if (isForeground) {
65      return `${this.uris[0]}?oper=thumbnail&width=${FOREGROUND_PHOTO_WIDTH}&height=${FOREGROUND_PHOTO_HEIGHT}`;
66    } else {
67      return `${this.uris[1]}?oper=thumbnail&width=${BACKGROUND_PHOTO_WIDTH}&height=${BACKGROUND_PHOTO_HEIGHT}`;
68    }
69  }
70
71  build() {
72    RelativeContainer() {
73      Column() {
74        Column() {
75          Stack({ alignContent: Alignment.Bottom }) {
76            if (this.uris.length > 1) {
77              Image(this.getThumbnail(false))
78                .objectFit(ImageFit.Fill)
79                .border({ radius: '12vp' })
80                .height('100%')
81                .width('100%')
82                .padding({ left: '16vp', right: '16vp' })
83            }
84
85            Image(this.getThumbnail(true))
86              .objectFit(ImageFit.Fill)
87              .border({ radius: '12vp' })
88              .height(this.uris.length > 1 ? '172vp' : '100%')
89              .width('100%')
90          }
91          .width('100%')
92          .height('180vp')
93          .alignContent(Alignment.Top)
94
95          Text($r('app.string.third_delete_dialog_message', this.thirdAppName, this.uris.length))
96            .textAlign(TextAlign.Center)
97            .fontSize($r('sys.float.ohos_id_text_size_body1'))
98            .fontWeight(FontWeight.Regular)
99            .fontColor($r('sys.color.ohos_id_color_text_primary'))
100            .margin({ top: '16vp' })
101        }
102        .alignItems(HorizontalAlign.Center)
103        .width('100%')
104        .padding({ top: '24vp', bottom: '8vp', left: '24vp', right: '24vp' })
105
106        Stack({ alignContent: Alignment.Top }) {
107          Row() {
108            Column() {
109              Button() {
110                Text($r('app.string.dialog_cancel'))
111                  .fontSize($r('sys.float.ohos_id_text_size_button1'))
112                  .fontColor($r('app.color.color_control_highlight'))
113                  .fontWeight(FontWeight.Medium)
114                  .width('100%')
115                  .textAlign(TextAlign.Center)
116              }
117              .backgroundColor($r('app.color.transparent'))
118              .borderRadius($r('sys.float.ohos_id_corner_radius_button'))
119              .height('40vp')
120              .onClick(() => {
121                this.setDeleteResult(false);
122              })
123            }.width('50%')
124
125
126            Divider()
127              .vertical(true)
128              .height(Constants.DEFAULT_DIVIDER_HEIGHT)
129              .color(Constants.DEFAULT_DIVIDER_COLOR)
130
131            Column() {
132              Button() {
133                Text($r('app.string.dialog_delete'))
134                  .fontSize($r('sys.float.ohos_id_text_size_button1'))
135                  .fontColor($r('sys.color.ohos_id_color_warning'))
136                  .fontWeight(FontWeight.Medium)
137                  .width('100%')
138                  .textAlign(TextAlign.Center)
139              }
140              .backgroundColor($r('app.color.transparent'))
141              .borderRadius($r('sys.float.ohos_id_corner_radius_button'))
142              .height('40vp')
143              .onClick(() => {
144                this.setDeleteResult(true);
145              })
146            }.width('50%')
147
148          }
149        }
150        .width('100%')
151        .height('56vp')
152      }
153      .borderRadius($r('sys.float.ohos_id_corner_radius_dialog'))
154      .backgroundColor(Color.White)
155      .width('410vp')
156      .height('303vp')
157      .alignItems(HorizontalAlign.Center)
158      .shadow({
159        radius: $r('app.float.dialog_defult_shadow_m_radio'),
160        color: $r('app.color.dialog_defult_shadow_m_color'),
161        offsetX: $r('app.float.dialog_defult_shadow_m_offsetX'),
162        offsetY: $r('app.float.dialog_defult_shadow_m_offsetY')
163      })
164      .margin({ bottom: '16vp' })
165      .alignRules(this.phoneAlignRule)
166      .id('Column')
167    }
168    .width('100%')
169    .height('100%')
170  }
171}