Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Leaqi committed Jun 22, 2022
1 parent ef80ef9 commit cfe80d6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Android SwipeDrawer滑动抽屉库,可同时添加上下左右四个方向抽

dependencies {
...
implementation 'cn.Leaqi:SwipeDrawer:1.0'
implementation 'cn.Leaqi:SwipeDrawer:1.1'
}

在布局文件中加入 `SwipeDrawer`
Expand Down
2 changes: 1 addition & 1 deletion README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Add `SwipeDrawer` dependencies:

dependencies {
...
implementation 'cn.Leaqi:SwipeDrawer:1.0'
implementation 'cn.Leaqi:SwipeDrawer:1.1'
}

Add `SwipeDrawer` to the layout file :
Expand Down
20 changes: 18 additions & 2 deletions drawer/src/main/java/cn/leaqi/drawer/SwipeDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class SwipeDrawer extends ViewGroup {
private float shrinkRange = 5;
private int dragDamping = 10;
private int dragRange = 0;
private int dragSlop = 5;
private int maxDragSize = 0;
private int duration = 200;
private int maskColor = -2147483648;
Expand Down Expand Up @@ -178,6 +179,7 @@ private void attrInit(Context context, AttributeSet attr) {
float getShrinkRange = attrArr.getFloat(R.styleable.SwipeDrawer_shrinkRange, shrinkRange);
int getDragDamping = attrArr.getInteger(R.styleable.SwipeDrawer_dragDamping, dragDamping);
int getDragRange = attrArr.getDimensionPixelSize(R.styleable.SwipeDrawer_dragRange, dragRange);
int getDragSlop = attrArr.getDimensionPixelSize(R.styleable.SwipeDrawer_dragSlop, dragSlop);
int getMaxDragSize = attrArr.getDimensionPixelSize(R.styleable.SwipeDrawer_maxDragSize, maxDragSize);
int getDuration = attrArr.getInteger(R.styleable.SwipeDrawer_duration, duration);
int getMaskColor = attrArr.getColor(R.styleable.SwipeDrawer_maskColor, maskColor);
Expand Down Expand Up @@ -217,6 +219,7 @@ private void attrInit(Context context, AttributeSet attr) {
setShrinkRange(getShrinkRange);
setDragDamping(getDragDamping);
setDragRange(getDragRange);
setDragSlop(getDragSlop);
setMaxDragSize(getMaxDragSize);
setMaskColor(getMaskColor);
setDuration(getDuration);
Expand Down Expand Up @@ -331,6 +334,11 @@ public void setDragRange(int num) {
dragRange = num;
}

public void setDragSlop(int num) {
if (num < 0) num = 0;
dragSlop = num;
}

public void setMaxDragSize(int num) {
if (num < 0) num = 0;
maxDragSize = num;
Expand Down Expand Up @@ -685,6 +693,10 @@ public int getDragRange() {
return dragRange;
}

public int getDragSlop() {
return dragSlop;
}

public int getMaxDragSize() {
return maxDragSize;
}
Expand Down Expand Up @@ -1246,6 +1258,9 @@ private boolean checkIntercept(MotionEvent ev) {
int getY = (int) ev.getY();
int shiftX = getX - downX;
int shiftY = getY - downY;
if (dragSlop > 0 && Math.abs(shiftX) < dragSlop && Math.abs(shiftY) < dragSlop){
return false;
}
ViewUtils viewUtils = getIntercept(shiftX, shiftY);
if (isShow && (mainOpen == MAIN_OPEN_CLICK || mainOpen == MAIN_OPEN_INTERCEPT)) {
ViewUtils showUtils = getViewUtils(inDirection);
Expand Down Expand Up @@ -1416,7 +1431,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
case MotionEvent.ACTION_CANCEL:
int getMoveX = Math.abs(getX - downX);
int getMoveY = Math.abs(getY - downY);
if (!isIntercept && (getMs - downMs) < ViewConfiguration.getLongPressTimeout() && getMoveX < 3 && getMoveY < 3){
if (!isIntercept && ((getMoveX == 0 && getMoveY == 0) || (getMs - downMs) < ViewConfiguration.getLongPressTimeout()) && (dragSlop == 0 || (getMoveX < dragSlop && getMoveY < dragSlop))){
boolean isClose = false;
if (isShow && maskClose && maskView != null) {
ViewUtils showUtils = getViewUtils(inDirection);
Expand Down Expand Up @@ -1546,7 +1561,8 @@ public boolean onTouchEvent(MotionEvent ev) {
} else {
int getMoveX = Math.abs(getX - downX);
int getMoveY = Math.abs(getY - downY);
if ((getMs - downMs) < ViewConfiguration.getLongPressTimeout() && getMoveX < 3 && getMoveY < 3) performClick();
if (((getMoveX == 0 && getMoveY == 0) || (getMs - downMs) < ViewConfiguration.getLongPressTimeout()) && (dragSlop == 0 || (getMoveX < dragSlop && getMoveY < dragSlop))) performClick();
//return super.onTouchEvent(ev);
}
break;
}
Expand Down
1 change: 1 addition & 0 deletions drawer/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<attr name="shrinkRange" format="float" />
<attr name="dragDamping" format="integer" />
<attr name="dragRange" format="dimension" />
<attr name="dragSlop" format="dimension" />
<attr name="maxDragSize" format="dimension" />
<attr name="duration" format="integer" />
<attr name="interpolator" format="reference" />
Expand Down

0 comments on commit cfe80d6

Please sign in to comment.