Update SlidingMenu

This commit is contained in:
Jean-Baptiste Kempf 2013-02-28 11:09:36 +01:00
parent 144276f9a0
commit 8ae54d40b2
24 changed files with 1839 additions and 819 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -6,15 +6,6 @@
<uses-sdk
android:minSdkVersion="5"
android:targetSdkVersion="16" />
<application>
<uses-library android:name="com.google.android.maps" />
<activity android:name=".SlidingMenuActivity" />
<activity android:name=".SlidingFragmentActivity" />
<activity android:name=".SlidingListActivity" />
<activity android:name=".SlidingPreferenceActivity" />
</application>
android:targetSdkVersion="17" />
</manifest>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="ResourceAsColor" severity="ignore" />
</lint>

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>slidingmenu</artifactId>
<name>SlidingMenu</name>
<packaging>apklib</packaging>
<parent>
<groupId>com.slidingmenu</groupId>
<artifactId>parent</artifactId>
<version>1.2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
</dependency>
<dependency>
<groupId>com.google.android.maps</groupId>
<artifactId>maps</artifactId>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<type>apklib</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<nativeLibrariesDirectory>ignored</nativeLibrariesDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,20 +0,0 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:endColor="#99000000"
android:centerColor="#33000000"
android:startColor="#00000000" />
</shape>

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="30dp"
android:layout_height="match_parent"
android:src="@drawable/defaultshadow" />

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<com.slidingmenu.lib.SlidingMenu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sliding="http://schemas.android.com/apk/res-auto"
android:id="@+id/slidingmenulayout"
sliding:viewAbove="@layout/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/slidingmenurowicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp" />
<TextView
android:id="@+id/slidingmenurowtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

View File

@ -17,6 +17,10 @@
<resources>
<declare-styleable name="SlidingMenu">
<attr name="mode">
<enum name="left" value="0" />
<enum name="right" value="1" />
</attr>
<attr name="viewAbove" format="reference" />
<attr name="viewBehind" format="reference" />
<attr name="behindOffset" format="dimension" />
@ -32,8 +36,8 @@
</attr>
<attr name="shadowDrawable" format="reference" />
<attr name="shadowWidth" format="dimension" />
<attr name="behindFadeEnabled" format="boolean" />
<attr name="behindFadeDegree" format="float" />
<attr name="fadeEnabled" format="boolean" />
<attr name="fadeDegree" format="float" />
<attr name="selectorEnabled" format="boolean" />
<attr name="selectorDrawable" format="reference" />
</declare-styleable>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="holo_blue_bright">#ff00ddff</color>
</resources>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="menu_item_padding">10dp</dimen>
<dimen name="menu_header_padding_top">8dp</dimen>
<dimen name="menu_header_line">3dp</dimen>
<dimen name="menu_icon_side">40dp</dimen>
</resources>

View File

