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 option to draw shadow outside below view (shadow is put on above v... #538

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
1 change: 1 addition & 0 deletions library/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
</attr>
<attr name="shadowDrawable" format="reference" />
<attr name="shadowWidth" format="dimension" />
<attr name="shadowOutside" format="boolean" />
<attr name="fadeEnabled" format="boolean" />
<attr name="fadeDegree" format="float" />
<attr name="selectorEnabled" format="boolean" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ protected float getPercentOpen() {
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
// Draw the margin drawable if needed.
mViewBehind.drawShadow(mContent, canvas);
mViewBehind.drawShadow(mContent, canvas, getPercentOpen());
mViewBehind.drawFade(mContent, canvas, getPercentOpen());
mViewBehind.drawSelector(mContent, canvas, getPercentOpen());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class CustomViewBehind extends ViewGroup {
private int mWidthOffset;
private CanvasTransformer mTransformer;
private boolean mChildrenEnabled;
private boolean mShadowOutside;

public CustomViewBehind(Context context) {
this(context, null);
Expand Down Expand Up @@ -190,6 +191,12 @@ public void setShadowWidth(int width) {
mShadowWidth = width;
invalidate();
}

public void setShadowOutside(boolean b) {
mShadowOutside = b;
invalidate();
}


public void setFadeEnabled(boolean b) {
mFadeEnabled = b;
Expand Down Expand Up @@ -340,20 +347,29 @@ public boolean menuOpenSlideAllowed(float dx) {
return false;
}

public void drawShadow(View content, Canvas canvas) {
public void drawShadow(View content, Canvas canvas, float openPercent) {
if (mShadowDrawable == null || mShadowWidth <= 0) return;
if (mShadowOutside && openPercent<0.1) return;
int left = 0;
if (mMode == SlidingMenu.LEFT) {
left = content.getLeft() - mShadowWidth;
} else if (mMode == SlidingMenu.RIGHT) {
if (mMode == SlidingMenu.LEFT) {
left = content.getLeft();
if(!mShadowOutside)
left-=mShadowWidth;
} else if (mMode == SlidingMenu.RIGHT) {
left = content.getRight();
if(mShadowOutside)
left-= mShadowWidth;
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
if (mSecondaryShadowDrawable != null) {
left = content.getRight();
if(mShadowOutside)
left-= mShadowWidth;
mSecondaryShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight());
mSecondaryShadowDrawable.draw(canvas);
}
left = content.getLeft() - mShadowWidth;
}
left = content.getLeft();
if(!mShadowOutside)
left-=mShadowWidth;
}
mShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight());
mShadowDrawable.draw(canvas);
Expand Down
11 changes: 11 additions & 0 deletions library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ else if (widthBehind != -1)
}
int shadowWidth = (int) ta.getDimension(R.styleable.SlidingMenu_shadowWidth, 0);
setShadowWidth(shadowWidth);
boolean shadowOutside = (boolean) ta.getBoolean(R.styleable.SlidingMenu_shadowOutside, false);
setShadowOutside(shadowOutside);
boolean fadeEnabled = ta.getBoolean(R.styleable.SlidingMenu_fadeEnabled, true);
setFadeEnabled(fadeEnabled);
float fadeDeg = ta.getFloat(R.styleable.SlidingMenu_fadeDegree, 0.33f);
Expand Down Expand Up @@ -792,6 +794,15 @@ public void setShadowWidthRes(int resId) {
public void setShadowWidth(int pixels) {
mViewBehind.setShadowWidth(pixels);
}

/**
* Sets the to be drawn on outside below view.
*
* @param b true to enable outside shadow, false to disable it
*/
public void setShadowOutside(boolean b) {
mViewBehind.setShadowOutside(b);
}

/**
* Enables or disables the SlidingMenu's fade in and out
Expand Down