diff options
-rw-r--r-- | src/com/android/launcher3/DragLayer.java | 32 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherAppWidgetHostView.java | 13 |
2 files changed, 38 insertions, 7 deletions
diff --git a/src/com/android/launcher3/DragLayer.java b/src/com/android/launcher3/DragLayer.java index 3c955cbe3..89f8275bf 100644 --- a/src/com/android/launcher3/DragLayer.java +++ b/src/com/android/launcher3/DragLayer.java @@ -69,6 +69,8 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang public static final int ANIMATION_END_FADE_OUT = 1; public static final int ANIMATION_END_REMAIN_VISIBLE = 2; + private TouchCompleteListener mTouchCompleteListener; + private final Rect mInsets = new Rect(); /** @@ -173,10 +175,17 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - if (ev.getAction() == MotionEvent.ACTION_DOWN) { + int action = ev.getAction(); + + if (action == MotionEvent.ACTION_DOWN) { if (handleTouchDown(ev, true)) { return true; } + } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { + if (mTouchCompleteListener != null) { + mTouchCompleteListener.onTouchComplete(); + } + mTouchCompleteListener = null; } clearAllResizeFrames(); return mDragController.onInterceptTouchEvent(ev); @@ -278,12 +287,15 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang int x = (int) ev.getX(); int y = (int) ev.getY(); - if (ev.getAction() == MotionEvent.ACTION_DOWN) { - if (ev.getAction() == MotionEvent.ACTION_DOWN) { - if (handleTouchDown(ev, false)) { - return true; - } + if (action == MotionEvent.ACTION_DOWN) { + if (handleTouchDown(ev, false)) { + return true; + } + } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { + if (mTouchCompleteListener != null) { + mTouchCompleteListener.onTouchComplete(); } + mTouchCompleteListener = null; } if (mCurrentResizeFrame != null) { @@ -818,4 +830,12 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang } } } + + public void setTouchCompleteListener(TouchCompleteListener listener) { + mTouchCompleteListener = listener; + } + + public interface TouchCompleteListener { + public void onTouchComplete(); + } } diff --git a/src/com/android/launcher3/LauncherAppWidgetHostView.java b/src/com/android/launcher3/LauncherAppWidgetHostView.java index 59bd307f2..83aef1a2f 100644 --- a/src/com/android/launcher3/LauncherAppWidgetHostView.java +++ b/src/com/android/launcher3/LauncherAppWidgetHostView.java @@ -24,20 +24,24 @@ import android.view.View; import android.view.ViewGroup; import android.widget.RemoteViews; +import com.android.launcher3.DragLayer.TouchCompleteListener; + /** * {@inheritDoc} */ -public class LauncherAppWidgetHostView extends AppWidgetHostView { +public class LauncherAppWidgetHostView extends AppWidgetHostView implements TouchCompleteListener { private CheckLongPressHelper mLongPressHelper; private LayoutInflater mInflater; private Context mContext; private int mPreviousOrientation; + private DragLayer mDragLayer; public LauncherAppWidgetHostView(Context context) { super(context); mContext = context; mLongPressHelper = new CheckLongPressHelper(this); mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mDragLayer = ((Launcher) context).getDragLayer(); } @Override @@ -72,6 +76,7 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: { mLongPressHelper.postCheckForLongPress(); + mDragLayer.setTouchCompleteListener(this); break; } @@ -100,7 +105,11 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView { @Override public void cancelLongPress() { super.cancelLongPress(); + mLongPressHelper.cancelLongPress(); + } + @Override + public void onTouchComplete() { mLongPressHelper.cancelLongPress(); } @@ -108,4 +117,6 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView { public int getDescendantFocusability() { return ViewGroup.FOCUS_BLOCK_DESCENDANTS; } + + } |