@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); // Draw the margin drawable if needed. mViewBehind.drawShadow(mContent, canvas); mViewBehind.drawFade(mContent, canvas, getPercentOpen()); mViewBehind.drawSelector(mContent, canvas, getPercentOpen()); }
private boolean thisSlideAllowed(float dx) { boolean allowed = false; if (isMenuOpen()) { allowed = mViewBehind.menuOpenSlideAllowed(dx); } else { allowed = mViewBehind.menuClosedSlideAllowed(dx); } if (DEBUG) Log.v(TAG, "this slide allowed " + allowed + " dx: " + dx); return allowed; }
@Override public void scrollTo(int x, int y) { super.scrollTo(x, y); mScrollX = x; mViewBehind.scrollBehindTo(mContent, x, y); ((SlidingMenu) getParent()).manageLayers(getPercentOpen()); }
private boolean thisTouchAllowed(MotionEvent ev) { int x = (int) (ev.getX() + mScrollX); if (isMenuOpen()) { return mViewBehind.menuOpenTouchAllowed(mContent, mCurItem, x); } else { switch (mTouchMode) { case SlidingMenu.TOUCHMODE_FULLSCREEN: return !isInIgnoredView(ev); case SlidingMenu.TOUCHMODE_NONE: return false; case SlidingMenu.TOUCHMODE_MARGIN: return mViewBehind.marginTouchAllowed(mContent, x); } } return false; }
public int getBehindWidth() { if (mViewBehind == null) { return 0; } else { return mViewBehind.getBehindWidth(); } }
/** * Controls whether the SlidingMenu can be opened with a swipe gesture. Options are {@link * #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN}, or * {@link #TOUCHMODE_NONE TOUCHMODE_NONE} * * @param i the new touch mode */ public void setTouchModeBehind(int i) { if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN && i != TOUCHMODE_NONE) { throw new IllegalStateException( "TouchMode must be set to either" + "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE."); } mViewBehind.setTouchMode(i); }
/** * Sets the behind offset. * * @param i The margin, in pixels, on the right of the screen that the behind view scrolls to. */ public void setBehindOffset(int i) { // RelativeLayout.LayoutParams params = // ((RelativeLayout.LayoutParams)mViewBehind.getLayoutParams()); // int bottom = params.bottomMargin; // int top = params.topMargin; // int left = params.leftMargin; // params.setMargins(left, top, i, bottom); mViewBehind.setWidthOffset(i); }
public int getDestScrollX(int page) { switch (page) { case 0: case 2: return mViewBehind.getMenuLeft(mContent, page); case 1: return mContent.getLeft(); } return 0; }
public void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity) { if (!always && mCurItem == item) { setScrollingCacheEnabled(false); return; } item = mViewBehind.getMenuPage(item); final boolean dispatchSelected = mCurItem != item; mCurItem = item; if (mViewBehind.getbMode()) { final int destY = getDestScrollX(mCurItem); if (dispatchSelected && mOnPageChangeListener != null) { mOnPageChangeListener.onPageSelected(item); } if (dispatchSelected && mInternalPageChangeListener != null) { mInternalPageChangeListener.onPageSelected(item); } if (smoothScroll) { smoothScrollTo(0, destY, velocity); } else { completeScroll(); scrollTo(0, destY); } } else { final int destX = getDestScrollX(mCurItem); if (dispatchSelected && mOnPageChangeListener != null) { mOnPageChangeListener.onPageSelected(item); } if (dispatchSelected && mInternalPageChangeListener != null) { mInternalPageChangeListener.onPageSelected(item); } if (smoothScroll) { smoothScrollTo(destX, 0, velocity); } else { completeScroll(); scrollTo(destX, 0); } } }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mEnabled) return false; final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (DEBUG) if (action == MotionEvent.ACTION_DOWN) Log.v(TAG, "Received ACTION_DOWN"); if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP || (action != MotionEvent.ACTION_DOWN && mIsUnableToDrag)) { endDrag(); return false; } switch (action) { case MotionEvent.ACTION_MOVE: determineDrag(ev); break; case MotionEvent.ACTION_DOWN: int index = MotionEventCompat.getActionIndex(ev); mActivePointerId = MotionEventCompat.getPointerId(ev, index); if (mActivePointerId == INVALID_POINTER) break; mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index); mLastMotionY = MotionEventCompat.getY(ev, index); if (thisTouchAllowed(ev)) { mIsBeingDragged = false; mIsUnableToDrag = false; if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) { mQuickReturn = true; } } else { mIsUnableToDrag = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } if (!mIsBeingDragged) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); } return mIsBeingDragged || mQuickReturn; }
private void determineDrag(MotionEvent ev) { final int activePointerId = mActivePointerId; final int pointerIndex = getPointerIndex(ev, activePointerId); if (activePointerId == INVALID_POINTER || pointerIndex == INVALID_POINTER) return; final float x = MotionEventCompat.getX(ev, pointerIndex); final float dx = x - mLastMotionX; final float xDiff = Math.abs(dx); final float y = MotionEventCompat.getY(ev, pointerIndex); final float dy = y - mLastMotionY; final float yDiff = Math.abs(dy); if (mViewBehind.getbMode()) { if (yDiff > (isMenuOpen() ? mTouchSlop / 2 : mTouchSlop) && yDiff > xDiff && thisSlideAllowed(dy)) { startDrag(); mLastMotionX = x; mLastMotionY = y; setScrollingCacheEnabled(true); // TODO add back in touch slop check } else if (yDiff > mTouchSlop) { mIsUnableToDrag = true; } } else { if (xDiff > (isMenuOpen() ? mTouchSlop / 2 : mTouchSlop) && xDiff > yDiff && thisSlideAllowed(dx)) { startDrag(); mLastMotionX = x; mLastMotionY = y; setScrollingCacheEnabled(true); // TODO add back in touch slop check } else if (xDiff > mTouchSlop) { mIsUnableToDrag = true; } } }
/** * Sets the shadow width. * * @param pixels the new shadow width, in pixels */ public void setShadowWidth(int pixels) { mViewBehind.setShadowWidth(pixels); }
/** * Sets the secondary (right) shadow drawable. * * @param d the new shadow drawable */ public void setSecondaryShadowDrawable(Drawable d) { mViewBehind.setSecondaryShadowDrawable(d); }
/** * Sets the behind canvas transformer. * * @param t the new behind canvas transformer */ public void setBehindCanvasTransformer(CanvasTransformer t) { mViewBehind.setCanvasTransformer(t); }
/** * Set the secondary behind view (right menu) content to the given View. * * @param view The desired content to display. */ public void setSecondaryMenu(View view) { mViewBehind.setSecondaryContent(view); // mViewBehind.invalidate(); }
/** * Sets the selector drawable. * * @param res a resource ID for the selector drawable */ public void setSelectorDrawable(int res) { mViewBehind.setSelectorBitmap(BitmapFactory.decodeResource(getResources(), res)); }
/** * Enables or disables whether the selector is drawn * * @param b true to draw the selector, false to not draw the selector */ public void setSelectorEnabled(boolean b) { mViewBehind.setSelectorEnabled(true); }
/** * Gets the behind scroll scale. * * @return The scale of the parallax scroll */ public float getBehindScrollScale() { return mViewBehind.getScrollScale(); }
/** * Gets the behind offset. * * @return The margin on the right of the screen that the behind view scrolls to */ public int getBehindOffset() { return ((RelativeLayout.LayoutParams) mViewBehind.getLayoutParams()).rightMargin; }
/** * Returns the current side that the SlidingMenu is on. * * @return the current mode, either SlidingMenu.LEFT or SlidingMenu.RIGHT */ public int getMode() { return mViewBehind.getMode(); }
/** * Sets which side the SlidingMenu should appear on. * * @param mode must be either SlidingMenu.LEFT or SlidingMenu.RIGHT */ public void setMode(int mode) { if (mode != LEFT && mode != RIGHT && mode != LEFT_RIGHT) { throw new IllegalStateException("SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT"); } mViewBehind.setMode(mode); }
/** * Retrieves the current secondary menu (right). * * @return the current menu */ public View getSecondaryMenu() { return mViewBehind.getSecondaryContent(); }
/** * Enables or disables the SlidingMenu's fade in and out * * @param b true to enable fade, false to disable it */ public void setFadeEnabled(boolean b) { mViewBehind.setFadeEnabled(b); }
/** * Gets the touch mode margin threshold * * @return the touch mode margin threshold */ public int getTouchmodeMarginThreshold() { return mViewBehind.getMarginThreshold(); }
/** * Sets how much the SlidingMenu fades in and out. Fade must be enabled, see {@link * #setFadeEnabled(boolean) setFadeEnabled(boolean)} * * @param f the new fade degree, between 0.0f and 1.0f */ public void setFadeDegree(float f) { mViewBehind.setFadeDegree(f); }
/** * Set the touch mode margin threshold * * @param touchmodeMarginThreshold touch mode margin threshold */ public void setTouchmodeMarginThreshold(int touchmodeMarginThreshold) { mViewBehind.setMarginThreshold(touchmodeMarginThreshold); }
/** * Sets the selected view. The selector will be drawn here * * @param v the new selected view */ public void setSelectedView(View v) { mViewBehind.setSelectedView(v); }
/** * Sets the behind scroll scale. * * @param f The scale of the parallax scroll (i.e. 1.0f scrolls 1 pixel for every 1 pixel that the * above view scrolls and 0.0f scrolls 0 pixels) */ public void setBehindScrollScale(float f) { if (f < 0 && f > 1) throw new IllegalStateException("ScrollScale must be between 0 and 1"); mViewBehind.setScrollScale(f); }
/** * Sets the selector drawable. * * @param b the new selector bitmap */ public void setSelectorBitmap(Bitmap b) { mViewBehind.setSelectorBitmap(b); }
/** * Retrieves the main menu. * * @return the main menu */ public View getMenu() { return mViewBehind.getContent(); }