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"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

View File

@ -6,15 +6,6 @@
<uses-sdk <uses-sdk
android:minSdkVersion="5" android:minSdkVersion="5"
android:targetSdkVersion="16" /> android:targetSdkVersion="17" />
<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>
</manifest> </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> <resources>
<declare-styleable name="SlidingMenu"> <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="viewAbove" format="reference" />
<attr name="viewBehind" format="reference" /> <attr name="viewBehind" format="reference" />
<attr name="behindOffset" format="dimension" /> <attr name="behindOffset" format="dimension" />
@ -32,8 +36,8 @@
</attr> </attr>
<attr name="shadowDrawable" format="reference" /> <attr name="shadowDrawable" format="reference" />
<attr name="shadowWidth" format="dimension" /> <attr name="shadowWidth" format="dimension" />
<attr name="behindFadeEnabled" format="boolean" /> <attr name="fadeEnabled" format="boolean" />
<attr name="behindFadeDegree" format="float" /> <attr name="fadeDegree" format="float" />
<attr name="selectorEnabled" format="boolean" /> <attr name="selectorEnabled" format="boolean" />
<attr name="selectorDrawable" format="reference" /> <attr name="selectorDrawable" format="reference" />
</declare-styleable> </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; import com.slidingmenu.lib.SlidingMenu.CanvasTransformer;
public class CanvasTranformerBuilder { public class CanvasTransformerBuilder {
private CanvasTransformer mTrans; private CanvasTransformer mTrans;

View File

@ -1,19 +1,33 @@
package com.slidingmenu.lib; package com.slidingmenu.lib;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.slidingmenu.lib.SlidingMenu.CanvasTransformer; 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 CustomViewAbove mViewAbove;
private View mContent;
private View mSecondaryContent;
private int mMarginThreshold;
private int mWidthOffset;
private CanvasTransformer mTransformer; private CanvasTransformer mTransformer;
private boolean mChildrenEnabled; private boolean mChildrenEnabled;
@ -22,57 +36,58 @@ public class CustomViewBehind extends CustomViewAbove {
} }
public CustomViewBehind(Context context, AttributeSet attrs) { 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) { public void setCustomViewAbove(CustomViewAbove customViewAbove) {
mViewAbove = customViewAbove; mViewAbove = customViewAbove;
mViewAbove.setTouchModeBehind(mTouchMode);
}
public void setTouchMode(int i) {
mTouchMode = i;
if (mViewAbove != null)
mViewAbove.setTouchModeBehind(i);
} }
public void setCanvasTransformer(CanvasTransformer t) { public void setCanvasTransformer(CanvasTransformer t) {
mTransformer = t; mTransformer = t;
} }
public int getChildLeft(int i) { public void setWidthOffset(int i) {
return 0; mWidthOffset = i;
} requestLayout();
@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 int getBehindWidth() { public int getBehindWidth() {
ViewGroup.LayoutParams params = getLayoutParams(); return mContent.getWidth();
return params.width;
} }
@Override
public void setContent(View v) { 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) { public void setChildrenEnabled(boolean enabled) {
mChildrenEnabled = enabled; mChildrenEnabled = enabled;
} }
@Override @Override
public void scrollTo(int x, int y) { public void scrollTo(int x, int y) {
super.scrollTo(x, y); super.scrollTo(x, y);
@ -87,7 +102,7 @@ public class CustomViewBehind extends CustomViewAbove {
@Override @Override
public boolean onTouchEvent(MotionEvent e) { public boolean onTouchEvent(MotionEvent e) {
return false; return !mChildrenEnabled;
} }
@Override @Override
@ -101,4 +116,316 @@ public class CustomViewBehind extends CustomViewAbove {
super.dispatchDraw(canvas); 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; private SlidingActivityHelper mHelper;
/* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -19,12 +22,18 @@ public class SlidingActivity extends Activity implements SlidingActivityBase {
mHelper.onCreate(savedInstanceState); mHelper.onCreate(savedInstanceState);
} }
/* (non-Javadoc)
* @see android.app.Activity#onPostCreate(android.os.Bundle)
*/
@Override @Override
public void onPostCreate(Bundle savedInstanceState) { public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState); super.onPostCreate(savedInstanceState);
mHelper.onPostCreate(savedInstanceState); mHelper.onPostCreate(savedInstanceState);
} }
/* (non-Javadoc)
* @see android.app.Activity#findViewById(int)
*/
@Override @Override
public View findViewById(int id) { public View findViewById(int id) {
View v = super.findViewById(id); View v = super.findViewById(id);
@ -33,54 +42,106 @@ public class SlidingActivity extends Activity implements SlidingActivityBase {
return mHelper.findViewById(id); 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 @Override
public void setContentView(int id) { public void setContentView(int id) {
setContentView(getLayoutInflater().inflate(id, null)); setContentView(getLayoutInflater().inflate(id, null));
} }
/* (non-Javadoc)
* @see android.app.Activity#setContentView(android.view.View)
*/
@Override @Override
public void setContentView(View v) { public void setContentView(View v) {
setContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 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 @Override
public void setContentView(View v, LayoutParams params) { public void setContentView(View v, LayoutParams params) {
super.setContentView(v, params); super.setContentView(v, params);
mHelper.registerAboveContentView(v, params); mHelper.registerAboveContentView(v, params);
} }
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(int)
*/
public void setBehindContentView(int id) { public void setBehindContentView(int id) {
setBehindContentView(getLayoutInflater().inflate(id, null)); setBehindContentView(getLayoutInflater().inflate(id, null));
} }
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(android.view.View)
*/
public void setBehindContentView(View v) { public void setBehindContentView(View v) {
setBehindContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 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) { public void setBehindContentView(View v, LayoutParams params) {
mHelper.setBehindContentView(v, params); mHelper.setBehindContentView(v, params);
} }
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#getSlidingMenu()
*/
public SlidingMenu getSlidingMenu() { public SlidingMenu getSlidingMenu() {
return mHelper.getSlidingMenu(); return mHelper.getSlidingMenu();
} }
/* (non-Javadoc)
* @see com.slidingmenu.lib.app.SlidingActivityBase#toggle()
*/
public void toggle() { public void toggle() {
mHelper.toggle(); mHelper.toggle();
} }
public void showAbove() { /* (non-Javadoc)
mHelper.showAbove(); * @see com.slidingmenu.lib.app.SlidingActivityBase#showAbove()
*/
public void showContent() {
mHelper.showContent();
} }
public void showBehind() { /* (non-Javadoc)
mHelper.showBehind(); * @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) { public void setSlidingActionBarEnabled(boolean b) {
mHelper.setSlidingActionBarEnabled(b); mHelper.setSlidingActionBarEnabled(b);
} }
/* (non-Javadoc)
* @see android.app.Activity#onKeyUp(int, android.view.KeyEvent)
*/
@Override @Override
public boolean onKeyUp(int keyCode, KeyEvent event) { public boolean onKeyUp(int keyCode, KeyEvent event) {
boolean b = mHelper.onKeyUp(keyCode, event); boolean b = mHelper.onKeyUp(keyCode, event);

View File

@ -7,14 +7,68 @@ import com.slidingmenu.lib.SlidingMenu;
public interface SlidingActivityBase { 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(); public SlidingMenu getSlidingMenu();
/**
* Toggle the SlidingMenu. If it is open, it will be closed, and vice versa.
*/
public void toggle(); 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; package com.slidingmenu.lib.app;
import android.app.Activity; import android.app.Activity;
import android.content.res.TypedArray;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
import com.slidingmenu.lib.R; import com.slidingmenu.lib.R;
@ -17,21 +16,40 @@ public class SlidingActivityHelper {
private Activity mActivity; private Activity mActivity;
private SlidingMenu mSlidingMenu; private SlidingMenu mSlidingMenu;
private View mViewAbove; private View mViewAbove;
private View mViewBehind; private View mViewBehind;
private boolean mBroadcasting = false; private boolean mBroadcasting = false;
private boolean mOnPostCreateCalled = false; private boolean mOnPostCreateCalled = false;
private boolean mEnableSlide = true; private boolean mEnableSlide = true;
/**
* Instantiates a new SlidingActivityHelper.
*
* @param activity the associated activity
*/
public SlidingActivityHelper(Activity activity) { public SlidingActivityHelper(Activity activity) {
mActivity = 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) { public void onCreate(Bundle savedInstanceState) {
mSlidingMenu = (SlidingMenu) LayoutInflater.from(mActivity).inflate(R.layout.slidingmenumain, null); 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) { public void onPostCreate(Bundle savedInstanceState) {
if (mViewBehind == null || mViewAbove == null) { if (mViewBehind == null || mViewAbove == null) {
throw new IllegalStateException("Both setBehindContentView must be called " + throw new IllegalStateException("Both setBehindContentView must be called " +
@ -40,40 +58,52 @@ public class SlidingActivityHelper {
mOnPostCreateCalled = true; mOnPostCreateCalled = true;
// get the window background mSlidingMenu.attachToActivity(mActivity,
TypedArray a = mActivity.getTheme().obtainStyledAttributes(new int[] {android.R.attr.windowBackground}); mEnableSlide ? SlidingMenu.SLIDING_WINDOW : SlidingMenu.SLIDING_CONTENT);
int background = a.getResourceId(0, 0);
final boolean open;
if (mEnableSlide) { final boolean secondary;
// move everything into the SlidingMenu if (savedInstanceState != null) {
ViewGroup decor = (ViewGroup) mActivity.getWindow().getDecorView(); open = savedInstanceState.getBoolean("SlidingActivityHelper.open");
ViewGroup decorChild = (ViewGroup) decor.getChildAt(0); secondary = savedInstanceState.getBoolean("SlidingActivityHelper.secondary");
// save ActionBar themes that have transparent assets
decorChild.setBackgroundResource(background);
decor.removeView(decorChild);
mSlidingMenu.setContent(decorChild);
decor.addView(mSlidingMenu);
} else { } else {
// take the above view out of open = false;
ViewGroup parent = (ViewGroup) mViewAbove.getParent(); secondary = false;
if (parent != null) {
parent.removeView(mViewAbove);
}
// save people from having transparent backgrounds
if (mViewAbove.getBackground() == null) {
mViewAbove.setBackgroundResource(background);
}
mSlidingMenu.setContent(mViewAbove);
parent.addView(mSlidingMenu, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
} }
new Handler().post(new Runnable() {
public void run() {
if (open) {
if (secondary) {
mSlidingMenu.showSecondaryMenu(false);
} else {
mSlidingMenu.showMenu(false);
}
} 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) if (mOnPostCreateCalled)
throw new IllegalStateException("enableSlidingActionBar must be called in onCreate."); 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) { public View findViewById(int id) {
View v; View v;
if (mSlidingMenu != null) { if (mSlidingMenu != null) {
@ -84,44 +114,103 @@ public class SlidingActivityHelper {
return null; 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) { public void registerAboveContentView(View v, LayoutParams params) {
if (!mBroadcasting) if (!mBroadcasting)
mViewAbove = v; 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) { public void setContentView(View v) {
mBroadcasting = true; mBroadcasting = true;
mActivity.setContentView(v); 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); mSlidingMenu.setMenu(mViewBehind);
} }
/**
* Gets the SlidingMenu associated with this activity.
*
* @return the SlidingMenu associated with this activity.
*/
public SlidingMenu getSlidingMenu() { public SlidingMenu getSlidingMenu() {
return mSlidingMenu; return mSlidingMenu;
} }
/**
* Toggle the SlidingMenu. If it is open, it will be closed, and vice versa.
*/
public void toggle() { public void toggle() {
if (mSlidingMenu.isBehindShowing()) { mSlidingMenu.toggle();
showAbove();
} else {
showBehind();
}
} }
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) { public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && mSlidingMenu.isBehindShowing()) { if (keyCode == KeyEvent.KEYCODE_BACK && mSlidingMenu.isMenuShowing()) {
showAbove(); showContent();
return true; return true;
} }
return false; return false;

View File

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

View File

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

View File

@ -1,7 +1,151 @@
package com.slidingmenu.lib.app; package com.slidingmenu.lib.app;
import com.slidingmenu.lib.SlidingMenu;
import android.os.Bundle;
import android.preference.PreferenceActivity; 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);
}
} }