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 | |
Sunny Goyal | 55bdeed | 2018-09-18 16:17:22 -0700 | [diff] [blame^] | 3 | import static com.android.launcher3.LauncherAnimUtils.LAYOUT_HEIGHT; |
| 4 | import static com.android.launcher3.LauncherAnimUtils.LAYOUT_WIDTH; |
| 5 | import static com.android.launcher3.views.BaseDragLayer.LAYOUT_X; |
| 6 | import static com.android.launcher3.views.BaseDragLayer.LAYOUT_Y; |
| 7 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 8 | import android.animation.AnimatorSet; |
| 9 | import android.animation.ObjectAnimator; |
| 10 | import android.animation.PropertyValuesHolder; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 11 | import android.appwidget.AppWidgetHostView; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 12 | import android.appwidget.AppWidgetProviderInfo; |
| 13 | import android.content.Context; |
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; |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 16 | import android.util.AttributeSet; |
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; |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 20 | import android.view.ViewGroup; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 21 | |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 22 | import com.android.launcher3.accessibility.DragViewStateAnnouncer; |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 23 | import com.android.launcher3.dragndrop.DragLayer; |
Tony Wickham | 71255bb | 2016-02-10 16:18:15 -0800 | [diff] [blame] | 24 | import com.android.launcher3.util.FocusLogic; |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 25 | import com.android.launcher3.widget.LauncherAppWidgetHostView; |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 26 | |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 27 | public class AppWidgetResizeFrame extends AbstractFloatingView implements View.OnKeyListener { |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 28 | private static final int SNAP_DURATION = 150; |
| 29 | private static final float DIMMED_HANDLE_ALPHA = 0f; |
| 30 | private static final float RESIZE_THRESHOLD = 0.66f; |
| 31 | |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 32 | private static final Rect sTmpRect = new Rect(); |
| 33 | |
| 34 | // Represents the cell size on the grid in the two orientations. |
| 35 | private static Point[] sCellSize; |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 36 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 37 | private static final int HANDLE_COUNT = 4; |
| 38 | private static final int INDEX_LEFT = 0; |
| 39 | private static final int INDEX_TOP = 1; |
| 40 | private static final int INDEX_RIGHT = 2; |
| 41 | private static final int INDEX_BOTTOM = 3; |
| 42 | |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 43 | private final Launcher mLauncher; |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 44 | private final DragViewStateAnnouncer mStateAnnouncer; |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 45 | private final FirstFrameAnimatorHelper mFirstFrameAnimatorHelper; |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 46 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 47 | private final View[] mDragHandles = new View[HANDLE_COUNT]; |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 48 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 49 | private LauncherAppWidgetHostView mWidgetView; |
| 50 | private CellLayout mCellLayout; |
| 51 | private DragLayer mDragLayer; |
| 52 | |
| 53 | private Rect mWidgetPadding; |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 54 | |
| 55 | private final int mBackgroundPadding; |
| 56 | private final int mTouchTargetWidth; |
| 57 | |
| 58 | private final int[] mDirectionVector = new int[2]; |
| 59 | private final int[] mLastDirectionVector = new int[2]; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 60 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 61 | private final IntRange mTempRange1 = new IntRange(); |
| 62 | private final IntRange mTempRange2 = new IntRange(); |
| 63 | |
| 64 | private final IntRange mDeltaXRange = new IntRange(); |
| 65 | private final IntRange mBaselineX = new IntRange(); |
| 66 | |
| 67 | private final IntRange mDeltaYRange = new IntRange(); |
| 68 | private final IntRange mBaselineY = new IntRange(); |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 69 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 70 | private boolean mLeftBorderActive; |
| 71 | private boolean mRightBorderActive; |
| 72 | private boolean mTopBorderActive; |
| 73 | private boolean mBottomBorderActive; |
| 74 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 75 | private int mResizeMode; |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 76 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 77 | private int mRunningHInc; |
| 78 | private int mRunningVInc; |
| 79 | private int mMinHSpan; |
| 80 | private int mMinVSpan; |
| 81 | private int mDeltaX; |
| 82 | private int mDeltaY; |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 83 | private int mDeltaXAddOn; |
| 84 | private int mDeltaYAddOn; |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 85 | |
Adam Cohen | 4459d6b | 2012-07-13 15:59:15 -0700 | [diff] [blame] | 86 | private int mTopTouchRegionAdjustment = 0; |
| 87 | private int mBottomTouchRegionAdjustment = 0; |
| 88 | |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame] | 89 | private int mXDown, mYDown; |
| 90 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 91 | public AppWidgetResizeFrame(Context context) { |
| 92 | this(context, null); |
| 93 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 94 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 95 | public AppWidgetResizeFrame(Context context, AttributeSet attrs) { |
| 96 | this(context, attrs, 0); |
| 97 | } |
| 98 | |
| 99 | public AppWidgetResizeFrame(Context context, AttributeSet attrs, int defStyleAttr) { |
| 100 | super(context, attrs, defStyleAttr); |
| 101 | |
| 102 | mLauncher = Launcher.getLauncher(context); |
| 103 | mStateAnnouncer = DragViewStateAnnouncer.createFor(this); |
| 104 | |
| 105 | mBackgroundPadding = getResources() |
| 106 | .getDimensionPixelSize(R.dimen.resize_frame_background_padding); |
| 107 | mTouchTargetWidth = 2 * mBackgroundPadding; |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 108 | mFirstFrameAnimatorHelper = new FirstFrameAnimatorHelper(this); |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | @Override |
| 112 | protected void onFinishInflate() { |
| 113 | super.onFinishInflate(); |
| 114 | |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 115 | ViewGroup content = (ViewGroup) getChildAt(0); |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 116 | for (int i = 0; i < HANDLE_COUNT; i ++) { |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 117 | mDragHandles[i] = content.getChildAt(i); |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 121 | public static void showForWidget(LauncherAppWidgetHostView widget, CellLayout cellLayout) { |
| 122 | Launcher launcher = Launcher.getLauncher(cellLayout.getContext()); |
| 123 | AbstractFloatingView.closeAllOpenViews(launcher); |
| 124 | |
| 125 | DragLayer dl = launcher.getDragLayer(); |
| 126 | AppWidgetResizeFrame frame = (AppWidgetResizeFrame) launcher.getLayoutInflater() |
| 127 | .inflate(R.layout.app_widget_resize_frame, dl, false); |
| 128 | frame.setupForWidget(widget, cellLayout, dl); |
| 129 | ((DragLayer.LayoutParams) frame.getLayoutParams()).customPosition = true; |
| 130 | |
| 131 | dl.addView(frame); |
| 132 | frame.mIsOpen = true; |
| 133 | frame.snapToWidget(false); |
| 134 | } |
| 135 | |
| 136 | private void setupForWidget(LauncherAppWidgetHostView widgetView, CellLayout cellLayout, |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 137 | DragLayer dragLayer) { |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 138 | mCellLayout = cellLayout; |
| 139 | mWidgetView = widgetView; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 140 | LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) |
| 141 | widgetView.getAppWidgetInfo(); |
| 142 | mResizeMode = info.resizeMode; |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 143 | mDragLayer = dragLayer; |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 144 | |
Sunny Goyal | 233ee96 | 2015-08-03 13:05:01 -0700 | [diff] [blame] | 145 | mMinHSpan = info.minSpanX; |
| 146 | mMinVSpan = info.minSpanY; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 147 | |
Sunny Goyal | 952e63d | 2017-08-16 04:59:08 -0700 | [diff] [blame] | 148 | mWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(getContext(), |
| 149 | widgetView.getAppWidgetInfo().provider, null); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 150 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 151 | if (mResizeMode == AppWidgetProviderInfo.RESIZE_HORIZONTAL) { |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 152 | mDragHandles[INDEX_TOP].setVisibility(GONE); |
| 153 | mDragHandles[INDEX_BOTTOM].setVisibility(GONE); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 154 | } else if (mResizeMode == AppWidgetProviderInfo.RESIZE_VERTICAL) { |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 155 | mDragHandles[INDEX_LEFT].setVisibility(GONE); |
| 156 | mDragHandles[INDEX_RIGHT].setVisibility(GONE); |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 159 | // When we create the resize frame, we first mark all cells as unoccupied. The appropriate |
| 160 | // cells (same if not resized, or different) will be marked as occupied when the resize |
| 161 | // frame is dismissed. |
| 162 | mCellLayout.markCellsAsUnoccupiedForView(mWidgetView); |
Tony Wickham | 71255bb | 2016-02-10 16:18:15 -0800 | [diff] [blame] | 163 | |
| 164 | setOnKeyListener(this); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | public boolean beginResizeIfPointInRegion(int x, int y) { |
| 168 | boolean horizontalActive = (mResizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0; |
| 169 | boolean verticalActive = (mResizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0; |
Adam Cohen | 4459d6b | 2012-07-13 15:59:15 -0700 | [diff] [blame] | 170 | |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 171 | mLeftBorderActive = (x < mTouchTargetWidth) && horizontalActive; |
| 172 | mRightBorderActive = (x > getWidth() - mTouchTargetWidth) && horizontalActive; |
Adam Cohen | 4459d6b | 2012-07-13 15:59:15 -0700 | [diff] [blame] | 173 | mTopBorderActive = (y < mTouchTargetWidth + mTopTouchRegionAdjustment) && verticalActive; |
| 174 | mBottomBorderActive = (y > getHeight() - mTouchTargetWidth + mBottomTouchRegionAdjustment) |
| 175 | && verticalActive; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 176 | |
| 177 | boolean anyBordersActive = mLeftBorderActive || mRightBorderActive |
| 178 | || mTopBorderActive || mBottomBorderActive; |
| 179 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 180 | if (anyBordersActive) { |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 181 | mDragHandles[INDEX_LEFT].setAlpha(mLeftBorderActive ? 1.0f : DIMMED_HANDLE_ALPHA); |
| 182 | mDragHandles[INDEX_RIGHT].setAlpha(mRightBorderActive ? 1.0f :DIMMED_HANDLE_ALPHA); |
| 183 | mDragHandles[INDEX_TOP].setAlpha(mTopBorderActive ? 1.0f : DIMMED_HANDLE_ALPHA); |
| 184 | mDragHandles[INDEX_BOTTOM].setAlpha(mBottomBorderActive ? 1.0f : DIMMED_HANDLE_ALPHA); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 185 | } |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 186 | |
| 187 | if (mLeftBorderActive) { |
| 188 | mDeltaXRange.set(-getLeft(), getWidth() - 2 * mTouchTargetWidth); |
| 189 | } else if (mRightBorderActive) { |
| 190 | mDeltaXRange.set(2 * mTouchTargetWidth - getWidth(), mDragLayer.getWidth() - getRight()); |
| 191 | } else { |
| 192 | mDeltaXRange.set(0, 0); |
| 193 | } |
| 194 | mBaselineX.set(getLeft(), getRight()); |
| 195 | |
| 196 | if (mTopBorderActive) { |
| 197 | mDeltaYRange.set(-getTop(), getHeight() - 2 * mTouchTargetWidth); |
| 198 | } else if (mBottomBorderActive) { |
| 199 | mDeltaYRange.set(2 * mTouchTargetWidth - getHeight(), mDragLayer.getHeight() - getBottom()); |
| 200 | } else { |
| 201 | mDeltaYRange.set(0, 0); |
| 202 | } |
| 203 | mBaselineY.set(getTop(), getBottom()); |
| 204 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 205 | return anyBordersActive; |
| 206 | } |
| 207 | |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 208 | /** |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 209 | * Based on the deltas, we resize the frame. |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 210 | */ |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 211 | public void visualizeResizeForDelta(int deltaX, int deltaY) { |
| 212 | mDeltaX = mDeltaXRange.clamp(deltaX); |
| 213 | mDeltaY = mDeltaYRange.clamp(deltaY); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 214 | |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 215 | DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 216 | mDeltaX = mDeltaXRange.clamp(deltaX); |
| 217 | mBaselineX.applyDelta(mLeftBorderActive, mRightBorderActive, mDeltaX, mTempRange1); |
| 218 | lp.x = mTempRange1.start; |
| 219 | lp.width = mTempRange1.size(); |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 220 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 221 | mDeltaY = mDeltaYRange.clamp(deltaY); |
| 222 | mBaselineY.applyDelta(mTopBorderActive, mBottomBorderActive, mDeltaY, mTempRange1); |
| 223 | lp.y = mTempRange1.start; |
| 224 | lp.height = mTempRange1.size(); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 225 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 226 | resizeWidgetIfNeeded(false); |
Jon Miranda | 097a725 | 2016-12-28 10:49:55 -0800 | [diff] [blame] | 227 | |
| 228 | // When the widget resizes in multi-window mode, the translation value changes to maintain |
| 229 | // a center fit. These overrides ensure the resize frame always aligns with the widget view. |
| 230 | getSnappedRectRelativeToDragLayer(sTmpRect); |
| 231 | if (mLeftBorderActive) { |
| 232 | lp.width = sTmpRect.width() + sTmpRect.left - lp.x; |
| 233 | } |
| 234 | if (mTopBorderActive) { |
| 235 | lp.height = sTmpRect.height() + sTmpRect.top - lp.y; |
| 236 | } |
| 237 | if (mRightBorderActive) { |
| 238 | lp.x = sTmpRect.left; |
| 239 | } |
| 240 | if (mBottomBorderActive) { |
| 241 | lp.y = sTmpRect.top; |
| 242 | } |
| 243 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 244 | requestLayout(); |
| 245 | } |
| 246 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 247 | private static int getSpanIncrement(float deltaFrac) { |
| 248 | return Math.abs(deltaFrac) > RESIZE_THRESHOLD ? Math.round(deltaFrac) : 0; |
| 249 | } |
| 250 | |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 251 | /** |
| 252 | * Based on the current deltas, we determine if and how to resize the widget. |
| 253 | */ |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 254 | private void resizeWidgetIfNeeded(boolean onDismiss) { |
Sunny Goyal | aa8a871 | 2016-11-20 15:26:01 +0530 | [diff] [blame] | 255 | float xThreshold = mCellLayout.getCellWidth(); |
| 256 | float yThreshold = mCellLayout.getCellHeight(); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 257 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 258 | int hSpanInc = getSpanIncrement((mDeltaX + mDeltaXAddOn) / xThreshold - mRunningHInc); |
| 259 | int vSpanInc = getSpanIncrement((mDeltaY + mDeltaYAddOn) / yThreshold - mRunningVInc); |
Adam Cohen | e4b7729 | 2011-03-08 18:35:52 -0800 | [diff] [blame] | 260 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 261 | if (!onDismiss && (hSpanInc == 0 && vSpanInc == 0)) return; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 262 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 263 | mDirectionVector[0] = 0; |
| 264 | mDirectionVector[1] = 0; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 265 | |
| 266 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mWidgetView.getLayoutParams(); |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 267 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 268 | int spanX = lp.cellHSpan; |
| 269 | int spanY = lp.cellVSpan; |
| 270 | int cellX = lp.useTmpCoords ? lp.tmpCellX : lp.cellX; |
| 271 | int cellY = lp.useTmpCoords ? lp.tmpCellY : lp.cellY; |
| 272 | |
Adam Cohen | 1b607ed | 2011-03-03 17:26:50 -0800 | [diff] [blame] | 273 | // For each border, we bound the resizing based on the minimum width, and the maximum |
| 274 | // expandability. |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 275 | mTempRange1.set(cellX, spanX + cellX); |
| 276 | int hSpanDelta = mTempRange1.applyDeltaAndBound(mLeftBorderActive, mRightBorderActive, |
| 277 | hSpanInc, mMinHSpan, mCellLayout.getCountX(), mTempRange2); |
| 278 | cellX = mTempRange2.start; |
| 279 | spanX = mTempRange2.size(); |
| 280 | if (hSpanDelta != 0) { |
| 281 | mDirectionVector[0] = mLeftBorderActive ? -1 : 1; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 282 | } |
| 283 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 284 | mTempRange1.set(cellY, spanY + cellY); |
| 285 | int vSpanDelta = mTempRange1.applyDeltaAndBound(mTopBorderActive, mBottomBorderActive, |
| 286 | vSpanInc, mMinVSpan, mCellLayout.getCountY(), mTempRange2); |
| 287 | cellY = mTempRange2.start; |
| 288 | spanY = mTempRange2.size(); |
| 289 | if (vSpanDelta != 0) { |
| 290 | mDirectionVector[1] = mTopBorderActive ? -1 : 1; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 293 | if (!onDismiss && vSpanDelta == 0 && hSpanDelta == 0) return; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 294 | |
Adam Cohen | e048950 | 2012-08-27 15:18:53 -0700 | [diff] [blame] | 295 | // We always want the final commit to match the feedback, so we make sure to use the |
| 296 | // last used direction vector when committing the resize / reorder. |
| 297 | if (onDismiss) { |
| 298 | mDirectionVector[0] = mLastDirectionVector[0]; |
| 299 | mDirectionVector[1] = mLastDirectionVector[1]; |
| 300 | } else { |
| 301 | mLastDirectionVector[0] = mDirectionVector[0]; |
| 302 | mLastDirectionVector[1] = mDirectionVector[1]; |
| 303 | } |
| 304 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 305 | if (mCellLayout.createAreaForResize(cellX, cellY, spanX, spanY, mWidgetView, |
| 306 | mDirectionVector, onDismiss)) { |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 307 | if (mStateAnnouncer != null && (lp.cellHSpan != spanX || lp.cellVSpan != spanY) ) { |
| 308 | mStateAnnouncer.announce( |
| 309 | mLauncher.getString(R.string.widget_resized, spanX, spanY)); |
| 310 | } |
| 311 | |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 312 | lp.tmpCellX = cellX; |
| 313 | lp.tmpCellY = cellY; |
| 314 | lp.cellHSpan = spanX; |
| 315 | lp.cellVSpan = spanY; |
| 316 | mRunningVInc += vSpanDelta; |
| 317 | mRunningHInc += hSpanDelta; |
Sunny Goyal | e78e3d7 | 2015-09-24 11:23:31 -0700 | [diff] [blame] | 318 | |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 319 | if (!onDismiss) { |
| 320 | updateWidgetSizeRanges(mWidgetView, mLauncher, spanX, spanY); |
| 321 | } |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 322 | } |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 323 | mWidgetView.requestLayout(); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 326 | static void updateWidgetSizeRanges(AppWidgetHostView widgetView, Launcher launcher, |
| 327 | int spanX, int spanY) { |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 328 | getWidgetSizeRanges(launcher, spanX, spanY, sTmpRect); |
| 329 | widgetView.updateAppWidgetSize(null, sTmpRect.left, sTmpRect.top, |
| 330 | sTmpRect.right, sTmpRect.bottom); |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Sunny Goyal | 16466f1 | 2016-03-10 05:34:30 -0800 | [diff] [blame] | 333 | public static Rect getWidgetSizeRanges(Context context, int spanX, int spanY, Rect rect) { |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 334 | if (sCellSize == null) { |
Sunny Goyal | 87f784c | 2017-01-11 10:48:34 -0800 | [diff] [blame] | 335 | InvariantDeviceProfile inv = LauncherAppState.getIDP(context); |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 336 | |
| 337 | // Initiate cell sizes. |
| 338 | sCellSize = new Point[2]; |
| 339 | sCellSize[0] = inv.landscapeProfile.getCellSize(); |
| 340 | sCellSize[1] = inv.portraitProfile.getCellSize(); |
| 341 | } |
| 342 | |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 343 | if (rect == null) { |
| 344 | rect = new Rect(); |
| 345 | } |
Sunny Goyal | 16466f1 | 2016-03-10 05:34:30 -0800 | [diff] [blame] | 346 | final float density = context.getResources().getDisplayMetrics().density; |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 347 | |
| 348 | // Compute landscape size |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 349 | int landWidth = (int) ((spanX * sCellSize[0].x) / density); |
| 350 | int landHeight = (int) ((spanY * sCellSize[0].y) / density); |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 351 | |
| 352 | // Compute portrait size |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 353 | int portWidth = (int) ((spanX * sCellSize[1].x) / density); |
| 354 | int portHeight = (int) ((spanY * sCellSize[1].y) / density); |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 355 | rect.set(portWidth, landHeight, landWidth, portHeight); |
| 356 | return rect; |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Sunny Goyal | 988ad27 | 2017-08-18 02:05:01 -0700 | [diff] [blame] | 359 | @Override |
| 360 | protected void onDetachedFromWindow() { |
| 361 | super.onDetachedFromWindow(); |
| 362 | |
| 363 | // We are done with resizing the widget. Save the widget size & position to LauncherModel |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 364 | resizeWidgetIfNeeded(true); |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 365 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 366 | |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame] | 367 | private void onTouchUp() { |
Sunny Goyal | aa8a871 | 2016-11-20 15:26:01 +0530 | [diff] [blame] | 368 | int xThreshold = mCellLayout.getCellWidth(); |
| 369 | int yThreshold = mCellLayout.getCellHeight(); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 370 | |
Jon Miranda | 097a725 | 2016-12-28 10:49:55 -0800 | [diff] [blame] | 371 | mDeltaXAddOn = mRunningHInc * xThreshold; |
| 372 | mDeltaYAddOn = mRunningVInc * yThreshold; |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 373 | mDeltaX = 0; |
| 374 | mDeltaY = 0; |
| 375 | |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 376 | post(() -> snapToWidget(true)); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 377 | } |
| 378 | |
Jon Miranda | 097a725 | 2016-12-28 10:49:55 -0800 | [diff] [blame] | 379 | /** |
| 380 | * Returns the rect of this view when the frame is snapped around the widget, with the bounds |
| 381 | * relative to the {@link DragLayer}. |
| 382 | */ |
| 383 | private void getSnappedRectRelativeToDragLayer(Rect out) { |
Jon Miranda | 2126691 | 2016-12-19 14:12:05 -0800 | [diff] [blame] | 384 | float scale = mWidgetView.getScaleToFit(); |
Adam Cohen | 37b59ff | 2011-06-13 17:13:42 -0700 | [diff] [blame] | 385 | |
Jon Miranda | 097a725 | 2016-12-28 10:49:55 -0800 | [diff] [blame] | 386 | mDragLayer.getViewRectRelativeToSelf(mWidgetView, out); |
Adam Cohen | d6e7aa3 | 2013-07-09 15:32:37 -0700 | [diff] [blame] | 387 | |
Jon Miranda | 097a725 | 2016-12-28 10:49:55 -0800 | [diff] [blame] | 388 | int width = 2 * mBackgroundPadding |
| 389 | + (int) (scale * (out.width() - mWidgetPadding.left - mWidgetPadding.right)); |
| 390 | int height = 2 * mBackgroundPadding |
| 391 | + (int) (scale * (out.height() - mWidgetPadding.top - mWidgetPadding.bottom)); |
Jon Miranda | 26e4d17 | 2016-12-12 15:43:18 -0800 | [diff] [blame] | 392 | |
Jon Miranda | 097a725 | 2016-12-28 10:49:55 -0800 | [diff] [blame] | 393 | int x = (int) (out.left - mBackgroundPadding + scale * mWidgetPadding.left); |
| 394 | int y = (int) (out.top - mBackgroundPadding + scale * mWidgetPadding.top); |
| 395 | |
| 396 | out.left = x; |
| 397 | out.top = y; |
| 398 | out.right = out.left + width; |
| 399 | out.bottom = out.top + height; |
| 400 | } |
| 401 | |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 402 | private void snapToWidget(boolean animate) { |
Jon Miranda | 097a725 | 2016-12-28 10:49:55 -0800 | [diff] [blame] | 403 | getSnappedRectRelativeToDragLayer(sTmpRect); |
| 404 | int newWidth = sTmpRect.width(); |
| 405 | int newHeight = sTmpRect.height(); |
| 406 | int newX = sTmpRect.left; |
| 407 | int newY = sTmpRect.top; |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 408 | |
Sunny Goyal | ba776d5 | 2015-05-18 20:52:57 -0700 | [diff] [blame] | 409 | // 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] | 410 | // DragLayer. We allow the actual handles to be clipped, but we shift the touch regions |
| 411 | // down accordingly to provide a proper touch target. |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 412 | if (newY < 0) { |
Adam Cohen | 4459d6b | 2012-07-13 15:59:15 -0700 | [diff] [blame] | 413 | // In this case we shift the touch region down to start at the top of the DragLayer |
| 414 | mTopTouchRegionAdjustment = -newY; |
| 415 | } else { |
| 416 | mTopTouchRegionAdjustment = 0; |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 417 | } |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 418 | if (newY + newHeight > mDragLayer.getHeight()) { |
Adam Cohen | 4459d6b | 2012-07-13 15:59:15 -0700 | [diff] [blame] | 419 | // In this case we shift the touch region up to end at the bottom of the DragLayer |
| 420 | mBottomTouchRegionAdjustment = -(newY + newHeight - mDragLayer.getHeight()); |
| 421 | } else { |
| 422 | mBottomTouchRegionAdjustment = 0; |
Adam Cohen | 3cba722 | 2011-03-02 19:03:11 -0800 | [diff] [blame] | 423 | } |
| 424 | |
Jon Miranda | 26e4d17 | 2016-12-12 15:43:18 -0800 | [diff] [blame] | 425 | final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 426 | if (!animate) { |
| 427 | lp.width = newWidth; |
| 428 | lp.height = newHeight; |
| 429 | lp.x = newX; |
| 430 | lp.y = newY; |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 431 | for (int i = 0; i < HANDLE_COUNT; i++) { |
| 432 | mDragHandles[i].setAlpha(1.0f); |
| 433 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 434 | requestLayout(); |
| 435 | } else { |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 436 | ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(lp, |
Sunny Goyal | 55bdeed | 2018-09-18 16:17:22 -0700 | [diff] [blame^] | 437 | PropertyValuesHolder.ofInt(LAYOUT_WIDTH, lp.width, newWidth), |
| 438 | PropertyValuesHolder.ofInt(LAYOUT_HEIGHT, lp.height, newHeight), |
| 439 | PropertyValuesHolder.ofInt(LAYOUT_X, lp.x, newX), |
| 440 | PropertyValuesHolder.ofInt(LAYOUT_Y, lp.y, newY)); |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 441 | mFirstFrameAnimatorHelper.addTo(oa).addUpdateListener(a -> requestLayout()); |
Sunny Goyal | 849c6a2 | 2018-08-08 16:33:46 -0700 | [diff] [blame] | 442 | |
| 443 | AnimatorSet set = new AnimatorSet(); |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 444 | set.play(oa); |
| 445 | for (int i = 0; i < HANDLE_COUNT; i++) { |
Sunny Goyal | f0b6db7 | 2018-08-13 16:10:14 -0700 | [diff] [blame] | 446 | set.play(mFirstFrameAnimatorHelper.addTo( |
| 447 | ObjectAnimator.ofFloat(mDragHandles[i], ALPHA, 1f))); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 448 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 449 | set.setDuration(SNAP_DURATION); |
| 450 | set.start(); |
| 451 | } |
Tony Wickham | 71255bb | 2016-02-10 16:18:15 -0800 | [diff] [blame] | 452 | |
| 453 | setFocusableInTouchMode(true); |
| 454 | requestFocus(); |
| 455 | } |
| 456 | |
| 457 | @Override |
| 458 | public boolean onKey(View v, int keyCode, KeyEvent event) { |
| 459 | // Clear the frame and give focus to the widget host view when a directional key is pressed. |
| 460 | if (FocusLogic.shouldConsume(keyCode)) { |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 461 | close(false); |
Tony Wickham | 71255bb | 2016-02-10 16:18:15 -0800 | [diff] [blame] | 462 | mWidgetView.requestFocus(); |
| 463 | return true; |
| 464 | } |
| 465 | return false; |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 466 | } |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame] | 467 | |
| 468 | private boolean handleTouchDown(MotionEvent ev) { |
| 469 | Rect hitRect = new Rect(); |
| 470 | int x = (int) ev.getX(); |
| 471 | int y = (int) ev.getY(); |
| 472 | |
| 473 | getHitRect(hitRect); |
| 474 | if (hitRect.contains(x, y)) { |
| 475 | if (beginResizeIfPointInRegion(x - getLeft(), y - getTop())) { |
| 476 | mXDown = x; |
| 477 | mYDown = y; |
| 478 | return true; |
| 479 | } |
| 480 | } |
| 481 | return false; |
| 482 | } |
| 483 | |
| 484 | @Override |
| 485 | public boolean onControllerTouchEvent(MotionEvent ev) { |
| 486 | int action = ev.getAction(); |
| 487 | int x = (int) ev.getX(); |
| 488 | int y = (int) ev.getY(); |
| 489 | |
| 490 | switch (action) { |
| 491 | case MotionEvent.ACTION_DOWN: |
| 492 | return handleTouchDown(ev); |
| 493 | case MotionEvent.ACTION_MOVE: |
| 494 | visualizeResizeForDelta(x - mXDown, y - mYDown); |
| 495 | break; |
| 496 | case MotionEvent.ACTION_CANCEL: |
| 497 | case MotionEvent.ACTION_UP: |
| 498 | visualizeResizeForDelta(x - mXDown, y - mYDown); |
| 499 | onTouchUp(); |
| 500 | mXDown = mYDown = 0; |
| 501 | break; |
| 502 | } |
| 503 | return true; |
| 504 | } |
| 505 | |
| 506 | @Override |
| 507 | public boolean onControllerInterceptTouchEvent(MotionEvent ev) { |
| 508 | if (ev.getAction() == MotionEvent.ACTION_DOWN && handleTouchDown(ev)) { |
| 509 | return true; |
| 510 | } |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 511 | close(false); |
Sunny Goyal | 6ad72f0 | 2016-09-23 11:01:10 -0700 | [diff] [blame] | 512 | return false; |
| 513 | } |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 514 | |
Sunny Goyal | 3792096 | 2017-09-28 13:43:24 -0700 | [diff] [blame] | 515 | @Override |
| 516 | protected void handleClose(boolean animate) { |
| 517 | mDragLayer.removeView(this); |
| 518 | } |
| 519 | |
| 520 | @Override |
| 521 | public void logActionCommand(int command) { |
| 522 | // TODO: Log this case. |
| 523 | } |
| 524 | |
| 525 | @Override |
| 526 | protected boolean isOfType(int type) { |
| 527 | return (type & TYPE_WIDGET_RESIZE_FRAME) != 0; |
| 528 | } |
| 529 | |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 530 | /** |
| 531 | * A mutable class for describing the range of two int values. |
| 532 | */ |
| 533 | private static class IntRange { |
| 534 | |
| 535 | public int start, end; |
| 536 | |
| 537 | public int clamp(int value) { |
| 538 | return Utilities.boundToRange(value, start, end); |
| 539 | } |
| 540 | |
| 541 | public void set(int s, int e) { |
| 542 | start = s; |
| 543 | end = e; |
| 544 | } |
| 545 | |
| 546 | public int size() { |
| 547 | return end - start; |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * Moves either the start or end edge (but never both) by {@param delta} and sets the |
| 552 | * result in {@param out} |
| 553 | */ |
| 554 | public void applyDelta(boolean moveStart, boolean moveEnd, int delta, IntRange out) { |
| 555 | out.start = moveStart ? start + delta : start; |
| 556 | out.end = moveEnd ? end + delta : end; |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Applies delta similar to {@link #applyDelta(boolean, boolean, int, IntRange)}, |
| 561 | * with extra conditions. |
| 562 | * @param minSize minimum size after with the moving edge should not be shifted any further. |
| 563 | * For eg, if delta = -3 when moving the endEdge brings the size to less than |
| 564 | * minSize, only delta = -2 will applied |
| 565 | * @param maxEnd The maximum value to the end edge (start edge is always restricted to 0) |
| 566 | * @return the amount of increase when endEdge was moves and the amount of decrease when |
| 567 | * the start edge was moved. |
| 568 | */ |
| 569 | public int applyDeltaAndBound(boolean moveStart, boolean moveEnd, int delta, |
| 570 | int minSize, int maxEnd, IntRange out) { |
| 571 | applyDelta(moveStart, moveEnd, delta, out); |
Jon Miranda | 9f33cb2 | 2017-01-03 09:30:00 -0800 | [diff] [blame] | 572 | if (out.start < 0) { |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 573 | out.start = 0; |
| 574 | } |
Jon Miranda | 9f33cb2 | 2017-01-03 09:30:00 -0800 | [diff] [blame] | 575 | if (out.end > maxEnd) { |
Sunny Goyal | 08ca40f | 2016-09-13 21:07:31 -0700 | [diff] [blame] | 576 | out.end = maxEnd; |
| 577 | } |
| 578 | if (out.size() < minSize) { |
| 579 | if (moveStart) { |
| 580 | out.start = out.end - minSize; |
| 581 | } else if (moveEnd) { |
| 582 | out.end = out.start + minSize; |
| 583 | } |
| 584 | } |
| 585 | return moveEnd ? out.size() - size() : size() - out.size(); |
| 586 | } |
| 587 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 588 | } |