Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadows #665

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.+'
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'android-library'
Expand All @@ -13,8 +13,8 @@ dependencies {
}

android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
compileSdkVersion 19
buildToolsVersion "19.1.0"

defaultConfig {
minSdkVersion 7
Expand Down
53 changes: 49 additions & 4 deletions library/library.iml
Original file line number Diff line number Diff line change
@@ -1,19 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/../../.." external.system.id="GRADLE" external.system.module.group="tvtag_android.libraries.SlidingMenu" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/res" />
<option name="LIBRARY_PROJECT" value="true" />
</configuration>
</facet>
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":libraries:SlidingMenu:library" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android 4.2.2" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-13.0.0" level="project" />
</component>
</module>

Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,19 @@ public float getInterpolation(float t) {
private OnOpenedListener mOpenedListener;

private List<View> mIgnoredViews = new ArrayList<View>();
private SlidingMenu.CanvasTransformer mTransformer;
private SlidingMenu.OnOpeningListener mOnOpeningListener;
private SlidingMenu.OnOpeningListener mSecondaryOnOpeningListener;

// private int mScrollState = SCROLL_STATE_IDLE;
public void setOnOpeningListener(SlidingMenu.OnOpeningListener onOpeningListener) {
mOnOpeningListener = onOpeningListener;
}

public void setSecondaryOnOpeningListener(SlidingMenu.OnOpeningListener onOpeningListener) {
mSecondaryOnOpeningListener = onOpeningListener;
}

// private int mScrollState = SCROLL_STATE_IDLE;

/**
* Callback interface for responding to changing state of the selected page.
Expand Down Expand Up @@ -157,6 +168,10 @@ public CustomViewAbove(Context context, AttributeSet attrs) {
initCustomViewAbove();
}

public void setCanvasTransformer(SlidingMenu.CanvasTransformer t) {
mTransformer = t;
}

void initCustomViewAbove() {
setWillNotDraw(false);
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
Expand Down Expand Up @@ -575,7 +590,7 @@ public int getTouchMode() {
private boolean thisTouchAllowed(MotionEvent ev) {
int x = (int) (ev.getX() + mScrollX);
if (isMenuOpen()) {
return mViewBehind.menuOpenTouchAllowed(mContent, mCurItem, x);
return mViewBehind.menuOpenTouchAllowed(mContent, mCurItem, x, ev.getY());
} else {
switch (mTouchMode) {
case SlidingMenu.TOUCHMODE_FULLSCREEN:
Expand Down Expand Up @@ -642,7 +657,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
if (thisTouchAllowed(ev)) {
mIsBeingDragged = false;
mIsUnableToDrag = false;
if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX, ev.getY())) {
mQuickReturn = true;
}
} else {
Expand Down Expand Up @@ -744,7 +759,7 @@ public boolean onTouchEvent(MotionEvent ev) {
}
mActivePointerId = INVALID_POINTER;
endDrag();
} else if (mQuickReturn && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
} else if (mQuickReturn && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX, ev.getY())) {
// close the menu
setCurrentItem(1);
endDrag();
Expand Down Expand Up @@ -789,14 +804,29 @@ private void determineDrag(MotionEvent ev) {
startDrag();
mLastMotionX = x;
mLastMotionY = y;
if (!isMenuOpen()) isOpening(dx == xDiff);
setScrollingCacheEnabled(true);
// TODO add back in touch slop check
} else if (xDiff > mTouchSlop) {
mIsUnableToDrag = true;
}
}

@Override
private void isOpening(boolean isMovingLeftToRight) {
if (mViewBehind.getMode() == SlidingMenu.LEFT && isMovingLeftToRight && mOnOpeningListener != null) {
mOnOpeningListener.onOpening();
}else if (mViewBehind.getMode() == SlidingMenu.RIGHT && !isMovingLeftToRight && mOnOpeningListener != null) {
mOnOpeningListener.onOpening();
}else if (mViewBehind.getMode() == SlidingMenu.LEFT_RIGHT) {
if (isMovingLeftToRight && mOnOpeningListener != null) {
mOnOpeningListener.onOpening();
}else if (!isMovingLeftToRight && mSecondaryOnOpeningListener != null) {
mSecondaryOnOpeningListener.onOpening();
}
}
}

@Override
public void scrollTo(int x, int y) {
super.scrollTo(x, y);
mScrollX = x;
Expand Down Expand Up @@ -824,7 +854,13 @@ protected float getPercentOpen() {

@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (mTransformer != null) {
canvas.save();
mTransformer.transformCanvas(canvas, getPercentOpen());
super.dispatchDraw(canvas);
canvas.restore();
} else
super.dispatchDraw(canvas);
// Draw the margin drawable if needed.
mViewBehind.drawShadow(mContent, canvas);
mViewBehind.drawFade(mContent, canvas, getPercentOpen());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public class CustomViewBehind extends ViewGroup {
private int mWidthOffset;
private CanvasTransformer mTransformer;
private boolean mChildrenEnabled;
private SlidingMenu.TouchRangeListener mTouchRangeListener;

public CustomViewBehind(Context context) {
public CustomViewBehind(Context context) {
this(context, null);
}

Expand Down Expand Up @@ -299,20 +300,22 @@ 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) {
public boolean menuTouchInQuickReturn(View content, int currPage, float x, float y) {
if (mMode == SlidingMenu.LEFT || (mMode == SlidingMenu.LEFT_RIGHT && currPage == 0)) {
if (mTouchRangeListener != null) return mTouchRangeListener.isInTouchRange((int)x, (int)y);
return x >= content.getLeft();
} else if (mMode == SlidingMenu.RIGHT || (mMode == SlidingMenu.LEFT_RIGHT && currPage == 2)) {
if (mTouchRangeListener != null) return mTouchRangeListener.isInTouchRange((int)x, (int)y);
return x <= content.getRight();
}
return false;
Expand Down Expand Up @@ -436,4 +439,7 @@ public void setSelectorBitmap(Bitmap b) {
refreshDrawableState();
}

public void setTouchRangeListener(SlidingMenu.TouchRangeListener touchRangeListener) {
mTouchRangeListener = touchRangeListener;
}
}
51 changes: 49 additions & 2 deletions library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,28 @@ public class SlidingMenu extends RelativeLayout {
private OnOpenListener mSecondaryOpenListner;

private OnCloseListener mCloseListener;
private OnOpeningListener mOpeningListener;
private OnOpeningListener mSecondaryOpeningListener;

/**
public void setAboveCanvasTransformer(CanvasTransformer canvasTransformer) {
mViewAbove.setCanvasTransformer(canvasTransformer);
}

public void setOnOpeningListener(OnOpeningListener onOpeningListener) {
mOpeningListener = onOpeningListener;
mViewAbove.setOnOpeningListener(onOpeningListener);
}

public void setSecondaryOnOpeningListner(OnOpeningListener onOpeningListener) {
mSecondaryOpeningListener = onOpeningListener;
mViewAbove.setSecondaryOnOpeningListener(onOpeningListener);
}

public void setTouchRangeListener(TouchRangeListener touchRangeListener) {
mViewBehind.setTouchRangeListener(touchRangeListener);
}

/**
* The listener interface for receiving onOpen events.
* The class that is interested in processing a onOpen
* event implements this interface, and the object created
Expand Down Expand Up @@ -490,6 +510,7 @@ public void showMenu() {
* @param animate true to animate the transition, false to ignore animation
*/
public void showMenu(boolean animate) {
if (mOpeningListener != null) mOpeningListener.onOpening();
mViewAbove.setCurrentItem(0, animate);
}

Expand All @@ -508,6 +529,7 @@ public void showSecondaryMenu() {
* @param animate true to animate the transition, false to ignore animation
*/
public void showSecondaryMenu(boolean animate) {
if (mSecondaryOpeningListener != null) mSecondaryOpeningListener.onOpening();
mViewAbove.setCurrentItem(2, animate);
}

Expand Down Expand Up @@ -547,6 +569,23 @@ public void toggle(boolean animate) {
}
}

public void toggleSecondaryMenu() {
toggleSecondaryMenu(true);
}

/**
* Toggle the SlidingMenu. If it is open, it will be closed, and vice versa.
*
* @param animate true to animate the transition, false to ignore animation
*/
public void toggleSecondaryMenu(boolean animate) {
if (isMenuShowing()) {
showContent(animate);
} else {
showSecondaryMenu(animate);
}
}

/**
* Checks if is the behind view showing.
*
Expand Down Expand Up @@ -922,7 +961,15 @@ public void setOnClosedListener(OnClosedListener listener) {
mViewAbove.setOnClosedListener(listener);
}

public static class SavedState extends BaseSavedState {
public interface OnOpeningListener {
void onOpening();
}

public interface TouchRangeListener {
boolean isInTouchRange(int x, int y);
}

public static class SavedState extends BaseSavedState {

private final int mItem;

Expand Down