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