diff --git a/app/src/main/java/com/lxj/xpopupdemo/fragment/CustomPopupDemo.java b/app/src/main/java/com/lxj/xpopupdemo/fragment/CustomPopupDemo.java index a5a056e1..850404fa 100644 --- a/app/src/main/java/com/lxj/xpopupdemo/fragment/CustomPopupDemo.java +++ b/app/src/main/java/com/lxj/xpopupdemo/fragment/CustomPopupDemo.java @@ -51,8 +51,8 @@ public void onItemSelected(AdapterView parent, View view, final int position, @Override public void run() { XPopup.get(getContext()) -// .popupAnimation(datas[position]) - .asCustom(new CustomPopup2(getContext())) + .popupAnimation(datas[position]) + .asCustom(new CustomPopup(getContext())) // .setWidthAndHeight(XPopupUtils.getWindowWidth(getContext()),XPopupUtils.getWindowHeight(getContext())) .show(); } diff --git a/app/src/main/java/com/lxj/xpopupdemo/fragment/QuickStartDemo.java b/app/src/main/java/com/lxj/xpopupdemo/fragment/QuickStartDemo.java index 77a1c933..37853119 100644 --- a/app/src/main/java/com/lxj/xpopupdemo/fragment/QuickStartDemo.java +++ b/app/src/main/java/com/lxj/xpopupdemo/fragment/QuickStartDemo.java @@ -186,12 +186,10 @@ public void onSelect(int position, String text) { @Override public void onPause() { super.onPause(); - Log.e("tag", "onPause"); } @Override public void onStop() { super.onStop(); - Log.e("tag", "onStop"); } } diff --git a/app/src/main/res/layout/custom_popup.xml b/app/src/main/res/layout/custom_popup.xml index 42154f23..bdd0ecf7 100644 --- a/app/src/main/res/layout/custom_popup.xml +++ b/app/src/main/res/layout/custom_popup.xml @@ -2,7 +2,7 @@ diff --git a/library/src/main/java/com/lxj/xpopup/widget/PopupDrawerLayout.java b/library/src/main/java/com/lxj/xpopup/widget/PopupDrawerLayout.java index 2fd18e5e..df0a631b 100644 --- a/library/src/main/java/com/lxj/xpopup/widget/PopupDrawerLayout.java +++ b/library/src/main/java/com/lxj/xpopup/widget/PopupDrawerLayout.java @@ -5,6 +5,7 @@ import android.support.v4.view.ViewCompat; import android.support.v4.widget.ViewDragHelper; import android.util.AttributeSet; +import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.widget.FrameLayout; @@ -61,14 +62,38 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto child.layout(getMeasuredWidth(), 0, getMeasuredWidth() + child.getMeasuredWidth(), getMeasuredHeight()); } hasLayout = true; - }else { + } else { child.layout(child.getLeft(), child.getTop(), child.getRight(), child.getBottom()); } } +// float x,y; +// @Override +// public boolean dispatchTouchEvent(MotionEvent ev) { +// switch (ev.getAction()) { +// case MotionEvent.ACTION_DOWN: +// x = ev.getX(); +// y = ev.getY(); +// break; +// case MotionEvent.ACTION_MOVE: +// float dx = ev.getX() - x; +// float dy = ev.getY() - y; +// if(Math.abs(dx) > Math.abs(dy)) +// +// break; +// case MotionEvent.ACTION_UP: +// case MotionEvent.ACTION_CANCEL: +// +// break; +// } +// return super.dispatchTouchEvent(ev); +// } + + boolean isIntercept = false; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - return dragHelper.shouldInterceptTouchEvent(ev); + isIntercept = dragHelper.shouldInterceptTouchEvent(ev); + return isIntercept; } @Override @@ -125,15 +150,23 @@ public void onViewPositionChanged(@NonNull View changedView, int left, int top, public void onViewReleased(@NonNull View releasedChild, float xvel, float yvel) { super.onViewReleased(releasedChild, xvel, yvel); int centerLeft = 0; + int finalLeft = 0; if (position == Position.Left) { - centerLeft = -child.getMeasuredWidth() / 2; - int finalLeft = child.getLeft() < centerLeft ? -child.getMeasuredWidth() : 0; - dragHelper.smoothSlideViewTo(releasedChild, finalLeft, releasedChild.getTop()); + if (xvel < -1000) { + finalLeft = -child.getMeasuredWidth(); + } else { + centerLeft = -child.getMeasuredWidth() / 2; + finalLeft = child.getLeft() < centerLeft ? -child.getMeasuredWidth() : 0; + } } else { - centerLeft = getMeasuredWidth() - child.getMeasuredWidth() / 2; - int finalLeft = releasedChild.getLeft() < centerLeft ? getMeasuredWidth() - child.getMeasuredWidth() : getMeasuredWidth(); - dragHelper.smoothSlideViewTo(releasedChild, finalLeft, releasedChild.getTop()); + if (xvel > 1000) { + finalLeft = getMeasuredWidth(); + } else { + centerLeft = getMeasuredWidth() - child.getMeasuredWidth() / 2; + finalLeft = releasedChild.getLeft() < centerLeft ? getMeasuredWidth() - child.getMeasuredWidth() : getMeasuredWidth(); + } } + dragHelper.smoothSlideViewTo(releasedChild, finalLeft, releasedChild.getTop()); ViewCompat.postInvalidateOnAnimation(PopupDrawerLayout.this); } };