From b7860bd85e0055ec00530817a82a30f42a49193a Mon Sep 17 00:00:00 2001 From: Fengjiang Li Date: Wed, 15 Mar 2023 10:50:50 -0700 Subject: [PATCH] [Predictive Back] Remove OnBackPressedHandler OnBackPressedHandler was mimicking android.window.OnBackAnimationCallback because later one was hidden API to T. Now that we have moved to U, we can remove the former handler. Test: manual Bug: 272797556 Change-Id: Ic5302cfa0a6fb15c4a64bdf5dc331834b1f06f38 --- .../allapps/TaskbarAllAppsSlideInView.java | 28 +----------- .../uioverrides/QuickstepLauncher.java | 37 ++++++++------- .../launcher3/AbstractFloatingView.java | 6 ++- src/com/android/launcher3/Launcher.java | 18 ++++---- .../launcher3/OnBackPressedHandler.java | 45 ------------------- .../launcher3/views/AbstractSlideInView.java | 9 ++-- .../widget/picker/WidgetsFullSheet.java | 11 +++-- 7 files changed, 48 insertions(+), 106 deletions(-) delete mode 100644 src/com/android/launcher3/OnBackPressedHandler.java diff --git a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsSlideInView.java b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsSlideInView.java index c6f7561ef9..9db4dddfd1 100644 --- a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsSlideInView.java +++ b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsSlideInView.java @@ -23,8 +23,6 @@ import android.graphics.Rect; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.animation.Interpolator; -import android.window.BackEvent; -import android.window.OnBackAnimationCallback; import android.window.OnBackInvokedDispatcher; import com.android.launcher3.DeviceProfile; @@ -57,28 +55,6 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView } /** - * Provide {@link OnBackPressedHandler} in below order: + * Provide {@link OnBackAnimationCallback} in below order: *
    *
  1. auto cancel action mode handler *
  2. drag handler @@ -575,7 +576,8 @@ public class Launcher extends StatefulActivity * Note that state handler will always be handling the back press event if the previous 3 don't. */ @NonNull - protected OnBackPressedHandler getOnBackPressedHandler() { + @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + protected OnBackAnimationCallback getOnBackAnimationCallback() { // #1 auto cancel action mode handler if (isInAutoCancelActionMode()) { return this::finishAutoCancelActionMode; @@ -594,17 +596,16 @@ public class Launcher extends StatefulActivity } // #4 state handler - return new OnBackPressedHandler() { + return new OnBackAnimationCallback() { @Override public void onBackInvoked() { onStateBack(); } @Override - public void onBackProgressed( - @FloatRange(from = 0.0, to = 1.0) float backProgress) { + public void onBackProgressed(@NonNull BackEvent backEvent) { mStateManager.getState().onBackProgressed( - Launcher.this, backProgress); + Launcher.this, backEvent.getProgress()); } @Override @@ -2117,8 +2118,9 @@ public class Launcher extends StatefulActivity } @Override + @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) public void onBackPressed() { - getOnBackPressedHandler().onBackInvoked(); + getOnBackAnimationCallback().onBackInvoked(); } protected void onStateBack() { diff --git a/src/com/android/launcher3/OnBackPressedHandler.java b/src/com/android/launcher3/OnBackPressedHandler.java deleted file mode 100644 index 485aa0ae38..0000000000 --- a/src/com/android/launcher3/OnBackPressedHandler.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2023 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 androidx.annotation.FloatRange; - -/** - * Interface that mimics {@link android.window.OnBackInvokedCallback} without dependencies on U's - * API such as {@link android.window.BackEvent}. - * - *

    Impl can assume below order during a back gesture: - *

      - *
    1. [optional] one {@link #onBackStarted()} will be called to start the gesture - *
    2. zero or multiple {@link #onBackProgressed(float)} will be called during swipe gesture - *
    3. either one of {@link #onBackInvoked()} or {@link #onBackCancelled()} will be called to end - * the gesture - */ -public interface OnBackPressedHandler { - - /** Called when back has started. */ - default void onBackStarted() {} - - /** Called when back is committed. */ - void onBackInvoked(); - - /** Called with back gesture's progress. */ - default void onBackProgressed(@FloatRange(from = 0.0, to = 1.0) float backProgress) {} - - /** Called when user drops the back gesture. */ - default void onBackCancelled() {} -} diff --git a/src/com/android/launcher3/views/AbstractSlideInView.java b/src/com/android/launcher3/views/AbstractSlideInView.java index 8a9b179a1b..57305827ef 100644 --- a/src/com/android/launcher3/views/AbstractSlideInView.java +++ b/src/com/android/launcher3/views/AbstractSlideInView.java @@ -28,10 +28,12 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; +import android.annotation.TargetApi; import android.content.Context; import android.graphics.Canvas; import android.graphics.Outline; import android.graphics.drawable.Drawable; +import android.os.Build; import android.util.AttributeSet; import android.util.Property; import android.view.MotionEvent; @@ -39,8 +41,8 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewOutlineProvider; import android.view.animation.Interpolator; +import android.window.BackEvent; -import androidx.annotation.FloatRange; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Px; @@ -193,8 +195,9 @@ public abstract class AbstractSlideInView } @Override - public void onBackProgressed(@FloatRange(from = 0.0, to = 1.0) float progress) { - super.onBackProgressed(progress); + @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + public void onBackProgressed(BackEvent backEvent) { + final float progress = backEvent.getProgress(); float deceleratedProgress = Interpolators.PREDICTIVE_BACK_DECELERATED_EASE.getInterpolation(progress); mIsBackProgressing = progress > 0f; diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java index 0403249307..0b2f5a547b 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java @@ -25,11 +25,13 @@ import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORD import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.PropertyValuesHolder; +import android.annotation.TargetApi; import android.content.Context; import android.content.pm.LauncherApps; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Rect; +import android.os.Build; import android.os.Process; import android.os.UserHandle; import android.os.UserManager; @@ -47,8 +49,8 @@ import android.widget.Button; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; +import android.window.BackEvent; -import androidx.annotation.FloatRange; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Px; @@ -360,9 +362,10 @@ public class WidgetsFullSheet extends BaseWidgetSheet } @Override - public void onBackProgressed(@FloatRange(from = 0.0, to = 1.0) float progress) { - super.onBackProgressed(progress); - mFastScroller.setVisibility(progress > 0 ? View.INVISIBLE : View.VISIBLE); + @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + public void onBackProgressed(@NonNull BackEvent backEvent) { + super.onBackProgressed(backEvent); + mFastScroller.setVisibility(backEvent.getProgress() > 0 ? View.INVISIBLE : View.VISIBLE); } private void attachScrollbarToRecyclerView(WidgetsRecyclerView recyclerView) {