diff --git a/library/src/com/jeremyfeinstein/slidingmenu/lib/CustomViewAbove.java b/library/src/com/jeremyfeinstein/slidingmenu/lib/CustomViewAbove.java index fa73ef05b..0da688d9f 100644 --- a/library/src/com/jeremyfeinstein/slidingmenu/lib/CustomViewAbove.java +++ b/library/src/com/jeremyfeinstein/slidingmenu/lib/CustomViewAbove.java @@ -5,7 +5,10 @@ import android.content.Context; import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; import android.graphics.Rect; +import android.graphics.drawable.Drawable; import android.os.Build; import android.support.v4.view.KeyEventCompat; import android.support.v4.view.MotionEventCompat; @@ -829,6 +832,29 @@ protected void dispatchDraw(Canvas canvas) { mViewBehind.drawShadow(mContent, canvas); mViewBehind.drawFade(mContent, canvas, getPercentOpen()); mViewBehind.drawSelector(mContent, canvas, getPercentOpen()); + drawFade(canvas, getPercentOpen()); + } + + private final Paint mFadePaint = new Paint(); + private float mFadeDegree; + private boolean mFadeEnabled; + + public void setFadeEnabled(boolean isEnabled) { + mFadeEnabled = isEnabled; + } + + public void setFadeDegree(float degree) { + if (degree > 1.0f || degree < 0.0f) + throw new IllegalStateException("The ContentFadeDegree must be between 0.0f and 1.0f"); + mFadeDegree = degree; + } + + private void drawFade(Canvas canvas, float openPercent) { + if (!mFadeEnabled) + return; + final int alpha = (int) (mFadeDegree * 255 * Math.abs(openPercent)); + mFadePaint.setColor(Color.argb(alpha, 0, 0, 0)); + canvas.drawRect(getLeft(), 0, getWidth(), getHeight(), mFadePaint); } // variables for drawing diff --git a/library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java b/library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java index 8b88708b9..814fa8a4b 100644 --- a/library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java +++ b/library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java @@ -802,6 +802,24 @@ public void setFadeEnabled(boolean b) { mViewBehind.setFadeEnabled(b); } + /** + * Enables or disables the content's fade in and out + * @param isEnabled true to enable fade, false to disable it + */ + public void setContentFadeEnabled(boolean isEnabled){ + mViewAbove.setFadeEnabled(isEnabled); + } + + /** + * Sets how much the content fades in and out. Fade must be enabled, see + * {@link #setFadeEnabled(boolean) setFadeEnabled(boolean)} + * + * @param f the new fade degree, between 0.0f and 1.0f + */ + public void setContentFadeDegree(float f) { + mViewAbove.setFadeDegree(f); + } + /** * Sets how much the SlidingMenu fades in and out. Fade must be enabled, see * {@link #setFadeEnabled(boolean) setFadeEnabled(boolean)} @@ -859,9 +877,9 @@ public void addIgnoredView(View v) { /** * Remove a View ignored by the Touch Down event when mode is Fullscreen - * - * @param v a view not wanted to be ignored anymore - */ + * + * @param v a view not wanted to be ignored anymore + */ public void removeIgnoredView(View v) { mViewAbove.removeIgnoredView(v); }