diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 7a4a3ea24..000000000 --- a/LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/library/project.properties b/library/project.properties index b15f1208a..52119bdae 100644 --- a/library/project.properties +++ b/library/project.properties @@ -9,4 +9,5 @@ android.library=true # Project target. -target=Google Inc.:Google APIs:16 +target=android-17 +android.library.reference.1=../ABS diff --git a/library/res/values/attrs.xml b/library/res/values/attrs.xml index d5ee00f32..74000cdda 100644 --- a/library/res/values/attrs.xml +++ b/library/res/values/attrs.xml @@ -18,8 +18,10 @@ - - + + + + diff --git a/library/src/com/slidingmenu/lib/CustomViewAbove.java b/library/src/com/slidingmenu/lib/CustomViewAbove.java index 24a3bc853..692727fdc 100644 --- a/library/src/com/slidingmenu/lib/CustomViewAbove.java +++ b/library/src/com/slidingmenu/lib/CustomViewAbove.java @@ -34,9 +34,9 @@ public class CustomViewAbove extends ViewGroup { private static final String TAG = "CustomViewAbove"; - private static final boolean DEBUG = false; + private static final boolean DEBUG = true; - private static final boolean USE_CACHE = false; + private static final boolean USE_CACHE = true; private static final int MAX_SETTLE_DURATION = 600; // ms private static final int MIN_DISTANCE_FOR_FLING = 25; // dips @@ -58,9 +58,11 @@ public float getInterpolation(float t) { private boolean mScrolling; private boolean mIsBeingDragged; + private boolean mDraggingHoz; private boolean mIsUnableToDrag; private int mTouchSlop; private float mInitialMotionX; + private float mInitialMotionY; /** * Position of the last motion event. */ @@ -167,22 +169,6 @@ void initCustomViewAbove() { mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); - setInternalPageChangeListener(new SimpleOnPageChangeListener() { - public void onPageSelected(int position) { - if (mViewBehind != null) { - switch (position) { - case 0: - case 2: - mViewBehind.setChildrenEnabled(true); - break; - case 1: - mViewBehind.setChildrenEnabled(false); - break; - } - } - } - }); - final float density = context.getResources().getDisplayMetrics().density; mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); } @@ -222,11 +208,13 @@ void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int return; } - item = mViewBehind.getMenuPage(item); - final boolean dispatchSelected = mCurItem != item; + item = mViewBehind.correctMenuPage(item); + if (DEBUG) + Log.v(TAG, "mCurItem was " + mCurItem + ", mCurItem now " + item); mCurItem = item; final int destX = getDestScrollX(mCurItem); + final int destY = getDestScrollY(mCurItem); if (dispatchSelected && mOnPageChangeListener != null) { mOnPageChangeListener.onPageSelected(item); } @@ -234,10 +222,10 @@ void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int mInternalPageChangeListener.onPageSelected(item); } if (smoothScroll) { - smoothScrollTo(destX, 0, velocity); + smoothScrollTo(destX, destY, velocity); } else { completeScroll(); - scrollTo(destX, 0); + scrollTo(destX, destY); } } @@ -309,17 +297,40 @@ public int getDestScrollX(int page) { case 2: return mViewBehind.getMenuLeft(mContent, page); case 1: + case 3: + case 4: return mContent.getLeft(); } return 0; } + public int getDestScrollY(int page) { + switch (page) { + case 0: + case 1: + case 2: + return mContent.getTop(); + case 3: + case 4: + return mViewBehind.getMenuTop(mContent, page); + } + return 0; + } + private int getLeftBound() { - return mViewBehind.getAbsLeftBound(mContent); + return !mDraggingHoz ? 0 : mViewBehind.getAbsLeftBound(mContent); } private int getRightBound() { - return mViewBehind.getAbsRightBound(mContent); + return !mDraggingHoz ? 0 : mViewBehind.getAbsRightBound(mContent); + } + + private int getTopBound() { + return mDraggingHoz ? 0 : mViewBehind.getAbsTopBound(mContent); + } + + private int getBottomBound() { + return mDraggingHoz ? 0 : mViewBehind.getAbsBottomBound(mContent); } public int getContentLeft() { @@ -327,7 +338,7 @@ public int getContentLeft() { } public boolean isMenuOpen() { - return mCurItem == 0 || mCurItem == 2; + return mCurItem != 1; } private boolean isInIgnoredView(MotionEvent ev) { @@ -343,18 +354,15 @@ public int getBehindWidth() { if (mViewBehind == null) { return 0; } else { - return mViewBehind.getBehindWidth(); + return mViewBehind.getBehindWidth(mCurItem); } } - public int getChildWidth(int i) { - switch (i) { - case 0: - return getBehindWidth(); - case 1: - return mContent.getWidth(); - default: + public int getBehindHeight() { + if (mViewBehind == null) { return 0; + } else { + return mViewBehind.getBehindHeight(mCurItem); } } @@ -453,19 +461,21 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int contentWidth = getChildMeasureSpec(widthMeasureSpec, 0, width); final int contentHeight = getChildMeasureSpec(heightMeasureSpec, 0, height); - mContent.measure(contentWidth, contentHeight); + if (mContent != null) + mContent.measure(contentWidth, contentHeight); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); // Make sure scroll position is set correctly. - if (w != oldw) { + if (w != oldw || h != oldh) { // [ChrisJ] - This fixes the onConfiguration change for orientation issue.. // maybe worth having a look why the recomputeScroll pos is screwing // up? + requestLayout(); completeScroll(); - scrollTo(getDestScrollX(mCurItem), getScrollY()); + setCurrentItem(mCurItem, false); } } @@ -473,7 +483,8 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { protected void onLayout(boolean changed, int l, int t, int r, int b) { final int width = r - l; final int height = b - t; - mContent.layout(0, 0, width, height); + if (mContent != null) + mContent.layout(0, 0, width, height); } public void setAboveOffset(int i) { @@ -574,8 +585,9 @@ public int getTouchMode() { private boolean thisTouchAllowed(MotionEvent ev) { int x = (int) (ev.getX() + mScrollX); + int y = (int) (ev.getY() + mScrollY); if (isMenuOpen()) { - return mViewBehind.menuOpenTouchAllowed(mContent, mCurItem, x); + return mViewBehind.menuOpenTouchAllowed(mContent, mCurItem, x, y); } else { switch (mTouchMode) { case SlidingMenu.TOUCHMODE_FULLSCREEN: @@ -583,18 +595,18 @@ private boolean thisTouchAllowed(MotionEvent ev) { case SlidingMenu.TOUCHMODE_NONE: return false; case SlidingMenu.TOUCHMODE_MARGIN: - return mViewBehind.marginTouchAllowed(mContent, x); + return mViewBehind.menuClosedTouchAllowed(mContent, x, y); } } return false; } - private boolean thisSlideAllowed(float dx) { + private boolean thisSlideAllowed(float dx, float dy) { boolean allowed = false; if (isMenuOpen()) { - allowed = mViewBehind.menuOpenSlideAllowed(dx); + allowed = mViewBehind.menuOpenSlideAllowed(dx, dy, mCurItem); } else { - allowed = mViewBehind.menuClosedSlideAllowed(dx); + allowed = mViewBehind.menuClosedSlideAllowed(dx, dy); } if (DEBUG) Log.v(TAG, "this slide allowed " + allowed + " dx: " + dx); @@ -630,35 +642,19 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { switch (action) { case MotionEvent.ACTION_MOVE: - final int activePointerId = mActivePointerId; - if (activePointerId == INVALID_POINTER) - break; - final int pointerIndex = this.getPointerIndex(ev, activePointerId); - final float x = MotionEventCompat.getX(ev, pointerIndex); - final float dx = x - mLastMotionX; - final float xDiff = Math.abs(dx); - final float y = MotionEventCompat.getY(ev, pointerIndex); - final float yDiff = Math.abs(y - mLastMotionY); - if (DEBUG) Log.v(TAG, "onInterceptTouch moved to:(" + x + ", " + y + "), diff:(" + xDiff + ", " + yDiff + "), mLastMotionX:" + mLastMotionX); - if (xDiff > mTouchSlop && xDiff > yDiff && thisSlideAllowed(dx)) { - if (DEBUG) Log.v(TAG, "Starting drag! from onInterceptTouch"); - startDrag(); - mLastMotionX = x; - setScrollingCacheEnabled(true); - } else if (yDiff > mTouchSlop) { - mIsUnableToDrag = true; - } + determineDrag(ev); break; - case MotionEvent.ACTION_DOWN: - mActivePointerId = ev.getAction() & ((Build.VERSION.SDK_INT >= 8) ? MotionEvent.ACTION_POINTER_INDEX_MASK : - MotionEvent.ACTION_POINTER_INDEX_MASK); - mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, mActivePointerId); - mLastMotionY = MotionEventCompat.getY(ev, mActivePointerId); + int index = MotionEventCompat.getActionIndex(ev); + mActivePointerId = MotionEventCompat.getPointerId(ev, index); + if (mActivePointerId == INVALID_POINTER) + break; + mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index); + mLastMotionY = mInitialMotionY = MotionEventCompat.getY(ev, index); if (thisTouchAllowed(ev)) { mIsBeingDragged = false; mIsUnableToDrag = false; - if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) { + if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, mLastMotionX, mLastMotionY)) { mQuickReturn = true; } } else { @@ -676,6 +672,8 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { } mVelocityTracker.addMovement(ev); } + + if (DEBUG && mIsBeingDragged) Log.v(TAG, "Starting drag! from onInterceptTouch"); return mIsBeingDragged || mQuickReturn; } @@ -708,30 +706,15 @@ public boolean onTouchEvent(MotionEvent ev) { completeScroll(); // Remember where the motion event started - mLastMotionX = mInitialMotionX = ev.getX(); - mActivePointerId = MotionEventCompat.getPointerId(ev, 0); + int index = MotionEventCompat.getActionIndex(ev); + mActivePointerId = MotionEventCompat.getPointerId(ev, index); + // mActivePointerId = MotionEventCompat.getPointerId(ev, MotionEventCompat.getActionIndex(ev)); + mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index); + mLastMotionY = mInitialMotionY = MotionEventCompat.getY(ev, index); break; case MotionEvent.ACTION_MOVE: - if (!mIsBeingDragged) { - if (mActivePointerId == INVALID_POINTER) - break; - final int pointerIndex = getPointerIndex(ev, mActivePointerId); - final float x = MotionEventCompat.getX(ev, pointerIndex); - final float dx = x - mLastMotionX; - final float xDiff = Math.abs(dx); - final float y = MotionEventCompat.getY(ev, pointerIndex); - final float yDiff = Math.abs(y - mLastMotionY); - if (DEBUG) Log.v(TAG, "onTouch moved to:(" + x + ", " + y + "), diff:(" + xDiff + ", " + yDiff + ")\nmIsBeingDragged:" + mIsBeingDragged + ", mLastMotionX:" + mLastMotionX); - if ((xDiff > mTouchSlop || (mQuickReturn && xDiff > mTouchSlop / 4)) - && xDiff > yDiff && thisSlideAllowed(dx)) { - if (DEBUG) Log.v(TAG, "Starting drag! from onTouch"); - startDrag(); - mLastMotionX = x; - setScrollingCacheEnabled(true); - } else { - if (DEBUG) Log.v(TAG, "onTouch returning false"); - return false; - } + if (!mIsBeingDragged) { + determineDrag(ev); } if (mIsBeingDragged) { // Scroll to follow the motion event @@ -740,20 +723,33 @@ && xDiff > yDiff && thisSlideAllowed(dx)) { break; } final float x = MotionEventCompat.getX(ev, activePointerIndex); + final float y = MotionEventCompat.getY(ev, activePointerIndex); final float deltaX = mLastMotionX - x; + final float deltaY = mLastMotionY - y; mLastMotionX = x; + mLastMotionY = y; float oldScrollX = getScrollX(); - float scrollX = oldScrollX + deltaX; + float scrollX = oldScrollX + (mDraggingHoz ? deltaX : 0); + float oldScrollY = getScrollY(); + float scrollY = oldScrollY + (mDraggingHoz ? 0 : deltaY); final float leftBound = getLeftBound(); final float rightBound = getRightBound(); + final float topBound = getTopBound(); + final float bottomBound = getBottomBound(); if (scrollX < leftBound) { scrollX = leftBound; } else if (scrollX > rightBound) { scrollX = rightBound; } + if (scrollY < topBound) { + scrollY = topBound; + } else if (scrollY > bottomBound) { + scrollY = bottomBound; + } // Don't lose the rounded component mLastMotionX += scrollX - (int) scrollX; - scrollTo((int) scrollX, getScrollY()); + mLastMotionY += scrollY - (int) scrollY; + scrollTo((int) scrollX, (int) scrollY); pageScrolled((int) scrollX); } break; @@ -761,7 +757,9 @@ && xDiff > yDiff && thisSlideAllowed(dx)) { if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); - int initialVelocity = (int) VelocityTrackerCompat.getXVelocity( + int initialVelocityX = (int) VelocityTrackerCompat.getXVelocity( + velocityTracker, mActivePointerId); + int initialVelocityY = (int) VelocityTrackerCompat.getYVelocity( velocityTracker, mActivePointerId); final int scrollX = getScrollX(); // final int widthWithMargin = getWidth(); @@ -771,15 +769,17 @@ && xDiff > yDiff && thisSlideAllowed(dx)) { final int activePointerIndex = getPointerIndex(ev, mActivePointerId); if (mActivePointerId != INVALID_POINTER) { final float x = MotionEventCompat.getX(ev, activePointerIndex); - final int totalDelta = (int) (x - mInitialMotionX); - int nextPage = determineTargetPage(pageOffset, initialVelocity, totalDelta); - setCurrentItemInternal(nextPage, true, true, initialVelocity); + final float y = MotionEventCompat.getY(ev, activePointerIndex); + final int totalDeltaX = (int) (x - mInitialMotionX); + final int totalDeltaY = (int) (y - mInitialMotionY); + int nextPage = determineTargetPage(pageOffset, initialVelocityX, totalDeltaX, initialVelocityY, totalDeltaY); + setCurrentItemInternal(nextPage, true, true, initialVelocityX); } else { - setCurrentItemInternal(mCurItem, true, true, initialVelocity); + setCurrentItemInternal(mCurItem, true, true, initialVelocityX); } mActivePointerId = INVALID_POINTER; endDrag(); - } else if (mQuickReturn && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) { + } else if (mQuickReturn && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, mLastMotionX, mLastMotionY)) { // close the menu setCurrentItem(1); endDrag(); @@ -793,10 +793,10 @@ && xDiff > yDiff && thisSlideAllowed(dx)) { } break; case MotionEventCompat.ACTION_POINTER_DOWN: { - final int index = MotionEventCompat.getActionIndex(ev); - final float x = MotionEventCompat.getX(ev, index); - mLastMotionX = x; - mActivePointerId = MotionEventCompat.getPointerId(ev, index); + final int indexx = MotionEventCompat.getActionIndex(ev); + mLastMotionX = MotionEventCompat.getX(ev, indexx); + mLastMotionY = MotionEventCompat.getY(ev, indexx); + mActivePointerId = MotionEventCompat.getPointerId(ev, indexx); break; } case MotionEventCompat.ACTION_POINTER_UP: @@ -807,34 +807,102 @@ && xDiff > yDiff && thisSlideAllowed(dx)) { mLastMotionX = MotionEventCompat.getX(ev, pointerIndex); break; } - return true; + return mIsBeingDragged || mQuickReturn; + } + + private void determineDrag(MotionEvent ev) { + final int activePointerId = mActivePointerId; + if (activePointerId == INVALID_POINTER) + return; + final int pointerIndex = this.getPointerIndex(ev, activePointerId); + final float x = MotionEventCompat.getX(ev, pointerIndex); + final float dx = x - mLastMotionX; + final float xDiff = Math.abs(dx); + final float y = MotionEventCompat.getY(ev, pointerIndex); + final float dy = y - mLastMotionY; + final float yDiff = Math.abs(dy); + if (DEBUG) Log.v(TAG, "onInterceptTouch moved to:(" + x + ", " + y + "), diff:(" + xDiff + ", " + yDiff + "), touch slop:" + mTouchSlop); + boolean lookAtHoz = !isMenuOpen() && mTouchMode == SlidingMenu.TOUCHMODE_MARGIN; + boolean touchHoz = mViewBehind.menuClosedTouchHoz(mContent, (int) (mScrollX + x), (int) (mScrollY + y)); + if (xDiff > mTouchSlop && xDiff > yDiff && thisSlideAllowed(dx, dy)) { + if (lookAtHoz && !touchHoz) { + mIsUnableToDrag = true; + return; + } + mDraggingHoz = true; + startDrag(); + mLastMotionX = x; + mLastMotionY = y; + setScrollingCacheEnabled(true); + // TODO add back in touch slop check + } else if (yDiff > xDiff && thisSlideAllowed(dx, dy)) { + if (lookAtHoz && touchHoz) { + mIsUnableToDrag = true; + return; + } + mDraggingHoz = false; + startDrag(); + mLastMotionX = x; + mLastMotionY = y; + setScrollingCacheEnabled(true); + } else if (xDiff > mTouchSlop || yDiff > mTouchSlop) { + mIsUnableToDrag = true; + } } @Override public void scrollTo(int x, int y) { super.scrollTo(x, y); mScrollX = x; + mScrollY = y; if (mEnabled) mViewBehind.scrollBehindTo(mContent, x, y); ((SlidingMenu)getParent()).manageLayers(getPercentOpen()); } - private int determineTargetPage(float pageOffset, int velocity, int deltaX) { + private int determineTargetPage(float pageOffset, int velocityX, int deltaX, int velocityY, int deltaY) { int targetPage = mCurItem; - if (Math.abs(deltaX) > mFlingDistance && Math.abs(velocity) > mMinimumVelocity) { - if (velocity > 0 && deltaX > 0) { - targetPage -= 1; - } else if (velocity < 0 && deltaX < 0){ - targetPage += 1; + if (mDraggingHoz && Math.abs(deltaX) > mFlingDistance && + Math.abs(velocityX) > mMinimumVelocity && Math.abs(deltaX) > Math.abs(deltaY)) { + // TODO check + if (velocityX > 0 && deltaX > 0) { + targetPage = mCurItem == 1 ? 0 : 1; + } else if (velocityX < 0 && deltaX < 0){ + targetPage = mCurItem == 1 ? 2 : 1; + } + } else if (!mDraggingHoz && Math.abs(deltaY) > mFlingDistance && + Math.abs(velocityY) > mMinimumVelocity && Math.abs(deltaY) > Math.abs(deltaX)) { + // TODO check + if (velocityY > 0 && deltaY > 0) { + targetPage = mCurItem == 1 ? 3 : 1; + } else if (velocityY < 0 && deltaY < 0) { + targetPage = mCurItem == 1 ? 4 : 1; } } else { - targetPage = (int) Math.round(mCurItem + pageOffset); + int hThresh = getBehindWidth()/2; + int vThresh = getBehindHeight()/2; + if (mCurItem == 1) { + if (mDraggingHoz) { + targetPage = deltaX > hThresh ? 0 : + deltaX < -hThresh ? 2 : 1; + } else { + targetPage = deltaY > vThresh ? 3 : + deltaY < -vThresh ? 4 : 1; + } + } else { + targetPage = Math.abs(deltaY) > vThresh || Math.abs(deltaX) > hThresh ? 1 : mCurItem; + } } return targetPage; } protected float getPercentOpen() { - return Math.abs(mScrollX-mContent.getLeft()) / getBehindWidth(); + // TODO check old : mScrollX == 0 + if (!mDraggingHoz) { + return Math.abs(mScrollY-mContent.getTop()) / getBehindHeight(); + } else { + return Math.abs(mScrollX-mContent.getLeft()) / getBehindWidth(); + } } @Override @@ -848,6 +916,7 @@ protected void dispatchDraw(Canvas canvas) { // variables for drawing private float mScrollX = 0.0f; + private float mScrollY = 0.0f; private void onSecondaryPointerUp(MotionEvent ev) { if (DEBUG) Log.v(TAG, "onSecondaryPointerUp called"); diff --git a/library/src/com/slidingmenu/lib/CustomViewBehind.java b/library/src/com/slidingmenu/lib/CustomViewBehind.java index 1432d4ae1..6cf11fbdb 100644 --- a/library/src/com/slidingmenu/lib/CustomViewBehind.java +++ b/library/src/com/slidingmenu/lib/CustomViewBehind.java @@ -1,17 +1,24 @@ package com.slidingmenu.lib; +import java.util.ArrayList; + +import android.annotation.TargetApi; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.drawable.Drawable; +import android.os.Build; import android.util.AttributeSet; -import android.util.Log; import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import static com.slidingmenu.lib.SlidingMode.LEFT; +import static com.slidingmenu.lib.SlidingMode.RIGHT; +import static com.slidingmenu.lib.SlidingMode.TOP; +import static com.slidingmenu.lib.SlidingMode.BOTTOM; import com.slidingmenu.lib.SlidingMenu.CanvasTransformer; @@ -24,12 +31,28 @@ public class CustomViewBehind extends ViewGroup { private CustomViewAbove mViewAbove; - private View mContent; - private View mSecondaryContent; + private static class Side { + public int side; + public View view = null; + public Drawable shadow = null; + public int shadowWidth = 0; + public int offset = 0; + public float scrollScale = 0.0f; + public Side(int side) { + this.side = side; + } + } + + private ArrayList mSides = new ArrayList(); + private int mMarginThreshold; - private int mWidthOffset; + private CanvasTransformer mTransformer; - private boolean mChildrenEnabled; + + private int mMode; + private boolean mFadeEnabled; + private final Paint mFadePaint = new Paint(); + private float mFadeDegree; public CustomViewBehind(Context context) { this(context, null); @@ -39,6 +62,8 @@ public CustomViewBehind(Context context, AttributeSet attrs) { super(context, attrs); mMarginThreshold = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, MARGIN_THRESHOLD, getResources().getDisplayMetrics()); + for (int side : SlidingMode.SIDES) + mSides.add(new Side(side)); } public void setCustomViewAbove(CustomViewAbove customViewAbove) { @@ -49,43 +74,59 @@ public void setCanvasTransformer(CanvasTransformer t) { mTransformer = t; } - public void setWidthOffset(int i) { - mWidthOffset = i; + public void setWidthOffset(int i, int side) { + // mWidthOffset = i; + Side s = getSide(side); + s.offset = i; requestLayout(); } - public int getBehindWidth() { - return mContent.getWidth(); - } - - public void setContent(View v) { - if (mContent != null) - removeView(mContent); - mContent = v; - addView(mContent); + public int getBehindWidth(int page) { + switch (page) { + case 0: + if (SlidingMode.isLeft(mMode) && getContent(LEFT) != null) + return getContent(LEFT).getWidth(); + break; + case 2: + if (SlidingMode.isRight(mMode) && getContent(RIGHT) != null) + return getContent(RIGHT).getWidth(); + break; + } + return getWidth(); } - public View getContent() { - return mContent; + public int getBehindHeight(int page) { + switch (page) { + case 3: + if (SlidingMode.isTop(mMode) && getContent(TOP) != null) + return getContent(TOP).getHeight(); + case 4: + if (SlidingMode.isBottom(mMode) && getContent(BOTTOM) != null) + return getContent(BOTTOM).getHeight(); + } + return getHeight(); } - /** - * Sets the secondary (right) menu for use when setMode is called with SlidingMenu.LEFT_RIGHT. - * @param v the right menu - */ - public void setSecondaryContent(View v) { - if (mSecondaryContent != null) - removeView(mSecondaryContent); - mSecondaryContent = v; - addView(mSecondaryContent); + private Side getSide(int side) { + for (Side s : mSides) + if ((s.side & side) == side) + return s; + return null; } - public View getSecondaryContent() { - return mSecondaryContent; + public View getContent(int side) { + return getSide(side).view; } - public void setChildrenEnabled(boolean enabled) { - mChildrenEnabled = enabled; + public void setContent(View v, int side) { + Side s = getSide(side); + if (s.view != null) { + removeView(s.view); + } + if (v != null) { + s.view = v; + addView(v); + } } @Override @@ -97,12 +138,12 @@ public void scrollTo(int x, int y) { @Override public boolean onInterceptTouchEvent(MotionEvent e) { - return !mChildrenEnabled; + return getVisibility() == View.INVISIBLE; } @Override public boolean onTouchEvent(MotionEvent e) { - return !mChildrenEnabled; + return getVisibility() == View.INVISIBLE; } @Override @@ -120,9 +161,14 @@ protected void dispatchDraw(Canvas canvas) { protected void onLayout(boolean changed, int l, int t, int r, int b) { final int width = r - l; final int height = b - t; - mContent.layout(0, 0, width-mWidthOffset, height); - if (mSecondaryContent != null) - mSecondaryContent.layout(0, 0, width-mWidthOffset, height); + for (Side s : mSides) { + if (s.view == null) + continue; + if (SlidingMode.isTop(s.side) || SlidingMode.isBottom(s.side)) + s.view.layout(0, 0, width, height-s.offset); + else if (SlidingMode.isLeft(s.side) || SlidingMode.isRight(s.side)) + s.view.layout(0, 0, width-s.offset, height); + } } @Override @@ -130,29 +176,34 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = getDefaultSize(0, widthMeasureSpec); int height = getDefaultSize(0, heightMeasureSpec); setMeasuredDimension(width, height); - final int contentWidth = getChildMeasureSpec(widthMeasureSpec, 0, width-mWidthOffset); - final int contentHeight = getChildMeasureSpec(heightMeasureSpec, 0, height); - mContent.measure(contentWidth, contentHeight); - if (mSecondaryContent != null) - mSecondaryContent.measure(contentWidth, contentHeight); + for (Side s : mSides) { + if (s.view == null) + continue; + int contentW = getChildMeasureSpec(widthMeasureSpec, 0, + width-(isVertical(s.side) ? 0 : s.offset)); + int contentH = getChildMeasureSpec(heightMeasureSpec, 0, + height-(isVertical(s.side) ? s.offset : 0)); + s.view.measure(contentW, contentH); + } } - private int mMode; - private boolean mFadeEnabled; - private final Paint mFadePaint = new Paint(); - private float mScrollScale; - private Drawable mShadowDrawable; - private Drawable mSecondaryShadowDrawable; - private int mShadowWidth; - private float mFadeDegree; + public int correctMenuPage(int page) { + if ((page == 0 && !SlidingMode.isLeft(mMode)) || + (page == 2 && !SlidingMode.isRight(mMode)) || + (page == 3 && !SlidingMode.isTop(mMode)) || + (page == 4 && !SlidingMode.isBottom(mMode))) + return 1; + return page; + } + + private boolean isVertical(int side) { + return SlidingMode.isTop(side) || SlidingMode.isBottom(side); + } public void setMode(int mode) { - if (mode == SlidingMenu.LEFT || mode == SlidingMenu.RIGHT) { - if (mContent != null) - mContent.setVisibility(View.VISIBLE); - if (mSecondaryContent != null) - mSecondaryContent.setVisibility(View.INVISIBLE); - } + for (Side s : mSides) + if (s.view != null) + s.view.setVisibility((s.side & mode) == s.side ? View.VISIBLE : View.GONE); mMode = mode; } @@ -160,26 +211,22 @@ public int getMode() { return mMode; } - public void setScrollScale(float scrollScale) { - mScrollScale = scrollScale; - } - - public float getScrollScale() { - return mScrollScale; + public void setScrollScale(float scrollScale, int side) { + getSide(side).scrollScale = scrollScale; } - public void setShadowDrawable(Drawable shadow) { - mShadowDrawable = shadow; - invalidate(); + public float getScrollScale(int side) { + return getSide(side).scrollScale; } - public void setSecondaryShadowDrawable(Drawable shadow) { - mSecondaryShadowDrawable = shadow; + public void setShadowDrawable(Drawable shadow, int side) { + Side s = getSide(side); + s.shadow = shadow; invalidate(); } - public void setShadowWidth(int width) { - mShadowWidth = width; + public void setShadowWidth(int width, int side) { + getSide(side).shadowWidth = width; invalidate(); } @@ -193,97 +240,138 @@ public void setFadeDegree(float degree) { mFadeDegree = degree; } - public int getMenuPage(int page) { - page = (page > 1) ? 2 : ((page < 1) ? 0 : page); - if (mMode == SlidingMenu.LEFT && page > 1) { - return 0; - } else if (mMode == SlidingMenu.RIGHT && page < 1) { - return 2; - } else { - return page; + public void scrollBehindTo(View content, int x, int y) { + + setVisibility(x == 0 && y == 0 ? View.INVISIBLE : View.VISIBLE); + + if (SlidingMode.isLeft(mMode)) { + Side s = getSide(LEFT); + if (s.view != null) { + s.view.setVisibility(x >= content.getLeft() ? View.INVISIBLE : View.VISIBLE); + if (x <= content.getLeft()) + scrollTo((int)((x + s.view.getWidth())*s.scrollScale), y); + } + } + + if (SlidingMode.isRight(mMode)) { + Side s = getSide(RIGHT); + if (s.view != null) { + s.view.setVisibility(x <= content.getLeft() ? View.INVISIBLE : View.VISIBLE); + if (x > content.getLeft()) + scrollTo((int)(s.view.getWidth() - getWidth() + + (x-s.view.getWidth())*s.scrollScale), y); + } } - } - public void scrollBehindTo(View content, int x, int y) { - int vis = View.VISIBLE; - if (mMode == SlidingMenu.LEFT) { - if (x >= content.getLeft()) vis = View.INVISIBLE; - scrollTo((int)((x + getBehindWidth())*mScrollScale), y); - } else if (mMode == SlidingMenu.RIGHT) { - if (x <= content.getLeft()) vis = View.INVISIBLE; - scrollTo((int)(getBehindWidth() - getWidth() + - (x-getBehindWidth())*mScrollScale), y); - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - mContent.setVisibility(x >= content.getLeft() ? View.INVISIBLE : View.VISIBLE); - mSecondaryContent.setVisibility(x <= content.getLeft() ? View.INVISIBLE : View.VISIBLE); - vis = x == 0 ? View.INVISIBLE : View.VISIBLE; - if (x <= content.getLeft()) { - scrollTo((int)((x + getBehindWidth())*mScrollScale), y); - } else { - scrollTo((int)(getBehindWidth() - getWidth() + - (x-getBehindWidth())*mScrollScale), y); + if (SlidingMode.isTop(mMode)) { + Side s = getSide(TOP); + if (s.view != null) { + s.view.setVisibility(y >= content.getTop() ? View.INVISIBLE : View.VISIBLE); + if (y <= content.getTop()) { + scrollTo(x, (int) ((y + s.view.getHeight()) * s.scrollScale)); + } } } - if (vis == View.INVISIBLE) - Log.v(TAG, "behind INVISIBLE"); - setVisibility(vis); + + if (SlidingMode.isBottom(mMode)) { + Side s = getSide(BOTTOM); + if (s.view != null) { + s.view.setVisibility(y < content.getTop() ? View.INVISIBLE : View.VISIBLE); + if (y > content.getTop()) { + scrollTo(x, (int) (s.view.getHeight() - getHeight() + + (y - s.view.getHeight()) * s.scrollScale)); + } + } + } + } public int getMenuLeft(View content, int page) { - if (mMode == SlidingMenu.LEFT) { - switch (page) { - case 0: - return content.getLeft() - getBehindWidth(); - case 2: - return content.getLeft(); - } - } else if (mMode == SlidingMenu.RIGHT) { + if (SlidingMode.isLeft(mMode) && SlidingMode.isRight(mMode)) { switch (page) { case 0: - return content.getLeft(); + return content.getLeft() - getContent(LEFT).getWidth(); case 2: - return content.getLeft() + getBehindWidth(); + return content.getLeft() + getContent(RIGHT).getWidth(); } - } else if (mMode == SlidingMenu.LEFT_RIGHT) { + } else if (SlidingMode.isLeft(mMode)) { + return content.getLeft() - getContent(LEFT).getWidth(); + } else if (SlidingMode.isRight(mMode)) { + return content.getLeft() + getContent(RIGHT).getWidth(); + } + return content.getLeft(); + } + + public int getMenuTop(View content, int page) { + if (SlidingMode.isTop(mMode) && SlidingMode.isBottom(mMode)) { switch (page) { - case 0: - return content.getLeft() - getBehindWidth(); - case 2: - return content.getLeft() + getBehindWidth(); + case 3: + return content.getTop() - getContent(TOP).getHeight(); + case 4: + return content.getTop() + getContent(BOTTOM).getHeight(); } + } else if (SlidingMode.isTop(mMode)) { + return content.getTop() - getContent(TOP).getHeight(); + } else if (SlidingMode.isBottom(mMode)) { + return content.getTop() + getContent(BOTTOM).getHeight(); } - return content.getLeft(); + return content.getTop(); } public int getAbsLeftBound(View content) { - if (mMode == SlidingMenu.LEFT || mMode == SlidingMenu.LEFT_RIGHT) { - return content.getLeft() - getBehindWidth(); - } else if (mMode == SlidingMenu.RIGHT) { - return content.getLeft(); + if (SlidingMode.isLeft(mMode)) { + return content.getLeft() - getContent(LEFT).getWidth(); } - return 0; + return content.getLeft(); } public int getAbsRightBound(View content) { - if (mMode == SlidingMenu.LEFT) { - return content.getLeft(); - } else if (mMode == SlidingMenu.RIGHT || mMode == SlidingMenu.LEFT_RIGHT) { - return content.getLeft() + getBehindWidth(); + if (SlidingMode.isRight(mMode)) { + return content.getLeft() + getContent(RIGHT).getWidth(); + } + return content.getLeft(); + } + + public int getAbsTopBound(View content) { + if (SlidingMode.isTop(mMode)) { + return content.getTop() - getContent(TOP).getHeight(); + } + return content.getTop(); + } + + public int getAbsBottomBound(View content) { + if (SlidingMode.isBottom(mMode)) { + return content.getTop() + getContent(BOTTOM).getHeight(); } return 0; } - public boolean marginTouchAllowed(View content, int x) { + public boolean menuClosedTouchAllowed(View content, int x, int y) { int left = content.getLeft(); int right = content.getRight(); - if (mMode == SlidingMenu.LEFT) { - return (x >= left && x <= mMarginThreshold + left); - } else if (mMode == SlidingMenu.RIGHT) { - return (x <= right && x >= right - mMarginThreshold); - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - return (x >= left && x <= mMarginThreshold + left) || - (x <= right && x >= right - mMarginThreshold); - } + int top = content.getTop(); + int bottom = content.getBottom(); + boolean touch = false; + if (SlidingMode.isLeft(mMode)) + touch |= (x >= left && x <= mMarginThreshold + left); + if (SlidingMode.isRight(mMode)) + touch |= (x <= right && x >= right - mMarginThreshold); + if (SlidingMode.isTop(mMode)) + touch |= (y >= top && y <= mMarginThreshold + top); + if (SlidingMode.isBottom(mMode)) + touch |= (y <= bottom && y >= bottom - mMarginThreshold); + return touch; + } + + public boolean menuClosedTouchHoz(View content, int x, int y) { + int left = content.getLeft(); + int right = content.getRight(); + if (SlidingMode.isLeft(mMode)) + if (x >= left && x <= mMarginThreshold + left) + return true; + if (SlidingMode.isRight(mMode)) + if (x <= right && x >= right - mMarginThreshold) + return true; return false; } @@ -291,92 +379,140 @@ public void setTouchMode(int i) { mTouchMode = i; } - public boolean menuOpenTouchAllowed(View content, int currPage, float x) { + public boolean menuOpenTouchAllowed(View content, int currPage, float x, float y) { switch (mTouchMode) { case SlidingMenu.TOUCHMODE_FULLSCREEN: return true; case SlidingMenu.TOUCHMODE_MARGIN: - return menuTouchInQuickReturn(content, currPage, x); + return menuTouchInQuickReturn(content, currPage, x, y); } return false; } - public boolean menuTouchInQuickReturn(View content, int currPage, float x) { - if (mMode == SlidingMenu.LEFT || (mMode == SlidingMenu.LEFT_RIGHT && currPage == 0)) { - return x >= content.getLeft(); - } else if (mMode == SlidingMenu.RIGHT || (mMode == SlidingMenu.LEFT_RIGHT && currPage == 2)) { - return x <= content.getRight(); + public boolean menuTouchInQuickReturn(View content, int currPage, float x, float y) { + boolean allowed = false; + if (SlidingMode.isLeft(mMode) && currPage == 0) { + allowed |= x >= content.getLeft(); } - return false; + if (SlidingMode.isRight(mMode) && currPage == 2) { + allowed |= x <= content.getRight(); + } + if (SlidingMode.isTop(mMode) && currPage == 3) { + allowed |= y >= content.getTop(); + } + if (SlidingMode.isBottom(mMode) && currPage == 4) { + allowed |= y <= content.getBottom(); + } + return allowed; } - public boolean menuClosedSlideAllowed(float dx) { - if (mMode == SlidingMenu.LEFT) { - return dx > 0; - } else if (mMode == SlidingMenu.RIGHT) { - return dx < 0; - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - return true; + public boolean menuOpenSlideAllowed(float dx, float dy, int page) { + boolean allowed = false; + if (SlidingMode.isLeft(mMode) && page == 0) { + allowed |= dx < 0; } - return false; + if (SlidingMode.isRight(mMode) && page == 2) { + allowed |= dx > 0; + } + if (SlidingMode.isTop(mMode) && page == 3) { + allowed |= dy < 0; + } + if (SlidingMode.isBottom(mMode) && page == 4) { + allowed |= dy > 0; + } + return allowed; } - public boolean menuOpenSlideAllowed(float dx) { - if (mMode == SlidingMenu.LEFT) { - return dx < 0; - } else if (mMode == SlidingMenu.RIGHT) { - return dx > 0; - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - return true; + public boolean menuClosedSlideAllowed(float dx, float dy) { + boolean allowed = false; + if (SlidingMode.isLeft(mMode)) { + allowed |= dx > 0; } - return false; + if (SlidingMode.isRight(mMode)) { + allowed |= dx < 0; + } + if (SlidingMode.isTop(mMode)) { + allowed |= dy > 0; + } + if (SlidingMode.isBottom(mMode)) { + allowed |= dy < 0; + } + return allowed; } public void drawShadow(View content, Canvas canvas) { - if (mShadowDrawable == null || mShadowWidth <= 0) return; - int left = 0; - if (mMode == SlidingMenu.LEFT) { - left = content.getLeft() - mShadowWidth; - } else if (mMode == SlidingMenu.RIGHT) { - left = content.getRight(); - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - if (mSecondaryShadowDrawable != null) { - left = content.getRight(); - mSecondaryShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight()); - mSecondaryShadowDrawable.draw(canvas); - } - left = content.getLeft() - mShadowWidth; + if (SlidingMode.isLeft(mMode)) { + Side s = getSide(LEFT); + View v = getContent(LEFT); + if (s.shadow != null && v != null && v.getVisibility() != View.INVISIBLE) + drawShadowLeft(canvas, s.shadow, content.getLeft()-s.shadowWidth, s.shadowWidth); + } + if (SlidingMode.isRight(mMode)) { + Side s = getSide(RIGHT); + View v = getContent(RIGHT); + if (s.shadow != null && v != null && v.getVisibility() != View.INVISIBLE) + drawShadowLeft(canvas, s.shadow, content.getRight(), s.shadowWidth); + } + if (SlidingMode.isTop(mMode)) { + Side s = getSide(TOP); + View v = getContent(TOP); + if (s.shadow != null && v != null && v.getVisibility() != View.INVISIBLE) + drawShadowTop(canvas, s.shadow, content.getTop()-s.shadowWidth, s.shadowWidth); } - mShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight()); - mShadowDrawable.draw(canvas); + if (SlidingMode.isBottom(mMode)) { + Side s = getSide(BOTTOM); + View v = getContent(BOTTOM); + if (s.shadow != null && v != null && v.getVisibility() != View.INVISIBLE) + drawShadowTop(canvas, s.shadow, content.getBottom(), s.shadowWidth); + } + } + + private void drawShadowLeft(Canvas canvas, Drawable d, int left, int width) { + d.setBounds(left, 0, left + width, getHeight()); + d.draw(canvas); + } + + private void drawShadowTop(Canvas canvas, Drawable d, int top, int width) { + d.setBounds(0, top, getWidth(), top + width); + d.draw(canvas); } public void drawFade(View content, Canvas canvas, float openPercent) { if (!mFadeEnabled) return; + if (openPercent == 1.0f) return; final int alpha = (int) (mFadeDegree * 255 * Math.abs(1-openPercent)); mFadePaint.setColor(Color.argb(alpha, 0, 0, 0)); int left = 0; int right = 0; - if (mMode == SlidingMenu.LEFT) { - left = content.getLeft() - getBehindWidth(); - right = content.getLeft(); - } else if (mMode == SlidingMenu.RIGHT) { - left = content.getRight(); - right = content.getRight() + getBehindWidth(); - } else if (mMode == SlidingMenu.LEFT_RIGHT) { - left = content.getLeft() - getBehindWidth(); + int top = 0; + int bottom = 0; + if (SlidingMode.isLeft(mMode)) { right = content.getLeft(); + left = right - getContent(LEFT).getWidth(); canvas.drawRect(left, 0, right, getHeight(), mFadePaint); + } + if (SlidingMode.isRight(mMode)) { left = content.getRight(); - right = content.getRight() + getBehindWidth(); + right = left + getContent(RIGHT).getWidth(); + canvas.drawRect(left, 0, right, getHeight(), mFadePaint); + } + if (SlidingMode.isTop(mMode)) { + bottom = content.getTop(); + top = bottom - getContent(TOP).getHeight(); + canvas.drawRect(0, top, getWidth(), bottom, mFadePaint); + } + if (SlidingMode.isBottom(mMode)) { + top = content.getBottom(); + bottom = top + getContent(BOTTOM).getHeight(); + canvas.drawRect(0, top, getWidth(), bottom, mFadePaint); } canvas.drawRect(left, 0, right, getHeight(), mFadePaint); } - + private boolean mSelectorEnabled = true; private Bitmap mSelectorDrawable; private View mSelectedView; - + public void drawSelector(View content, Canvas canvas, float openPercent) { if (!mSelectorEnabled) return; if (mSelectorDrawable != null && mSelectedView != null) { @@ -385,12 +521,12 @@ public void drawSelector(View content, Canvas canvas, float openPercent) { canvas.save(); int left, right, offset; offset = (int) (mSelectorDrawable.getWidth() * openPercent); - if (mMode == SlidingMenu.LEFT) { + if (SlidingMode.isLeft(mMode)) { right = content.getLeft(); left = right - offset; canvas.clipRect(left, 0, right, getHeight()); canvas.drawBitmap(mSelectorDrawable, left, getSelectorTop(), null); - } else if (mMode == SlidingMenu.RIGHT) { + } else if (SlidingMode.isRight(mMode)) { left = content.getRight(); right = left + offset; canvas.clipRect(left, 0, right, getHeight()); @@ -400,7 +536,7 @@ public void drawSelector(View content, Canvas canvas, float openPercent) { } } } - + public void setSelectorEnabled(boolean b) { mSelectorEnabled = b; } @@ -428,4 +564,12 @@ public void setSelectorBitmap(Bitmap b) { refreshDrawableState(); } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + public void setChildLayerType(int layerType) { + if (Build.VERSION.SDK_INT < 11) return; + for (Side s : mSides) + if (s.view != null) + s.view.setLayerType(layerType, null); + } + } diff --git a/library/src/com/slidingmenu/lib/SlidingMenu.java b/library/src/com/slidingmenu/lib/SlidingMenu.java index 9060ee7e3..06d54bb7d 100644 --- a/library/src/com/slidingmenu/lib/SlidingMenu.java +++ b/library/src/com/slidingmenu/lib/SlidingMenu.java @@ -52,17 +52,7 @@ public class SlidingMenu extends RelativeLayout { */ public static final int TOUCHMODE_NONE = 2; - /** Constant value for use with setMode(). Puts the menu to the left of the content. - */ - public static final int LEFT = 0; - - /** Constant value for use with setMode(). Puts the menu to the right of the content. - */ - public static final int RIGHT = 1; - - /** Constant value for use with setMode(). Puts menus to the left and right of the content. - */ - public static final int LEFT_RIGHT = 2; + private int DEFAULT_SIDE = SlidingMode.LEFT; private CustomViewAbove mViewAbove; @@ -199,7 +189,7 @@ public SlidingMenu(Context context, AttributeSet attrs) { */ public SlidingMenu(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - + LayoutParams behindParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mViewBehind = new CustomViewBehind(context); addView(mViewBehind, behindParams); @@ -228,7 +218,7 @@ public void onPageSelected(int position) { // now style everything! TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingMenu); // set the above and behind views if defined in xml - int mode = ta.getInt(R.styleable.SlidingMenu_mode, LEFT); + int mode = ta.getInt(R.styleable.SlidingMenu_mode, DEFAULT_SIDE); setMode(mode); int viewAbove = ta.getResourceId(R.styleable.SlidingMenu_viewAbove, -1); if (viewAbove != -1) { @@ -238,9 +228,9 @@ public void onPageSelected(int position) { } int viewBehind = ta.getResourceId(R.styleable.SlidingMenu_viewBehind, -1); if (viewBehind != -1) { - setMenu(viewBehind); + setMenu(viewBehind, DEFAULT_SIDE); } else { - setMenu(new FrameLayout(context)); + setMenu(new FrameLayout(context), DEFAULT_SIDE); } int touchModeAbove = ta.getInt(R.styleable.SlidingMenu_touchModeAbove, TOUCHMODE_MARGIN); setTouchModeAbove(touchModeAbove); @@ -252,16 +242,16 @@ public void onPageSelected(int position) { if (offsetBehind != -1 && widthBehind != -1) throw new IllegalStateException("Cannot set both behindOffset and behindWidth for a SlidingMenu"); else if (offsetBehind != -1) - setBehindOffset(offsetBehind); + setBehindOffset(offsetBehind, DEFAULT_SIDE); else if (widthBehind != -1) - setBehindWidth(widthBehind); + setBehindWidth(widthBehind, DEFAULT_SIDE); else - setBehindOffset(0); + setBehindOffset(0, DEFAULT_SIDE); float scrollOffsetBehind = ta.getFloat(R.styleable.SlidingMenu_behindScrollScale, 0.33f); - setBehindScrollScale(scrollOffsetBehind); + setBehindScrollScale(scrollOffsetBehind, DEFAULT_SIDE); int shadowRes = ta.getResourceId(R.styleable.SlidingMenu_shadowDrawable, -1); if (shadowRes != -1) { - setShadowDrawable(shadowRes); + setShadowDrawable(shadowRes, DEFAULT_SIDE); } int shadowWidth = (int) ta.getDimension(R.styleable.SlidingMenu_shadowWidth, 0); setShadowWidth(shadowWidth); @@ -366,8 +356,11 @@ public View getContent() { * * @param res the new content */ + public void setMenu(int res, int side) { + setMenu(LayoutInflater.from(getContext()).inflate(res, null), side); + } public void setMenu(int res) { - setMenu(LayoutInflater.from(getContext()).inflate(res, null)); + setMenu(res, DEFAULT_SIDE); } /** @@ -375,47 +368,26 @@ public void setMenu(int res) { * * @param view The desired content to display. */ + public void setMenu(View v, int side) { + if (!SlidingMode.isValidSide(side)) + throw new IllegalArgumentException("side must be either TOP, BOTTOM, LEFT, or RIGHT"); + mViewBehind.setContent(v, side); + } public void setMenu(View v) { - mViewBehind.setContent(v); + setMenu(v, DEFAULT_SIDE); } /** * Retrieves the main menu. * @return the main menu */ - public View getMenu() { - return mViewBehind.getContent(); + public View getMenu(int side) { + return mViewBehind.getContent(side); } - - /** - * Set the secondary behind view (right menu) content from a layout resource. The resource will be inflated, adding all top-level views - * to the behind view. - * - * @param res the new content - */ - public void setSecondaryMenu(int res) { - setSecondaryMenu(LayoutInflater.from(getContext()).inflate(res, null)); - } - - /** - * Set the secondary behind view (right menu) content to the given View. - * - * @param view The desired content to display. - */ - public void setSecondaryMenu(View v) { - mViewBehind.setSecondaryContent(v); - // mViewBehind.invalidate(); - } - - /** - * Retrieves the current secondary menu (right). - * @return the current menu - */ - public View getSecondaryMenu() { - return mViewBehind.getSecondaryContent(); + public View getMenu() { + return mViewBehind.getContent(DEFAULT_SIDE); } - /** * Sets the sliding enabled. * @@ -439,8 +411,8 @@ public boolean isSlidingEnabled() { * @param mode must be either SlidingMenu.LEFT or SlidingMenu.RIGHT */ public void setMode(int mode) { - if (mode != LEFT && mode != RIGHT && mode != LEFT_RIGHT) { - throw new IllegalStateException("SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT"); + if (!SlidingMode.isValidMode(mode)) { + throw new IllegalArgumentException("SlidingMenu mode must be a valid SlidingMode"); } mViewBehind.setMode(mode); } @@ -548,9 +520,9 @@ public void toggle(boolean animate) { * @return Whether or not the behind view is showing */ public boolean isMenuShowing() { - return mViewAbove.getCurrentItem() == 0 || mViewAbove.getCurrentItem() == 2; + return mViewAbove.getCurrentItem() != 1; } - + /** * Checks if is the behind view showing. * @@ -574,13 +546,17 @@ public int getBehindOffset() { * * @param i The margin, in pixels, on the right of the screen that the behind view scrolls to. */ - public void setBehindOffset(int i) { + public void setBehindOffset(int i, int side) { // RelativeLayout.LayoutParams params = ((RelativeLayout.LayoutParams)mViewBehind.getLayoutParams()); // int bottom = params.bottomMargin; // int top = params.topMargin; // int left = params.leftMargin; // params.setMargins(left, top, i, bottom); - mViewBehind.setWidthOffset(i); + mViewBehind.setWidthOffset(i, side); + } + public void setBehindOffset(int i) { + for (int side : SlidingMode.SIDES) + setBehindOffset(i, side); } /** @@ -589,9 +565,13 @@ public void setBehindOffset(int i) { * @param resID The dimension resource id to be set as the behind offset. * The menu, when open, will leave this width margin on the right of the screen. */ - public void setBehindOffsetRes(int resID) { + public void setBehindOffsetRes(int resID, int side) { int i = (int) getContext().getResources().getDimension(resID); - setBehindOffset(i); + setBehindOffset(i, side); + } + public void setBehindOffsetRes(int resId) { + for (int side : SlidingMode.SIDES) + setBehindOffsetRes(resId, side); } /** @@ -619,7 +599,7 @@ public void setAboveOffsetRes(int resID) { * @param i The width the Sliding Menu will open to, in pixels */ @SuppressWarnings("deprecation") - public void setBehindWidth(int i) { + public void setBehindWidth(int i, int side) { int width; Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); @@ -633,7 +613,11 @@ public void setBehindWidth(int i) { } catch (Exception e) { width = display.getWidth(); } - setBehindOffset(width-i); + setBehindOffset(width-i, side); + } + public void setBehindWidth(int i) { + for (int side : SlidingMode.SIDES) + setBehindWidth(i, side); } /** @@ -642,9 +626,13 @@ public void setBehindWidth(int i) { * @param res The dimension resource id to be set as the behind width offset. * The menu, when open, will open this wide. */ - public void setBehindWidthRes(int res) { + public void setBehindWidthRes(int res, int side) { int i = (int) getContext().getResources().getDimension(res); - setBehindWidth(i); + setBehindWidth(i, side); + } + public void setBehindWidthRes(int res) { + for (int side : SlidingMode.SIDES) + setBehindWidthRes(res, side); } /** @@ -652,8 +640,11 @@ public void setBehindWidthRes(int res) { * * @return The scale of the parallax scroll */ + public float getBehindScrollScale(int side) { + return mViewBehind.getScrollScale(side); + } public float getBehindScrollScale() { - return mViewBehind.getScrollScale(); + return mViewBehind.getScrollScale(DEFAULT_SIDE); } /** @@ -662,10 +653,14 @@ public float getBehindScrollScale() { * @param f The scale of the parallax scroll (i.e. 1.0f scrolls 1 pixel for every * 1 pixel that the above view scrolls and 0.0f scrolls 0 pixels) */ - public void setBehindScrollScale(float f) { + public void setBehindScrollScale(float f, int side) { if (f < 0 && f > 1) throw new IllegalStateException("ScrollScale must be between 0 and 1"); - mViewBehind.setScrollScale(f); + mViewBehind.setScrollScale(f, side); + } + public void setBehindScrollScale(float f) { + for (int side : SlidingMode.SIDES) + setBehindScrollScale(f, side); } /** @@ -723,8 +718,11 @@ public void setTouchModeBehind(int i) { * * @param resId the resource ID of the new shadow drawable */ + public void setShadowDrawable(int resId, int side) { + setShadowDrawable(getContext().getResources().getDrawable(resId), side); + } public void setShadowDrawable(int resId) { - setShadowDrawable(getContext().getResources().getDrawable(resId)); + setShadowDrawable(resId, DEFAULT_SIDE); } /** @@ -732,26 +730,13 @@ public void setShadowDrawable(int resId) { * * @param d the new shadow drawable */ - public void setShadowDrawable(Drawable d) { - mViewBehind.setShadowDrawable(d); + public void setShadowDrawable(Drawable d, int side) { + if (!SlidingMode.isValidSide(side)) + throw new IllegalArgumentException("side must be either TOP, BOTTOM, LEFT, or RIGHT"); + mViewBehind.setShadowDrawable(d, side); } - - /** - * Sets the secondary (right) shadow drawable. - * - * @param resId the resource ID of the new shadow drawable - */ - public void setSecondaryShadowDrawable(int resId) { - setSecondaryShadowDrawable(getContext().getResources().getDrawable(resId)); - } - - /** - * Sets the secondary (right) shadow drawable. - * - * @param d the new shadow drawable - */ - public void setSecondaryShadowDrawable(Drawable d) { - mViewBehind.setSecondaryShadowDrawable(d); + public void setShadowDrawable(Drawable d) { + setShadowDrawable(d, DEFAULT_SIDE); } /** @@ -768,8 +753,12 @@ public void setShadowWidthRes(int resId) { * * @param pixels the new shadow width, in pixels */ + public void setShadowWidth(int pixels, int side) { + mViewBehind.setShadowWidth(pixels, side); + } public void setShadowWidth(int pixels) { - mViewBehind.setShadowWidth(pixels); + for (int side : SlidingMode.SIDES) + setShadowWidth(pixels, side); } /** @@ -965,7 +954,7 @@ protected boolean fitSystemWindows(Rect insets) { } return true; } - + private Handler mHandler = new Handler(); @TargetApi(Build.VERSION_CODES.HONEYCOMB) @@ -978,12 +967,8 @@ public void manageLayers(float percentOpen) { if (layerType != getContent().getLayerType()) { mHandler.post(new Runnable() { public void run() { - Log.v(TAG, "changing layerType. hardware? " + (layerType == View.LAYER_TYPE_HARDWARE)); getContent().setLayerType(layerType, null); - getMenu().setLayerType(layerType, null); - if (getSecondaryMenu() != null) { - getSecondaryMenu().setLayerType(layerType, null); - } + mViewBehind.setChildLayerType(layerType); } }); } diff --git a/library/src/com/slidingmenu/lib/SlidingMode.java b/library/src/com/slidingmenu/lib/SlidingMode.java new file mode 100644 index 000000000..d75f83c20 --- /dev/null +++ b/library/src/com/slidingmenu/lib/SlidingMode.java @@ -0,0 +1,59 @@ +package com.slidingmenu.lib; + +public class SlidingMode +{ + + public static final int DISABLED = 0x0000; + /** + * Constant value for use with setMode(). Puts the menu to the left of the content. + */ + public static final int LEFT = 0x0001; + /** + * Constant value for use with setMode(). Puts the menu to the right of the content. + */ + public static final int RIGHT = 0x0010; + /** + * Constant bit mask for left and right menu. Will allow a left and right menu each side of the content. + */ + public static final int LEFT_RIGHT = LEFT | RIGHT; + /** + * Constant value for use with setMode(). Puts menus to Bottom mode + */ + public static final int TOP = 0x0100; + /** + * Constant value for use with setMode(). Puts menus to Bottom mode + */ + public static final int BOTTOM = 0x1000; + + /** + * Constat value for use with setMode(). Puts menus to Bottom and Top mode. + */ + public static final int TOP_BOTTOM = TOP | BOTTOM; + + public static final int[] SIDES = new int[] {LEFT, RIGHT, TOP, BOTTOM}; + + public static boolean isLeft(int mode) { + return (mode & LEFT) == LEFT; + } + + public static boolean isRight(int mode) { + return (mode & RIGHT) == RIGHT; + } + + public static boolean isTop(int mode) { + return (mode & TOP) == TOP; + } + + public static boolean isBottom(int mode) { + return (mode & BOTTOM) == BOTTOM; + } + + public static boolean isValidMode(int mode) { + return mode > DISABLED && mode <= (TOP|BOTTOM|LEFT|RIGHT); + } + + public static boolean isValidSide(int side) { + return side == LEFT || side == RIGHT || side == TOP || side == BOTTOM; + } + +} diff --git a/library/src/com/slidingmenu/lib/app/SlidingActivityHelper.java b/library/src/com/slidingmenu/lib/app/SlidingActivityHelper.java index 2128df8b9..12ab57e95 100644 --- a/library/src/com/slidingmenu/lib/app/SlidingActivityHelper.java +++ b/library/src/com/slidingmenu/lib/app/SlidingActivityHelper.java @@ -10,6 +10,7 @@ import com.slidingmenu.lib.R; import com.slidingmenu.lib.SlidingMenu; +import com.slidingmenu.lib.SlidingMode; public class SlidingActivityHelper { @@ -160,7 +161,7 @@ public void setContentView(View v) { */ public void setBehindContentView(View view, LayoutParams layoutParams) { mViewBehind = view; - mSlidingMenu.setMenu(mViewBehind); + mSlidingMenu.setMenu(mViewBehind, SlidingMode.LEFT); } /** diff --git a/library/src/com/slidingmenu/lib/app/SlidingFragmentActivity.java b/library/src/com/slidingmenu/lib/app/SlidingFragmentActivity.java index a5eddae74..be8f0f40e 100644 --- a/library/src/com/slidingmenu/lib/app/SlidingFragmentActivity.java +++ b/library/src/com/slidingmenu/lib/app/SlidingFragmentActivity.java @@ -1,14 +1,14 @@ package com.slidingmenu.lib.app; import android.os.Bundle; -import android.support.v4.app.FragmentActivity; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup.LayoutParams; +import com.actionbarsherlock.app.SherlockFragmentActivity; import com.slidingmenu.lib.SlidingMenu; -public class SlidingFragmentActivity extends FragmentActivity implements SlidingActivityBase { +public class SlidingFragmentActivity extends SherlockFragmentActivity implements SlidingActivityBase { private SlidingActivityHelper mHelper; diff --git a/library/src/com/slidingmenu/lib/app/SlidingMapActivity.java b/library/src/com/slidingmenu/lib/app/SlidingMapActivity.java deleted file mode 100644 index f70133f95..000000000 --- a/library/src/com/slidingmenu/lib/app/SlidingMapActivity.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.slidingmenu.lib.app; - -import android.os.Bundle; -import android.view.KeyEvent; -import android.view.View; -import android.view.ViewGroup.LayoutParams; - -import com.google.android.maps.MapActivity; -import com.slidingmenu.lib.SlidingMenu; - -public abstract class SlidingMapActivity extends MapActivity implements SlidingActivityBase { - - private SlidingActivityHelper mHelper; - - /* (non-Javadoc) - * @see com.google.android.maps.MapActivity#onCreate(android.os.Bundle) - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mHelper = new SlidingActivityHelper(this); - mHelper.onCreate(savedInstanceState); - } - - /* (non-Javadoc) - * @see android.app.Activity#onPostCreate(android.os.Bundle) - */ - @Override - public void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - mHelper.onPostCreate(savedInstanceState); - } - - /* (non-Javadoc) - * @see android.app.Activity#findViewById(int) - */ - @Override - public View findViewById(int id) { - View v = super.findViewById(id); - if (v != null) - return v; - return mHelper.findViewById(id); - } - - /* (non-Javadoc) - * @see android.app.Activity#onSaveInstanceState(android.os.Bundle) - */ - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mHelper.onSaveInstanceState(outState); - } - - /* (non-Javadoc) - * @see android.app.Activity#setContentView(int) - */ - @Override - public void setContentView(int id) { - setContentView(getLayoutInflater().inflate(id, null)); - } - - /* (non-Javadoc) - * @see android.app.Activity#setContentView(android.view.View) - */ - @Override - public void setContentView(View v) { - setContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); - } - - /* (non-Javadoc) - * @see android.app.Activity#setContentView(android.view.View, android.view.ViewGroup.LayoutParams) - */ - @Override - public void setContentView(View v, LayoutParams params) { - super.setContentView(v, params); - mHelper.registerAboveContentView(v, params); - } - - /* (non-Javadoc) - * @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(int) - */ - public void setBehindContentView(int id) { - setBehindContentView(getLayoutInflater().inflate(id, null)); - } - - /* (non-Javadoc) - * @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(android.view.View) - */ - public void setBehindContentView(View v) { - setBehindContentView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); - } - - /* (non-Javadoc) - * @see com.slidingmenu.lib.app.SlidingActivityBase#setBehindContentView(android.view.View, android.view.ViewGroup.LayoutParams) - */ - public void setBehindContentView(View v, LayoutParams params) { - mHelper.setBehindContentView(v, params); - } - - /* (non-Javadoc) - * @see com.slidingmenu.lib.app.SlidingActivityBase#getSlidingMenu() - */ - public SlidingMenu getSlidingMenu() { - return mHelper.getSlidingMenu(); - } - - /* (non-Javadoc) - * @see com.slidingmenu.lib.app.SlidingActivityBase#toggle() - */ - public void toggle() { - mHelper.toggle(); - } - - /* (non-Javadoc) - * @see com.slidingmenu.lib.app.SlidingActivityBase#showAbove() - */ - public void showContent() { - mHelper.showContent(); - } - - /* (non-Javadoc) - * @see com.slidingmenu.lib.app.SlidingActivityBase#showBehind() - */ - public void showMenu() { - mHelper.showMenu(); - } - - /* (non-Javadoc) - * @see com.slidingmenu.lib.app.SlidingActivityBase#showSecondaryMenu() - */ - public void showSecondaryMenu() { - mHelper.showSecondaryMenu(); - } - - /* (non-Javadoc) - * @see com.slidingmenu.lib.app.SlidingActivityBase#setSlidingActionBarEnabled(boolean) - */ - public void setSlidingActionBarEnabled(boolean b) { - mHelper.setSlidingActionBarEnabled(b); - } - - /* (non-Javadoc) - * @see android.app.Activity#onKeyUp(int, android.view.KeyEvent) - */ - @Override - public boolean onKeyUp(int keyCode, KeyEvent event) { - boolean b = mHelper.onKeyUp(keyCode, event); - if (b) return b; - return super.onKeyUp(keyCode, event); - } - -} diff --git a/library/src/com/slidingmenu/lib/app/SlidingPreferenceActivity.java b/library/src/com/slidingmenu/lib/app/SlidingPreferenceActivity.java index 403ab0cb3..50db0b493 100644 --- a/library/src/com/slidingmenu/lib/app/SlidingPreferenceActivity.java +++ b/library/src/com/slidingmenu/lib/app/SlidingPreferenceActivity.java @@ -1,13 +1,13 @@ package com.slidingmenu.lib.app; -import com.slidingmenu.lib.SlidingMenu; - import android.os.Bundle; import android.preference.PreferenceActivity; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup.LayoutParams; +import com.slidingmenu.lib.SlidingMenu; + public class SlidingPreferenceActivity extends PreferenceActivity implements SlidingActivityBase { private SlidingActivityHelper mHelper;