From ea3763c2672f77539538af8cdd395ad97058eaab Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Mon, 11 Jan 2010 18:02:04 -0800 Subject: [PATCH] Fix dpad nav: go left/right when dpad is moved and dots are focused. Bug #2359364 --- src/com/android/launcher2/DragController.java | 29 ++++++++++++------- src/com/android/launcher2/DragLayer.java | 7 ++++- src/com/android/launcher2/Launcher.java | 1 + 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java index 590ca69270..daabbcc4cf 100644 --- a/src/com/android/launcher2/DragController.java +++ b/src/com/android/launcher2/DragController.java @@ -18,25 +18,18 @@ package com.android.launcher2; import android.content.Context; import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Matrix; import android.graphics.Rect; import android.graphics.RectF; import android.os.IBinder; import android.os.Handler; import android.os.Vibrator; -import android.os.SystemClock; -import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; import android.view.View; -import android.view.ViewGroup; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; -import android.widget.FrameLayout; -import android.widget.ImageView; import java.util.ArrayList; @@ -44,6 +37,7 @@ import java.util.ArrayList; * Class for initiating a drag within a view or across multiple views. */ public class DragController { + @SuppressWarnings({"UnusedDeclaration"}) private static final String TAG = "Launcher.DragController"; /** Indicates the drag is a move. */ @@ -113,6 +107,8 @@ public class DragController { /** The view that will be scrolled when dragging to the left and right edges of the screen. */ private View mScrollView; + private View mMoveTarget; + private DragScroller mDragScroller; private int mScrollState = SCROLL_OUTSIDE_ZONE; private ScrollRunnable mScrollRunnable = new ScrollRunnable(); @@ -147,7 +143,6 @@ public class DragController { * Used to create a new DragLayer from XML. * * @param context The application's context. - * @param attrs The attribtues set containing the Workspace's customization values. */ public DragController(Context context) { mContext = context; @@ -159,7 +154,7 @@ public class DragController { * * @param v The view that is being dragged * @param source An object representing where the drag originated - * @param info The data associated with the object that is being dragged + * @param dragInfo The data associated with the object that is being dragged * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or * {@link #DRAG_ACTION_COPY} */ @@ -195,7 +190,7 @@ public class DragController { * @param textureWidth The width of the region inside b to use. * @param textureHeight The height of the region inside b to use. * @param source An object representing where the drag originated - * @param info The data associated with the object that is being dragged + * @param dragInfo The data associated with the object that is being dragged * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or * {@link #DRAG_ACTION_COPY} */ @@ -275,6 +270,7 @@ public class DragController { * || super.dispatchKeyEvent(event); * */ + @SuppressWarnings({"UnusedDeclaration"}) public boolean dispatchKeyEvent(KeyEvent event) { return mDragging; } @@ -342,6 +338,17 @@ public class DragController { return mDragging; } + /** + * Sets the view that should handle move events. + */ + void setMoveTarget(View view) { + mMoveTarget = view; + } + + public boolean dispatchUnhandledMove(View focused, int direction) { + return mMoveTarget != null && mMoveTarget.dispatchUnhandledMove(focused, direction); + } + /** * Call this from a drag source view. */ @@ -377,7 +384,7 @@ public class DragController { // Drop on someone? final int[] coordinates = mCoordinatesTemp; - DropTarget dropTarget = findDropTarget((int) screenX, (int) screenY, coordinates); + DropTarget dropTarget = findDropTarget(screenX, screenY, coordinates); if (dropTarget != null) { if (mLastDropTarget == dropTarget) { dropTarget.onDragOver(mDragSource, coordinates[0], coordinates[1], diff --git a/src/com/android/launcher2/DragLayer.java b/src/com/android/launcher2/DragLayer.java index 7ae98917d2..c683207641 100644 --- a/src/com/android/launcher2/DragLayer.java +++ b/src/com/android/launcher2/DragLayer.java @@ -18,9 +18,9 @@ package com.android.launcher2; import android.content.Context; import android.util.AttributeSet; -import android.util.Log; import android.view.MotionEvent; import android.view.KeyEvent; +import android.view.View; import android.widget.FrameLayout; /** @@ -57,4 +57,9 @@ public class DragLayer extends FrameLayout { public boolean onTouchEvent(MotionEvent ev) { return mDragController.onTouchEvent(ev); } + + @Override + public boolean dispatchUnhandledMove(View focused, int direction) { + return mDragController.dispatchUnhandledMove(focused, direction); + } } diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 6f6183e454..d29d721878 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -556,6 +556,7 @@ public final class Launcher extends Activity dragController.setDragScoller(workspace); dragController.setDragListener(deleteZone); dragController.setScrollView(dragLayer); + dragController.setMoveTarget(workspace); // The order here is bottom to top. dragController.addDropTarget(workspace);