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)
&& !