diff options
author | Adam Cohen <adamcohen@google.com> | 2011-03-03 17:26:50 -0800 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2011-03-03 18:30:20 -0800 |
commit | 1b607ed454ed22c2fd855cb3e428376520fb2388 (patch) | |
tree | 09181f6a15782dbe721284b046601db5771588bc /src/com/android/launcher2/CellLayoutChildren.java | |
parent | 3c438bcbd3a0e40141117c5b68a82a8be5ddf140 (diff) | |
download | android_packages_apps_Trebuchet-1b607ed454ed22c2fd855cb3e428376520fb2388.tar.gz android_packages_apps_Trebuchet-1b607ed454ed22c2fd855cb3e428376520fb2388.tar.bz2 android_packages_apps_Trebuchet-1b607ed454ed22c2fd855cb3e428376520fb2388.zip |
Cleaning up widget resizing code
Change-Id: Ib4c0de0080f0b69f873fd88016f23c319a13c6ff
Diffstat (limited to 'src/com/android/launcher2/CellLayoutChildren.java')
-rw-r--r-- | src/com/android/launcher2/CellLayoutChildren.java | 79 |
1 files changed, 39 insertions, 40 deletions
diff --git a/src/com/android/launcher2/CellLayoutChildren.java b/src/com/android/launcher2/CellLayoutChildren.java index 9a0d77276..04996f359 100644 --- a/src/com/android/launcher2/CellLayoutChildren.java +++ b/src/com/android/launcher2/CellLayoutChildren.java @@ -43,6 +43,12 @@ public class CellLayoutChildren extends ViewGroup { private int mWidthGap; private int mHeightGap; + // Variables relating to resizing widgets + private final ArrayList<AppWidgetResizeFrame> mResizeFrames = + new ArrayList<AppWidgetResizeFrame>(); + private AppWidgetResizeFrame mCurrentResizeFrame; + private int mXDown, mYDown; + public CellLayoutChildren(Context context) { super(context); mWallpaperManager = WallpaperManager.getInstance(context); @@ -171,11 +177,6 @@ public class CellLayoutChildren extends ViewGroup { super.setChildrenDrawnWithCacheEnabled(enabled); } - private final ArrayList<AppWidgetResizeFrame> mResizeFrames = new ArrayList<AppWidgetResizeFrame>(); - private AppWidgetResizeFrame mCurrentResizeFrame; - private int mXDown, mYDown; - private boolean mIsWidgetBeingResized; - public void clearAllResizeFrames() { for (AppWidgetResizeFrame frame: mResizeFrames) { removeView(frame); @@ -183,32 +184,41 @@ public class CellLayoutChildren extends ViewGroup { mResizeFrames.clear(); } + public boolean hasResizeFrames() { + return mResizeFrames.size() > 0; + } + public boolean isWidgetBeingResized() { - return mIsWidgetBeingResized; + return mCurrentResizeFrame != null; } - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { + private boolean handleTouchDown(MotionEvent ev) { Rect hitRect = new Rect(); int x = (int) ev.getX(); int y = (int) ev.getY(); - if (ev.getAction() == MotionEvent.ACTION_DOWN) { - for (AppWidgetResizeFrame child: mResizeFrames) { - child.getHitRect(hitRect); - if (hitRect.contains(x, y)) { - if (child.beginResizeIfPointInRegion(x - child.getLeft(), y - child.getTop())) { - mCurrentResizeFrame = child; - mIsWidgetBeingResized = true; - mXDown = x; - mYDown = y; - requestDisallowInterceptTouchEvent(true); - return true; - } + for (AppWidgetResizeFrame child: mResizeFrames) { + child.getHitRect(hitRect); + if (hitRect.contains(x, y)) { + if (child.beginResizeIfPointInRegion(x - child.getLeft(), y - child.getTop())) { + mCurrentResizeFrame = child; + mXDown = x; + mYDown = y; + requestDisallowInterceptTouchEvent(true); + return true; } } - mCurrentResizeFrame = null; + } + return false; + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + if (ev.getAction() == MotionEvent.ACTION_DOWN) { + if (handleTouchDown(ev)) { + return true; + } } return false; } @@ -216,47 +226,36 @@ public class CellLayoutChildren extends ViewGroup { @Override public boolean onTouchEvent(MotionEvent ev) { boolean handled = false; - Rect hitRect = new Rect(); int action = ev.getAction(); int x = (int) ev.getX(); int y = (int) ev.getY(); if (ev.getAction() == MotionEvent.ACTION_DOWN) { - for (AppWidgetResizeFrame child: mResizeFrames) { - child.getHitRect(hitRect); - if (hitRect.contains(x, y)) { - if (child.beginResizeIfPointInRegion(x - child.getLeft(), y - child.getTop())) { - mCurrentResizeFrame = child; - mIsWidgetBeingResized = true; - mXDown = x; - mYDown = y; - requestDisallowInterceptTouchEvent(true); - return true; - } + if (ev.getAction() == MotionEvent.ACTION_DOWN) { + if (handleTouchDown(ev)) { + return true; } } - mCurrentResizeFrame = null; } - // TODO: Need to handle ACTION_POINTER_UP / multi-touch if (mCurrentResizeFrame != null) { + handled = true; switch (action) { case MotionEvent.ACTION_MOVE: mCurrentResizeFrame.visualizeResizeForDelta(x - mXDown, y - mYDown); break; case MotionEvent.ACTION_CANCEL: - case MotionEvent.ACTION_UP: { + case MotionEvent.ACTION_UP: mCurrentResizeFrame.commitResizeForDelta(x - mXDown, y - mYDown); - mIsWidgetBeingResized = false; - handled = true; - } + mCurrentResizeFrame = null; } } return handled; } - public void addResizeFrame(ItemInfo itemInfo, LauncherAppWidgetHostView widget, CellLayout cellLayout) { + public void addResizeFrame(ItemInfo itemInfo, LauncherAppWidgetHostView widget, + CellLayout cellLayout) { AppWidgetResizeFrame resizeFrame = new AppWidgetResizeFrame(getContext(), itemInfo, widget, cellLayout); |