Skip to content

Commit 60028d2

Browse files
author
jfeinstein10
committed
Moving away from ABS dependency
1 parent 7886f39 commit 60028d2

File tree

7 files changed

+94
-423
lines changed

7 files changed

+94
-423
lines changed

library/src/com/slidingmenu/lib/CustomViewAbove.java

Lines changed: 31 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
import android.content.res.TypedArray;
88
import android.database.DataSetObserver;
99
import android.graphics.Canvas;
10+
import android.graphics.Color;
11+
import android.graphics.Paint;
1012
import android.graphics.Rect;
1113
import android.graphics.drawable.Drawable;
1214
import android.os.Build;
13-
import android.os.Parcel;
14-
import android.os.Parcelable;
15-
import android.support.v4.os.ParcelableCompat;
16-
import android.support.v4.os.ParcelableCompatCreatorCallbacks;
1715
import android.support.v4.view.KeyEventCompat;
1816
import android.support.v4.view.MotionEventCompat;
1917
import android.support.v4.view.VelocityTrackerCompat;
@@ -24,7 +22,6 @@
2422
import android.view.FocusFinder;
2523
import android.view.Gravity;
2624
import android.view.KeyEvent;
27-
import android.view.LayoutInflater;
2825
import android.view.MotionEvent;
2926
import android.view.SoundEffectConstants;
3027
import android.view.VelocityTracker;
@@ -34,7 +31,6 @@
3431
import android.view.ViewParent;
3532
import android.view.accessibility.AccessibilityEvent;
3633
import android.view.animation.Interpolator;
37-
import android.widget.ImageView;
3834
import android.widget.LinearLayout;
3935
import android.widget.Scroller;
4036

@@ -647,82 +643,6 @@ void populate() {
647643
}
648644
}
649645

650-
/**
651-
* This is the persistent state that is saved by CustomViewPager. Only needed
652-
* if you are creating a sublass of CustomViewPager that must save its own
653-
* state, in which case it should implement a subclass of this which
654-
* contains that state.
655-
*/
656-
// public static class SavedState extends BaseSavedState {
657-
// int position;
658-
// Parcelable adapterState;
659-
// ClassLoader loader;
660-
//
661-
// public SavedState(Parcelable superState) {
662-
// super(superState);
663-
// }
664-
//
665-
//
666-
// public void writeToParcel(Parcel out, int flags) {
667-
// super.writeToParcel(out, flags);
668-
// out.writeInt(position);
669-
// out.writeParcelable(adapterState, flags);
670-
// }
671-
//
672-
//
673-
// public String toString() {
674-
// return "FragmentPager.SavedState{"
675-
// + Integer.toHexString(System.identityHashCode(this))
676-
// + " position=" + position + "}";
677-
// }
678-
//
679-
// public static final Parcelable.Creator<SavedState> CREATOR
680-
// = ParcelableCompat.newCreator(new ParcelableCompatCreatorCallbacks<SavedState>() {
681-
//
682-
// public SavedState createFromParcel(Parcel in, ClassLoader loader) {
683-
// return new SavedState(in, loader);
684-
// }
685-
//
686-
// public SavedState[] newArray(int size) {
687-
// return new SavedState[size];
688-
// }
689-
// });
690-
//
691-
// SavedState(Parcel in, ClassLoader loader) {
692-
// super(in);
693-
// if (loader == null) {
694-
// loader = getClass().getClassLoader();
695-
// }
696-
// position = in.readInt();
697-
// adapterState = in.readParcelable(loader);
698-
// this.loader = loader;
699-
// }
700-
// }
701-
//
702-
//
703-
// public Parcelable onSaveInstanceState() {
704-
// Parcelable superState = super.onSaveInstanceState();
705-
// SavedState ss = new SavedState(superState);
706-
// ss.position = mCurItem;
707-
// return ss;
708-
// }
709-
//
710-
//
711-
// public void onRestoreInstanceState(Parcelable state) {
712-
// if (!(state instanceof SavedState)) {
713-
// super.onRestoreInstanceState(state);
714-
// return;
715-
// }
716-
//
717-
// SavedState ss = (SavedState)state;
718-
// super.onRestoreInstanceState(ss.getSuperState());
719-
//
720-
// setCurrentItemInternal(ss.position, false, true);
721-
// mRestoredCurItem = ss.position;
722-
// mRestoredAdapterState = ss.adapterState;
723-
// mRestoredClassLoader = ss.loader;
724-
// }
725-
726646
protected void setMenu(View v) {
727647
ItemInfo ii = new ItemInfo();
728648
ii.position = 0;
@@ -878,10 +798,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
878798
}
879799
}
880800

