瀏覽代碼

Set minSdkVersion to 23 (Android 6)

Because of updating the minSdkVersion to 23 it comes to some obscure UI
freezes when using frescos 'RoundPostprocessor#process' to round avatar
bitmaps.
So the function 'DisplayUtils#roundBitmap' is adopted from Nextcloud
Files for Android.

Signed-off-by: Tim Krüger <t@timkrueger.me>
Tim Krüger 2 年之前
父節點
當前提交
8a0e60f68a

+ 1 - 1
app/build.gradle

@@ -42,7 +42,7 @@ android {
     namespace 'com.nextcloud.talk'
 
     defaultConfig {
-        minSdkVersion 21
+        minSdkVersion 23
         targetSdkVersion 31
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
 

+ 24 - 12
app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java

@@ -32,6 +32,11 @@ import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
+import android.graphics.Rect;
+import android.graphics.RectF;
 import android.graphics.Typeface;
 import android.graphics.drawable.Animatable;
 import android.graphics.drawable.BitmapDrawable;
@@ -164,21 +169,28 @@ public class DisplayUtils {
         }
     }
 
-    public static Drawable getRoundedDrawable(Drawable drawable) {
-        Bitmap bitmap = getBitmap(drawable);
-        new RoundAsCirclePostprocessor(true).process(bitmap);
-        return new BitmapDrawable(bitmap);
-    }
+    public static Bitmap roundBitmap(Bitmap bitmap) {
+        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
 
-    public static Bitmap getRoundedBitmapFromVectorDrawableResource(Resources resources, int resource) {
-        VectorDrawable vectorDrawable = (VectorDrawable) ResourcesCompat.getDrawable(resources, resource, null);
-        Bitmap bitmap = getBitmap(vectorDrawable);
-        new RoundPostprocessor(true).process(bitmap);
-        return bitmap;
+        final Canvas canvas = new Canvas(output);
+
+        final Paint paint = new Paint();
+        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
+        final RectF rectF = new RectF(rect);
+
+        paint.setAntiAlias(true);
+        canvas.drawARGB(0, 0, 0, 0);
+        canvas.drawOval(rectF, paint);
+
+        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
+        canvas.drawBitmap(bitmap, rect, rect, paint);
+
+        return output;
     }
 
-    public static Drawable getRoundedBitmapDrawableFromVectorDrawableResource(Resources resources, int resource) {
-        return new BitmapDrawable(getRoundedBitmapFromVectorDrawableResource(resources, resource));
+    public static Drawable getRoundedDrawable(Drawable drawable) {
+        Bitmap bitmap = getBitmap(drawable);
+        return new BitmapDrawable(roundBitmap(bitmap));
     }
 
     public static Bitmap getBitmap(Drawable drawable) {

+ 1 - 5
app/src/main/java/com/nextcloud/talk/utils/NotificationUtils.kt

@@ -38,7 +38,6 @@ import com.facebook.common.references.CloseableReference
 import com.facebook.datasource.DataSources
 import com.facebook.drawee.backends.pipeline.Fresco
 import com.facebook.imagepipeline.image.CloseableBitmap
-import com.facebook.imagepipeline.postprocessors.RoundAsCirclePostprocessor
 import com.nextcloud.talk.BuildConfig
 import com.nextcloud.talk.R
 import com.nextcloud.talk.data.user.model.User
@@ -334,10 +333,7 @@ object NotificationUtils {
         val closeableImageRef = DataSources.waitForFinalResult(dataSource) as CloseableReference<CloseableBitmap>?
         val bitmap = closeableImageRef?.get()?.underlyingBitmap
         if (bitmap != null) {
-            // According to Fresco documentation a copy of the bitmap should be made before closing the references.
-            // However, it seems to work without making a copy... ;-)
-            RoundAsCirclePostprocessor(true).process(bitmap)
-            avatarIcon = IconCompat.createWithBitmap(bitmap)
+            avatarIcon = IconCompat.createWithBitmap(DisplayUtils.roundBitmap(bitmap))
         }
         CloseableReference.closeSafely(closeableImageRef)
         dataSource.close()