mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 12:39:58 +01:00
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>
This commit is contained in:
parent
e26a7a7beb
commit
8a0e60f68a
@ -42,7 +42,7 @@ android {
|
|||||||
namespace 'com.nextcloud.talk'
|
namespace 'com.nextcloud.talk'
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 21
|
minSdkVersion 23
|
||||||
targetSdkVersion 31
|
targetSdkVersion 31
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
@ -32,6 +32,11 @@ import android.content.res.Resources;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
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.Typeface;
|
||||||
import android.graphics.drawable.Animatable;
|
import android.graphics.drawable.Animatable;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
@ -164,21 +169,28 @@ public class DisplayUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Bitmap roundBitmap(Bitmap bitmap) {
|
||||||
|
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
|
||||||
|
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 getRoundedDrawable(Drawable drawable) {
|
public static Drawable getRoundedDrawable(Drawable drawable) {
|
||||||
Bitmap bitmap = getBitmap(drawable);
|
Bitmap bitmap = getBitmap(drawable);
|
||||||
new RoundAsCirclePostprocessor(true).process(bitmap);
|
return new BitmapDrawable(roundBitmap(bitmap));
|
||||||
return new BitmapDrawable(bitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Drawable getRoundedBitmapDrawableFromVectorDrawableResource(Resources resources, int resource) {
|
|
||||||
return new BitmapDrawable(getRoundedBitmapFromVectorDrawableResource(resources, resource));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap getBitmap(Drawable drawable) {
|
public static Bitmap getBitmap(Drawable drawable) {
|
||||||
|
@ -38,7 +38,6 @@ import com.facebook.common.references.CloseableReference
|
|||||||
import com.facebook.datasource.DataSources
|
import com.facebook.datasource.DataSources
|
||||||
import com.facebook.drawee.backends.pipeline.Fresco
|
import com.facebook.drawee.backends.pipeline.Fresco
|
||||||
import com.facebook.imagepipeline.image.CloseableBitmap
|
import com.facebook.imagepipeline.image.CloseableBitmap
|
||||||
import com.facebook.imagepipeline.postprocessors.RoundAsCirclePostprocessor
|
|
||||||
import com.nextcloud.talk.BuildConfig
|
import com.nextcloud.talk.BuildConfig
|
||||||
import com.nextcloud.talk.R
|
import com.nextcloud.talk.R
|
||||||
import com.nextcloud.talk.data.user.model.User
|
import com.nextcloud.talk.data.user.model.User
|
||||||
@ -334,10 +333,7 @@ object NotificationUtils {
|
|||||||
val closeableImageRef = DataSources.waitForFinalResult(dataSource) as CloseableReference<CloseableBitmap>?
|
val closeableImageRef = DataSources.waitForFinalResult(dataSource) as CloseableReference<CloseableBitmap>?
|
||||||
val bitmap = closeableImageRef?.get()?.underlyingBitmap
|
val bitmap = closeableImageRef?.get()?.underlyingBitmap
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
// According to Fresco documentation a copy of the bitmap should be made before closing the references.
|
avatarIcon = IconCompat.createWithBitmap(DisplayUtils.roundBitmap(bitmap))
|
||||||
// However, it seems to work without making a copy... ;-)
|
|
||||||
RoundAsCirclePostprocessor(true).process(bitmap)
|
|
||||||
avatarIcon = IconCompat.createWithBitmap(bitmap)
|
|
||||||
}
|
}
|
||||||
CloseableReference.closeSafely(closeableImageRef)
|
CloseableReference.closeSafely(closeableImageRef)
|
||||||
dataSource.close()
|
dataSource.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user