Skip to content

Commit 4a53fb1

Browse files
author
jfeinstein10
committed
Fixing attach for overlays
1 parent 10f123b commit 4a53fb1

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

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

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.lang.reflect.Method;
44

5+
import android.annotation.SuppressLint;
56
import android.app.Activity;
67
import android.content.Context;
78
import android.content.res.TypedArray;
@@ -11,13 +12,15 @@
1112
import android.graphics.Point;
1213
import android.graphics.Rect;
1314
import android.graphics.drawable.Drawable;
15+
import android.os.Build;
1416
import android.os.Parcel;
1517
import android.os.Parcelable;
1618
import android.util.AttributeSet;
1719
import android.view.Display;
1820
import android.view.LayoutInflater;
1921
import android.view.View;
2022
import android.view.ViewGroup;
23+
import android.view.Window;
2124
import android.view.WindowManager;
2225
import android.widget.FrameLayout;
2326
import android.widget.RelativeLayout;
@@ -28,6 +31,7 @@ public class SlidingMenu extends RelativeLayout {
2831

2932
public static final int SLIDING_WINDOW = 0;
3033
public static final int SLIDING_CONTENT = 1;
34+
private boolean mActionbarOverlay = false;
3135

3236
/** Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe
3337
* gesture on the screen's margin
@@ -160,7 +164,7 @@ public interface CanvasTransformer {
160164
public SlidingMenu(Context context) {
161165
this(context, null);
162166
}
163-
167+
164168
/**
165169
* Instantiates a new SlidingMenu and attach to Activity.
166170
*
@@ -269,20 +273,38 @@ else if (widthBehind != -1)
269273
ta.recycle();
270274
}
271275

276+
/**
277+
* Attaches the SlidingMenu to an entire Activity
278+
*
279+
* @param activity the Activity
280+
* @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW
281+
*/
272282
public void attachToActivity(Activity activity, int slideStyle) {
283+
attachToActivity(activity, slideStyle, false);
284+
}
285+
286+
/**
287+
* Attaches the SlidingMenu to an entire Activity
288+
*
289+
* @param activity the Activity
290+
* @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW
291+
* @param actionbarOverlay whether or not the ActionBar is overlaid
292+
*/
293+
public void attachToActivity(Activity activity, int slideStyle, boolean actionbarOverlay) {
273294
if (slideStyle != SLIDING_WINDOW && slideStyle != SLIDING_CONTENT)
274295
throw new IllegalArgumentException("slideStyle must be either SLIDING_WINDOW or SLIDING_CONTENT");
275296

276297
if (getParent() != null)
277298
throw new IllegalStateException("This SlidingMenu appears to already be attached");
278-
299+
279300
// get the window background
280301
TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] {android.R.attr.windowBackground});
281302
int background = a.getResourceId(0, 0);
282303
a.recycle();
283304

284305
switch (slideStyle) {
285306
case SLIDING_WINDOW:
307+
mActionbarOverlay = false;
286308
ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
287309
ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
288310
// save ActionBar themes that have transparent assets
@@ -292,17 +314,12 @@ public void attachToActivity(Activity activity, int slideStyle) {
292314
decor.addView(this);
293315
break;
294316
case SLIDING_CONTENT:
317+
mActionbarOverlay = actionbarOverlay;
295318
// take the above view out of
296-
ViewGroup content = (ViewGroup) activity.findViewById(android.R.id.content);
297-
ViewGroup contentParent = (ViewGroup) content.getParent();
298-
int index = 0;
299-
for (int i = 0; i < contentParent.getChildCount(); i++)
300-
if (contentParent.getChildAt(i) == content) {
301-
index = i;
302-
break;
303-
}
319+
ViewGroup contentParent = (ViewGroup)activity.findViewById(android.R.id.content);
320+
View content = contentParent.getChildAt(0);
304321
contentParent.removeView(content);
305-
contentParent.addView(this, index, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
322+
contentParent.addView(this, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
306323
setContent(content);
307324
// save people from having transparent backgrounds
308325
if (content.getBackground() == null)
@@ -670,7 +687,7 @@ public void setTouchModeAbove(int i) {
670687
}
671688
mViewAbove.setTouchMode(i);
672689
}
673-
690+
674691
/**
675692
* Controls whether the SlidingMenu can be opened with a swipe gesture.
676693
* Options are {@link #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN},
@@ -867,12 +884,12 @@ public SavedState(Parcelable superState, int item) {
867884
super(superState);
868885
mItem = item;
869886
}
870-
887+
871888
private SavedState(Parcel in) {
872889
super(in);
873890
mItem = in.readInt();
874891
}
875-
892+
876893
public int getItem() {
877894
return mItem;
878895
}
@@ -921,13 +938,15 @@ protected void onRestoreInstanceState(Parcelable state) {
921938
/* (non-Javadoc)
922939
* @see android.view.ViewGroup#fitSystemWindows(android.graphics.Rect)
923940
*/
941+
@SuppressLint("NewApi")
924942
@Override
925943
protected boolean fitSystemWindows(Rect insets) {
926944
int leftPadding = insets.left;
927945
int rightPadding = insets.right;
928946
int topPadding = insets.top;
929947
int bottomPadding = insets.bottom;
930-
setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
948+
if (!mActionbarOverlay)
949+
setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
931950
return true;
932951
}
933952

0 commit comments

Comments
 (0)