From 4c9ee63540dcd2c039831edb0816a56458e30f8f Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 6 Mar 2020 15:16:22 -0800 Subject: [PATCH] Converting some anonymous classes to lambda calls Change-Id: I386046a4a515d84801a8bbd11cfa090ba7adfd71 --- .../HotseatPredictionController.java | 9 +++----- .../NavBarToHomeTouchController.java | 8 ++----- ...ButtonNavbarToOverviewTouchController.java | 9 ++------ .../android/quickstep/views/RecentsView.java | 16 ++++++-------- .../launcher3/LauncherStateManager.java | 8 ++----- .../allapps/AllAppsTransitionController.java | 7 +------ .../anim/AnimationSuccessListener.java | 21 +++++++++++++++++++ .../anim/SpringAnimationBuilder.java | 13 ++++-------- 8 files changed, 41 insertions(+), 50 deletions(-) diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java index 0b054277e1..c85786f01f 100644 --- a/quickstep/recents_ui_overrides/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java +++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java @@ -226,12 +226,9 @@ public class HotseatPredictionController implements DragController.DragListener, } } if (animate) { - animationSet.addListener(new AnimationSuccessListener() { - @Override - public void onAnimationSuccess(Animator animator) { - if (callback != null) callback.run(); - } - }); + if (callback != null) { + animationSet.addListener(AnimationSuccessListener.forRunnable(callback)); + } animationSet.start(); } else { if (callback != null) callback.run(); diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NavBarToHomeTouchController.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NavBarToHomeTouchController.java index 19a2bae467..cebb0758da 100644 --- a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NavBarToHomeTouchController.java +++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NavBarToHomeTouchController.java @@ -219,12 +219,8 @@ public class NavBarToHomeTouchController implements TouchController, // Quickly return to the state we came from (we didn't move far). ValueAnimator anim = mCurrentAnimation.getAnimationPlayer(); anim.setFloatValues(progress, 0); - anim.addListener(new AnimationSuccessListener() { - @Override - public void onAnimationSuccess(Animator animator) { - onSwipeInteractionCompleted(mStartState); - } - }); + anim.addListener(AnimationSuccessListener.forRunnable( + () -> onSwipeInteractionCompleted(mStartState))); anim.setDuration(80).start(); } } diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java index ab634a4b12..7bae211c1a 100644 --- a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java +++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonNavbarToOverviewTouchController.java @@ -24,7 +24,6 @@ import static com.android.launcher3.Utilities.EDGE_NAV_BAR; import static com.android.launcher3.anim.Interpolators.ACCEL_DEACCEL; import static com.android.launcher3.util.VibratorWrapper.OVERVIEW_HAPTIC; -import android.animation.Animator; import android.animation.AnimatorSet; import android.animation.ValueAnimator; import android.graphics.PointF; @@ -177,12 +176,8 @@ public class NoButtonNavbarToOverviewTouchController extends FlingAndHoldTouchCo AnimatorSet anim = stateManager.createAtomicAnimation( stateManager.getState(), NORMAL, builder, ATOMIC_OVERVIEW_PEEK_COMPONENT, duration); - anim.addListener(new AnimationSuccessListener() { - @Override - public void onAnimationSuccess(Animator animator) { - onSwipeInteractionCompleted(NORMAL, Touch.SWIPE); - } - }); + anim.addListener(AnimationSuccessListener.forRunnable( + () -> onSwipeInteractionCompleted(NORMAL, Touch.SWIPE))); anim.start(); } } else { diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java index 872e690acc..d24528a6b9 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java @@ -88,7 +88,6 @@ import com.android.launcher3.DeviceProfile; import com.android.launcher3.Insettable; import com.android.launcher3.InsettableFrameLayout; import com.android.launcher3.InvariantDeviceProfile; -import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; import com.android.launcher3.PagedView; import com.android.launcher3.R; @@ -962,15 +961,12 @@ public abstract class RecentsView extends PagedView impl } AnimatorSet pa = setRecentsChangedOrientation(true); - pa.addListener(new AnimationSuccessListener() { - @Override - public void onAnimationSuccess(Animator animator) { - updateLayoutRotation(newRotation); - ((DragLayer)mActivity.getDragLayer()).recreateControllers(); - rotateAllChildTasks(); - setRecentsChangedOrientation(false).start(); - } - }); + pa.addListener(AnimationSuccessListener.forRunnable(() -> { + updateLayoutRotation(newRotation); + ((DragLayer) mActivity.getDragLayer()).recreateControllers(); + rotateAllChildTasks(); + setRecentsChangedOrientation(false).start(); + })); pa.start(); } diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java index 9f25729602..04c5ccb622 100644 --- a/src/com/android/launcher3/LauncherStateManager.java +++ b/src/com/android/launcher3/LauncherStateManager.java @@ -244,12 +244,8 @@ public class LauncherStateManager { } else if (!mConfig.userControlled && animated && mConfig.mTargetState == state) { // We are running the same animation as requested if (onCompleteRunnable != null) { - mConfig.mCurrentAnimation.addListener(new AnimationSuccessListener() { - @Override - public void onAnimationSuccess(Animator animator) { - onCompleteRunnable.run(); - } - }); + mConfig.mCurrentAnimation.addListener( + AnimationSuccessListener.forRunnable(onCompleteRunnable)); } return; } diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java index 217916205d..b87c5b13ba 100644 --- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java +++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java @@ -224,12 +224,7 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil } public AnimatorListenerAdapter getProgressAnimatorListener() { - return new AnimationSuccessListener() { - @Override - public void onAnimationSuccess(Animator animator) { - onProgressAnimationEnd(); - } - }; + return AnimationSuccessListener.forRunnable(this::onProgressAnimationEnd); } public void setupViews(AllAppsContainerView appsView) { diff --git a/src/com/android/launcher3/anim/AnimationSuccessListener.java b/src/com/android/launcher3/anim/AnimationSuccessListener.java index 9448632ac5..9905e81638 100644 --- a/src/com/android/launcher3/anim/AnimationSuccessListener.java +++ b/src/com/android/launcher3/anim/AnimationSuccessListener.java @@ -39,4 +39,25 @@ public abstract class AnimationSuccessListener extends AnimatorListenerAdapter { } public abstract void onAnimationSuccess(Animator animator); + + /** + * Returns an AnimationSuccessListener which runs the provided action on success + */ + public static AnimationSuccessListener forRunnable(Runnable r) { + return new RunnableSuccessListener(r); + } + + private static class RunnableSuccessListener extends AnimationSuccessListener { + + private final Runnable mRunnable; + + private RunnableSuccessListener(Runnable r) { + mRunnable = r; + } + + @Override + public void onAnimationSuccess(Animator animator) { + mRunnable.run(); + } + } } diff --git a/src/com/android/launcher3/anim/SpringAnimationBuilder.java b/src/com/android/launcher3/anim/SpringAnimationBuilder.java index 0f34c1e97e..f22a9f0ac6 100644 --- a/src/com/android/launcher3/anim/SpringAnimationBuilder.java +++ b/src/com/android/launcher3/anim/SpringAnimationBuilder.java @@ -15,16 +15,15 @@ */ package com.android.launcher3.anim; -import android.animation.Animator; import android.animation.ObjectAnimator; import android.content.Context; import android.util.FloatProperty; -import com.android.launcher3.util.DefaultDisplay; - import androidx.annotation.FloatRange; import androidx.dynamicanimation.animation.SpringForce; +import com.android.launcher3.util.DefaultDisplay; + /** * Utility class to build an object animator which follows the same path as a spring animation for * an underdamped spring. @@ -192,12 +191,8 @@ public class SpringAnimationBuilder extends FloatProperty { long durationMs = (long) (1000.0 * duration); ObjectAnimator animator = ObjectAnimator.ofFloat(mTarget, this, 0, (float) duration); animator.setDuration(durationMs).setInterpolator(Interpolators.LINEAR); - animator.addListener(new AnimationSuccessListener() { - @Override - public void onAnimationSuccess(Animator animator) { - mProperty.setValue(mTarget, mEndValue); - } - }); + animator.addListener(AnimationSuccessListener.forRunnable( + () -> mProperty.setValue(mTarget, mEndValue))); return animator; }