harmony 鸿蒙@ohos.animation.windowAnimationManager (Window Animation Management)

2022-10-28 浏览 (743)

@ohos.animation.windowAnimationManager (Window Animation Management)

The WindowAnimationManager module provides APIs to listen for application start/exit events and window minimization/maximization events and associate animations with these events.

NOTE

The APIs of this module are supported since API version 9. Updates will be marked with a superscript to indicate their earliest API version.

The APIs provided by this module are system APIs.

Modules to Import

import windowAnimationManager from '@ohos.animation.windowAnimationManager'

windowAnimationManager.setController

setController(controller: WindowAnimationController): void

Sets a window animation controller. For details about the controller, see WindowAnimationController.

Before using other APIs of windowAnimationManager, you must call this API to set a window animation controller.

System capability: SystemCapability.WindowManager.WindowManager.Core

Parameters

NameTypeMandatoryDescription
controllerWindowAnimationControllerYesWindow animation controller to set.

Example

let controller: windowAnimationManager.WindowAnimationController = {
    onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget);
        finishCallback.onAnimationFinish();
	  },
    onStartAppFromRecent(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onStartAppFromRecent, the startingWindowTarget is: ' + startingWindowTarget);
        finishCallback.onAnimationFinish();
    },
    onStartAppFromOther(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onStartAppFromOther, the startingWindowTarget is: ' + startingWindowTarget);
        finishCallback.onAnimationFinish();
    },
    onAppTransition(fromWindowTarget: windowAnimationManager.WindowAnimationTarget, toWindowTarget: WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onAppTransition, the fromWindowTarget is: ' + fromWindowTarget);
        console.log('onAppTransition, the toWindowTarget is: ' + toWindowTarget);
        finishCallback.onAnimationFinish();
    },
    onMinimizeWindow(minimizingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onMinimizeWindow, the minimizingWindowTarget is: ' + minimizingWindowTarget);
        finishCallback.onAnimationFinish();
    },
    onCloseWindow(closingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onCloseWindow, the closingWindowTarget is: ' + closingWindowTarget);
        finishCallback.onAnimationFinish();
    },
    onScreenUnlock(finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onScreenUnlock called');
        finishCallback.onAnimationFinish();
    },
    onWindowAnimationTargetsUpdate(fullScreenWindowTarget: windowAnimationManager.WindowAnimationTarget, floatingWindowTargets: Array<windowAnimationManager.WindowAnimationTarget>): void {
        console.log('onWindowAnimationTargetsUpdate, the fullScreenWindowTarget is: ' + fullScreenWindowTarget);
        console.log('onWindowAnimationTargetsUpdate, the floatingWindowTargets are: ' + floatingWindowTargets);
    }
}

windowAnimationManager.setController(controller);

windowAnimationManager.minimizeWindowWithAnimation

minimizeWindowWithAnimation(windowTarget: WindowAnimationTarget, callback: AsyncCallback<WindowAnimationFinishedCallback>): void

Minimizes the window that displays the animation. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.WindowManager.WindowManager.Core

Parameters

NameTypeMandatoryDescription
windowTargetWindowAnimationTargetYesTarget window to minimize.
callbackAsyncCallback<WindowAnimationFinishedCallback>YesCallback 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.

Example

import {BusinessError} from '@ohos.base';

let target: windowAnimationManager.WindowAnimationTarget|null = null;
let controller: windowAnimationManager.WindowAnimationController = {
    onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget);
        target = startingWindowTarget;
        finishCallback.onAnimationFinish();
	  },
    onStartAppFromRecent(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onStartAppFromRecent, the startingWindowTarget is: ' + startingWindowTarget);
        target = startingWindowTarget;
        finishCallback.onAnimationFinish();
    },
    onStartAppFromOther(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onStartAppFromOther, the startingWindowTarget is: ' + startingWindowTarget);
        target = startingWindowTarget;
        finishCallback.onAnimationFinish();
    },
    onAppTransition(fromWindowTarget: windowAnimationManager.WindowAnimationTarget, toWindowTarget: WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onAppTransition, the fromWindowTarget is: ' + fromWindowTarget);
        console.log('onAppTransition, the toWindowTarget is: ' + toWindowTarget);
        target = toWindowTarget;
        finishCallback.onAnimationFinish();
    },
    onMinimizeWindow(minimizingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onMinimizeWindow, the minimizingWindowTarget is: ' + minimizingWindowTarget);
        target = minimizingWindowTarget;
        finishCallback.onAnimationFinish();
    },
    onCloseWindow(closingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onCloseWindow, the closingWindowTarget is: ' + closingWindowTarget);
        target = closingWindowTarget;
        finishCallback.onAnimationFinish();
    },
    onScreenUnlock(finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onScreenUnlock called');
        finishCallback.onAnimationFinish();
    },
    onWindowAnimationTargetsUpdate(fullScreenWindowTarget: windowAnimationManager.WindowAnimationTarget, floatingWindowTargets: Array<windowAnimationManager.WindowAnimationTarget>): void {
        console.log('onWindowAnimationTargetsUpdate, the fullScreenWindowTarget is: ' + fullScreenWindowTarget);
        console.log('onWindowAnimationTargetsUpdate, the floatingWindowTargets are: ' + floatingWindowTargets);
        target = fullScreenWindowTarget;
    }
}

