Merge "Fix widget longpress issue where longpress misfires (issue 10988288)" into jb-ub-now-indigo-rose

This commit is contained in:
Adam Cohen
2013-10-09 18:20:24 +00:00
committed by Android (Google) Code Review
2 changed files with 38 additions and 7 deletions
+26 -6
View File
@@ -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();
}
}
@@ -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;
}
}