1
1
package com.goodayapps.widget
2
2
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.*
17
4
import android.graphics.drawable.Animatable
18
- import android.graphics.drawable.AnimatedImageDrawable
19
5
import android.graphics.drawable.BitmapDrawable
20
6
import android.graphics.drawable.Drawable
21
7
import android.media.ThumbnailUtils
@@ -200,7 +186,7 @@ class AvatarDrawable private constructor(
200
186
is Animatable -> {
201
187
isIconDrawable = false
202
188
203
- createAvatarBitmap (avatarDrawable, 1f )
189
+ createAnimatableAvatarBitmap (avatarDrawable)
204
190
}
205
191
is Drawable -> {
206
192
isIconDrawable = true
@@ -263,6 +249,19 @@ class AvatarDrawable private constructor(
263
249
}
264
250
}
265
251
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
+ }
266
265
267
266
private fun calculateBounds (): RectF {
268
267
val availableWidth = size
@@ -279,7 +278,7 @@ class AvatarDrawable private constructor(
279
278
private fun drawBorder () {
280
279
if (border.width > 0 ) {
281
280
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 )
283
282
&& totalArchesDegreeArea > 0f
284
283
) {
285
284
drawArcBorder()
@@ -358,7 +357,7 @@ class AvatarDrawable private constructor(
358
357
359
358
private fun calculateSpaceBetweenArches () =
360
359
(totalArchesDegreeArea - (border.archesCount * individualArcDegreeLength)) /
361
- (border.archesCount + if (totalArchesDegreeArea == 360f ) 0 else 1 )
360
+ (border.archesCount + if (totalArchesDegreeArea == 360f ) 0 else 1 )
362
361
363
362
private fun calculateArcDegreeLength () =
364
363
totalArchesDegreeArea / (if (border.archesType == Border .ARCH_TYPE_DEFAULT ) {
@@ -382,8 +381,8 @@ class AvatarDrawable private constructor(
382
381
val intrinsicHeightF = intrinsicHeight.toFloat()
383
382
val intrinsicWidthF = intrinsicWidth.toFloat()
384
383
385
- val ratioOfWidth = intrinsicWidthF/ maxF
386
- val ratioOfHeight = intrinsicHeightF/ maxF
384
+ val ratioOfWidth = intrinsicWidthF / maxF
385
+ val ratioOfHeight = intrinsicHeightF / maxF
387
386
val ratio = intrinsicWidth / intrinsicHeightF
388
387
389
388
when {
@@ -395,7 +394,7 @@ class AvatarDrawable private constructor(
395
394
_width = intrinsicWidth / ratioOfWidth * ratio
396
395
_height = maxF
397
396
}
398
- ratio == 1f -> {
397
+ ratio == 1f -> {
399
398
_width = maxF
400
399
_height = maxF
401
400
}
0 commit comments