summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-09-15 12:32:28 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-09-15 13:37:13 -0700
commit1cc48e1d0c0bd30bc59cc37c4d49ee78b01424f0 (patch)
tree9a57d9f4d96959cd5effc131c71b01a54e3cd9f0
parentda1c17c492d7e253a08a47dd2d79637177c4401d (diff)
downloadandroid_packages_apps_Trebuchet-1cc48e1d0c0bd30bc59cc37c4d49ee78b01424f0.tar.gz
android_packages_apps_Trebuchet-1cc48e1d0c0bd30bc59cc37c4d49ee78b01424f0.tar.bz2
android_packages_apps_Trebuchet-1cc48e1d0c0bd30bc59cc37c4d49ee78b01424f0.zip
Adding support for extending the touch target in the touchDelegate
Bug: 31458312 Change-Id: Ic819bdede2776ff63ec17053cc1326415edc1ca0
-rw-r--r--src/com/android/launcher3/util/TransformingTouchDelegate.java29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/com/android/launcher3/util/TransformingTouchDelegate.java b/src/com/android/launcher3/util/TransformingTouchDelegate.java
index da1de5e77..3197ba946 100644
--- a/src/com/android/launcher3/util/TransformingTouchDelegate.java
+++ b/src/com/android/launcher3/util/TransformingTouchDelegate.java
@@ -33,6 +33,10 @@ public class TransformingTouchDelegate extends TouchDelegate {
private final RectF mBounds;
+ private final RectF mTouchCheckBounds;
+ private float mTouchExtension;
+ private boolean mWasTouchOutsideBounds;
+
private View mDelegateView;
private boolean mDelegateTargeted;
@@ -41,10 +45,22 @@ public class TransformingTouchDelegate extends TouchDelegate {
mDelegateView = delegateView;
mBounds = new RectF();
+ mTouchCheckBounds = new RectF();
}
public void setBounds(int left, int top, int right, int bottom) {
mBounds.set(left, top, right, bottom);
+ updateTouchBounds();
+ }
+
+ public void extendTouchBounds(float extension) {
+ mTouchExtension = extension;
+ updateTouchBounds();
+ }
+
+ private void updateTouchBounds() {
+ mTouchCheckBounds.set(mBounds);
+ mTouchCheckBounds.inset(-mTouchExtension, -mTouchExtension);
}
public void setDelegateView(View view) {
@@ -62,8 +78,9 @@ public class TransformingTouchDelegate extends TouchDelegate {
boolean sendToDelegate = false;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
- mDelegateTargeted = mBounds.contains(event.getX(), event.getY());
+ mDelegateTargeted = mTouchCheckBounds.contains(event.getX(), event.getY());
if (mDelegateTargeted) {
+ mWasTouchOutsideBounds = !mBounds.contains(event.getX(), event.getY());
sendToDelegate = true;
}
break;
@@ -78,9 +95,15 @@ public class TransformingTouchDelegate extends TouchDelegate {
}
boolean handled = false;
if (sendToDelegate) {
- event.offsetLocation(-mBounds.left, -mBounds.top);
+ float x = event.getX();
+ float y = event.getY();
+ if (mWasTouchOutsideBounds) {
+ event.setLocation(mBounds.centerX(), mBounds.centerY());
+ } else {
+ event.offsetLocation(-mBounds.left, -mBounds.top);
+ }
handled = mDelegateView.dispatchTouchEvent(event);
- event.offsetLocation(mBounds.left, mBounds.top);
+ event.setLocation(x, y);
}
return handled;
}