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

Added fade effect for the content #675

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
24 changes: 21 additions & 3 deletions library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -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);
}
Expand Down