Implementing TouchDelegate to make full chip clickable.

Merging to ub-launcher3-master manually as automerger failed.
Tested: Manual

Change-Id: I1b8b43de7f04e1e13cb283c88f95a7c6fea84ea6
This commit is contained in:
Sreyas committed 2020-08-28 12:10:55 -07:00
1 parent d4d2a73b67
commit 90faa282f1
2 files changed
+37 -9

No files matched your search

@@ -135,6 +135,7 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
* delegated bounds only to be updated.
*/
private TransformingTouchDelegate mIconTouchDelegate;
private TransformingTouchDelegate mChipTouchDelegate;
private static final List<Rect> SYSTEM_GESTURE_EXCLUSION_RECT =
Collections.singletonList(new Rect());
@@ -200,6 +201,7 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
private View mContextualChipWrapper;
private View mContextualChip;
private final float[] mIconCenterCoords = new float[2];
private final float[] mChipCenterCoords = new float[2];
public TaskView(Context context) {
this(context, null);
@@ -259,11 +261,22 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
mIconTouchDelegate = new TransformingTouchDelegate(mIconView);
}
public TouchDelegate getIconTouchDelegate(MotionEvent event) {
/**
* Whether the taskview should take the touch event from parent. Events passed to children
* that might require special handling.
*/
public boolean offerTouchToChildren(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
computeAndSetIconTouchDelegate();
computeAndSetChipTouchDelegate();
}
return mIconTouchDelegate;
if (mIconTouchDelegate != null && mIconTouchDelegate.onTouchEvent(event)) {
return true;
}
if (mChipTouchDelegate != null && mChipTouchDelegate.onTouchEvent(event)) {
return true;
}
return false;
}
private void computeAndSetIconTouchDelegate() {
@@ -278,6 +291,23 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
(int) (mIconCenterCoords[1] + iconHalfSize));
}
private void computeAndSetChipTouchDelegate() {
if (mContextualChipWrapper != null) {
float chipHalfWidth = mContextualChipWrapper.getWidth() / 2f;
float chipHalfHeight = mContextualChipWrapper.getHeight() / 2f;
mChipCenterCoords[0] = chipHalfWidth;
mChipCenterCoords[1] = chipHalfHeight;
getDescendantCoordRelativeToAncestor(mContextualChipWrapper, mActivity.getDragLayer(),
mChipCenterCoords,
false);
mChipTouchDelegate.setBounds(
(int) (mChipCenterCoords[0] - chipHalfWidth),
(int) (mChipCenterCoords[1] - chipHalfHeight),
(int) (mChipCenterCoords[0] + chipHalfWidth),
(int) (mChipCenterCoords[1] + chipHalfHeight));
}
}
/**
* The modalness of this view is how it should be displayed when it is shown on its own in the
* modal state of overview.
@@ -712,6 +742,7 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
mContextualChip.animate().scaleX(1f).scaleY(1f).setDuration(50);
}
if (mContextualChipWrapper != null) {
mChipTouchDelegate = new TransformingTouchDelegate(mContextualChipWrapper);
mContextualChipWrapper.animate().alpha(1f).setDuration(50);
}
}
@@ -733,6 +764,7 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
View oldContextualChipWrapper = mContextualChipWrapper;
mContextualChipWrapper = null;
mContextualChip = null;
mChipTouchDelegate = null;
return oldContextualChipWrapper;
}