@ -5,7 +5,7 @@ import android.view.animation.Interpolator;
import com.slidingmenu.lib.SlidingMenu.CanvasTransformer;
public class CanvasTranformerBuilder {
public class CanvasTransformerBuilder {
private CanvasTransformer mTrans;

View File

@ -1,12 +1,11 @@
package com.slidingmenu.lib;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.view.KeyEventCompat;
import android.support.v4.view.MotionEventCompat;
@ -16,7 +15,6 @@ import android.support.v4.view.ViewConfigurationCompat;
import android.util.AttributeSet;
import android.util.FloatMath;
import android.util.Log;
import android.util.TypedValue;
import android.view.FocusFinder;
import android.view.KeyEvent;
import android.view.MotionEvent;
@ -26,15 +24,12 @@ import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Scroller;
//import com.slidingmenu.lib.SlidingMenu.OnCloseListener;
import com.slidingmenu.lib.SlidingMenu.OnClosedListener;
//import com.slidingmenu.lib.SlidingMenu.OnOpenListener;
import com.slidingmenu.lib.SlidingMenu.OnOpenedListener;
//import com.slidingmenu.lib.SlidingMenu.OnCloseListener;
//import com.slidingmenu.lib.SlidingMenu.OnOpenListener;
public class CustomViewAbove extends ViewGroup {
@ -53,21 +48,17 @@ public class CustomViewAbove extends ViewGroup {
}
};
private Window mMenu;
private Content mContent;
private View mContent;
private int mCurItem;
private Scroller mScroller;
private int mShadowWidth;
private Drawable mShadowDrawable;
private boolean mScrollingCacheEnabled;
private boolean mScrolling;
private boolean mIsBeingDragged;
// private boolean mIsUnableToDrag;
private boolean mIsUnableToDrag;
private int mTouchSlop;
private float mInitialMotionX;
/**
@ -94,9 +85,8 @@ public class CustomViewAbove extends ViewGroup {
protected int mMaximumVelocity;
private int mFlingDistance;
private boolean mLastTouchAllowed = false;
private final int mSlidingMenuThreshold = 20;
private CustomViewBehind mCustomViewBehind;
private CustomViewBehind mViewBehind;
// private int mMode;
private boolean mEnabled = true;
private OnPageChangeListener mOnPageChangeListener;
@ -107,6 +97,8 @@ public class CustomViewAbove extends ViewGroup {
private OnClosedListener mClosedListener;
private OnOpenedListener mOpenedListener;
private List<View> mIgnoredViews = new ArrayList<View>();
// private int mScrollState = SCROLL_STATE_IDLE;
/**
@ -146,70 +138,26 @@ public class CustomViewAbove extends ViewGroup {
// This space for rent
}
public void onPageSelected(int position) {
// This space for rent
}
public void onPageScrollStateChanged(int state) {
// This space for rent
}
}
private class Window extends FrameLayout {
public Window(Context context) {
super(context);
}
public boolean onTouchEvent(MotionEvent event) {
return false;
}
public boolean onInterceptTouchEvent(MotionEvent event) {
return false;
}
}
public class Content extends FrameLayout {
public Content(Context context) {
super(context);
}
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}
public boolean onInterceptTouchEvent(MotionEvent event) {
if (event.getX() < getPaddingLeft()) {
Log.v(TAG, "ignoring touch");
return false;
}
return super.onInterceptTouchEvent(event);
}
}
public CustomViewAbove(Context context) {
this(context, null);
}
public CustomViewAbove(Context context, AttributeSet attrs) {
this(context, attrs, true);
}
public CustomViewAbove(Context context, AttributeSet attrs, boolean isAbove) {
super(context, attrs);
initCustomViewAbove(isAbove);
initCustomViewAbove();
}
void initCustomViewAbove() {
initCustomViewAbove(false);
}
void initCustomViewAbove(boolean isAbove) {
setWillNotDraw(false);
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
setFocusable(true);
@ -220,36 +168,23 @@ public class CustomViewAbove extends ViewGroup {
mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
setInternalPageChangeListener(new SimpleOnPageChangeListener() {
public void onPageSelected(int position) {
if (mCustomViewBehind != null) {
if (mViewBehind != null) {
switch (position) {
case 0:
mCustomViewBehind.setChildrenEnabled(true);
case 2:
mViewBehind.setChildrenEnabled(true);
break;
case 1:
mCustomViewBehind.setChildrenEnabled(false);
mViewBehind.setChildrenEnabled(false);
break;
}
}
}
});
final float density = context.getResources().getDisplayMetrics().density;
mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
mMenu = new Window(getContext());
super.addView(mMenu);
mContent = new Content(getContext());
super.addView(mContent);
if (isAbove) {
View v = new LinearLayout(getContext());
v.setBackgroundResource(android.R.color.transparent);
setMenu(v);
}
}
/**
@ -282,15 +217,13 @@ public class CustomViewAbove extends ViewGroup {
}
void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity) {
if (!always && mCurItem == item && mMenu != null && mContent != null) {
if (!always && mCurItem == item) {
setScrollingCacheEnabled(false);
return;
}
if (item < 0) {
item = 0;
} else if (item >= 2) {
item = 1;
}
item = mViewBehind.getMenuPage(item);
final boolean dispatchSelected = mCurItem != item;
mCurItem = item;
final int destX = getDestScrollX(mCurItem);
@ -346,63 +279,18 @@ public class CustomViewAbove extends ViewGroup {
return oldListener;
}
/**
* Set the margin between pages.
*
* @param shadowWidth Distance between adjacent pages in pixels
* @see #getShadowWidth()
* @see #setShadowDrawable(Drawable)
* @see #setShadowDrawable(int)
*/
public void setShadowWidth(int shadowWidth) {
mShadowWidth = shadowWidth;
invalidate();
public void addIgnoredView(View v) {
if (!mIgnoredViews.contains(v)) {
mIgnoredViews.add(v);
}
}
/**
* Return the margin between pages.
*
* @return The size of the margin in pixels
*/
public int getShadowWidth() {
return mShadowWidth;
public void removeIgnoredView(View v) {
mIgnoredViews.remove(v);
}
/**
* Set a drawable that will be used to fill the margin between pages.
*
* @param d Drawable to display between pages
*/
public void setShadowDrawable(Drawable d) {
mShadowDrawable = d;
refreshDrawableState();
setWillNotDraw(false);
invalidate();
}
/**
* Set a drawable that will be used to fill the margin between pages.
*
* @param resId Resource ID of a drawable to display between pages
*/
public void setShadowDrawable(int resId) {
setShadowDrawable(getContext().getResources().getDrawable(resId));
}
@Override
protected boolean verifyDrawable(Drawable who) {
return super.verifyDrawable(who) || who == mShadowDrawable;
}
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
final Drawable d = mShadowDrawable;
if (d != null && d.isStateful()) {
d.setState(getDrawableState());
}
public void clearIgnoredViews() {
mIgnoredViews.clear();
}
// We want the duration of the page snap animation to be influenced by the distance that
@ -415,59 +303,58 @@ public class CustomViewAbove extends ViewGroup {
return (float) FloatMath.sin(f);
}
public int getDestScrollX() {
if (isMenuOpen()) {
return getBehindWidth();
} else {
return 0;
}
}
public int getDestScrollX(int page) {
switch (page) {
case 0:
return mContent.getPaddingLeft();
case 2:
return mViewBehind.getMenuLeft(mContent, page);
case 1:
return mContent.getLeft();
}
return 0;
}
private int getLeftBound() {
return mViewBehind.getAbsLeftBound(mContent);
}
private int getRightBound() {
return mViewBehind.getAbsRightBound(mContent);
}
public int getContentLeft() {
return mContent.getLeft() + mContent.getPaddingLeft();
}
public int getChildLeft(int i) {
if (i <= 0) return 0;
return getChildWidth(i-1) + getChildLeft(i-1);
}
public int getChildRight(int i) {
return getChildLeft(i) + getChildWidth(i);
}
public boolean isMenuOpen() {
return getCurrentItem() == 0;
return mCurItem == 0 || mCurItem == 2;
}
public int getCustomWidth() {
int i = isMenuOpen()? 0 : 1;
return getChildWidth(i);
}
public int getChildWidth(int i) {
if (i <= 0) {
return getBehindWidth();
} else {
return getChildAt(i).getWidth();
private boolean isInIgnoredView(MotionEvent ev) {
Rect rect = new Rect();
for (View v : mIgnoredViews) {
v.getHitRect(rect);
if (rect.contains((int)ev.getX(), (int)ev.getY())) return true;
}
return false;
}
public int getBehindWidth() {
if (mCustomViewBehind == null) {
if (mViewBehind == null) {
return 0;
} else {
return mCustomViewBehind.getWidth();
return mViewBehind.getBehindWidth();
}
}
public int getChildWidth(int i) {
switch (i) {
case 0:
return getBehindWidth();
case 1:
return mContent.getWidth();
default:
return 0;
}
}
@ -521,7 +408,7 @@ public class CustomViewAbove extends ViewGroup {
setScrollingCacheEnabled(true);
mScrolling = true;
final int width = getCustomWidth();
final int width = getBehindWidth();
final int halfWidth = width / 2;
final float distanceRatio = Math.min(1f, 1.0f * Math.abs(dx) / width);
final float distance = halfWidth + halfWidth *
@ -532,7 +419,7 @@ public class CustomViewAbove extends ViewGroup {
if (velocity > 0) {
duration = 4 * Math.round(1000 * Math.abs(distance / velocity));
} else {
final float pageDelta = (float) Math.abs(dx) / (width + mShadowWidth);
final float pageDelta = (float) Math.abs(dx) / width;
duration = (int) ((pageDelta + 1) * 100);
duration = MAX_SETTLE_DURATION;
}
@ -542,22 +429,19 @@ public class CustomViewAbove extends ViewGroup {
invalidate();
}
protected void setMenu(View v) {
if (mMenu.getChildCount() > 0) {
mMenu.removeAllViews();
}
mMenu.addView(v);
public void setContent(View v) {
if (mContent != null)
this.removeView(mContent);
mContent = v;
addView(mContent);
}
public void setContent(View v) {
if (mContent.getChildCount() > 0) {
mContent.removeAllViews();
}
mContent.addView(v);
public View getContent() {
return mContent;
}
public void setCustomViewBehind(CustomViewBehind cvb) {
mCustomViewBehind = cvb;
mViewBehind = cvb;
}
@Override
@ -570,9 +454,6 @@ public class CustomViewAbove extends ViewGroup {
final int contentWidth = getChildMeasureSpec(widthMeasureSpec, 0, width);
final int contentHeight = getChildMeasureSpec(heightMeasureSpec, 0, height);
mContent.measure(contentWidth, contentHeight);
final int menuWidth = getChildMeasureSpec(widthMeasureSpec, 0, getBehindWidth());
mMenu.measure(menuWidth, contentHeight);
}
@Override
@ -584,7 +465,7 @@ public class CustomViewAbove extends ViewGroup {
// maybe worth having a look why the recomputeScroll pos is screwing
// up?
completeScroll();
scrollTo(getChildLeft(mCurItem), getScrollY());
scrollTo(getDestScrollX(mCurItem), getScrollY());
}
}
@ -592,10 +473,7 @@ public class CustomViewAbove extends ViewGroup {
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int width = r - l;
final int height = b - t;
int contentLeft = getChildLeft(1);
mMenu.layout(0, 0, width, height);
mContent.layout(contentLeft, 0, contentLeft + width, height);
mContent.layout(0, 0, width, height);
}
public void setAboveOffset(int i) {
@ -610,7 +488,6 @@ public class CustomViewAbove extends ViewGroup {
public void computeScroll() {
if (!mScroller.isFinished()) {
if (mScroller.computeScrollOffset()) {
if (DEBUG) Log.i(TAG, "computeScroll: still scrolling");
int oldX = getScrollX();
int oldY = getScrollY();
int x = mScroller.getCurrX();
@ -632,7 +509,7 @@ public class CustomViewAbove extends ViewGroup {
}
private void pageScrolled(int xpos) {
final int widthWithMargin = getChildWidth(mCurItem) + mShadowWidth;
final int widthWithMargin = getWidth();
final int position = xpos / widthWithMargin;
final int offsetPixels = xpos % widthWithMargin;
final float offset = (float) offsetPixels / widthWithMargin;
@ -686,7 +563,6 @@ public class CustomViewAbove extends ViewGroup {
}
protected int mTouchMode = SlidingMenu.TOUCHMODE_MARGIN;
private int mTouchModeBehind = SlidingMenu.TOUCHMODE_MARGIN;
public void setTouchMode(int i) {
mTouchMode = i;
@ -696,125 +572,79 @@ public class CustomViewAbove extends ViewGroup {
return mTouchMode;
}
protected void setTouchModeBehind(int i) {
mTouchModeBehind = i;
}
protected int getTouchModeBehind() {
return mTouchModeBehind;
}
private boolean thisTouchAllowed(MotionEvent ev) {
int x = (int) (ev.getX() + mScrollX);
if (isMenuOpen()) {
switch (mTouchModeBehind) {
case SlidingMenu.TOUCHMODE_FULLSCREEN:
return true;
case SlidingMenu.TOUCHMODE_NONE:
return false;
case SlidingMenu.TOUCHMODE_MARGIN:
return x >= getContentLeft();
default:
return false;
}
return mViewBehind.menuOpenTouchAllowed(mContent, mCurItem, x);
} else {
switch (mTouchMode) {
case SlidingMenu.TOUCHMODE_FULLSCREEN:
return true;
return !isInIgnoredView(ev);
case SlidingMenu.TOUCHMODE_NONE:
return false;
case SlidingMenu.TOUCHMODE_MARGIN:
int pixels = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
mSlidingMenuThreshold, getResources().getDisplayMetrics());
int left = getContentLeft();
return (x >= left && x <= pixels + left);
default:
return mViewBehind.marginTouchAllowed(mContent, x);
}
}
return false;
}
}
}
private boolean thisSlideAllowed(float dx) {
boolean allowed = false;
if (isMenuOpen()) {
allowed = dx < 0;
} else if (mCustomViewBehind != null) {
allowed = dx > 0;
allowed = mViewBehind.menuOpenSlideAllowed(dx);
} else {
allowed = mViewBehind.menuClosedSlideAllowed(dx);
}
Log.v(TAG, "this slide allowed " + allowed);
if (DEBUG)
Log.v(TAG, "this slide allowed " + allowed + " dx: " + dx);
return allowed;
}
private boolean mIsUnableToDrag;
private int getPointerIndex(MotionEvent ev, int id) {
int activePointerIndex = MotionEventCompat.findPointerIndex(ev, id);
if (activePointerIndex == -1)
mActivePointerId = INVALID_POINTER;
return activePointerIndex;
}
private boolean mQuickReturn = false;
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (!mEnabled) {
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) {
mIsBeingDragged = false;
mIsUnableToDrag = false;
mActivePointerId = INVALID_POINTER;
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
return false;
}
if (action != MotionEvent.ACTION_DOWN) {
if (mIsBeingDragged)
return true;
else if (mIsUnableToDrag)
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP
|| (action != MotionEvent.ACTION_DOWN && mIsUnableToDrag)) {
endDrag();
return false;
}
switch (action) {
case MotionEvent.ACTION_MOVE:
final int activePointerId = mActivePointerId;
if (activePointerId == INVALID_POINTER || activePointerId >= ev.getPointerCount())
determineDrag(ev);
break;
final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
if (pointerIndex==-1 || activePointerId >= ev.getPointerCount()) {
mActivePointerId = INVALID_POINTER;
break;
}
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 yDiff = Math.abs(y - mLastMotionY);
if (xDiff > mTouchSlop && xDiff > yDiff && thisSlideAllowed(dx)) {
if (DEBUG) Log.v(TAG, "Starting drag! from onInterceptTouch");
mIsBeingDragged = true;
mLastMotionX = x;
setScrollingCacheEnabled(true);
} else if (yDiff > mTouchSlop) {
mIsUnableToDrag = true;
}
break;
case MotionEvent.ACTION_DOWN:
mActivePointerId = ev.getAction() & ((Build.VERSION.SDK_INT >= 8) ? MotionEvent.ACTION_POINTER_INDEX_MASK :
MotionEvent.ACTION_POINTER_INDEX_MASK);
Log.v(TAG, "active pointer id : " + mActivePointerId);
mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, mActivePointerId);
mLastMotionY = MotionEventCompat.getY(ev, mActivePointerId);
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() && mInitialMotionX > getBehindWidth())
return true;
if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
mQuickReturn = true;
}
} else {
mIsUnableToDrag = true;
}
@ -830,31 +660,24 @@ public class CustomViewAbove extends ViewGroup {
}
mVelocityTracker.addMovement(ev);
}
return mIsBeingDragged;
return mIsBeingDragged || mQuickReturn;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (!mEnabled) {
return false;
}
if (!mIsBeingDragged && !mLastTouchAllowed && !thisTouchAllowed(ev)) {
if (!mEnabled)
return false;
}
if (!mIsBeingDragged && !thisTouchAllowed(ev))
return false;
// if (!mIsBeingDragged && !mQuickReturn)
// return false;
final int action = ev.getAction();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_CANCEL ||
action == MotionEvent.ACTION_OUTSIDE) {
mLastTouchAllowed = false;
} else {
mLastTouchAllowed = true;
}
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
@ -869,35 +692,28 @@ public class CustomViewAbove extends ViewGroup {
completeScroll();
// Remember where the motion event started
int index = MotionEventCompat.getActionIndex(ev);
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
mLastMotionX = mInitialMotionX = ev.getX();
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
break;
case MotionEvent.ACTION_MOVE:
if (!mIsBeingDragged) {
final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
final float x = MotionEventCompat.getX(ev, pointerIndex);
final float xDiff = Math.abs(x - mLastMotionX);
final float y = MotionEventCompat.getY(ev, pointerIndex);
final float yDiff = Math.abs(y - mLastMotionY);
if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
if (xDiff > mTouchSlop && xDiff > yDiff) {
if (DEBUG) Log.v(TAG, "Starting drag! from onTouch");
mIsBeingDragged = true;
mLastMotionX = x;
setScrollingCacheEnabled(true);
}
determineDrag(ev);
if (mIsUnableToDrag)
return false;
}
if (mIsBeingDragged) {
// Scroll to follow the motion event
final int activePointerIndex = MotionEventCompat.findPointerIndex(
ev, mActivePointerId);
final int activePointerIndex = getPointerIndex(ev, mActivePointerId);
if (mActivePointerId == INVALID_POINTER)
break;
final float x = MotionEventCompat.getX(ev, activePointerIndex);
final float deltaX = mLastMotionX - x;
mLastMotionX = x;
float oldScrollX = getScrollX();
float scrollX = oldScrollX + deltaX;
final float leftBound = getDestScrollX(0);
final float rightBound = getDestScrollX(1);
final float leftBound = getLeftBound();
final float rightBound = getRightBound();
if (scrollX < leftBound) {
scrollX = leftBound;
} else if (scrollX > rightBound) {
@ -915,23 +731,26 @@ public class CustomViewAbove extends ViewGroup {
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(
velocityTracker, mActivePointerId);
final int widthWithMargin = getChildWidth(mCurItem) + mShadowWidth;
final int scrollX = getScrollX();
final int currentPage = scrollX / widthWithMargin;
final float pageOffset = (float) (scrollX % widthWithMargin) / widthWithMargin;
final int activePointerIndex =
MotionEventCompat.findPointerIndex(ev, mActivePointerId);
// final int widthWithMargin = getWidth();
// final float pageOffset = (float) (scrollX % widthWithMargin) / widthWithMargin;
// TODO test this. should get better flinging behavior
final float pageOffset = (float) (scrollX - getDestScrollX(mCurItem)) / getBehindWidth();
final int activePointerIndex = getPointerIndex(ev, mActivePointerId);
if (mActivePointerId != INVALID_POINTER) {
final float x = MotionEventCompat.getX(ev, activePointerIndex);
final int totalDelta = (int) (x - mInitialMotionX);
int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
totalDelta);
int nextPage = determineTargetPage(pageOffset, initialVelocity, totalDelta);
setCurrentItemInternal(nextPage, true, true, initialVelocity);
} else {
setCurrentItemInternal(mCurItem, true, true, initialVelocity);
}
mActivePointerId = INVALID_POINTER;
endDrag();
} else if (isMenuOpen()) {
} else if (mQuickReturn && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
// close the menu
setCurrentItem(1);
endDrag();
}
break;
case MotionEvent.ACTION_CANCEL:
@ -942,173 +761,82 @@ public class CustomViewAbove extends ViewGroup {
}
break;
case MotionEventCompat.ACTION_POINTER_DOWN: {
final int index = MotionEventCompat.getActionIndex(ev);
final float x = MotionEventCompat.getX(ev, index);
mLastMotionX = x;
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
final int indexx = MotionEventCompat.getActionIndex(ev);
mLastMotionX = MotionEventCompat.getX(ev, indexx);
mActivePointerId = MotionEventCompat.getPointerId(ev, indexx);
break;
}
case MotionEventCompat.ACTION_POINTER_UP:
onSecondaryPointerUp(ev);
mLastMotionX = MotionEventCompat.getX(ev,
MotionEventCompat.findPointerIndex(ev, mActivePointerId));
int pointerIndex = getPointerIndex(ev, mActivePointerId);
if (mActivePointerId == INVALID_POINTER)
break;
mLastMotionX = MotionEventCompat.getX(ev, pointerIndex);
break;
}
if (mActivePointerId == INVALID_POINTER)
mLastTouchAllowed = false;
return true;
}
private float mScrollScale;
public float getScrollScale() {
return mScrollScale;
private void determineDrag(MotionEvent ev) {
final int activePointerId = mActivePointerId;
final int pointerIndex = getPointerIndex(ev, activePointerId);
if (activePointerId == 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 (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;
}
public void setScrollScale(float f) {
if (f < 0 && f > 1)
throw new IllegalStateException("ScrollScale must be between 0 and 1");
mScrollScale = f;
}
@Override
public void scrollTo(int x, int y) {
super.scrollTo(x, y);
mScrollX = x;
if (mCustomViewBehind != null && mEnabled) {
mCustomViewBehind.scrollTo((int)(x*mScrollScale), y);
}
if (mShadowDrawable != null || mSelectorDrawable != null)
invalidate();
if (mEnabled)
mViewBehind.scrollBehindTo(mContent, x, y);
((SlidingMenu)getParent()).manageLayers(getPercentOpen());
}
private int determineTargetPage(int currentPage, float pageOffset, int velocity, int deltaX) {
int targetPage;
private int determineTargetPage(float pageOffset, int velocity, int deltaX) {
int targetPage = mCurItem;
if (Math.abs(deltaX) > mFlingDistance && Math.abs(velocity) > mMinimumVelocity) {
targetPage = velocity > 0 ? currentPage : currentPage + 1;
if (velocity > 0 && deltaX > 0) {
targetPage -= 1;
} else if (velocity < 0 && deltaX < 0){
targetPage += 1;
}
} else {
targetPage = (int) (currentPage + pageOffset + 0.5f);
targetPage = (int) Math.round(mCurItem + pageOffset);
}
return targetPage;
}
protected float getPercentOpen() {
return (getBehindWidth() - mScrollX) / getBehindWidth();
return Math.abs(mScrollX-mContent.getLeft()) / getBehindWidth();
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
// Draw the margin drawable if needed.
if (mShadowWidth > 0 && mShadowDrawable != null) {
final int left = getContentLeft() - mShadowWidth;
mShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight());
mShadowDrawable.draw(canvas);
}
if (mFadeEnabled)
onDrawBehindFade(canvas, getPercentOpen());
if (mSelectorEnabled)
onDrawMenuSelector(canvas, getPercentOpen());
}
/**
* Pads our content window so that it fits within the system windows.
* @param insets The insets by which we need to offset our view.
* @return True since we handled the padding change.
*/
@Override
protected boolean fitSystemWindows(Rect insets) {
if (mContent != null) {
int leftPadding = mContent.getPaddingLeft() + insets.left;
int rightPadding = mContent.getPaddingRight() + insets.right;
int topPadding = insets.top;
int bottomPadding = insets.bottom;
mContent.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
return true;
}
return super.fitSystemWindows(insets);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mViewBehind.drawShadow(mContent, canvas);
mViewBehind.drawFade(mContent, canvas, getPercentOpen());
mViewBehind.drawSelector(mContent, canvas, getPercentOpen());
}
// variables for drawing
private float mScrollX = 0.0f;
// for the fade
private boolean mFadeEnabled;
private float mFadeDegree = 1.0f;
private final Paint mBehindFadePaint = new Paint();
// for the indicator
private boolean mSelectorEnabled = true;
private Bitmap mSelectorDrawable;
private View mSelectedView;
private void onDrawBehindFade(Canvas canvas, float openPercent) {
final int alpha = (int) (mFadeDegree * 255 * Math.abs(1-openPercent));
if (alpha > 0) {
mBehindFadePaint.setColor(Color.argb(alpha, 0, 0, 0));
canvas.drawRect(0, 0, getContentLeft(), getHeight(), mBehindFadePaint);
}
}
private void onDrawMenuSelector(Canvas canvas, float openPercent) {
if (mSelectorDrawable != null && mSelectedView != null) {
String tag = (String) mSelectedView.getTag(R.id.selected_view);
if (tag.equals(TAG+"SelectedView")) {
int right = getChildLeft(1);
int left = (int) (right - mSelectorDrawable.getWidth() * openPercent);
canvas.save();
canvas.clipRect(left, 0, right, getHeight());
canvas.drawBitmap(mSelectorDrawable, left, getSelectedTop(), null);
canvas.restore();
}
}
}
public void setBehindFadeEnabled(boolean b) {
mFadeEnabled = b;
}
public void setBehindFadeDegree(float f) {
if (f > 1.0f || f < 0.0f)
throw new IllegalStateException("The BehindFadeDegree must be between 0.0f and 1.0f");
mFadeDegree = f;
}
public void setSelectorEnabled(boolean b) {
mSelectorEnabled = b;
}
public void setSelectedView(View v) {
if (mSelectedView != null) {
mSelectedView.setTag(R.id.selected_view, null);
mSelectedView = null;
}
if (v.getParent() != null) {
mSelectedView = v;
mSelectedView.setTag(R.id.selected_view, TAG+"SelectedView");
invalidate();
}
}
private int getSelectedTop() {
int y = mSelectedView.getTop();
y += (mSelectedView.getHeight() - mSelectorDrawable.getHeight()) / 2;
return y;
}
public void setSelectorDrawable(Bitmap b) {
mSelectorDrawable = b;
refreshDrawableState();
}
private void onSecondaryPointerUp(MotionEvent ev) {
if (DEBUG) Log.v(TAG, "onSecondaryPointerUp called");
@ -1126,10 +854,16 @@ public class CustomViewAbove extends ViewGroup {
}
}
private void startDrag() {
mIsBeingDragged = true;
mQuickReturn = false;
}
private void endDrag() {
mQuickReturn = false;
mIsBeingDragged = false;
mIsUnableToDrag = false;
mLastTouchAllowed = false;
mActivePointerId = INVALID_POINTER;
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
@ -1235,13 +969,7 @@ public class CustomViewAbove extends ViewGroup {
direction);
if (nextFocused != null && nextFocused != currentFocused) {
if (direction == View.FOCUS_LEFT) {
// If there is nothing to the left, or this is causing us to
// jump to the right, then what we really want to do is page left.
if (currentFocused != null && nextFocused.getLeft() >= currentFocused.getLeft()) {
handled = pageLeft();
} else {
handled = nextFocused.requestFocus();
}
} else if (direction == View.FOCUS_RIGHT) {
// If there is nothing to the right, or this is causing us to
// jump to the left, then what we really want to do is page right.

View File

@ -1,19 +1,33 @@
package com.slidingmenu.lib;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import com.slidingmenu.lib.SlidingMenu.CanvasTransformer;
public class CustomViewBehind extends CustomViewAbove {
public class CustomViewBehind extends ViewGroup {
//private static final String TAG = "CustomViewBehind";
private static final String TAG = "CustomViewBehind";
private static final int MARGIN_THRESHOLD = 48; // dips
private int mTouchMode = SlidingMenu.TOUCHMODE_MARGIN;
private CustomViewAbove mViewAbove;
private View mContent;
private View mSecondaryContent;
private int mMarginThreshold;
private int mWidthOffset;
private CanvasTransformer mTransformer;
private boolean mChildrenEnabled;
@ -22,51 +36,52 @@ public class CustomViewBehind extends CustomViewAbove {
}
public CustomViewBehind(Context context, AttributeSet attrs) {
super(context, attrs, false);
super(context, attrs);
mMarginThreshold = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
MARGIN_THRESHOLD, getResources().getDisplayMetrics());
}
public void setCustomViewAbove(CustomViewAbove customViewAbove) {
mViewAbove = customViewAbove;
mViewAbove.setTouchModeBehind(mTouchMode);
}
public void setTouchMode(int i) {
mTouchMode = i;
if (mViewAbove != null)
mViewAbove.setTouchModeBehind(i);
}
public void setCanvasTransformer(CanvasTransformer t) {
mTransformer = t;
}
public int getChildLeft(int i) {
return 0;
}
@Override
public int getCustomWidth() {
int i = isMenuOpen()? 0 : 1;
return getChildWidth(i);
}
@Override
public int getChildWidth(int i) {
if (i <= 0) {
return getBehindWidth();
} else {
return getChildAt(i).getMeasuredWidth();
}
public void setWidthOffset(int i) {
mWidthOffset = i;
requestLayout();
}
public int getBehindWidth() {
ViewGroup.LayoutParams params = getLayoutParams();
return params.width;
return mContent.getWidth();
}
@Override
public void setContent(View v) {
super.setMenu(v);
if (mContent != null)
removeView(mContent);
mContent = v;
addView(mContent);
}
public View getContent() {
return mContent;
}
/**
* Sets the secondary (right) menu for use when setMode is called with SlidingMenu.LEFT_RIGHT.
* @param v the right menu
*/
public void setSecondaryContent(View v) {
if (mSecondaryContent != null)
removeView(mSecondaryContent);
mSecondaryContent = v;
addView(mSecondaryContent);
}
public View getSecondaryContent() {
return mSecondaryContent;
}
public void setChildrenEnabled(boolean enabled) {
@ -87,7 +102,7 @@ public class CustomViewBehind extends CustomViewAbove {
@Override
public boolean onTouchEvent(MotionEvent e) {
return false;
return !mChildrenEnabled;
}
@Override
@ -101,4 +116,316 @@ public class CustomViewBehind extends CustomViewAbove {
super.dispatchDraw(canvas);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int width = r - l;
final int height = b - t;
mContent.layout(0, 0, width-mWidthOffset, height);
if (mSecondaryContent != null)
mSecondaryContent.layout(0, 0, width-mWidthOffset, height);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = getDefaultSize(0, widthMeasureSpec);
int height = getDefaultSize(0, heightMeasureSpec);
setMeasuredDimension(width, height);
final int contentWidth = getChildMeasureSpec(widthMeasureSpec, 0, width-mWidthOffset);
final int contentHeight = getChildMeasureSpec(heightMeasureSpec, 0, height);
mContent.measure(contentWidth, contentHeight);
if (mSecondaryContent != null)
mSecondaryContent.measure(contentWidth, contentHeight);
}
private int mMode;
private boolean mFadeEnabled;
private final Paint mFadePaint = new Paint();
private float mScrollScale;
private Drawable mShadowDrawable;
private Drawable mSecondaryShadowDrawable;
private int mShadowWidth;
private float mFadeDegree;
public void setMode(int mode) {
if (mode == SlidingMenu.LEFT || mode == SlidingMenu.RIGHT) {
if (mContent != null)
mContent.setVisibility(View.VISIBLE);
if (mSecondaryContent != null)
mSecondaryContent.setVisibility(View.INVISIBLE);
}
mMode = mode;
}
public int getMode() {
return mMode;
}
public void setScrollScale(float scrollScale) {
mScrollScale = scrollScale;
}
public float getScrollScale() {
return mScrollScale;
}
public void setShadowDrawable(Drawable shadow) {
mShadowDrawable = shadow;
invalidate();
}
public void setSecondaryShadowDrawable(Drawable shadow) {
mSecondaryShadowDrawable = shadow;
invalidate();
}
public void setShadowWidth(int width) {
mShadowWidth = width;
invalidate();
}
public void setFadeEnabled(boolean b) {
mFadeEnabled = b;
}
public void setFadeDegree(float degree) {
if (degree > 1.0f || degree < 0.0f)
throw new IllegalStateException("The BehindFadeDegree must be between 0.0f and 1.0f");
mFadeDegree = degree;
}
public int getMenuPage(int page) {
page = (page > 1) ? 2 : ((page < 1) ? 0 : page);
if (mMode == SlidingMenu.LEFT && page > 1) {
return 0;
} else if (mMode == SlidingMenu.RIGHT && page < 1) {
return 2;
} else {
return page;
}
}
public void scrollBehindTo(View content, int x, int y) {
int vis = View.VISIBLE;
if (mMode == SlidingMenu.LEFT) {
if (x >= content.getLeft()) vis = View.INVISIBLE;
scrollTo((int)((x + getBehindWidth())*mScrollScale), y);
} else if (mMode == SlidingMenu.RIGHT) {
if (x <= content.getLeft()) vis = View.INVISIBLE;
scrollTo((int)(getBehindWidth() - getWidth() +
(x-getBehindWidth())*mScrollScale), y);
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
mContent.setVisibility(x >= content.getLeft() ? View.INVISIBLE : View.VISIBLE);
mSecondaryContent.setVisibility(x <= content.getLeft() ? View.INVISIBLE : View.VISIBLE);
vis = x == 0 ? View.INVISIBLE : View.VISIBLE;
if (x <= content.getLeft()) {
scrollTo((int)((x + getBehindWidth())*mScrollScale), y);
} else {
scrollTo((int)(getBehindWidth() - getWidth() +
(x-getBehindWidth())*mScrollScale), y);
}
}
if (vis == View.INVISIBLE)
Log.v(TAG, "behind INVISIBLE");
setVisibility(vis);
}
public int getMenuLeft(View content, int page) {
if (mMode == SlidingMenu.LEFT) {
switch (page) {
case 0:
return content.getLeft() - getBehindWidth();
case 2:
return content.getLeft();
}
} else if (mMode == SlidingMenu.RIGHT) {
switch (page) {
case 0:
return content.getLeft();
case 2:
return content.getLeft() + getBehindWidth();
}
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
switch (page) {
case 0:
return content.getLeft() - getBehindWidth();
case 2:
return content.getLeft() + getBehindWidth();
}
}
return content.getLeft();
}
public int getAbsLeftBound(View content) {
if (mMode == SlidingMenu.LEFT || mMode == SlidingMenu.LEFT_RIGHT) {
return content.getLeft() - getBehindWidth();
} else if (mMode == SlidingMenu.RIGHT) {
return content.getLeft();
}
return 0;
}
public int getAbsRightBound(View content) {
if (mMode == SlidingMenu.LEFT) {
return content.getLeft();
} else if (mMode == SlidingMenu.RIGHT || mMode == SlidingMenu.LEFT_RIGHT) {
return content.getLeft() + getBehindWidth();
}
return 0;
}
public boolean marginTouchAllowed(View content, int x) {
int left = content.getLeft();
int right = content.getRight();
if (mMode == SlidingMenu.LEFT) {
return (x >= left && x <= mMarginThreshold + left);
} else if (mMode == SlidingMenu.RIGHT) {
return (x <= right && x >= right - mMarginThreshold);
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
return (x >= left && x <= mMarginThreshold + left) ||
(x <= right && x >= right - mMarginThreshold);
}
return false;
}
public void setTouchMode(int i) {
mTouchMode = i;
}
public boolean menuOpenTouchAllowed(View content, int currPage, float x) {
switch (mTouchMode) {
case SlidingMenu.TOUCHMODE_FULLSCREEN:
return true;
case SlidingMenu.TOUCHMODE_MARGIN:
return menuTouchInQuickReturn(content, currPage, x);
}
return false;
}
public boolean menuTouchInQuickReturn(View content, int currPage, float x) {
if (mMode == SlidingMenu.LEFT || (mMode == SlidingMenu.LEFT_RIGHT && currPage == 0)) {
return x >= content.getLeft();
} else if (mMode == SlidingMenu.RIGHT || (mMode == SlidingMenu.LEFT_RIGHT && currPage == 2)) {
return x <= content.getRight();
}
return false;
}
public boolean menuClosedSlideAllowed(float dx) {
if (mMode == SlidingMenu.LEFT) {
return dx > 0;
} else if (mMode == SlidingMenu.RIGHT) {
return dx < 0;
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
return true;
}
return false;
}
public boolean menuOpenSlideAllowed(float dx) {
if (mMode == SlidingMenu.LEFT) {
return dx < 0;
} else if (mMode == SlidingMenu.RIGHT) {
return dx > 0;
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
return true;
}
return false;
}
public void drawShadow(View content, Canvas canvas) {
if (mShadowDrawable == null || mShadowWidth <= 0) return;
int left = 0;
if (mMode == SlidingMenu.LEFT) {
left = content.getLeft() - mShadowWidth;
} else if (mMode == SlidingMenu.RIGHT) {
left = content.getRight();
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
if (mSecondaryShadowDrawable != null) {
left = content.getRight();
mSecondaryShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight());
mSecondaryShadowDrawable.draw(canvas);
}
left = content.getLeft() - mShadowWidth;
}
mShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight());
mShadowDrawable.draw(canvas);
}
public void drawFade(View content, Canvas canvas, float openPercent) {
if (!mFadeEnabled) return;
final int alpha = (int) (mFadeDegree * 255 * Math.abs(1-openPercent));
mFadePaint.setColor(Color.argb(alpha, 0, 0, 0));
int left = 0;
int right = 0;
if (mMode == SlidingMenu.LEFT) {
left = content.getLeft() - getBehindWidth();
right = content.getLeft();
} else if (mMode == SlidingMenu.RIGHT) {
left = content.getRight();
right = content.getRight() + getBehindWidth();
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
left = content.getLeft() - getBehindWidth();
right = content.getLeft();
canvas.drawRect(left, 0, right, getHeight(), mFadePaint);
left = content.getRight();
right = content.getRight() + getBehindWidth();
}
canvas.drawRect(left, 0, right, getHeight(), mFadePaint);
}
private boolean mSelectorEnabled = true;
private Bitmap mSelectorDrawable;
private View mSelectedView;
public void drawSelector(View content, Canvas canvas, float openPercent) {
if (!mSelectorEnabled) return;
if (mSelectorDrawable != null && mSelectedView != null) {
String tag = (String) mSelectedView.getTag(R.id.selected_view);
if (tag.equals(TAG+"SelectedView")) {
canvas.save();
int left, right, offset;
offset = (int) (mSelectorDrawable.getWidth() * openPercent);
if (mMode == SlidingMenu.LEFT) {
right = content.getLeft();
left = right - offset;
canvas.clipRect(left, 0, right, getHeight());
canvas.drawBitmap(mSelectorDrawable, left, getSelectorTop(), null);
} else if (mMode == SlidingMenu.RIGHT) {
left = content.getRight();
right = left + offset;
canvas.clipRect(left, 0, right, getHeight());
canvas.drawBitmap(mSelectorDrawable, right - mSelectorDrawable.getWidth(), getSelectorTop(), null);
}
canvas.restore();
}
}
}
public void setSelectorEnabled(boolean b) {
mSelectorEnabled = b;
}
public void setSelectedView(View v) {
if (mSelectedView != null) {
mSelectedView.setTag(R.id.selected_view, null);
mSelectedView = null;
}
if (v != null && v.getParent() != null) {
mSelectedView = v;
mSelectedView.setTag(R.id.selected_view, TAG+"SelectedView");
invalidate();
}
}
private int getSelectorTop() {
int y = mSelectedView.getTop();
y += (mSelectedView.getHeight() - mSelectorDrawable.getHeight()) / 2;
return y;
}
public void setSelectorBitmap(Bitmap b) {
mSelectorDrawable = b;
refreshDrawableState();
}
}

View File

@ -0,0 +1,35 @@
package com.slidingmenu.lib;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.view.View;
public interface MenuInterface {
public abstract void scrollBehindTo(int x, int y,
CustomViewBehind cvb, float scrollScale);
public abstract int getMenuLeft(CustomViewBehind cvb, View content);
public abstract int getAbsLeftBound(CustomViewBehind cvb, View content);
public abstract int getAbsRightBound(CustomViewBehind cvb, View content);
public abstract boolean marginTouchAllowed(View content, int x, int threshold);
public abstract boolean menuOpenTouchAllowed(View content, int currPage, int x);
public abstract boolean menuTouchInQuickReturn(View content, int currPage, int x);
public abstract boolean menuClosedSlideAllowed(int x);
public abstract boolean menuOpenSlideAllowed(int x);
public abstract void drawShadow(Canvas canvas, Drawable shadow, int width);
public abstract void drawFade(Canvas canvas, int alpha,
CustomViewBehind cvb, View content);
public abstract void drawSelector(View content, Canvas canvas, float percentOpen);
}

View File

@ -12,6 +12,9 @@ public class SlidingActivity extends Activity implements SlidingActivityBase {
private SlidingActivityHelper mHelper;
/* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -19,12 +22,18 @@ public class SlidingActivity extends Activity implements SlidingActivityBase {
mHelper.onCreate(savedInstanceState);
}
/* (non-Javadoc)
* @see android.app.Activity#onPostCreate(android.os.Bundle)
*/
@Override
public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mHelper.onPostCreate(savedInstanceState);
}
/* (non-Javadoc)
* @see android.app.Activity#findViewById(int)
*/
@Override
public View findViewById(int id) {
View v = super.findViewById(id);
@ -33,54 +42,106 @@ public class SlidingActivity extends Activity implements SlidingActivityBase {
return mHelper.findViewById(id);
}
/* (non-Javadoc)
* @see android.app.Activity#onSaveInstanceState(android.os.Bundle)
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mHelper.onSaveInstanceState(outState);
}
/* (non-Javadoc)
* @see android.app.Activity#setContentView(int)
*/
@Override
public void setContentView(int id) {
setContentView(getLayoutInflater().inflate(id, null));
}
/* (non-Javadoc)
* @see android.app.Activity#setContentView(android.view.View)
*/
@Override
public void setContentView(View v) {
setContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
/* (non-Javadoc)
* @see android.app.Activity#setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
@Override
public void setContentView(View v, LayoutParams params) {
super.setContentView(v, params);
mHelper.registerAboveContentView(v, params);
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(int)
*/
public void setBehindContentView(int id) {
setBehindContentView(getLayoutInflater().inflate(id, null));
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(android.view.View)
*/
public void setBehindContentView(View v) {
setBehindContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
public void setBehindContentView(View v, LayoutParams params) {
mHelper.setBehindContentView(v, params);
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#getSlidingMenu()
*/
public SlidingMenu getSlidingMenu() {
return mHelper.getSlidingMenu();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#toggle()
*/
public void toggle() {
mHelper.toggle();
}
public void showAbove() {
mHelper.showAbove();
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#showAbove()
*/
public void showContent() {
mHelper.showContent();
}
public void showBehind() {
mHelper.showBehind();
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#showBehind()
*/
public void showMenu() {
mHelper.showMenu();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#showSecondaryMenu()
*/
public void showSecondaryMenu() {
mHelper.showSecondaryMenu();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setSlidingActionBarEnabled(boolean)
*/
public void setSlidingActionBarEnabled(boolean b) {
mHelper.setSlidingActionBarEnabled(b);
}
/* (non-Javadoc)
* @see android.app.Activity#onKeyUp(int, android.view.KeyEvent)
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
boolean b = mHelper.onKeyUp(keyCode, event);

View File

@ -7,14 +7,68 @@ import com.slidingmenu.lib.SlidingMenu;
public interface SlidingActivityBase {
public void setBehindContentView(View v, LayoutParams p);
/**
* Set the behind view content to an explicit view. This view is placed directly into the behind view 's view hierarchy.
* It can itself be a complex view hierarchy.
*
* @param view The desired content to display.
* @param layoutParams Layout parameters for the view.
*/
public void setBehindContentView(View view, LayoutParams layoutParams);
/**
* Set the behind view content to an explicit view. This view is placed directly into the behind view 's view hierarchy.
* It can itself be a complex view hierarchy. When calling this method, the layout parameters of the specified
* view are ignored. Both the width and the height of the view are set by default to MATCH_PARENT. To use your
* own layout parameters, invoke setContentView(android.view.View, android.view.ViewGroup.LayoutParams) instead.
*
* @param view The desired content to display.
*/
public void setBehindContentView(View view);
/**
* Set the behind view content from a layout resource. The resource will be inflated, adding all top-level views
* to the behind view.
*
* @param layoutResID Resource ID to be inflated.
*/
public void setBehindContentView(int layoutResID);
/**
* Gets the SlidingMenu associated with this activity.
*
* @return the SlidingMenu associated with this activity.
*/
public SlidingMenu getSlidingMenu();
/**
* Toggle the SlidingMenu. If it is open, it will be closed, and vice versa.
*/
public void toggle();
public void showAbove();
/**
* Close the SlidingMenu and show the content view.
*/
public void showContent();
public void showBehind();
/**
* Open the SlidingMenu and show the menu view.
*/
public void showMenu();
/**
* Open the SlidingMenu and show the secondary (right) menu view. Will default to the regular menu
* if there is only one.
*/
public void showSecondaryMenu();
/**
* Controls whether the ActionBar slides along with the above view when the menu is opened,
* or if it stays in place.
*
* @param slidingActionBarEnabled True if you want the ActionBar to slide along with the SlidingMenu,
* false if you want the ActionBar to stay in place
*/
public void setSlidingActionBarEnabled(boolean slidingActionBarEnabled);
}

View File

@ -1,12 +1,11 @@
package com.slidingmenu.lib.app;
import android.app.Activity;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import com.slidingmenu.lib.R;
@ -17,21 +16,40 @@ public class SlidingActivityHelper {
private Activity mActivity;
private SlidingMenu mSlidingMenu;
private View mViewAbove;
private View mViewBehind;
private boolean mBroadcasting = false;
private boolean mOnPostCreateCalled = false;
private boolean mEnableSlide = true;
/**
* Instantiates a new SlidingActivityHelper.
*
* @param activity the associated activity
*/
public SlidingActivityHelper(Activity activity) {
mActivity = activity;
}
/**
* Sets mSlidingMenu as a newly inflated SlidingMenu. Should be called within the activitiy's onCreate()
*
* @param savedInstanceState the saved instance state (unused)
*/
public void onCreate(Bundle savedInstanceState) {
mSlidingMenu = (SlidingMenu) LayoutInflater.from(mActivity).inflate(R.layout.slidingmenumain, null);
}
/**
* Further SlidingMenu initialization. Should be called within the activitiy's onPostCreate()
*
* @param savedInstanceState the saved instance state (unused)
*/
public void onPostCreate(Bundle savedInstanceState) {
if (mViewBehind == null || mViewAbove == null) {
throw new IllegalStateException("Both setBehindContentView must be called " +
@ -40,40 +58,52 @@ public class SlidingActivityHelper {
mOnPostCreateCalled = true;
// get the window background
TypedArray a = mActivity.getTheme().obtainStyledAttributes(new int[] {android.R.attr.windowBackground});
int background = a.getResourceId(0, 0);
mSlidingMenu.attachToActivity(mActivity,
mEnableSlide ? SlidingMenu.SLIDING_WINDOW : SlidingMenu.SLIDING_CONTENT);
if (mEnableSlide) {
// move everything into the SlidingMenu
ViewGroup decor = (ViewGroup) mActivity.getWindow().getDecorView();
ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
// save ActionBar themes that have transparent assets
decorChild.setBackgroundResource(background);
decor.removeView(decorChild);
mSlidingMenu.setContent(decorChild);
decor.addView(mSlidingMenu);
final boolean open;
final boolean secondary;
if (savedInstanceState != null) {
open = savedInstanceState.getBoolean("SlidingActivityHelper.open");
secondary = savedInstanceState.getBoolean("SlidingActivityHelper.secondary");
} else {
// take the above view out of
ViewGroup parent = (ViewGroup) mViewAbove.getParent();
if (parent != null) {
parent.removeView(mViewAbove);
open = false;
secondary = false;
}
// save people from having transparent backgrounds
if (mViewAbove.getBackground() == null) {
mViewAbove.setBackgroundResource(background);
new Handler().post(new Runnable() {
public void run() {
if (open) {
if (secondary) {
mSlidingMenu.showSecondaryMenu(false);
} else {
mSlidingMenu.showMenu(false);
}
mSlidingMenu.setContent(mViewAbove);
parent.addView(mSlidingMenu, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
} else {
mSlidingMenu.showContent(false);
}
}
});
}
public void setSlidingActionBarEnabled(boolean b) {
/**
* Controls whether the ActionBar slides along with the above view when the menu is opened,
* or if it stays in place.
*
* @param slidingActionBarEnabled True if you want the ActionBar to slide along with the SlidingMenu,
* false if you want the ActionBar to stay in place
*/
public void setSlidingActionBarEnabled(boolean slidingActionBarEnabled) {
if (mOnPostCreateCalled)
throw new IllegalStateException("enableSlidingActionBar must be called in onCreate.");
mEnableSlide = b;
mEnableSlide = slidingActionBarEnabled;
}
/**
* Finds a view that was identified by the id attribute from the XML that was processed in onCreate(Bundle).
*
* @param id the resource id of the desired view
* @return The view if found or null otherwise.
*/
public View findViewById(int id) {
View v;
if (mSlidingMenu != null) {
@ -84,44 +114,103 @@ public class SlidingActivityHelper {
return null;
}
/**
* Called to retrieve per-instance state from an activity before being killed so that the state can be
* restored in onCreate(Bundle) or onRestoreInstanceState(Bundle) (the Bundle populated by this method
* will be passed to both).
*
* @param outState Bundle in which to place your saved state.
*/
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean("SlidingActivityHelper.open", mSlidingMenu.isMenuShowing());
outState.putBoolean("SlidingActivityHelper.secondary", mSlidingMenu.isSecondaryMenuShowing());
}
/**
* Register the above content view.
*
* @param v the above content view to register
* @param params LayoutParams for that view (unused)
*/
public void registerAboveContentView(View v, LayoutParams params) {
if (!mBroadcasting)
mViewAbove = v;
}
/**
* Set the activity content to an explicit view. This view is placed directly into the activity's view
* hierarchy. It can itself be a complex view hierarchy. When calling this method, the layout parameters
* of the specified view are ignored. Both the width and the height of the view are set by default to
* MATCH_PARENT. To use your own layout parameters, invoke setContentView(android.view.View,
* android.view.ViewGroup.LayoutParams) instead.
*
* @param v The desired content to display.
*/
public void setContentView(View v) {
mBroadcasting = true;
mActivity.setContentView(v);
}
public void setBehindContentView(View v, LayoutParams params) {
mViewBehind = v;
/**
* Set the behind view content to an explicit view. This view is placed directly into the behind view 's view hierarchy.
* It can itself be a complex view hierarchy.
*
* @param view The desired content to display.
* @param layoutParams Layout parameters for the view. (unused)
*/
public void setBehindContentView(View view, LayoutParams layoutParams) {
mViewBehind = view;
mSlidingMenu.setMenu(mViewBehind);
}
/**
* Gets the SlidingMenu associated with this activity.
*
* @return the SlidingMenu associated with this activity.
*/
public SlidingMenu getSlidingMenu() {
return mSlidingMenu;
}
/**
* Toggle the SlidingMenu. If it is open, it will be closed, and vice versa.
*/
public void toggle() {
if (mSlidingMenu.isBehindShowing()) {
showAbove();
} else {
showBehind();
}
mSlidingMenu.toggle();
}
public void showAbove() {
mSlidingMenu.showAbove();
/**
* Close the SlidingMenu and show the content view.
*/
public void showContent() {
mSlidingMenu.showContent();
}
public void showBehind() {
mSlidingMenu.showBehind();
/**
* Open the SlidingMenu and show the menu view.
*/
public void showMenu() {
mSlidingMenu.showMenu();
}
/**
* Open the SlidingMenu and show the secondary menu view. Will default to the regular menu
* if there is only one.
*/
public void showSecondaryMenu() {
mSlidingMenu.showSecondaryMenu();
}
/**
* On key up.
*
* @param keyCode the key code
* @param event the event
* @return true, if successful
*/
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && mSlidingMenu.isBehindShowing()) {
showAbove();
if (keyCode == KeyEvent.KEYCODE_BACK && mSlidingMenu.isMenuShowing()) {
showContent();
return true;
}
return false;

View File

@ -12,6 +12,9 @@ public class SlidingFragmentActivity extends FragmentActivity implements Sliding
private SlidingActivityHelper mHelper;
/* (non-Javadoc)
* @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -19,12 +22,18 @@ public class SlidingFragmentActivity extends FragmentActivity implements Sliding
mHelper.onCreate(savedInstanceState);
}
/* (non-Javadoc)
* @see android.app.Activity#onPostCreate(android.os.Bundle)
*/
@Override
public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mHelper.onPostCreate(savedInstanceState);
}
/* (non-Javadoc)
* @see android.app.Activity#findViewById(int)
*/
@Override
public View findViewById(int id) {
View v = super.findViewById(id);
@ -33,54 +42,106 @@ public class SlidingFragmentActivity extends FragmentActivity implements Sliding
return mHelper.findViewById(id);
}
/* (non-Javadoc)
* @see android.support.v4.app.FragmentActivity#onSaveInstanceState(android.os.Bundle)
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mHelper.onSaveInstanceState(outState);
}
/* (non-Javadoc)
* @see android.app.Activity#setContentView(int)
*/
@Override
public void setContentView(int id) {
setContentView(getLayoutInflater().inflate(id, null));
}
/* (non-Javadoc)
* @see android.app.Activity#setContentView(android.view.View)
*/
@Override
public void setContentView(View v) {
setContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
/* (non-Javadoc)
* @see android.app.Activity#setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
@Override
public void setContentView(View v, LayoutParams params) {
super.setContentView(v, params);
mHelper.registerAboveContentView(v, params);
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(int)
*/
public void setBehindContentView(int id) {
setBehindContentView(getLayoutInflater().inflate(id, null));
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(android.view.View)
*/
public void setBehindContentView(View v) {
setBehindContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
public void setBehindContentView(View v, LayoutParams params) {
mHelper.setBehindContentView(v, params);
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#getSlidingMenu()
*/
public SlidingMenu getSlidingMenu() {
return mHelper.getSlidingMenu();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#toggle()
*/
public void toggle() {
mHelper.toggle();
}
public void showAbove() {
mHelper.showAbove();
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#showAbove()
*/
public void showContent() {
mHelper.showContent();
}
public void showBehind() {
mHelper.showBehind();
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#showBehind()
*/
public void showMenu() {
mHelper.showMenu();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#showSecondaryMenu()
*/
public void showSecondaryMenu() {
mHelper.showSecondaryMenu();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setSlidingActionBarEnabled(boolean)
*/
public void setSlidingActionBarEnabled(boolean b) {
mHelper.setSlidingActionBarEnabled(b);
}
/* (non-Javadoc)
* @see android.app.Activity#onKeyUp(int, android.view.KeyEvent)
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
boolean b = mHelper.onKeyUp(keyCode, event);

View File

@ -13,6 +13,9 @@ public class SlidingListActivity extends ListActivity implements SlidingActivity
private SlidingActivityHelper mHelper;
/* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -23,12 +26,18 @@ public class SlidingListActivity extends ListActivity implements SlidingActivity
setContentView(listView);
}
/* (non-Javadoc)
* @see android.app.Activity#onPostCreate(android.os.Bundle)
*/
@Override
public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mHelper.onPostCreate(savedInstanceState);
}
/* (non-Javadoc)
* @see android.app.Activity#findViewById(int)
*/
@Override
public View findViewById(int id) {
View v = super.findViewById(id);
@ -37,54 +46,107 @@ public class SlidingListActivity extends ListActivity implements SlidingActivity
return mHelper.findViewById(id);
}
/* (non-Javadoc)
* @see android.app.Activity#onSaveInstanceState(android.os.Bundle)
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mHelper.onSaveInstanceState(outState);
}
/* (non-Javadoc)
* @see android.app.Activity#setContentView(int)
*/
@Override
public void setContentView(int id) {
setContentView(getLayoutInflater().inflate(id, null));
}
/* (non-Javadoc)
* @see android.app.Activity#setContentView(android.view.View)
*/
@Override
public void setContentView(View v) {
setContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
/* (non-Javadoc)
* @see android.app.Activity#setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
@Override
public void setContentView(View v, LayoutParams params) {
super.setContentView(v, params);
mHelper.registerAboveContentView(v, params);
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(int)
*/
public void setBehindContentView(int id) {
setBehindContentView(getLayoutInflater().inflate(id, null));
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(android.view.View)
*/
public void setBehindContentView(View v) {
setBehindContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
public void setBehindContentView(View v, LayoutParams params) {
mHelper.setBehindContentView(v, params);
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#getSlidingMenu()
*/
public SlidingMenu getSlidingMenu() {
return mHelper.getSlidingMenu();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#toggle()
*/
public void toggle() {
mHelper.toggle();
}
public void showAbove() {
mHelper.showAbove();
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#showAbove()
*/
public void showContent() {
mHelper.showContent();
}
public void showBehind() {
mHelper.showBehind();
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#showBehind()
*/
public void showMenu() {
mHelper.showMenu();
}
/*
* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#showSecondaryMenu()
*/
public void showSecondaryMenu() {
mHelper.showSecondaryMenu();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setSlidingActionBarEnabled(boolean)
*/
public void setSlidingActionBarEnabled(boolean b) {
mHelper.setSlidingActionBarEnabled(b);
}
/* (non-Javadoc)
* @see android.app.Activity#onKeyUp(int, android.view.KeyEvent)
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
boolean b = mHelper.onKeyUp(keyCode, event);

View File

@ -1,7 +1,151 @@
package com.slidingmenu.lib.app;
import com.slidingmenu.lib.SlidingMenu;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
public class SlidingPreferenceActivity extends PreferenceActivity {
public class SlidingPreferenceActivity extends PreferenceActivity implements SlidingActivityBase {
private SlidingActivityHelper mHelper;
/* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(Bundle savedInstanceState) {
mHelper = new SlidingActivityHelper(this);
super.onCreate(savedInstanceState);
mHelper.onCreate(savedInstanceState);
}
/* (non-Javadoc)
* @see android.app.Activity#onPostCreate(android.os.Bundle)
*/
@Override
public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mHelper.onPostCreate(savedInstanceState);
}
/* (non-Javadoc)
* @see android.app.Activity#findViewById(int)
*/
@Override
public View findViewById(int id) {
View v = super.findViewById(id);
if (v != null)
return v;
return mHelper.findViewById(id);
}
/* (non-Javadoc)
* @see android.app.Activity#onSaveInstanceState(android.os.Bundle)
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mHelper.onSaveInstanceState(outState);
}
/* (non-Javadoc)
* @see android.app.Activity#setContentView(int)
*/
@Override
public void setContentView(int id) {
setContentView(getLayoutInflater().inflate(id, null));
}
/* (non-Javadoc)
* @see android.app.Activity#setContentView(android.view.View)
*/
@Override
public void setContentView(View v) {
setContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
/* (non-Javadoc)
* @see android.app.Activity#setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
@Override
public void setContentView(View v, LayoutParams params) {
super.setContentView(v, params);
mHelper.registerAboveContentView(v, params);
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(int)
*/
public void setBehindContentView(int id) {
setBehindContentView(getLayoutInflater().inflate(id, null));
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(android.view.View)
*/
public void setBehindContentView(View v) {
setBehindContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
public void setBehindContentView(View v, LayoutParams params) {
mHelper.setBehindContentView(v, params);
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#getSlidingMenu()
*/
public SlidingMenu getSlidingMenu() {
return mHelper.getSlidingMenu();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#toggle()
*/
public void toggle() {
mHelper.toggle();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#showAbove()
*/
public void showContent() {
mHelper.showContent();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#showBehind()
*/
public void showMenu() {
mHelper.showMenu();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#showSecondaryMenu()
*/
public void showSecondaryMenu() {
mHelper.showSecondaryMenu();
}
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setSlidingActionBarEnabled(boolean)
*/
public void setSlidingActionBarEnabled(boolean b) {
mHelper.setSlidingActionBarEnabled(b);
}
/* (non-Javadoc)
* @see android.app.Activity#onKeyUp(int, android.view.KeyEvent)
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
boolean b = mHelper.onKeyUp(keyCode, event);
if (b) return b;
return super.onKeyUp(keyCode, event);
}
}