public int getSlideState() { int retValue = STATE_CLOSE; if (mIsScrolling) { retValue = STATE_SLIDING; } else { retValue = (getScrollX() == 0) ? STATE_CLOSE : STATE_OPEN; } return retValue; }
public MiniSlideRightLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context, attrs); }
public void smoothCloseSlide() { smoothScrollTo(0, 0); }
int eventX = (int) event.getX(); int eventY = (int) event.getY(); int scrollX = getScrollX(); break; getParent().requestDisallowInterceptTouchEvent(true); mIsScrolling = true; int newScrollX = scrollX - offsetX; newScrollX = mSlideView.getMeasuredWidth(); scrollTo(newScrollX, 0); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsScrolling = false; getParent().requestDisallowInterceptTouchEvent(false); int finalScrollX = 0; mSlideSensitiveWidth = mSlideView.getMeasuredWidth() / 2; finalScrollX = mSlideView.getMeasuredWidth(); smoothScrollTo(finalScrollX, 0); break;
private void smoothScrollTo(int destX, int destY) { int scrollX = getScrollX(); int deltaX = destX - scrollX; int scrollY = getScrollY(); int deltaY = destY - scrollY; mScroller.startScroll(scrollX, scrollY, deltaX, deltaY, (int) (Math.abs(Math.sqrt(deltaX*deltaX + deltaY*deltaY)) * 3)); postInvalidate(); }
@Override public void computeScroll() { if (mScroller.computeScrollOffset()) { scrollTo(mScroller.getCurrX(), mScroller.getCurrY()); postInvalidate(); } } }
@Override protected void onFinishInflate() { super.onFinishInflate(); if (getChildCount() != 2) { throw new IllegalArgumentException("SlideLayout only need contains two child (content and slide)."); } mContentView = getChildAt(0); mSlideView = getChildAt(1); }
private void init(Context context, AttributeSet attrs) { setOrientation(HORIZONTAL); mScroller = new Scroller(context); }
public void smoothOpenSlide() { smoothScrollTo(mSlideView.getMeasuredWidth(), 0); }