mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
Fixed generated avatars color when switching between light/dark modes
This commit is contained in:
parent
7ab7136a5b
commit
c6a0f25041
2 changed files with 6 additions and 8 deletions
|
|
@ -25,7 +25,6 @@ import android.graphics.Canvas
|
|||
import android.graphics.Paint
|
||||
import android.graphics.Rect
|
||||
import android.graphics.RectF
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.text.TextPaint
|
||||
import android.util.TypedValue
|
||||
import androidx.core.content.ContextCompat
|
||||
|
|
@ -34,7 +33,6 @@ import androidx.core.graphics.drawable.IconCompat
|
|||
import org.linphone.R
|
||||
import org.linphone.utils.AppUtils
|
||||
import androidx.core.graphics.createBitmap
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
|
||||
class AvatarGenerator(private val context: Context) {
|
||||
private var textSize: Float = AppUtils.getDimension(R.dimen.avatar_initials_text_size)
|
||||
|
|
@ -92,10 +90,6 @@ class AvatarGenerator(private val context: Context) {
|
|||
return bitmap
|
||||
}
|
||||
|
||||
fun buildDrawable(): BitmapDrawable {
|
||||
return buildBitmap(true).toDrawable(context.resources)
|
||||
}
|
||||
|
||||
fun buildIcon(): IconCompat {
|
||||
return IconCompat.createWithAdaptiveBitmap(buildBitmap(false))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
package org.linphone.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.ImageDecoder
|
||||
|
|
@ -41,7 +42,10 @@ class ImageUtils {
|
|||
|
||||
@AnyThread
|
||||
fun generatedAvatarIfNeededAndReturnPath(context: Context, size: Int = 0, textSize: Int = 0, initials: String): String {
|
||||
val generatedAvatarPath = FileUtils.getFileStorageCacheDir("$initials.png", overrideExisting = true)
|
||||
val darkMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
|
||||
val suffix = if (darkMode) "_dark" else "_light"
|
||||
|
||||
val generatedAvatarPath = FileUtils.getFileStorageCacheDir("$initials$suffix.png", overrideExisting = true)
|
||||
if (generatedAvatarPath.exists()) {
|
||||
val path = generatedAvatarPath.absolutePath
|
||||
return path
|
||||
|
|
@ -57,7 +61,7 @@ class ImageUtils {
|
|||
if (textSize > 0) {
|
||||
builder.setTextSize(AppUtils.getDimension(textSize))
|
||||
}
|
||||
val bitmap = builder.buildBitmap(true)
|
||||
val bitmap = builder.buildBitmap(false)
|
||||
val path = FileUtils.storeBitmap(bitmap, generatedAvatarPath)
|
||||
return path
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue