net.simonvt.widget
Class MenuDrawer

java.lang.Object
  extended by android.view.View
      extended by android.view.ViewGroup
          extended by net.simonvt.widget.MenuDrawer
All Implemented Interfaces:
android.graphics.drawable.Drawable.Callback, android.view.accessibility.AccessibilityEventSource, android.view.KeyEvent.Callback, android.view.ViewManager, android.view.ViewParent
Direct Known Subclasses:
LeftDrawer, RightDrawer

public abstract class MenuDrawer
extends android.view.ViewGroup


Nested Class Summary
static interface MenuDrawer.OnDrawerStateChangeListener
          Callback interface for changing state of the drawer.
 
Nested classes/interfaces inherited from class android.view.ViewGroup
android.view.ViewGroup.LayoutParams, android.view.ViewGroup.MarginLayoutParams, android.view.ViewGroup.OnHierarchyChangeListener
 
Nested classes/interfaces inherited from class android.view.View
android.view.View.AccessibilityDelegate, android.view.View.BaseSavedState, android.view.View.DragShadowBuilder, android.view.View.MeasureSpec, android.view.View.OnAttachStateChangeListener, android.view.View.OnClickListener, android.view.View.OnCreateContextMenuListener, android.view.View.OnDragListener, android.view.View.OnFocusChangeListener, android.view.View.OnGenericMotionListener, android.view.View.OnHoverListener, android.view.View.OnKeyListener, android.view.View.OnLayoutChangeListener, android.view.View.OnLongClickListener, android.view.View.OnSystemUiVisibilityChangeListener, android.view.View.OnTouchListener
 
Field Summary
protected static int ANIMATION_DELAY
          The time between each frame when animating the drawer.
protected static android.view.animation.Interpolator ARROW_INTERPOLATOR
          Interpolator used for stretching/retracting the arrow indicator.
protected  int mActivePosition
          Position of the active view.
protected  android.graphics.Rect mActiveRect
          Used when reading the position of the active view.
protected  android.view.View mActiveView
          The currently active view.
protected  android.graphics.Bitmap mArrowBitmap
          Arrow bitmap used to indicate the active view.
protected static int MAX_MENU_OVERLAY_ALPHA
          The maximum alpha of the dark menu overlay used for dimming the menu.
protected  int mCloseEnough
          Distance in px from closed position from where the drawer is considered closed with regards to touch events.
protected  BuildLayerFrameLayout mContentView
          The parent of the content view.
protected  android.graphics.drawable.Drawable mDropShadowDrawable
          Drawable used as content drop shadow onto the menu.
protected  int mDropShadowWidth
          The width of the content drop shadow.
static int MENU_DRAG_CONTENT
          Drag mode for sliding only the content view.
static int MENU_DRAG_WINDOW
          Drag mode for sliding the entire window.
static int MENU_POSITION_LEFT
          Position the menu to the left of the content.
static int MENU_POSITION_RIGHT
          Position the menu to the right of the content.
protected  float mInitialMotionX
          The initial X position of a drag.
protected  boolean mIsDragging
          Indicates whether the drawer is currently being dragged.
protected  float mLastMotionX
          The last X position of a drag.
protected  float mLastMotionY
          The last Y position of a drag.
protected  int mMaxTouchBezelWidth
          The maximum touch area width of the drawer in px.
protected  int mMaxVelocity
          Maximum velocity allowed when animating the drawer open/closed.
protected  BuildLayerFrameLayout mMenuContainer
          The parent of the menu view.
protected  android.graphics.drawable.Drawable mMenuOverlay
          Drawable used as menu overlay.
protected  boolean mMenuVisible
          Indicates whether the menu is currently visible.
protected  int mMenuWidth
          The width of the menu.
protected  boolean mOffsetMenu
          Indicates whether the menu should be offset when dragging the drawer.
protected  int mOffsetPixels
          Current left position of the content.
protected  long mPeekDelay
          Default delay between each subsequent animation, after peekDrawer() has been called.
protected  Runnable mPeekRunnable
          Runnable used when the peek animation is running.
protected  Scroller mPeekScroller
          Scroller used for the peek drawer animation.
protected  int mTouchMode
          Touch mode for the Drawer.
protected  int mTouchSlop
          Slop before starting a drag.
protected  int mTouchWidth
          The touch area width of the drawer in px.
protected  android.view.VelocityTracker mVelocityTracker
          Velocity tracker used when animating the drawer open/closed after a drag.
static int STATE_CLOSED
          Indicates that the drawer is currently closed.
static int STATE_CLOSING
          Indicates that the drawer is currently closing.
static int STATE_DRAGGING
          Indicates that the drawer is currently being dragged by the user.
static int STATE_OPEN
          Indicates that the drawer is currently open.
static int STATE_OPENING
          Indicates that the drawer is currently opening.
static int TOUCH_MODE_BEZEL
          Allow opening drawer only by dragging on the edge of the screen.
static int TOUCH_MODE_FULLSCREEN
          Allow opening drawer by dragging anywhere on the screen.
static int TOUCH_MODE_NONE
          Disallow opening the drawer by dragging the screen.
 
Fields inherited from class android.view.ViewGroup
CLIP_TO_PADDING_MASK, FOCUS_AFTER_DESCENDANTS, FOCUS_BEFORE_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS, PERSISTENT_ALL_CACHES, PERSISTENT_ANIMATION_CACHE, PERSISTENT_NO_CACHE, PERSISTENT_SCROLLING_CACHE
 
Fields inherited from class android.view.View
ALPHA, DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIND_VIEWS_WITH_CONTENT_DESCRIPTION, FIND_VIEWS_WITH_TEXT, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, IMPORTANT_FOR_ACCESSIBILITY_AUTO, IMPORTANT_FOR_ACCESSIBILITY_NO, IMPORTANT_FOR_ACCESSIBILITY_YES, INVISIBLE, KEEP_SCREEN_ON, LAYER_TYPE_HARDWARE, LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, NO_ID, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCREEN_STATE_OFF, SCREEN_STATE_ON, SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT, SCROLLBAR_POSITION_RIGHT, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, STATUS_BAR_HIDDEN, STATUS_BAR_VISIBLE, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_VISIBLE, SYSTEM_UI_LAYOUT_FLAGS, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_RESOLVED_DEFAULT, TRANSLATION_X, TRANSLATION_Y, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y
 
Constructor Summary
MenuDrawer(android.content.Context context)
           
MenuDrawer(android.content.Context context, android.util.AttributeSet attrs)
           
MenuDrawer(android.content.Context context, android.util.AttributeSet attrs, int defStyle)
           
 
Method Summary
protected  void animateOffsetTo(int position, int velocity, boolean animate)
          Moves the drawer to the position passed.
 void closeMenu()
          Animates the menu closed.
 void closeMenu(boolean animate)
          Closes the menu.
protected  void dispatchDraw(android.graphics.Canvas canvas)
           
protected abstract  void drawArrow(android.graphics.Canvas canvas, int offsetPixels)
          Called when the arrow indicator should be drawn.
protected abstract  void drawDropShadow(android.graphics.Canvas canvas, int offsetPixels)
          Called when the content drop shadow should be drawn.
protected abstract  void drawMenuOverlay(android.graphics.Canvas canvas, int offsetPixels)
          Called when the menu overlay should be drawn.
protected  void endPeek()
          Stops ongoing peek drawer animation.
protected  boolean fitSystemWindows(android.graphics.Rect insets)
           
 int getDrawerState()
          Returns the state of the drawer.
 android.graphics.drawable.Drawable getDropShadow()
          Returns the drawable of the drop shadow.
 boolean getOffsetMenuEnabled()
          Indicates whether the menu is being offset when dragging the drawer.
 int getTouchMode()
          Returns the touch mode.
protected  boolean isCloseEnough()
           
protected abstract  boolean isContentTouch(android.view.MotionEvent ev)
          Returns true if the touch event occurs over the content.
 boolean isMenuVisible()
          Indicates whether the menu is currently visible.
protected abstract  boolean onDownAllowDrag(android.view.MotionEvent ev)
          Returns true if dragging the content should be allowed.
 boolean onInterceptTouchEvent(android.view.MotionEvent ev)
           
protected  void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
           
protected abstract  boolean onMoveAllowDrag(android.view.MotionEvent ev, float dx)
          Returns true if dragging the content should be allowed.
protected abstract  void onMoveEvent(float dx)
          Called when a move event has happened while dragging the content is in progress.
protected abstract  void onOffsetPixelsChanged(int offsetPixels)
          Called when the number of pixels the content should be offset by has changed.
 boolean onTouchEvent(android.view.MotionEvent ev)
           
protected abstract  void onUpEvent(android.view.MotionEvent ev)
          Called when MotionEvent.ACTION_UP of MotionEvent.ACTION_CANCEL is delivered to onTouchEvent(android.view.MotionEvent).
 void openMenu()
          Animates the menu open.
 void openMenu(boolean animate)
          Opens the menu.
 void peekDrawer()
          Animates the drawer slightly open until the user opens the drawer.
 void peekDrawer(long delay)
          Animates the drawer slightly open.
 void peekDrawer(long startDelay, long delay)
          Animates the drawer slightly open.
 void postOnAnimation(Runnable action)
           
 void restoreState(android.os.Parcelable in)
          Restores the state of the drawer.
 android.os.Parcelable saveState()
          Saves the state of the drawer.
 void setActiveView(android.view.View v, int position)
          Set the active view.
 void setDragMode(int dragMode)
          Sets the drawer drag mode.
protected  void setDrawerState(int state)
          Sets the drawer state.
 void setDropShadow(android.graphics.drawable.Drawable drawable)
          Sets the drawable of the drop shadow.
 void setDropShadow(int resId)
          Sets the drawable of the drop shadow.
abstract  void setDropShadowColor(int color)
          Sets the color of the drop shadow.
 void setDropShadowEnabled(boolean enabled)
          Defines whether the drop shadow is enabled.
 void setDropShadowWidth(int width)
          Sets the width of the drop shadow.
 void setHardwareLayerEnabled(boolean enabled)
          Enables or disables the user of View.LAYER_TYPE_HARDWARE when animations views.
 void setMenuWidth(int width)
          Set the width of the menu drawer when open.
 void setOffsetMenuEnabled(boolean offsetMenu)
          Enables or disables offsetting the menu when dragging the drawer.
protected  void setOffsetPixels(int offsetPixels)
          Sets the number of pixels the content should be offset.
 void setOnDrawerStateChangeListener(MenuDrawer.OnDrawerStateChangeListener listener)
          Register a callback to be invoked when the drawer state changes.
 void setTouchMode(int mode)
          Sets the drawer touch mode.
protected  void startLayerTranslation()
          If possible, set the layer type to View.LAYER_TYPE_HARDWARE.
protected  void startPeek()
          Starts peek drawer animation.
protected  void stopAnimation()
          Stops ongoing animation of the drawer.
 void toggleMenu()
          Toggles the menu open and close with animation.
 void toggleMenu(boolean animate)
          Toggles the menu open and close.
 
