Handle swipe down on taskbar to stash

- Moved all touch-to-stash logic to new TaskbarStashViaTouchController
  (handles both tap outside to stash instantly as well as swipe down
  inside to stash after letting go)
- This is a TouchController on TaskbarDragLayer, so it intercepts
  touches from TaskbarView before icons can be dragged during swipe down

Test: swipe up to invoke transient taskbar in an app, swipe down or
touch outside to stash
Flag: ENABLE_TRANSIENT_TASKBAR=true
Fixes: 246631710

Change-Id: I5cf64848bba34ad32fcc80a93fb4f79ebd2c10a7
This commit is contained in:
Tony Wickham
2023-03-17 23:49:09 +00:00
parent fad8c1c449
commit c73db73a79
10 changed files with 162 additions and 153 deletions

View File

@@ -18,15 +18,12 @@ package com.android.launcher3.taskbar;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.ViewTreeObserver;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.anim.AnimatedFloat;
import com.android.launcher3.testing.shared.ResourceUtils;
import com.android.launcher3.util.DimensionUtils;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.TouchController;
import java.io.PrintWriter;
@@ -40,7 +37,6 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa
private final TaskbarActivityContext mActivity;
private final TaskbarDragLayer mTaskbarDragLayer;
private final int mFolderMargin;
private float mGestureHeightYThreshold;
// Alpha properties for taskbar background.
private final AnimatedFloat mBgTaskbar = new AnimatedFloat(this::updateBackgroundAlpha);
@@ -59,6 +55,7 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa
// Initialized in init.
private TaskbarControllers mControllers;
private TaskbarStashViaTouchController mTaskbarStashViaTouchController;
private AnimatedFloat mOnBackgroundNavButtonColorIntensity;
private float mLastSetBackgroundAlpha;
@@ -69,11 +66,11 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa
mTaskbarDragLayer = taskbarDragLayer;
final Resources resources = mTaskbarDragLayer.getResources();
mFolderMargin = resources.getDimensionPixelSize(R.dimen.taskbar_folder_margin);
updateGestureHeight();
}
public void init(TaskbarControllers controllers) {
mControllers = controllers;
mTaskbarStashViaTouchController = new TaskbarStashViaTouchController(mControllers);
mTaskbarDragLayer.init(new TaskbarDragLayerCallbacks());
mOnBackgroundNavButtonColorIntensity = mControllers.navbarButtonsViewController
@@ -130,17 +127,11 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa
return mBgOffset;
}
private void updateGestureHeight() {
int gestureHeight = ResourceUtils.getNavbarSize(ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE,
mActivity.getResources());
mGestureHeightYThreshold = mActivity.getDeviceProfile().heightPx - gestureHeight;
}
/**
* Make updates when configuration changes.
*/
public void onConfigurationChanged() {
updateGestureHeight();
mTaskbarStashViaTouchController.updateGestureHeight();
}
private void updateBackgroundAlpha() {
@@ -206,8 +197,6 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa
*/
public class TaskbarDragLayerCallbacks {
private final int[] mTempOutLocation = new int[2];
/**
* Called to update the touchable insets.
* @see ViewTreeObserver.InternalInsetsInfo#setTouchableInsets(int)
@@ -216,37 +205,6 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa
mControllers.taskbarInsetsController.updateInsetsTouchability(insetsInfo);
}
/**
* Listens to TaskbarDragLayer touch events and responds accordingly.
*/
public void tryStashBasedOnMotionEvent(MotionEvent ev) {
if (!DisplayController.isTransientTaskbar(mActivity)) {
return;
}
if (mControllers.taskbarStashController.isStashed()) {
return;
}
boolean stashTaskbar = false;
MotionEvent screenCoordinates = MotionEvent.obtain(ev);
if (ev.getAction() == MotionEvent.ACTION_OUTSIDE) {
stashTaskbar = true;
} else if (ev.getAction() == MotionEvent.ACTION_DOWN) {
mTaskbarDragLayer.getLocationOnScreen(mTempOutLocation);
screenCoordinates.offsetLocation(mTempOutLocation[0], mTempOutLocation[1]);
if (!mControllers.taskbarViewController.isEventOverAnyItem(screenCoordinates)
&& screenCoordinates.getY() < mGestureHeightYThreshold) {
stashTaskbar = true;
}
}
if (stashTaskbar) {
mControllers.taskbarStashController.updateAndAnimateTransientTaskbar(true);
}
}
/**
* Called when a child is removed from TaskbarDragLayer.
*/
@@ -276,9 +234,12 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa
* Returns touch controllers.
*/
public TouchController[] getTouchControllers() {
return new TouchController[]{mActivity.getDragController(),
return new TouchController[] {
mActivity.getDragController(),
mControllers.taskbarForceVisibleImmersiveController,
mControllers.navbarButtonsViewController.getTouchController()};
mControllers.navbarButtonsViewController.getTouchController(),
mTaskbarStashViaTouchController,
};
}
}
}