881-
882801
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
883802
super.onSizeChanged(w, h, oldw, oldh);
884-
885803
// Make sure scroll position is set correctly.
886804
if (w != oldw) {
887805
recomputeScrollPosition(w, oldw, mShadowWidth, mShadowWidth);
@@ -911,7 +829,6 @@ private void recomputeScrollPosition(int width, int oldWidth, int margin, int ol
911829
}
912830
}
913831

914-
915832
protected void onLayout(boolean changed, int l, int t, int r, int b) {
916833
mInLayout = true;
917834
populate();
@@ -1386,14 +1303,41 @@ private int determineTargetPage(int currentPage, float pageOffset, int velocity,
13861303

13871304
protected void onDraw(Canvas canvas) {
13881305
super.onDraw(canvas);
1306+
final int behindWidth = getBehindWidth();
13891307
// Draw the margin drawable if needed.
13901308
if (mShadowWidth > 0 && mShadowDrawable != null) {
1391-
final int left = this.getBehindWidth() - mShadowWidth;
1309+
final int left = behindWidth - mShadowWidth;
13921310
mShadowDrawable.setBounds(left, mTopPageBounds, left + mShadowWidth,
13931311
mBottomPageBounds);
13941312
mShadowDrawable.draw(canvas);
13951313
}
1396-
}
1314+
1315+
if (mFadeEnabled) {
1316+
final float openPercent = (mScroller.getCurrX()) / (float) behindWidth;
1317+
onDrawBehindFade(canvas, openPercent, behindWidth);
1318+
}
1319+
}
1320+
1321+
private float mFadeDegree;
1322+
private Paint mBehindFadePaint = new Paint();
1323+
private boolean mFadeEnabled;
1324+
1325+
private void onDrawBehindFade(Canvas canvas, float openPercent, int width) {
1326+
final int alpha = (int) (mFadeDegree * 255 * openPercent);
1327+
1328+
if (alpha > 0) {
1329+
mBehindFadePaint.setColor(Color.argb(alpha, 0, 0, 0));
1330+
canvas.drawRect(0, 0, width, getHeight(), mBehindFadePaint);
1331+
}
1332+
}
1333+
1334+
public void setBehindFadeEnabled(boolean b) {
1335+
mFadeEnabled = b;
1336+
}
1337+
1338+
public void setBehindFadeDegree(float f) {
1339+
mFadeDegree = f;
1340+
}
13971341

13981342
private void onSecondaryPointerUp(MotionEvent ev) {
13991343
final int pointerIndex = MotionEventCompat.getActionIndex(ev);

library/src/com/slidingmenu/lib/MenuScreen.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

library/src/com/slidingmenu/lib/SlidingMenu.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,18 @@ public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
6060
// set the offset and scroll scale if defined in xml
6161
int offsetBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindOffset, 0);
6262
setBehindOffset(offsetBehind);
63-
float scrollOffsetBehind = ta.getFloat(R.styleable.SlidingMenu_behindScrollScale, 0.0f);
63+
float scrollOffsetBehind = ta.getFloat(R.styleable.SlidingMenu_behindScrollScale, 0.25f);
6464
setBehindScrollScale(scrollOffsetBehind);
6565
int shadowRes = ta.getResourceId(R.styleable.SlidingMenu_shadowDrawable, -1);
6666
if (shadowRes != -1) {
6767
setShadowDrawable(shadowRes);
6868
}
6969
int shadowWidth = (int) ta.getDimension(R.styleable.SlidingMenu_shadowWidth, 0);
7070
setShadowWidth(shadowWidth);
71-
71+
boolean fadeEnabled = ta.getBoolean(R.styleable.SlidingMenu_behindFadeEnabled, true);
72+
setFadeEnabled(fadeEnabled);
73+
float fadeDeg = ta.getFloat(R.styleable.SlidingMenu_behindFadeDegree, 0.5f);
74+
setFadeDegree(fadeDeg);
7275
showAbove();
7376
}
7477

