Skip to content
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 @@ -418,10 +418,24 @@ void smoothScrollTo(int x, int y, int velocity) {
velocity = Math.abs(velocity);
if (velocity > 0) {
duration = 4 * Math.round(1000 * Math.abs(distance / velocity));
} else {
final float pageDelta = (float) Math.abs(dx) / width;
duration = (int) ((pageDelta + 1) * 100);
duration = MAX_SETTLE_DURATION;

} else {//Ensure that the same two menu sliding speed
switch (mViewBehind.getMode()) {
case SlidingMenu.LEFT:
case SlidingMenu.RIGHT:
duration = MAX_SETTLE_DURATION;
break;
case SlidingMenu.LEFT_RIGHT:
if (mViewBehind.getBehindWidth() > mViewBehind.getSecondaryBehindWidth()) {
duration = MAX_SETTLE_DURATION * Math.abs(dx) / mViewBehind.getBehindWidth();
} else {
duration = MAX_SETTLE_DURATION * Math.abs(dx) / mViewBehind.getSecondaryBehindWidth();
}
break;
default:
duration = MAX_SETTLE_DURATION;
break;
}
}
duration = Math.min(duration, MAX_SETTLE_DURATION);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class CustomViewBehind extends ViewGroup {
private View mSecondaryContent;
private int mMarginThreshold;
private int mWidthOffset;
private int mSecondaryWidthOffset;
private CanvasTransformer mTransformer;
private boolean mChildrenEnabled;

Expand All @@ -53,6 +54,11 @@ public void setWidthOffset(int i) {
mWidthOffset = i;
requestLayout();
}

public void setSecondaryWidthOffset(int offset) {
mSecondaryWidthOffset = offset;
requestLayout();
}

public void setMarginThreshold(int marginThreshold) {
mMarginThreshold = marginThreshold;
Expand All @@ -66,6 +72,10 @@ public int getBehindWidth() {
return mContent.getWidth();
}

public int getSecondaryBehindWidth() {
return mSecondaryContent==null ? 0 : mSecondaryContent.getWidth();
}

public void setContent(View v) {
if (mContent != null)
removeView(mContent);
Expand Down Expand Up @@ -130,7 +140,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int height = b - t;
mContent.layout(0, 0, width-mWidthOffset, height);
if (mSecondaryContent != null)
mSecondaryContent.layout(0, 0, width-mWidthOffset, height);
mSecondaryContent.layout(0, 0, width-mSecondaryWidthOffset, height);
}

@Override
Expand All @@ -141,8 +151,11 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int contentWidth = getChildMeasureSpec(widthMeasureSpec, 0, width-mWidthOffset);
final int contentHeight = getChildMeasureSpec(heightMeasureSpec, 0, height);
mContent.measure(contentWidth, contentHeight);
if (mSecondaryContent != null)
mSecondaryContent.measure(contentWidth, contentHeight);
if (mSecondaryContent != null){
final int contentSecondaryWidth = getChildMeasureSpec(
widthMeasureSpec, 0, width - mSecondaryWidthOffset);
mSecondaryContent.measure(contentSecondaryWidth, contentHeight);
}
}

private int mMode;
Expand Down Expand Up @@ -228,8 +241,8 @@ public void scrollBehindTo(View content, int x, int y) {
if (x <= content.getLeft()) {
scrollTo((int)((x + getBehindWidth())*mScrollScale), y);
} else {
scrollTo((int)(getBehindWidth() - getWidth() +
(x-getBehindWidth())*mScrollScale), y);
scrollTo((int)(getSecondaryBehindWidth() - getWidth() +
(x-getSecondaryBehindWidth())*mScrollScale), y);
}
}
if (vis == View.INVISIBLE)
Expand Down Expand Up @@ -257,7 +270,7 @@ public int getMenuLeft(View content, int page) {
case 0:
return content.getLeft() - getBehindWidth();
case 2:
return content.getLeft() + getBehindWidth();
return content.getLeft() + getSecondaryBehindWidth();
}
}
return content.getLeft();
Expand All @@ -275,9 +288,11 @@ public int getAbsLeftBound(View content) {
public int getAbsRightBound(View content) {
if (mMode == SlidingMenu.LEFT) {
return content.getLeft();
} else if (mMode == SlidingMenu.RIGHT || mMode == SlidingMenu.LEFT_RIGHT) {
return content.getLeft() + getBehindWidth();
}
} else if (mMode == SlidingMenu.RIGHT) {
return content.getLeft() + getBehindWidth();
}else if(mMode == SlidingMenu.LEFT_RIGHT){
return content.getLeft() + getSecondaryBehindWidth();
}
return 0;
}

Expand Down Expand Up @@ -372,11 +387,11 @@ public void drawFade(View content, Canvas canvas, float openPercent) {
left = content.getRight();
right = content.getRight() + getBehindWidth();
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
left = content.getLeft() - getBehindWidth();
left = content.getLeft() - getSecondaryBehindWidth();
right = content.getLeft();
canvas.drawRect(left, 0, right, getHeight(), mFadePaint);
left = content.getRight();
right = content.getRight() + getBehindWidth();
right = content.getRight() + getSecondaryBehindWidth();
}
canvas.drawRect(left, 0, right, getHeight(), mFadePaint);
}
Expand Down
54 changes: 54 additions & 0 deletions library/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,15 @@ public void setBehindOffset(int i) {
mViewBehind.setWidthOffset(i);
}

/**
* Sets the behind secondary offset.
*
* @param offset The margin, in pixels, on the right of the screen that the behind secondary view scrolls to.
*/
public void setBehindSecondaryOffset(int offset) {
mViewBehind.setSecondaryWidthOffset(offset);
}

/**
* Sets the behind offset.
*
Expand All @@ -599,6 +608,17 @@ public void setBehindOffsetRes(int resID) {
setBehindOffset(i);
}

/**
* Sets the behind secondary offset.
*
* @param resID The dimension resource id to be set as the behind secondary offset.
* The secondary menu, when open, will leave this width margin on the right of the screen.
*/
public void setBehindSecondaryOffsetRes(int resID) {
int i = (int) getContext().getResources().getDimension(resID);
setBehindSecondaryOffset(i);
}

/**
* Sets the above offset.
*
Expand Down Expand Up @@ -641,6 +661,29 @@ public void setBehindWidth(int i) {
setBehindOffset(width-i);
}

/**
* Sets the behind secondary width.
*
* @param i The width the Secondary Sliding Menu will open to, in pixels
*/
@SuppressWarnings("deprecation")
public void setBehindSecondaryWidth(int i) {
int width;
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
try {
Class<?> cls = Display.class;
Class<?>[] parameterTypes = {Point.class};
Point parameter = new Point();
Method method = cls.getMethod("getSize", parameterTypes);
method.invoke(display, parameter);
width = parameter.x;
} catch (Exception e) {
width = display.getWidth();
}
setBehindSecondaryOffset(width - i);
}

/**
* Sets the behind width.
*
Expand All @@ -652,6 +695,17 @@ public void setBehindWidthRes(int res) {
setBehindWidth(i);
}

/**
* Sets the behind secondary width.
*
* @param res The dimension resource id to be set as the behind secondary width offset.
* The secondary menu, when open, will open this wide.
*/
public void setBehindSecondaryWidthRes(int res) {
int i = (int) getContext().getResources().getDimension(res);
setBehindSecondaryWidth(i);
}

/**
* Gets the behind scroll scale.
*
Expand Down