public void closeMenu() { if (mCloseScroller.computeScrollOffset()) { mCloseScroller.abortAnimation(); } if (state == STATE_OPEN) { state = STATE_CLOSE; swipe(0); } }
public void smoothOpenMenu() { state = STATE_OPEN; if (mSwipeDirection == SwipeMenuRecyclerView.DIRECTION_LEFT) { mOpenScroller.startScroll(-mContentView.getLeft(), 0, mMenuView.getWidth(), 0, animDuration); } else { mOpenScroller.startScroll(mContentView.getLeft(), 0, mMenuView.getWidth(), 0, animDuration); } postInvalidate(); }
public void smoothScrollBy(int dx, int dy, int duration, Interpolator interpolator) { if (mInterpolator != interpolator) { mInterpolator = interpolator; mScroller = ScrollerCompat.create(getContext(), interpolator); } setScrollState(SCROLL_STATE_SETTLING); mLastFlingX = mLastFlingY = 0; mScroller.startScroll(0, 0, dx, dy, duration); postOnAnimation(); }
public void closeOpenedMenu() { state = STATE_CLOSE; if (mSwipeDirection == SwipeMenuRecyclerView.DIRECTION_LEFT) { mBaseX = -mContentView.getLeft(); mCloseScroller.startScroll(0, 0, mMenuView.getWidth(), 0, animDuration); } else { mBaseX = mMenuView.getRight(); mCloseScroller.startScroll(0, 0, mMenuView.getWidth(), 0, animDuration); } postInvalidate(); }
public void smoothCloseMenu() { state = STATE_CLOSE; if (mSwipeDirection == SwipeMenuListView.DIRECTION_LEFT) { mBaseX = -mContentView.getLeft(); mCloseScroller.startScroll(0, 0, mMenuView.getWidth(), 0, 350); } else { mBaseX = mMenuView.getRight(); mCloseScroller.startScroll(0, 0, mMenuView.getWidth(), 0, 350); } postInvalidate(); }
@Override public void computeScroll() { boolean invalidate = mDragHelper.continueSettling(true); if (!mTouchDown && mScroller.computeScrollOffset()) { if (!invalidate) { offsetHeaderBy(mScroller.getCurrY() - getHeaderTop()); } invalidate = true; } updateViewOffset(); if (invalidate) { ViewCompat.postInvalidateOnAnimation(this); } }
private void init() { setLayoutParams( new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); mGestureListener = new SimpleOnGestureListener() { @Override public boolean onDown(MotionEvent e) { isFling = false; return true; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // TODO if ((e1.getX() - e2.getX()) > MIN_FLING && velocityX < MAX_VELOCITYX) { isFling = true; } // Log.i("byz", MAX_VELOCITYX + ", velocityX = " + velocityX); return super.onFling(e1, e2, velocityX, velocityY); } }; mGestureDetector = new GestureDetectorCompat(getContext(), mGestureListener); // mScroller = ScrollerCompat.create(getContext(), new // BounceInterpolator()); if (mCloseInterpolator != null) { mCloseScroller = ScrollerCompat.create(getContext(), mCloseInterpolator); } else { mCloseScroller = ScrollerCompat.create(getContext()); } if (mOpenInterpolator != null) { mOpenScroller = ScrollerCompat.create(getContext(), mOpenInterpolator); } else { mOpenScroller = ScrollerCompat.create(getContext()); } LayoutParams contentParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); mContentView.setLayoutParams(contentParams); if (mContentView.getId() < 1) { mContentView.setId(CONTENT_VIEW_ID); } mMenuView.setId(MENU_VIEW_ID); mMenuView.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); addView(mContentView); addView(mMenuView); }
@Override public void computeScroll() { if (state == STATE_OPEN) { if (mOpenScroller.computeScrollOffset()) { swipe(mOpenScroller.getCurrX() * mSwipeDirection); postInvalidate(); } } else { if (mCloseScroller.computeScrollOffset()) { swipe((mBaseX - mCloseScroller.getCurrX()) * mSwipeDirection); postInvalidate(); } } }
public void flingHeader(float velocity) { if (mTouchDown) { mScroller.abortAnimation(); return; } mScroller.fling( 0, getHeaderTop(), 0, (int) velocity, 0, 0, mContainer.getHeaderTopMinimum(), mContainer.getHeaderTopMaximum()); ViewCompat.postInvalidateOnAnimation(this); }
public void fling(int viewWidth, int viewHeight, int velocityX, int velocityY) { final RectF rect = getDisplayRect(); if (null == rect) { return; } final int startX = Math.round(-rect.left); final int minX, maxX, minY, maxY; if (viewWidth < rect.width()) { minX = 0; maxX = Math.round(rect.width() - viewWidth); } else { minX = maxX = startX; } final int startY = Math.round(-rect.top); if (viewHeight < rect.height()) { minY = 0; maxY = Math.round(rect.height() - viewHeight); } else { minY = maxY = startY; } mCurrentX = startX; mCurrentY = startY; if (startX != maxX || startY != maxY) { mScroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY, 0, 0); } }
@Override public void run() { if (mScroller.isFinished()) { return; } DraweeView<GenericDraweeHierarchy> draweeView = getDraweeView(); if (draweeView != null && mScroller.computeScrollOffset()) { final int newX = mScroller.getCurrX(); final int newY = mScroller.getCurrY(); mMatrix.postTranslate(mCurrentX - newX, mCurrentY - newY); draweeView.invalidate(); mCurrentX = newX; mCurrentY = newY; postOnAnimation(draweeView, this); } }
public void init() { mGestureListener = new SimpleOnGestureListener() { @Override public boolean onDown(MotionEvent e) { isFling = false; return true; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (velocityX > mViewConfiguration.getScaledMinimumFlingVelocity() || velocityY > mViewConfiguration.getScaledMinimumFlingVelocity()) isFling = true; return isFling; } }; mGestureDetector = new GestureDetectorCompat(getContext(), mGestureListener); mCloseScroller = ScrollerCompat.create(getContext()); mOpenScroller = ScrollerCompat.create(getContext()); }
public void fling(int velocityX, int velocityY) { setScrollState(SCROLL_STATE_SETTLING); mLastFlingX = mLastFlingY = 0; mScroller.fling( 0, 0, velocityX, velocityY, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE); postOnAnimation(); }
public HeaderDrawerLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HeaderDrawerLayout); final int headerLayoutId = a.getResourceId(R.styleable.HeaderDrawerLayout_hdl_headerLayout, 0); final int contentLayoutId = a.getResourceId(R.styleable.HeaderDrawerLayout_hdl_contentLayout, 0); addView( mContainer = new InternalContainer(this, context, headerLayoutId, contentLayoutId), LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); a.recycle(); mDragHelper = ViewDragHelper.create(this, mDragCallback = new DragCallback(this)); mGestureDetector = new GestureDetector(context, new GestureListener(this)); mScroller = ScrollerCompat.create(context); }
@Override public boolean dispatchTouchEvent(@NonNull MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: { mScroller.abortAnimation(); mTouchDown = true; mTouchingScrollableContent = isScrollContentCallback(ev.getX(), ev.getY()); mUsingDragHelper = false; break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { mTouchDown = false; mTouchingScrollableContent = false; mUsingDragHelper = false; } } mGestureDetector.onTouchEvent(ev); return super.dispatchTouchEvent(ev); }
public void smoothOpenMenu() { state = STATE_OPEN; mOpenScroller.startScroll(-mContentView.getLeft(), 0, mMenuView.getWidth(), 0, 350); postInvalidate(); }
public ViewFlinger() { mScroller = ScrollerCompat.create(getContext(), sQuinticInterpolator); }
public void cancelFling() { mScroller.abortAnimation(); }
public void setCloseInterpolator(Interpolator closeInterpolator) { mCloseInterpolator = closeInterpolator; if (mCloseInterpolator != null) { mCloseScroller = ScrollerCompat.create(getContext(), mCloseInterpolator); } }
@Override public void run() { disableRunOnAnimationRequests(); // consumePendingUpdateOperations(); // keep a local reference so that if it is changed during onAnimation method, it won't // cause unexpected behaviors final ScrollerCompat scroller = mScroller; if (scroller.computeScrollOffset()) { final int x = scroller.getCurrX(); final int y = scroller.getCurrY(); final int dx = x - mLastFlingX; final int dy = y - mLastFlingY; int hresult = 0; int vresult = 0; mLastFlingX = x; mLastFlingY = y; int overscrollX = 0; int overscrollY = 0; Log.v( TAG, "scrolling scrolling scrolling: " + dy + " y: " + y + " lastY: " + mLastFlingY + " time:"); PlaylistContainerWrapper.this.scrollInternal(dy, 0, null, false); vresult = dy; if (!PlaylistContainerWrapper.this.canScrollDown()) { vresult = 0; scroller.abortAnimation(); } if (overscrollX != 0 || overscrollY != 0) { final int vel = (int) scroller.getCurrVelocity(); int velX = 0; if (overscrollX != x) { velX = overscrollX < 0 ? -vel : overscrollX > 0 ? vel : 0; } int velY = 0; if (overscrollY != y) { velY = overscrollY < 0 ? -vel : overscrollY > 0 ? vel : 0; } if ((velX != 0 || overscrollX == x || scroller.getFinalX() == 0) && (velY != 0 || overscrollY == y || scroller.getFinalY() == 0)) { scroller.abortAnimation(); } } if (hresult != 0 || vresult != 0) { dispatchOnScrolled(hresult, vresult); } if (!awakenScrollBars()) { invalidate(); } final boolean fullyConsumedVertical = dy != 0 && true && vresult == dy; final boolean fullyConsumedHorizontal = dx != 0 && false && hresult == dx; final boolean fullyConsumedAny = (dx == 0 && dy == 0) || fullyConsumedHorizontal || fullyConsumedVertical; if (scroller.isFinished() || !fullyConsumedAny) { setScrollState(SCROLL_STATE_IDLE); // setting state to idle will stop this. } else { postOnAnimation(); } } // call this after the onAnimation is complete not to have inconsistent callbacks etc. /* if (smoothScroller != null) { if (smoothScroller.isPendingInitialRun()) { smoothScroller.onAnimation(0, 0); } if (!mReSchedulePostAnimationCallback) { smoothScroller.stop(); //stop if it does not trigger any scroll } } */ enableRunOnAnimationRequests(); }
public void stop() { removeCallbacks(this); mScroller.abortAnimation(); }
public void smoothCloseMenu() { state = STATE_CLOSE; mBaseX = -mContentView.getLeft(); mCloseScroller.startScroll(0, 0, mBaseX, 0, 350); postInvalidate(); }
public FlingRunnable(Context context) { mScroller = ScrollerCompat.create(context); }
private void init() { setLayoutParams( new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); mGestureListener = new SimpleOnGestureListener() { @Override public boolean onDown(MotionEvent e) { isFling = false; return true; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // TODO if ((e1.getX() - e2.getX()) > MIN_FLING && velocityX < MAX_VELOCITYX) { isFling = true; } // Log.i("byz", MAX_VELOCITYX + ", velocityX = " + velocityX); return super.onFling(e1, e2, velocityX, velocityY); } }; mGestureDetector = new GestureDetectorCompat(getContext(), mGestureListener); // mScroller = ScrollerCompat.create(getContext(), new // BounceInterpolator()); if (mCloseInterpolator != null) { mCloseScroller = ScrollerCompat.create(getContext(), mCloseInterpolator); } else { mCloseScroller = ScrollerCompat.create(getContext()); } if (mOpenInterpolator != null) { mOpenScroller = ScrollerCompat.create(getContext(), mOpenInterpolator); } else { mOpenScroller = ScrollerCompat.create(getContext()); } LayoutParams contentParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); mContentView.setLayoutParams(contentParams); if (mContentView.getId() < 1) { mContentView.setId(CONTENT_VIEW_ID); } mMenuView.setId(MENU_VIEW_ID); mMenuView.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); addView(mContentView); addView(mMenuView); // if (mContentView.getBackground() == null) { // mContentView.setBackgroundColor(Color.WHITE); // } // in android 2.x, MenuView height is MATCH_PARENT is not work. // getViewTreeObserver().addOnGlobalLayoutListener( // new OnGlobalLayoutListener() { // @Override // public void onGlobalLayout() { // setMenuHeight(mContentView.getHeight()); // // getViewTreeObserver() // // .removeGlobalOnLayoutListener(this); // } // }); }
public void setOpenInterpolator(Interpolator openInterpolator) { mOpenInterpolator = openInterpolator; if (mOpenInterpolator != null) { mOpenScroller = ScrollerCompat.create(getContext(), mOpenInterpolator); } }