Merge "Fix deep shortcuts RTL issues." into ub-launcher3-calgary

This commit is contained in:
Tony Wickham
2016-07-21 22:26:56 +00:00
committed by Android (Google) Code Review
2 changed files with 38 additions and 26 deletions
@@ -75,7 +75,7 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
private final int mStartDragThreshold;
private BubbleTextView mDeferredDragIcon;
private int mActivePointerId;
private Point mTouchDown = null;
private int[] mTouchDown = null;
private DragView mDragView;
private float mLastX, mLastY;
private float mDistanceDragged = 0;
@@ -236,7 +236,7 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
/**
* Orients this container above or below the given icon, aligning with the left or right.
*
* These are the preferred orientations, in order:
* These are the preferred orientations, in order (RTL prefers right-aligned over left):
* - Above and left-aligned
* - Above and right-aligned
* - Below and left-aligned
@@ -253,16 +253,25 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
DragLayer dragLayer = mLauncher.getDragLayer();
dragLayer.getDescendantRectRelativeToSelf(icon, mTempRect);
// Align left and above by default.
int x = mTempRect.left + icon.getPaddingLeft();
int y = mTempRect.top - height;
Rect insets = dragLayer.getInsets();
mIsLeftAligned = x + width < dragLayer.getRight() - insets.right;
if (!mIsLeftAligned) {
x = mTempRect.right - width - icon.getPaddingRight();
// Align left (right in RTL) if there is room.
boolean isRtl = Utilities.isRtl(getResources());
int leftAlignedX = mTempRect.left + icon.getPaddingLeft();
int rightAlignedX = mTempRect.right - width - icon.getPaddingRight();
int x = leftAlignedX;
boolean canBeLeftAligned = leftAlignedX + width < dragLayer.getRight() - insets.right;
boolean canBeRightAligned = rightAlignedX > dragLayer.getLeft() + insets.left;
if (!canBeLeftAligned || (isRtl && canBeRightAligned)) {
x = rightAlignedX;
}
mIsLeftAligned = x == leftAlignedX;
if (isRtl) {
x -= dragLayer.getWidth() - width;
}
// Open above icon if there is room.
int y = mTempRect.top - height;
mIsAboveIcon = mTempRect.top - height > dragLayer.getTop() + insets.top;
if (!mIsAboveIcon) {
y = mTempRect.bottom;
@@ -304,7 +313,7 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
mDragView.show(motionDownX, motionDownY);
}
public boolean onForwardedEvent(MotionEvent ev, int activePointerId, Point touchDown) {
public boolean onForwardedEvent(MotionEvent ev, int activePointerId, int[] touchDown) {
mActivePointerId = activePointerId;
mTouchDown = touchDown;
return dispatchTouchEvent(ev);
@@ -398,9 +407,9 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
*/
private boolean shouldStartDeferredDrag(int x, int y, boolean containerContainsTouch) {
int closestEdgeY = mIsAboveIcon ? getMeasuredHeight() : 0;
double distToEdge = Math.abs(mTouchDown.y - closestEdgeY);
double newDistToEdge = Math.hypot(x - mTouchDown.x, y - closestEdgeY);
return !containerContainsTouch && (newDistToEdge - distToEdge > mStartDragThreshold);
double distToEdge = Math.abs(mTouchDown[1] - closestEdgeY);
double newDistToEdge = Math.hypot(x - mTouchDown[0], y - closestEdgeY);
return !containerContainsTouch && (newDistToEdge - distToEdge > mStartDragThreshold);
}
public void cleanupDeferredDrag() {
@@ -1,7 +1,6 @@
package com.android.launcher3.shortcuts;
import android.content.Context;
import android.graphics.Point;
import android.os.SystemClock;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
@@ -53,9 +52,9 @@ public class ShortcutsContainerListener implements View.OnTouchListener,
private Launcher mLauncher;
private DragLayer mDragLayer;
private MotionEvent mTouchDownEvent;
/** The coordinates of the touch down, relative do the shortcuts container. */
private final Point mTouchDown;
/** The coordinates of the touch down, relative to the shortcuts container. */
private final int[] mTouchDown;
private boolean mHasMappedTouchDownToContainerCoord;
public ShortcutsContainerListener(BubbleTextView icon) {
mSrcIcon = icon;
@@ -68,7 +67,7 @@ public class ShortcutsContainerListener implements View.OnTouchListener,
mLauncher = Launcher.getLauncher(mSrcIcon.getContext());
mDragLayer = mLauncher.getDragLayer();
mTouchDown = new Point();
mTouchDown = new int[2];
}
@Override
@@ -79,10 +78,10 @@ public class ShortcutsContainerListener implements View.OnTouchListener,
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (mTouchDownEvent != null) {
mTouchDownEvent.recycle();
}
mTouchDownEvent = MotionEvent.obtainNoHistory(event);
mTouchDown[0] = (int) event.getX();
mTouchDown[1] = (int) event.getY();
mDragLayer.getDescendantCoordRelativeToSelf(mSrcIcon, mTouchDown);
mHasMappedTouchDownToContainerCoord = false;
}
final boolean wasForwarding = mForwarding;
@@ -140,10 +139,6 @@ public class ShortcutsContainerListener implements View.OnTouchListener,
deepShortcutsContainer.populateAndShow(mSrcIcon, ids);
mSrcIcon.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
// Convert touch down event to the container's coordinates.
Utilities.translateEventCoordinates(mSrcIcon, deepShortcutsContainer, mTouchDownEvent);
mTouchDown.set((int) mTouchDownEvent.getX(), (int) mTouchDownEvent.getY());
return true;
}
return false;
@@ -257,13 +252,21 @@ public class ShortcutsContainerListener implements View.OnTouchListener,
if (dst == null) {
return false;
}
if (!dst.isLaidOut()) {
return true;
}
// Convert event to destination-local coordinates.
final MotionEvent dstEvent = MotionEvent.obtainNoHistory(srcEvent);
Utilities.translateEventCoordinates(src, dst, dstEvent);
// Convert touch down event to destination-local coordinates.
if (!mHasMappedTouchDownToContainerCoord) {
mDragLayer.mapCoordInSelfToDescendent(dst, mTouchDown);
mHasMappedTouchDownToContainerCoord = true;
}
// Forward converted event to destination view, then recycle it.
// TODO: don't create objects in onForwardedEvent.
final boolean handled = dst.onForwardedEvent(dstEvent, mActivePointerId, mTouchDown);
dstEvent.recycle();