Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.calculator2; |
| 18 | |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.ValueAnimator; |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 23 | import android.graphics.PointF; |
| 24 | import android.graphics.Rect; |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 25 | import android.os.Bundle; |
| 26 | import android.os.Parcelable; |
| 27 | import android.support.v4.view.ViewCompat; |
| 28 | import android.support.v4.widget.ViewDragHelper; |
| 29 | import android.util.AttributeSet; |
| 30 | import android.view.MotionEvent; |
| 31 | import android.view.View; |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 32 | import android.view.ViewGroup; |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 33 | import android.widget.FrameLayout; |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 34 | |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 35 | import java.util.HashMap; |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 36 | import java.util.List; |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 37 | import java.util.Map; |
Annie Chin | b9ce4d0 | 2016-12-09 15:26:41 -0800 | [diff] [blame] | 38 | import java.util.concurrent.CopyOnWriteArrayList; |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 39 | |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 40 | public class DragLayout extends ViewGroup { |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 41 | |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 42 | private static final double AUTO_OPEN_SPEED_LIMIT = 600.0; |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 43 | private static final String KEY_IS_OPEN = "IS_OPEN"; |
| 44 | private static final String KEY_SUPER_STATE = "SUPER_STATE"; |
| 45 | |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 46 | private FrameLayout mHistoryFrame; |
| 47 | private ViewDragHelper mDragHelper; |
| 48 | |
Annie Chin | b9ce4d0 | 2016-12-09 15:26:41 -0800 | [diff] [blame] | 49 | // No concurrency; allow modifications while iterating. |
| 50 | private final List<DragCallback> mDragCallbacks = new CopyOnWriteArrayList<>(); |
Annie Chin | 9a21113 | 2016-11-30 12:52:06 -0800 | [diff] [blame] | 51 | private CloseCallback mCloseCallback; |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 52 | |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 53 | private final Map<Integer, PointF> mLastMotionPoints = new HashMap<>(); |
| 54 | private final Rect mHitRect = new Rect(); |
| 55 | |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 56 | private int mVerticalRange; |
| 57 | private boolean mIsOpen; |
| 58 | |
| 59 | public DragLayout(Context context, AttributeSet attrs) { |
| 60 | super(context, attrs); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | protected void onFinishInflate() { |
| 65 | mDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback()); |
| 66 | mHistoryFrame = (FrameLayout) findViewById(R.id.history_frame); |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 67 | super.onFinishInflate(); |
| 68 | } |
| 69 | |
| 70 | @Override |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 71 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 72 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 73 | measureChildren(widthMeasureSpec, heightMeasureSpec); |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 77 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 78 | int displayHeight = 0; |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 79 | for (DragCallback c : mDragCallbacks) { |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 80 | displayHeight = Math.max(displayHeight, c.getDisplayHeight()); |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 81 | } |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 82 | mVerticalRange = getHeight() - displayHeight; |
| 83 | |
| 84 | final int childCount = getChildCount(); |
| 85 | for (int i = 0; i < childCount; ++i) { |
| 86 | final View child = getChildAt(i); |
| 87 | |
| 88 | int top = 0; |
| 89 | if (child == mHistoryFrame) { |
Justin Klaassen | dec67e4 | 2017-01-09 08:11:51 -0800 | [diff] [blame^] | 90 | if (mDragHelper.getCapturedView() == mHistoryFrame |
| 91 | && mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE) { |
| 92 | top = child.getTop(); |
| 93 | } else { |
| 94 | top = mIsOpen ? 0 : -mVerticalRange; |
| 95 | } |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 96 | } |
| 97 | child.layout(0, top, child.getMeasuredWidth(), top + child.getMeasuredHeight()); |
| 98 | } |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | @Override |
| 102 | protected Parcelable onSaveInstanceState() { |
| 103 | final Bundle bundle = new Bundle(); |
| 104 | bundle.putParcelable(KEY_SUPER_STATE, super.onSaveInstanceState()); |
| 105 | bundle.putBoolean(KEY_IS_OPEN, mIsOpen); |
| 106 | return bundle; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | protected void onRestoreInstanceState(Parcelable state) { |
| 111 | if (state instanceof Bundle) { |
| 112 | final Bundle bundle = (Bundle) state; |
| 113 | mIsOpen = bundle.getBoolean(KEY_IS_OPEN); |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 114 | mHistoryFrame.setVisibility(mIsOpen ? View.VISIBLE : View.INVISIBLE); |
| 115 | for (DragCallback c : mDragCallbacks) { |
| 116 | c.onInstanceStateRestored(mIsOpen); |
| 117 | } |
| 118 | |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 119 | state = bundle.getParcelable(KEY_SUPER_STATE); |
| 120 | } |
| 121 | super.onRestoreInstanceState(state); |
| 122 | } |
| 123 | |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 124 | private void saveLastMotion(MotionEvent event) { |
Annie Chin | c5b6e4f | 2016-12-05 13:34:14 -0800 | [diff] [blame] | 125 | final int action = event.getActionMasked(); |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 126 | switch (action) { |
| 127 | case MotionEvent.ACTION_DOWN: |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 128 | case MotionEvent.ACTION_POINTER_DOWN: { |
| 129 | final int actionIndex = event.getActionIndex(); |
| 130 | final int pointerId = event.getPointerId(actionIndex); |
| 131 | final PointF point = new PointF(event.getX(actionIndex), event.getY(actionIndex)); |
| 132 | mLastMotionPoints.put(pointerId, point); |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 133 | break; |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 134 | } |
| 135 | case MotionEvent.ACTION_MOVE: { |
| 136 | for (int i = event.getPointerCount() - 1; i >= 0; --i) { |
| 137 | final int pointerId = event.getPointerId(i); |
| 138 | final PointF point = mLastMotionPoints.get(pointerId); |
| 139 | if (point != null) { |
| 140 | point.set(event.getX(i), event.getY(i)); |
| 141 | } |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 142 | } |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 143 | break; |
| 144 | } |
| 145 | case MotionEvent.ACTION_POINTER_UP: { |
| 146 | final int actionIndex = event.getActionIndex(); |
| 147 | final int pointerId = event.getPointerId(actionIndex); |
| 148 | mLastMotionPoints.remove(pointerId); |
| 149 | break; |
| 150 | } |
| 151 | case MotionEvent.ACTION_UP: |
| 152 | case MotionEvent.ACTION_CANCEL: { |
| 153 | mLastMotionPoints.clear(); |
| 154 | break; |
| 155 | } |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 156 | } |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public boolean onInterceptTouchEvent(MotionEvent event) { |
| 161 | saveLastMotion(event); |
| 162 | return mDragHelper.shouldInterceptTouchEvent(event); |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public boolean onTouchEvent(MotionEvent event) { |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 167 | saveLastMotion(event); |
Annie Chin | c5b6e4f | 2016-12-05 13:34:14 -0800 | [diff] [blame] | 168 | mDragHelper.processTouchEvent(event); |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 169 | return true; |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public void computeScroll() { |
| 174 | if (mDragHelper.continueSettling(true)) { |
| 175 | ViewCompat.postInvalidateOnAnimation(this); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | private void onStartDragging() { |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 180 | for (DragCallback c : mDragCallbacks) { |
Annie Chin | 9a21113 | 2016-11-30 12:52:06 -0800 | [diff] [blame] | 181 | c.onStartDraggingOpen(); |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 182 | } |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 183 | mHistoryFrame.setVisibility(VISIBLE); |
| 184 | } |
| 185 | |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 186 | public boolean isViewUnder(View view, int x, int y) { |
| 187 | view.getHitRect(mHitRect); |
| 188 | offsetDescendantRectToMyCoords((View) view.getParent(), mHitRect); |
| 189 | return mHitRect.contains(x, y); |
| 190 | } |
| 191 | |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 192 | public boolean isMoving() { |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 193 | final int draggingState = mDragHelper.getViewDragState(); |
| 194 | return draggingState == ViewDragHelper.STATE_DRAGGING |
| 195 | || draggingState == ViewDragHelper.STATE_SETTLING; |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | public boolean isOpen() { |
| 199 | return mIsOpen; |
| 200 | } |
| 201 | |
Justin Klaassen | dec67e4 | 2017-01-09 08:11:51 -0800 | [diff] [blame^] | 202 | private void setClosed() { |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 203 | if (mIsOpen) { |
| 204 | mIsOpen = false; |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 205 | mHistoryFrame.setVisibility(View.INVISIBLE); |
| 206 | |
| 207 | if (mCloseCallback != null) { |
| 208 | mCloseCallback.onClose(); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
Justin Klaassen | dec67e4 | 2017-01-09 08:11:51 -0800 | [diff] [blame^] | 213 | public Animator createAnimator(boolean toOpen) { |
| 214 | if (mIsOpen == toOpen) { |
| 215 | return null; |
| 216 | } |
| 217 | |
| 218 | mIsOpen = true; |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 219 | mHistoryFrame.setVisibility(VISIBLE); |
| 220 | |
| 221 | final ValueAnimator animator = ValueAnimator.ofInt(mHistoryFrame.getTop(), |
| 222 | toOpen ? 0 : -mVerticalRange); |
| 223 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 224 | @Override |
| 225 | public void onAnimationUpdate(ValueAnimator animator) { |
| 226 | final int top = (int) animator.getAnimatedValue(); |
| 227 | mHistoryFrame.offsetTopAndBottom(top - mHistoryFrame.getTop()); |
| 228 | |
| 229 | for (DragCallback c : mDragCallbacks) { |
| 230 | // Top is between [-mVerticalRange, 0]. |
| 231 | c.whileDragging(1f + (float) top / mVerticalRange); |
| 232 | } |
| 233 | } |
| 234 | }); |
Justin Klaassen | dec67e4 | 2017-01-09 08:11:51 -0800 | [diff] [blame^] | 235 | if (!toOpen) { |
| 236 | animator.addListener(new AnimatorListenerAdapter() { |
| 237 | @Override |
| 238 | public void onAnimationEnd(Animator animator) { |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 239 | setClosed(); |
| 240 | } |
Justin Klaassen | dec67e4 | 2017-01-09 08:11:51 -0800 | [diff] [blame^] | 241 | }); |
| 242 | } |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 243 | |
| 244 | return animator; |
Annie Chin | 9a21113 | 2016-11-30 12:52:06 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | public void setCloseCallback(CloseCallback callback) { |
| 248 | mCloseCallback = callback; |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 251 | public void addDragCallback(DragCallback callback) { |
| 252 | mDragCallbacks.add(callback); |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 255 | public void removeDragCallback(DragCallback callback) { |
| 256 | mDragCallbacks.remove(callback); |
| 257 | } |
| 258 | |
| 259 | /** |
Annie Chin | 9a21113 | 2016-11-30 12:52:06 -0800 | [diff] [blame] | 260 | * Callback when the layout is closed. |
| 261 | * We use this to pop the HistoryFragment off the backstack. |
| 262 | * We can't use a method in DragCallback because we get ConcurrentModificationExceptions on |
| 263 | * mDragCallbacks when executePendingTransactions() is called for popping the fragment off the |
| 264 | * backstack. |
| 265 | */ |
| 266 | public interface CloseCallback { |
| 267 | void onClose(); |
| 268 | } |
| 269 | |
| 270 | /** |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 271 | * Callbacks for coordinating with the RecyclerView or HistoryFragment. |
| 272 | */ |
| 273 | public interface DragCallback { |
Annie Chin | 9a21113 | 2016-11-30 12:52:06 -0800 | [diff] [blame] | 274 | // Callback when a drag to open begins. |
| 275 | void onStartDraggingOpen(); |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 276 | |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 277 | // Callback in onRestoreInstanceState. |
| 278 | void onInstanceStateRestored(boolean isOpen); |
| 279 | |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 280 | // Animate the RecyclerView text. |
| 281 | void whileDragging(float yFraction); |
| 282 | |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 283 | // Whether we should allow the view to be dragged. |
| 284 | boolean shouldCaptureView(View view, int x, int y); |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 285 | |
| 286 | int getDisplayHeight(); |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | public class DragHelperCallback extends ViewDragHelper.Callback { |
| 290 | @Override |
| 291 | public void onViewDragStateChanged(int state) { |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 292 | // The view stopped moving. |
Justin Klaassen | dec67e4 | 2017-01-09 08:11:51 -0800 | [diff] [blame^] | 293 | if (state == ViewDragHelper.STATE_IDLE |
| 294 | && mDragHelper.getCapturedView().getTop() < -(mVerticalRange / 2)) { |
| 295 | setClosed(); |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 296 | } |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | @Override |
| 300 | public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) { |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 301 | for (DragCallback c : mDragCallbacks) { |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 302 | // Top is between [-mVerticalRange, 0]. |
| 303 | c.whileDragging(1f + (float) top / mVerticalRange); |
Annie Chin | d0f87d2 | 2016-10-24 09:04:12 -0700 | [diff] [blame] | 304 | } |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public int getViewVerticalDragRange(View child) { |
| 309 | return mVerticalRange; |
| 310 | } |
| 311 | |
| 312 | @Override |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 313 | public boolean tryCaptureView(View view, int pointerId) { |
| 314 | final PointF point = mLastMotionPoints.get(pointerId); |
| 315 | if (point == null) { |
| 316 | return false; |
| 317 | } |
| 318 | |
| 319 | final int x = (int) point.x; |
| 320 | final int y = (int) point.y; |
| 321 | |
| 322 | for (DragCallback c : mDragCallbacks) { |
| 323 | if (!c.shouldCaptureView(view, x, y)) { |
| 324 | return false; |
| 325 | } |
| 326 | } |
| 327 | return true; |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | @Override |
| 331 | public int clampViewPositionVertical(View child, int top, int dy) { |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 332 | return Math.max(Math.min(top, 0), -mVerticalRange); |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void onViewCaptured(View capturedChild, int activePointerId) { |
| 337 | super.onViewCaptured(capturedChild, activePointerId); |
| 338 | |
| 339 | if (!mIsOpen) { |
| 340 | mIsOpen = true; |
| 341 | onStartDragging(); |
| 342 | } |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | @Override |
| 346 | public void onViewReleased(View releasedChild, float xvel, float yvel) { |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 347 | final boolean settleToOpen; |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 348 | if (yvel > AUTO_OPEN_SPEED_LIMIT) { |
| 349 | // Speed has priority over position. |
| 350 | settleToOpen = true; |
| 351 | } else if (yvel < -AUTO_OPEN_SPEED_LIMIT) { |
| 352 | settleToOpen = false; |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 353 | } else { |
| 354 | settleToOpen = releasedChild.getTop() > -(mVerticalRange / 2); |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Justin Klaassen | 3929778 | 2016-12-19 09:11:38 -0800 | [diff] [blame] | 357 | if (mDragHelper.settleCapturedViewAt(0, settleToOpen ? 0 : -mVerticalRange)) { |
Annie Chin | 0954753 | 2016-10-14 10:59:07 -0700 | [diff] [blame] | 358 | ViewCompat.postInvalidateOnAnimation(DragLayout.this); |
| 359 | } |
| 360 | } |
| 361 | } |
Annie Chin | d344322 | 2016-12-07 17:19:07 -0800 | [diff] [blame] | 362 | } |