From 87fc8922998ed16f71975d0fe185a4c95f48210e Mon Sep 17 00:00:00 2001 From: razerdp Date: Wed, 13 Dec 2017 17:27:09 +0800 Subject: [PATCH] // update to 1.8.8 and fix #47 --- ISSUE_TEMPLATE.md | 9 ++- README.md | 11 ++- .../java/razerdp/demo/popup/ScalePopup.java | 20 +++-- lib/build.gradle | 2 +- .../razerdp/basepopup/BasePopupHelper.java | 15 ++-- .../razerdp/basepopup/BasePopupWindow.java | 74 ++++++++++++------ ...nimUtil.java => SimpleAnimationUtils.java} | 78 ++++++++++--------- 7 files changed, 129 insertions(+), 80 deletions(-) rename lib/src/main/java/razerdp/util/{SimpleAnimUtil.java => SimpleAnimationUtils.java} (54%) diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index a1e7dc87..c2472d85 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -6,4 +6,11 @@ -### 报错信息 +### 报错信息/系统版本 + +```java + +``` + + +### 建议或优化点 \ No newline at end of file diff --git a/README.md b/README.md index 82084343..f6789fea 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,14 @@ ## 更新日志: -#### 1.8.8(未发布,等到解决别的issue后一同发布) +#### 1.8.8 - `BasePopupWindowProxy`和`PopupWindowProxy`权限收拢,不暴露放开 + - 优化`SimpleAnimUtil`,修改部分动画时间和插值器 + - 增加`setOutsideTouchable()`方法,和`setDismissWhenTouchOutside()`搭配使用有奇效哦 + - 增加`BasePopupHelper`优化`BasePopupWindow`代码可读性 + - 动画方面修正`AnimaView.clearAnimation()`->`Animation.cancel()` + - 优化`showOnTop()`/`showOnDown()`方法。。。虽然可能没什么人用 + - 【未解决】`setBackPressEnable()`在M以上依然未能解决,除非我hook掉(但是代价太大),详情请看[#33](https://github.com/razerdp/BasePopup/issues/33)/问题描述:[查看描述](https://github.com/razerdp/BasePopup/blob/master/%E5%85%B3%E4%BA%8EAndorid%20M%E4%BB%A5%E4%B8%8AsetBackPressEnable()%E5%A4%B1%E6%95%88%E7%9A%84%E9%97%AE%E9%A2%98%E7%9A%84%E5%88%86%E6%9E%90.md) #### 1.8.7 - 抽取`PopupWindowProxy`->`BasePopupWindowProxy` @@ -35,9 +41,6 @@ - 针对诸位提出的setBackPress在6.0以上失效的问题,请查看这份[MD](https://github.com/razerdp/BasePopup/blob/master/%E5%85%B3%E4%BA%8EAndorid%20M%E4%BB%A5%E4%B8%8AsetBackPressEnable()%E5%A4%B1%E6%95%88%E7%9A%84%E9%97%AE%E9%A2%98%E7%9A%84%E5%88%86%E6%9E%90.md)文件(没错,暂时无法修复) - 删除`setRelativeToAnchorView()`方法,该方法本身就没有什么用处。。。 -##### 1.8.4: - - 补充PopupWindowProxy的scanForActivity方法(不知明原因在merged后丢失了) - ### 最低SDK版本要求 : API 11 diff --git a/app/src/main/java/razerdp/demo/popup/ScalePopup.java b/app/src/main/java/razerdp/demo/popup/ScalePopup.java index 0731280a..9b627979 100644 --- a/app/src/main/java/razerdp/demo/popup/ScalePopup.java +++ b/app/src/main/java/razerdp/demo/popup/ScalePopup.java @@ -4,6 +4,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.animation.Animation; + import razerdp.basepopup.BasePopupWindow; import razerdp.basepopup.R; import razerdp.demo.utils.ToastUtils; @@ -12,7 +13,7 @@ * Created by 大灯泡 on 2016/1/15. * 普通的popup */ -public class ScalePopup extends BasePopupWindow implements View.OnClickListener{ +public class ScalePopup extends BasePopupWindow implements View.OnClickListener { private View popupView; @@ -22,12 +23,15 @@ public ScalePopup(Activity context) { } - @Override protected Animation initShowAnimation() { return getDefaultScaleAnimation(); } + @Override + protected Animation initExitAnimation() { + return getDefaultScaleAnimation(false); + } @Override public View getClickToDismissView() { @@ -36,7 +40,7 @@ public View getClickToDismissView() { @Override public View onCreatePopupView() { - popupView= LayoutInflater.from(getContext()).inflate(R.layout.popup_normal,null); + popupView = LayoutInflater.from(getContext()).inflate(R.layout.popup_normal, null); return popupView; } @@ -46,7 +50,7 @@ public View initAnimaView() { } private void bindEvent() { - if (popupView!=null){ + if (popupView != null) { popupView.findViewById(R.id.tx_1).setOnClickListener(this); popupView.findViewById(R.id.tx_2).setOnClickListener(this); popupView.findViewById(R.id.tx_3).setOnClickListener(this); @@ -56,15 +60,15 @@ private void bindEvent() { @Override public void onClick(View v) { - switch (v.getId()){ + switch (v.getId()) { case R.id.tx_1: - ToastUtils.ToastMessage(getContext(),"click tx_1"); + ToastUtils.ToastMessage(getContext(), "click tx_1"); break; case R.id.tx_2: - ToastUtils.ToastMessage(getContext(),"click tx_2"); + ToastUtils.ToastMessage(getContext(), "click tx_2"); break; case R.id.tx_3: - ToastUtils.ToastMessage(getContext(),"click tx_3"); + ToastUtils.ToastMessage(getContext(), "click tx_3"); break; default: break; diff --git a/lib/build.gradle b/lib/build.gradle index b3414f7a..d2600ff2 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -31,7 +31,7 @@ publish { userOrg = 'razerdp' groupId = 'com.github.razerdp' artifactId = 'BasePopup' - publishVersion = '1.8.7' + publishVersion = '1.8.8' desc = '打造一个通用的Popup' website = 'https://github.com/razerdp/BasePopup' } diff --git a/lib/src/main/java/razerdp/basepopup/BasePopupHelper.java b/lib/src/main/java/razerdp/basepopup/BasePopupHelper.java index d30c92af..94d90360 100644 --- a/lib/src/main/java/razerdp/basepopup/BasePopupHelper.java +++ b/lib/src/main/java/razerdp/basepopup/BasePopupHelper.java @@ -44,7 +44,7 @@ final class BasePopupHelper { //点击popup外部是否消失 private boolean dismissWhenTouchOutside; //外部是否可用点击 - private boolean mOutsideClickable; + private boolean mOutsideTouchable; //是否需要淡入window动画 private volatile boolean needPopupFadeAnima = true; @@ -235,16 +235,19 @@ public BasePopupHelper setDismissWhenTouchOutside(boolean dismissWhenTouchOutsid outsideTouchable = false; hasBackground = false; } + if (outsideTouchable) { + focusable = false; + } return this; } - public boolean isOutsideClickable() { - return mOutsideClickable; + public boolean isOutsideTouchable() { + return mOutsideTouchable; } - public BasePopupHelper setOutsideClickable(boolean outsideClickable) { - mOutsideClickable = outsideClickable; - focusable = true; + public BasePopupHelper setOutsideTouchable(boolean outsideClickable) { + mOutsideTouchable = outsideClickable; + focusable = false; return this; } diff --git a/lib/src/main/java/razerdp/basepopup/BasePopupWindow.java b/lib/src/main/java/razerdp/basepopup/BasePopupWindow.java index 121b2c71..9cafb179 100644 --- a/lib/src/main/java/razerdp/basepopup/BasePopupWindow.java +++ b/lib/src/main/java/razerdp/basepopup/BasePopupWindow.java @@ -205,6 +205,7 @@ file or class name and description of purpose be included on the package razerdp.basepopup; import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; import android.app.Activity; import android.content.Context; @@ -225,7 +226,7 @@ file or class name and description of purpose be included on the import java.lang.reflect.Field; import razerdp.util.InputMethodUtils; -import razerdp.util.SimpleAnimUtil; +import razerdp.util.SimpleAnimationUtils; /** * Created by 大灯泡 on 2016/1/14. @@ -543,9 +544,9 @@ private int[] calculateOffset(View anchorView) { final boolean onTop = (getScreenHeight() - (mHelper.getAnchorY() + offset[1]) < getHeight()); if (onTop) { offset[1] = -anchorView.getHeight() - getHeight() - offset[1]; - showOnTop(mPopupView); + showOnTop(mPopupView, anchorView); } else { - showOnDown(mPopupView); + showOnDown(mPopupView, anchorView); } } return offset; @@ -824,8 +825,8 @@ public BasePopupWindow setDismissWhenTouchOutside(boolean dismissWhenTouchOutsid return this; } - public BasePopupWindow setOutsideClickable(boolean clickable) { - mHelper.setOutsideClickable(clickable); + public BasePopupWindow setOutsideTouchable(boolean touchable) { + mHelper.setOutsideTouchable(touchable); return this; } @@ -834,7 +835,7 @@ public boolean isDismissWhenTouchOutside() { } public boolean isOutsideClickable() { - return mHelper.isOutsideClickable(); + return mHelper.isOutsideTouchable(); } //------------------------------------------状态控制----------------------------------------------- @@ -915,7 +916,8 @@ private boolean checkPerformShow(View v) { //------------------------------------------Anima----------------------------------------------- - private Animator.AnimatorListener mAnimatorListener = new Animator.AnimatorListener() { + private Animator.AnimatorListener mAnimatorListener = new AnimatorListenerAdapter() { + @Override public void onAnimationStart(Animator animation) { isExitAnimaPlaying = true; @@ -932,13 +934,9 @@ public void onAnimationCancel(Animator animation) { isExitAnimaPlaying = false; } - @Override - public void onAnimationRepeat(Animator animation) { - - } }; - private Animation.AnimationListener mAnimationListener = new Animation.AnimationListener() { + private Animation.AnimationListener mAnimationListener = new SimpleAnimationUtils.AnimationListenerAdapter() { @Override public void onAnimationStart(Animation animation) { isExitAnimaPlaying = true; @@ -949,11 +947,6 @@ public void onAnimationEnd(Animation animation) { mPopupWindow.callSuperDismiss(); isExitAnimaPlaying = false; } - - @Override - public void onAnimationRepeat(Animation animation) { - - } }; /** @@ -963,7 +956,7 @@ public void onAnimationRepeat(Animation animation) { * @param start 初始位置 */ protected Animation getTranslateAnimation(int start, int end, int durationMillis) { - return SimpleAnimUtil.getTranslateAnimation(start, end, durationMillis); + return SimpleAnimationUtils.getTranslateAnimation(start, end, durationMillis); } /** @@ -979,28 +972,48 @@ protected Animation getScaleAnimation(float fromX, float pivotXValue, int pivotYType, float pivotYValue) { - return SimpleAnimUtil.getScaleAnimation(fromX, toX, fromY, toY, pivotXType, pivotXValue, pivotYType, pivotYValue); + return SimpleAnimationUtils.getScaleAnimation(fromX, toX, fromY, toY, pivotXType, pivotXValue, pivotYType, pivotYValue); } + /** * 生成自定义ScaleAnimation */ protected Animation getDefaultScaleAnimation() { - return SimpleAnimUtil.getDefaultScaleAnimation(); + return getDefaultScaleAnimation(true); } + /** + * 生成自定义ScaleAnimation + * + * @param in true for scale in + */ + protected Animation getDefaultScaleAnimation(boolean in) { + return SimpleAnimationUtils.getDefaultScaleAnimation(in); + } + + /** * 生成默认的AlphaAnimation */ protected Animation getDefaultAlphaAnimation() { - return SimpleAnimUtil.getDefaultAlphaAnimation(); + return getDefaultAlphaAnimation(true); + } + + /** + * 生成默认的AlphaAnimation + * + * @param in true for alpha in + */ + protected Animation getDefaultAlphaAnimation(boolean in) { + return SimpleAnimationUtils.getDefaultAlphaAnimation(in); } /** * 从下方滑动上来 */ protected AnimatorSet getDefaultSlideFromBottomAnimationSet() { - return SimpleAnimUtil.getDefaultSlideFromBottomAnimationSet(mAnimaView); + return SimpleAnimationUtils.getDefaultSlideFromBottomAnimationSet(mAnimaView); } /** @@ -1018,11 +1031,24 @@ public int getScreenWidth() { } //------------------------------------------callback----------------------------------------------- - protected void showOnTop(View mPopupView) { + + /** + * 在anchorView上方显示,autoLocatePopup为true时适用 + * + * @param mPopupView {@link #onCreatePopupView()}返回的View + * @param anchorView {@link #showPopupWindow(View)}传入的View + */ + protected void showOnTop(View mPopupView, View anchorView) { } - protected void showOnDown(View mPopupView) { + /** + * 在anchorView下方显示,autoLocatePopup为true时适用 + * + * @param mPopupView {@link #onCreatePopupView()}返回的View + * @param anchorView {@link #showPopupWindow(View)}传入的View + */ + protected void showOnDown(View mPopupView, View anchorView) { } diff --git a/lib/src/main/java/razerdp/util/SimpleAnimUtil.java b/lib/src/main/java/razerdp/util/SimpleAnimationUtils.java similarity index 54% rename from lib/src/main/java/razerdp/util/SimpleAnimUtil.java rename to lib/src/main/java/razerdp/util/SimpleAnimationUtils.java index 6106d4dd..5653e1be 100644 --- a/lib/src/main/java/razerdp/util/SimpleAnimUtil.java +++ b/lib/src/main/java/razerdp/util/SimpleAnimationUtils.java @@ -13,7 +13,7 @@ * Created by 大灯泡 on 2017/1/13. */ -public class SimpleAnimUtil { +public class SimpleAnimationUtils { /** @@ -25,46 +25,36 @@ public class SimpleAnimUtil { public static Animation getTranslateAnimation(int start, int end, int durationMillis) { Animation translateAnimation = new TranslateAnimation(0, 0, start, end); translateAnimation.setDuration(durationMillis); - translateAnimation.setFillEnabled(true); - translateAnimation.setFillAfter(true); return translateAnimation; } /** - * 生成ScaleAnimation - * - * time=300 + * 生成自定义ScaleAnimation */ - public static Animation getScaleAnimation(float fromX, - float toX, - float fromY, - float toY, - int pivotXType, - float pivotXValue, - int pivotYType, - float pivotYValue) { - Animation scaleAnimation = new ScaleAnimation(fromX, toX, fromY, toY, pivotXType, pivotXValue, pivotYType, - pivotYValue - ); - scaleAnimation.setDuration(300); - scaleAnimation.setFillEnabled(true); - scaleAnimation.setFillAfter(true); - return scaleAnimation; + public static Animation getDefaultScaleAnimation(boolean in) { + return getScaleAnimation(in ? 0 : 1, in ? 1 : 0, in ? 0 : 1, in ? 1 : 0, Animation.RELATIVE_TO_SELF, 0.5f, + Animation.RELATIVE_TO_SELF, 0.5f); } /** - * 生成自定义ScaleAnimation + * 生成ScaleAnimation + *

