Skip to content

Commit

Permalink
Merge pull request jfeinstein10#176 from CmoaToto/master
Browse files Browse the repository at this point in the history
Add/Remove Views ignored by the Touch Down Event when mode is Fullscreen
  • Loading branch information
jfeinstein10 committed Dec 17, 2012
2 parents 71d057d + caa723c commit ca72682
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
35 changes: 29 additions & 6 deletions library/src/com/slidingmenu/lib/CustomViewAbove.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.slidingmenu.lib;

import java.util.ArrayList;
import java.util.List;

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.support.v4.view.KeyEventCompat;
import android.support.v4.view.MotionEventCompat;
Expand All @@ -15,7 +15,6 @@
import android.util.AttributeSet;
import android.util.FloatMath;
import android.util.Log;
import android.util.TypedValue;
import android.view.FocusFinder;
import android.view.KeyEvent;
import android.view.MotionEvent;
Expand All @@ -25,7 +24,6 @@
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.FrameLayout;
import android.widget.Scroller;

import com.slidingmenu.lib.SlidingMenu.OnClosedListener;
Expand Down Expand Up @@ -99,6 +97,8 @@ public float getInterpolation(float t) {
private OnClosedListener mClosedListener;
private OnOpenedListener mOpenedListener;

private List<View> mIgnoredViews = new ArrayList<View>();

// private int mScrollState = SCROLL_STATE_IDLE;

/**
Expand Down Expand Up @@ -283,6 +283,20 @@ OnPageChangeListener setInternalPageChangeListener(OnPageChangeListener listener
return oldListener;
}

public void addIgnoredView(View v) {
if (!mIgnoredViews.contains(v)) {
mIgnoredViews.add(v);
}
}

public void removeIgnoredView(View v) {
mIgnoredViews.remove(v);
}

public void clearIgnoredViews() {
mIgnoredViews.clear();
}

// We want the duration of the page snap animation to be influenced by the distance that
// the screen has to travel, however, we don't want this duration to be effected in a
// purely linear fashion. Instead, we use this method to moderate the effect that the distance
Expand Down Expand Up @@ -320,6 +334,15 @@ public boolean isMenuOpen() {
return mCurItem == 0 || mCurItem == 2;
}

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;
}
return false;
}

public int getBehindWidth() {
if (mCustomViewBehind == null) {
return 0;
Expand Down Expand Up @@ -560,7 +583,7 @@ private boolean thisTouchAllowed(MotionEvent ev) {
} else {
switch (mTouchMode) {
case SlidingMenu.TOUCHMODE_FULLSCREEN:
return true;
return !isInIgnoredView(ev);
case SlidingMenu.TOUCHMODE_NONE:
return false;
case SlidingMenu.TOUCHMODE_MARGIN:
Expand Down
27 changes: 25 additions & 2 deletions library/src/com/slidingmenu/lib/SlidingMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

Expand Down Expand Up @@ -775,6 +773,31 @@ public void setSelectorBitmap(Bitmap b) {
mViewAbove.setSelectorBitmap(b);
}

/**
* Add a View ignored by the Touch Down event when mode is Fullscreen
*
* @param v a view to be ignored
*/
public void addIgnoredView(View v) {
mViewAbove.addIgnoredView(v);
}

/**
* Remove a View ignored by the Touch Down event when mode is Fullscreen
*
* @param v a view not wanted to be ignored anymore
*/
public void removeIgnoredView(View v) {
mViewAbove.removeIgnoredView(v);
}

/**
* Clear the list of Views ignored by the Touch Down event when mode is Fullscreen
*/
public void clearIgnoredViews() {
mViewAbove.clearIgnoredViews();
}

/**
* Sets the OnOpenListener. {@link OnOpenListener#onOpen() OnOpenListener.onOpen()} will be called when the SlidingMenu is opened
*
Expand Down

0 comments on commit ca72682

Please sign in to comment.