• 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 */
15import Prompt from '@ohos.promptAction';
16import windowAnimationManager from '@ohos.animation.windowAnimationManager';
17import { CheckEmptyUtils } from '../../utils/CheckEmptyUtils';
18import { Log } from '../../utils/Log';
19import RemoteConstants from '../../constants/RemoteConstants';
20
21const TAG = 'WindowAnimationControllerImpl';
22
23class WindowAnimationControllerImpl implements windowAnimationManager.WindowAnimationController {
24  onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget,
25                         finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void
26  {
27    Log.showInfo(TAG, `remote window animaion onStartAppFromLauncher`);
28    this.setRemoteAnimation(startingWindowTarget, null, finishCallback, RemoteConstants.TYPE_START_APP_FROM_LAUNCHER);
29    this.printfTarget(startingWindowTarget);
30    finishCallback.onAnimationFinish();
31  }
32
33  onStartAppFromRecent(startingWindowTarget: windowAnimationManager.WindowAnimationTarget,
34                       finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
35    Log.showInfo(TAG, `remote window animaion onStartAppFromRecent`);
36    this.setRemoteAnimation(startingWindowTarget, null, finishCallback, RemoteConstants.TYPE_START_APP_FROM_RECENT);
37    this.printfTarget(startingWindowTarget);
38    finishCallback.onAnimationFinish();
39  }
40
41  onStartAppFromOther(startingWindowTarget: windowAnimationManager.WindowAnimationTarget,
42                      finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
43    Log.showInfo(TAG, `remote window animaion onStartAppFromOther`);
44    this.setRemoteAnimation(startingWindowTarget, null, finishCallback, RemoteConstants.TYPE_START_APP_FROM_OTHER);
45    this.printfTarget(startingWindowTarget);
46    finishCallback.onAnimationFinish();
47  }
48
49  onAppTransition(fromWindowTarget: windowAnimationManager.WindowAnimationTarget,
50                  toWindowTarget: windowAnimationManager.WindowAnimationTarget,
51                  finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void{
52    Log.showInfo(TAG, `remote window animaion onAppTransition`);
53    this.setRemoteAnimation(toWindowTarget, fromWindowTarget, finishCallback, RemoteConstants.TYPE_APP_TRANSITION);
54    this.printfTarget(fromWindowTarget);
55    this.printfTarget(toWindowTarget);
56    finishCallback.onAnimationFinish();
57  }
58
59  onMinimizeWindow(minimizingWindowTarget: windowAnimationManager.WindowAnimationTarget,
60                   finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
61    Log.showInfo(TAG, `remote window animaion onMinimizeWindow`);
62    this.setRemoteAnimation(null, minimizingWindowTarget, finishCallback, RemoteConstants.TYPE_MINIMIZE_WINDOW);
63    this.printfTarget(minimizingWindowTarget);
64    finishCallback.onAnimationFinish();
65  }
66
67  onCloseWindow(closingWindowTarget: windowAnimationManager.WindowAnimationTarget,
68                finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
69    Log.showInfo(TAG, `remote window animaion onCloseWindow`);
70    this.setRemoteAnimation(null, closingWindowTarget, finishCallback, RemoteConstants.TYPE_CLOSE_WINDOW);
71    this.printfTarget(closingWindowTarget);
72    finishCallback.onAnimationFinish();
73  }
74
75  onScreenUnlock(finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
76    Log.showInfo(TAG, `remote window animaion onScreenUnlock`);
77    this.setRemoteAnimation(null, null, finishCallback, RemoteConstants.TYPE_SCREEN_UNLOCK);
78    finishCallback.onAnimationFinish();
79  }
80
81  onWindowAnimationTargetsUpdate(fullScreenWindowTarget: windowAnimationManager.WindowAnimationTarget, floatingWindowTargets: Array<windowAnimationManager.WindowAnimationTarget>): void {}
82
83  printfTarget(target: windowAnimationManager.WindowAnimationTarget): void {
84    if (CheckEmptyUtils.isEmpty(target) || CheckEmptyUtils.isEmpty(target.windowBounds)) {
85      Log.showInfo(TAG, `remote window animaion with invalid target`);
86      return;
87    }
88    Log.showInfo(TAG, `remote window animaion bundleName: ${target.bundleName} abilityName: ${target.abilityName}`);
89    Log.showInfo(TAG, `remote window animaion windowBounds left: ${target.windowBounds.left} top: ${target.windowBounds.top}
90      width: ${target.windowBounds.width} height: ${target.windowBounds.height} radius: ${target.windowBounds.radius}`);
91  }
92
93  private setRemoteAnimation(startingWindowTarget: windowAnimationManager.WindowAnimationTarget,
94                             closingWindowTarget: windowAnimationManager.WindowAnimationTarget,
95                             finishCallback: windowAnimationManager.WindowAnimationFinishedCallback,
96                             remoteAnimationType: number): void {
97    if (!CheckEmptyUtils.isEmpty(startingWindowTarget)) {
98      AppStorage.SetOrCreate('startingWindowTarget', startingWindowTarget);
99    }
100
101    if (!CheckEmptyUtils.isEmpty(closingWindowTarget)) {
102      AppStorage.SetOrCreate('closingWindowTarget', closingWindowTarget);
103    }
104
105    if (!CheckEmptyUtils.isEmpty(finishCallback)) {
106      AppStorage.SetOrCreate('remoteAnimationFinishCallback', finishCallback);
107    }
108
109    AppStorage.SetOrCreate('remoteAnimationType', remoteAnimationType);
110  }
111}
112
113export default WindowAnimationControllerImpl
114