diff options
author | Patrick Dubroy <dubroy@google.com> | 2010-10-06 15:49:50 -0700 |
---|---|---|
committer | Patrick Dubroy <dubroy@google.com> | 2010-10-06 17:39:05 -0700 |
commit | 1262e369484ce7f2565655ed80e6299232c70bd7 (patch) | |
tree | 91e599271b6d0bdbbc60889af8a73ce8d4b595d5 /src | |
parent | 7ed39f3362e4701101967339b1be41b365712d1c (diff) | |
download | android_packages_apps_Trebuchet-1262e369484ce7f2565655ed80e6299232c70bd7.tar.gz android_packages_apps_Trebuchet-1262e369484ce7f2565655ed80e6299232c70bd7.tar.bz2 android_packages_apps_Trebuchet-1262e369484ce7f2565655ed80e6299232c70bd7.zip |
wip 3029324: Implement new drag feedback
- Show page borders when dragging
- Enlarge scroll region (landscape only)
- When inside scroll region, show green border on adjacent page
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher2/CellLayout.java | 38 | ||||
-rw-r--r-- | src/com/android/launcher2/DragController.java | 11 | ||||
-rw-r--r-- | src/com/android/launcher2/DragScroller.java | 12 | ||||
-rw-r--r-- | src/com/android/launcher2/Launcher.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher2/PagedView.java | 24 | ||||
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 84 |
6 files changed, 114 insertions, 57 deletions
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 3f9945fd2..d26b2f932 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -41,8 +41,6 @@ import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; import android.view.animation.LayoutAnimationController; -import java.util.Arrays; - public class CellLayout extends ViewGroup implements Dimmable { static final String TAG = "CellLayout"; @@ -75,12 +73,13 @@ public class CellLayout extends ViewGroup implements Dimmable { private OnTouchListener mInterceptTouchListener; private float mBackgroundAlpha; - private final Rect mBackgroundLayoutRect = new Rect(); private Drawable mBackground; private Drawable mBackgroundMini; private Drawable mBackgroundMiniHover; - // If we're actively dragging something over this screen and it's small, mHover is true + private Drawable mBackgroundHover; + + // If we're actively dragging something over this screen, mHover is true private boolean mHover = false; private final Point mDragCenter = new Point(); @@ -154,6 +153,8 @@ public class CellLayout extends ViewGroup implements Dimmable { mBackground.setFilterBitmap(true); mBackgroundMiniHover = res.getDrawable(R.drawable.mini_home_screen_bg_hover); mBackgroundMiniHover.setFilterBitmap(true); + mBackgroundHover = res.getDrawable(R.drawable.home_screen_bg_hover); + mBackgroundHover.setFilterBitmap(true); } // Initialize the data structures used for the drag visualization. @@ -215,27 +216,25 @@ public class CellLayout extends ViewGroup implements Dimmable { anim.start(); } + public void drawChildren(Canvas canvas) { + super.dispatchDraw(canvas); + } + @Override - public void dispatchDraw(Canvas canvas) { + protected void onDraw(Canvas canvas) { if (mBackgroundAlpha > 0.0f) { Drawable bg; - if (mHover && getScaleX() < 0.5f) { - bg = mBackgroundMiniHover; - } else if (getScaleX() < 0.5f) { - bg = mBackgroundMini; + if (getScaleX() < 0.5f) { + bg = mHover ? mBackgroundMiniHover : mBackgroundMini; } else { - bg = mBackground; + bg = mHover ? mBackgroundHover : mBackground; } if (bg != null) { bg.setAlpha((int) (mBackgroundAlpha * 255)); bg.draw(canvas); } } - super.dispatchDraw(canvas); - } - @Override - protected void onDraw(Canvas canvas) { if (mCrosshairsVisibility > 0.0f) { final int countX = mCountX; final int countY = mCountY; @@ -641,15 +640,17 @@ public class CellLayout extends ViewGroup implements Dimmable { @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); - mBackgroundLayoutRect.set(0, 0, w, h); if (mBackground != null) { - mBackground.setBounds(mBackgroundLayoutRect); + mBackground.setBounds(0, 0, w, h); + } + if (mBackgroundHover != null) { + mBackgroundHover.setBounds(0, 0, w, h); } if (mBackgroundMiniHover != null) { - mBackgroundMiniHover.setBounds(mBackgroundLayoutRect); + mBackgroundMiniHover.setBounds(0, 0, w, h); } if (mBackgroundMini != null) { - mBackgroundMini.setBounds(mBackgroundLayoutRect); + mBackgroundMini.setBounds(0, 0, w, h); } } @@ -1016,7 +1017,6 @@ public class CellLayout extends ViewGroup implements Dimmable { mDragCell[1] = -1; setHover(false); - invalidate(); // Fade out the drag indicators if (mCrosshairsAnimator != null) { diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java index d54434002..68dfb35fc 100644 --- a/src/com/android/launcher2/DragController.java +++ b/src/com/android/launcher2/DragController.java @@ -56,8 +56,8 @@ public class DragController { private static final int SCROLL_OUTSIDE_ZONE = 0; private static final int SCROLL_WAITING_IN_ZONE = 1; - private static final int SCROLL_LEFT = 0; - private static final int SCROLL_RIGHT = 1; + static final int SCROLL_LEFT = 0; + static final int SCROLL_RIGHT = 1; private Context mContext; private Handler mHandler; @@ -156,6 +156,10 @@ public class DragController { mScrollZone = context.getResources().getDimensionPixelSize(R.dimen.scroll_zone); } + public boolean dragging() { + return mDragging; + } + /** * Starts a drag. * @@ -487,18 +491,21 @@ public class DragController { mScrollState = SCROLL_WAITING_IN_ZONE; mScrollRunnable.setDirection(SCROLL_LEFT); mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); + mDragScroller.onEnterScrollArea(SCROLL_LEFT); } } else if (!inDeleteRegion && x > mScrollView.getWidth() - mScrollZone) { if (mScrollState == SCROLL_OUTSIDE_ZONE) { mScrollState = SCROLL_WAITING_IN_ZONE; mScrollRunnable.setDirection(SCROLL_RIGHT); mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); + mDragScroller.onEnterScrollArea(SCROLL_RIGHT); } } else { if (mScrollState == SCROLL_WAITING_IN_ZONE) { mScrollState = SCROLL_OUTSIDE_ZONE; mScrollRunnable.setDirection(SCROLL_RIGHT); mHandler.removeCallbacks(mScrollRunnable); + mDragScroller.onExitScrollArea(); } } } diff --git a/src/com/android/launcher2/DragScroller.java b/src/com/android/launcher2/DragScroller.java index c3c251c2f..6af9c3032 100644 --- a/src/com/android/launcher2/DragScroller.java +++ b/src/com/android/launcher2/DragScroller.java @@ -23,4 +23,16 @@ package com.android.launcher2; public interface DragScroller { void scrollLeft(); void scrollRight(); + + /** + * The touch point has entered the scroll area; a scroll is imminent. + * + * @param direction The scroll direction + */ + void onEnterScrollArea(int direction); + + /** + * The touch point has left the scroll area. + */ + void onExitScrollArea(); } diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index c065170a8..f5a593543 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -2029,7 +2029,7 @@ public final class Launcher extends Activity final Canvas c = new Canvas(bitmap); c.scale(scale, scale); c.translate(-cell.getLeftPadding(), -cell.getTopPadding()); - cell.dispatchDraw(c); + cell.drawChildren(c); image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background)); image.setImageBitmap(bitmap); diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java index 732bfbd9b..bf0eb1287 100644 --- a/src/com/android/launcher2/PagedView.java +++ b/src/com/android/launcher2/PagedView.java @@ -133,6 +133,8 @@ public abstract class PagedView extends ViewGroup { // (SmoothPagedView does this) protected boolean mDeferScrollUpdate = false; + protected boolean mIsPageMoving = false; + /** * Simple cache mechanism for PagedViewIcon outlines. */ @@ -159,11 +161,6 @@ public abstract class PagedView extends ViewGroup { void onPageSwitch(View newPage, int newPageIndex); } - public interface PageMovingListener { - void onPageBeginMoving(); - void onPageEndMoving(); - } - public PagedView(Context context) { this(context, null); } @@ -257,12 +254,22 @@ public abstract class PagedView extends ViewGroup { } } + private void pageBeginMoving() { + mIsPageMoving = true; + onPageBeginMoving(); + } + + private void pageEndMoving() { + onPageEndMoving(); + mIsPageMoving = false; + } + // a method that subclasses can override to add behavior - protected void pageBeginMoving() { + protected void onPageBeginMoving() { } // a method that subclasses can override to add behavior - protected void pageEndMoving() { + protected void onPageEndMoving() { } /** @@ -657,12 +664,9 @@ public abstract class PagedView extends ViewGroup { case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: - // Release the drag - pageEndMoving(); mTouchState = TOUCH_STATE_REST; mAllowLongPress = false; mActivePointerId = INVALID_POINTER; - break; case MotionEvent.ACTION_POINTER_UP: diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 47e172f71..d9bff5e19 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -33,9 +33,7 @@ import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.content.res.Resources; import android.content.res.TypedArray; -import android.graphics.Camera; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Rect; import android.graphics.drawable.Drawable; @@ -78,9 +76,6 @@ public class Workspace extends SmoothPagedView private static final int BACKGROUND_FADE_OUT_DURATION = 300; private static final int BACKGROUND_FADE_IN_DURATION = 100; - static final int SCROLL_RIGHT = 0; - static final int SCROLL_LEFT = 1; - // These animators are used to fade the private ObjectAnimator<Float> mBackgroundFadeIn; private ObjectAnimator<Float> mBackgroundFadeOut; @@ -126,11 +121,14 @@ public class Workspace extends SmoothPagedView private Drawable mPreviousIndicator; private Drawable mNextIndicator; - // State variable that indicated whether the pages are small (ie when you're + // State variable that indicates whether the pages are small (ie when you're // in all apps or customize mode) private boolean mIsSmall; + private AnimatorListener mUnshrinkAnimationListener; + private boolean mInScrollArea = false; + /** * Used to inflate the Workspace from XML. * @@ -389,7 +387,7 @@ public class Workspace extends SmoothPagedView return super.onInterceptTouchEvent(ev); } - protected void pageBeginMoving() { + protected void onPageBeginMoving() { if (mNextPage != INVALID_PAGE) { // we're snapping to a particular screen enableChildrenCache(mCurrentPage, mNextPage); @@ -401,9 +399,13 @@ public class Workspace extends SmoothPagedView showOutlines(); } - protected void pageEndMoving() { + protected void onPageEndMoving() { clearChildrenCache(); - hideOutlines(); + + // Hide the outlines, as long as we're not dragging + if (!mDragController.dragging()) { + hideOutlines(); + } } @Override @@ -500,11 +502,11 @@ public class Workspace extends SmoothPagedView getRelativeChildOffset(mCurrentPage) + halfScreenSize); float scrollProgress = Math.abs(delta/(pageWidth*1.0f + mPageSpacing)); - int scrollDirection = delta > 0 ? SCROLL_LEFT : SCROLL_RIGHT; + boolean scrollRight = (delta <= 0); float rotation; - if (scrollDirection == SCROLL_RIGHT) { + if (scrollRight) { rotation = -scrollProgress * WORKSPACE_ROTATION; cur.setRotationY(rotation); cur.setScaleX(getScaleXForRotation(rotation)); @@ -933,6 +935,7 @@ public class Workspace extends SmoothPagedView public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) { getCurrentDropLayout().onDragEnter(dragView); + showOutlines(); } public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset, @@ -1050,6 +1053,7 @@ public class Workspace extends SmoothPagedView mDragTargetLayout.onDragExit(); } mDragTargetLayout = bestMatchingScreen; + // TODO: Should we be calling mDragTargetLayout.onDragEnter() here? } return bestMatchingScreen; } @@ -1103,23 +1107,27 @@ public class Workspace extends SmoothPagedView } } } - if (currentLayout != mDragTargetLayout) { - if (mDragTargetLayout != null) { - mDragTargetLayout.onDragExit(); + + // When touch is inside the scroll area, skip dragOver actions for the current screen + if (!mInScrollArea) { + if (currentLayout != mDragTargetLayout) { + if (mDragTargetLayout != null) { + mDragTargetLayout.onDragExit(); + } currentLayout.onDragEnter(dragView); + mDragTargetLayout = currentLayout; } - mDragTargetLayout = currentLayout; - } - // only visualize the drop locations for moving icons within the home screen on tablet - // on phone, we also visualize icons dragged in from All Apps - if ((!LauncherApplication.isScreenXLarge() || source == this) - && mDragTargetLayout != null) { - final View child = (mDragInfo == null) ? null : mDragInfo.cell; - int localOriginX = originX - (mDragTargetLayout.getLeft() - mScrollX); - int localOriginY = originY - (mDragTargetLayout.getTop() - mScrollY); - mDragTargetLayout.visualizeDropLocation( - child, localOriginX, localOriginY, item.spanX, item.spanY); + // only visualize the drop locations for moving icons within the home screen on tablet + // on phone, we also visualize icons dragged in from All Apps + if ((!LauncherApplication.isScreenXLarge() || source == this) + && mDragTargetLayout != null) { + final View child = (mDragInfo == null) ? null : mDragInfo.cell; + int localOriginX = originX - (mDragTargetLayout.getLeft() - mScrollX); + int localOriginY = originY - (mDragTargetLayout.getTop() - mScrollY); + mDragTargetLayout.visualizeDropLocation( + child, localOriginX, localOriginY, item.spanX, item.spanY); + } } } @@ -1129,6 +1137,9 @@ public class Workspace extends SmoothPagedView mDragTargetLayout.onDragExit(); mDragTargetLayout = null; } + if (!mIsPageMoving) { + hideOutlines(); + } } private void onDropExternal(int x, int y, Object dragInfo, @@ -1342,6 +1353,29 @@ public class Workspace extends SmoothPagedView } } + @Override + public void onEnterScrollArea(int direction) { + mInScrollArea = true; + final int screen = getCurrentPage() + ((direction == DragController.SCROLL_LEFT) ? -1 : 1); + if (0 <= screen && screen < getChildCount()) { + ((CellLayout) getChildAt(screen)).setHover(true); + } + + if (mDragTargetLayout != null) { + mDragTargetLayout.onDragExit(); + mDragTargetLayout = null; + } + } + + @Override + public void onExitScrollArea() { + mInScrollArea = false; + final int childCount = getChildCount(); + for (int i = 0; i < childCount; i++) { + ((CellLayout) getChildAt(i)).setHover(false); + } + } + public Folder getFolderForTag(Object tag) { final int screenCount = getChildCount(); for (int screen = 0; screen < screenCount; screen++) { |