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 60cc0414..41038575 100644 --- a/app/src/main/java/com/lxj/xpopupdemo/fragment/QuickStartDemo.java +++ b/app/src/main/java/com/lxj/xpopupdemo/fragment/QuickStartDemo.java @@ -269,6 +269,7 @@ public void run() { case R.id.btnShowBottomList: //从底部弹出,带手势拖拽的列表弹窗 popupView = new XPopup.Builder(getContext()) .isDarkTheme(true) + .hasShadowBg(false) .customHostLifecycle(getLifecycle()) .moveUpToKeyboard(false) .isDestroyOnDismiss(false) @@ -303,6 +304,7 @@ public void onSelect(int position, String text) { break; case R.id.btnCustomBottomPopup: //自定义的底部弹窗 new XPopup.Builder(getContext()) + .hasShadowBg(false) .moveUpToKeyboard(false) //如果不加这个,评论弹窗会移动到软键盘上面 // .isViewMode(true) .isDestroyOnDismiss(true) //对于只使用一次的弹窗,推荐设置这个 @@ -312,6 +314,7 @@ public void onSelect(int position, String text) { break; case R.id.btnPagerBottomPopup: //自定义的底部弹窗 new XPopup.Builder(getContext()) + .hasShadowBg(false) .isDestroyOnDismiss(true) //对于只使用一次的弹窗,推荐设置这个 .isViewMode(true) .asCustom(new PagerBottomPopup(getContext())) @@ -324,6 +327,7 @@ public void onSelect(int position, String text) { .hasStatusBarShadow(false) // .isRequestFocus(false) .isCoverSoftInput(true) + .hasShadowBg(false) // .popupAnimation(PopupAnimation.ScrollAlphaFromTop) // .isClickThrough(true) // .isDestroyOnDismiss(true) //对于只使用一次的弹窗,推荐设置这个 @@ -363,7 +367,6 @@ public void onSelect(int position, String text) { new XPopup.Builder(getContext()) .isDestroyOnDismiss(true) //对于只使用一次的弹窗,推荐设置这个 .atView(v) - .hasShadowBg(false) // 去掉半透明背景 .asCustom(customAttach2) .show(); break; @@ -389,6 +392,7 @@ public void onSelect(int position, String text) { break; case R.id.btnBubbleAttachPopup2: //垂直方向带气泡弹窗 new XPopup.Builder(getContext()) + .hasShadowBg(false) .isTouchThrough(true) .isDestroyOnDismiss(true) //对于只使用一次的弹窗,推荐设置这个 .atView(view.findViewById(R.id.vv)) @@ -451,7 +455,7 @@ public void onSelect(int position, String text) { .offsetY(300) .offsetX(-100) .hasShadowBg(false) -// .hasBlurBg(true) + .hasBlurBg(true) .popupAnimation(PopupAnimation.TranslateFromLeft) .asCustom(new QQMsgPopup(getContext())) .show(); @@ -459,7 +463,7 @@ public void onSelect(int position, String text) { case R.id.btnShowPosition2: new XPopup.Builder(getContext()) .hasShadowBg(false) -// .hasBlurBg(true) + .hasBlurBg(true) .isDestroyOnDismiss(true) //对于只使用一次的弹窗,推荐设置这个 .isCenterHorizontal(true) .offsetY(200) diff --git a/library/build.gradle b/library/build.gradle index 4d2c7cb3..5b7ffaa1 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -26,4 +26,5 @@ dependencies { implementation 'com.github.li-xiaojun:EasyAdapter:1.2.8' implementation 'com.github.bumptech.glide:glide:4.12.0' implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0' + implementation 'com.github.mmin18:realtimeblurview:1.2.1' } diff --git a/library/src/main/java/com/lxj/xpopup/animator/BlurAnimator.java b/library/src/main/java/com/lxj/xpopup/animator/BlurAnimator.java index e63a2144..83153d98 100644 --- a/library/src/main/java/com/lxj/xpopup/animator/BlurAnimator.java +++ b/library/src/main/java/com/lxj/xpopup/animator/BlurAnimator.java @@ -27,7 +27,7 @@ public BlurAnimator(View target, int shadowColor) { public BlurAnimator() {} @Override public void initAnimator() { - Bitmap blurBmp = XPopupUtils.renderScriptBlur(targetView.getContext(), decorBitmap, 25, true); + Bitmap blurBmp = XPopupUtils.renderScriptBlur(targetView.getContext(), decorBitmap, 10, true); BitmapDrawable drawable = new BitmapDrawable(targetView.getResources(), blurBmp); if(hasShadowBg) drawable.setColorFilter(shadowColor, PorterDuff.Mode.SRC_OVER); targetView.setBackground(drawable); diff --git a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java index 7e6612f2..b8105c87 100644 --- a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java @@ -5,6 +5,7 @@ import android.app.Application; import android.content.Context; import android.content.res.Configuration; +import android.graphics.Color; import android.graphics.Point; import android.graphics.Rect; import android.os.Build; @@ -259,7 +260,8 @@ protected void init() { if (popupInfo.hasBlurBg) { blurAnimator = new BlurAnimator(this, getShadowBgColor()); blurAnimator.hasShadowBg = popupInfo.hasShadowBg; - blurAnimator.decorBitmap = XPopupUtils.view2Bitmap((getActivity()).getWindow().getDecorView()); + blurAnimator.decorBitmap = XPopupUtils.view2Bitmap((getActivity()).getWindow().getDecorView(), + getActivityContentView().getHeight(), 5); } //1. 初始化Popup diff --git a/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java b/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java index a68df770..6ef971b1 100644 --- a/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java +++ b/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java @@ -538,13 +538,17 @@ public static Bitmap renderScriptBlur(Context context, final Bitmap src, return ret; } + public static Bitmap view2Bitmap(final View view) { + return view2Bitmap(view, -1, 1); + } + /** * View to bitmap. * * @param view The view. * @return bitmap */ - public static Bitmap view2Bitmap(final View view) { + public static Bitmap view2Bitmap(final View view, int clipHeight, int scale) { if (view == null) return null; boolean drawingCacheEnabled = view.isDrawingCacheEnabled(); boolean willNotCacheDrawing = view.willNotCacheDrawing(); @@ -559,20 +563,21 @@ public static Bitmap view2Bitmap(final View view) { view.buildDrawingCache(); drawingCache = view.getDrawingCache(); if (drawingCache != null) { - bitmap = Bitmap.createBitmap(drawingCache); + bitmap = Bitmap.createBitmap(drawingCache, 0,0,drawingCache.getWidth(),clipHeight>0 ?clipHeight: drawingCache.getHeight()); } else { - bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888); + bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), clipHeight>0 ?clipHeight: view.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); } } else { - bitmap = Bitmap.createBitmap(drawingCache); + bitmap = Bitmap.createBitmap(drawingCache,0,0,drawingCache.getWidth(),clipHeight>0 ?clipHeight: drawingCache.getHeight()); } view.destroyDrawingCache(); view.setWillNotCacheDrawing(willNotCacheDrawing); view.setDrawingCacheEnabled(drawingCacheEnabled); -// return bitmap; - return Bitmap.createScaledBitmap(bitmap, view.getMeasuredWidth() / 2, view.getMeasuredHeight() / 2, true); + Bitmap small = Bitmap.createScaledBitmap(bitmap, view.getMeasuredWidth() / scale, view.getMeasuredHeight() / scale, true); + if (!bitmap.isRecycled() && bitmap!=small ) bitmap.recycle(); + return small; } public static boolean isLayoutRtl(Context context) {