Methods inherited from class android.view.ViewGroup
addChildrenForAccessibility, addFocusables, addStatesFromChildren, addTouchables, addView, addView, addView, addView, addView, addViewInLayout, addViewInLayout, attachLayoutAnimationParameters, attachViewToParent, bringChildToFront, canAnimate, checkLayoutParams, childDrawableStateChanged, cleanupLayoutState, clearChildFocus, clearDisappearingChildren, clearFocus, debug, detachAllViewsFromParent, detachViewFromParent, detachViewFromParent, detachViewsFromParent, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchFreezeSelfOnly, dispatchGenericFocusedEvent, dispatchGenericPointerEvent, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchSystemUiVisibilityChanged, dispatchThawSelfOnly, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, drawableStateChanged, drawChild, endViewTransition, findFocus, findViewsWithText, focusableViewAvailable, focusSearch, gatherTransparentRegion, generateDefaultLayoutParams, generateLayoutParams, generateLayoutParams, getChildAt, getChildCount, getChildDrawingOrder, getChildMeasureSpec, getChildStaticTransformation, getChildVisibleRect, getDescendantFocusability, getFocusedChild, getLayoutAnimation, getLayoutAnimationListener, getLayoutTransition, getPersistentDrawingCache, hasFocus, hasFocusable, indexOfChild, invalidateChild, invalidateChildInParent, isAlwaysDrawnWithCacheEnabled, isAnimationCacheEnabled, isChildrenDrawingOrderEnabled, isChildrenDrawnWithCacheEnabled, isMotionEventSplittingEnabled, jumpDrawablesToCurrentState, layout, measureChild, measureChildren, measureChildWithMargins, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onAnimationEnd, onAnimationStart, onCreateDrawableState, onInterceptHoverEvent, onLayout, onRequestFocusInDescendants, onRequestSendAccessibilityEvent, recomputeViewAttributes, removeAllViews, removeAllViewsInLayout, removeDetachedView, removeView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestChildFocus, requestChildRectangleOnScreen, requestDisallowInterceptTouchEvent, requestFocus, requestSendAccessibilityEvent, requestTransparentRegion, scheduleLayoutAnimation, setAddStatesFromChildren, setAlwaysDrawnWithCacheEnabled, setAnimationCacheEnabled, setChildrenDrawingCacheEnabled, setChildrenDrawingOrderEnabled, setChildrenDrawnWithCacheEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutAnimation, setLayoutAnimationListener, setLayoutTransition, setMotionEventSplittingEnabled, setOnHierarchyChangeListener, setPadding, setPersistentDrawingCache, setStaticTransformationsEnabled, shouldDelayChildPressedState, showContextMenuForChild, startActionModeForChild, startLayoutAnimation, startViewTransition, updateViewLayout
 
Methods inherited from class android.view.View
addFocusables, addOnAttachStateChangeListener, addOnLayoutChangeListener, animate, announceForAccessibility, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, buildLayer, callOnClick, cancelLongPress, canScrollHorizontally, canScrollVertically, checkInputConnectionProxy, clearAnimation, combineMeasuredStates, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createAccessibilityNodeInfo, createContextMenu, destroyDrawingCache, dispatchGenericMotionEvent, dispatchPopulateAccessibilityEvent, draw, findViewById, findViewWithTag, focusSearch, forceLayout, getAccessibilityNodeProvider, getAlpha, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getCameraDistance, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getId, getImportantForAccessibility, getKeepScreenOn, getKeyDispatcherState, getLayerType, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOverScrollMode, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getResources, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getSystemUiVisibility, getTag, getTag, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getTranslationX, getTranslationY, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, hasOnClickListeners, hasOverlappingRendering, hasTransientState, hasWindowFocus, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, invalidateDrawable, isActivated, isClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isInEditMode, isInTouchMode, isLayoutRequested, isLongClickable, isOpaque, isPaddingOffsetRequired, isPressed, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isScrollContainer, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onAttachedToWindow, onCheckIsTextEditor, onConfigurationChanged, onCreateContextMenu, onCreateInputConnection, onDetachedFromWindow, onDisplayHint, onDragEvent, onDraw, onDrawScrollBars, onFilterTouchEventForSecurity, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onGenericMotionEvent, onHoverChanged, onHoverEvent, onInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfo, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onOverScrolled, onPopulateAccessibilityEvent, onRestoreInstanceState, onSaveInstanceState, onScreenStateChanged, onScrollChanged, onSetAlpha, onSizeChanged, onStartTemporaryDetach, onTrackballEvent, onVisibilityChanged, onWindowFocusChanged, onWindowSystemUiVisibilityChanged, onWindowVisibilityChanged, overScrollBy, performAccessibilityAction, performClick, performHapticFeedback, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimationDelayed, refreshDrawableState, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestFitSystemWindows, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, resolveSizeAndState, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAccessibilityDelegate, setActivated, setAlpha, setAnimation, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBottom, setCameraDistance, setClickable, setContentDescription, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusableInTouchMode, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHovered, setId, setImportantForAccessibility, setKeepScreenOn, setLayerType, setLayoutParams, setLeft, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOverScrollMode, setPivotX, setPivotY, setPressed, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setSystemUiVisibility, setTag, setTag, setTop, setTouchDelegate, setTranslationX, setTranslationY, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, showContextMenu, startActionMode, startAnimation, startDrag, unscheduleDrawable, unscheduleDrawable, verifyDrawable, willNotCacheDrawing, willNotDraw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface android.view.ViewParent
createContextMenu, getParent, getParentForAccessibility, isLayoutRequested, requestFitSystemWindows, requestLayout
 

