diff --git a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsSlideInView.java b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsSlideInView.java index 001c3bcfc0..2df98da069 100644 --- a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsSlideInView.java +++ b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsSlideInView.java @@ -168,13 +168,14 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView * previous 3 don't. */ @NonNull - @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) - protected OnBackAnimationCallback getOnBackAnimationCallback() { + protected OnBackPressedHandler getOnBackPressedHandler() { // #1 auto cancel action mode handler if (isInAutoCancelActionMode()) { return this::finishAutoCancelActionMode; @@ -655,16 +655,17 @@ public class Launcher extends StatefulActivity } // #4 state handler - return new OnBackAnimationCallback() { + return new OnBackPressedHandler() { @Override public void onBackInvoked() { onStateBack(); } @Override - public void onBackProgressed(@NonNull BackEvent backEvent) { + public void onBackProgressed( + @FloatRange(from = 0.0, to = 1.0) float backProgress) { mStateManager.getState().onBackProgressed( - Launcher.this, backEvent.getProgress()); + Launcher.this, backProgress); } @Override @@ -2198,7 +2199,7 @@ public class Launcher extends StatefulActivity @Override @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) public void onBackPressed() { - getOnBackAnimationCallback().onBackInvoked(); + getOnBackPressedHandler().onBackInvoked(); } protected void onStateBack() { diff --git a/src/com/android/launcher3/OnBackPressedHandler.java b/src/com/android/launcher3/OnBackPressedHandler.java new file mode 100644 index 0000000000..b3dc37f7e0 --- /dev/null +++ b/src/com/android/launcher3/OnBackPressedHandler.java @@ -0,0 +1,45 @@ +/* + * 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() {} +} \ No newline at end of file diff --git a/src/com/android/launcher3/views/AbstractSlideInView.java b/src/com/android/launcher3/views/AbstractSlideInView.java index 4d497f3768..e2057827bd 100644 --- a/src/com/android/launcher3/views/AbstractSlideInView.java +++ b/src/com/android/launcher3/views/AbstractSlideInView.java @@ -40,6 +40,7 @@ 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; @@ -294,11 +295,9 @@ public abstract class AbstractSlideInView } @Override - @RequiresApi(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; + public void onBackProgressed(float backProgress) { + float deceleratedProgress = Interpolators.PREDICTIVE_BACK_DECELERATED_EASE.getInterpolation(backProgress); + mIsBackProgressing = backProgress > 0f; mSlideInViewScale.updateValue(PREDICTIVE_BACK_MIN_SCALE + (1 - PREDICTIVE_BACK_MIN_SCALE) * (1 - deceleratedProgress)); } diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java index 3e79b5db0e..16aeeea6c2 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java @@ -305,9 +305,9 @@ public class WidgetsFullSheet extends BaseWidgetSheet @Override @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) - public void onBackProgressed(@NonNull BackEvent backEvent) { - super.onBackProgressed(backEvent); - mFastScroller.setVisibility(backEvent.getProgress() > 0 ? View.INVISIBLE : View.VISIBLE); + public void onBackProgressed(float backProgress) { + super.onBackProgressed(backProgress); + mFastScroller.setVisibility(backProgress > 0 ? View.INVISIBLE : View.VISIBLE); } private void attachScrollbarToRecyclerView(WidgetsRecyclerView recyclerView) {