Android 应用的退场和入场动画分析

Android 应用的退场和入场动画分析

一、情景

在Android14上,由于新增了需求,需要定制自己的打开应用和退出应用动画。因此着手调查,应用打开和退出动画的出处。

二、任务

调查创建应用动画的创建流程和播放流程

三、行动

根据网上的的回答大多数都说应用的默认入场动画都在目录frameworks/base/core/res/res/anim这下面,分别是入场进入动画activity_open_enter.xml、入场退出动画activity_open_exit.xml、退场进入动画activity_close_enter.xml、退场退出动画activity_close_exit.xml。但是以为改这个就能改变就太想当然了,当然是不生效,既然是默认的,肯定是没人用的,最后还是得去撸代码,优先去看Launcher,应用的入场动画肯定是launcher侧创建的,需要ActivityOption去传递,基于这个猜测我找到launcher打开应用的操作:

应用打开动画

ActivityContext.java
 /**
     * Safely starts an activity.
     *
     * @param v View starting the activity.
     * @param intent Base intent being launched.
     * @param item Item associated with the view.
     * @return RunnableList for listening for animation finish if the activity was properly
     *         or started, {@code null} if the launch finished
     */
    default RunnableList startActivitySafely(
            View v, Intent intent, @Nullable ItemInfo item) {
   
        Preconditions.assertUIThread();
        Context context = (Context) this;
        if (isAppBlockedForSafeMode() && !PackageManagerHelper.isSystemApp(context, intent)) {
   
            Toast.makeText(context, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
            return null;
        }
        
		//此处开始创建打开桌面应用的一些属性和动作,很显然v不为null,此处调用的是getActivityLaunchOptions,开始引入一些动画。
        ActivityOptionsWrapper options = v != null ? getActivityLaunchOptions(v, item)
                : makeDefaultActivityOptions(item != null && item.animationType == DEFAULT_NO_ICON
                        ? SPLASH_SCREEN_STYLE_SOLID_COLOR : -1 /* SPLASH_SCREEN_STYLE_UNDEFINED */);
        UserHandle user = item == null ? null : item.user;
        Bundle optsBundle = options.toBundle();
        // Prepare intent
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (v != null) {
   
            intent.setSourceBounds(Utilities.getViewBounds(v));
        }
        try {
   
            boolean isShortcut = (item instanceof WorkspaceItemInfo)
                    && (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT
                    || item.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT)
                    && !
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

何愁无路QAQ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值