Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 1 | package com.android.launcher3; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2 | |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 3 | import com.android.launcher3.dragndrop.DragLayer; |
| 4 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 5 | import android.animation.AnimatorSet; |
| 6 | import android.animation.ObjectAnimator; |
| 7 | import android.animation.PropertyValuesHolder; |
| 8 | import android.animation.ValueAnimator; |
| 9 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 10 | import android.appwidget.AppWidgetHostView; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 11 | import android.appwidget.AppWidgetProviderInfo; |
| 12 | import android.content.Context; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 13 | import android.content.res.Resources; |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 14 | import android.graphics.Point; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 15 | import android.graphics.Rect; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 16 | import android.view.Gravity; |
Tony Wickham | 71255bb | 2016-02-10 16:18:15 -0800 | [diff] [blame] | 17 | import android.view.KeyEvent; |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame^] | 18 | import android.view.MotionEvent; |
Tony Wickham | 71255bb | 2016-02-10 16:18:15 -0800 | [diff] [blame] | 19 | import android.view.View; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 20 | import android.widget.FrameLayout; |
| 21 | import android.widget.ImageView; |
| 22 | |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 23 | import com.android.launcher3.accessibility.DragViewStateAnnouncer; |
Tony Wickham | 71255bb | 2016-02-10 16:18:15 -0800 | [diff] [blame] | 24 | import com.android.launcher3.util.FocusLogic; |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame^] | 25 | import com.android.launcher3.util.TouchController; |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 26 | |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame^] | 27 | public class AppWidgetResizeFrame extends FrameLayout |
| 28 | implements View.OnKeyListener, TouchController { |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 29 | private static final int SNAP_DURATION = 150; |
| 30 | private static final float DIMMED_HANDLE_ALPHA = 0f; |
| 31 | private static final float RESIZE_THRESHOLD = 0.66f; |
| 32 | |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 33 | private static final Rect sTmpRect = new Rect(); |
| 34 | |
| 35 | // Represents the cell size on the grid in the two orientations. |
| 36 | private static Point[] sCellSize; |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 37 | |
| 38 | private final Launcher mLauncher; |
| 39 | private final LauncherAppWidgetHostView mWidgetView; |
| 40 | private final CellLayout mCellLayout; |
| 41 | private final DragLayer mDragLayer; |
| 42 | |
| 43 | private final ImageView mLeftHandle; |
| 44 | private final ImageView mRightHandle; |
| 45 | private final ImageView mTopHandle; |
| 46 | private final ImageView mBottomHandle; |
| 47 | |
| 48 | private final Rect mWidgetPadding; |
| 49 | |
| 50 | private final int mBackgroundPadding; |
| 51 | private final int mTouchTargetWidth; |
| 52 | |
| 53 | private final int[] mDirectionVector = new int[2]; |
| 54 | private final int[] mLastDirectionVector = new int[2]; |
| 55 | private final int[] mTmpPt = new int[2]; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 56 | |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 57 | private final DragViewStateAnnouncer mStateAnnouncer; |
| 58 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 59 | private boolean mLeftBorderActive; |
| 60 | private boolean mRightBorderActive; |
| 61 | private boolean mTopBorderActive; |
| 62 | private boolean mBottomBorderActive; |
| 63 | |
| 64 | private int mBaselineWidth; |
| 65 | private int mBaselineHeight; |
| 66 | private int mBaselineX; |
| 67 | private int mBaselineY; |
| 68 | private int mResizeMode; |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 69 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 70 | private int mRunningHInc; |
| 71 | private int mRunningVInc; |
| 72 | private int mMinHSpan; |
| 73 | private int mMinVSpan; |
| 74 | private int mDeltaX; |
| 75 | private int mDeltaY; |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 76 | private int mDeltaXAddOn; |
| 77 | private int mDeltaYAddOn; |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 78 | |
Adam Cohen | 4459d6b | 2012-07-13 15:59:15 -0700 | [diff] [blame] | 79 | private int mTopTouchRegionAdjustment = 0; |
| 80 | private int mBottomTouchRegionAdjustment = 0; |
| 81 | |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame^] | 82 | private int mXDown, mYDown; |
| 83 | |
Michael Jurka | 3a9fced | 2012-04-13 14:44:29 -0700 | [diff] [blame] | 84 | public AppWidgetResizeFrame(Context context, |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 85 | LauncherAppWidgetHostView widgetView, CellLayout cellLayout, DragLayer dragLayer) { |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 86 | |
| 87 | super(context); |
Adam Cohen | cbf47e3 | 2011-09-16 17:32:37 -0700 | [diff] [blame] | 88 | mLauncher = (Launcher) context; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 89 | mCellLayout = cellLayout; |
| 90 | mWidgetView = widgetView; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 91 | LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) |
| 92 | widgetView.getAppWidgetInfo(); |
| 93 | mResizeMode = info.resizeMode; |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 94 | mDragLayer = dragLayer; |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 95 | |
Sunny Goyal | 233ee96 | 2015-08-03 13:05:01 -0700 | [diff] [blame] | 96 | mMinHSpan = info.minSpanX; |
| 97 | mMinVSpan = info.minSpanY; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 98 | |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 99 | mStateAnnouncer = DragViewStateAnnouncer.createFor(this); |
| 100 | |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 101 | setBackgroundResource(R.drawable.widget_resize_shadow); |
| 102 | setForeground(getResources().getDrawable(R.drawable.widget_resize_frame)); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 103 | setPadding(0, 0, 0, 0); |
| 104 | |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 105 | final int handleMargin = getResources().getDimensionPixelSize(R.dimen.widget_handle_margin); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 106 | LayoutParams lp; |
| 107 | mLeftHandle = new ImageView(context); |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 108 | mLeftHandle.setImageResource(R.drawable.ic_widget_resize_handle); |
| 109 | lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, |
Adam Cohen | 283dcbe | 2013-09-26 16:35:40 -0700 | [diff] [blame] | 110 | Gravity.LEFT | Gravity.CENTER_VERTICAL); |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 111 | lp.leftMargin = handleMargin; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 112 | addView(mLeftHandle, lp); |
| 113 | |
| 114 | mRightHandle = new ImageView(context); |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 115 | mRightHandle.setImageResource(R.drawable.ic_widget_resize_handle); |
| 116 | lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, |
Adam Cohen | 283dcbe | 2013-09-26 16:35:40 -0700 | [diff] [blame] | 117 | Gravity.RIGHT | Gravity.CENTER_VERTICAL); |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 118 | lp.rightMargin = handleMargin; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 119 | addView(mRightHandle, lp); |
| 120 | |
| 121 | mTopHandle = new ImageView(context); |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 122 | mTopHandle.setImageResource(R.drawable.ic_widget_resize_handle); |
| 123 | lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 124 | Gravity.CENTER_HORIZONTAL | Gravity.TOP); |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 125 | lp.topMargin = handleMargin; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 126 | addView(mTopHandle, lp); |
| 127 | |
| 128 | mBottomHandle = new ImageView(context); |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 129 | mBottomHandle.setImageResource(R.drawable.ic_widget_resize_handle); |
| 130 | lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 131 | Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM); |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 132 | lp.bottomMargin = handleMargin; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 133 | addView(mBottomHandle, lp); |
| 134 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 135 | if (!info.isCustomWidget) { |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 136 | mWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 137 | widgetView.getAppWidgetInfo().provider, null); |
| 138 | } else { |
| 139 | Resources r = context.getResources(); |
| 140 | int padding = r.getDimensionPixelSize(R.dimen.default_widget_padding); |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 141 | mWidgetPadding = new Rect(padding, padding, padding, padding); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 144 | if (mResizeMode == AppWidgetProviderInfo.RESIZE_HORIZONTAL) { |
| 145 | mTopHandle.setVisibility(GONE); |
| 146 | mBottomHandle.setVisibility(GONE); |
| 147 | } else if (mResizeMode == AppWidgetProviderInfo.RESIZE_VERTICAL) { |
| 148 | mLeftHandle.setVisibility(GONE); |
| 149 | mRightHandle.setVisibility(GONE); |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 152 | mBackgroundPadding = getResources() |
| 153 | .getDimensionPixelSize(R.dimen.resize_frame_background_padding); |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 154 | mTouchTargetWidth = 2 * mBackgroundPadding; |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 155 | |
| 156 | // When we create the resize frame, we first mark all cells as unoccupied. The appropriate |
| 157 | // cells (same if not resized, or different) will be marked as occupied when the resize |
| 158 | // frame is dismissed. |
| 159 | mCellLayout.markCellsAsUnoccupiedForView(mWidgetView); |
Tony Wickham | 71255bb | 2016-02-10 16:18:15 -0800 | [diff] [blame] | 160 | |
| 161 | setOnKeyListener(this); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | public boolean beginResizeIfPointInRegion(int x, int y) { |
| 165 | boolean horizontalActive = (mResizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0; |
| 166 | boolean verticalActive = (mResizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0; |
Adam Cohen | 4459d6b | 2012-07-13 15:59:15 -0700 | [diff] [blame] | 167 | |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 168 | mLeftBorderActive = (x < mTouchTargetWidth) && horizontalActive; |
| 169 | mRightBorderActive = (x > getWidth() - mTouchTargetWidth) && horizontalActive; |
Adam Cohen | 4459d6b | 2012-07-13 15:59:15 -0700 | [diff] [blame] | 170 | mTopBorderActive = (y < mTouchTargetWidth + mTopTouchRegionAdjustment) && verticalActive; |
| 171 | mBottomBorderActive = (y > getHeight() - mTouchTargetWidth + mBottomTouchRegionAdjustment) |
| 172 | && verticalActive; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 173 | |
| 174 | boolean anyBordersActive = mLeftBorderActive || mRightBorderActive |
| 175 | || mTopBorderActive || mBottomBorderActive; |
| 176 | |
| 177 | mBaselineWidth = getMeasuredWidth(); |
| 178 | mBaselineHeight = getMeasuredHeight(); |
| 179 | mBaselineX = getLeft(); |
| 180 | mBaselineY = getTop(); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 181 | |
| 182 | if (anyBordersActive) { |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 183 | mLeftHandle.setAlpha(mLeftBorderActive ? 1.0f : DIMMED_HANDLE_ALPHA); |
| 184 | mRightHandle.setAlpha(mRightBorderActive ? 1.0f :DIMMED_HANDLE_ALPHA); |
| 185 | mTopHandle.setAlpha(mTopBorderActive ? 1.0f : DIMMED_HANDLE_ALPHA); |
| 186 | mBottomHandle.setAlpha(mBottomBorderActive ? 1.0f : DIMMED_HANDLE_ALPHA); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 187 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 188 | return anyBordersActive; |
| 189 | } |
| 190 | |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 191 | /** |
| 192 | * Here we bound the deltas such that the frame cannot be stretched beyond the extents |
| 193 | * of the CellLayout, and such that the frame's borders can't cross. |
| 194 | */ |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 195 | public void updateDeltas(int deltaX, int deltaY) { |
| 196 | if (mLeftBorderActive) { |
| 197 | mDeltaX = Math.max(-mBaselineX, deltaX); |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 198 | mDeltaX = Math.min(mBaselineWidth - 2 * mTouchTargetWidth, mDeltaX); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 199 | } else if (mRightBorderActive) { |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 200 | mDeltaX = Math.min(mDragLayer.getWidth() - (mBaselineX + mBaselineWidth), deltaX); |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 201 | mDeltaX = Math.max(-mBaselineWidth + 2 * mTouchTargetWidth, mDeltaX); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | if (mTopBorderActive) { |
| 205 | mDeltaY = Math.max(-mBaselineY, deltaY); |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 206 | mDeltaY = Math.min(mBaselineHeight - 2 * mTouchTargetWidth, mDeltaY); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 207 | } else if (mBottomBorderActive) { |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 208 | mDeltaY = Math.min(mDragLayer.getHeight() - (mBaselineY + mBaselineHeight), deltaY); |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 209 | mDeltaY = Math.max(-mBaselineHeight + 2 * mTouchTargetWidth, mDeltaY); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame^] | 213 | private void visualizeResizeForDelta(int deltaX, int deltaY) { |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 214 | visualizeResizeForDelta(deltaX, deltaY, false); |
| 215 | } |
| 216 | |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 217 | /** |
| 218 | * Based on the deltas, we resize the frame, and, if needed, we resize the widget. |
| 219 | */ |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 220 | private void visualizeResizeForDelta(int deltaX, int deltaY, boolean onDismiss) { |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 221 | updateDeltas(deltaX, deltaY); |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 222 | DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
| 223 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 224 | if (mLeftBorderActive) { |
| 225 | lp.x = mBaselineX + mDeltaX; |
| 226 | lp.width = mBaselineWidth - mDeltaX; |
| 227 | } else if (mRightBorderActive) { |
| 228 | lp.width = mBaselineWidth + mDeltaX; |
| 229 | } |
| 230 | |
| 231 | if (mTopBorderActive) { |
| 232 | lp.y = mBaselineY + mDeltaY; |
| 233 | lp.height = mBaselineHeight - mDeltaY; |
| 234 | } else if (mBottomBorderActive) { |
| 235 | lp.height = mBaselineHeight + mDeltaY; |
| 236 | } |
| 237 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 238 | resizeWidgetIfNeeded(onDismiss); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 239 | requestLayout(); |
| 240 | } |
| 241 | |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 242 | /** |
| 243 | * Based on the current deltas, we determine if and how to resize the widget. |
| 244 | */ |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 245 | private void resizeWidgetIfNeeded(boolean onDismiss) { |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 246 | int xThreshold = mCellLayout.getCellWidth() + mCellLayout.getWidthGap(); |
| 247 | int yThreshold = mCellLayout.getCellHeight() + mCellLayout.getHeightGap(); |
| 248 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 249 | int deltaX = mDeltaX + mDeltaXAddOn; |
| 250 | int deltaY = mDeltaY + mDeltaYAddOn; |
| 251 | |
| 252 | float hSpanIncF = 1.0f * deltaX / xThreshold - mRunningHInc; |
| 253 | float vSpanIncF = 1.0f * deltaY / yThreshold - mRunningVInc; |
Adam Cohen | e4b7729 | 2011-03-08 18:35:52 -0800 | [diff] [blame] | 254 | |
| 255 | int hSpanInc = 0; |
| 256 | int vSpanInc = 0; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 257 | int cellXInc = 0; |
| 258 | int cellYInc = 0; |
| 259 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 260 | int countX = mCellLayout.getCountX(); |
| 261 | int countY = mCellLayout.getCountY(); |
| 262 | |
Adam Cohen | e4b7729 | 2011-03-08 18:35:52 -0800 | [diff] [blame] | 263 | if (Math.abs(hSpanIncF) > RESIZE_THRESHOLD) { |
| 264 | hSpanInc = Math.round(hSpanIncF); |
| 265 | } |
| 266 | if (Math.abs(vSpanIncF) > RESIZE_THRESHOLD) { |
| 267 | vSpanInc = Math.round(vSpanIncF); |
| 268 | } |
| 269 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 270 | if (!onDismiss && (hSpanInc == 0 && vSpanInc == 0)) return; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 271 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 272 | |
| 273 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mWidgetView.getLayoutParams(); |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 274 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 275 | int spanX = lp.cellHSpan; |
| 276 | int spanY = lp.cellVSpan; |
| 277 | int cellX = lp.useTmpCoords ? lp.tmpCellX : lp.cellX; |
| 278 | int cellY = lp.useTmpCoords ? lp.tmpCellY : lp.cellY; |
| 279 | |
| 280 | int hSpanDelta = 0; |
| 281 | int vSpanDelta = 0; |
| 282 | |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 283 | // For each border, we bound the resizing based on the minimum width, and the maximum |
| 284 | // expandability. |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 285 | if (mLeftBorderActive) { |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 286 | cellXInc = Math.max(-cellX, hSpanInc); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 287 | cellXInc = Math.min(lp.cellHSpan - mMinHSpan, cellXInc); |
| 288 | hSpanInc *= -1; |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 289 | hSpanInc = Math.min(cellX, hSpanInc); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 290 | hSpanInc = Math.max(-(lp.cellHSpan - mMinHSpan), hSpanInc); |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 291 | hSpanDelta = -hSpanInc; |
| 292 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 293 | } else if (mRightBorderActive) { |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 294 | hSpanInc = Math.min(countX - (cellX + spanX), hSpanInc); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 295 | hSpanInc = Math.max(-(lp.cellHSpan - mMinHSpan), hSpanInc); |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 296 | hSpanDelta = hSpanInc; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | if (mTopBorderActive) { |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 300 | cellYInc = Math.max(-cellY, vSpanInc); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 301 | cellYInc = Math.min(lp.cellVSpan - mMinVSpan, cellYInc); |
| 302 | vSpanInc *= -1; |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 303 | vSpanInc = Math.min(cellY, vSpanInc); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 304 | vSpanInc = Math.max(-(lp.cellVSpan - mMinVSpan), vSpanInc); |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 305 | vSpanDelta = -vSpanInc; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 306 | } else if (mBottomBorderActive) { |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 307 | vSpanInc = Math.min(countY - (cellY + spanY), vSpanInc); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 308 | vSpanInc = Math.max(-(lp.cellVSpan - mMinVSpan), vSpanInc); |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 309 | vSpanDelta = vSpanInc; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 312 | mDirectionVector[0] = 0; |
| 313 | mDirectionVector[1] = 0; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 314 | // Update the widget's dimensions and position according to the deltas computed above |
| 315 | if (mLeftBorderActive || mRightBorderActive) { |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 316 | spanX += hSpanInc; |
| 317 | cellX += cellXInc; |
Adam Cohen | e048950 | 2012-08-27 15:18:53 -0700 | [diff] [blame] | 318 | if (hSpanDelta != 0) { |
| 319 | mDirectionVector[0] = mLeftBorderActive ? -1 : 1; |
| 320 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | if (mTopBorderActive || mBottomBorderActive) { |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 324 | spanY += vSpanInc; |
| 325 | cellY += cellYInc; |
Adam Cohen | e048950 | 2012-08-27 15:18:53 -0700 | [diff] [blame] | 326 | if (vSpanDelta != 0) { |
| 327 | mDirectionVector[1] = mTopBorderActive ? -1 : 1; |
| 328 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 331 | if (!onDismiss && vSpanDelta == 0 && hSpanDelta == 0) return; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 332 | |
Adam Cohen | e048950 | 2012-08-27 15:18:53 -0700 | [diff] [blame] | 333 | // We always want the final commit to match the feedback, so we make sure to use the |
| 334 | // last used direction vector when committing the resize / reorder. |
| 335 | if (onDismiss) { |
| 336 | mDirectionVector[0] = mLastDirectionVector[0]; |
| 337 | mDirectionVector[1] = mLastDirectionVector[1]; |
| 338 | } else { |
| 339 | mLastDirectionVector[0] = mDirectionVector[0]; |
| 340 | mLastDirectionVector[1] = mDirectionVector[1]; |
| 341 | } |
| 342 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 343 | if (mCellLayout.createAreaForResize(cellX, cellY, spanX, spanY, mWidgetView, |
| 344 | mDirectionVector, onDismiss)) { |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 345 | if (mStateAnnouncer != null && (lp.cellHSpan != spanX || lp.cellVSpan != spanY) ) { |
| 346 | mStateAnnouncer.announce( |
| 347 | mLauncher.getString(R.string.widget_resized, spanX, spanY)); |
| 348 | } |
| 349 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 350 | lp.tmpCellX = cellX; |
| 351 | lp.tmpCellY = cellY; |
| 352 | lp.cellHSpan = spanX; |
| 353 | lp.cellVSpan = spanY; |
| 354 | mRunningVInc += vSpanDelta; |
| 355 | mRunningHInc += hSpanDelta; |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 356 | |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 357 | if (!onDismiss) { |
| 358 | updateWidgetSizeRanges(mWidgetView, mLauncher, spanX, spanY); |
| 359 | } |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 360 | } |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 361 | mWidgetView.requestLayout(); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 362 | } |
| 363 | |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 364 | static void updateWidgetSizeRanges(AppWidgetHostView widgetView, Launcher launcher, |
| 365 | int spanX, int spanY) { |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 366 | getWidgetSizeRanges(launcher, spanX, spanY, sTmpRect); |
| 367 | widgetView.updateAppWidgetSize(null, sTmpRect.left, sTmpRect.top, |
| 368 | sTmpRect.right, sTmpRect.bottom); |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Sunny Goyal | 16466f1 | 2016-03-10 05:34:30 -0800 | [diff] [blame] | 371 | public static Rect getWidgetSizeRanges(Context context, int spanX, int spanY, Rect rect) { |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 372 | if (sCellSize == null) { |
| 373 | InvariantDeviceProfile inv = LauncherAppState.getInstance().getInvariantDeviceProfile(); |
| 374 | |
| 375 | // Initiate cell sizes. |
| 376 | sCellSize = new Point[2]; |
| 377 | sCellSize[0] = inv.landscapeProfile.getCellSize(); |
| 378 | sCellSize[1] = inv.portraitProfile.getCellSize(); |
| 379 | } |
| 380 | |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 381 | if (rect == null) { |
| 382 | rect = new Rect(); |
| 383 | } |
Sunny Goyal | 16466f1 | 2016-03-10 05:34:30 -0800 | [diff] [blame] | 384 | final float density = context.getResources().getDisplayMetrics().density; |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 385 | |
| 386 | // Compute landscape size |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 387 | int landWidth = (int) ((spanX * sCellSize[0].x) / density); |
| 388 | int landHeight = (int) ((spanY * sCellSize[0].y) / density); |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 389 | |
| 390 | // Compute portrait size |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 391 | int portWidth = (int) ((spanX * sCellSize[1].x) / density); |
| 392 | int portHeight = (int) ((spanY * sCellSize[1].y) / density); |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 393 | rect.set(portWidth, landHeight, landWidth, portHeight); |
| 394 | return rect; |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 397 | /** |
| 398 | * This is the final step of the resize. Here we save the new widget size and position |
| 399 | * to LauncherModel and animate the resize frame. |
| 400 | */ |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 401 | public void commitResize() { |
| 402 | resizeWidgetIfNeeded(true); |
| 403 | requestLayout(); |
| 404 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 405 | |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame^] | 406 | private void onTouchUp() { |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 407 | int xThreshold = mCellLayout.getCellWidth() + mCellLayout.getWidthGap(); |
| 408 | int yThreshold = mCellLayout.getCellHeight() + mCellLayout.getHeightGap(); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 409 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 410 | mDeltaXAddOn = mRunningHInc * xThreshold; |
| 411 | mDeltaYAddOn = mRunningVInc * yThreshold; |
| 412 | mDeltaX = 0; |
| 413 | mDeltaY = 0; |
| 414 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 415 | post(new Runnable() { |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 416 | @Override |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 417 | public void run() { |
| 418 | snapToWidget(true); |
| 419 | } |
| 420 | }); |
| 421 | } |
| 422 | |
| 423 | public void snapToWidget(boolean animate) { |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 424 | final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 425 | int newWidth = mWidgetView.getWidth() + 2 * mBackgroundPadding |
| 426 | - mWidgetPadding.left - mWidgetPadding.right; |
| 427 | int newHeight = mWidgetView.getHeight() + 2 * mBackgroundPadding |
| 428 | - mWidgetPadding.top - mWidgetPadding.bottom; |
Adam Cohen | 37b59ff | 2011-06-13 17:13:42 -0700 | [diff] [blame] | 429 | |
Adam Cohen | d6e7aa3 | 2013-07-09 15:32:37 -0700 | [diff] [blame] | 430 | mTmpPt[0] = mWidgetView.getLeft(); |
| 431 | mTmpPt[1] = mWidgetView.getTop(); |
| 432 | mDragLayer.getDescendantCoordRelativeToSelf(mCellLayout.getShortcutsAndWidgets(), mTmpPt); |
| 433 | |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 434 | int newX = mTmpPt[0] - mBackgroundPadding + mWidgetPadding.left; |
| 435 | int newY = mTmpPt[1] - mBackgroundPadding + mWidgetPadding.top; |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 436 | |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 437 | // We need to make sure the frame's touchable regions lie fully within the bounds of the |
Adam Cohen | 4459d6b | 2012-07-13 15:59:15 -0700 | [diff] [blame] | 438 | // DragLayer. We allow the actual handles to be clipped, but we shift the touch regions |
| 439 | // down accordingly to provide a proper touch target. |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 440 | if (newY < 0) { |
Adam Cohen | 4459d6b | 2012-07-13 15:59:15 -0700 | [diff] [blame] | 441 | // In this case we shift the touch region down to start at the top of the DragLayer |
| 442 | mTopTouchRegionAdjustment = -newY; |
| 443 | } else { |
| 444 | mTopTouchRegionAdjustment = 0; |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 445 | } |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 446 | if (newY + newHeight > mDragLayer.getHeight()) { |
Adam Cohen | 4459d6b | 2012-07-13 15:59:15 -0700 | [diff] [blame] | 447 | // In this case we shift the touch region up to end at the bottom of the DragLayer |
| 448 | mBottomTouchRegionAdjustment = -(newY + newHeight - mDragLayer.getHeight()); |
| 449 | } else { |
| 450 | mBottomTouchRegionAdjustment = 0; |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 451 | } |
| 452 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 453 | if (!animate) { |
| 454 | lp.width = newWidth; |
| 455 | lp.height = newHeight; |
| 456 | lp.x = newX; |
| 457 | lp.y = newY; |
| 458 | mLeftHandle.setAlpha(1.0f); |
| 459 | mRightHandle.setAlpha(1.0f); |
| 460 | mTopHandle.setAlpha(1.0f); |
| 461 | mBottomHandle.setAlpha(1.0f); |
| 462 | requestLayout(); |
| 463 | } else { |
| 464 | PropertyValuesHolder width = PropertyValuesHolder.ofInt("width", lp.width, newWidth); |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 465 | PropertyValuesHolder height = PropertyValuesHolder.ofInt("height", lp.height, |
| 466 | newHeight); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 467 | PropertyValuesHolder x = PropertyValuesHolder.ofInt("x", lp.x, newX); |
| 468 | PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", lp.y, newY); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 469 | ObjectAnimator oa = |
| 470 | LauncherAnimUtils.ofPropertyValuesHolder(lp, this, width, height, x, y); |
Sunny Goyal | 5d2fc32 | 2015-07-06 22:52:49 -0700 | [diff] [blame] | 471 | ObjectAnimator leftOa = LauncherAnimUtils.ofFloat(mLeftHandle, ALPHA, 1.0f); |
| 472 | ObjectAnimator rightOa = LauncherAnimUtils.ofFloat(mRightHandle, ALPHA, 1.0f); |
| 473 | ObjectAnimator topOa = LauncherAnimUtils.ofFloat(mTopHandle, ALPHA, 1.0f); |
| 474 | ObjectAnimator bottomOa = LauncherAnimUtils.ofFloat(mBottomHandle, ALPHA, 1.0f); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 475 | oa.addUpdateListener(new AnimatorUpdateListener() { |
| 476 | public void onAnimationUpdate(ValueAnimator animation) { |
| 477 | requestLayout(); |
| 478 | } |
| 479 | }); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 480 | AnimatorSet set = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 481 | if (mResizeMode == AppWidgetProviderInfo.RESIZE_VERTICAL) { |
| 482 | set.playTogether(oa, topOa, bottomOa); |
| 483 | } else if (mResizeMode == AppWidgetProviderInfo.RESIZE_HORIZONTAL) { |
| 484 | set.playTogether(oa, leftOa, rightOa); |
| 485 | } else { |
| 486 | set.playTogether(oa, leftOa, rightOa, topOa, bottomOa); |
| 487 | } |
| 488 | |
| 489 | set.setDuration(SNAP_DURATION); |
| 490 | set.start(); |
| 491 | } |
Tony Wickham | 71255bb | 2016-02-10 16:18:15 -0800 | [diff] [blame] | 492 | |
| 493 | setFocusableInTouchMode(true); |
| 494 | requestFocus(); |
| 495 | } |
| 496 | |
| 497 | @Override |
| 498 | public boolean onKey(View v, int keyCode, KeyEvent event) { |
| 499 | // Clear the frame and give focus to the widget host view when a directional key is pressed. |
| 500 | if (FocusLogic.shouldConsume(keyCode)) { |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame^] | 501 | mDragLayer.clearResizeFrame(); |
Tony Wickham | 71255bb | 2016-02-10 16:18:15 -0800 | [diff] [blame] | 502 | mWidgetView.requestFocus(); |
| 503 | return true; |
| 504 | } |
| 505 | return false; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 506 | } |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame^] | 507 | |
| 508 | private boolean handleTouchDown(MotionEvent ev) { |
| 509 | Rect hitRect = new Rect(); |
| 510 | int x = (int) ev.getX(); |
| 511 | int y = (int) ev.getY(); |
| 512 | |
| 513 | getHitRect(hitRect); |
| 514 | if (hitRect.contains(x, y)) { |
| 515 | if (beginResizeIfPointInRegion(x - getLeft(), y - getTop())) { |
| 516 | mXDown = x; |
| 517 | mYDown = y; |
| 518 | return true; |
| 519 | } |
| 520 | } |
| 521 | return false; |
| 522 | } |
| 523 | |
| 524 | @Override |
| 525 | public boolean onControllerTouchEvent(MotionEvent ev) { |
| 526 | int action = ev.getAction(); |
| 527 | int x = (int) ev.getX(); |
| 528 | int y = (int) ev.getY(); |
| 529 | |
| 530 | switch (action) { |
| 531 | case MotionEvent.ACTION_DOWN: |
| 532 | return handleTouchDown(ev); |
| 533 | case MotionEvent.ACTION_MOVE: |
| 534 | visualizeResizeForDelta(x - mXDown, y - mYDown); |
| 535 | break; |
| 536 | case MotionEvent.ACTION_CANCEL: |
| 537 | case MotionEvent.ACTION_UP: |
| 538 | visualizeResizeForDelta(x - mXDown, y - mYDown); |
| 539 | onTouchUp(); |
| 540 | mXDown = mYDown = 0; |
| 541 | break; |
| 542 | } |
| 543 | return true; |
| 544 | } |
| 545 | |
| 546 | @Override |
| 547 | public boolean onControllerInterceptTouchEvent(MotionEvent ev) { |
| 548 | if (ev.getAction() == MotionEvent.ACTION_DOWN && handleTouchDown(ev)) { |
| 549 | return true; |
| 550 | } |
| 551 | return false; |
| 552 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 553 | } |