+ * time=360 */ - public static Animation getDefaultScaleAnimation() { - Animation scaleAnimation = new ScaleAnimation(0f, 1f, 0f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, - Animation.RELATIVE_TO_SELF, 0.5f + public static Animation getScaleAnimation(float fromX, + float toX, + float fromY, + float toY, + int pivotXType, + float pivotXValue, + int pivotYType, + float pivotYValue) { + Animation scaleAnimation = new ScaleAnimation(fromX, toX, fromY, toY, pivotXType, pivotXValue, pivotYType, + pivotYValue ); - scaleAnimation.setDuration(300); - scaleAnimation.setInterpolator(new AccelerateInterpolator()); - scaleAnimation.setFillEnabled(true); - scaleAnimation.setFillAfter(true); + scaleAnimation.setDuration(360); return scaleAnimation; } @@ -72,17 +62,14 @@ public static Animation getDefaultScaleAnimation() { /** * 生成默认的AlphaAnimation */ - public static Animation getDefaultAlphaAnimation() { - Animation alphaAnimation = new AlphaAnimation(0.0f, 1.0f); - alphaAnimation.setDuration(300); + public static Animation getDefaultAlphaAnimation(boolean in) { + Animation alphaAnimation = new AlphaAnimation(in ? 0 : 1, in ? 1 : 0); + alphaAnimation.setDuration(360); alphaAnimation.setInterpolator(new AccelerateInterpolator()); - alphaAnimation.setFillEnabled(true); - alphaAnimation.setFillAfter(true); return alphaAnimation; } - /** * 从下方滑动上来 */ @@ -93,8 +80,27 @@ public static AnimatorSet getDefaultSlideFromBottomAnimationSet(View mAnimaView) set.playTogether( ObjectAnimator.ofFloat(mAnimaView, "translationY", 250, 0).setDuration(400), ObjectAnimator.ofFloat(mAnimaView, "alpha", 0.4f, 1).setDuration(250 * 3 / 2) - ); + ); } return set; } + + + public static abstract class AnimationListenerAdapter implements Animation.AnimationListener { + @Override + public void onAnimationStart(Animation animation) { + + } + + @Override + public void onAnimationEnd(Animation animation) { + + } + + @Override + public void onAnimationRepeat(Animation animation) { + + } + } + }