Skip to content

Commit d5732a5

Browse files
author
jfeinstein10
committed
Reading stuff from xml to configure the SlidingMenu.
1 parent 7ce9f11 commit d5732a5

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

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

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.slidingmenu.lib;
22

33
import android.content.Context;
4+
import android.content.res.TypedArray;
45
import android.util.AttributeSet;
6+
import android.view.LayoutInflater;
57
import android.view.View;
68
import android.view.ViewGroup;
79
import android.widget.RelativeLayout;
@@ -28,35 +30,29 @@ public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
2830
LayoutParams aboveParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
2931
mViewAbove = new CustomViewAbove(context);
3032
addView(mViewAbove, aboveParams);
33+
// register the CustomViewBehind with the CustomViewAbove
3134
mViewAbove.setCustomViewBehind(mViewBehind);
3235

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);
6056
}
6157

6258
public void registerViews(CustomViewAbove va, CustomViewBehind vb) {
@@ -65,17 +61,13 @@ public void registerViews(CustomViewAbove va, CustomViewBehind vb) {
6561
mViewAbove.setCustomViewBehind(mViewBehind);
6662
}
6763

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) {
7365
mViewAbove.setContent(v, p);
7466
mViewAbove.invalidate();
7567
mViewAbove.dataSetChanged();
7668
}
7769

78-
public void setBehindContent(View v) {
70+
public void setBehindView(View v) {
7971
mViewBehind.setContent(v);
8072
mViewBehind.invalidate();
8173
mViewBehind.dataSetChanged();
@@ -136,8 +128,7 @@ public void setBehindOffset(int i) {
136128
* 1 pixel that the above view scrolls and 0.0f scrolls 0 pixels)
137129
*/
138130
public void setBehindScrollScale(float f) {
139-
// mViewBehind.setScrollScale(f);
140131
mViewAbove.setScrollScale(f);
141132
}
142133

143-
}
134+
}

0 commit comments

Comments
 (0)