Field Detail

ANIMATION_DELAY

protected static final int ANIMATION_DELAY
The time between each frame when animating the drawer.

See Also:
Constant Field Values

ARROW_INTERPOLATOR

protected static final android.view.animation.Interpolator ARROW_INTERPOLATOR
Interpolator used for stretching/retracting the arrow indicator.


MAX_MENU_OVERLAY_ALPHA

protected static final int MAX_MENU_OVERLAY_ALPHA
The maximum alpha of the dark menu overlay used for dimming the menu.

See Also:
Constant Field Values

MENU_DRAG_CONTENT

public static final int MENU_DRAG_CONTENT
Drag mode for sliding only the content view.

See Also:
Constant Field Values

MENU_DRAG_WINDOW

public static final int MENU_DRAG_WINDOW
Drag mode for sliding the entire window.

See Also:
Constant Field Values

MENU_POSITION_LEFT

public static final int MENU_POSITION_LEFT
Position the menu to the left of the content.

See Also:
Constant Field Values

MENU_POSITION_RIGHT

public static final int MENU_POSITION_RIGHT
Position the menu to the right of the content.

See Also:
Constant Field Values

TOUCH_MODE_NONE

public static final int TOUCH_MODE_NONE
Disallow opening the drawer by dragging the screen.

See Also:
Constant Field Values

TOUCH_MODE_BEZEL

public static final int TOUCH_MODE_BEZEL
Allow opening drawer only by dragging on the edge of the screen.

See Also:
Constant Field Values

TOUCH_MODE_FULLSCREEN

public static final int TOUCH_MODE_FULLSCREEN
Allow opening drawer by dragging anywhere on the screen.

See Also:
Constant Field Values

STATE_CLOSED

public static final int STATE_CLOSED
Indicates that the drawer is currently closed.

See Also:
Constant Field Values

STATE_CLOSING

public static final int STATE_CLOSING
Indicates that the drawer is currently closing.

See Also:
Constant Field Values

STATE_DRAGGING

public static final int STATE_DRAGGING
Indicates that the drawer is currently being dragged by the user.

See Also:
Constant Field Values

STATE_OPENING

public static final int STATE_OPENING
Indicates that the drawer is currently opening.

See Also:
Constant Field Values

STATE_OPEN

public static final int STATE_OPEN
Indicates that the drawer is currently open.

See Also:
Constant Field Values

mMenuOverlay

protected android.graphics.drawable.Drawable mMenuOverlay
Drawable used as menu overlay.


mDropShadowDrawable

protected android.graphics.drawable.Drawable mDropShadowDrawable
Drawable used as content drop shadow onto the menu.


mDropShadowWidth

protected int mDropShadowWidth
The width of the content drop shadow.


mArrowBitmap

protected android.graphics.Bitmap mArrowBitmap
Arrow bitmap used to indicate the active view.


