Merge "Ignore events that occur between app icons on the taskbar" into main

This commit is contained in:
Treehugger Robot
2024-11-27 20:22:17 +00:00
committed by Android (Google) Code Review
7 changed files with 58 additions and 23 deletions
@@ -1314,7 +1314,8 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
// If the task bar is not start aligned, the navigation bar is located in the center
// between the taskbar and screen edges, depending on the bubble bar location.
float navbarWidth = mNavButtonContainer.getWidth();
Rect taskbarBounds = mControllers.taskbarViewController.getIconLayoutBounds();
Rect taskbarBounds = mControllers.taskbarViewController
.getTransientTaskbarIconLayoutBoundsInParent();
if (isNavbarOnRight) {
if (mNavButtonsView.isLayoutRtl()) {
float taskBarEnd = taskbarBounds.right;
@@ -1334,8 +1335,10 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
public void onLayoutsUpdated() {
// no need to do anything if on phone, or if taskbar or navbar views were not placed on
// screen.
Rect transientTaskbarIconLayoutBoundsInParent = mControllers.taskbarViewController
.getTransientTaskbarIconLayoutBoundsInParent();
if (mContext.getDeviceProfile().isPhone
|| mControllers.taskbarViewController.getIconLayoutBounds().isEmpty()
|| transientTaskbarIconLayoutBoundsInParent.isEmpty()
|| mNavButtonsView.getWidth() == 0) {
return;
}
@@ -212,7 +212,8 @@ public class StashedHandleViewController implements TaskbarControllers.LoggableT
* morphs into the size of where the taskbar icons will be.
*/
public Animator createRevealAnimToIsStashed(boolean isStashed) {
Rect visualBounds = mControllers.taskbarViewController.getIconLayoutVisualBounds();
Rect visualBounds = mControllers.taskbarViewController
.getTransientTaskbarIconLayoutBounds();
float startRadius = mStashedHandleRadius;
if (DisplayController.isTransientTaskbar(mActivity)) {
@@ -764,7 +764,7 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
) {
return 0;
}
Rect iconsBounds = getIconLayoutBounds();
Rect iconsBounds = getTransientTaskbarIconLayoutBoundsInParent();
return getTaskBarIconsEndForBubbleBarLocation(location) - iconsBounds.right;
}
@@ -892,26 +892,46 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
}
/**
* Returns whether the given MotionEvent, *in screen coorindates*, is within any Taskbar item's
* Returns whether the given MotionEvent, *in screen coordinates*, is within any Taskbar item's
* touch bounds.
*/
public boolean isEventOverAnyItem(MotionEvent ev) {
getLocationOnScreen(mTempOutLocation);
int xInOurCoordinates = (int) ev.getX() - mTempOutLocation[0];
int yInOurCoorindates = (int) ev.getY() - mTempOutLocation[1];
return isShown() && mIconLayoutBounds.contains(xInOurCoordinates, yInOurCoorindates);
int xInOurCoordinates = (int) ev.getRawX() - mTempOutLocation[0];
int yInOurCoordinates = (int) ev.getRawY() - mTempOutLocation[1];
return isShown() && getTaskbarIconsActualBounds().contains(xInOurCoordinates,
yInOurCoordinates);
}
/**
* Returns the current visual taskbar icons bounds (unlike `mIconLayoutBounds` which contains
* bounds for transient mode only).
*/
private Rect getTaskbarIconsActualBounds() {
View[] iconViews = getIconViews();
if (iconViews.length == 0) {
return new Rect();
}
int[] firstIconViewLocation = new int[2];
int[] lastIconViewLocation = new int[2];
iconViews[0].getLocationOnScreen(firstIconViewLocation);
iconViews[iconViews.length - 1].getLocationOnScreen(lastIconViewLocation);
return new Rect(firstIconViewLocation[0], 0, lastIconViewLocation[0] + mIconTouchSize,
getHeight());
}
/**
* Gets visual bounds of the taskbar view. The visual bounds correspond to the taskbar touch
* area, rather than layout placement in the parent view.
*/
public Rect getIconLayoutVisualBounds() {
public Rect getTransientTaskbarIconLayoutBounds() {
return new Rect(mIconLayoutBounds);
}
/** Gets taskbar layout bounds in parent view. */
public Rect getIconLayoutBounds() {
public Rect getTransientTaskbarIconLayoutBoundsInParent() {
Rect actualBounds = new Rect(mIconLayoutBounds);
actualBounds.top = getTop();
actualBounds.bottom = getBottom();
@@ -203,6 +203,10 @@ public class TaskbarViewCallbacks {
private class TaskbarViewGestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDown(@NonNull MotionEvent event) {
if (event.isFromSource(InputDevice.SOURCE_MOUSE)
&& event.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
maybeShowPinningView(event);
}
return true;
}
@@ -212,11 +216,16 @@ public class TaskbarViewCallbacks {
}
@Override
public void onLongPress(MotionEvent event) {
if (DisplayController.isPinnedTaskbar(mActivity)) {
mControllers.taskbarPinningController.showPinningView(mTaskbarView,
event.getRawX());
public void onLongPress(@NonNull MotionEvent event) {
maybeShowPinningView(event);
}
private void maybeShowPinningView(@NonNull MotionEvent event) {
if (!DisplayController.isPinnedTaskbar(mActivity) || mTaskbarView.isEventOverAnyItem(
event)) {
return;
}
mControllers.taskbarPinningController.showPinningView(mTaskbarView, event.getRawX());
}
}
}
@@ -356,12 +356,12 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
return mTaskbarView.getMaxNumIconViews();
}
public Rect getIconLayoutVisualBounds() {
return mTaskbarView.getIconLayoutVisualBounds();
public Rect getTransientTaskbarIconLayoutBounds() {
return mTaskbarView.getTransientTaskbarIconLayoutBounds();
}
public Rect getIconLayoutBounds() {
return mTaskbarView.getIconLayoutBounds();
public Rect getTransientTaskbarIconLayoutBoundsInParent() {
return mTaskbarView.getTransientTaskbarIconLayoutBoundsInParent();
}
public View[] getIconViews() {
@@ -559,14 +559,14 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
if (mControllers.getSharedState().startTaskbarVariantIsTransient) {
float transY =
mTransientTaskbarDp.taskbarBottomMargin + (mTransientTaskbarDp.taskbarHeight
- mTaskbarView.getIconLayoutVisualBounds().bottom)
- mTaskbarView.getTransientTaskbarIconLayoutBounds().bottom)
- (mPersistentTaskbarDp.taskbarHeight
- mTransientTaskbarDp.taskbarIconSize) / 2f;
taskbarIconTranslationYForPinningValue = mapRange(scale, 0f, transY);
} else {
float transY =
-mTransientTaskbarDp.taskbarBottomMargin + (mPersistentTaskbarDp.taskbarHeight
- mTaskbarView.getIconLayoutVisualBounds().bottom)
- mTaskbarView.getTransientTaskbarIconLayoutBounds().bottom)
- (mTransientTaskbarDp.taskbarHeight
- mTransientTaskbarDp.taskbarIconSize) / 2f;
taskbarIconTranslationYForPinningValue = mapRange(scale, transY, 0f);
@@ -102,7 +102,8 @@ public class BubbleControllers {
new TaskbarViewPropertiesProvider() {
@Override
public Rect getTaskbarViewBounds() {
return taskbarControllers.taskbarViewController.getIconLayoutBounds();
return taskbarControllers.taskbarViewController
.getTransientTaskbarIconLayoutBoundsInParent();
}
@Override
@@ -272,7 +272,8 @@ class TaskbarOverflowTest {
private val taskbarIconsCentered: Boolean
get() {
return getOnUiThread {
val iconLayoutBounds = taskbarViewController.iconLayoutBounds
val iconLayoutBounds =
taskbarViewController.transientTaskbarIconLayoutBoundsInParent
val availableWidth = taskbarUnitTestRule.activityContext.deviceProfile.widthPx
iconLayoutBounds.left - (availableWidth - iconLayoutBounds.right) < 2
}
@@ -282,7 +283,7 @@ class TaskbarOverflowTest {
get() {
return getOnUiThread {
taskbarUnitTestRule.activityContext.deviceProfile.widthPx -
taskbarViewController.iconLayoutBounds.right
taskbarViewController.transientTaskbarIconLayoutBoundsInParent.right
}
}