• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2022-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 windowAnimationManager from '@ohos.animation.windowAnimationManager';
17import curves from '@ohos.curves';
18import { Log } from '../utils/Log';
19import { Trace } from '../utils/Trace';
20import { StyleConstants } from '../constants/StyleConstants';
21import { CommonConstants } from '../constants/CommonConstants';
22import OverlayAppIcon from './OverlayAppIcon';
23import RemoteConstants from '../constants/RemoteConstants';
24import { localEventManager } from '../manager/LocalEventManager';
25import { EventConstants } from '../constants/EventConstants';
26import { CloseAppManager } from '../manager/CloseAppManager';
27import WindowAnimationControllerImpl from '../animation/remoteanimation/WindowAnimationControllerImpl';
28
29const TAG = 'RemoteWindowWrapper';
30
31@Observed
32class RemoteVo {
33  public remoteAnimationType: number;
34  public finishCallback: windowAnimationManager.WindowAnimationFinishedCallback;
35  public target: windowAnimationManager.WindowAnimationTarget;
36  public fromWindowTarget: windowAnimationManager.WindowAnimationTarget;
37  public remoteWindowKey: string;
38  public iconInfo: any;
39  public appItemInfo: any;
40  public count: number = 0;
41
42  mScreenWidth: number;
43  mScreenHeight: number;
44
45  startAppTypeFromPageDesktop: number;
46
47  remoteWindowScaleX: number;
48  remoteWindowScaleY: number;
49  remoteWindowTranslateX: number;
50  remoteWindowTranslateY: number;
51  remoteWindowWindowAlpha: number;
52  remoteWindowRadius: number;
53
54  fromRemoteWindowScaleX: number = 1.0;
55  fromRemoteWindowScaleY: number = 1.0;
56  fromRemoteWindowTranslateX: number = 0;
57  fromRemoteWindowTranslateY: number = 0;
58  fromRemoteWindowWindowAlpha: number = 1.0;
59
60  startAppIconScaleX: number;
61  startAppIconScaleY: number;
62  startAppIconTranslateX: number;
63  startAppIconTranslateY: number;
64  startAppIconWindowAlpha: number;
65
66  constructor(
67    remoteAnimationType: number,
68    startAppTypeFromPageDesktop: number,
69    target: windowAnimationManager.WindowAnimationTarget,
70    iconInfo: any = {},
71    appItemInfo: any = {},
72    fromWindowTarget: windowAnimationManager.WindowAnimationTarget = undefined,
73    finishCallback: windowAnimationManager.WindowAnimationFinishedCallback
74  ) {
75    this.remoteAnimationType = remoteAnimationType;
76    this.target = target;
77    this.fromWindowTarget = fromWindowTarget;
78    this.mScreenWidth = px2vp(this.target.windowBounds.width);
79    this.mScreenHeight = px2vp(this.target.windowBounds.height);
80    this.iconInfo = iconInfo;
81    this.appItemInfo = appItemInfo;
82    this.startAppTypeFromPageDesktop = startAppTypeFromPageDesktop;
83    this.finishCallback = finishCallback;
84    this.remoteWindowKey = this.target.bundleName + this.target.abilityName + this.target.missionId;
85    this.initRemoteWindowProperty();
86  }
87
88  initRemoteWindowProperty() {
89    if (this.remoteAnimationType == RemoteConstants.TYPE_START_APP_FROM_LAUNCHER) {
90      const res = this.calculateStartAppProperty();
91      Log.showInfo(TAG, `initRemoteWindowProperty res: ${JSON.stringify(res)}, mScreenWidth: ${this.mScreenWidth}, mScreenHeight: ${this.mScreenHeight}, startAppTypeFromPageDesktop: ${this.startAppTypeFromPageDesktop}`);
92      this.remoteWindowScaleX = res.startAppCalculateScaleX;
93      this.remoteWindowScaleY = res.startAppCalculateScaleY;
94      this.remoteWindowTranslateX = res.startAppCalculateTranslateX;
95      this.remoteWindowTranslateY = res.startAppCalculateTranslateY;
96      this.remoteWindowWindowAlpha = 0.0;
97      this.remoteWindowRadius = 96;
98
99      this.startAppIconWindowAlpha = 1.0;
100      this.startAppIconScaleX = 1.0;
101      this.startAppIconScaleY = 1.0;
102      this.startAppIconTranslateX = 0.0;
103      this.startAppIconTranslateY = 0.0;
104      this.count = 1;
105    } else if (this.remoteAnimationType == RemoteConstants.TYPE_START_APP_FROM_RECENT) {
106    } else if (this.remoteAnimationType == RemoteConstants.TYPE_START_APP_FROM_OTHER) {
107    } else if (this.remoteAnimationType == RemoteConstants.TYPE_APP_TRANSITION) {
108      this.remoteWindowScaleX = 1.0;
109      this.remoteWindowScaleY = 1.0;
110      this.remoteWindowTranslateX = px2vp(this.target?.windowBounds.width - this.target?.windowBounds.left);
111      this.remoteWindowTranslateY = 0.0;
112      this.remoteWindowWindowAlpha = 1.0;
113      this.remoteWindowRadius = 12;
114
115      this.startAppIconScaleX = 1.0;
116      this.startAppIconScaleY = 1.0;
117      this.startAppIconTranslateX = 0.0;
118      this.startAppIconTranslateY = 0.0;
119      this.startAppIconWindowAlpha = 1.0;
120    } else if (this.remoteAnimationType == RemoteConstants.TYPE_MINIMIZE_WINDOW) {
121      this.remoteWindowScaleX = 1.0;
122      this.remoteWindowScaleY = 1.0;
123      this.remoteWindowTranslateX = 0.0;
124      this.remoteWindowTranslateY = 0.0;
125      this.remoteWindowWindowAlpha = 1.0;
126      this.remoteWindowRadius = 12;
127
128      const res = this.calculateCloseAppProperty();
129      this.startAppIconScaleX = res.closeAppCalculateScaleX;
130      this.startAppIconScaleY = res.closeAppCalculateScaleY;
131      this.startAppIconTranslateX = -res.closeAppCalculateTranslateX;
132      this.startAppIconTranslateY = -res.closeAppCalculateTranslateY;
133      this.startAppIconWindowAlpha = 0.0;
134    } else if (this.remoteAnimationType == RemoteConstants.TYPE_CLOSE_WINDOW) {
135      this.remoteWindowScaleX = 1.0;
136      this.remoteWindowScaleY = 1.0;
137      this.remoteWindowTranslateX = 0.0;
138      this.remoteWindowTranslateY = 0.0;
139      this.remoteWindowRadius = 12;
140      this.remoteWindowWindowAlpha = 1.0;
141
142      this.startAppIconScaleX = 1.0;
143      this.startAppIconScaleY = 1.0;
144      this.startAppIconTranslateX = 0.0;
145      this.startAppIconTranslateY = 0.0;
146      this.startAppIconWindowAlpha = 0.0;
147    }
148  }
149
150  calculateStartAppProperty() {
151    let startAppCalculateScaleX: number;
152    let startAppCalculateScaleY: number;
153    let startAppCalculateTranslateX: number;
154    let startAppCalculateTranslateY: number;
155    Log.showInfo(TAG, `calculateStartAppProperty appIconSize: ${this.iconInfo?.appIconSize}, windowBounds: ${JSON.stringify(this.target?.windowBounds)},
156    appIconPosition: [${this.iconInfo?.appIconPositionX}, ${this.iconInfo?.appIconPositionY}], appIconPositionY: ${this.startAppTypeFromPageDesktop}`);
157    startAppCalculateScaleX = this.iconInfo?.appIconSize / px2vp(this.target?.windowBounds.width);
158    startAppCalculateTranslateX = this.iconInfo?.appIconPositionX + this.iconInfo?.appIconSize / 2
159    - (px2vp(this.target?.windowBounds.left) + px2vp(this.target?.windowBounds.width) / 2);
160
161    if (this.startAppTypeFromPageDesktop === CommonConstants.OVERLAY_TYPE_CARD) {
162      startAppCalculateScaleY = this.iconInfo?.appIconHeight / px2vp(this.target?.windowBounds.height);
163      startAppCalculateTranslateY = this.iconInfo?.appIconPositionY + this.iconInfo?.appIconHeight / 2
164      - (px2vp(this.target?.windowBounds.top) + px2vp(this.target?.windowBounds.height) / 2);
165    } else {
166      startAppCalculateScaleY = this.iconInfo?.appIconSize / px2vp(this.target?.windowBounds.height);
167      startAppCalculateTranslateY = this.iconInfo?.appIconPositionY + this.iconInfo?.appIconSize / 2
168      - (px2vp(this.target?.windowBounds.top) + px2vp(this.target?.windowBounds.height) / 2);
169    }
170    return {
171      startAppCalculateScaleX: startAppCalculateScaleX,
172      startAppCalculateScaleY: startAppCalculateScaleY,
173      startAppCalculateTranslateX: startAppCalculateTranslateX,
174      startAppCalculateTranslateY: startAppCalculateTranslateY
175    }
176  }
177
178  calculateCloseAppProperty() {
179    let closeAppCalculateScaleX: number;
180    let closeAppCalculateScaleY: number;
181    let closeAppCalculateTranslateX: number;
182    let closeAppCalculateTranslateY: number;
183    closeAppCalculateScaleX = px2vp(this.target?.windowBounds.width) / this.iconInfo?.appIconSize;
184    closeAppCalculateTranslateX = this.iconInfo?.appIconPositionX + this.iconInfo?.appIconSize / 2
185    - (px2vp(this.target?.windowBounds.left) + px2vp(this.target?.windowBounds.width) / 2);
186    if (this.startAppTypeFromPageDesktop === CommonConstants.OVERLAY_TYPE_CARD) {
187      closeAppCalculateScaleY = px2vp(this.target?.windowBounds.height) / this.iconInfo?.appIconHeight;
188      closeAppCalculateTranslateY = this.iconInfo?.appIconPositionY + this.iconInfo?.appIconHeight / 2
189      - (px2vp(this.target?.windowBounds.top) + px2vp(this.target?.windowBounds.height) / 2);
190    } else {
191      closeAppCalculateScaleY = px2vp(this.target?.windowBounds.height) / this.iconInfo?.appIconSize;
192      closeAppCalculateTranslateY = this.iconInfo?.appIconPositionY + this.iconInfo?.appIconSize / 2
193      - (px2vp(this.target?.windowBounds.top) + px2vp(this.target?.windowBounds.height) / 2);
194    }
195    return {
196      closeAppCalculateScaleX: closeAppCalculateScaleX,
197      closeAppCalculateScaleY: closeAppCalculateScaleY,
198      closeAppCalculateTranslateX: closeAppCalculateTranslateX,
199      closeAppCalculateTranslateY: closeAppCalculateTranslateY
200    }
201  }
202}
203
204@Component
205export struct RemoteWindowWrapper {
206  private mCloseAppManager: CloseAppManager;
207  private mLastRemoteVo: RemoteVo;
208  @StorageLink('remoteWindowList') remoteWindowList: RemoteVo[] = [];
209
210  getRemoteWindowVo(remoteWindowKey: string): RemoteVo {
211    const remoteVoIndex = this.remoteWindowList.findIndex(item => {
212      return (item.remoteWindowKey) == remoteWindowKey;
213    })
214    if (remoteVoIndex != -1) {
215      return this.remoteWindowList[remoteVoIndex];
216    } else if (this.mLastRemoteVo && this.mLastRemoteVo.remoteWindowKey === remoteWindowKey) {
217      return this.mLastRemoteVo;
218    } else {
219      return null;
220    }
221  }
222
223  private pushRemoteVoIntoList(remoteVo: RemoteVo): void {
224    const remoteVoIndex = this.remoteWindowList.findIndex(item => {
225      return (item.remoteWindowKey) == remoteVo.remoteWindowKey;
226    })
227    if (remoteVoIndex == -1) {
228      this.remoteWindowList.push(remoteVo);
229    }
230  }
231
232  aboutToAppear(): void {
233    let control = new WindowAnimationControllerImpl();
234    this.mCloseAppManager = CloseAppManager.getInstance();
235    windowAnimationManager.setController(control);
236    control.onStartAppFromLauncher = (startingWindowTarget, finishCallback) => {
237      Log.showInfo(TAG, `remote window animaion onStartAppFromLauncher`);
238      const remoteWindowKey = startingWindowTarget.bundleName + startingWindowTarget.abilityName + startingWindowTarget.missionId;
239      const startAppTypeFromPageDesktop: number = AppStorage.Get('startAppTypeFromPageDesktop');
240      const appItemInfo: any = AppStorage.Get('startAppItemInfo');
241      const startAppIconInfo: any = AppStorage.Get('startAppIconInfo');
242      let remoteVo: RemoteVo | null = this.getRemoteWindowVo(remoteWindowKey);
243      if (remoteVo) {
244        remoteVo.remoteAnimationType = RemoteConstants.TYPE_START_APP_FROM_LAUNCHER;
245        remoteVo.target = startingWindowTarget;
246        remoteVo.startAppTypeFromPageDesktop = startAppTypeFromPageDesktop;
247        remoteVo.iconInfo = startAppIconInfo;
248        remoteVo.appItemInfo = appItemInfo;
249        remoteVo.count = remoteVo.count + 1;
250      } else {
251        remoteVo = new RemoteVo(
252          RemoteConstants.TYPE_START_APP_FROM_LAUNCHER,
253          startAppTypeFromPageDesktop,
254          startingWindowTarget,
255          startAppIconInfo,
256          appItemInfo,
257          undefined,
258          finishCallback
259        );
260        this.mLastRemoteVo = remoteVo;
261      }
262      this.pushRemoteVoIntoList(remoteVo);
263      AppStorage.SetOrCreate(remoteWindowKey, remoteVo.count);
264      this.calculateAppProperty(remoteVo, finishCallback);
265    }
266
267    control.onStartAppFromRecent = (startingWindowTarget, finishCallback) => {
268      Log.showInfo(TAG, `remote window animaion onStartAppFromRecent`);
269      const remoteWindowKey = startingWindowTarget.bundleName + startingWindowTarget.abilityName + startingWindowTarget.missionId;
270      const startAppTypeFromPageDesktop: number = AppStorage.Get('startAppTypeFromPageDesktop');
271      const appItemInfo: any = AppStorage.Get('startAppItemInfo');
272      const startAppIconInfo: any = AppStorage.Get('startAppIconInfo');
273      let remoteVo: RemoteVo | null = this.getRemoteWindowVo(remoteWindowKey);
274      if (remoteVo) {
275        remoteVo.remoteAnimationType = RemoteConstants.TYPE_START_APP_FROM_LAUNCHER;
276        remoteVo.target = startingWindowTarget;
277        remoteVo.startAppTypeFromPageDesktop = startAppTypeFromPageDesktop;
278        remoteVo.iconInfo = startAppIconInfo;
279        remoteVo.appItemInfo = appItemInfo;
280        remoteVo.count = remoteVo.count + 1;
281      } else {
282        remoteVo = new RemoteVo(
283          RemoteConstants.TYPE_START_APP_FROM_LAUNCHER,
284          startAppTypeFromPageDesktop,
285          startingWindowTarget,
286          startAppIconInfo,
287          appItemInfo,
288          undefined,
289          finishCallback
290        );
291        this.mLastRemoteVo = remoteVo;
292      }
293      this.pushRemoteVoIntoList(remoteVo);
294      AppStorage.SetOrCreate(remoteWindowKey, remoteVo.count);
295      this.calculateAppProperty(remoteVo, finishCallback);
296    }
297
298    control.onStartAppFromOther = (startingWindowTarget, finishCallback) => {
299      Log.showInfo(TAG, `remote window animaion onStartAppFromOther`);
300      const remoteWindowKey = startingWindowTarget.bundleName + startingWindowTarget.abilityName + startingWindowTarget.missionId;
301      const startAppTypeFromPageDesktop: number = AppStorage.Get('startAppTypeFromPageDesktop');
302      const appItemInfo: any = AppStorage.SetOrCreate('startAppItemInfo', {});
303      const startAppIconInfo: any = AppStorage.SetOrCreate('startAppIconInfo', {});
304      let remoteVo: RemoteVo | null = this.getRemoteWindowVo(remoteWindowKey);
305      if (remoteVo) {
306        remoteVo.remoteAnimationType = RemoteConstants.TYPE_START_APP_FROM_LAUNCHER;
307        remoteVo.target = startingWindowTarget;
308        remoteVo.startAppTypeFromPageDesktop = startAppTypeFromPageDesktop;
309        remoteVo.iconInfo = startAppIconInfo;
310        remoteVo.appItemInfo = appItemInfo;
311        remoteVo.count = remoteVo.count + 1;
312      } else {
313        remoteVo = new RemoteVo(
314          RemoteConstants.TYPE_START_APP_FROM_LAUNCHER,
315          startAppTypeFromPageDesktop,
316          startingWindowTarget,
317          startAppIconInfo,
318          appItemInfo,
319          undefined,
320          finishCallback
321        );
322        this.mLastRemoteVo = remoteVo;
323      }
324      this.pushRemoteVoIntoList(remoteVo);
325      AppStorage.SetOrCreate(remoteWindowKey, remoteVo.count);
326      this.calculateAppProperty(remoteVo, finishCallback);
327    }
328
329    control.onAppTransition = (fromWindowTarget, toWindowTarget, finishCallback) => {
330      Log.showInfo(TAG, `remote window animaion onAppTransition`);
331      const remoteWindowKey = toWindowTarget.bundleName + toWindowTarget.abilityName + toWindowTarget.missionId;
332      const startAppTypeFromPageDesktop: number = AppStorage.Get('startAppTypeFromPageDesktop');
333      const remoteVo = new RemoteVo(
334        RemoteConstants.TYPE_APP_TRANSITION,
335        startAppTypeFromPageDesktop,
336        toWindowTarget,
337        {},
338        {},
339        fromWindowTarget,
340        finishCallback
341      );
342      this.mLastRemoteVo = remoteVo;
343      this.pushRemoteVoIntoList(remoteVo);
344      this.calculateAppProperty(remoteVo, finishCallback);
345    }
346
347    control.onMinimizeWindow = (minimizingWindowTarget, finishCallback) => {
348      Log.showInfo(TAG, `remote window animaion onMinimizeWindow`);
349      const startAppTypeFromPageDesktop: number = AppStorage.Get('startAppTypeFromPageDesktop');
350      const appInfo: {iconInfo: any, appItemInfo: any} = this.mCloseAppManager.getAppInfo(minimizingWindowTarget);
351      const remoteWindowKey = minimizingWindowTarget.bundleName + minimizingWindowTarget.abilityName + minimizingWindowTarget.missionId;
352      let remoteVo: RemoteVo | null = this.getRemoteWindowVo(remoteWindowKey);
353      if (appInfo.appItemInfo?.page) {
354        AppStorage.SetOrCreate('pageIndex', appInfo.appItemInfo?.page);
355      }
356      if (remoteVo) {
357        remoteVo.remoteAnimationType = RemoteConstants.TYPE_MINIMIZE_WINDOW;
358        remoteVo.target = minimizingWindowTarget;
359        remoteVo.startAppTypeFromPageDesktop = startAppTypeFromPageDesktop;
360        remoteVo.iconInfo = appInfo.iconInfo;
361        remoteVo.appItemInfo = appInfo.appItemInfo;
362        remoteVo.count = remoteVo.count + 1;
363      } else {
364        remoteVo = new RemoteVo(
365          RemoteConstants.TYPE_MINIMIZE_WINDOW,
366          startAppTypeFromPageDesktop,
367          minimizingWindowTarget,
368          appInfo.iconInfo,
369          appInfo.appItemInfo,
370          undefined,
371          finishCallback
372        );
373        this.mLastRemoteVo = remoteVo;
374      }
375      this.pushRemoteVoIntoList(remoteVo);
376      AppStorage.SetOrCreate(remoteWindowKey, remoteVo.count);
377      this.calculateAppProperty(remoteVo, finishCallback);
378    }
379
380    control.onCloseWindow = (closingWindowTarget, finishCallback) => {
381      Log.showInfo(TAG, `remote window animaion onCloseWindow`);
382      const startAppTypeFromPageDesktop: number = AppStorage.Get('startAppTypeFromPageDesktop');
383      const appInfo: {iconInfo: any, appItemInfo: any} = this.mCloseAppManager.getAppInfo(closingWindowTarget);
384      const remoteWindowKey = closingWindowTarget.bundleName + closingWindowTarget.abilityName + closingWindowTarget.missionId;
385      let remoteVo: RemoteVo | null = this.getRemoteWindowVo(remoteWindowKey);
386      if (remoteVo) {
387        remoteVo.remoteAnimationType = RemoteConstants.TYPE_MINIMIZE_WINDOW;
388        remoteVo.target = closingWindowTarget;
389        remoteVo.startAppTypeFromPageDesktop = startAppTypeFromPageDesktop;
390        remoteVo.iconInfo = appInfo.iconInfo;
391        remoteVo.appItemInfo = appInfo.appItemInfo;
392      } else {
393        remoteVo = new RemoteVo(
394          RemoteConstants.TYPE_MINIMIZE_WINDOW,
395          startAppTypeFromPageDesktop,
396          closingWindowTarget,
397          appInfo.iconInfo,
398          appInfo.appItemInfo,
399          undefined,
400          finishCallback
401        );
402        this.mLastRemoteVo = remoteVo;
403      }
404      this.pushRemoteVoIntoList(remoteVo);
405      AppStorage.SetOrCreate(remoteWindowKey, remoteVo.count);
406      this.calculateAppProperty(remoteVo, finishCallback);
407    }
408  }
409
410  removeRemoteWindowFromList(remoteWindowKey: string): void {
411    const remoteWindowIndex = this.remoteWindowList.findIndex(item => {
412      return item.remoteWindowKey === remoteWindowKey;
413    });
414    if (remoteWindowIndex != CommonConstants.INVALID_VALUE) {
415      this.remoteWindowList.splice(remoteWindowIndex, 1);
416      Log.showDebug(TAG, `removeRemoteWindowFromList remoteWindowList length: ${this.remoteWindowList.length}`);
417    }
418  }
419
420  calculateAppProperty(remoteVo: RemoteVo, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback) {
421    Log.showDebug(TAG, `calculateAppProperty ${remoteVo.remoteAnimationType}`);
422    if (remoteVo.remoteAnimationType == RemoteConstants.TYPE_START_APP_FROM_LAUNCHER) {
423      Trace.start(Trace.CORE_METHOD_START_APP_ANIMATION);
424      const callback = Object.assign(finishCallback);
425      const count = remoteVo.count;
426      localEventManager.sendLocalEventSticky(EventConstants.EVENT_ANIMATION_START_APPLICATION, null);
427      animateTo({
428        duration: 50,
429        delay: 50,
430        curve: Curve.Friction,
431        onFinish: () => {
432        }
433      }, () => {
434        remoteVo.startAppIconWindowAlpha = 0.0;
435        remoteVo.remoteWindowWindowAlpha = 1.0;
436      })
437
438      animateTo({
439        duration: 370,
440        // @ts-ignore
441        curve: curves.springMotion(0.25, 0.99, 0),
442        onFinish: () => {
443          callback.onAnimationFinish();
444          Trace.end(Trace.CORE_METHOD_START_APP_ANIMATION);
445          const startCount: number = AppStorage.Get(remoteVo.remoteWindowKey);
446          Log.showDebug(TAG, `calculateAppProperty ${remoteVo.remoteAnimationType}, count: ${count}, startCount: ${startCount}`);
447          if (startCount === count) {
448            this.removeRemoteWindowFromList(remoteVo.remoteWindowKey);
449            AppStorage.SetOrCreate(remoteVo.remoteWindowKey, 0);
450          }
451        }
452      }, () => {
453        remoteVo.remoteWindowScaleX = 1.0;
454        remoteVo.remoteWindowScaleY = 1.0;
455        remoteVo.remoteWindowTranslateX = 0.0;
456        remoteVo.remoteWindowTranslateY = 0.0;
457        remoteVo.startAppIconScaleX = remoteVo.mScreenWidth / remoteVo.iconInfo?.appIconSize;
458        remoteVo.startAppIconTranslateX = remoteVo.mScreenWidth / 2 - remoteVo.iconInfo?.appIconPositionX - remoteVo.iconInfo?.appIconSize / 2;
459        remoteVo.remoteWindowRadius = 0;
460        if (remoteVo.startAppTypeFromPageDesktop === CommonConstants.OVERLAY_TYPE_CARD) {
461          remoteVo.startAppIconScaleY = remoteVo.mScreenHeight / remoteVo.iconInfo?.appIconHeight;
462          remoteVo.startAppIconTranslateY = remoteVo.mScreenHeight / 2 + px2vp(remoteVo.target.windowBounds.top) - remoteVo.iconInfo?.appIconPositionY - remoteVo.iconInfo?.appIconHeight / 2;
463        } else {
464          remoteVo.startAppIconScaleY = remoteVo.mScreenHeight / remoteVo.iconInfo?.appIconSize;
465          remoteVo.startAppIconTranslateY = remoteVo.mScreenHeight / 2 + px2vp(remoteVo.target.windowBounds.top) - remoteVo.iconInfo?.appIconPositionY - remoteVo.iconInfo?.appIconSize / 2;
466        }
467      })
468    } else if (remoteVo.remoteAnimationType  == RemoteConstants.TYPE_MINIMIZE_WINDOW) {
469      Trace.start(Trace.CORE_METHOD_CLOSE_APP_ANIMATION);
470      const res = remoteVo.calculateCloseAppProperty();
471      const callback = Object.assign(finishCallback);
472      const count = remoteVo.count;
473      localEventManager.sendLocalEventSticky(EventConstants.EVENT_ANIMATION_CLOSE_APPLICATION, null);
474      animateTo({
475        duration: 370,
476        // @ts-ignore
477        curve: curves.springMotion(0.25, 0.99, 0),
478        onFinish: () => {
479          callback.onAnimationFinish();
480          Trace.end(Trace.CORE_METHOD_CLOSE_APP_ANIMATION);
481          const startCount: number = AppStorage.Get(remoteVo.remoteWindowKey);
482          Log.showDebug(TAG, `calculateAppProperty ${remoteVo.remoteAnimationType}, count: ${count}, startCount: ${startCount}`);
483          if (startCount === count) {
484            this.removeRemoteWindowFromList(remoteVo.remoteWindowKey);
485            AppStorage.SetOrCreate(remoteVo.remoteWindowKey, 0);
486          }
487        }
488      }, () => {
489        remoteVo.remoteWindowScaleX = 1 / res.closeAppCalculateScaleX;
490        remoteVo.remoteWindowScaleY = 1 / res.closeAppCalculateScaleY;
491        remoteVo.remoteWindowTranslateX = res.closeAppCalculateTranslateX;
492        remoteVo.remoteWindowTranslateY = res.closeAppCalculateTranslateY;
493
494        remoteVo.startAppIconScaleX = 1.0;
495        remoteVo.startAppIconScaleY = 1.0;
496        remoteVo.startAppIconTranslateX = 0.0;
497        remoteVo.startAppIconTranslateY = 0.0;
498        remoteVo.remoteWindowRadius = 96;
499      })
500
501      animateTo({
502        duration: 50,
503        delay: 50,
504        curve: Curve.Friction,
505        onFinish: () => {
506        }
507      }, () => {
508        remoteVo.startAppIconWindowAlpha = 1.0;
509        remoteVo.remoteWindowWindowAlpha = 0;
510      })
511    } else if (remoteVo.remoteAnimationType  == RemoteConstants.TYPE_CLOSE_WINDOW) {
512    } else if (remoteVo.remoteAnimationType  == RemoteConstants.TYPE_APP_TRANSITION) {
513      const callback = Object.assign(finishCallback);
514      animateTo({
515        duration: 300,
516        curve: Curve.Friction,
517        onFinish: () => {
518          this.removeRemoteWindowFromList(remoteVo.remoteWindowKey);
519        }
520      }, () => {
521        remoteVo.remoteWindowRadius = 0;
522        remoteVo.remoteWindowTranslateX = 0;
523        remoteVo.fromRemoteWindowTranslateX = px2vp(remoteVo.fromWindowTarget?.windowBounds.left - remoteVo.fromWindowTarget?.windowBounds.width);
524      })
525
526      animateTo({
527        duration: 150,
528        curve: Curve.Friction,
529        onFinish: () => {
530          this.removeRemoteWindowFromList(remoteVo.remoteWindowKey);
531        }
532      }, () => {
533        remoteVo.remoteWindowScaleX = 0.9
534        remoteVo.remoteWindowScaleY = 0.9
535        remoteVo.fromRemoteWindowScaleX = 0.9
536        remoteVo.fromRemoteWindowScaleY = 0.9
537      })
538
539      animateTo({
540        duration: 350,
541        delay: 150,
542        curve: Curve.Friction,
543        onFinish: () => {
544          callback.onAnimationFinish();
545          this.removeRemoteWindowFromList(remoteVo.remoteWindowKey);
546        }
547      }, () => {
548        remoteVo.remoteWindowScaleX = 1.0
549        remoteVo.remoteWindowScaleY = 1.0
550        remoteVo.fromRemoteWindowScaleX = 1.0
551        remoteVo.fromRemoteWindowScaleY = 1.0
552      })
553    }
554  }
555
556  build() {
557    Stack() {
558      ForEach(this.remoteWindowList, (item) => {
559        if (item.remoteAnimationType == RemoteConstants.TYPE_APP_TRANSITION) {
560          StartAppTransitionRemoteWindow({
561            targetInfo: item
562          })
563        } else {
564          StartAppFromLauncherRemoteWindow({
565            targetInfo: item
566          })
567        }
568      }, (item) => item.remoteWindowKey)
569    }
570    .width(StyleConstants.PERCENTAGE_100)
571    .height(StyleConstants.PERCENTAGE_100)
572    .focusable(false)
573    .enabled(false)
574  }
575}
576
577@Component
578export struct StartAppFromLauncherRemoteWindow {
579  @ObjectLink targetInfo: RemoteVo;
580
581  aboutToAppear(): void {
582  }
583
584  aboutToDisappear(): void {
585  }
586
587  build() {
588    Stack() {
589      Column() {
590        if (this.targetInfo.startAppTypeFromPageDesktop === CommonConstants.OVERLAY_TYPE_CARD) {
591          FormComponent({
592            id: this.targetInfo.appItemInfo?.cardId,
593            name: this.targetInfo.appItemInfo?.cardName,
594            bundle: this.targetInfo.appItemInfo?.bundleName,
595            ability: this.targetInfo.appItemInfo?.abilityName,
596            module: this.targetInfo.appItemInfo?.moduleName,
597            dimension: this.targetInfo.appItemInfo?.cardDimension
598          })
599            .clip(new Rect({
600              width: this.targetInfo.iconInfo?.appIconSize,
601              height: this.targetInfo.iconInfo?.appIconHeight,
602              radius: 24
603            }))
604            .size({ width: this.targetInfo.iconInfo?.appIconSize, height: this.targetInfo.iconInfo?.appIconHeight })
605        } else {
606          OverlayAppIcon({
607            iconSize: this.targetInfo.iconInfo?.appIconSize,
608            icon: this.targetInfo.appItemInfo?.icon
609          })
610        }
611      }
612      .translate({ x: this.targetInfo.startAppIconTranslateX, y: this.targetInfo.startAppIconTranslateY })
613      .scale({ x: this.targetInfo.startAppIconScaleX, y: this.targetInfo.startAppIconScaleY })
614      .opacity(this.targetInfo.startAppIconWindowAlpha)
615      .position({
616        x: this.targetInfo.iconInfo?.appIconPositionX,
617        y: this.targetInfo.iconInfo?.appIconPositionY,
618      })
619
620      RemoteWindow(this.targetInfo.target)
621        .translate({ x: this.targetInfo.remoteWindowTranslateX, y: this.targetInfo.remoteWindowTranslateY })
622        .scale({ x: this.targetInfo.remoteWindowScaleX, y: this.targetInfo.remoteWindowScaleY })
623        .opacity(this.targetInfo.remoteWindowWindowAlpha)
624        .position({ x: px2vp(this.targetInfo.target?.windowBounds.left), y: px2vp(this.targetInfo.target?.windowBounds.top) })
625        .width(px2vp(this.targetInfo.target?.windowBounds.width))
626        .height(px2vp(this.targetInfo.target?.windowBounds.height))
627        .borderRadius(this.targetInfo.remoteWindowRadius)
628    }
629    .width(StyleConstants.PERCENTAGE_100)
630    .height(StyleConstants.PERCENTAGE_100)
631    .focusable(false)
632    .enabled(false)
633  }
634}
635
636@Component
637export struct StartAppTransitionRemoteWindow {
638  @ObjectLink targetInfo: RemoteVo;
639  private target: windowAnimationManager.WindowAnimationTarget;
640  private mFromWindowTarget: windowAnimationManager.WindowAnimationTarget = undefined;
641  private remoteAnimationType: number = 0;
642  private startAppTypeFromPageDesktop: number = 1;
643  private mScreenWidth: number = 0;
644  private mScreenHeight: number = 0;
645  private startAppIconInfo: {
646    appIconSize: number,
647    appIconHeight: number,
648    appIconPositionX: number,
649    appIconPositionY: number
650  } =
651    { appIconSize: 0,
652      appIconHeight: 0,
653      appIconPositionX: 0,
654      appIconPositionY: 0 };
655  private mStartAppItemInfo: any = {};
656  private mFinishCallback: windowAnimationManager.WindowAnimationFinishedCallback;
657  private remoteWindowKey: string;
658
659  aboutToAppear(): void  {
660    this.target = this.targetInfo.target;
661    this.mFromWindowTarget = this.targetInfo.fromWindowTarget;
662    this.mFinishCallback = this.targetInfo.finishCallback;
663    this.remoteWindowKey = this.targetInfo.remoteWindowKey;
664    this.mStartAppItemInfo = this.targetInfo.appItemInfo;
665    this.mScreenWidth = px2vp(this.target.windowBounds.width);
666    this.mScreenHeight = px2vp(this.target.windowBounds.height);
667  }
668
669  aboutToDisappear() {
670  }
671
672  build() {
673    Stack() {
674      Column() {
675        RemoteWindow(this.targetInfo.target)
676          .position({ x: px2vp(this.target?.windowBounds.left), y: px2vp(this.target?.windowBounds.top) })
677          .width(px2vp(this.target?.windowBounds.width))
678          .height(px2vp(this.target?.windowBounds.height))
679          .translate({ x: this.targetInfo.remoteWindowTranslateX, y: this.targetInfo.remoteWindowTranslateY })
680          .scale({ x: this.targetInfo.remoteWindowScaleX, y: this.targetInfo.remoteWindowScaleY })
681          .opacity(this.targetInfo.remoteWindowWindowAlpha)
682          .borderRadius(this.targetInfo.remoteWindowRadius)
683
684        RemoteWindow(this.mFromWindowTarget)
685          .translate({ x: this.targetInfo.fromRemoteWindowTranslateX, y: this.targetInfo.fromRemoteWindowTranslateY })
686          .scale({ x: this.targetInfo.fromRemoteWindowScaleX, y: this.targetInfo.fromRemoteWindowScaleY })
687          .opacity(this.targetInfo.fromRemoteWindowWindowAlpha)
688          .position({
689            x: px2vp(this.mFromWindowTarget?.windowBounds.left),
690            y: px2vp(this.mFromWindowTarget?.windowBounds.top)
691          })
692          .width(px2vp(this.mFromWindowTarget?.windowBounds.width))
693          .height(px2vp(this.mFromWindowTarget?.windowBounds.height))
694          .borderRadius(this.targetInfo.remoteWindowRadius)
695      }
696      .width(StyleConstants.PERCENTAGE_100)
697      .height(StyleConstants.PERCENTAGE_100)
698      .focusable(false)
699      .enabled(false)
700    }
701  }
702}