1
1
package com .slidingmenu .lib ;
2
2
3
+ import com .slidingmenu .lib .CustomViewAbove .OnPageChangeListener ;
4
+
3
5
import android .annotation .SuppressLint ;
4
6
import android .content .Context ;
5
7
import android .content .res .TypedArray ;
@@ -22,6 +24,17 @@ public class SlidingMenu extends RelativeLayout {
22
24
23
25
private CustomViewAbove mViewAbove ;
24
26
private CustomViewBehind mViewBehind ;
27
+
28
+ private OnOpenListener mOpenListener ;
29
+ private OnCloseListener mCloseListener ;
30
+
31
+ public interface OnOpenListener {
32
+ public void onOpen ();
33
+ }
34
+
35
+ public interface OnCloseListener {
36
+ public void onClose ();
37
+ }
25
38
26
39
public SlidingMenu (Context context ) {
27
40
this (context , null );
@@ -42,6 +55,18 @@ public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
42
55
addView (mViewAbove , aboveParams );
43
56
// register the CustomViewBehind2 with the CustomViewAbove
44
57
mViewAbove .setCustomViewBehind2 (mViewBehind );
58
+ mViewAbove .setOnPageChangeListener (new OnPageChangeListener () {
59
+ public void onPageScrolled (int position , float positionOffset ,
60
+ int positionOffsetPixels ) { }
61
+ public void onPageScrollStateChanged (int state ) { }
62
+ public void onPageSelected (int position ) {
63
+ if (position == 0 && mOpenListener != null ) {
64
+ mOpenListener .onOpen ();
65
+ } else if (position == 1 && mCloseListener != null ) {
66
+ mCloseListener .onClose ();
67
+ }
68
+ }
69
+ });
45
70
46
71
// now style everything!
47
72
TypedArray ta = context .obtainStyledAttributes (attrs , R .styleable .SlidingMenu );
@@ -236,6 +261,14 @@ public void setFadeEnabled(boolean b) {
236
261
public void setFadeDegree (float f ) {
237
262
mViewAbove .setBehindFadeDegree (f );
238
263
}
264
+
265
+ public void setOnOpenListener (OnOpenListener listener ) {
266
+ mOpenListener = listener ;
267
+ }
268
+
269
+ public void setOnCloseListener (OnCloseListener listener ) {
270
+ mCloseListener = listener ;
271
+ }
239
272
240
273
public static class SavedState extends BaseSavedState {
241
274
boolean mBehindShowing ;
0 commit comments