From a78c3b89777dc3826c3cf60c7edc3651362ebb3a Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 15 Apr 2020 19:46:47 +0200 Subject: [PATCH] adding a helper function for getting a colored group icon --- build.gradle | 2 +- .../commons/extensions/Context.kt | 9 +++++++++ .../src/main/res/drawable/ic_group_circle_bg.xml | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 commons/src/main/res/drawable/ic_group_circle_bg.xml diff --git a/build.gradle b/build.gradle index 2a2c90db1..7f8b77461 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { propMinSdkVersion = 21 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 - propVersionName = '5.25.18' + propVersionName = '5.25.19' kotlin_version = '1.3.72' } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt index 85aa04dc6..25c74b3d5 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt @@ -8,6 +8,8 @@ import android.content.pm.PackageManager import android.content.res.Configuration import android.database.Cursor import android.graphics.* +import android.graphics.drawable.Drawable +import android.graphics.drawable.LayerDrawable import android.media.ExifInterface import android.media.MediaMetadataRetriever import android.media.RingtoneManager @@ -854,3 +856,10 @@ fun Context.getContactLetterIcon(name: String): Bitmap { view.draw(canvas) return bitmap } + +fun Context.getColoredGroupIcon(title: String): Drawable { + val icon = resources.getDrawable(R.drawable.ic_group_circle_bg) + val bgColor = letterBackgroundColors[Math.abs(title.hashCode()) % letterBackgroundColors.size].toInt() + (icon as LayerDrawable).findDrawableByLayerId(R.id.attendee_circular_background).applyColorFilter(bgColor) + return icon +} diff --git a/commons/src/main/res/drawable/ic_group_circle_bg.xml b/commons/src/main/res/drawable/ic_group_circle_bg.xml new file mode 100644 index 000000000..eef63aa58 --- /dev/null +++ b/commons/src/main/res/drawable/ic_group_circle_bg.xml @@ -0,0 +1,16 @@ + + + + + + + + + + +