1
1
package com .slidingmenu .lib ;
2
2
3
3
import android .content .Context ;
4
+ import android .content .res .TypedArray ;
4
5
import android .util .AttributeSet ;
6
+ import android .view .LayoutInflater ;
5
7
import android .view .View ;
6
8
import android .view .ViewGroup ;
7
9
import android .widget .RelativeLayout ;
@@ -28,35 +30,29 @@ public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
28
30
LayoutParams aboveParams = new LayoutParams (LayoutParams .FILL_PARENT , LayoutParams .FILL_PARENT );
29
31
mViewAbove = new CustomViewAbove (context );
30
32
addView (mViewAbove , aboveParams );
33
+ // register the CustomViewBehind with the CustomViewAbove
31
34
mViewAbove .setCustomViewBehind (mViewBehind );
32
35
33
- // if (mViewAbove == null || mViewBehind == null) {
34
- // throw new IllegalStateException("id slidingmenuabove and slidingmenubehind must" +
35
- // " be declared within a SlidingMenu");
36
- // }
37
- //
38
- // // register the CustomViewBehind with the CustomViewAbove
39
- // mViewAbove.setCustomViewBehind(mViewBehind);
40
- //
41
- // // now style everything!
42
- // TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingMenu);
43
- // // set the above and behind views if defined in xml
44
- // int viewAbove = ta.getResourceId(R.styleable.SlidingMenu_viewAbove, -1);
45
- // if (viewAbove != -1) {
46
- // LayoutInflater inflater = (LayoutInflater)
47
- // context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
48
- // mViewAbove.setContent(inflater.inflate(viewAbove, this), null);
49
- // }
50
- // int viewBehind = ta.getResourceId(R.styleable.SlidingMenu_viewBehind, -1);
51
- // if (viewBehind != -1) {
52
- // LayoutInflater inflater = (LayoutInflater)
53
- // context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
54
- // mViewBehind.setContent(inflater.inflate(viewBehind, this));
55
- // }
56
- // float offsetBehind = ta.getFloat(R.styleable.SlidingMenu_offsetBehind, 0f);
57
- // setBehindOffset((int) offsetBehind);
58
- // float scrollOffsetBehind = ta.getFloat(R.styleable.SlidingMenu_scrollOffsetBehind, 0f);
59
- // mViewBehind.setScrollScale(scrollOffsetBehind);
36
+ // now style everything!
37
+ TypedArray ta = context .obtainStyledAttributes (attrs , R .styleable .SlidingMenu );
38
+ // set the above and behind views if defined in xml
39
+ int viewAbove = ta .getResourceId (R .styleable .SlidingMenu_viewAbove , -1 );
40
+ if (viewAbove != -1 ) {
41
+ LayoutInflater inflater = (LayoutInflater )
42
+ context .getSystemService (Context .LAYOUT_INFLATER_SERVICE );
43
+ setAboveView (inflater .inflate (viewAbove , this ), null );
44
+ }
45
+ int viewBehind = ta .getResourceId (R .styleable .SlidingMenu_viewBehind , -1 );
46
+ if (viewBehind != -1 ) {
47
+ LayoutInflater inflater = (LayoutInflater )
48
+ context .getSystemService (Context .LAYOUT_INFLATER_SERVICE );
49
+ setBehindView (inflater .inflate (viewBehind , null ));
50
+ }
51
+ // set the offset and scroll scale if defined in xml
52
+ int offsetBehind = ta .getInt (R .styleable .SlidingMenu_behindOffset , 0 );
53
+ setBehindOffset (offsetBehind );
54
+ float scrollOffsetBehind = ta .getFloat (R .styleable .SlidingMenu_behindScrollScale , 0.0f );
55
+ setBehindScrollScale (scrollOffsetBehind );
60
56
}
61
57
62
58
public void registerViews (CustomViewAbove va , CustomViewBehind vb ) {
@@ -65,17 +61,13 @@ public void registerViews(CustomViewAbove va, CustomViewBehind vb) {
65
61
mViewAbove .setCustomViewBehind (mViewBehind );
66
62
}
67
63
68
- public void onMeasure (int widthSpec , int heightSpec ) {
69
- super .onMeasure (widthSpec , heightSpec );
70
- }
71
-
72
- public void setAboveContent (View v , ViewGroup .LayoutParams p ) {
64
+ public void setAboveView (View v , ViewGroup .LayoutParams p ) {
73
65
mViewAbove .setContent (v , p );
74
66
mViewAbove .invalidate ();
75
67
mViewAbove .dataSetChanged ();
76
68
}
77
69
78
- public void setBehindContent (View v ) {
70
+ public void setBehindView (View v ) {
79
71
mViewBehind .setContent (v );
80
72
mViewBehind .invalidate ();
81
73
mViewBehind .dataSetChanged ();
@@ -136,8 +128,7 @@ public void setBehindOffset(int i) {
136
128
* 1 pixel that the above view scrolls and 0.0f scrolls 0 pixels)
137
129
*/
138
130
public void setBehindScrollScale (float f ) {
139
- // mViewBehind.setScrollScale(f);
140
131
mViewAbove .setScrollScale (f );
141
132
}
142
133
143
- }
134
+ }
0 commit comments