• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.animation.windowAnimationManager (Window Animation Management)
2
3The **WindowAnimationManager** module provides APIs to listen for application start/exit events and window minimization/maximization events and associate animations with these events.
4
5>  **NOTE**
6>
7>  The APIs of this module are supported since API version 9. Updates will be marked with a superscript to indicate their earliest API version.
8>
9>  The APIs provided by this module are system APIs.
10
11## Modules to Import
12
13```ts
14import windowAnimationManager from '@ohos.animation.windowAnimationManager'
15```
16
17## windowAnimationManager.setController
18
19setController(controller: WindowAnimationController): void
20
21Sets a window animation controller. For details about the controller, see [WindowAnimationController](#windowanimationcontroller).
22
23Before using other APIs of **windowAnimationManager**, you must call this API to set a window animation controller.
24
25**System capability**: SystemCapability.WindowManager.WindowManager.Core
26
27**Parameters**
28
29| Name| Type| Mandatory| Description|
30| -------- | -------- | -------- | -------- |
31| controller | [WindowAnimationController](#windowanimationcontroller) | Yes| Window animation controller to set.|
32
33**Example**
34
35```ts
36let controller: windowAnimationManager.WindowAnimationController = {
37    onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
38        console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget);
39        finishCallback.onAnimationFinish();
40	  },
41    onStartAppFromRecent(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
42        console.log('onStartAppFromRecent, the startingWindowTarget is: ' + startingWindowTarget);
43        finishCallback.onAnimationFinish();
44    },
45    onStartAppFromOther(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
46        console.log('onStartAppFromOther, the startingWindowTarget is: ' + startingWindowTarget);
47        finishCallback.onAnimationFinish();
48    },
49    onAppTransition(fromWindowTarget: windowAnimationManager.WindowAnimationTarget, toWindowTarget: WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
50        console.log('onAppTransition, the fromWindowTarget is: ' + fromWindowTarget);
51        console.log('onAppTransition, the toWindowTarget is: ' + toWindowTarget);
52        finishCallback.onAnimationFinish();
53    },
54    onMinimizeWindow(minimizingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
55        console.log('onMinimizeWindow, the minimizingWindowTarget is: ' + minimizingWindowTarget);
56        finishCallback.onAnimationFinish();
57    },
58    onCloseWindow(closingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
59        console.log('onCloseWindow, the closingWindowTarget is: ' + closingWindowTarget);
60        finishCallback.onAnimationFinish();
61    },
62    onScreenUnlock(finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
63        console.log('onScreenUnlock called');
64        finishCallback.onAnimationFinish();
65    },
66    onWindowAnimationTargetsUpdate(fullScreenWindowTarget: windowAnimationManager.WindowAnimationTarget, floatingWindowTargets: Array<windowAnimationManager.WindowAnimationTarget>): void {
67        console.log('onWindowAnimationTargetsUpdate, the fullScreenWindowTarget is: ' + fullScreenWindowTarget);
68        console.log('onWindowAnimationTargetsUpdate, the floatingWindowTargets are: ' + floatingWindowTargets);
69    }
70}
71
72windowAnimationManager.setController(controller);
73```
74
75## windowAnimationManager.minimizeWindowWithAnimation
76
77minimizeWindowWithAnimation(windowTarget: WindowAnimationTarget, callback: AsyncCallback&lt;WindowAnimationFinishedCallback&gt;): void
78
79Minimizes the window that displays the animation. This API uses an asynchronous callback to return the result.
80
81**System capability**: SystemCapability.WindowManager.WindowManager.Core
82
83**Parameters**
84
85| Name| Type| Mandatory| Description|
86| -------- | -------- | -------- | -------- |
87| windowTarget | [WindowAnimationTarget](#windowanimationtarget) | Yes| Target window to minimize.|
88| callback | AsyncCallback&lt;[WindowAnimationFinishedCallback](#windowanimationfinishedcallback)&gt; | Yes| Callback used to return the result. If the target window is minimized, **err** is **undefined** and **data** is the **WindowAnimationFinishedCallback** obtained; otherwise, **err.code** is **-1** and **data** is **undefined**.|
89
90**Example**
91
92```ts
93import {BusinessError} from '@ohos.base';
94
95let target: windowAnimationManager.WindowAnimationTarget | null = null;
96let controller: windowAnimationManager.WindowAnimationController = {
97    onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
98        console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget);
99        target = startingWindowTarget;
100        finishCallback.onAnimationFinish();
101	  },
102    onStartAppFromRecent(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
103        console.log('onStartAppFromRecent, the startingWindowTarget is: ' + startingWindowTarget);
104        target = startingWindowTarget;
105        finishCallback.onAnimationFinish();
106    },
107    onStartAppFromOther(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
108        console.log('onStartAppFromOther, the startingWindowTarget is: ' + startingWindowTarget);
109        target = startingWindowTarget;
110        finishCallback.onAnimationFinish();
111    },
112    onAppTransition(fromWindowTarget: windowAnimationManager.WindowAnimationTarget, toWindowTarget: WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
113        console.log('onAppTransition, the fromWindowTarget is: ' + fromWindowTarget);
114        console.log('onAppTransition, the toWindowTarget is: ' + toWindowTarget);
115        target = toWindowTarget;
116        finishCallback.onAnimationFinish();
117    },
118    onMinimizeWindow(minimizingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
119        console.log('onMinimizeWindow, the minimizingWindowTarget is: ' + minimizingWindowTarget);
120        target = minimizingWindowTarget;
121        finishCallback.onAnimationFinish();
122    },
123    onCloseWindow(closingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
124        console.log('onCloseWindow, the closingWindowTarget is: ' + closingWindowTarget);
125        target = closingWindowTarget;
126        finishCallback.onAnimationFinish();
127    },
128    onScreenUnlock(finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
129        console.log('onScreenUnlock called');
130        finishCallback.onAnimationFinish();
131    },
132    onWindowAnimationTargetsUpdate(fullScreenWindowTarget: windowAnimationManager.WindowAnimationTarget, floatingWindowTargets: Array<windowAnimationManager.WindowAnimationTarget>): void {
133        console.log('onWindowAnimationTargetsUpdate, the fullScreenWindowTarget is: ' + fullScreenWindowTarget);
134        console.log('onWindowAnimationTargetsUpdate, the floatingWindowTargets are: ' + floatingWindowTargets);
135        target = fullScreenWindowTarget;
136    }
137}
138
139windowAnimationManager.setController(controller);
140
141let finishedCallback: windowAnimationManager.WindowAnimationFinishedCallback;
142windowAnimationManager.minimizeWindowWithAnimation(target, (err: BusinessError, data: windowAnimationManager.WindowAnimationFinishedCallback) => {
143    if (err) {
144        console.error('Failed to minimize the window target. Cause: ' + JSON.stringify(err));
145        return;
146    }
147    finishedCallback = data;
148
149    // After the callback is received, the window starts to play the animation. After the animation is finished, the **onAnimationFinish** callback is invoked.
150    finishedCallback.onAnimationFinish();
151});
152```
153
154## windowAnimationManager.minimizeWindowWithAnimation
155
156minimizeWindowWithAnimation(windowTarget: WindowAnimationTarget): Promise&lt;WindowAnimationFinishedCallback&gt;
157
158Minimizes the window that displays the animation. This API uses a promise to return the result.
159
160**System capability**: SystemCapability.WindowManager.WindowManager.Core
161
162**Parameters**
163
164| Name| Type| Mandatory| Description|
165| -------- | -------- | -------- | -------- |
166| windowTarget | [WindowAnimationTarget](#windowanimationtarget) | Yes| Target window to display the animation.|
167
168**Return value**
169
170| Type                            | Description                                   |
171| -------------------------------- | --------------------------------------- |
172| Promise&lt;[WindowAnimationFinishedCallback](#windowanimationfinishedcallback)&gt; | Promise used to return a call when the animation is finished.|
173
174
175**Example**
176
177```ts
178import {BusinessError} from '@ohos.base';
179
180let target: windowAnimationManager.WindowAnimationTarget | null  = null;
181let controller: windowAnimationManager.WindowAnimationController = {
182    onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
183        console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget);
184        finishCallback.onAnimationFinish();
185	  },
186    onStartAppFromRecent(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
187        console.log('onStartAppFromRecent, the startingWindowTarget is: ' + startingWindowTarget);
188        finishCallback.onAnimationFinish();
189    },
190    onStartAppFromOther(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
191        console.log('onStartAppFromOther, the startingWindowTarget is: ' + startingWindowTarget);
192        finishCallback.onAnimationFinish();
193    },
194    onAppTransition(fromWindowTarget: windowAnimationManager.WindowAnimationTarget, toWindowTarget: WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
195        console.log('onAppTransition, the fromWindowTarget is: ' + fromWindowTarget);
196        console.log('onAppTransition, the toWindowTarget is: ' + toWindowTarget);
197        finishCallback.onAnimationFinish();
198    },
199    onMinimizeWindow(minimizingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
200        console.log('onMinimizeWindow, the minimizingWindowTarget is: ' + minimizingWindowTarget);
201        finishCallback.onAnimationFinish();
202    },
203    onCloseWindow(closingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
204        console.log('onCloseWindow, the closingWindowTarget is: ' + closingWindowTarget);
205        finishCallback.onAnimationFinish();
206    },
207    onScreenUnlock(finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
208        console.log('onScreenUnlock called');
209        finishCallback.onAnimationFinish();
210    },
211    onWindowAnimationTargetsUpdate(fullScreenWindowTarget: windowAnimationManager.WindowAnimationTarget, floatingWindowTargets: Array<windowAnimationManager.WindowAnimationTarget>): void {
212        console.log('onWindowAnimationTargetsUpdate, the fullScreenWindowTarget is: ' + fullScreenWindowTarget);
213        console.log('onWindowAnimationTargetsUpdate, the floatingWindowTargets are: ' + floatingWindowTargets);
214    }
215}
216
217windowAnimationManager.setController(controller);
218
219let promise: Promise<windowAnimationManager.WindowAnimationFinishedCallback> = windowAnimationManager.minimizeWindowWithAnimation(target);
220promise.then((data: windowAnimationManager.WindowAnimationFinishedCallback) => {
221    data.onAnimationFinish();
222}).catch((err: BusinessError)=>{
223    console.error('Failed to minimize the window target. Cause: ' + JSON.stringify(err));
224    return;
225});
226```
227
228## WindowAnimationController
229
230Implements the window animation controller. When creating a **WindowAnimationController** object, you must implement all callbacks in the object.
231
232**System capability**: SystemCapability.WindowManager.WindowManager.Core
233
234### onStartAppFromLauncher
235
236onStartAppFromLauncher(startingWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void
237
238Called when an application is started from the home screen.
239
240**System capability**: SystemCapability.WindowManager.WindowManager.Core
241
242| Name              | Type                                                        | Mandatory| Description              |
243| -------------------- | ------------------------------------------------------------ | ---- | ------------------ |
244| startingWindowTarget | [WindowAnimationTarget](#windowanimationtarget)              | Yes  | Target window to display the animation.    |
245| finishCallback       | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes  | Callback invoked when the animation is finished.|
246
247**Example**
248
249For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller).
250
251### onStartAppFromRecent
252
253onStartAppFromRecent(startingWindowTarget: WindowAnimationTarget,finishCallback:WindowAnimationFinishedCallback): void
254
255Called when an application is started from the recent task list.
256
257**System capability**: SystemCapability.WindowManager.WindowManager.Core
258
259| Name              | Type                                                        | Mandatory| Description              |
260| -------------------- | ------------------------------------------------------------ | ---- | ------------------ |
261| startingWindowTarget | [WindowAnimationTarget](#windowanimationtarget)              | Yes  | Target window to display the animation.    |
262| finishCallback       | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes  | Callback invoked when the animation is finished.|
263
264**Example**
265
266For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller).
267
268### onStartAppFromOther
269
270onStartAppFromOther(startingWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void
271
272Called when an application is started from a place other than the home screen and recent task list.
273
274**System capability**: SystemCapability.WindowManager.WindowManager.Core
275
276| Name              | Type                                                        | Mandatory| Description              |
277| -------------------- | ------------------------------------------------------------ | ---- | ------------------ |
278| startingWindowTarget | [WindowAnimationTarget](#windowanimationtarget)              | Yes  | Target window to display the animation.    |
279| finishCallback       | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes  | Callback invoked when the animation is finished.|
280
281**Example**
282
283For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller).
284
285### onAppTransition
286
287onAppTransition(fromWindowTarget: WindowAnimationTarget, toWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void
288
289Called during application transition.
290
291**System capability**: SystemCapability.WindowManager.WindowManager.Core
292
293| Name              | Type                           | Mandatory| Description            |
294| -------------------- | ------------------------------- | ---- | ---------------- |
295| fromWindowTarget | [WindowAnimationTarget](#windowanimationtarget)           | Yes  | Window that displays the animation before the transition.|
296| toWindowTarget       | [WindowAnimationTarget](#windowanimationtarget) | Yes  | Window that displays the animation after the transition.|
297| finishCallback | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes  | Callback invoked when the animation is finished.|
298
299**Example**
300
301For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller).
302
303### onMinimizeWindow
304
305onMinimizeWindow(minimizingWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void
306
307Called when a window is minimized.
308
309**System capability**: SystemCapability.WindowManager.WindowManager.Core
310
311| Name              | Type                           | Mandatory| Description            |
312| -------------------- | ------------------------------- | ---- | ---------------- |
313| minimizingWindowTarget | [WindowAnimationTarget](#windowanimationtarget)           | Yes  | Target window to display the animation.   |
314| finishCallback       | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes  | Callback invoked when the animation is finished.|
315
316**Example**
317
318For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller).
319
320### onCloseWindow
321
322onCloseWindow(closingWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void
323
324Called when a window is closed.
325
326**System capability**: SystemCapability.WindowManager.WindowManager.Core
327
328| Name              | Type                           | Mandatory| Description            |
329| -------------------- | ------------------------------- | ---- | ---------------- |
330| closingWindowTarget | [WindowAnimationTarget](#windowanimationtarget)           | Yes  | Target window to display the animation.   |
331| finishCallback       | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes  | Callback invoked when the animation is finished.|
332
333**Example**
334
335For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller).
336
337### onScreenUnlock
338
339onScreenUnlock(finishCallback: [WindowAnimationFinishedCallback](#windowanimationfinishedcallback)): void
340
341Called when the screen is unlocked.
342
343**System capability**: SystemCapability.WindowManager.WindowManager.Core
344
345| Name        | Type                                                        | Mandatory| Description              |
346| -------------- | ------------------------------------------------------------ | ---- | ------------------ |
347| finishCallback | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes  | Callback invoked when the animation is finished.|
348
349**Example**
350
351For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller).
352
353### onWindowAnimationTargetsUpdate
354
355onWindowAnimationTargetsUpdate(fullScreenWindowTarget: WindowAnimationTarget, floatingWindowTargets: Array&lt;WindowAnimationTarget&gt;): void
356
357Called when the window that displays the animation is updated.
358
359**System capability**: SystemCapability.WindowManager.WindowManager.Core
360
361| Name              | Type                           | Mandatory| Description            |
362| -------------------- | ------------------------------- | ---- | ---------------- |
363| fullScreenWindowTarget | [WindowAnimationTarget](#windowanimationtarget) | Yes  | Target window in full-screen mode.|
364| floatingWindowTargets| Array&lt;[WindowAnimationTarget](#windowanimationtarget)&gt; | Yes  | Target window in the form of a floating window.|
365
366**Example**
367
368For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller).
369
370## WindowAnimationFinishedCallback
371Implements a callback that is invoked when the animation is finished.
372
373### onAnimationFinish
374
375onAnimationFinish():void
376
377Called when the animation is finished.
378
379**System capability**: SystemCapability.WindowManager.WindowManager.Core
380
381**Example**
382
383For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller).
384
385## WindowAnimationTarget
386Defines a window to display animation.
387
388**System capability**: SystemCapability.WindowManager.WindowManager.Core
389
390| Name     | Type    | Mandatory| Description|
391| ------- | ------ | ------ | ----------------------- |
392| bundleName  | string | Yes|Bundle name corresponding to the target window.|
393| abilityName | string | Yes|Ability name corresponding to the target window.|
394| windowBounds | [RRect](#rrect) | Yes|Actual size of the target window.|
395| missionId  | number | Yes|Mission ID, which is used to match an ability when there are multiple missions.|
396
397## RRect
398Describes a rounded rectangle.
399
400**System capability**: SystemCapability.WindowManager.WindowManager.Core
401
402| Name     | Type    | Mandatory| Description|
403| ------- | ------ | ------|----------------------- |
404| left  | number | Yes|Horizontal coordinate of the upper left corner of the target window relative to the screen.|
405| top | number | Yes|Vertical coordinate of the upper left corner of the target window relative to the screen.|
406| width | number | Yes|Width of the target window.|
407| height | number | Yes|Height of the target window.|
408| radius | number | Yes|Radius of the rounded corner of the target window.|
409