mActiveView

protected android.view.View mActiveView
The currently active view.


mActivePosition

protected int mActivePosition
Position of the active view. This is compared to View#getTag(R.id.mdActiveViewPosition) when drawing the arrow.


mActiveRect

protected final android.graphics.Rect mActiveRect
Used when reading the position of the active view.


mMenuContainer

protected BuildLayerFrameLayout mMenuContainer
The parent of the menu view.


mContentView

protected BuildLayerFrameLayout mContentView
The parent of the content view.


mMenuWidth

protected int mMenuWidth
The width of the menu.


mOffsetPixels

protected int mOffsetPixels
Current left position of the content.


mMenuVisible

protected boolean mMenuVisible
Indicates whether the menu is currently visible.


mMaxTouchBezelWidth

protected int mMaxTouchBezelWidth
The maximum touch area width of the drawer in px.


mTouchWidth

protected int mTouchWidth
The touch area width of the drawer in px.


mIsDragging

protected boolean mIsDragging
Indicates whether the drawer is currently being dragged.


mTouchSlop

protected final int mTouchSlop
Slop before starting a drag.


mInitialMotionX

protected float mInitialMotionX
The initial X position of a drag.


mLastMotionX

protected float mLastMotionX
The last X position of a drag.


mLastMotionY

protected float mLastMotionY
The last Y position of a drag.


mPeekRunnable

protected final Runnable mPeekRunnable
Runnable used when the peek animation is running.


mPeekDelay

protected long mPeekDelay
Default delay between each subsequent animation, after peekDrawer() has been called.


mPeekScroller

protected Scroller mPeekScroller
Scroller used for the peek drawer animation.


mVelocityTracker

protected android.view.VelocityTracker mVelocityTracker
Velocity tracker used when animating the drawer open/closed after a drag.


mMaxVelocity

protected int mMaxVelocity
Maximum velocity allowed when animating the drawer open/closed.


mOffsetMenu

protected boolean mOffsetMenu
Indicates whether the menu should be offset when dragging the drawer.


mTouchMode

protected int mTouchMode
Touch mode for the Drawer. Possible values are TOUCH_MODE_NONE, TOUCH_MODE_BEZEL or TOUCH_MODE_FULLSCREEN Default: TOUCH_MODE_BEZEL


mCloseEnough

protected int mCloseEnough
Distance in px from closed position from where the drawer is considered closed with regards to touch events.

Constructor Detail

MenuDrawer

public MenuDrawer(android.content.Context context)

MenuDrawer

public MenuDrawer(android.content.Context context,
                  android.util.AttributeSet attrs)

MenuDrawer

public MenuDrawer(android.content.Context context,
                  android.util.AttributeSet attrs,
                  int defStyle)
Method Detail

toggleMenu

public void toggleMenu()
Toggles the menu open and close with animation.


toggleMenu

public void toggleMenu(boolean animate)
Toggles the menu open and close.

Parameters:
animate - Whether open/close should be animated.

openMenu

public void openMenu()
Animates the menu open.


openMenu

public void openMenu(boolean animate)
Opens the menu.

Parameters:
animate - Whether open/close should be animated.

closeMenu

public void closeMenu()
Animates the menu closed.


closeMenu

public void closeMenu(boolean animate)
Closes the menu.

Parameters:
animate - Whether open/close should be animated.

isMenuVisible

public boolean isMenuVisible()
Indicates whether the menu is currently visible.

Returns:
True if the menu is open, false otherwise.

setMenuWidth

public void setMenuWidth(int width)
Set the width of the menu drawer when open.

Parameters:
width -

setActiveView

public void setActiveView(android.view.View v,
                          int position)
Set the active view. If the mdArrowDrawable attribute is set, this View will have an arrow drawn next to it.

Parameters:
v - The active view.
position - Optional position, usually used with ListView. v.setTag(R.id.mdActiveViewPosition, position) must be called first.

setOffsetMenuEnabled

