Skip to content

Commit 6ca0c5e

Browse files
author
jfeinstein10
committed
Working on FULLSCREEN behind. Reintroduced selectors. Cleaned up quick returning
1 parent 9b7d10a commit 6ca0c5e

File tree

5 files changed

+209
-137
lines changed

5 files changed

+209
-137
lines changed

library/res/values/attrs.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@
3030
<enum name="margin" value="0" />
3131
<enum name="fullscreen" value="1" />
3232
</attr>
33+
<attr name="touchModeBehind">
34+
<enum name="margin" value="0" />
35+
<enum name="fullscreen" value="1" />
36+
</attr>
3337
<attr name="shadowDrawable" format="reference" />
3438
<attr name="shadowWidth" format="dimension" />
35-
<attr name="behindFadeEnabled" format="boolean" />
36-
<attr name="behindFadeDegree" format="float" />
39+
<attr name="fadeEnabled" format="boolean" />
40+
<attr name="fadeDegree" format="float" />
3741
<attr name="selectorEnabled" format="boolean" />
3842
<attr name="selectorDrawable" format="reference" />
3943
</declare-styleable>

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

Lines changed: 57 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
public class CustomViewAbove extends ViewGroup {
3636

3737
private static final String TAG = "CustomViewAbove";
38-
private static final boolean DEBUG = false;
38+
private static final boolean DEBUG = true;
3939

4040
private static final boolean USE_CACHE = false;
4141

@@ -86,7 +86,7 @@ public float getInterpolation(float t) {
8686
protected int mMaximumVelocity;
8787
private int mFlingDistance;
8888

89-
private CustomViewBehind mCustomViewBehind;
89+
private CustomViewBehind mViewBehind;
9090
// private int mMode;
9191
private boolean mEnabled = true;
9292

@@ -154,10 +154,6 @@ public CustomViewAbove(Context context) {
154154
}
155155

156156
public CustomViewAbove(Context context, AttributeSet attrs) {
157-
this(context, attrs, true);
158-
}
159-
160-
public CustomViewAbove(Context context, AttributeSet attrs, boolean isAbove) {
161157
super(context, attrs);
162158
initCustomViewAbove();
163159
}
@@ -174,14 +170,14 @@ void initCustomViewAbove() {
174170
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
175171
setInternalPageChangeListener(new SimpleOnPageChangeListener() {
176172
public void onPageSelected(int position) {
177-
if (mCustomViewBehind != null) {
173+
if (mViewBehind != null) {
178174
switch (position) {
179175
case 0:
180176
case 2:
181-
mCustomViewBehind.setChildrenEnabled(true);
177+
mViewBehind.setChildrenEnabled(true);
182178
break;
183179
case 1:
184-
mCustomViewBehind.setChildrenEnabled(false);
180+
mViewBehind.setChildrenEnabled(false);
185181
break;
186182
}
187183
}
@@ -227,7 +223,7 @@ void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int
227223
return;
228224
}
229225

230-
item = mCustomViewBehind.getMenuPage(item);
226+
item = mViewBehind.getMenuPage(item);
231227

232228
final boolean dispatchSelected = mCurItem != item;
233229
mCurItem = item;
@@ -312,19 +308,19 @@ public int getDestScrollX(int page) {
312308
switch (page) {
313309
case 0:
314310
case 2:
315-
return mCustomViewBehind.getMenuLeft(mContent, page);
311+
return mViewBehind.getMenuLeft(mContent, page);
316312
case 1:
317313
return mContent.getLeft();
318314
}
319315
return 0;
320316
}
321317

322318
private int getLeftBound() {
323-
return mCustomViewBehind.getAbsLeftBound(mContent);
319+
return mViewBehind.getAbsLeftBound(mContent);
324320
}
325321

326322
private int getRightBound() {
327-
return mCustomViewBehind.getAbsRightBound(mContent);
323+
return mViewBehind.getAbsRightBound(mContent);
328324
}
329325

330326
public int getContentLeft() {
@@ -345,10 +341,10 @@ private boolean isInIgnoredView(MotionEvent ev) {
345341
}
346342

347343
public int getBehindWidth() {
348-
if (mCustomViewBehind == null) {
344+
if (mViewBehind == null) {
349345
return 0;
350346
} else {
351-
return mCustomViewBehind.getBehindWidth();
347+
return mViewBehind.getBehindWidth();
352348
}
353349
}
354350

@@ -446,7 +442,7 @@ public View getContent() {
446442
}
447443

448444
public void setCustomViewBehind(CustomViewBehind cvb) {
449-
mCustomViewBehind = cvb;
445+
mViewBehind = cvb;
450446
}
451447

452448
@Override
@@ -477,7 +473,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
477473
@Override
478474
protected void onLayout(boolean changed, int l, int t, int r, int b) {
479475
final int width = r - l;
480-
final int height = b - t;
476+
final int height = b - t;
481477
mContent.layout(0, 0, width, height);
482478
}
483479

@@ -580,15 +576,15 @@ public int getTouchMode() {
580576
private boolean thisTouchAllowed(MotionEvent ev) {
581577
int x = (int) (ev.getX() + mScrollX);
582578
if (isMenuOpen()) {
583-
return mCustomViewBehind.menuOpenTouchAllowed(mContent, mCurItem, x);
579+
return mViewBehind.menuOpenTouchAllowed(mContent, mCurItem, x);
584580
} else {
585581
switch (mTouchMode) {
586582
case SlidingMenu.TOUCHMODE_FULLSCREEN:
587583
return !isInIgnoredView(ev);
588584
case SlidingMenu.TOUCHMODE_NONE:
589585
return false;
590586
case SlidingMenu.TOUCHMODE_MARGIN:
591-
return mCustomViewBehind.marginTouchAllowed(mContent, x);
587+
return mViewBehind.marginTouchAllowed(mContent, x);
592588
}
593589
}
594590
return false;
@@ -597,9 +593,9 @@ private boolean thisTouchAllowed(MotionEvent ev) {
597593
private boolean thisSlideAllowed(float dx) {
598594
boolean allowed = false;
599595
if (isMenuOpen()) {
600-
allowed = mCustomViewBehind.menuOpenSlideAllowed(dx);
596+
allowed = mViewBehind.menuOpenSlideAllowed(dx);
601597
} else {
602-
allowed = mCustomViewBehind.menuClosedSlideAllowed(dx);
598+
allowed = mViewBehind.menuClosedSlideAllowed(dx);
603599
}
604600
if (DEBUG)
605601
Log.v(TAG, "this slide allowed " + allowed + " dx: " + dx);
@@ -613,6 +609,8 @@ private int getPointerIndex(MotionEvent ev, int id) {
613609
return activePointerIndex;
614610
}
615611

612+
private boolean mQuickReturn = false;
613+
616614
@Override
617615
public boolean onInterceptTouchEvent(MotionEvent ev) {
618616

@@ -635,19 +633,16 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
635633
final int activePointerId = mActivePointerId;
636634
if (activePointerId == INVALID_POINTER)
637635
break;
638-
639636
final int pointerIndex = this.getPointerIndex(ev, activePointerId);
640-
if (mActivePointerId == INVALID_POINTER)
641-
break;
642637
final float x = MotionEventCompat.getX(ev, pointerIndex);
643638
final float dx = x - mLastMotionX;
644639
final float xDiff = Math.abs(dx);
645640
final float y = MotionEventCompat.getY(ev, pointerIndex);
646641
final float yDiff = Math.abs(y - mLastMotionY);
647-
if (DEBUG) Log.v(TAG, "onInterceptTouch moved to:(" + x + ", " + y + "), diff:(" + xDiff + ", " + yDiff + "), mLastMotionX:" + mLastMotionX);
642+
// if (DEBUG) Log.v(TAG, "onInterceptTouch moved to:(" + x + ", " + y + "), diff:(" + xDiff + ", " + yDiff + "), mLastMotionX:" + mLastMotionX);
648643
if (xDiff > mTouchSlop && xDiff > yDiff && thisSlideAllowed(dx)) {
649644
if (DEBUG) Log.v(TAG, "Starting drag! from onInterceptTouch");
650-
mIsBeingDragged = true;
645+
startDrag();
651646
mLastMotionX = x;
652647
setScrollingCacheEnabled(true);
653648
} else if (yDiff > mTouchSlop) {
@@ -663,8 +658,9 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
663658
if (thisTouchAllowed(ev)) {
664659
mIsBeingDragged = false;
665660
mIsUnableToDrag = false;
666-
if (isMenuOpen())
667-
return true;
661+
if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
662+
mQuickReturn = true;
663+
}
668664
} else {
669665
mIsUnableToDrag = true;
670666
}
@@ -680,8 +676,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
680676
}
681677
mVelocityTracker.addMovement(ev);
682678
}
683-
684-
return mIsBeingDragged;
679+
return mIsBeingDragged || mQuickReturn;
685680
}
686681

687682

@@ -691,7 +686,10 @@ public boolean onTouchEvent(MotionEvent ev) {
691686
if (!mEnabled)
692687
return false;
693688

694-
if (!mIsBeingDragged && !thisTouchAllowed(ev))
689+
// if (!mIsBeingDragged && !thisTouchAllowed(ev))
690+
// return false;
691+
692+
if (!mIsBeingDragged && !mQuickReturn)
695693
return false;
696694

697695
final int action = ev.getAction();
@@ -714,22 +712,24 @@ public boolean onTouchEvent(MotionEvent ev) {
714712
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
715713
break;
716714
case MotionEvent.ACTION_MOVE:
717-
if (!mIsBeingDragged) {
718-
final int pointerIndex = getPointerIndex(ev, mActivePointerId);
719-
if (mActivePointerId == INVALID_POINTER) {
715+
if (!mIsBeingDragged) {
716+
if (mActivePointerId == INVALID_POINTER)
720717
break;
721-
}
718+
final int pointerIndex = getPointerIndex(ev, mActivePointerId);
722719
final float x = MotionEventCompat.getX(ev, pointerIndex);
723720
final float dx = x - mLastMotionX;
724721
final float xDiff = Math.abs(dx);
725722
final float y = MotionEventCompat.getY(ev, pointerIndex);
726723
final float yDiff = Math.abs(y - mLastMotionY);
727-
if (DEBUG) Log.v(TAG, "onTouch moved to:(" + x + ", " + y + "), diff:(" + xDiff + ", " + yDiff + "), mLastMotionX:" + mLastMotionX);
728-
if (xDiff > mTouchSlop && xDiff > yDiff && thisSlideAllowed(dx)) {
724+
// if (DEBUG) Log.v(TAG, "onTouch moved to:(" + x + ", " + y + "), diff:(" + xDiff + ", " + yDiff + ")\nmIsBeingDragged:" + mIsBeingDragged + ", mLastMotionX:" + mLastMotionX);
725+
if ((xDiff > mTouchSlop || mQuickReturn) && xDiff > yDiff && thisSlideAllowed(dx)) {
729726
if (DEBUG) Log.v(TAG, "Starting drag! from onTouch");
730-
mIsBeingDragged = true;
727+
startDrag();
731728
mLastMotionX = x;
732729
setScrollingCacheEnabled(true);
730+
} else {
731+
if (DEBUG) Log.v(TAG, "onTouch returning false");
732+
return false;
733733
}
734734
}
735735
if (mIsBeingDragged) {
@@ -763,8 +763,8 @@ public boolean onTouchEvent(MotionEvent ev) {
763763
int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(
764764
velocityTracker, mActivePointerId);
765765
final int scrollX = getScrollX();
766-
// final int widthWithMargin = getWidth();
767-
// final float pageOffset = (float) (scrollX % widthWithMargin) / widthWithMargin;
766+
// final int widthWithMargin = getWidth();
767+
// final float pageOffset = (float) (scrollX % widthWithMargin) / widthWithMargin;
768768
// TODO test this. should get better flinging behavior
769769
final float pageOffset = (float) (scrollX - getDestScrollX(mCurItem)) / getBehindWidth();
770770
final int activePointerIndex = getPointerIndex(ev, mActivePointerId);
@@ -778,9 +778,10 @@ public boolean onTouchEvent(MotionEvent ev) {
778778
}
779779
mActivePointerId = INVALID_POINTER;
780780
endDrag();
781-
} else if (isMenuOpen()) {
781+
} else if (mQuickReturn && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
782782
// close the menu
783783
setCurrentItem(1);
784+
endDrag();
784785
}
785786
break;
786787
case MotionEvent.ACTION_CANCEL:
@@ -813,9 +814,9 @@ public void scrollTo(int x, int y) {
813814
super.scrollTo(x, y);
814815
mScrollX = x;
815816
if (mEnabled)
816-
mCustomViewBehind.scrollBehindTo(mContent, x, y);
817-
// if (mSelectorDrawable != null)
818-
// invalidate();
817+
mViewBehind.scrollBehindTo(mContent, x, y);
818+
// if (mSelectorDrawable != null)
819+
// invalidate();
819820
}
820821

821822
private int determineTargetPage(float pageOffset, int velocity, int deltaX) {
@@ -833,68 +834,21 @@ private int determineTargetPage(float pageOffset, int velocity, int deltaX) {
833834
}
834835

835836
protected float getPercentOpen() {
836-
return Math.abs(mScrollX) / getBehindWidth();
837+
if (DEBUG) Log.v(TAG, ""+ Math.abs(mScrollX-mContent.getLeft()) / getBehindWidth());
838+
return Math.abs(mScrollX-mContent.getLeft()) / getBehindWidth();
837839
}
838840

839841
@Override
840842
protected void dispatchDraw(Canvas canvas) {
841843
super.dispatchDraw(canvas);
842844
// Draw the margin drawable if needed.
843-
mCustomViewBehind.drawShadow(mContent, canvas);
844-
845-
mCustomViewBehind.drawFade(mContent, canvas, getPercentOpen());
846-
// if (mSelectorEnabled)
847-
// onDrawMenuSelector(canvas, getPercentOpen());
845+
mViewBehind.drawShadow(mContent, canvas);
846+
mViewBehind.drawFade(mContent, canvas, getPercentOpen());
847+
mViewBehind.drawSelector(mContent, canvas, getPercentOpen());
848848
}
849849

850850
// variables for drawing
851851
private float mScrollX = 0.0f;
852-
// for the indicator
853-
private boolean mSelectorEnabled = true;
854-
private Bitmap mSelectorDrawable;
855-
private View mSelectedView;
856-
857-
private void onDrawMenuSelector(Canvas canvas, float openPercent) {
858-
if (mSelectorDrawable != null && mSelectedView != null) {
859-
String tag = (String) mSelectedView.getTag(R.id.selected_view);
860-
if (tag.equals(TAG+"SelectedView")) {
861-
int right = getContentLeft();
862-
int left = (int) (right - mSelectorDrawable.getWidth() * openPercent);
863-
864-
canvas.save();
865-
canvas.clipRect(left, 0, right, getHeight());
866-
canvas.drawBitmap(mSelectorDrawable, left, getSelectedTop(), null);
867-
canvas.restore();
868-
}
869-
}
870-
}
871-
872-
public void setSelectorEnabled(boolean b) {
873-
mSelectorEnabled = b;
874-
}
875-
876-
public void setSelectedView(View v) {
877-
if (mSelectedView != null) {
878-
mSelectedView.setTag(R.id.selected_view, null);
879-
mSelectedView = null;
880-
}
881-
if (v.getParent() != null) {
882-
mSelectedView = v;
883-
mSelectedView.setTag(R.id.selected_view, TAG+"SelectedView");
884-
invalidate();
885-
}
886-
}
887-
888-
private int getSelectedTop() {
889-
int y = mSelectedView.getTop();
890-
y += (mSelectedView.getHeight() - mSelectorDrawable.getHeight()) / 2;
891-
return y;
892-
}
893-
894-
public void setSelectorBitmap(Bitmap b) {
895-
mSelectorDrawable = b;
896-
refreshDrawableState();
897-
}
898852

899853
private void onSecondaryPointerUp(MotionEvent ev) {
900854
if (DEBUG) Log.v(TAG, "onSecondaryPointerUp called");
@@ -912,7 +866,13 @@ private void onSecondaryPointerUp(MotionEvent ev) {
912866
}
913867
}
914868

869+
private void startDrag() {
870+
mIsBeingDragged = true;
871+
mQuickReturn = false;
872+
}
873+
915874
private void endDrag() {
875+
mQuickReturn = false;
916876
mIsBeingDragged = false;
917877
mIsUnableToDrag = false;
918878
mActivePointerId = INVALID_POINTER;
@@ -1021,7 +981,7 @@ public boolean arrowScroll(int direction) {
1021981
direction);
1022982
if (nextFocused != null && nextFocused != currentFocused) {
1023983
if (direction == View.FOCUS_LEFT) {
1024-
handled = nextFocused.requestFocus();
984+
handled = nextFocused.requestFocus();
1025985
} else if (direction == View.FOCUS_RIGHT) {
1026986
// If there is nothing to the right, or this is causing us to
1027987
// jump to the left, then what we really want to do is page right.

0 commit comments

Comments
 (0)