11package com.goodayapps.widget
22
3- import android.graphics.Bitmap
4- import android.graphics.Canvas
5- import android.graphics.Color
6- import android.graphics.ColorFilter
7- import android.graphics.LinearGradient
8- import android.graphics.Matrix
9- import android.graphics.Paint
10- import android.graphics.Path
11- import android.graphics.PixelFormat
12- import android.graphics.PorterDuff
13- import android.graphics.PorterDuffXfermode
14- import android.graphics.RectF
15- import android.graphics.Shader
16- import android.graphics.Typeface
3+ import android.graphics.*
174import android.graphics.drawable.Animatable
18- import android.graphics.drawable.AnimatedImageDrawable
195import android.graphics.drawable.BitmapDrawable
206import android.graphics.drawable.Drawable
217import android.media.ThumbnailUtils
@@ -200,7 +186,7 @@ class AvatarDrawable private constructor(
200186 is Animatable -> {
201187 isIconDrawable = false
202188
203- createAvatarBitmap (avatarDrawable, 1f )
189+ createAnimatableAvatarBitmap (avatarDrawable)
204190 }
205191 is Drawable -> {
206192 isIconDrawable = true
@@ -263,6 +249,19 @@ class AvatarDrawable private constructor(
263249 }
264250 }
265251
252+ private fun createAnimatableAvatarBitmap (
253+ avatarDrawable : Drawable
254+ ): Bitmap ? {
255+ val cropDrawable = CenterCropDrawable (avatarDrawable)
256+
257+ return Bitmap .createBitmap(size, size, Bitmap .Config .ARGB_8888 ).also {
258+ cropDrawable.setBounds(0 , 0 , size, size)
259+
260+ iconColorFilter?.let { filter -> cropDrawable.colorFilter = filter }
261+
262+ cropDrawable.draw(Canvas (it))
263+ }
264+ }
266265
267266 private fun calculateBounds (): RectF {
268267 val availableWidth = size
@@ -279,7 +278,7 @@ class AvatarDrawable private constructor(
279278 private fun drawBorder () {
280279 if (border.width > 0 ) {
281280 if (((border.archesType == Border .ARCH_TYPE_DEFAULT && border.archesCount > 1 )
282- || border.archesType == Border .ARCH_TYPE_MIRROR && border.archesCount > 0 )
281+ || border.archesType == Border .ARCH_TYPE_MIRROR && border.archesCount > 0 )
283282 && totalArchesDegreeArea > 0f
284283 ) {
285284 drawArcBorder()
@@ -358,7 +357,7 @@ class AvatarDrawable private constructor(
358357
359358 private fun calculateSpaceBetweenArches () =
360359 (totalArchesDegreeArea - (border.archesCount * individualArcDegreeLength)) /
361- (border.archesCount + if (totalArchesDegreeArea == 360f ) 0 else 1 )
360+ (border.archesCount + if (totalArchesDegreeArea == 360f ) 0 else 1 )
362361
363362 private fun calculateArcDegreeLength () =
364363 totalArchesDegreeArea / (if (border.archesType == Border .ARCH_TYPE_DEFAULT ) {
@@ -382,8 +381,8 @@ class AvatarDrawable private constructor(
382381 val intrinsicHeightF = intrinsicHeight.toFloat()
383382 val intrinsicWidthF = intrinsicWidth.toFloat()
384383
385- val ratioOfWidth = intrinsicWidthF/ maxF
386- val ratioOfHeight = intrinsicHeightF/ maxF
384+ val ratioOfWidth = intrinsicWidthF / maxF
385+ val ratioOfHeight = intrinsicHeightF / maxF
387386 val ratio = intrinsicWidth / intrinsicHeightF
388387
389388 when {
@@ -395,7 +394,7 @@ class AvatarDrawable private constructor(
395394 _width = intrinsicWidth / ratioOfWidth * ratio
396395 _height = maxF
397396 }
398- ratio == 1f -> {
397+ ratio == 1f -> {
399398 _width = maxF
400399 _height = maxF
401400 }
0 commit comments