diff --git a/.gitignore b/.gitignore index 9eed7dbf6..f94c1adaf 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ gen target/ *.iml +build \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 000000000..eb30e1d18 --- /dev/null +++ b/build.gradle @@ -0,0 +1,18 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.2.1' + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} diff --git a/library/build.gradle b/library/build.gradle index e2a5bf978..1d386eb21 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,37 +1,29 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:0.4.+' - } -} -apply plugin: 'android-library' +apply plugin: 'com.android.library' dependencies { - compile 'com.android.support:support-v4:13.0.0' + compile 'com.android.support:support-v4:24.2.1' } android { - compileSdkVersion 17 - buildToolsVersion "17.0.0" + compileSdkVersion 24 + buildToolsVersion "24.0.2" - defaultConfig { - minSdkVersion 7 - targetSdkVersion 16 - } + defaultConfig { + minSdkVersion 15 + targetSdkVersion 24 + } - sourceSets { - main { - java.srcDirs = ['src'] - resources.srcDirs = ['src'] - aidl.srcDirs = ['src'] - renderscript.srcDirs = ['src'] - res.srcDirs = ['res'] - assets.srcDirs = ['assets'] + sourceSets { + main { + java.srcDirs = ['src'] + resources.srcDirs = ['src'] + aidl.srcDirs = ['src'] + renderscript.srcDirs = ['src'] + res.srcDirs = ['res'] + assets.srcDirs = ['assets'] - manifest.srcFile 'AndroidManifest.xml' - } - } + manifest.srcFile 'AndroidManifest.xml' + } + } } diff --git a/library/library.iml b/library/library.iml index a6e3c8f47..5328d0bec 100644 --- a/library/library.iml +++ b/library/library.iml @@ -1,19 +1,115 @@ - + + + + + + - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + - - + \ No newline at end of file diff --git a/library/src/com/jeremyfeinstein/slidingmenu/lib/CustomViewAbove.java b/library/src/com/jeremyfeinstein/slidingmenu/lib/CustomViewAbove.java index fa73ef05b..0d6f53dff 100644 --- a/library/src/com/jeremyfeinstein/slidingmenu/lib/CustomViewAbove.java +++ b/library/src/com/jeremyfeinstein/slidingmenu/lib/CustomViewAbove.java @@ -1,8 +1,5 @@ package com.jeremyfeinstein.slidingmenu.lib; -import java.util.ArrayList; -import java.util.List; - import android.content.Context; import android.graphics.Canvas; import android.graphics.Rect; @@ -13,7 +10,6 @@ import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewConfigurationCompat; import android.util.AttributeSet; -import android.util.FloatMath; import android.util.Log; import android.view.FocusFinder; import android.view.KeyEvent; @@ -28,6 +24,9 @@ import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnClosedListener; import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnOpenedListener; + +import java.util.ArrayList; +import java.util.List; //import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnCloseListener; //import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnOpenListener; @@ -110,12 +109,12 @@ public interface OnPageChangeListener { * This method will be invoked when the current page is scrolled, either as part * of a programmatically initiated smooth scroll or a user initiated touch scroll. * - * @param position Position index of the first page currently being displayed. - * Page position+1 will be visible if positionOffset is nonzero. - * @param positionOffset Value from [0, 1) indicating the offset from the page at position. + * @param position Position index of the first page currently being displayed. + * Page position+1 will be visible if positionOffset is nonzero. + * @param positionOffset Value from [0, 1) indicating the offset from the page at position. * @param positionOffsetPixels Value in pixels indicating the offset from position. */ - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels); + void onPageScrolled(int position, float positionOffset, int positionOffsetPixels); /** * This method will be invoked when a new page becomes selected. Animation is not @@ -123,7 +122,7 @@ public interface OnPageChangeListener { * * @param position Position index of the new selected page. */ - public void onPageSelected(int position); + void onPageSelected(int position); } @@ -171,13 +170,13 @@ void initCustomViewAbove() { public void onPageSelected(int position) { if (mViewBehind != null) { switch (position) { - case 0: - case 2: - mViewBehind.setChildrenEnabled(true); - break; - case 1: - mViewBehind.setChildrenEnabled(false); - break; + case 0: + case 2: + mViewBehind.setChildrenEnabled(true); + break; + case 1: + mViewBehind.setChildrenEnabled(false); + break; } } } @@ -201,7 +200,7 @@ public void setCurrentItem(int item) { /** * Set the currently selected page. * - * @param item Item index to select + * @param item Item index to select * @param smoothScroll True to smoothly scroll to the new item, false to transition immediately */ public void setCurrentItem(int item, boolean smoothScroll) { @@ -250,6 +249,7 @@ void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int public void setOnPageChangeListener(OnPageChangeListener listener) { mOnPageChangeListener = listener; } + /* public void setOnOpenListener(OnOpenListener l) { mOpenListener = l; @@ -300,16 +300,16 @@ public void clearIgnoredViews() { float distanceInfluenceForSnapDuration(float f) { f -= 0.5f; // center the values about 0. f *= 0.3f * Math.PI / 2.0f; - return (float) FloatMath.sin(f); + return (float) Math.sin(f); } public int getDestScrollX(int page) { switch (page) { - case 0: - case 2: - return mViewBehind.getMenuLeft(mContent, page); - case 1: - return mContent.getLeft(); + case 0: + case 2: + return mViewBehind.getMenuLeft(mContent, page); + case 1: + return mContent.getLeft(); } return 0; } @@ -334,7 +334,7 @@ private boolean isInIgnoredView(MotionEvent ev) { Rect rect = new Rect(); for (View v : mIgnoredViews) { v.getHitRect(rect); - if (rect.contains((int)ev.getX(), (int)ev.getY())) return true; + if (rect.contains((int) ev.getX(), (int) ev.getY())) return true; } return false; } @@ -349,12 +349,12 @@ public int getBehindWidth() { public int getChildWidth(int i) { switch (i) { - case 0: - return getBehindWidth(); - case 1: - return mContent.getWidth(); - default: - return 0; + case 0: + return getBehindWidth(); + case 1: + return mContent.getWidth(); + default: + return 0; } } @@ -379,8 +379,8 @@ void smoothScrollTo(int x, int y) { /** * Like {@link View#scrollBy}, but scroll smoothly instead of immediately. * - * @param x the number of pixels to scroll by on the X axis - * @param y the number of pixels to scroll by on the Y axis + * @param x the number of pixels to scroll by on the X axis + * @param y the number of pixels to scroll by on the Y axis * @param velocity the velocity associated with a fling, if applicable. (0 otherwise) */ void smoothScrollTo(int x, int y, int velocity) { @@ -430,7 +430,7 @@ void smoothScrollTo(int x, int y, int velocity) { } public void setContent(View v) { - if (mContent != null) + if (mContent != null) this.removeView(mContent); mContent = v; addView(mContent); @@ -479,8 +479,8 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { public void setAboveOffset(int i) { // RelativeLayout.LayoutParams params = ((RelativeLayout.LayoutParams)mContent.getLayoutParams()); // params.setMargins(i, params.topMargin, params.rightMargin, params.bottomMargin); - mContent.setPadding(i, mContent.getPaddingTop(), - mContent.getPaddingRight(), mContent.getPaddingBottom()); + mContent.setPadding(i, mContent.getPaddingTop(), + mContent.getPaddingRight(), mContent.getPaddingBottom()); } @@ -524,9 +524,9 @@ private void pageScrolled(int xpos) { * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled * returns. * - * @param position Position index of the first page currently being displayed. - * Page position+1 will be visible if positionOffset is nonzero. - * @param offset Value from [0, 1) indicating the offset from the page at position. + * @param position Position index of the first page currently being displayed. + * Page position+1 will be visible if positionOffset is nonzero. + * @param offset Value from [0, 1) indicating the offset from the page at position. * @param offsetPixels Value in pixels indicating the offset from position. */ protected void onPageScrolled(int position, float offset, int offsetPixels) { @@ -578,12 +578,12 @@ private boolean thisTouchAllowed(MotionEvent ev) { return mViewBehind.menuOpenTouchAllowed(mContent, mCurItem, x); } else { switch (mTouchMode) { - case SlidingMenu.TOUCHMODE_FULLSCREEN: - return !isInIgnoredView(ev); - case SlidingMenu.TOUCHMODE_NONE: - return false; - case SlidingMenu.TOUCHMODE_MARGIN: - return mViewBehind.marginTouchAllowed(mContent, x); + case SlidingMenu.TOUCHMODE_FULLSCREEN: + return !isInIgnoredView(ev); + case SlidingMenu.TOUCHMODE_NONE: + return false; + case SlidingMenu.TOUCHMODE_MARGIN: + return mViewBehind.marginTouchAllowed(mContent, x); } } return false; @@ -629,29 +629,29 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { } switch (action) { - case MotionEvent.ACTION_MOVE: - determineDrag(ev); - break; - case MotionEvent.ACTION_DOWN: - int index = MotionEventCompat.getActionIndex(ev); - mActivePointerId = MotionEventCompat.getPointerId(ev, index); - if (mActivePointerId == INVALID_POINTER) + case MotionEvent.ACTION_MOVE: + determineDrag(ev); break; - mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index); - mLastMotionY = MotionEventCompat.getY(ev, index); - if (thisTouchAllowed(ev)) { - mIsBeingDragged = false; - mIsUnableToDrag = false; - if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) { - mQuickReturn = true; + case MotionEvent.ACTION_DOWN: + int index = MotionEventCompat.getActionIndex(ev); + mActivePointerId = MotionEventCompat.getPointerId(ev, index); + if (mActivePointerId == INVALID_POINTER) + break; + mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index); + mLastMotionY = MotionEventCompat.getY(ev, index); + if (thisTouchAllowed(ev)) { + mIsBeingDragged = false; + mIsUnableToDrag = false; + if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) { + mQuickReturn = true; + } + } else { + mIsUnableToDrag = true; } - } else { - mIsUnableToDrag = true; - } - break; - case MotionEventCompat.ACTION_POINTER_UP: - onSecondaryPointerUp(ev); - break; + break; + case MotionEventCompat.ACTION_POINTER_UP: + onSecondaryPointerUp(ev); + break; } if (!mIsBeingDragged) { @@ -684,96 +684,96 @@ public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev); switch (action & MotionEventCompat.ACTION_MASK) { - case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_DOWN: /* * If being flinged and user touches, stop the fling. isFinished * will be false if being flinged. */ - completeScroll(); + completeScroll(); - // Remember where the motion event started - int index = MotionEventCompat.getActionIndex(ev); - mActivePointerId = MotionEventCompat.getPointerId(ev, index); - mLastMotionX = mInitialMotionX = ev.getX(); - break; - case MotionEvent.ACTION_MOVE: - if (!mIsBeingDragged) { - determineDrag(ev); - if (mIsUnableToDrag) - return false; - } - if (mIsBeingDragged) { - // Scroll to follow the motion event - final int activePointerIndex = getPointerIndex(ev, mActivePointerId); - if (mActivePointerId == INVALID_POINTER) - break; - final float x = MotionEventCompat.getX(ev, activePointerIndex); - final float deltaX = mLastMotionX - x; - mLastMotionX = x; - float oldScrollX = getScrollX(); - float scrollX = oldScrollX + deltaX; - final float leftBound = getLeftBound(); - final float rightBound = getRightBound(); - if (scrollX < leftBound) { - scrollX = leftBound; - } else if (scrollX > rightBound) { - scrollX = rightBound; + // Remember where the motion event started + int index = MotionEventCompat.getActionIndex(ev); + mActivePointerId = MotionEventCompat.getPointerId(ev, index); + mLastMotionX = mInitialMotionX = ev.getX(); + break; + case MotionEvent.ACTION_MOVE: + if (!mIsBeingDragged) { + determineDrag(ev); + if (mIsUnableToDrag) + return false; } - // Don't lose the rounded component - mLastMotionX += scrollX - (int) scrollX; - scrollTo((int) scrollX, getScrollY()); - pageScrolled((int) scrollX); - } - break; - case MotionEvent.ACTION_UP: - if (mIsBeingDragged) { - final VelocityTracker velocityTracker = mVelocityTracker; - velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); - int initialVelocity = (int) VelocityTrackerCompat.getXVelocity( - velocityTracker, mActivePointerId); - final int scrollX = getScrollX(); - final float pageOffset = (float) (scrollX - getDestScrollX(mCurItem)) / getBehindWidth(); - final int activePointerIndex = getPointerIndex(ev, mActivePointerId); - if (mActivePointerId != INVALID_POINTER) { + if (mIsBeingDragged) { + // Scroll to follow the motion event + final int activePointerIndex = getPointerIndex(ev, mActivePointerId); + if (mActivePointerId == INVALID_POINTER) + break; final float x = MotionEventCompat.getX(ev, activePointerIndex); - final int totalDelta = (int) (x - mInitialMotionX); - int nextPage = determineTargetPage(pageOffset, initialVelocity, totalDelta); - setCurrentItemInternal(nextPage, true, true, initialVelocity); - } else { - setCurrentItemInternal(mCurItem, true, true, initialVelocity); + final float deltaX = mLastMotionX - x; + mLastMotionX = x; + float oldScrollX = getScrollX(); + float scrollX = oldScrollX + deltaX; + final float leftBound = getLeftBound(); + final float rightBound = getRightBound(); + if (scrollX < leftBound) { + scrollX = leftBound; + } else if (scrollX > rightBound) { + scrollX = rightBound; + } + // Don't lose the rounded component + mLastMotionX += scrollX - (int) scrollX; + scrollTo((int) scrollX, getScrollY()); + pageScrolled((int) scrollX); } - mActivePointerId = INVALID_POINTER; - endDrag(); - } else if (mQuickReturn && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) { - // close the menu - setCurrentItem(1); - endDrag(); - } - break; - case MotionEvent.ACTION_CANCEL: - if (mIsBeingDragged) { - setCurrentItemInternal(mCurItem, true, true); - mActivePointerId = INVALID_POINTER; - endDrag(); + break; + case MotionEvent.ACTION_UP: + if (mIsBeingDragged) { + final VelocityTracker velocityTracker = mVelocityTracker; + velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); + int initialVelocity = (int) VelocityTrackerCompat.getXVelocity( + velocityTracker, mActivePointerId); + final int scrollX = getScrollX(); + final float pageOffset = (float) (scrollX - getDestScrollX(mCurItem)) / getBehindWidth(); + 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); + } else { + setCurrentItemInternal(mCurItem, true, true, initialVelocity); + } + mActivePointerId = INVALID_POINTER; + endDrag(); + } else if (mQuickReturn && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) { + // close the menu + setCurrentItem(1); + endDrag(); + } + break; + case MotionEvent.ACTION_CANCEL: + if (mIsBeingDragged) { + setCurrentItemInternal(mCurItem, true, true); + mActivePointerId = INVALID_POINTER; + endDrag(); + } + break; + case MotionEventCompat.ACTION_POINTER_DOWN: { + final int indexx = MotionEventCompat.getActionIndex(ev); + mLastMotionX = MotionEventCompat.getX(ev, indexx); + mActivePointerId = MotionEventCompat.getPointerId(ev, indexx); + break; } - break; - case MotionEventCompat.ACTION_POINTER_DOWN: { - final int indexx = MotionEventCompat.getActionIndex(ev); - mLastMotionX = MotionEventCompat.getX(ev, indexx); - mActivePointerId = MotionEventCompat.getPointerId(ev, indexx); - break; - } - case MotionEventCompat.ACTION_POINTER_UP: - onSecondaryPointerUp(ev); - int pointerIndex = getPointerIndex(ev, mActivePointerId); - if (mActivePointerId == INVALID_POINTER) + case MotionEventCompat.ACTION_POINTER_UP: + onSecondaryPointerUp(ev); + int pointerIndex = getPointerIndex(ev, mActivePointerId); + if (mActivePointerId == INVALID_POINTER) + break; + mLastMotionX = MotionEventCompat.getX(ev, pointerIndex); break; - mLastMotionX = MotionEventCompat.getX(ev, pointerIndex); - break; } return true; } - + private void determineDrag(MotionEvent ev) { final int activePointerId = mActivePointerId; final int pointerIndex = getPointerIndex(ev, activePointerId); @@ -785,7 +785,7 @@ private void determineDrag(MotionEvent ev) { final float y = MotionEventCompat.getY(ev, pointerIndex); final float dy = y - mLastMotionY; final float yDiff = Math.abs(dy); - if (xDiff > (isMenuOpen()?mTouchSlop/2:mTouchSlop) && xDiff > yDiff && thisSlideAllowed(dx)) { + if (xDiff > (isMenuOpen() ? mTouchSlop / 2 : mTouchSlop) && xDiff > yDiff && thisSlideAllowed(dx)) { startDrag(); mLastMotionX = x; mLastMotionY = y; @@ -800,8 +800,9 @@ private void determineDrag(MotionEvent ev) { public void scrollTo(int x, int y) { super.scrollTo(x, y); mScrollX = x; - mViewBehind.scrollBehindTo(mContent, x, y); - ((SlidingMenu)getParent()).manageLayers(getPercentOpen()); + mViewBehind.scrollBehindTo(mContent, x, y); + // this is making the veiwAbove UI non responsive + //((SlidingMenu)getParent()).manageLayers(getPercentOpen()); } private int determineTargetPage(float pageOffset, int velocity, int deltaX) { @@ -809,17 +810,17 @@ private int determineTargetPage(float pageOffset, int velocity, int deltaX) { if (Math.abs(deltaX) > mFlingDistance && Math.abs(velocity) > mMinimumVelocity) { if (velocity > 0 && deltaX > 0) { targetPage -= 1; - } else if (velocity < 0 && deltaX < 0){ + } else if (velocity < 0 && deltaX < 0) { targetPage += 1; } } else { - targetPage = (int) Math.round(mCurItem + pageOffset); + targetPage = Math.round(mCurItem + pageOffset); } return targetPage; } protected float getPercentOpen() { - return Math.abs(mScrollX-mContent.getLeft()) / getBehindWidth(); + return Math.abs(mScrollX - mContent.getLeft()) / getBehindWidth(); } @Override @@ -885,12 +886,12 @@ private void setScrollingCacheEnabled(boolean enabled) { /** * Tests scrollability within child views of v given a delta of dx. * - * @param v View to test for horizontal scrollability + * @param v View to test for horizontal scrollability * @param checkV Whether the view v passed should itself be checked for scrollability (true), * or just its children (false). - * @param dx Delta scrolled in pixels - * @param x X coordinate of the active touch point - * @param y Y coordinate of the active touch point + * @param dx Delta scrolled in pixels + * @param x X coordinate of the active touch point + * @param y Y coordinate of the active touch point * @return true if child views of v can be scrolled by delta of dx. */ protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { @@ -905,7 +906,7 @@ protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, dx, x + scrollX - child.getLeft(), - y + scrollY - child.getTop())) { + y + scrollY - child.getTop())) { return true; } } @@ -933,23 +934,23 @@ public boolean executeKeyEvent(KeyEvent event) { boolean handled = false; if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { - case KeyEvent.KEYCODE_DPAD_LEFT: - handled = arrowScroll(FOCUS_LEFT); - break; - case KeyEvent.KEYCODE_DPAD_RIGHT: - handled = arrowScroll(FOCUS_RIGHT); - break; - case KeyEvent.KEYCODE_TAB: - if (Build.VERSION.SDK_INT >= 11) { - // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD - // before Android 3.0. Ignore the tab key on those devices. - if (KeyEventCompat.hasNoModifiers(event)) { - handled = arrowScroll(FOCUS_FORWARD); - } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { - handled = arrowScroll(FOCUS_BACKWARD); + case KeyEvent.KEYCODE_DPAD_LEFT: + handled = arrowScroll(FOCUS_LEFT); + break; + case KeyEvent.KEYCODE_DPAD_RIGHT: + handled = arrowScroll(FOCUS_RIGHT); + break; + case KeyEvent.KEYCODE_TAB: + if (Build.VERSION.SDK_INT >= 11) { + // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD + // before Android 3.0. Ignore the tab key on those devices. + if (KeyEventCompat.hasNoModifiers(event)) { + handled = arrowScroll(FOCUS_FORWARD); + } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { + handled = arrowScroll(FOCUS_BACKWARD); + } } - } - break; + break; } } return handled; @@ -962,7 +963,7 @@ public boolean arrowScroll(int direction) { boolean handled = false; View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, - direction); + direction); if (nextFocused != null && nextFocused != currentFocused) { if (direction == View.FOCUS_LEFT) { handled = nextFocused.requestFocus(); @@ -990,7 +991,7 @@ public boolean arrowScroll(int direction) { boolean pageLeft() { if (mCurItem > 0) { - setCurrentItem(mCurItem-1, true); + setCurrentItem(mCurItem - 1, true); return true; } return false; @@ -998,7 +999,7 @@ boolean pageLeft() { boolean pageRight() { if (mCurItem < 1) { - setCurrentItem(mCurItem+1, true); + setCurrentItem(mCurItem + 1, true); return true; } return false; diff --git a/library/src/com/jeremyfeinstein/slidingmenu/lib/MenuInterface.java b/library/src/com/jeremyfeinstein/slidingmenu/lib/MenuInterface.java index 73e64bda2..fe1cd4ad7 100644 --- a/library/src/com/jeremyfeinstein/slidingmenu/lib/MenuInterface.java +++ b/library/src/com/jeremyfeinstein/slidingmenu/lib/MenuInterface.java @@ -6,30 +6,30 @@ public interface MenuInterface { - public abstract void scrollBehindTo(int x, int y, - CustomViewBehind cvb, float scrollScale); - - public abstract int getMenuLeft(CustomViewBehind cvb, View content); - - public abstract int getAbsLeftBound(CustomViewBehind cvb, View content); + void scrollBehindTo(int x, int y, + CustomViewBehind cvb, float scrollScale); - public abstract int getAbsRightBound(CustomViewBehind cvb, View content); + int getMenuLeft(CustomViewBehind cvb, View content); - public abstract boolean marginTouchAllowed(View content, int x, int threshold); - - public abstract boolean menuOpenTouchAllowed(View content, int currPage, int x); - - public abstract boolean menuTouchInQuickReturn(View content, int currPage, int x); - - public abstract boolean menuClosedSlideAllowed(int x); - - public abstract boolean menuOpenSlideAllowed(int x); - - public abstract void drawShadow(Canvas canvas, Drawable shadow, int width); - - public abstract void drawFade(Canvas canvas, int alpha, - CustomViewBehind cvb, View content); - - public abstract void drawSelector(View content, Canvas canvas, float percentOpen); + int getAbsLeftBound(CustomViewBehind cvb, View content); + + int getAbsRightBound(CustomViewBehind cvb, View content); + + boolean marginTouchAllowed(View content, int x, int threshold); + + boolean menuOpenTouchAllowed(View content, int currPage, int x); + + boolean menuTouchInQuickReturn(View content, int currPage, int x); + + boolean menuClosedSlideAllowed(int x); + + boolean menuOpenSlideAllowed(int x); + + void drawShadow(Canvas canvas, Drawable shadow, int width); + + void drawFade(Canvas canvas, int alpha, + CustomViewBehind cvb, View content); + + void drawSelector(View content, Canvas canvas, float percentOpen); } diff --git a/library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java b/library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java index 8b88708b9..8ddd47d3b 100644 --- a/library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java +++ b/library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java @@ -1,11 +1,10 @@ package com.jeremyfeinstein.slidingmenu.lib; -import java.lang.reflect.Method; - import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; +import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -14,12 +13,13 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; -import android.os.Handler; import android.os.Parcel; import android.os.Parcelable; import android.util.AttributeSet; import android.util.Log; import android.view.Display; +import android.view.KeyCharacterMap; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -29,6 +29,8 @@ import com.jeremyfeinstein.slidingmenu.lib.CustomViewAbove.OnPageChangeListener; +import java.lang.reflect.Method; + public class SlidingMenu extends RelativeLayout { private static final String TAG = SlidingMenu.class.getSimpleName(); @@ -37,30 +39,36 @@ public class SlidingMenu extends RelativeLayout { public static final int SLIDING_CONTENT = 1; private boolean mActionbarOverlay = false; - /** Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe + /** + * Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe * gesture on the screen's margin */ public static final int TOUCHMODE_MARGIN = 0; - /** Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe + /** + * Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe * gesture anywhere on the screen */ public static final int TOUCHMODE_FULLSCREEN = 1; - /** Constant value for use with setTouchModeAbove(). Denies the SlidingMenu to be opened with a swipe + /** + * Constant value for use with setTouchModeAbove(). Denies the SlidingMenu to be opened with a swipe * gesture */ public static final int TOUCHMODE_NONE = 2; - /** Constant value for use with setMode(). Puts the menu to the left of the content. + /** + * 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. + /** + * 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. + /** + * Constant value for use with setMode(). Puts menus to the left and right of the content. */ public static final int LEFT_RIGHT = 2; @@ -69,7 +77,7 @@ public class SlidingMenu extends RelativeLayout { private CustomViewBehind mViewBehind; private OnOpenListener mOpenListener; - + private OnOpenListener mSecondaryOpenListner; private OnCloseListener mCloseListener; @@ -88,7 +96,7 @@ public interface OnOpenListener { /** * On open. */ - public void onOpen(); + void onOpen(); } /** @@ -107,7 +115,7 @@ public interface OnOpenedListener { /** * On opened. */ - public void onOpened(); + void onOpened(); } /** @@ -126,7 +134,7 @@ public interface OnCloseListener { /** * On close. */ - public void onClose(); + void onClose(); } /** @@ -145,7 +153,7 @@ public interface OnClosedListener { /** * On closed. */ - public void onClosed(); + void onClosed(); } /** @@ -156,10 +164,10 @@ public interface CanvasTransformer { /** * Transform canvas. * - * @param canvas the canvas + * @param canvas the canvas * @param percentOpen the percent open */ - public void transformCanvas(Canvas canvas, float percentOpen); + void transformCanvas(Canvas canvas, float percentOpen); } /** @@ -174,7 +182,7 @@ public SlidingMenu(Context context) { /** * Instantiates a new SlidingMenu and attach to Activity. * - * @param activity the activity to attach slidingmenu + * @param activity the activity to attach slidingmenu * @param slideStyle the slidingmenu style */ public SlidingMenu(Activity activity, int slideStyle) { @@ -186,7 +194,7 @@ public SlidingMenu(Activity activity, int slideStyle) { * Instantiates a new SlidingMenu. * * @param context the associated Context - * @param attrs the attrs + * @param attrs the attrs */ public SlidingMenu(Context context, AttributeSet attrs) { this(context, attrs, 0); @@ -195,13 +203,13 @@ public SlidingMenu(Context context, AttributeSet attrs) { /** * Instantiates a new SlidingMenu. * - * @param context the associated Context - * @param attrs the attrs + * @param context the associated Context + * @param attrs the attrs * @param defStyle the def style */ 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); @@ -217,14 +225,15 @@ public SlidingMenu(Context context, AttributeSet attrs, int defStyle) { public static final int POSITION_SECONDARY_OPEN = 2; public void onPageScrolled(int position, float positionOffset, - int positionOffsetPixels) { } + int positionOffsetPixels) { + } public void onPageSelected(int position) { if (position == POSITION_OPEN && mOpenListener != null) { mOpenListener.onOpen(); } else if (position == POSITION_CLOSE && mCloseListener != null) { mCloseListener.onClose(); - } else if (position == POSITION_SECONDARY_OPEN && mSecondaryOpenListner != null ) { + } else if (position == POSITION_SECONDARY_OPEN && mSecondaryOpenListner != null) { mSecondaryOpenListner.onOpen(); } } @@ -243,7 +252,7 @@ public void onPageSelected(int position) { } int viewBehind = ta.getResourceId(R.styleable.SlidingMenu_viewBehind, -1); if (viewBehind != -1) { - setMenu(viewBehind); + setMenu(viewBehind); } else { setMenu(new FrameLayout(context)); } @@ -280,12 +289,14 @@ else if (widthBehind != -1) if (selectorRes != -1) setSelectorDrawable(selectorRes); ta.recycle(); + +// setPadding(0, 0, 0, 96); } /** * Attaches the SlidingMenu to an entire Activity - * - * @param activity the Activity + * + * @param activity the Activity * @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW */ public void attachToActivity(Activity activity, int slideStyle) { @@ -294,9 +305,9 @@ public void attachToActivity(Activity activity, int slideStyle) { /** * Attaches the SlidingMenu to an entire Activity - * - * @param activity the Activity - * @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW + * + * @param activity the Activity + * @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW * @param actionbarOverlay whether or not the ActionBar is overlaid */ public void attachToActivity(Activity activity, int slideStyle, boolean actionbarOverlay) { @@ -307,33 +318,34 @@ public void attachToActivity(Activity activity, int slideStyle, boolean actionba throw new IllegalStateException("This SlidingMenu appears to already be attached"); // get the window background - TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] {android.R.attr.windowBackground}); + TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.windowBackground}); int background = a.getResourceId(0, 0); a.recycle(); switch (slideStyle) { - case SLIDING_WINDOW: - mActionbarOverlay = false; - ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView(); - ViewGroup decorChild = (ViewGroup) decor.getChildAt(0); - // save ActionBar themes that have transparent assets - decorChild.setBackgroundResource(background); - decor.removeView(decorChild); - decor.addView(this); - setContent(decorChild); - break; - case SLIDING_CONTENT: - mActionbarOverlay = actionbarOverlay; - // take the above view out of - ViewGroup contentParent = (ViewGroup)activity.findViewById(android.R.id.content); - View content = contentParent.getChildAt(0); - contentParent.removeView(content); - contentParent.addView(this); - setContent(content); - // save people from having transparent backgrounds - if (content.getBackground() == null) - content.setBackgroundResource(background); - break; + case SLIDING_WINDOW: + mActionbarOverlay = false; + ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView(); + ViewGroup decorChild = (ViewGroup) decor.getChildAt(0); + // save ActionBar themes that have transparent assets + decorChild.setBackgroundResource(background); + decor.removeView(decorChild); + decor.addView(this); + setContent(decorChild); + + break; + case SLIDING_CONTENT: + mActionbarOverlay = actionbarOverlay; + // take the above view out of + ViewGroup contentParent = (ViewGroup) activity.findViewById(android.R.id.content); + View content = contentParent.getChildAt(0); + contentParent.removeView(content); + contentParent.addView(this); + setContent(content); + // save people from having transparent backgrounds + if (content.getBackground() == null) + content.setBackgroundResource(background); + break; } } @@ -359,6 +371,7 @@ public void setContent(View view) { /** * Retrieves the current content. + * * @return the current content */ public View getContent() { @@ -386,6 +399,7 @@ public void setMenu(View v) { /** * Retrieves the main menu. + * * @return the main menu */ public View getMenu() { @@ -414,6 +428,7 @@ public void setSecondaryMenu(View v) { /** * Retrieves the current secondary menu (right). + * * @return the current menu */ public View getSecondaryMenu() { @@ -441,6 +456,7 @@ public boolean isSlidingEnabled() { /** * Sets which side the SlidingMenu should appear on. + * * @param mode must be either SlidingMenu.LEFT or SlidingMenu.RIGHT */ public void setMode(int mode) { @@ -452,6 +468,7 @@ public void setMode(int mode) { /** * Returns the current side that the SlidingMenu is on. + * * @return the current mode, either SlidingMenu.LEFT or SlidingMenu.RIGHT */ public int getMode() { @@ -555,7 +572,7 @@ public void toggle(boolean animate) { public boolean isMenuShowing() { return mViewAbove.getCurrentItem() == 0 || mViewAbove.getCurrentItem() == 2; } - + /** * Checks if is the behind view showing. * @@ -571,7 +588,7 @@ public boolean isSecondaryMenuShowing() { * @return The margin on the right of the screen that the behind view scrolls to */ public int getBehindOffset() { - return ((RelativeLayout.LayoutParams)mViewBehind.getLayoutParams()).rightMargin; + return ((RelativeLayout.LayoutParams) mViewBehind.getLayoutParams()).rightMargin; } /** @@ -592,7 +609,7 @@ public void setBehindOffset(int i) { * Sets the behind offset. * * @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. + * The menu, when open, will leave this width margin on the right of the screen. */ public void setBehindOffsetRes(int resID) { int i = (int) getContext().getResources().getDimension(resID); @@ -638,14 +655,14 @@ public void setBehindWidth(int i) { } catch (Exception e) { width = display.getWidth(); } - setBehindOffset(width-i); + setBehindOffset(width - i); } /** * Sets the behind width. * * @param res The dimension resource id to be set as the behind width offset. - * The menu, when open, will open this wide. + * The menu, when open, will open this wide. */ public void setBehindWidthRes(int res) { int i = (int) getContext().getResources().getDimension(res); @@ -660,17 +677,19 @@ public void setBehindWidthRes(int res) { public float getBehindScrollScale() { return mViewBehind.getScrollScale(); } - + /** * Gets the touch mode margin threshold + * * @return the touch mode margin threshold */ public int getTouchmodeMarginThreshold() { return mViewBehind.getMarginThreshold(); } - + /** * Set the touch mode margin threshold + * * @param touchmodeMarginThreshold */ public void setTouchmodeMarginThreshold(int touchmodeMarginThreshold) { @@ -681,7 +700,7 @@ public void setTouchmodeMarginThreshold(int touchmodeMarginThreshold) { * Sets the behind scroll scale. * * @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) + * 1 pixel that the above view scrolls and 0.0f scrolls 0 pixels) */ public void setBehindScrollScale(float f) { if (f < 0 && f > 1) @@ -718,7 +737,7 @@ public void setTouchModeAbove(int i) { if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN && i != TOUCHMODE_NONE) { throw new IllegalStateException("TouchMode must be set to either" + - "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE."); + "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE."); } mViewAbove.setTouchMode(i); } @@ -734,7 +753,7 @@ public void setTouchModeBehind(int i) { if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN && i != TOUCHMODE_NONE) { throw new IllegalStateException("TouchMode must be set to either" + - "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE."); + "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE."); } mViewBehind.setTouchMode(i); } @@ -781,7 +800,7 @@ public void setSecondaryShadowDrawable(Drawable d) { * @param resId The dimension resource id to be set as the shadow width. */ public void setShadowWidthRes(int resId) { - setShadowWidth((int)getResources().getDimension(resId)); + setShadowWidth((int) getResources().getDimension(resId)); } /** @@ -883,17 +902,17 @@ public void setOnOpenListener(OnOpenListener listener) { mOpenListener = listener; } - + /** * Sets the OnOpenListner for secondary menu {@link OnOpenListener#onOpen() OnOpenListener.onOpen()} will be called when the secondary SlidingMenu is opened - * + * * @param listener the new OnOpenListener */ - + public void setSecondaryOnOpenListner(OnOpenListener listener) { mSecondaryOpenListner = listener; } - + /** * Sets the OnCloseListener. {@link OnCloseListener#onClose() OnCloseListener.onClose()} will be called when any one of the SlidingMenu is closed * @@ -950,14 +969,14 @@ public void writeToParcel(Parcel out, int flags) { public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public SavedState createFromParcel(Parcel in) { - return new SavedState(in); - } + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } - public SavedState[] newArray(int size) { - return new SavedState[size]; - } - }; + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; } @@ -976,7 +995,7 @@ protected Parcelable onSaveInstanceState() { */ @Override protected void onRestoreInstanceState(Parcelable state) { - SavedState ss = (SavedState)state; + SavedState ss = (SavedState) state; super.onRestoreInstanceState(ss.getSuperState()); mViewAbove.setCurrentItem(ss.getItem()); } @@ -995,9 +1014,27 @@ protected boolean fitSystemWindows(Rect insets) { Log.v(TAG, "setting padding!"); setPadding(leftPadding, topPadding, rightPadding, bottomPadding); } + if (Build.VERSION.SDK_INT >= 21) { + setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); + } return true; } + public int navKeysHeight() { + boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); + boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME); + + if (hasBackKey && hasHomeKey) { + return 0; + } + Resources resources = getContext().getResources(); + int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); + if (resourceId > 0) { + return resources.getDimensionPixelSize(resourceId); + } + return 0; + } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void manageLayers(float percentOpen) { if (Build.VERSION.SDK_INT < 11) return; diff --git a/library/src/com/jeremyfeinstein/slidingmenu/lib/app/SlidingActivityBase.java b/library/src/com/jeremyfeinstein/slidingmenu/lib/app/SlidingActivityBase.java index 7bff1f2a2..22d55b0cb 100644 --- a/library/src/com/jeremyfeinstein/slidingmenu/lib/app/SlidingActivityBase.java +++ b/library/src/com/jeremyfeinstein/slidingmenu/lib/app/SlidingActivityBase.java @@ -14,7 +14,7 @@ public interface SlidingActivityBase { * @param view The desired content to display. * @param layoutParams Layout parameters for the view. */ - public void setBehindContentView(View view, LayoutParams layoutParams); + void setBehindContentView(View view, LayoutParams layoutParams); /** * Set the behind view content to an explicit view. This view is placed directly into the behind view 's view hierarchy. @@ -24,7 +24,7 @@ public interface SlidingActivityBase { * * @param view The desired content to display. */ - public void setBehindContentView(View view); + void setBehindContentView(View view); /** * Set the behind view content from a layout resource. The resource will be inflated, adding all top-level views @@ -32,35 +32,35 @@ public interface SlidingActivityBase { * * @param layoutResID Resource ID to be inflated. */ - public void setBehindContentView(int layoutResID); + void setBehindContentView(int layoutResID); /** * Gets the SlidingMenu associated with this activity. * * @return the SlidingMenu associated with this activity. */ - public SlidingMenu getSlidingMenu(); + SlidingMenu getSlidingMenu(); /** * Toggle the SlidingMenu. If it is open, it will be closed, and vice versa. */ - public void toggle(); + void toggle(); /** * Close the SlidingMenu and show the content view. */ - public void showContent(); + void showContent(); /** * Open the SlidingMenu and show the menu view. */ - public void showMenu(); + void showMenu(); /** * Open the SlidingMenu and show the secondary (right) menu view. Will default to the regular menu * if there is only one. */ - public void showSecondaryMenu(); + void showSecondaryMenu(); /** * Controls whether the ActionBar slides along with the above view when the menu is opened, @@ -69,6 +69,6 @@ public interface SlidingActivityBase { * @param slidingActionBarEnabled True if you want the ActionBar to slide along with the SlidingMenu, * false if you want the ActionBar to stay in place */ - public void setSlidingActionBarEnabled(boolean slidingActionBarEnabled); + void setSlidingActionBarEnabled(boolean slidingActionBarEnabled); } diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 000000000..d8f14a134 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':library'