public void setOffsetMenuEnabled(boolean offsetMenu)
Enables or disables offsetting the menu when dragging the drawer.

Parameters:
offsetMenu - True to offset the menu, false otherwise.

getOffsetMenuEnabled

public boolean getOffsetMenuEnabled()
Indicates whether the menu is being offset when dragging the drawer.

Returns:
True if the menu is being offset, false otherwise.

getDrawerState

public int getDrawerState()
Returns the state of the drawer. Can be one of STATE_CLOSED, STATE_CLOSING, STATE_DRAGGING, STATE_OPENING or STATE_OPEN.

Returns:
The drawers state.

setOnDrawerStateChangeListener

public void setOnDrawerStateChangeListener(MenuDrawer.OnDrawerStateChangeListener listener)
Register a callback to be invoked when the drawer state changes.

Parameters:
listener - The callback that will run.

setDropShadowEnabled

public void setDropShadowEnabled(boolean enabled)
Defines whether the drop shadow is enabled.

Parameters:
enabled - Whether the drop shadow is enabled.

setDropShadowColor

public abstract void setDropShadowColor(int color)
Sets the color of the drop shadow.

Parameters:
color - The color of the drop shadow.

setDropShadow

public void setDropShadow(android.graphics.drawable.Drawable drawable)
Sets the drawable of the drop shadow.

Parameters:
drawable - The drawable of the drop shadow.

setDropShadow

public void setDropShadow(int resId)
Sets the drawable of the drop shadow.

Parameters:
resId - The resource identifier of the the drawable.

getDropShadow

public android.graphics.drawable.Drawable getDropShadow()
Returns the drawable of the drop shadow.


setDropShadowWidth

public void setDropShadowWidth(int width)
Sets the width of the drop shadow.

Parameters:
width - The width of the drop shadow in px.

peekDrawer

public void peekDrawer()
Animates the drawer slightly open until the user opens the drawer.


peekDrawer

public void peekDrawer(long delay)
Animates the drawer slightly open. If delay is larger than 0, this happens until the user opens the drawer.

Parameters:
delay - The delay (in milliseconds) between each run of the animation. If 0, this animation is only run once.

peekDrawer

public void peekDrawer(long startDelay,
                       long delay)
Animates the drawer slightly open. If delay is larger than 0, this happens until the user opens the drawer.

Parameters:
startDelay - The delay (in milliseconds) until the animation is first run.
delay - The delay (in milliseconds) between each run of the animation. If 0, this animation is only run once.

setHardwareLayerEnabled

public void setHardwareLayerEnabled(boolean enabled)
Enables or disables the user of View.LAYER_TYPE_HARDWARE when animations views.

Parameters:
enabled - Whether hardware layers are enabled.

setDrawerState

protected void setDrawerState(int state)
Sets the drawer state.

Parameters:
state - The drawer state. Must be one of STATE_CLOSED, STATE_CLOSING, STATE_DRAGGING, STATE_OPENING or STATE_OPEN.

setDragMode

public void setDragMode(int dragMode)
Sets the drawer drag mode. Can be either MENU_DRAG_CONTENT or MENU_DRAG_WINDOW.

Parameters:
dragMode - The drag mode.

getTouchMode

public int getTouchMode()
Returns the touch mode.


setTouchMode

public void setTouchMode(int mode)
Sets the drawer touch mode. Possible values are TOUCH_MODE_NONE, TOUCH_MODE_BEZEL or TOUCH_MODE_FULLSCREEN.

Parameters:
dragMode - The drag mode.

dispatchDraw

protected void dispatchDraw(android.graphics.Canvas canvas)
Overrides:
dispatchDraw in class android.view.ViewGroup

drawDropShadow

protected abstract void drawDropShadow(android.graphics.Canvas canvas,
                                       int offsetPixels)
Called when the content drop shadow should be drawn.

Parameters:
canvas - The canvas on which to draw.
offsetPixels - Value in pixels indicating the offset.