windowAnimationManager.setController(controller);

let finishedCallback: windowAnimationManager.WindowAnimationFinishedCallback;
windowAnimationManager.minimizeWindowWithAnimation(target, (err: BusinessError, data: windowAnimationManager.WindowAnimationFinishedCallback) => {
    if (err) {
        console.error('Failed to minimize the window target. Cause: ' + JSON.stringify(err));
        return;
    }
    finishedCallback = data;

    // After the callback is received, the window starts to play the animation. After the animation is finished, the **onAnimationFinish** callback is invoked.
    finishedCallback.onAnimationFinish();
});

windowAnimationManager.minimizeWindowWithAnimation

minimizeWindowWithAnimation(windowTarget: WindowAnimationTarget): Promise<WindowAnimationFinishedCallback>

Minimizes the window that displays the animation. This API uses a promise to return the result.

System capability: SystemCapability.WindowManager.WindowManager.Core

Parameters

NameTypeMandatoryDescription
windowTargetWindowAnimationTargetYesTarget window to display the animation.

Return value

TypeDescription
Promise<WindowAnimationFinishedCallback>Promise used to return a call when the animation is finished.

Example

import {BusinessError} from '@ohos.base';

let target: windowAnimationManager.WindowAnimationTarget|null  = null;
let controller: windowAnimationManager.WindowAnimationController = {
    onStartAppFromLauncher(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onStartAppFromLauncher, the startingWindowTarget is: ' + startingWindowTarget);
        finishCallback.onAnimationFinish();
	  },
    onStartAppFromRecent(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onStartAppFromRecent, the startingWindowTarget is: ' + startingWindowTarget);
        finishCallback.onAnimationFinish();
    },
    onStartAppFromOther(startingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onStartAppFromOther, the startingWindowTarget is: ' + startingWindowTarget);
        finishCallback.onAnimationFinish();
    },
    onAppTransition(fromWindowTarget: windowAnimationManager.WindowAnimationTarget, toWindowTarget: WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onAppTransition, the fromWindowTarget is: ' + fromWindowTarget);
        console.log('onAppTransition, the toWindowTarget is: ' + toWindowTarget);
        finishCallback.onAnimationFinish();
    },
    onMinimizeWindow(minimizingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onMinimizeWindow, the minimizingWindowTarget is: ' + minimizingWindowTarget);
        finishCallback.onAnimationFinish();
    },
    onCloseWindow(closingWindowTarget: windowAnimationManager.WindowAnimationTarget, finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onCloseWindow, the closingWindowTarget is: ' + closingWindowTarget);
        finishCallback.onAnimationFinish();
    },
    onScreenUnlock(finishCallback: windowAnimationManager.WindowAnimationFinishedCallback): void {
        console.log('onScreenUnlock called');
        finishCallback.onAnimationFinish();
    },
    onWindowAnimationTargetsUpdate(fullScreenWindowTarget: windowAnimationManager.WindowAnimationTarget, floatingWindowTargets: Array<windowAnimationManager.WindowAnimationTarget>): void {
        console.log('onWindowAnimationTargetsUpdate, the fullScreenWindowTarget is: ' + fullScreenWindowTarget);
        console.log('onWindowAnimationTargetsUpdate, the floatingWindowTargets are: ' + floatingWindowTargets);
    }
}

windowAnimationManager.setController(controller);

let promise: Promise<windowAnimationManager.WindowAnimationFinishedCallback> = windowAnimationManager.minimizeWindowWithAnimation(target);
promise.then((data: windowAnimationManager.WindowAnimationFinishedCallback) => {
    data.onAnimationFinish();
}).catch((err: BusinessError)=>{
    console.error('Failed to minimize the window target. Cause: ' + JSON.stringify(err));
    return;
});

WindowAnimationController

Implements the window animation controller. When creating a WindowAnimationController object, you must implement all callbacks in the object.

