/** * Sets whether or not the SlidingMenu is in static mode (i.e. nothing is moving and everything is * showing) * * @param b true to set static mode, false to disable static mode. */ public void setStatic(boolean b) { if (b) { setSlidingEnabled(false); mViewAbove.setCustomViewBehind(null); mViewAbove.setCurrentItem(1); // mViewBehind.setCurrentItem(0); } else { mViewAbove.setCurrentItem(1); // mViewBehind.setCurrentItem(1); mViewAbove.setCustomViewBehind(mViewBehind); setSlidingEnabled(true); } }
/** * 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 setTouchModeAbove(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."); } mViewAbove.setTouchMode(i); }
@Override protected void dispatchDraw(Canvas canvas) { if (mTransformer != null) { canvas.save(); mTransformer.transformCanvas(canvas, mViewAbove.getPercentOpen()); super.dispatchDraw(canvas); canvas.restore(); } else super.dispatchDraw(canvas); }
/** * Gets the touch mode above. * * @return the touch mode above */ public int getTouchModeAbove() { return mViewAbove.getTouchMode(); }
/** * Sets the above offset. * * @param i the new above offset, in pixels */ public void setAboveOffset(int i) { mViewAbove.setAboveOffset(i); }
/** * Checks if is the behind view showing. * * @return Whether or not the behind view is showing */ public boolean isSecondaryMenuShowing() { return mViewAbove.getCurrentItem() == 2; }
/** * Instantiates a new SlidingMenu. * * @param context the associated Context * @param attrs the attrs * @param defStyle the def style */ public SlidingMenu(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); LayoutParams behindParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mViewBehind = new CustomViewBehind(context); addView(mViewBehind, behindParams); LayoutParams aboveParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mViewAbove = new CustomViewAbove(context); addView(mViewAbove, aboveParams); // register the CustomViewBehind with the CustomViewAbove mViewAbove.setCustomViewBehind(mViewBehind); mViewBehind.setCustomViewAbove(mViewAbove); mViewAbove.setOnPageChangeListener( new OnPageChangeListener() { public static final int POSITION_OPEN = 0; public static final int POSITION_CLOSE = 1; public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} public void onPageSelected(int position) { if (position == POSITION_OPEN && mOpenListener != null) { mOpenListener.onOpen(); } else if (position == POSITION_CLOSE && mCloseListener != null) { mCloseListener.onClose(); } } }); // now style everything! TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingMenu); // set the above and behind views if defined in xml int mode = ta.getInt(R.styleable.SlidingMenu_mode, LEFT); setMode(mode); int viewAbove = ta.getResourceId(R.styleable.SlidingMenu_viewAbove, -1); if (viewAbove != -1) { setContent(viewAbove); } else { setContent(new FrameLayout(context)); } int viewBehind = ta.getResourceId(R.styleable.SlidingMenu_viewBehind, -1); if (viewBehind != -1) { setMenu(viewBehind); } else { setMenu(new FrameLayout(context)); } int touchModeAbove = ta.getInt(R.styleable.SlidingMenu_touchModeAbove, TOUCHMODE_MARGIN); setTouchModeAbove(touchModeAbove); int touchModeBehind = ta.getInt(R.styleable.SlidingMenu_touchModeBehind, TOUCHMODE_MARGIN); setTouchModeBehind(touchModeBehind); int offsetBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindOffset, -1); int widthBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindWidth, -1); if (offsetBehind != -1 && widthBehind != -1) throw new IllegalStateException( "Cannot set both behindOffset and behindWidth for a SlidingMenu"); else if (offsetBehind != -1) setBehindOffset(offsetBehind); else if (widthBehind != -1) setBehindWidth(widthBehind); else setBehindOffset(0); float scrollOffsetBehind = ta.getFloat(R.styleable.SlidingMenu_behindScrollScale, 0.33f); setBehindScrollScale(scrollOffsetBehind); int shadowRes = ta.getResourceId(R.styleable.SlidingMenu_shadowDrawable, -1); if (shadowRes != -1) { setShadowDrawable(shadowRes); } int shadowWidth = (int) ta.getDimension(R.styleable.SlidingMenu_shadowWidth, 0); setShadowWidth(shadowWidth); boolean fadeEnabled = ta.getBoolean(R.styleable.SlidingMenu_fadeEnabled, true); setFadeEnabled(fadeEnabled); float fadeDeg = ta.getFloat(R.styleable.SlidingMenu_fadeDegree, 0.33f); setFadeDegree(fadeDeg); boolean selectorEnabled = ta.getBoolean(R.styleable.SlidingMenu_selectorEnabled, false); setSelectorEnabled(selectorEnabled); int selectorRes = ta.getResourceId(R.styleable.SlidingMenu_selectorDrawable, -1); if (selectorRes != -1) setSelectorDrawable(selectorRes); ta.recycle(); }
/* (non-Javadoc) * @see android.view.View#onSaveInstanceState() */ @Override protected Parcelable onSaveInstanceState() { Parcelable superState = super.onSaveInstanceState(); SavedState ss = new SavedState(superState, mViewAbove.getCurrentItem()); return ss; }
/** Clear the list of Views ignored by the Touch Down event when mode is Fullscreen */ public void clearIgnoredViews() { mViewAbove.clearIgnoredViews(); }
/** * Opens the menu and shows the menu view. * * @param animate true to animate the transition, false to ignore animation */ public void showMenu(boolean animate) { mViewAbove.setCurrentItem(0, animate); }
/** * Checks if is sliding enabled. * * @return true, if is sliding enabled */ public boolean isSlidingEnabled() { return mViewAbove.isSlidingEnabled(); }
/** * Sets the sliding enabled. * * @param b true to enable sliding, false to disable it. */ public void setSlidingEnabled(boolean b) { mViewAbove.setSlidingEnabled(b); }
/** * Retrieves the current content. * * @return the current content */ public View getContent() { return mViewAbove.getContent(); }
/** * Set the above view content to the given View. * * @param view The desired content to display. */ public void setContent(View view) { mViewAbove.setContent(view); showContent(); }
/** * Add a View ignored by the Touch Down event when mode is Fullscreen * * @param v a view to be ignored */ public void addIgnoredView(View v) { mViewAbove.addIgnoredView(v); }
/** * Remove a View ignored by the Touch Down event when mode is Fullscreen * * @param v a view not wanted to be ignored anymore */ public void removeIgnoredView(View v) { mViewAbove.removeIgnoredView(v); }
/** * Opens the menu and shows the secondary (right) menu view. Will default to the regular menu if * there is only one. * * @param animate true to animate the transition, false to ignore animation */ public void showSecondaryMenu(boolean animate) { mViewAbove.setCurrentItem(2, animate); }
/** * Sets the OnClosedListener. {@link OnClosedListener#onClosed() OnClosedListener.onClosed()} will * be called after the SlidingMenu is closed * * @param listener the new OnClosedListener */ public void setOnClosedListener(OnClosedListener listener) { mViewAbove.setOnClosedListener(listener); }
/** * Closes the menu and shows the above view. * * @param animate true to animate the transition, false to ignore animation */ public void showContent(boolean animate) { mViewAbove.setCurrentItem(1, animate); }
/* (non-Javadoc) * @see android.view.View#onRestoreInstanceState(android.os.Parcelable) */ @Override protected void onRestoreInstanceState(Parcelable state) { SavedState ss = (SavedState) state; super.onRestoreInstanceState(ss.getSuperState()); mViewAbove.setCurrentItem(ss.getItem()); }
/** * Checks if is the behind view showing. * * @return Whether or not the behind view is showing */ public boolean isMenuShowing() { return mViewAbove.getCurrentItem() == 0 || mViewAbove.getCurrentItem() == 2; }