Skip to content

Commit 7618959

Browse files
committed
Bug fixing
1 parent c98b8dc commit 7618959

File tree

19 files changed

+54
-45
lines changed

19 files changed

+54
-45
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44

55
android {
6-
compileSdkVersion 29
7-
buildToolsVersion "30.0.0"
6+
compileSdkVersion 30
7+
buildToolsVersion "30.0.3"
88

99
defaultConfig {
1010
applicationId "com.goodayapps.avatarview"
1111
minSdkVersion 19
12-
targetSdkVersion 29
12+
targetSdkVersion 30
1313
versionCode 1
1414
versionName "1.0"
1515

@@ -35,9 +35,9 @@ android {
3535

3636
dependencies {
3737
implementation fileTree(dir: "libs", include: ["*.jar"])
38-
implementation 'androidx.core:core-ktx:1.3.2'
39-
implementation 'androidx.appcompat:appcompat:1.2.0'
38+
implementation 'androidx.core:core-ktx:1.6.0'
39+
implementation 'androidx.appcompat:appcompat:1.3.1'
4040
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
4141

42-
implementation(project(":widget"))
42+
implementation(project(':avatar-view'))
4343
}

app/src/main/res/layout/activity_main.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@
2727
android:id="@+id/avatars_list"
2828
android:layout_width="wrap_content"
2929
android:layout_height="wrap_content"
30+
android:columnCount="3"
31+
android:minHeight="200dp"
3032
android:divider="@drawable/divider_vertical_blank"
3133
android:gravity="center"
32-
android:columnCount="3"
3334
android:orientation="horizontal"
3435
android:showDividers="middle">
3536

3637
<com.goodayapps.widget.AvatarView
3738
android:id="@+id/avatarView0"
39+
style="@style/AvatarStyleHelper"
3840
android:layout_width="@dimen/avatar_size"
3941
android:layout_height="@dimen/avatar_size"
4042
android:src="@drawable/ic_bell"
@@ -47,6 +49,7 @@
4749

4850
<com.goodayapps.widget.AvatarView
4951
android:id="@+id/avatarView10"
52+
style="@style/AvatarStyleHelper"
5053
android:layout_width="@dimen/avatar_size"
5154
android:layout_height="@dimen/avatar_size"
5255
android:src="@drawable/ic_more"
@@ -59,6 +62,7 @@
5962

6063
<com.goodayapps.widget.AvatarView
6164
android:id="@+id/avatarView1"
65+
style="@style/AvatarStyleHelper"
6266
android:layout_width="@dimen/avatar_size"
6367
android:layout_height="@dimen/avatar_size"
6468
android:src="@drawable/ic_launcher_foreground"
@@ -77,16 +81,17 @@
7781

7882
<com.goodayapps.widget.AvatarView
7983
android:id="@+id/avatarView2"
84+
style="@style/AvatarStyleHelper"
8085
android:layout_width="@dimen/avatar_size"
8186
android:layout_height="@dimen/avatar_size"
8287
android:src="@drawable/avatar1"
83-
8488
app:avBackgroundColor="@color/colorPrimary"
8589
app:avBorderColor="@color/colorAccent"
8690
app:avBorderWidth="5dp" />
8791

8892
<com.goodayapps.widget.AvatarView
8993
android:id="@+id/avatarView3"
94+
style="@style/AvatarStyleHelper"
9095
android:layout_width="@dimen/avatar_size"
9196
android:layout_height="@dimen/avatar_size"
9297
android:fontFamily="@font/font_19849"
@@ -96,6 +101,7 @@
96101
app:iconDrawableScale=".7"
97102
app:placeholderText="AV" />
98103
</GridLayout>
104+
99105
<LinearLayout
100106
android:layout_width="match_parent"
101107
android:layout_height="wrap_content"

app/src/main/res/values/styles.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
<item name="fontFamily">@font/avenir_medium</item>
99
</style>
1010

11+
<style name="AvatarStyleHelper">
12+
<item name="android:layout_margin">8dp</item>
13+
</style>
1114
</resources>
File renamed without changes.
File renamed without changes.
File renamed without changes.

widget/src/main/java/com/goodayapps/widget/AvatarDrawable.kt renamed to avatar-view/src/main/java/com/goodayapps/widget/AvatarDrawable.kt

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class AvatarDrawable private constructor(
3737
private val border: Border,
3838
private val placeholder: Placeholder,
3939
) : Drawable() {
40+
private var iconColorFilter: ColorFilter? = null
4041
private var textLayout: StaticLayout? = null
4142

4243
private var placeholderPaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
@@ -101,6 +102,23 @@ class AvatarDrawable private constructor(
101102
private val arcBorderRect = RectF()
102103
private val borderRect = RectF()
103104

105+
private val totalArchesDegreeArea
106+
get() = border.archesDegreeArea.toFloat()
107+
108+
private val animationLoopDegrees
109+
get() = border.archesAngle.toFloat()
110+
111+
private var animationArchesSparseness = 1f
112+
113+
private val individualArcDegreeLength
114+
get() = calculateArcDegreeLength()
115+
116+
private val spaceBetweenArches
117+
get() = calculateSpaceBetweenArches()
118+
119+
private val currentAnimationArchesArea
120+
get() = animationArchesSparseness * totalArchesDegreeArea
121+
104122
constructor(builder: Builder) : this(
105123
size = builder.size,
106124
backgroundColor = builder.backgroundColor,
@@ -150,20 +168,20 @@ class AvatarDrawable private constructor(
150168
}
151169
}
152170

153-
private fun calculateBounds(): RectF {
154-
val availableWidth = size
155-
val availableHeight = size
171+
override fun setAlpha(alpha: Int) {
172+
}
156173

157-
val sideLength = availableWidth.coerceAtMost(availableHeight)
174+
override fun setColorFilter(colorFilter: ColorFilter?) {
175+
iconColorFilter = colorFilter
176+
invalidateSelf()
177+
}
158178

159-
val left = (availableWidth - sideLength) / 2f
160-
val top = (availableHeight - sideLength) / 2f
179+
override fun getColorFilter(): ColorFilter? = iconColorFilter
161180

162-
return RectF(left, top, left + sideLength, top + sideLength)
181+
override fun getOpacity(): Int {
182+
return PixelFormat.TRANSLUCENT
163183
}
164184

165-
private var iconColorFilter: ColorFilter? = null
166-
167185
override fun draw(canvas: Canvas) {
168186
canvas.save()
169187
canvas.translate(bounds.left.toFloat(), bounds.top.toFloat())
@@ -230,22 +248,18 @@ class AvatarDrawable private constructor(
230248
canvas.restore()
231249
}
232250

233-
private val totalArchesDegreeArea
234-
get() = border.archesDegreeArea.toFloat()
235251

236-
private val animationLoopDegrees
237-
get() = border.archesAngle.toFloat()
238-
239-
private var animationArchesSparseness = 1f
252+
private fun calculateBounds(): RectF {
253+
val availableWidth = size
254+
val availableHeight = size
240255

241-
private val individualArcDegreeLength
242-
get() = calculateArcDegreeLength()
256+
val sideLength = availableWidth.coerceAtMost(availableHeight)
243257

244-
private val spaceBetweenArches
245-
get() = calculateSpaceBetweenArches()
258+
val left = (availableWidth - sideLength) / 2f
259+
val top = (availableHeight - sideLength) / 2f
246260

247-
private val currentAnimationArchesArea
248-
get() = animationArchesSparseness * totalArchesDegreeArea
261+
return RectF(left, top, left + sideLength, top + sideLength)
262+
}
249263

250264
private fun drawBorder() {
251265
if (border.width > 0) {
@@ -296,20 +310,6 @@ class AvatarDrawable private constructor(
296310
}
297311
}
298312

299-
override fun setAlpha(alpha: Int) {
300-
}
301-
302-
override fun setColorFilter(colorFilter: ColorFilter?) {
303-
iconColorFilter = colorFilter
304-
invalidateSelf()
305-
}
306-
307-
override fun getColorFilter(): ColorFilter? = iconColorFilter
308-
309-
override fun getOpacity(): Int {
310-
return PixelFormat.TRANSLUCENT
311-
}
312-
313313
private fun drawBitmap(isIconDrawable: Boolean, avatarBitmap: Bitmap) {
314314
if (isIconDrawable) {
315315
//Draw background

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
include ':widget'
1+
include ':avatar-view'
22
include ':app'
33
rootProject.name = "AvatarView"

0 commit comments

Comments
 (0)