Skip to content

Commit

Permalink
修复hasBlurBg()被错位的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
junixapp committed Dec 15, 2022
1 parent 81a918c commit 4e5041b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) //对于只使用一次的弹窗,推荐设置这个
Expand All @@ -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()))
Expand All @@ -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) //对于只使用一次的弹窗,推荐设置这个
Expand Down Expand Up @@ -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;
Expand All @@ -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))
Expand Down Expand Up @@ -451,15 +455,15 @@ 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();
break;
case R.id.btnShowPosition2:
new XPopup.Builder(getContext())
.hasShadowBg(false)
// .hasBlurBg(true)
.hasBlurBg(true)
.isDestroyOnDismiss(true) //对于只使用一次的弹窗,推荐设置这个
.isCenterHorizontal(true)
.offsetY(200)
Expand Down
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion library/src/main/java/com/lxj/xpopup/core/BasePopupView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down

0 comments on commit 4e5041b

Please sign in to comment.