Skip to content

Commit 6249663

Browse files
author
jfeinstein10
committed
Now working with CustomViewBehind2. Methods calls not as initially planned. Must go back and fix.
1 parent b77a203 commit 6249663

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.view.FocusFinder;
2525
import android.view.Gravity;
2626
import android.view.KeyEvent;
27+
import android.view.LayoutInflater;
2728
import android.view.MotionEvent;
2829
import android.view.SoundEffectConstants;
2930
import android.view.VelocityTracker;
@@ -33,6 +34,8 @@
3334
import android.view.ViewParent;
3435
import android.view.accessibility.AccessibilityEvent;
3536
import android.view.animation.Interpolator;
37+
import android.widget.ImageView;
38+
import android.widget.LinearLayout;
3639
import android.widget.Scroller;
3740

3841
public class CustomViewAbove extends ViewGroup {
@@ -124,7 +127,7 @@ public float getInterpolation(float t) {
124127

125128
private boolean mLastTouchAllowed = false;
126129
private int mSlidingMenuThreshold = 30;
127-
private CustomViewBehind mCustomViewBehind;
130+
private CustomViewBehind2 mCustomViewBehind2;
128131
private boolean mEnabled = true;
129132

130133
private OnPageChangeListener mOnPageChangeListener;
@@ -246,8 +249,10 @@ void initCustomViewAbove(boolean isAbove) {
246249
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
247250

248251
if (isAbove) {
249-
View v = new View(getContext());
250-
v.setBackgroundColor(android.R.color.transparent);
252+
View v = new LinearLayout(getContext());
253+
v.setBackgroundResource(android.R.color.transparent);
254+
// ImageView v = new ImageView(getContext());
255+
// v.setImageResource(R.drawable.ic_launcher);
251256
setMenu(v);
252257
}
253258

@@ -509,10 +514,10 @@ public int getChildWidth(int i) {
509514
}
510515

511516
public int getBehindWidth() {
512-
if (mCustomViewBehind == null) {
517+
if (mCustomViewBehind2 == null) {
513518
return 0;
514519
} else {
515-
return mCustomViewBehind.getWidth();
520+
return mCustomViewBehind2.getWidth();
516521
}
517522
}
518523

@@ -771,7 +776,7 @@ protected void setMenu(View v) {
771776
if (mWindow != null) {
772777
removeView((View)mWindow.object);
773778
}
774-
addView(v, 0);
779+
addView(v);
775780
mWindow = ii;
776781
}
777782

@@ -782,12 +787,12 @@ public void setContent(View v) {
782787
if (mContent != null) {
783788
removeView((View)mContent.object);
784789
}
785-
addView(v, 1);
790+
addView(v);
786791
mContent = ii;
787792
}
788793

789-
public void setCustomViewBehind(CustomViewBehind cvb) {
790-
mCustomViewBehind = cvb;
794+
public void setCustomViewBehind2(CustomViewBehind2 cvb) {
795+
mCustomViewBehind2 = cvb;
791796
}
792797

793798
public void addView(View child, int index, ViewGroup.LayoutParams params) {
@@ -816,9 +821,9 @@ public void addView(View child, int index, ViewGroup.LayoutParams params) {
816821
}
817822

818823
ItemInfo infoForChild(View child) {
819-
if (child.equals(mWindow.object)) {
824+
if (mWindow != null && child.equals(mWindow.object)) {
820825
return mWindow;
821-
} else if (child.equals(mContent.object)) {
826+
} else if (mContent != null && child.equals(mContent.object)) {
822827
return mContent;
823828
}
824829
return null;
@@ -880,7 +885,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
880885
} else if (consumeHorizontal) {
881886
heightMode = MeasureSpec.EXACTLY;
882887
}
883-
888+
int pos = infoForChild(child).position;
889+
childWidthSize = getChildWidth(pos);
884890
final int widthSpec = MeasureSpec.makeMeasureSpec(childWidthSize, widthMode);
885891
final int heightSpec = MeasureSpec.makeMeasureSpec(childHeightSize, heightMode);
886892
child.measure(widthSpec, heightSpec);
@@ -966,11 +972,11 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
966972
final View child = getChildAt(i);
967973
if (child.getVisibility() != GONE) {
968974
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
969-
ItemInfo ii;
975+
int pos = infoForChild(child).position;
970976
int childLeft = 0;
971977
int childTop = 0;
972-
childLeft = getChildLeft(i);
973-
int childWidth = getChildWidth(i);
978+
childLeft = getChildLeft(pos);
979+
int childWidth = getChildWidth(pos);
974980
Log.v(TAG, "Child#" + i + " left:" + childLeft +
975981
" right:" + (childLeft + child.getMeasuredWidth()));
976982
child.layout(childLeft, childTop,
@@ -1449,8 +1455,8 @@ public void setScrollScale(float f) {
14491455
@Override
14501456
public void scrollTo(int x, int y) {
14511457
super.scrollTo(x, y);
1452-
if (mCustomViewBehind != null && mEnabled) {
1453-
mCustomViewBehind.scrollTo((int)(x*mScrollScale), y);
1458+
if (mCustomViewBehind2 != null && mEnabled) {
1459+
mCustomViewBehind2.scrollTo((int)(x*mScrollScale), y);
14541460
}
14551461
}
14561462

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public CustomViewBehind2(Context context) {
1515
}
1616

1717
public CustomViewBehind2(Context context, AttributeSet attrs) {
18-
super(context, attrs, false);
18+
super(context, attrs, true);
1919
}
2020

2121
public int getDestScrollX() {
@@ -56,10 +56,10 @@ public int getBehindWidth() {
5656
return params.width;
5757
}
5858

59-
@Override
60-
public void setContent(View v) {
61-
setMenu(v);
62-
}
59+
// @Override
60+
// public void setContent(View v) {
61+
// super.setMenu(v);
62+
// }
6363

6464
@Override
6565
public boolean onInterceptTouchEvent(MotionEvent e) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class SlidingMenu extends RelativeLayout {
1313
public static final int TOUCHMODE_FULLSCREEN = 1;
1414

1515
private CustomViewAbove mViewAbove;
16-
private CustomViewBehind mViewBehind;
16+
private CustomViewBehind2 mViewBehind;
1717

1818
public SlidingMenu(Context context) {
1919
this(context, null);
@@ -27,13 +27,13 @@ public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
2727
super(context, attrs, defStyle);
2828

2929
LayoutParams behindParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
30-
mViewBehind = new CustomViewBehind(context);
30+
mViewBehind = new CustomViewBehind2(context);
3131
addView(mViewBehind, behindParams);
3232
LayoutParams aboveParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
3333
mViewAbove = new CustomViewAbove(context);
3434
addView(mViewAbove, aboveParams);
35-
// register the CustomViewBehind with the CustomViewAbove
36-
mViewAbove.setCustomViewBehind(mViewBehind);
35+
// register the CustomViewBehind2 with the CustomViewAbove
36+
mViewAbove.setCustomViewBehind2(mViewBehind);
3737

3838
// now style everything!
3939
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingMenu);
@@ -97,13 +97,13 @@ public boolean isSlidingEnabled() {
9797
public void setStatic(boolean b) {
9898
if (b) {
9999
setSlidingEnabled(false);
100-
mViewAbove.setCustomViewBehind(null);
100+
mViewAbove.setCustomViewBehind2(null);
101101
mViewAbove.setCurrentItem(1);
102102
mViewBehind.setCurrentItem(0);
103103
} else {
104104
mViewAbove.setCurrentItem(1);
105105
mViewBehind.setCurrentItem(1);
106-
mViewAbove.setCustomViewBehind(mViewBehind);
106+
mViewAbove.setCustomViewBehind2(mViewBehind);
107107
setSlidingEnabled(true);
108108
}
109109
}

0 commit comments

Comments
 (0)