2
2
3
3
import java .lang .reflect .Method ;
4
4
5
+ import android .annotation .SuppressLint ;
5
6
import android .app .Activity ;
6
7
import android .content .Context ;
7
8
import android .content .res .TypedArray ;
11
12
import android .graphics .Point ;
12
13
import android .graphics .Rect ;
13
14
import android .graphics .drawable .Drawable ;
15
+ import android .os .Build ;
14
16
import android .os .Parcel ;
15
17
import android .os .Parcelable ;
16
18
import android .util .AttributeSet ;
17
19
import android .view .Display ;
18
20
import android .view .LayoutInflater ;
19
21
import android .view .View ;
20
22
import android .view .ViewGroup ;
23
+ import android .view .Window ;
21
24
import android .view .WindowManager ;
22
25
import android .widget .FrameLayout ;
23
26
import android .widget .RelativeLayout ;
@@ -28,6 +31,7 @@ public class SlidingMenu extends RelativeLayout {
28
31
29
32
public static final int SLIDING_WINDOW = 0 ;
30
33
public static final int SLIDING_CONTENT = 1 ;
34
+ private boolean mActionbarOverlay = false ;
31
35
32
36
/** Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe
33
37
* gesture on the screen's margin
@@ -160,7 +164,7 @@ public interface CanvasTransformer {
160
164
public SlidingMenu (Context context ) {
161
165
this (context , null );
162
166
}
163
-
167
+
164
168
/**
165
169
* Instantiates a new SlidingMenu and attach to Activity.
166
170
*
@@ -269,20 +273,38 @@ else if (widthBehind != -1)
269
273
ta .recycle ();
270
274
}
271
275
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
+ */
272
282
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 ) {
273
294
if (slideStyle != SLIDING_WINDOW && slideStyle != SLIDING_CONTENT )
274
295
throw new IllegalArgumentException ("slideStyle must be either SLIDING_WINDOW or SLIDING_CONTENT" );
275
296
276
297
if (getParent () != null )
277
298
throw new IllegalStateException ("This SlidingMenu appears to already be attached" );
278
-
299
+
279
300
// get the window background
280
301
TypedArray a = activity .getTheme ().obtainStyledAttributes (new int [] {android .R .attr .windowBackground });
281
302
int background = a .getResourceId (0 , 0 );
282
303
a .recycle ();
283
304
284
305
switch (slideStyle ) {
285
306
case SLIDING_WINDOW :
307
+ mActionbarOverlay = false ;
286
308
ViewGroup decor = (ViewGroup ) activity .getWindow ().getDecorView ();
287
309
ViewGroup decorChild = (ViewGroup ) decor .getChildAt (0 );
288
310
// save ActionBar themes that have transparent assets
@@ -292,17 +314,12 @@ public void attachToActivity(Activity activity, int slideStyle) {
292
314
decor .addView (this );
293
315
break ;
294
316
case SLIDING_CONTENT :
317
+ mActionbarOverlay = actionbarOverlay ;
295
318
// 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 );
304
321
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 ));
306
323
setContent (content );
307
324
// save people from having transparent backgrounds
308
325
if (content .getBackground () == null )
@@ -670,7 +687,7 @@ public void setTouchModeAbove(int i) {
670
687
}
671
688
mViewAbove .setTouchMode (i );
672
689
}
673
-
690
+
674
691
/**
675
692
* Controls whether the SlidingMenu can be opened with a swipe gesture.
676
693
* Options are {@link #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN},
@@ -867,12 +884,12 @@ public SavedState(Parcelable superState, int item) {
867
884
super (superState );
868
885
mItem = item ;
869
886
}
870
-
887
+
871
888
private SavedState (Parcel in ) {
872
889
super (in );
873
890
mItem = in .readInt ();
874
891
}
875
-
892
+
876
893
public int getItem () {
877
894
return mItem ;
878
895
}
@@ -921,13 +938,15 @@ protected void onRestoreInstanceState(Parcelable state) {
921
938
/* (non-Javadoc)
922
939
* @see android.view.ViewGroup#fitSystemWindows(android.graphics.Rect)
923
940
*/
941
+ @ SuppressLint ("NewApi" )
924
942
@ Override
925
943
protected boolean fitSystemWindows (Rect insets ) {
926
944
int leftPadding = insets .left ;
927
945
int rightPadding = insets .right ;
928
946
int topPadding = insets .top ;
929
947
int bottomPadding = insets .bottom ;
930
- setPadding (leftPadding , topPadding , rightPadding , bottomPadding );
948
+ if (!mActionbarOverlay )
949
+ setPadding (leftPadding , topPadding , rightPadding , bottomPadding );
931
950
return true ;
932
951
}
933
952
0 commit comments