Merge "[Predictive Back] Remove OnBackPressedHandler" into udc-dev am: d44129149c

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/22102382

Change-Id: I8027353d2ce0fc096fbcf0e3b69f505052e5cbb4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Fengjiang Li
2023-03-16 21:55:58 +00:00
committed by Automerger Merge Worker
7 changed files with 48 additions and 106 deletions
@@ -23,8 +23,6 @@ import android.graphics.Rect;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.animation.Interpolator; import android.view.animation.Interpolator;
import android.window.BackEvent;
import android.window.OnBackAnimationCallback;
import android.window.OnBackInvokedDispatcher; import android.window.OnBackInvokedDispatcher;
import com.android.launcher3.DeviceProfile; import com.android.launcher3.DeviceProfile;
@@ -57,28 +55,6 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView<TaskbarOverla
mAllAppsCallbacks = callbacks; mAllAppsCallbacks = callbacks;
} }
private final OnBackAnimationCallback mOnBackAnimationCallback = new OnBackAnimationCallback() {
@Override
public void onBackCancelled() {
TaskbarAllAppsSlideInView.this.onBackCancelled();
}
@Override
public void onBackInvoked() {
TaskbarAllAppsSlideInView.this.onBackInvoked();
}
@Override
public void onBackProgressed(BackEvent backEvent) {
TaskbarAllAppsSlideInView.this.onBackProgressed(backEvent.getProgress());
}
@Override
public void onBackStarted(BackEvent backEvent) {
TaskbarAllAppsSlideInView.this.onBackStarted();
}
};
/** Opens the all apps view. */ /** Opens the all apps view. */
void show(boolean animate) { void show(boolean animate) {
if (mIsOpen || mOpenCloseAnimator.isRunning()) { if (mIsOpen || mOpenCloseAnimator.isRunning()) {
@@ -100,7 +76,7 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView<TaskbarOverla
mAppsView.getAppsRecyclerViewContainer().setOutlineProvider(mViewOutlineProvider); mAppsView.getAppsRecyclerViewContainer().setOutlineProvider(mViewOutlineProvider);
mAppsView.getAppsRecyclerViewContainer().setClipToOutline(true); mAppsView.getAppsRecyclerViewContainer().setClipToOutline(true);
findOnBackInvokedDispatcher().registerOnBackInvokedCallback( findOnBackInvokedDispatcher().registerOnBackInvokedCallback(
OnBackInvokedDispatcher.PRIORITY_DEFAULT, mOnBackAnimationCallback); OnBackInvokedDispatcher.PRIORITY_DEFAULT, this);
} }
} }
@@ -113,7 +89,7 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView<TaskbarOverla
protected void handleClose(boolean animate) { protected void handleClose(boolean animate) {
handleClose(animate, mAllAppsCallbacks.getCloseDuration()); handleClose(animate, mAllAppsCallbacks.getCloseDuration());
if (FeatureFlags.ENABLE_BACK_SWIPE_LAUNCHER_ANIMATION.get()) { if (FeatureFlags.ENABLE_BACK_SWIPE_LAUNCHER_ANIMATION.get()) {
findOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(mOnBackAnimationCallback); findOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(this);
} }
} }
@@ -97,7 +97,6 @@ import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher; import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.LauncherState; import com.android.launcher3.LauncherState;
import com.android.launcher3.OnBackPressedHandler;
import com.android.launcher3.QuickstepAccessibilityDelegate; import com.android.launcher3.QuickstepAccessibilityDelegate;
import com.android.launcher3.QuickstepTransitionManager; import com.android.launcher3.QuickstepTransitionManager;
import com.android.launcher3.R; import com.android.launcher3.R;
@@ -172,7 +171,6 @@ import com.android.quickstep.views.FloatingTaskView;
import com.android.quickstep.views.OverviewActionsView; import com.android.quickstep.views.OverviewActionsView;
import com.android.quickstep.views.RecentsView; import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView; import com.android.quickstep.views.TaskView;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.system.ActivityManagerWrapper; import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.unfold.RemoteUnfoldSharedComponent; import com.android.systemui.unfold.RemoteUnfoldSharedComponent;
import com.android.systemui.unfold.UnfoldSharedComponent; import com.android.systemui.unfold.UnfoldSharedComponent;
@@ -192,7 +190,6 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -745,48 +742,50 @@ public class QuickstepLauncher extends Launcher {
OnBackInvokedDispatcher.PRIORITY_DEFAULT, OnBackInvokedDispatcher.PRIORITY_DEFAULT,
new OnBackAnimationCallback() { new OnBackAnimationCallback() {
@Nullable OnBackPressedHandler mActiveOnBackPressedHandler; @Nullable OnBackAnimationCallback mActiveOnBackAnimationCallback;
@Override @Override
public void onBackStarted(@NonNull BackEvent backEvent) { public void onBackStarted(@NonNull BackEvent backEvent) {
if (mActiveOnBackPressedHandler != null) { if (mActiveOnBackAnimationCallback != null) {
mActiveOnBackPressedHandler.onBackCancelled(); mActiveOnBackAnimationCallback.onBackCancelled();
} }
mActiveOnBackPressedHandler = getOnBackPressedHandler(); mActiveOnBackAnimationCallback = getOnBackAnimationCallback();
mActiveOnBackPressedHandler.onBackStarted(); mActiveOnBackAnimationCallback.onBackStarted(backEvent);
} }
@Override @Override
public void onBackInvoked() { public void onBackInvoked() {
// Recreate mActiveOnBackPressedHandler if necessary to avoid NPE because: // Recreate mActiveOnBackAnimationCallback if necessary to avoid NPE
// because:
// 1. b/260636433: In 3-button-navigation mode, onBackStarted() is not // 1. b/260636433: In 3-button-navigation mode, onBackStarted() is not
// called on ACTION_DOWN before onBackInvoked() is called in ACTION_UP. // called on ACTION_DOWN before onBackInvoked() is called in ACTION_UP.
// 2. Launcher#onBackPressed() will call onBackInvoked() without calling // 2. Launcher#onBackPressed() will call onBackInvoked() without calling
// onBackInvoked() beforehand. // onBackInvoked() beforehand.
if (mActiveOnBackPressedHandler == null) { if (mActiveOnBackAnimationCallback == null) {
mActiveOnBackPressedHandler = getOnBackPressedHandler(); mActiveOnBackAnimationCallback = getOnBackAnimationCallback();
} }
mActiveOnBackPressedHandler.onBackInvoked(); mActiveOnBackAnimationCallback.onBackInvoked();
mActiveOnBackPressedHandler = null; mActiveOnBackAnimationCallback = null;
TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onBackInvoked"); TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onBackInvoked");
} }
@Override @Override
public void onBackProgressed(@NonNull BackEvent backEvent) { public void onBackProgressed(@NonNull BackEvent backEvent) {
if (!FeatureFlags.IS_STUDIO_BUILD && mActiveOnBackPressedHandler == null) { if (!FeatureFlags.IS_STUDIO_BUILD
&& mActiveOnBackAnimationCallback == null) {
return; return;
} }
mActiveOnBackPressedHandler mActiveOnBackAnimationCallback.onBackProgressed(backEvent);
.onBackProgressed(backEvent.getProgress());
} }
@Override @Override
public void onBackCancelled() { public void onBackCancelled() {
if (!FeatureFlags.IS_STUDIO_BUILD && mActiveOnBackPressedHandler == null) { if (!FeatureFlags.IS_STUDIO_BUILD
&& mActiveOnBackAnimationCallback == null) {
return; return;
} }
mActiveOnBackPressedHandler.onBackCancelled(); mActiveOnBackAnimationCallback.onBackCancelled();
mActiveOnBackPressedHandler = null; mActiveOnBackAnimationCallback = null;
} }
}); });
} }
@@ -24,7 +24,9 @@ import static com.android.launcher3.compat.AccessibilityManagerCompat.isAccessib
import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustomAccessibilityEvent; import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustomAccessibilityEvent;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Pair; import android.util.Pair;
import android.view.MotionEvent; import android.view.MotionEvent;
@@ -32,6 +34,7 @@ import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.Interpolator; import android.view.animation.Interpolator;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.window.OnBackAnimationCallback;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
@@ -46,8 +49,9 @@ import java.lang.annotation.RetentionPolicy;
/** /**
* Base class for a View which shows a floating UI on top of the launcher UI. * Base class for a View which shows a floating UI on top of the launcher UI.
*/ */
@TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
public abstract class AbstractFloatingView extends LinearLayout implements TouchController, public abstract class AbstractFloatingView extends LinearLayout implements TouchController,
OnBackPressedHandler { OnBackAnimationCallback {
@IntDef(flag = true, value = { @IntDef(flag = true, value = {
TYPE_FOLDER, TYPE_FOLDER,
+10 -8
View File
@@ -116,9 +116,10 @@ import android.view.WindowManager.LayoutParams;
import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent;
import android.view.animation.OvershootInterpolator; import android.view.animation.OvershootInterpolator;
import android.widget.Toast; import android.widget.Toast;
import android.window.BackEvent;
import android.window.OnBackAnimationCallback;
import androidx.annotation.CallSuper; import androidx.annotation.CallSuper;
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
@@ -560,7 +561,7 @@ public class Launcher extends StatefulActivity<LauncherState>
} }
/** /**
* Provide {@link OnBackPressedHandler} in below order: * Provide {@link OnBackAnimationCallback} in below order:
* <ol> * <ol>
* <li> auto cancel action mode handler * <li> auto cancel action mode handler
* <li> drag handler * <li> drag handler
@@ -575,7 +576,8 @@ public class Launcher extends StatefulActivity<LauncherState>
* Note that state handler will always be handling the back press event if the previous 3 don't. * Note that state handler will always be handling the back press event if the previous 3 don't.
*/ */
@NonNull @NonNull
protected OnBackPressedHandler getOnBackPressedHandler() { @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
protected OnBackAnimationCallback getOnBackAnimationCallback() {
// #1 auto cancel action mode handler // #1 auto cancel action mode handler
if (isInAutoCancelActionMode()) { if (isInAutoCancelActionMode()) {
return this::finishAutoCancelActionMode; return this::finishAutoCancelActionMode;
@@ -594,17 +596,16 @@ public class Launcher extends StatefulActivity<LauncherState>
} }
// #4 state handler // #4 state handler
return new OnBackPressedHandler() { return new OnBackAnimationCallback() {
@Override @Override
public void onBackInvoked() { public void onBackInvoked() {
onStateBack(); onStateBack();
} }
@Override @Override
public void onBackProgressed( public void onBackProgressed(@NonNull BackEvent backEvent) {
@FloatRange(from = 0.0, to = 1.0) float backProgress) {
mStateManager.getState().onBackProgressed( mStateManager.getState().onBackProgressed(
Launcher.this, backProgress); Launcher.this, backEvent.getProgress());
} }
@Override @Override
@@ -2117,8 +2118,9 @@ public class Launcher extends StatefulActivity<LauncherState>
} }
@Override @Override
@TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
public void onBackPressed() { public void onBackPressed() {
getOnBackPressedHandler().onBackInvoked(); getOnBackAnimationCallback().onBackInvoked();
} }
protected void onStateBack() { protected void onStateBack() {
@@ -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}.
*
* <p> Impl can assume below order during a back gesture:
* <ol>
* <li> [optional] one {@link #onBackStarted()} will be called to start the gesture
* <li> zero or multiple {@link #onBackProgressed(float)} will be called during swipe gesture
* <li> 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() {}
}
@@ -28,10 +28,12 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder; import android.animation.PropertyValuesHolder;
import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Outline; import android.graphics.Outline;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Property; import android.util.Property;
import android.view.MotionEvent; import android.view.MotionEvent;
@@ -39,8 +41,8 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewOutlineProvider; import android.view.ViewOutlineProvider;
import android.view.animation.Interpolator; import android.view.animation.Interpolator;
import android.window.BackEvent;
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.Px; import androidx.annotation.Px;
@@ -193,8 +195,9 @@ public abstract class AbstractSlideInView<T extends Context & ActivityContext>
} }
@Override @Override
public void onBackProgressed(@FloatRange(from = 0.0, to = 1.0) float progress) { @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
super.onBackProgressed(progress); public void onBackProgressed(BackEvent backEvent) {
final float progress = backEvent.getProgress();
float deceleratedProgress = float deceleratedProgress =
Interpolators.PREDICTIVE_BACK_DECELERATED_EASE.getInterpolation(progress); Interpolators.PREDICTIVE_BACK_DECELERATED_EASE.getInterpolation(progress);
mIsBackProgressing = progress > 0f; mIsBackProgressing = progress > 0f;
@@ -25,11 +25,13 @@ import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORD
import android.animation.Animator; import android.animation.Animator;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.animation.PropertyValuesHolder; import android.animation.PropertyValuesHolder;
import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.pm.LauncherApps; import android.content.pm.LauncherApps;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Build;
import android.os.Process; import android.os.Process;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
@@ -47,8 +49,8 @@ import android.widget.Button;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.window.BackEvent;
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.Px; import androidx.annotation.Px;
@@ -360,9 +362,10 @@ public class WidgetsFullSheet extends BaseWidgetSheet
} }
@Override @Override
public void onBackProgressed(@FloatRange(from = 0.0, to = 1.0) float progress) { @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
super.onBackProgressed(progress); public void onBackProgressed(@NonNull BackEvent backEvent) {
mFastScroller.setVisibility(progress > 0 ? View.INVISIBLE : View.VISIBLE); super.onBackProgressed(backEvent);
mFastScroller.setVisibility(backEvent.getProgress() > 0 ? View.INVISIBLE : View.VISIBLE);
} }
private void attachScrollbarToRecyclerView(WidgetsRecyclerView recyclerView) { private void attachScrollbarToRecyclerView(WidgetsRecyclerView recyclerView) {