System capability: SystemCapability.WindowManager.WindowManager.Core

onStartAppFromLauncher

onStartAppFromLauncher(startingWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void

Called when an application is started from the home screen.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeMandatoryDescription
startingWindowTargetWindowAnimationTargetYesTarget window to display the animation.
finishCallbackWindowAnimationFinishedCallbackYesCallback invoked when the animation is finished.

Example

For details, see the sample code under windowAnimationManager.setController.

onStartAppFromRecent

onStartAppFromRecent(startingWindowTarget: WindowAnimationTarget,finishCallback:WindowAnimationFinishedCallback): void

Called when an application is started from the recent task list.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeMandatoryDescription
startingWindowTargetWindowAnimationTargetYesTarget window to display the animation.
finishCallbackWindowAnimationFinishedCallbackYesCallback invoked when the animation is finished.

Example

For details, see the sample code under windowAnimationManager.setController.

onStartAppFromOther

onStartAppFromOther(startingWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void

Called when an application is started from a place other than the home screen and recent task list.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeMandatoryDescription
startingWindowTargetWindowAnimationTargetYesTarget window to display the animation.
finishCallbackWindowAnimationFinishedCallbackYesCallback invoked when the animation is finished.

Example

For details, see the sample code under windowAnimationManager.setController.

onAppTransition

onAppTransition(fromWindowTarget: WindowAnimationTarget, toWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void

Called during application transition.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeMandatoryDescription
fromWindowTargetWindowAnimationTargetYesWindow that displays the animation before the transition.
toWindowTargetWindowAnimationTargetYesWindow that displays the animation after the transition.
finishCallbackWindowAnimationFinishedCallbackYesCallback invoked when the animation is finished.

Example

For details, see the sample code under windowAnimationManager.setController.

onMinimizeWindow

onMinimizeWindow(minimizingWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void

Called when a window is minimized.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeMandatoryDescription
minimizingWindowTargetWindowAnimationTargetYesTarget window to display the animation.
finishCallbackWindowAnimationFinishedCallbackYesCallback invoked when the animation is finished.

Example

For details, see the sample code under windowAnimationManager.setController.

onCloseWindow

onCloseWindow(closingWindowTarget: WindowAnimationTarget,finishCallback: WindowAnimationFinishedCallback): void

Called when a window is closed.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeMandatoryDescription
closingWindowTargetWindowAnimationTargetYesTarget window to display the animation.
finishCallbackWindowAnimationFinishedCallbackYesCallback invoked when the animation is finished.

Example

For details, see the sample code under windowAnimationManager.setController.

onScreenUnlock

onScreenUnlock(finishCallback: WindowAnimationFinishedCallback): void

Called when the screen is unlocked.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeMandatoryDescription
finishCallbackWindowAnimationFinishedCallbackYesCallback invoked when the animation is finished.

Example

For details, see the sample code under windowAnimationManager.setController.

onWindowAnimationTargetsUpdate

onWindowAnimationTargetsUpdate(fullScreenWindowTarget: WindowAnimationTarget, floatingWindowTargets: Array<WindowAnimationTarget>): void

Called when the window that displays the animation is updated.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeMandatoryDescription
fullScreenWindowTargetWindowAnimationTargetYesTarget window in full-screen mode.
floatingWindowTargetsArray<WindowAnimationTarget>YesTarget window in the form of a floating window.

Example

For details, see the sample code under windowAnimationManager.setController.

WindowAnimationFinishedCallback

Implements a callback that is invoked when the animation is finished.

onAnimationFinish

onAnimationFinish():void

Called when the animation is finished.

System capability: SystemCapability.WindowManager.WindowManager.Core

Example

For details, see the sample code under windowAnimationManager.setController.

WindowAnimationTarget

Defines a window to display animation.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeMandatoryDescription
bundleNamestringYesBundle name corresponding to the target window.
abilityNamestringYesAbility name corresponding to the target window.
windowBoundsRRectYesActual size of the target window.
missionIdnumberYesMission ID, which is used to match an ability when there are multiple missions.

RRect

Describes a rounded rectangle.

System capability: SystemCapability.WindowManager.WindowManager.Core

NameTypeMandatoryDescription
leftnumberYesHorizontal coordinate of the upper left corner of the target window relative to the screen.
topnumberYesVertical coordinate of the upper left corner of the target window relative to the screen.
widthnumberYesWidth of the target window.
heightnumberYesHeight of the target window.
radiusnumberYesRadius of the rounded corner of the target window.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/af0c5659ccdf43238b4fb2fab380e1f7