From 0d5daafd2f99945664284126f2dad75838f14e7a Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Wed, 7 Feb 2018 15:18:00 -0800 Subject: [PATCH] Prevent blinking when user presses home. Intead of finishing the entire animation (launcher animation and window animation), we finish just the launcher animation. Bug: 73071035 Change-Id: Ied84cb641f3cedc367433ad99d21ab1b258ae7f8 --- .../launcher3/LauncherAnimationRunner.java | 1 - .../LauncherAppTransitionManagerImpl.java | 24 ++++---- .../launcher3/LauncherTransitionAnimator.java | 58 +++++++++++++++++++ .../LauncherAppTransitionManager.java | 4 +- .../launcher3/LauncherStateManager.java | 2 +- 5 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 quickstep/src/com/android/launcher3/LauncherTransitionAnimator.java diff --git a/quickstep/src/com/android/launcher3/LauncherAnimationRunner.java b/quickstep/src/com/android/launcher3/LauncherAnimationRunner.java index 489e55b9bf..872e6ca020 100644 --- a/quickstep/src/com/android/launcher3/LauncherAnimationRunner.java +++ b/quickstep/src/com/android/launcher3/LauncherAnimationRunner.java @@ -16,7 +16,6 @@ package com.android.launcher3; import android.animation.AnimatorSet; -import android.os.Handler; import com.android.systemui.shared.system.RemoteAnimationRunnerCompat; diff --git a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java index 1fb2f79983..35246b611d 100644 --- a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java +++ b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java @@ -88,7 +88,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag private ImageView mFloatingView; private boolean mIsRtl; - private Animator mCurrentAnimator; + private LauncherTransitionAnimator mCurrentAnimator; public LauncherAppTransitionManagerImpl(Context context) { mLauncher = Launcher.getLauncher(context); @@ -110,7 +110,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag mDeviceProfile = dp; } - private void setCurrentAnimator(Animator animator) { + private void setCurrentAnimator(LauncherTransitionAnimator animator) { if (mCurrentAnimator != null && mCurrentAnimator.isRunning()) { mCurrentAnimator.cancel(); } @@ -118,9 +118,9 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag } @Override - public void finishAnimation() { + public void finishLauncherAnimation() { if (mCurrentAnimator != null && mCurrentAnimator.isRunning()) { - mCurrentAnimator.end(); + mCurrentAnimator.finishLauncherAnimation(); } mCurrentAnimator = null; } @@ -140,10 +140,10 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag // Post at front of queue ignoring sync barriers to make sure it gets // processed before the next frame. postAtFrontOfQueueAsynchronously(v.getHandler(), () -> { - mAnimator = new AnimatorSet(); - setCurrentAnimator(mAnimator); - mAnimator.play(getLauncherAnimators(v)); - mAnimator.play(getWindowAnimators(v, targets)); + LauncherTransitionAnimator animator = new LauncherTransitionAnimator( + getLauncherAnimators(v), getWindowAnimators(v, targets)); + setCurrentAnimator(animator); + mAnimator = animator.getAnimatorSet(); mAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { @@ -450,16 +450,16 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag return; } - mAnimator = new AnimatorSet(); - setCurrentAnimator(mAnimator); + LauncherTransitionAnimator animator = new LauncherTransitionAnimator( + getLauncherResumeAnimation(), getClosingWindowAnimators(targets)); + setCurrentAnimator(animator); + mAnimator = animator.getAnimatorSet(); mAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { finishedCallback.run(); } }); - mAnimator.play(getClosingWindowAnimators(targets)); - mAnimator.play(getLauncherResumeAnimation()); mAnimator.start(); // Because t=0 has the app icon in its original spot, we can skip the diff --git a/quickstep/src/com/android/launcher3/LauncherTransitionAnimator.java b/quickstep/src/com/android/launcher3/LauncherTransitionAnimator.java new file mode 100644 index 0000000000..80eaef7e31 --- /dev/null +++ b/quickstep/src/com/android/launcher3/LauncherTransitionAnimator.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3; + +import android.animation.Animator; +import android.animation.AnimatorSet; + +/** + * Creates an AnimatorSet consisting on one Animator for Launcher transition, and one Animator for + * the Window transitions. + * + * Allows for ending the Launcher animator without ending the Window animator. + */ +public class LauncherTransitionAnimator { + + private AnimatorSet mAnimatorSet; + private Animator mLauncherAnimator; + private Animator mWindowAnimator; + + LauncherTransitionAnimator(Animator launcherAnimator, Animator windowAnimator) { + mLauncherAnimator = launcherAnimator; + mWindowAnimator = windowAnimator; + + mAnimatorSet = new AnimatorSet(); + mAnimatorSet.play(launcherAnimator); + mAnimatorSet.play(windowAnimator); + } + + public AnimatorSet getAnimatorSet() { + return mAnimatorSet; + } + + public void cancel() { + mAnimatorSet.cancel(); + } + + public boolean isRunning() { + return mAnimatorSet.isRunning(); + } + + public void finishLauncherAnimation() { + mLauncherAnimator.end(); + } +} diff --git a/src/com/android/launcher3/LauncherAppTransitionManager.java b/src/com/android/launcher3/LauncherAppTransitionManager.java index c0d52c1c19..43d5e623dc 100644 --- a/src/com/android/launcher3/LauncherAppTransitionManager.java +++ b/src/com/android/launcher3/LauncherAppTransitionManager.java @@ -65,7 +65,7 @@ public class LauncherAppTransitionManager { return getDefaultActivityLaunchOptions(launcher, v); } - /** Cancels the current transition animation */ - public void finishAnimation() { + /** Cancels the current Launcher transition animation */ + public void finishLauncherAnimation() { } } diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java index 4aed520996..137e4b13e1 100644 --- a/src/com/android/launcher3/LauncherStateManager.java +++ b/src/com/android/launcher3/LauncherStateManager.java @@ -276,7 +276,7 @@ public class LauncherStateManager { // finish it and let this state animation take over. LauncherAppTransitionManager transitionManager = mLauncher.getAppTransitionManager(); if (transitionManager != null) { - transitionManager.finishAnimation(); + transitionManager.finishLauncherAnimation(); } }