@@ -219,6 +222,14 @@ public void setShadowWidthRes(int resId) {
219222
public void setShadowWidth(int pixels) {
220223
mViewAbove.setShadowWidth(pixels);
221224
}
225+
226+
public void setFadeEnabled(boolean b) {
227+
mViewAbove.setBehindFadeEnabled(b);
228+
}
229+
230+
public void setFadeDegree(float f) {
231+
mViewAbove.setBehindFadeDegree(f);
232+
}
222233

223234
public static class SavedState extends BaseSavedState {
224235
boolean mBehindShowing;

library/src/com/slidingmenu/lib/app/SlidingActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public void onPostCreate(Bundle savedInstanceState) {
2222
super.onPostCreate(savedInstanceState);
2323
mHelper.onPostCreate(savedInstanceState);
2424
}
25+
26+
public View findViewById(int id) {
27+
return mHelper.findViewById(id);
28+
}
2529

2630
public void setBehindContentView(int id) {
2731
setBehindContentView(getLayoutInflater().inflate(id, null));

library/src/com/slidingmenu/lib/app/SlidingActivityHelper.java

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.slidingmenu.lib.app;
22

3+
import android.annotation.TargetApi;
34
import android.app.Activity;
4-
import android.content.res.Resources;
5-
import android.os.Build;
65
import android.os.Bundle;
76
import android.view.KeyEvent;
87
import android.view.LayoutInflater;
98
import android.view.View;
109
import android.view.ViewGroup;
1110
import android.view.ViewGroup.LayoutParams;
11+
import android.widget.LinearLayout;
1212
import android.widget.ListView;
1313
import android.widget.RelativeLayout;
1414

@@ -20,58 +20,48 @@ public class SlidingActivityHelper {
2020
private Activity mActivity;
2121

2222
private SlidingMenu mSlidingMenu;
23-
private ViewGroup mContentView;
24-
private boolean mBehindContentViewCalled = false;
25-
23+
24+
private boolean mViewBehindSet = false;
25+
2626
public SlidingActivityHelper(Activity activity) {
2727
mActivity = activity;
2828
}
2929

3030
public void onCreate(Bundle savedInstanceState) {
31-
32-
mContentView = new RelativeLayout(mActivity);
33-
// if (Build.VERSION.SDK_INT < 11) {
34-
// unregister the current content view
35-
mActivity.getWindow().getDecorView().findViewById(android.R.id.content).setId(View.NO_ID);
36-
// register a new content view
37-
mContentView.setId(android.R.id.content);
38-
// } else {
39-
// int content = Resources.getSystem().getIdentifier("content", "id", "android");
40-
// int c2 = android.R.id.content;
41-
// // unregister the current content view
42-
// mActivity.getWindow().getDecorView().findViewById(content).setId(View.NO_ID);
43-
// // register a new content view
44-
// mContentView.setId(content);
45-
// }
46-
47-
// customize based on type of Activity
48-
if (mActivity instanceof SlidingListActivity) {
49-
ListView lv = new ListView(mActivity);
50-
lv.setId(android.R.id.list);
51-
mContentView.addView(lv, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
52-
}
53-
54-
// set up the SlidingMenu
55-
mSlidingMenu = (SlidingMenu) LayoutInflater.from(mActivity).inflate(R.layout.slidingmenumain, null);
56-
mSlidingMenu.setViewAbove(mContentView);
57-
mSlidingMenu.setBackgroundDrawable(mActivity.getWindow().getDecorView().getBackground());
58-
mActivity.getWindow().setContentView(mSlidingMenu);
31+
mSlidingMenu = new SlidingMenu(mActivity);
5932
}
6033

6134
public void onPostCreate(Bundle savedInstanceState) {
62-
if (!mBehindContentViewCalled) {
35+
if (!mViewBehindSet) {
6336
throw new IllegalStateException("Both setBehindContentView must be called " +
6437
"in onCreate in addition to setContentView.");
6538
}
39+
ViewGroup decor = (ViewGroup) mActivity.getWindow().getDecorView();
40+
LinearLayout newDecor = new LinearLayout(mActivity);
41+
while (decor.getChildCount() > 0) {
42+
View child = decor.getChildAt(0);
43+
decor.removeView(child);
44+
newDecor.addView(child);
45+
}
46+
decor.addView(mSlidingMenu, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
47+
mSlidingMenu.setViewAbove(newDecor);
48+
}
49+
50+
public View findViewById(int id) {
51+
View v;
52+
if (mSlidingMenu != null) {
53+
v = mSlidingMenu.findViewById(id);
54+
if (v != null)
55+
return v;
56+
}
57+
return mActivity.findViewById(id);
6658
}
6759

6860
public void setBehindContentView(View v, LayoutParams params) {
69-
if (!mBehindContentViewCalled) {
70-
mBehindContentViewCalled = true;
71-
}
7261
mSlidingMenu.setViewBehind(v);
62+
mViewBehindSet = true;
7363
}
74-
64+
7565
public SlidingMenu getSlidingMenu() {
7666
return mSlidingMenu;
7767
}

0 commit comments

Comments
 (0)