drawMenuOverlay

protected abstract void drawMenuOverlay(android.graphics.Canvas canvas,
                                        int offsetPixels)
Called when the menu overlay should be drawn.

Parameters:
canvas - The canvas on which to draw.
offsetPixels - Value in pixels indicating the offset.

drawArrow

protected abstract void drawArrow(android.graphics.Canvas canvas,
                                  int offsetPixels)
Called when the arrow indicator should be drawn.

Parameters:
canvas - The canvas on which to draw.
offsetPixels - Value in pixels indicating the offset.

setOffsetPixels

protected void setOffsetPixels(int offsetPixels)
Sets the number of pixels the content should be offset.

Parameters:
offsetPixels - The number of pixels to offset the content by.

onOffsetPixelsChanged

protected abstract void onOffsetPixelsChanged(int offsetPixels)
Called when the number of pixels the content should be offset by has changed.

Parameters:
offsetPixels - The number of pixels to offset the content by.

startLayerTranslation

protected void startLayerTranslation()
If possible, set the layer type to View.LAYER_TYPE_HARDWARE.


onMeasure

protected void onMeasure(int widthMeasureSpec,
                         int heightMeasureSpec)
Overrides:
onMeasure in class android.view.View

fitSystemWindows

protected boolean fitSystemWindows(android.graphics.Rect insets)
Overrides:
fitSystemWindows in class android.view.ViewGroup

stopAnimation

protected void stopAnimation()
Stops ongoing animation of the drawer.


animateOffsetTo

protected void animateOffsetTo(int position,
                               int velocity,
                               boolean animate)
Moves the drawer to the position passed.

Parameters:
position - The position the content is moved to.
velocity - Optional velocity if called by releasing a drag event.
animate - Whether the move is animated.

startPeek

protected void startPeek()
Starts peek drawer animation.


endPeek

protected void endPeek()
Stops ongoing peek drawer animation.


postOnAnimation

public void postOnAnimation(Runnable action)
Overrides:
postOnAnimation in class android.view.View

isCloseEnough

protected boolean isCloseEnough()

isContentTouch

protected abstract boolean isContentTouch(android.view.MotionEvent ev)
Returns true if the touch event occurs over the content.

Parameters:
ev - The motion event.
Returns:
True if the touch event occured over the content, false otherwise.

onDownAllowDrag

protected abstract boolean onDownAllowDrag(android.view.MotionEvent ev)
Returns true if dragging the content should be allowed.

Parameters:
ev - The motion event.
Returns:
True if dragging the content should be allowed, false otherwise.

onMoveAllowDrag

protected abstract boolean onMoveAllowDrag(android.view.MotionEvent ev,
                                           float dx)
Returns true if dragging the content should be allowed.

Parameters:
ev - The motion event.
Returns:
True if dragging the content should be allowed, false otherwise.

onMoveEvent

protected abstract void onMoveEvent(float dx)
Called when a move event has happened while dragging the content is in progress.

Parameters:
dx - The X difference between the last motion event and the current motion event.

onUpEvent

protected abstract void onUpEvent(android.view.MotionEvent ev)
Called when MotionEvent.ACTION_UP of MotionEvent.ACTION_CANCEL is delivered to onTouchEvent(android.view.MotionEvent).

Parameters:
ev - The motion event.

onInterceptTouchEvent

public boolean onInterceptTouchEvent(android.view.MotionEvent ev)
Overrides:
onInterceptTouchEvent in class android.view.ViewGroup

onTouchEvent

public boolean onTouchEvent(android.view.MotionEvent ev)
Overrides:
onTouchEvent in class android.view.View

saveState

public android.os.Parcelable saveState()
Saves the state of the drawer.

Returns:
Returns a Parcelable containing the drawer state.

restoreState

public void restoreState(android.os.Parcelable in)
Restores the state of the drawer.

Parameters:
in - A parcelable containing the drawer state.


Copyright © 2012. All Rights Reserved.