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```js 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```js 36let controller = { 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<WindowAnimationFinishedCallback>): 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<[WindowAnimationFinishedCallback](#windowanimationfinishedcallback)> | 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```js 93let target: WindowAnimationTarget = undefined; 94let controller = { 95 onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 96 console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget); 97 target = startingWindowTarget; 98 finishCallback.onAnimationFinish(); 99 }, 100 onStartAppFromRecent(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 101 console.log('onStartAppFromRecent, the startingWindowTarget is: ' + startingWindowTarget); 102 target = startingWindowTarget; 103 finishCallback.onAnimationFinish(); 104 }, 105 onStartAppFromOther(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 106 console.log('onStartAppFromOther, the startingWindowTarget is: ' + startingWindowTarget); 107 target = startingWindowTarget; 108 finishCallback.onAnimationFinish(); 109 }, 110 onAppTransition(fromWindowTarget: windowAnimationManager.WindowAnimationTarget, toWindowTarget: WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 111 console.log('onAppTransition, the fromWindowTarget is: ' + fromWindowTarget); 112 console.log('onAppTransition, the toWindowTarget is: ' + toWindowTarget); 113 target = toWindowTarget; 114 finishCallback.onAnimationFinish(); 115 }, 116 onMinimizeWindow(minimizingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 117 console.log('onMinimizeWindow, the minimizingWindowTarget is: ' + minimizingWindowTarget); 118 target = minimizingWindowTarget; 119 finishCallback.onAnimationFinish(); 120 }, 121 onCloseWindow(closingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 122 console.log('onCloseWindow, the closingWindowTarget is: ' + closingWindowTarget); 123 target = closingWindowTarget; 124 finishCallback.onAnimationFinish(); 125 }, 126 onScreenUnlock(finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 127 console.log('onScreenUnlock called'); 128 finishCallback.onAnimationFinish(); 129 }, 130 onWindowAnimationTargetsUpdate(fullScreenWindowTarget: windowAnimationManager.WindowAnimationTarget, floatingWindowTargets: Array<windowAnimationManager.WindowAnimationTarget>): void { 131 console.log('onWindowAnimationTargetsUpdate, the fullScreenWindowTarget is: ' + fullScreenWindowTarget); 132 console.log('onWindowAnimationTargetsUpdate, the floatingWindowTargets are: ' + floatingWindowTargets); 133 target = fullScreenWindowTarget; 134 } 135} 136 137windowAnimationManager.setController(controller) 138 139let finishedCallback: windowAnimationManager.WindowAnimationFinishedCallback = undefined; 140windowAnimationManager.minimizeWindowWithAnimation(target, (err, data) => { 141 if (err) { 142 console.error('Failed to minimize the window target. Cause: ' + JSON.stringify(err)); 143 return; 144 } 145 finishedCallback = data; 146 147 // After the callback is received, the window starts to play the animation. After the animation is finished, the **onAnimationFinish** callback is invoked. 148 finishedCallback.onAnimationFinish(); 149}); 150``` 151 152## windowAnimationManager.minimizeWindowWithAnimation 153 154minimizeWindowWithAnimation(windowTarget: WindowAnimationTarget): Promise<WindowAnimationFinishedCallback> 155 156Minimizes the window that displays the animation. This API uses a promise to return the result. 157 158**System capability**: SystemCapability.WindowManager.WindowManager.Core 159 160**Parameters** 161 162| Name| Type| Mandatory| Description| 163| -------- | -------- | -------- | -------- | 164| windowTarget | [WindowAnimationTarget](#windowanimationtarget) | Yes| Target window to display the animation.| 165 166**Return value** 167 168| Type | Description | 169| -------------------------------- | --------------------------------------- | 170| Promise<[WindowAnimationFinishedCallback](#windowanimationfinishedcallback)> | Promise used to return a call when the animation is finished.| 171 172 173**Example** 174 175```js 176let target: WindowAnimationTarget = undefined; 177let controller = { 178 onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 179 console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget); 180 finishCallback.onAnimationFinish(); 181 }, 182 onStartAppFromRecent(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 183 console.log('onStartAppFromRecent, the startingWindowTarget is: ' + startingWindowTarget); 184 finishCallback.onAnimationFinish(); 185 }, 186 onStartAppFromOther(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 187 console.log('onStartAppFromOther, the startingWindowTarget is: ' + startingWindowTarget); 188 finishCallback.onAnimationFinish(); 189 }, 190 onAppTransition(fromWindowTarget: windowAnimationManager.WindowAnimationTarget, toWindowTarget: WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 191 console.log('onAppTransition, the fromWindowTarget is: ' + fromWindowTarget); 192 console.log('onAppTransition, the toWindowTarget is: ' + toWindowTarget); 193 finishCallback.onAnimationFinish(); 194 }, 195 onMinimizeWindow(minimizingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 196 console.log('onMinimizeWindow, the minimizingWindowTarget is: ' + minimizingWindowTarget); 197 finishCallback.onAnimationFinish(); 198 }, 199 onCloseWindow(closingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 200 console.log('onCloseWindow, the closingWindowTarget is: ' + closingWindowTarget); 201 finishCallback.onAnimationFinish(); 202 }, 203 onScreenUnlock(finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void { 204 console.log('onScreenUnlock called'); 205 finishCallback.onAnimationFinish(); 206 }, 207 onWindowAnimationTargetsUpdate(fullScreenWindowTarget: windowAnimationManager.WindowAnimationTarget, floatingWindowTargets: Array<windowAnimationManager.WindowAnimationTarget>): void { 208 console.log('onWindowAnimationTargetsUpdate, the fullScreenWindowTarget is: ' + fullScreenWindowTarget); 209 console.log('onWindowAnimationTargetsUpdate, the floatingWindowTargets are: ' + floatingWindowTargets); 210 } 211} 212 213windowAnimationManager.setController(controller) 214 215let promise = windowAnimationManager.minimizeWindowWithAnimation(target); 216promise.then((data) => { 217 data.onAnimationFinish(); 218}).catch((err)=>{ 219 console.error('Failed to minimize the window target. Cause: ' + JSON.stringify(err)); 220 return; 221}); 222``` 223 224## WindowAnimationController 225 226Implements the window animation controller. When creating a **WindowAnimationController** object, you must implement all callbacks in the object. 227 228**System capability**: SystemCapability.WindowManager.WindowManager.Core 229 230### onStartAppFromLauncher 231 232onStartAppFromLauncher(startingWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void 233 234Called when an application is started from the home screen. 235 236**System capability**: SystemCapability.WindowManager.WindowManager.Core 237 238| Name | Type | Mandatory| Description | 239| -------------------- | ------------------------------------------------------------ | ---- | ------------------ | 240| startingWindowTarget | [WindowAnimationTarget](#windowanimationtarget) | Yes | Target window to display the animation. | 241| finishCallback | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes | Callback invoked when the animation is finished.| 242 243**Example** 244 245For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller). 246 247### onStartAppFromRecent 248 249onStartAppFromRecent(startingWindowTarget: WindowAnimationTarget,finishCallback:WindowAnimationFinishedCallback): void 250 251Called when an application is started from the recent task list. 252 253**System capability**: SystemCapability.WindowManager.WindowManager.Core 254 255| Name | Type | Mandatory| Description | 256| -------------------- | ------------------------------------------------------------ | ---- | ------------------ | 257| startingWindowTarget | [WindowAnimationTarget](#windowanimationtarget) | Yes | Target window to display the animation. | 258| finishCallback | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes | Callback invoked when the animation is finished.| 259 260**Example** 261 262For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller). 263 264### onStartAppFromOther 265 266onStartAppFromOther(startingWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void 267 268Called when an application is started from a place other than the home screen and recent task list. 269 270**System capability**: SystemCapability.WindowManager.WindowManager.Core 271 272| Name | Type | Mandatory| Description | 273| -------------------- | ------------------------------------------------------------ | ---- | ------------------ | 274| startingWindowTarget | [WindowAnimationTarget](#windowanimationtarget) | Yes | Target window to display the animation. | 275| finishCallback | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes | Callback invoked when the animation is finished.| 276 277**Example** 278 279For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller). 280 281### onAppTransition 282 283onAppTransition(fromWindowTarget: WindowAnimationTarget, toWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void 284 285Called during application transition. 286 287**System capability**: SystemCapability.WindowManager.WindowManager.Core 288 289| Name | Type | Mandatory| Description | 290| -------------------- | ------------------------------- | ---- | ---------------- | 291| fromWindowTarget | [WindowAnimationTarget](#windowanimationtarget) | Yes | Window that displays the animation before the transition.| 292| toWindowTarget | [WindowAnimationTarget](#windowanimationtarget) | Yes | Window that displays the animation after the transition.| 293| finishCallback | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes | Callback invoked when the animation is finished.| 294 295**Example** 296 297For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller). 298 299### onMinimizeWindow 300 301onMinimizeWindow(minimizingWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void 302 303Called when a window is minimized. 304 305**System capability**: SystemCapability.WindowManager.WindowManager.Core 306 307| Name | Type | Mandatory| Description | 308| -------------------- | ------------------------------- | ---- | ---------------- | 309| minimizingWindowTarget | [WindowAnimationTarget](#windowanimationtarget) | Yes | Target window to display the animation. | 310| finishCallback | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes | Callback invoked when the animation is finished.| 311 312**Example** 313 314For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller). 315 316### onCloseWindow 317 318onCloseWindow(closingWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void 319 320Called when a window is closed. 321 322**System capability**: SystemCapability.WindowManager.WindowManager.Core 323 324| Name | Type | Mandatory| Description | 325| -------------------- | ------------------------------- | ---- | ---------------- | 326| closingWindowTarget | [WindowAnimationTarget](#windowanimationtarget) | Yes | Target window to display the animation. | 327| finishCallback | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes | Callback invoked when the animation is finished.| 328 329**Example** 330 331For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller). 332 333### onScreenUnlock 334 335onScreenUnlock(finishCallback: [WindowAnimationFinishedCallback](#windowanimationfinishedcallback)): void 336 337Called when the screen is unlocked. 338 339**System capability**: SystemCapability.WindowManager.WindowManager.Core 340 341| Name | Type | Mandatory| Description | 342| -------------- | ------------------------------------------------------------ | ---- | ------------------ | 343| finishCallback | [WindowAnimationFinishedCallback](#windowanimationfinishedcallback) | Yes | Callback invoked when the animation is finished.| 344 345**Example** 346 347For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller). 348 349### onWindowAnimationTargetsUpdate 350 351onWindowAnimationTargetsUpdate(fullScreenWindowTarget: WindowAnimationTarget, floatingWindowTargets: Array<WindowAnimationTarget>): void 352 353Called when the window that displays the animation is updated. 354 355**System capability**: SystemCapability.WindowManager.WindowManager.Core 356 357| Name | Type | Mandatory| Description | 358| -------------------- | ------------------------------- | ---- | ---------------- | 359| fullScreenWindowTarget | [WindowAnimationTarget](#windowanimationtarget) | Yes | Target window in full-screen mode.| 360| floatingWindowTargets| Array<[WindowAnimationTarget](#windowanimationtarget)> | Yes | Target window in the form of a floating window.| 361 362**Example** 363 364For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller). 365 366## WindowAnimationFinishedCallback 367Implements a callback that is invoked when the animation is finished. 368 369### onAnimationFinish 370 371onAnimationFinish():void 372 373Called when the animation is finished. 374 375**System capability**: SystemCapability.WindowManager.WindowManager.Core 376 377**Example** 378 379For details, see the sample code under [windowAnimationManager.setController](#windowanimationmanagersetcontroller). 380 381## WindowAnimationTarget 382Defines a window to display animation. 383 384**System capability**: SystemCapability.WindowManager.WindowManager.Core 385 386| Name | Type | Mandatory| Description| 387| ------- | ------ | ------ | ----------------------- | 388| bundleName | string | Yes|Bundle name corresponding to the target window.| 389| abilityName | string | Yes|Ability name corresponding to the target window.| 390| windowBounds | [RRect](#rrect) | Yes|Actual size of the target window.| 391| missionId | number | Yes|Mission ID, which is used to match an ability when there are multiple missions.| 392 393## RRect 394Describes a rounded rectangle. 395 396**System capability**: SystemCapability.WindowManager.WindowManager.Core 397 398| Name | Type | Mandatory| Description| 399| ------- | ------ | ------|----------------------- | 400| left | number | Yes|Horizontal coordinate of the upper left corner of the target window relative to the screen.| 401| top | number | Yes|Vertical coordinate of the upper left corner of the target window relative to the screen.| 402| width | number | Yes|Width of the target window.| 403| height | number | Yes|Height of the target window.| 404| radius | number | Yes|Radius of the rounded corner of the target window.| 405