Skip to content

Commit

Permalink
Merge pull request daimajia#257 from sergiandreplace/master
Browse files Browse the repository at this point in the history
Added ability to setup the willOpen percents for automated opening
  • Loading branch information
linfaxin committed Jan 5, 2016
2 parents f66ac69 + be4a2c7 commit d7a5759
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion library/src/main/java/com/daimajia/swipe/SwipeLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class SwipeLayout extends FrameLayout {
private boolean mSwipeEnabled = true;
private boolean[] mSwipesEnabled = new boolean[]{true, true, true, true};
private boolean mClickToClose = false;
private float mWillOpenPercentAfterOpen=0.75f;
private float mWillOpenPercentAfterClose=0.25f;

public enum DragEdge {
Left,
Expand Down Expand Up @@ -1041,6 +1043,39 @@ public boolean isBottomSwipeEnabled() {
public void setBottomSwipeEnabled(boolean bottomSwipeEnabled) {
this.mSwipesEnabled[DragEdge.Bottom.ordinal()] = bottomSwipeEnabled;
}
/***
* Returns the percentage of revealing at which the view below should the view finish opening
* if it was already open before dragging
* @returns The percentage of view revealed to trigger, default value is 0.25
*/
public float getWillOpenPercentAfterOpen() {
return mWillOpenPercentAfterOpen;
}

/***
* Allows to stablish at what percentage of revealing the view below should the view finish opening
* if it was already open before dragging
* @param willOpenPercentAfterOpen The percentage of view revealed to trigger, default value is 0.25
*/
public void setWillOpenPercentAfterOpen(float willOpenPercentAfterOpen) {
this.mWillOpenPercentAfterOpen = willOpenPercentAfterOpen;
}
/***
* Returns the percentage of revealing at which the view below should the view finish opening
* if it was already closed before dragging
* @returns The percentage of view revealed to trigger, default value is 0.25
*/
public float getWillOpenPercentAfterClose() {
return mWillOpenPercentAfterClose;
}
/***
* Allows to stablish at what percentage of revealing the view below should the view finish opening
* if it was already closed before dragging
* @param willOpenPercentAfterClose The percentage of view revealed to trigger, default value is 0.75
*/
public void setWillOpenPercentAfterClose(float willOpenPercentAfterClose) {
this.mWillOpenPercentAfterClose = willOpenPercentAfterClose;
}

private boolean insideAdapterView() {
return getAdapterView() != null;
Expand Down Expand Up @@ -1289,7 +1324,7 @@ protected void processHandRelease(float xvel, float yvel, boolean isCloseBeforeD
if (currentDragEdge == null || surfaceView == null) {
return;
}
float willOpenPercent = (isCloseBeforeDragged ? .25f : .75f);
float willOpenPercent = (isCloseBeforeDragged ? mWillOpenPercentAfterClose : mWillOpenPercentAfterOpen););
if (currentDragEdge == DragEdge.Left) {
if (xvel > minVelocity) open();
else if (xvel < -minVelocity) close();
Expand Down

0 comments on commit d7a5759

Please sign in to comment.