Browse Source

0.0.40.beta10

kongzue 4 years ago
parent
commit
e75b1a0f94

+ 73 - 16
DialogX/src/main/java/com/kongzue/dialogx/util/views/BlurView.java

@@ -3,16 +3,26 @@ package com.kongzue.dialogx.util.views;
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.BitmapShader;
 import android.graphics.Canvas;
 import android.graphics.Color;
+import android.graphics.Matrix;
+import android.graphics.Outline;
 import android.graphics.Paint;
+import android.graphics.PaintFlagsDrawFilter;
 import android.graphics.Path;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
 import android.graphics.Rect;
 import android.graphics.RectF;
+import android.graphics.Shader;
+import android.graphics.drawable.BitmapDrawable;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.util.TypedValue;
 import android.view.View;
+import android.view.ViewOutlineProvider;
 import android.view.ViewTreeObserver;
 
 import androidx.annotation.ColorInt;
@@ -81,6 +91,9 @@ public class BlurView extends View {
     
     private boolean isInit = false;
     
+    Paint cutPaint;
+    Paint overlayPaint;
+    
     private void init(Context context, AttributeSet attrs) {
         if (!isInit) {
             TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RealtimeBlurView);
@@ -96,6 +109,13 @@ public class BlurView extends View {
             mPaint.setAntiAlias(true);
             mRectF = new RectF();
             
+            cutPaint = new Paint();
+            cutPaint.setAntiAlias(true);
+            cutPaint.setColor(mOverlayColor);
+            
+            overlayPaint = new Paint();
+            overlayPaint.setAntiAlias(true);
+            
             mRadius = a.getDimension(R.styleable.RealtimeBlurView_radius, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, context.getResources().getDisplayMetrics()));
             a.recycle();
             
@@ -338,9 +358,6 @@ public class BlurView extends View {
     @Override
     public void draw(Canvas canvas) {
         if (!useBlur) {
-            Paint cutPaint = new Paint();
-            cutPaint.setAntiAlias(true);
-            cutPaint.setColor(mOverlayColor);
             mRectF.right = getWidth();
             mRectF.bottom = getHeight();
             canvas.drawRoundRect(mRectF, mRadius, mRadius, cutPaint);
@@ -351,14 +368,6 @@ public class BlurView extends View {
             } else if (RENDERING_COUNT > 0) {
                 // Doesn't support blurview overlap on another blurview
             } else {
-                if (mRadius != 0) {
-                    Rect rect = new Rect();
-                    getLocalVisibleRect(rect);
-                    rect.right = rect.left + getWidth();
-                    rect.bottom = rect.top + getHeight();
-                    mBoundPath = caculateRoundRectPath(rect);
-                    canvas.clipPath(mBoundPath);
-                }
                 super.draw(canvas);
             }
         }
@@ -386,14 +395,55 @@ public class BlurView extends View {
      * @param overlayColor
      */
     protected void drawBlurredBitmap(Canvas canvas, Bitmap blurredBitmap, int overlayColor) {
+        mRectDst.right = getWidth();
+        mRectDst.bottom = getHeight();
         if (blurredBitmap != null) {
             mRectSrc.right = blurredBitmap.getWidth();
             mRectSrc.bottom = blurredBitmap.getHeight();
-            mRectDst.right = getWidth();
-            mRectDst.bottom = getHeight();
-            canvas.drawBitmap(blurredBitmap, mRectSrc, mRectDst, null);
+            blurredBitmap = getRoundedCornerBitmap(blurredBitmap, mRectDst);
+            if (blurredBitmap != null) canvas.drawBitmap(blurredBitmap, 0, 0, null);
+        }
+    }
+    
+    private Bitmap getRoundedCornerBitmap(Bitmap bitmap,  Rect mRectDst) {
+        bitmap = drawOverlyColor(resizeImage(bitmap, mRectDst.width(), mRectDst.height()));
+        if (bitmap == null) return null;
+        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
+        Canvas canvas = new Canvas(output);
+        BitmapShader bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
+        Paint paint = new Paint();
+        paint.setAntiAlias(true);
+        paint.setShader(bitmapShader);
+        canvas.drawRoundRect(new RectF(mRectDst), mRadius, mRadius, paint);
+        return output;
+    }
+    
+    private Bitmap drawOverlyColor(Bitmap bitmap) {
+        if (bitmap != null) {
+            Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
+            Canvas canvas = new Canvas(output);
+            Rect originRect = new Rect();
+            originRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
+            canvas.drawBitmap(bitmap, originRect, originRect, overlayPaint);
+            canvas.drawColor((supportRenderScript && useBlur) ? mOverlayColor : removeAlphaColor(mOverlayColor));
+            return output;
+        } else {
+            return null;
+        }
+    }
+    
+    private Bitmap resizeImage(Bitmap bitmap, int newWidth, int newHeight) {
+        if (bitmap != null) {
+            int width = bitmap.getWidth();
+            int height = bitmap.getHeight();
+            float scaleWidth = ((float) newWidth) / width;
+            float scaleHeight = ((float) newHeight) / height;
+            Matrix matrix = new Matrix();
+            matrix.postScale(scaleWidth, scaleHeight);
+            return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
+        } else {
+            return null;
         }
-        canvas.drawColor((supportRenderScript && useBlur) ? overlayColor : removeAlphaColor(overlayColor));
     }
     
     private static boolean supportRenderScript = false;
@@ -409,6 +459,13 @@ public class BlurView extends View {
         return this;
     }
     
+    private static int replaceAlphaColor(@ColorInt int color, int alpha) {
+        int red = Color.red(color);
+        int green = Color.green(color);
+        int blue = Color.blue(color);
+        return Color.argb(alpha, red, green, blue);
+    }
+    
     private static int removeAlphaColor(@ColorInt int color) {
         int alpha = 255;
         int red = Color.red(color);
@@ -439,7 +496,7 @@ public class BlurView extends View {
         }.start();
     }
     
-    public static boolean DEBUGMODE = false;
+    public static boolean DEBUGMODE = true;
     
     static boolean isDebug() {
         return DEBUGMODE && DialogX.DEBUGMODE;

+ 7 - 2
DialogX/src/main/java/com/kongzue/dialogx/util/views/DialogXBaseRelativeLayout.java

@@ -68,7 +68,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
             setForceDarkAllowed(false);
         }
-        if (!isInited ) {
+        if (!isInited) {
             if (attrs != null) {
                 TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DialogXBaseRelativeLayout);
                 focusable = a.getBoolean(R.styleable.DialogXBaseRelativeLayout_baseFocusable, true);
@@ -126,7 +126,8 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
         super.onAttachedToWindow();
         final ViewParent parent = getParent();
         
-        if (parent instanceof View)ViewCompat.setFitsSystemWindows(this, ViewCompat.getFitsSystemWindows((View) parent));
+        if (parent instanceof View)
+            ViewCompat.setFitsSystemWindows(this, ViewCompat.getFitsSystemWindows((View) parent));
         ViewCompat.requestApplyInsets(this);
         
         if (BaseDialog.getContext() == null) return;
@@ -190,6 +191,10 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     protected Rect unsafePlace = new Rect();
     
     private void paddingView(int left, int top, int right, int bottom) {
+        if (unsafePlace.top == top && unsafePlace.left == left && unsafePlace.right == right && bottom == 0) {
+            //for Github issues #69: https://github.com/kongzue/DialogX/issues/69
+            return;
+        }
         unsafePlace = new Rect(left, top, right, bottom);
         if (onSafeInsetsChangeListener != null) onSafeInsetsChangeListener.onChange(unsafePlace);
         MaxRelativeLayout bkgView = findViewById(R.id.bkg);

+ 2 - 0
app/build.gradle

@@ -41,4 +41,6 @@ dependencies {
     implementation project(path: ':DialogXMIUIStyle')
 
     implementation 'com.github.kongzue:DialogXStyle-Snackbar:1.0.6'
+    implementation 'com.google.android.material:material:1.4.0'
+    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
 }

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -12,6 +12,7 @@
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
         android:theme="@style/AppTheme">
+        <activity android:name=".AppCompatActivityTest"></activity>
         <activity
             android:name=".MainActivity"
             android:configChanges="orientation|keyboardHidden|screenSize|uiMode|screenLayout|smallestScreenSize|layoutDirection">

+ 36 - 0
app/src/main/java/com/kongzue/dialogxdemo/AppCompatActivityTest.java

@@ -0,0 +1,36 @@
+package com.kongzue.dialogxdemo;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.os.Bundle;
+import android.view.View;
+
+import com.kongzue.dialogx.dialogs.BottomDialog;
+import com.kongzue.dialogx.dialogs.PopTip;
+import com.kongzue.dialogx.interfaces.OnBindView;
+
+public class AppCompatActivityTest extends AppCompatActivity {
+    
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_app_compat_test);
+    }
+    
+    public void btnTextClick(View view) {
+        String s =  "你可以点击空白区域或返回键来关闭这个对话框";
+        new BottomDialog("标题", "这里是对话框内容。\n" + s + "。\n底部对话框也支持自定义布局扩展使用方式。",
+                new OnBindView<BottomDialog>(R.layout.layout_custom_view) {
+                    @Override
+                    public void onBind(BottomDialog dialog, View v) {
+                        v.setOnClickListener(new View.OnClickListener() {
+                            @Override
+                            public void onClick(View v) {
+                                PopTip.show("TESTA!!");
+                            }
+                        });
+                    }
+                })
+                .show();
+    }
+}

+ 7 - 2
app/src/main/java/com/kongzue/dialogxdemo/MainActivity.java

@@ -416,7 +416,12 @@ public class MainActivity extends BaseActivity {
                         new OnBindView<BottomDialog>(R.layout.layout_custom_view) {
                             @Override
                             public void onBind(BottomDialog dialog, View v) {
-                            
+                                v.setOnClickListener(new View.OnClickListener() {
+                                    @Override
+                                    public void onClick(View v) {
+                                    
+                                    }
+                                });
                             }
                         })
                         .show();
@@ -561,7 +566,7 @@ public class MainActivity extends BaseActivity {
         btnShowBreak.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                jump(MainActivity.class, new JumpParameter().put("showBreak", true));
+                jump(AppCompatActivityTest.class, new JumpParameter().put("showBreak", true));
             }
         });
         

+ 16 - 0
app/src/main/res/layout/activity_app_compat_test.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".AppCompatActivityTest">
+
+    <Button
+        android:onClick="btnTextClick"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerInParent="true"
+        android:text="Test!"/>
+
+</RelativeLayout>

+ 1 - 1
app/src/main/res/layout/activity_main.xml

@@ -4,7 +4,7 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="#f4f5f6"
+    android:background="@color/background"
     android:fitsSystemWindows="true"
     tools:context=".MainActivity">
 

+ 2 - 0
app/src/main/res/values/colors.xml

@@ -6,4 +6,6 @@
 
     <color name="colorNavbarBkg">#01000000</color>
     <color name="emptyNavBar">#01FFFFFF</color>
+    <color name="background">#f4f5f6</color>
+<!--    <color name="background">#000000</color>-->
 </resources>

+ 1 - 1
build.gradle

@@ -8,7 +8,7 @@ buildscript {
         }
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:4.2.0'
+        classpath 'com.android.tools.build:gradle:4.2.2'
         classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
 
         // NOTE: Do not place your application dependencies here; they belong

+ 1 - 1
gradle.properties

@@ -18,5 +18,5 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 
-BUILD_VERSION=0.0.40.debug9
+BUILD_VERSION=0.0.40.beta10
 BUILD_VERSION_INT=39