-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathSlidingMenu.java
1030 lines (912 loc) · 28.4 KB
/
SlidingMenu.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.jeremyfeinstein.slidingmenu.lib;
import java.lang.reflect.Method;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import com.jeremyfeinstein.slidingmenu.lib.CustomViewAbove.OnPageChangeListener;
public class SlidingMenu extends RelativeLayout {
private static final String TAG = SlidingMenu.class.getSimpleName();
public static final int SLIDING_WINDOW = 0;
public static final int SLIDING_CONTENT = 1;
private boolean mActionbarOverlay = false;
/** Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe
* gesture on the screen's margin
*/
public static final int TOUCHMODE_MARGIN = 0;
/** Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe
* gesture anywhere on the screen
*/
public static final int TOUCHMODE_FULLSCREEN = 1;
/** Constant value for use with setTouchModeAbove(). Denies the SlidingMenu to be opened with a swipe
* gesture
*/
public static final int TOUCHMODE_NONE = 2;
/** Constant value for use with setMode(). Puts the menu to the left of the content.
*/
public static final int LEFT = 0;
/** Constant value for use with setMode(). Puts the menu to the right of the content.
*/
public static final int RIGHT = 1;
/** Constant value for use with setMode(). Puts menus to the left and right of the content.
*/
public static final int LEFT_RIGHT = 2;
private CustomViewAbove mViewAbove;
private CustomViewBehind mViewBehind;
private OnOpenListener mOpenListener;
private OnOpenListener mSecondaryOpenListener;
private OnCloseListener mCloseListener;
/**
* The listener interface for receiving onOpen events.
* The class that is interested in processing a onOpen
* event implements this interface, and the object created
* with that class is registered with a component using the
* component's <code>addOnOpenListener<code> method. When
* the onOpen event occurs, that object's appropriate
* method is invoked
*/
public interface OnOpenListener {
/**
* On open.
*/
public void onOpen();
}
/**
* The listener interface for receiving onOpened events.
* The class that is interested in processing a onOpened
* event implements this interface, and the object created
* with that class is registered with a component using the
* component's <code>addOnOpenedListener<code> method. When
* the onOpened event occurs, that object's appropriate
* method is invoked.
*
* @see OnOpenedEvent
*/
public interface OnOpenedListener {
/**
* On opened.
*/
public void onOpened();
}
/**
* The listener interface for receiving onClose events.
* The class that is interested in processing a onClose
* event implements this interface, and the object created
* with that class is registered with a component using the
* component's <code>addOnCloseListener<code> method. When
* the onClose event occurs, that object's appropriate
* method is invoked.
*
* @see OnCloseEvent
*/
public interface OnCloseListener {
/**
* On close.
*/
public void onClose();
}
/**
* The listener interface for receiving onClosed events.
* The class that is interested in processing a onClosed
* event implements this interface, and the object created
* with that class is registered with a component using the
* component's <code>addOnClosedListener<code> method. When
* the onClosed event occurs, that object's appropriate
* method is invoked.
*
* @see OnClosedEvent
*/
public interface OnClosedListener {
/**
* On closed.
*/
public void onClosed();
}
/**
* The Interface CanvasTransformer.
*/
public interface CanvasTransformer {
/**
* Transform canvas.
*
* @param canvas the canvas
* @param percentOpen the percent open
*/
public void transformCanvas(Canvas canvas, float percentOpen);
}
/**
* Instantiates a new SlidingMenu.
*
* @param context the associated Context
*/
public SlidingMenu(Context context) {
this(context, null);
}
/**
* Instantiates a new SlidingMenu and attach to Activity.
*
* @param activity the activity to attach slidingmenu
* @param slideStyle the slidingmenu style
*/
public SlidingMenu(Activity activity, int slideStyle) {
this(activity, null);
this.attachToActivity(activity, slideStyle);
}
/**
* Instantiates a new SlidingMenu.
*
* @param context the associated Context
* @param attrs the attrs
*/
public SlidingMenu(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
/**
* Instantiates a new SlidingMenu.
*
* @param context the associated Context
* @param attrs the attrs
* @param defStyle the def style
*/
public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
LayoutParams behindParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
mViewBehind = new CustomViewBehind(context);
addView(mViewBehind, behindParams);
LayoutParams aboveParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
mViewAbove = new CustomViewAbove(context);
addView(mViewAbove, aboveParams);
// register the CustomViewBehind with the CustomViewAbove
mViewAbove.setCustomViewBehind(mViewBehind);
mViewBehind.setCustomViewAbove(mViewAbove);
mViewAbove.setOnPageChangeListener(new OnPageChangeListener() {
public static final int POSITION_OPEN = 0;
public static final int POSITION_CLOSE = 1;
public static final int POSITION_SECONDARY_OPEN = 2;
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) { }
public void onPageSelected(int position) {
if (position == POSITION_OPEN && mOpenListener != null) {
mOpenListener.onOpen();
} else if (position == POSITION_CLOSE && mCloseListener != null) {
mCloseListener.onClose();
} else if (position == POSITION_SECONDARY_OPEN && mSecondaryOpenListener != null ) {
mSecondaryOpenListener.onOpen();
}
}
});
// now style everything!
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingMenu);
// set the above and behind views if defined in xml
int mode = ta.getInt(R.styleable.SlidingMenu_mode, LEFT);
setMode(mode);
int viewAbove = ta.getResourceId(R.styleable.SlidingMenu_viewAbove, -1);
if (viewAbove != -1) {
setContent(viewAbove);
} else {
setContent(new FrameLayout(context));
}
int viewBehind = ta.getResourceId(R.styleable.SlidingMenu_viewBehind, -1);
if (viewBehind != -1) {
setMenu(viewBehind);
} else {
setMenu(new FrameLayout(context));
}
int touchModeAbove = ta.getInt(R.styleable.SlidingMenu_touchModeAbove, TOUCHMODE_MARGIN);
setTouchModeAbove(touchModeAbove);
int touchModeBehind = ta.getInt(R.styleable.SlidingMenu_touchModeBehind, TOUCHMODE_MARGIN);
setTouchModeBehind(touchModeBehind);
int offsetBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindOffset, -1);
int widthBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindWidth, -1);
if (offsetBehind != -1 && widthBehind != -1)
throw new IllegalStateException("Cannot set both behindOffset and behindWidth for a SlidingMenu");
else if (offsetBehind != -1)
setBehindOffset(offsetBehind);
else if (widthBehind != -1)
setBehindWidth(widthBehind);
else
setBehindOffset(0);
float scrollOffsetBehind = ta.getFloat(R.styleable.SlidingMenu_behindScrollScale, 0.33f);
setBehindScrollScale(scrollOffsetBehind);
int shadowRes = ta.getResourceId(R.styleable.SlidingMenu_shadowDrawable, -1);
if (shadowRes != -1) {
setShadowDrawable(shadowRes);
}
int shadowWidth = (int) ta.getDimension(R.styleable.SlidingMenu_shadowWidth, 0);
setShadowWidth(shadowWidth);
boolean fadeEnabled = ta.getBoolean(R.styleable.SlidingMenu_fadeEnabled, true);
setFadeEnabled(fadeEnabled);
float fadeDeg = ta.getFloat(R.styleable.SlidingMenu_fadeDegree, 0.33f);
setFadeDegree(fadeDeg);
boolean selectorEnabled = ta.getBoolean(R.styleable.SlidingMenu_selectorEnabled, false);
setSelectorEnabled(selectorEnabled);
int selectorRes = ta.getResourceId(R.styleable.SlidingMenu_selectorDrawable, -1);
if (selectorRes != -1)
setSelectorDrawable(selectorRes);
ta.recycle();
}
/**
* Attaches the SlidingMenu to an entire Activity
*
* @param activity the Activity
* @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW
*/
public void attachToActivity(Activity activity, int slideStyle) {
attachToActivity(activity, slideStyle, false);
}
/**
* Attaches the SlidingMenu to an entire Activity
*
* @param activity the Activity
* @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW
* @param actionbarOverlay whether or not the ActionBar is overlaid
*/
public void attachToActivity(Activity activity, int slideStyle, boolean actionbarOverlay) {
if (slideStyle != SLIDING_WINDOW && slideStyle != SLIDING_CONTENT)
throw new IllegalArgumentException("slideStyle must be either SLIDING_WINDOW or SLIDING_CONTENT");
if (getParent() != null)
throw new IllegalStateException("This SlidingMenu appears to already be attached");
// get the window background
TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] {android.R.attr.windowBackground});
int background = a.getResourceId(0, 0);
a.recycle();
switch (slideStyle) {
case SLIDING_WINDOW:
mActionbarOverlay = false;
ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
// save ActionBar themes that have transparent assets
decorChild.setBackgroundResource(background);
decor.removeView(decorChild);
decor.addView(this);
setContent(decorChild);
break;
case SLIDING_CONTENT:
mActionbarOverlay = actionbarOverlay;
// take the above view out of
ViewGroup contentParent = (ViewGroup)activity.findViewById(android.R.id.content);
View content = contentParent.getChildAt(0);
contentParent.removeView(content);
contentParent.addView(this);
setContent(content);
// save people from having transparent backgrounds
if (content.getBackground() == null)
content.setBackgroundResource(background);
break;
}
}
/**
* Set the above view content from a layout resource. The resource will be inflated, adding all top-level views
* to the above view.
*
* @param res the new content
*/
public void setContent(int res) {
setContent(LayoutInflater.from(getContext()).inflate(res, null));
}
/**
* Set the above view content to the given View.
*
* @param view The desired content to display.
*/
public void setContent(View view) {
mViewAbove.setContent(view);
showContent();
}
/**
* Retrieves the current content.
* @return the current content
*/
public View getContent() {
return mViewAbove.getContent();
}
/**
* Set the behind view (menu) content from a layout resource. The resource will be inflated, adding all top-level views
* to the behind view.
*
* @param res the new content
*/
public void setMenu(int res) {
setMenu(LayoutInflater.from(getContext()).inflate(res, null));
}
/**
* Set the behind view (menu) content to the given View.
*
* @param view The desired content to display.
*/
public void setMenu(View v) {
mViewBehind.setContent(v);
}
/**
* Retrieves the main menu.
* @return the main menu
*/
public View getMenu() {
return mViewBehind.getContent();
}
/**
* Set the secondary behind view (right menu) content from a layout resource. The resource will be inflated, adding all top-level views
* to the behind view.
*
* @param res the new content
*/
public void setSecondaryMenu(int res) {
setSecondaryMenu(LayoutInflater.from(getContext()).inflate(res, null));
}
/**
* Set the secondary behind view (right menu) content to the given View.
*
* @param view The desired content to display.
*/
public void setSecondaryMenu(View v) {
mViewBehind.setSecondaryContent(v);
// mViewBehind.invalidate();
}
/**
* Retrieves the current secondary menu (right).
* @return the current menu
*/
public View getSecondaryMenu() {
return mViewBehind.getSecondaryContent();
}
/**
* Sets the sliding enabled.
*
* @param b true to enable sliding, false to disable it.
*/
public void setSlidingEnabled(boolean b) {
mViewAbove.setSlidingEnabled(b);
}
/**
* Checks if is sliding enabled.
*
* @return true, if is sliding enabled
*/
public boolean isSlidingEnabled() {
return mViewAbove.isSlidingEnabled();
}
/**
* Sets which side the SlidingMenu should appear on.
* @param mode must be either SlidingMenu.LEFT or SlidingMenu.RIGHT
*/
public void setMode(int mode) {
if (mode != LEFT && mode != RIGHT && mode != LEFT_RIGHT) {
throw new IllegalStateException("SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT");
}
mViewBehind.setMode(mode);
}
/**
* Returns the current side that the SlidingMenu is on.
* @return the current mode, either SlidingMenu.LEFT or SlidingMenu.RIGHT
*/
public int getMode() {
return mViewBehind.getMode();
}
/**
* Sets whether or not the SlidingMenu is in static mode (i.e. nothing is moving and everything is showing)
*
* @param b true to set static mode, false to disable static mode.
*/
public void setStatic(boolean b) {
if (b) {
setSlidingEnabled(false);
mViewAbove.setCustomViewBehind(null);
mViewAbove.setCurrentItem(1);
// mViewBehind.setCurrentItem(0);
} else {
mViewAbove.setCurrentItem(1);
// mViewBehind.setCurrentItem(1);
mViewAbove.setCustomViewBehind(mViewBehind);
setSlidingEnabled(true);
}
}
/**
* Opens the menu and shows the menu view.
*/
public void showMenu() {
showMenu(true);
}
/**
* Opens the menu and shows the menu view.
*
* @param animate true to animate the transition, false to ignore animation
*/
public void showMenu(boolean animate) {
mViewAbove.setCurrentItem(0, animate);
}
/**
* Opens the menu and shows the secondary menu view. Will default to the regular menu
* if there is only one.
*/
public void showSecondaryMenu() {
showSecondaryMenu(true);
}
/**
* Opens the menu and shows the secondary (right) menu view. Will default to the regular menu
* if there is only one.
*
* @param animate true to animate the transition, false to ignore animation
*/
public void showSecondaryMenu(boolean animate) {
mViewAbove.setCurrentItem(2, animate);
}
/**
* Closes the menu and shows the above view.
*/
public void showContent() {
showContent(true);
}
/**
* Closes the menu and shows the above view.
*
* @param animate true to animate the transition, false to ignore animation
*/
public void showContent(boolean animate) {
mViewAbove.setCurrentItem(1, animate);
}
/**
* Toggle the SlidingMenu. If it is open, it will be closed, and vice versa.
*/
public void toggle() {
toggle(true);
}
/**
* Toggle the SlidingMenu. If it is open, it will be closed, and vice versa.
*
* @param animate true to animate the transition, false to ignore animation
*/
public void toggle(boolean animate) {
if (isMenuShowing()) {
showContent(animate);
} else {
showMenu(animate);
}
}
/**
* Checks if is the behind view showing.
*
* @return Whether or not the behind view is showing
*/
public boolean isMenuShowing() {
return mViewAbove.getCurrentItem() == 0 || mViewAbove.getCurrentItem() == 2;
}
/**
* Checks if is the behind view showing.
*
* @return Whether or not the behind view is showing
*/
public boolean isSecondaryMenuShowing() {
return mViewAbove.getCurrentItem() == 2;
}
/**
* Gets the behind offset.
*
* @return The margin on the right of the screen that the behind view scrolls to
*/
public int getBehindOffset() {
return ((RelativeLayout.LayoutParams)mViewBehind.getLayoutParams()).rightMargin;
}
/**
* Sets the behind offset.
*
* @param i The margin, in pixels, on the right of the screen that the behind view scrolls to.
*/
public void setBehindOffset(int i) {
// RelativeLayout.LayoutParams params = ((RelativeLayout.LayoutParams)mViewBehind.getLayoutParams());
// int bottom = params.bottomMargin;
// int top = params.topMargin;
// int left = params.leftMargin;
// params.setMargins(left, top, i, bottom);
mViewBehind.setWidthOffset(i);
}
/**
* Sets the behind offset.
*
* @param resID The dimension resource id to be set as the behind offset.
* The menu, when open, will leave this width margin on the right of the screen.
*/
public void setBehindOffsetRes(int resID) {
int i = (int) getContext().getResources().getDimension(resID);
setBehindOffset(i);
}
/**
* Sets the above offset.
*
* @param i the new above offset, in pixels
*/
public void setAboveOffset(int i) {
mViewAbove.setAboveOffset(i);
}
/**
* Sets the above offset.
*
* @param resID The dimension resource id to be set as the above offset.
*/
public void setAboveOffsetRes(int resID) {
int i = (int) getContext().getResources().getDimension(resID);
setAboveOffset(i);
}
/**
* Sets the behind width.
*
* @param i The width the Sliding Menu will open to, in pixels
*/
@SuppressWarnings("deprecation")
public void setBehindWidth(int i) {
int width;
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
try {
Class<?> cls = Display.class;
Class<?>[] parameterTypes = {Point.class};
Point parameter = new Point();
Method method = cls.getMethod("getSize", parameterTypes);
method.invoke(display, parameter);
width = parameter.x;
} catch (Exception e) {
width = display.getWidth();
}
setBehindOffset(width-i);
}
/**
* Sets the behind width.
*
* @param res The dimension resource id to be set as the behind width offset.
* The menu, when open, will open this wide.
*/
public void setBehindWidthRes(int res) {
int i = (int) getContext().getResources().getDimension(res);
setBehindWidth(i);
}
/**
* Gets the behind scroll scale.
*
* @return The scale of the parallax scroll
*/
public float getBehindScrollScale() {
return mViewBehind.getScrollScale();
}
/**
* Gets the touch mode margin threshold
* @return the touch mode margin threshold
*/
public int getTouchmodeMarginThreshold() {
return mViewBehind.getMarginThreshold();
}
/**
* Set the touch mode margin threshold
* @param touchmodeMarginThreshold
*/
public void setTouchmodeMarginThreshold(int touchmodeMarginThreshold) {
mViewBehind.setMarginThreshold(touchmodeMarginThreshold);
}
/**
* Sets the behind scroll scale.
*
* @param f The scale of the parallax scroll (i.e. 1.0f scrolls 1 pixel for every
* 1 pixel that the above view scrolls and 0.0f scrolls 0 pixels)
*/
public void setBehindScrollScale(float f) {
if (f < 0 && f > 1)
throw new IllegalStateException("ScrollScale must be between 0 and 1");
mViewBehind.setScrollScale(f);
}
/**
* Sets the behind canvas transformer.
*
* @param t the new behind canvas transformer
*/
public void setBehindCanvasTransformer(CanvasTransformer t) {
mViewBehind.setCanvasTransformer(t);
}
/**
* Gets the touch mode above.
*
* @return the touch mode above
*/
public int getTouchModeAbove() {
return mViewAbove.getTouchMode();
}
/**
* Controls whether the SlidingMenu can be opened with a swipe gesture.
* Options are {@link #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN},
* or {@link #TOUCHMODE_NONE TOUCHMODE_NONE}
*
* @param i the new touch mode
*/
public void setTouchModeAbove(int i) {
if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN
&& i != TOUCHMODE_NONE) {
throw new IllegalStateException("TouchMode must be set to either" +
"TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE.");
}
mViewAbove.setTouchMode(i);
}
/**
* Controls whether the SlidingMenu can be opened with a swipe gesture.
* Options are {@link #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN},
* or {@link #TOUCHMODE_NONE TOUCHMODE_NONE}
*
* @param i the new touch mode
*/
public void setTouchModeBehind(int i) {
if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN
&& i != TOUCHMODE_NONE) {
throw new IllegalStateException("TouchMode must be set to either" +
"TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE.");
}
mViewBehind.setTouchMode(i);
}
/**
* Sets the shadow drawable.
*
* @param resId the resource ID of the new shadow drawable
*/
public void setShadowDrawable(int resId) {
setShadowDrawable(getContext().getResources().getDrawable(resId));
}
/**
* Sets the shadow drawable.
*
* @param d the new shadow drawable
*/
public void setShadowDrawable(Drawable d) {
mViewBehind.setShadowDrawable(d);
}
/**
* Sets the secondary (right) shadow drawable.
*
* @param resId the resource ID of the new shadow drawable
*/
public void setSecondaryShadowDrawable(int resId) {
setSecondaryShadowDrawable(getContext().getResources().getDrawable(resId));
}
/**
* Sets the secondary (right) shadow drawable.
*
* @param d the new shadow drawable
*/
public void setSecondaryShadowDrawable(Drawable d) {
mViewBehind.setSecondaryShadowDrawable(d);
}
/**
* Sets the shadow width.
*
* @param resId The dimension resource id to be set as the shadow width.
*/
public void setShadowWidthRes(int resId) {
setShadowWidth((int)getResources().getDimension(resId));
}
/**
* Sets the shadow width.
*
* @param pixels the new shadow width, in pixels
*/
public void setShadowWidth(int pixels) {
mViewBehind.setShadowWidth(pixels);
}
/**
* Enables or disables the SlidingMenu's fade in and out
*
* @param b true to enable fade, false to disable it
*/
public void setFadeEnabled(boolean b) {
mViewBehind.setFadeEnabled(b);
}
/**
* Sets how much the SlidingMenu fades in and out. Fade must be enabled, see
* {@link #setFadeEnabled(boolean) setFadeEnabled(boolean)}
*
* @param f the new fade degree, between 0.0f and 1.0f
*/
public void setFadeDegree(float f) {
mViewBehind.setFadeDegree(f);
}
/**
* Enables or disables whether the selector is drawn
*
* @param b true to draw the selector, false to not draw the selector
*/
public void setSelectorEnabled(boolean b) {
mViewBehind.setSelectorEnabled(true);
}
/**
* Sets the selected view. The selector will be drawn here
*
* @param v the new selected view
*/
public void setSelectedView(View v) {
mViewBehind.setSelectedView(v);
}
/**
* Sets the selector drawable.
*
* @param res a resource ID for the selector drawable
*/
public void setSelectorDrawable(int res) {
mViewBehind.setSelectorBitmap(BitmapFactory.decodeResource(getResources(), res));
}
/**
* Sets the selector drawable.
*
* @param b the new selector bitmap
*/
public void setSelectorBitmap(Bitmap b) {
mViewBehind.setSelectorBitmap(b);
}
/**
* Add a View ignored by the Touch Down event when mode is Fullscreen
*
* @param v a view to be ignored
*/
public void addIgnoredView(View v) {
mViewAbove.addIgnoredView(v);
}
/**
* Remove a View ignored by the Touch Down event when mode is Fullscreen
*
* @param v a view not wanted to be ignored anymore
*/
public void removeIgnoredView(View v) {
mViewAbove.removeIgnoredView(v);
}
/**
* Clear the list of Views ignored by the Touch Down event when mode is Fullscreen
*/
public void clearIgnoredViews() {
mViewAbove.clearIgnoredViews();
}
/**
* Sets the OnOpenListener. {@link OnOpenListener#onOpen() OnOpenListener.onOpen()} will be called when the SlidingMenu is opened
*
* @param listener the new OnOpenListener
*/
public void setOnOpenListener(OnOpenListener listener) {
//mViewAbove.setOnOpenListener(listener);
mOpenListener = listener;
}
/**
* Sets the OnOpenListener for the secondary menu. {@link OnOpenListener#onOpen() OnOpenListener.onOpen()} will be called when the secondary SlidingMenu is opened
*
* @param listener the new OnOpenListener
*/
public void setSecondaryOnOpenListener(OnOpenListener listener) {
mSecondaryOpenListener = listener;
}
/**
* Sets the OnOpenListener for the secondary menu. {@link OnOpenListener#onOpen() OnOpenListener.onOpen()} will be called when the secondary SlidingMenu is opened
*
* @param listener the new OnOpenListener
* @deprecated Use {@link #setSecondaryOnOpenListener} instead.
*/
@Deprecated
public void setSecondaryOnOpenListner(OnOpenListener listener) {
mSecondaryOpenListener = listener;
}
/**
* Sets the OnCloseListener. {@link OnCloseListener#onClose() OnCloseListener.onClose()} will be called when any one of the SlidingMenu is closed
*
* @param listener the new setOnCloseListener
*/
public void setOnCloseListener(OnCloseListener listener) {
//mViewAbove.setOnCloseListener(listener);
mCloseListener = listener;
}
/**
* Sets the OnOpenedListener. {@link OnOpenedListener#onOpened() OnOpenedListener.onOpened()} will be called after the SlidingMenu is opened
*
* @param listener the new OnOpenedListener
*/
public void setOnOpenedListener(OnOpenedListener listener) {
mViewAbove.setOnOpenedListener(listener);
}
/**
* Sets the OnClosedListener. {@link OnClosedListener#onClosed() OnClosedListener.onClosed()} will be called after the SlidingMenu is closed
*
* @param listener the new OnClosedListener
*/
public void setOnClosedListener(OnClosedListener listener) {
mViewAbove.setOnClosedListener(listener);
}
public static class SavedState extends BaseSavedState {
private final int mItem;
public SavedState(Parcelable superState, int item) {
super(superState);
mItem = item;
}
private SavedState(Parcel in) {
super(in);
mItem = in.readInt();
}
public int getItem() {
return mItem;
}
/* (non-Javadoc)
* @see android.view.AbsSavedState#writeToParcel(android.os.Parcel, int)
*/
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeInt(mItem);
}
public static final Parcelable.Creator<SavedState> CREATOR =
new Parcelable.Creator<SavedState>() {
public SavedState createFromParcel(Parcel in) {
return new SavedState(in);
}
public SavedState[] newArray(int size) {
return new SavedState[size];
}
};
}
/* (non-Javadoc)
* @see android.view.View#onSaveInstanceState()
*/
@Override
protected Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState();
SavedState ss = new SavedState(superState, mViewAbove.getCurrentItem());
return ss;
}
/* (non-Javadoc)
* @see android.view.View#onRestoreInstanceState(android.os.Parcelable)
*/
@Override
protected void onRestoreInstanceState(Parcelable state) {
SavedState ss = (SavedState)state;
super.onRestoreInstanceState(ss.getSuperState());
mViewAbove.setCurrentItem(ss.getItem());
}
/* (non-Javadoc)
* @see android.view.ViewGroup#fitSystemWindows(android.graphics.Rect)
*/
@SuppressLint("NewApi")
@Override
protected boolean fitSystemWindows(Rect insets) {
int leftPadding = insets.left;
int rightPadding = insets.right;
int topPadding = insets.top;