Merge "Removing hacks to delay app animations until window animations complete."

This commit is contained in:
Winson Chung
2015-11-12 16:42:20 +00:00
committed by Android (Google) Code Review
7 changed files with 64 additions and 95 deletions

View File

@@ -42,7 +42,7 @@ import com.android.systemui.R;
import com.android.systemui.recents.events.EventBus;
import com.android.systemui.recents.events.activity.AppWidgetProviderChangedEvent;
import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent;
import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationStartedEvent;
import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent;
import com.android.systemui.recents.events.activity.EnterRecentsWindowLastAnimationFrameEvent;
import com.android.systemui.recents.events.activity.HideRecentsEvent;
import com.android.systemui.recents.events.activity.IterateRecentsEvent;
@@ -115,29 +115,33 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
});
/**
* A common Runnable to finish Recents either by calling finish() (with a custom animation) or
* launching Home with some ActivityOptions. Generally we always launch home when we exit
* Recents rather than just finishing the activity since we don't know what is behind Recents in
* the task stack. The only case where we finish() directly is when we are cancelling the full
* screen transition from the app.
* A common Runnable to finish Recents by launching Home with an animation depending on the
* last activity launch state. Generally we always launch home when we exit Recents rather than
* just finishing the activity since we don't know what is behind Recents in the task stack.
*/
class FinishRecentsRunnable implements Runnable {
Intent mLaunchIntent;
ActivityOptions mLaunchOpts;
/**
* Creates a finish runnable that starts the specified intent, using the given
* ActivityOptions.
* Creates a finish runnable that starts the specified intent.
*/
public FinishRecentsRunnable(Intent launchIntent, ActivityOptions opts) {
public FinishRecentsRunnable(Intent launchIntent) {
mLaunchIntent = launchIntent;
mLaunchOpts = opts;
}
@Override
public void run() {
try {
startActivityAsUser(mLaunchIntent, mLaunchOpts.toBundle(), UserHandle.CURRENT);
RecentsActivityLaunchState launchState =
Recents.getConfiguration().getLaunchState();
ActivityOptions opts = ActivityOptions.makeCustomAnimation(RecentsActivity.this,
launchState.launchedFromSearchHome ?
R.anim.recents_to_search_launcher_enter :
R.anim.recents_to_launcher_enter,
launchState.launchedFromSearchHome ?
R.anim.recents_to_search_launcher_exit :
R.anim.recents_to_launcher_exit);
startActivityAsUser(mLaunchIntent, opts.toBundle(), UserHandle.CURRENT);
} catch (Exception e) {
Log.e(TAG, getString(R.string.recents_launch_error_message, "Home"), e);
}
@@ -191,18 +195,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
mRecentsView.setTaskStack(stack);
}
// Create the home intent runnable
Intent homeIntent = new Intent(Intent.ACTION_MAIN, null);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
mFinishLaunchHomeRunnable = new FinishRecentsRunnable(homeIntent,
ActivityOptions.makeCustomAnimation(this,
launchState.launchedFromSearchHome ? R.anim.recents_to_search_launcher_enter :
R.anim.recents_to_launcher_enter,
launchState.launchedFromSearchHome ? R.anim.recents_to_search_launcher_exit :
R.anim.recents_to_launcher_exit));
// Mark the task that is the launch target
int launchTaskIndexInStack = 0;
if (launchState.launchedToTaskId != -1) {
@@ -361,6 +353,13 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
mEmptyViewStub = (ViewStub) findViewById(R.id.empty_view_stub);
mScrimViews = new SystemBarScrimViews(this);
// Create the home intent runnable
Intent homeIntent = new Intent(Intent.ACTION_MAIN, null);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
mFinishLaunchHomeRunnable = new FinishRecentsRunnable(homeIntent);
// Bind the search app widget when we first start up
if (!Constants.DebugFlags.App.DisableSearchBar) {
mSearchWidgetInfo = ssp.getOrBindSearchAppWidget(this, mAppWidgetHost);
@@ -396,7 +395,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
boolean wasLaunchedByAm = !launchState.launchedFromHome &&
!launchState.launchedFromAppWithThumbnail;
if (launchState.launchedHasConfigurationChanged || wasLaunchedByAm) {
EventBus.getDefault().send(new EnterRecentsWindowAnimationStartedEvent());
EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent());
}
if (!launchState.launchedHasConfigurationChanged) {
@@ -421,6 +420,12 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
}
}
@Override
public void onEnterAnimationComplete() {
super.onEnterAnimationComplete();
EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent());
}
@Override
protected void onPause() {
super.onPause();
@@ -603,7 +608,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
}
}
public final void onBusEvent(EnterRecentsWindowAnimationStartedEvent event) {
public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) {
// Try and start the enter animation (or restart it on configuration changed)
ReferenceCountedTrigger t = new ReferenceCountedTrigger(this, null, null, null);
ViewAnimation.TaskViewEnterContext ctx = new ViewAnimation.TaskViewEnterContext(t);

View File

@@ -40,7 +40,6 @@ import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.SystemUIApplication;
import com.android.systemui.recents.events.EventBus;
import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationStartedEvent;
import com.android.systemui.recents.events.activity.EnterRecentsWindowLastAnimationFrameEvent;
import com.android.systemui.recents.events.activity.HideRecentsEvent;
import com.android.systemui.recents.events.activity.IterateRecentsEvent;
@@ -70,7 +69,7 @@ import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
* be called remotely from the system user.
*/
public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub
implements ActivityOptions.OnAnimationStartedListener, ActivityOptions.OnAnimationFinishedListener {
implements ActivityOptions.OnAnimationFinishedListener {
private final static String TAG = "RecentsImpl";
private final static boolean DEBUG = false;
@@ -140,7 +139,6 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub
TaskStackListenerImpl mTaskStackListener;
RecentsAppWidgetHost mAppWidgetHost;
boolean mBootCompleted;
boolean mStartAnimationTriggered;
boolean mCanReuseTaskStackViews = true;
// Task launching
@@ -613,7 +611,7 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub
final Task toTask = new Task();
final TaskViewTransform toTransform = getThumbnailTransitionTransform(stack, stackView,
topTask.id, toTask);
ForegroundThread.getHandler().post(new Runnable() {
ForegroundThread.getHandler().postAtFrontOfQueue(new Runnable() {
@Override
public void run() {
final Bitmap transitionBitmap = drawThumbnailTransitionBitmap(toTask, toTransform);
@@ -635,7 +633,7 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub
return ActivityOptions.makeCustomAnimation(mContext,
R.anim.recents_from_unknown_enter,
R.anim.recents_from_unknown_exit,
mHandler, this);
mHandler, null);
}
/**
@@ -646,12 +644,12 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub
return ActivityOptions.makeCustomAnimation(mContext,
R.anim.recents_from_search_launcher_enter,
R.anim.recents_from_search_launcher_exit,
mHandler, this);
mHandler, null);
}
return ActivityOptions.makeCustomAnimation(mContext,
R.anim.recents_from_launcher_enter,
R.anim.recents_from_launcher_exit,
mHandler, this);
mHandler, null);
}
/**
@@ -677,7 +675,7 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub
AppTransitionAnimationSpec[] specsArray = new AppTransitionAnimationSpec[specs.size()];
specs.toArray(specsArray);
return ActivityOptions.makeThumbnailAspectScaleDownAnimation(mDummyStackView,
specsArray, mHandler, this, this);
specsArray, mHandler, null, this);
} else {
// Update the destination rect
Task toTask = new Task();
@@ -688,7 +686,7 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub
if (thumbnail != null) {
return ActivityOptions.makeThumbnailAspectScaleDownAnimation(mDummyStackView,
thumbnail, (int) toTaskRect.left, (int) toTaskRect.top,
(int) toTaskRect.width(), (int) toTaskRect.height(), mHandler, this);
(int) toTaskRect.width(), (int) toTaskRect.height(), mHandler, null);
}
// If both the screenshot and thumbnail fails, then just fall back to the default transition
return getUnknownTransitionActivityOptions();
@@ -841,8 +839,6 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub
private void startRecentsActivity(ActivityManager.RunningTaskInfo topTask,
ActivityOptions opts, boolean fromHome, boolean fromSearchHome, boolean fromThumbnail,
TaskStackLayoutAlgorithm.VisibilityReport vr) {
mStartAnimationTriggered = false;
// Update the configuration based on the launch options
RecentsConfiguration config = Recents.getConfiguration();
RecentsActivityLaunchState launchState = config.getLaunchState();
@@ -870,16 +866,7 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub
mCanReuseTaskStackViews = true;
}
/**** OnAnimationStartedListener Implementation ****/
@Override
public void onAnimationStarted() {
// Notify recents to start the enter animation
if (!mStartAnimationTriggered) {
mStartAnimationTriggered = true;
EventBus.getDefault().post(new EnterRecentsWindowAnimationStartedEvent());
}
}
/**** OnAnimationFinishedListener Implementation ****/
@Override
public void onAnimationFinished() {

View File

@@ -19,8 +19,10 @@ package com.android.systemui.recents.events.activity;
import com.android.systemui.recents.events.EventBus;
/**
* This is sent when the window animation into Recents starts.
* This is sent when the window animation into Recents completes. We use this signal to know when
* we can start in-app animations so that they don't conflict with the window transition into
* Recents.
*/
public class EnterRecentsWindowAnimationStartedEvent extends EventBus.Event {
public class EnterRecentsWindowAnimationCompletedEvent extends EventBus.Event {
// Simple event
}

View File

@@ -26,7 +26,7 @@ import com.android.systemui.recents.Recents;
import com.android.systemui.recents.RecentsActivityLaunchState;
import com.android.systemui.recents.RecentsConfiguration;
import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationStartedEvent;
import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent;
/** Manages the scrims for the various system bars. */
public class SystemBarScrimViews {
@@ -81,21 +81,11 @@ public class SystemBarScrimViews {
/**
* Starts animating the scrim views when entering Recents.
*/
public final void onBusEvent(EnterRecentsWindowAnimationStartedEvent event) {
RecentsConfiguration config = Recents.getConfiguration();
RecentsActivityLaunchState launchState = config.getLaunchState();
int transitionEnterFromAppDelay = mContext.getResources().getInteger(
R.integer.recents_enter_from_app_transition_duration);
int transitionEnterFromHomeDelay = mContext.getResources().getInteger(
R.integer.recents_enter_from_home_transition_duration);
public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) {
if (mHasStatusBarScrim && mShouldAnimateStatusBarScrim) {
mStatusBarScrimView.setTranslationY(-mStatusBarScrimView.getMeasuredHeight());
mStatusBarScrimView.animate()
.translationY(0)
.setStartDelay(launchState.launchedFromHome ?
transitionEnterFromHomeDelay :
transitionEnterFromAppDelay)
.setDuration(mNavBarScrimEnterDuration)
.setInterpolator(mQuintOutInterpolator)
.withStartAction(new Runnable() {
@@ -110,9 +100,6 @@ public class SystemBarScrimViews {
mNavBarScrimView.setTranslationY(mNavBarScrimView.getMeasuredHeight());
mNavBarScrimView.animate()
.translationY(0)
.setStartDelay(launchState.launchedFromHome ?
transitionEnterFromHomeDelay :
transitionEnterFromAppDelay)
.setDuration(mNavBarScrimEnterDuration)
.setInterpolator(mQuintOutInterpolator)
.withStartAction(new Runnable() {

View File

@@ -1161,7 +1161,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
TaskView frontTv = getChildViewForTask(newFrontMostTask);
if (frontTv != null) {
frontTv.onTaskBound(newFrontMostTask);
frontTv.fadeInActionButton(0, getResources().getInteger(
frontTv.fadeInActionButton(getResources().getInteger(
R.integer.recents_task_enter_from_app_duration));
}
}

View File

@@ -313,10 +313,6 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
RecentsActivityLaunchState launchState = config.getLaunchState();
Resources res = mContext.getResources();
final TaskViewTransform transform = ctx.currentTaskTransform;
final int transitionEnterFromAppDelay = res.getInteger(
R.integer.recents_enter_from_app_transition_duration);
final int transitionEnterFromHomeDelay = res.getInteger(
R.integer.recents_enter_from_home_transition_duration);
final int taskViewEnterFromAppDuration = res.getInteger(
R.integer.recents_task_enter_from_app_duration);
final int taskViewEnterFromHomeDuration = res.getInteger(
@@ -332,25 +328,22 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
if (Constants.DebugFlags.App.EnableThumbnailAlphaOnFrontmost) {
// Animate the thumbnail alpha before the dim animation (to prevent updating the
// hardware layer)
mThumbnailView.startEnterRecentsAnimation(transitionEnterFromAppDelay,
new Runnable() {
@Override
public void run() {
animateDimToProgress(0, taskViewEnterFromAppDuration,
ctx.postAnimationTrigger.decrementOnAnimationEnd());
}
});
mThumbnailView.startEnterRecentsAnimation(new Runnable() {
@Override
public void run() {
animateDimToProgress(taskViewEnterFromAppDuration,
ctx.postAnimationTrigger.decrementOnAnimationEnd());
}
});
} else {
// Immediately start the dim animation
animateDimToProgress(transitionEnterFromAppDelay,
taskViewEnterFromAppDuration,
animateDimToProgress(taskViewEnterFromAppDuration,
ctx.postAnimationTrigger.decrementOnAnimationEnd());
}
ctx.postAnimationTrigger.increment();
// Animate the action button in
fadeInActionButton(transitionEnterFromAppDelay,
taskViewEnterFromAppDuration);
fadeInActionButton(taskViewEnterFromAppDuration);
} else {
// Animate the task up if it was occluding the launch target
if (ctx.currentTaskOccludesLaunchTarget) {
@@ -358,7 +351,6 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
setAlpha(0f);
animate().alpha(1f)
.translationY(transform.translationY)
.setStartDelay(transitionEnterFromAppDelay)
.setUpdateListener(null)
.setInterpolator(mFastOutSlowInInterpolator)
.setDuration(taskViewEnterFromHomeDuration)
@@ -377,8 +369,7 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
} else if (launchState.launchedFromHome) {
// Animate the tasks up
int frontIndex = (ctx.currentStackViewCount - ctx.currentStackViewIndex - 1);
int delay = transitionEnterFromHomeDelay +
frontIndex * taskViewEnterFromHomeStaggerDelay;
int delay = frontIndex * taskViewEnterFromHomeStaggerDelay;
setScaleX(transform.scale);
setScaleY(transform.scale);
@@ -404,13 +395,12 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
}
}
public void fadeInActionButton(int delay, int duration) {
public void fadeInActionButton(int duration) {
// Hide the action button
mActionButtonView.setAlpha(0f);
// Animate the action button in
mActionButtonView.animate().alpha(1f)
.setStartDelay(delay)
.setDuration(duration)
.setInterpolator(PhoneStatusBar.ALPHA_IN)
.start();
@@ -611,12 +601,11 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
}
/** Animates the dim to the task progress. */
void animateDimToProgress(int delay, int duration, Animator.AnimatorListener postAnimRunnable) {
void animateDimToProgress(int duration, Animator.AnimatorListener postAnimRunnable) {
// Animate the dim into view as well
int toDim = getDimFromTaskProgress();
if (toDim != getDim()) {
ObjectAnimator anim = ObjectAnimator.ofInt(TaskView.this, "dim", toDim);
anim.setStartDelay(delay);
anim.setDuration(duration);
if (postAnimRunnable != null) {
anim.addListener(postAnimRunnable);

View File

@@ -218,13 +218,13 @@ public class TaskViewThumbnail extends View {
void onFocusChanged(boolean focused) {
if (focused) {
if (Float.compare(getAlpha(), 1f) != 0) {
startFadeAnimation(1f, 0, 150, null);
startFadeAnimation(1f, 150, null);
}
} else {
float taskViewThumbnailAlpha = getResources().getFloat(
R.dimen.recents_task_view_thumbnail_alpha);
if (Float.compare(getAlpha(), taskViewThumbnailAlpha) != 0) {
startFadeAnimation(taskViewThumbnailAlpha, 0, 150, null);
startFadeAnimation(taskViewThumbnailAlpha, 150, null);
}
}
}
@@ -244,10 +244,10 @@ public class TaskViewThumbnail extends View {
}
/** Animates this task thumbnail as it enters Recents. */
void startEnterRecentsAnimation(int delay, Runnable postAnimRunnable) {
void startEnterRecentsAnimation(Runnable postAnimRunnable) {
float taskViewThumbnailAlpha = getResources().getFloat(
R.dimen.recents_task_view_thumbnail_alpha);
startFadeAnimation(taskViewThumbnailAlpha, delay,
startFadeAnimation(taskViewThumbnailAlpha,
getResources().getInteger(R.integer.recents_task_enter_from_app_duration),
postAnimRunnable);
}
@@ -256,14 +256,13 @@ public class TaskViewThumbnail extends View {
void startLaunchTaskAnimation(Runnable postAnimRunnable) {
int taskViewExitToAppDuration = mContext.getResources().getInteger(
R.integer.recents_task_exit_to_app_duration);
startFadeAnimation(1f, 0, taskViewExitToAppDuration, postAnimRunnable);
startFadeAnimation(1f, taskViewExitToAppDuration, postAnimRunnable);
}
/** Starts a new thumbnail alpha animation. */
void startFadeAnimation(float finalAlpha, int delay, int duration, final Runnable postAnimRunnable) {
void startFadeAnimation(float finalAlpha, int duration, final Runnable postAnimRunnable) {
Utilities.cancelAnimationWithoutCallbacks(mThumbnailAlphaAnimator);
mThumbnailAlphaAnimator = ValueAnimator.ofFloat(mThumbnailAlpha, finalAlpha);
mThumbnailAlphaAnimator.setStartDelay(delay);
mThumbnailAlphaAnimator.setDuration(duration);
mThumbnailAlphaAnimator.setInterpolator(mFastOutSlowInInterpolator);
mThumbnailAlphaAnimator.addUpdateListener(mThumbnailAlphaUpdateListener);