Skip to content

Commit 029e549

Browse files
release v1.0
0 parents  commit 029e549

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1354
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deploymentTargetDropDown.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/migrations.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LetterAvatar/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

LetterAvatar/build.gradle.kts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
plugins {
2+
id("com.android.library")
3+
id("org.jetbrains.kotlin.android")
4+
id("maven-publish")
5+
}
6+
7+
android {
8+
namespace = "com.pranathicodes.letteravatar"
9+
compileSdk = 34
10+
11+
defaultConfig {
12+
minSdk = 24
13+
14+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
15+
consumerProguardFiles("consumer-rules.pro")
16+
}
17+
18+
buildTypes {
19+
release {
20+
isMinifyEnabled = false
21+
proguardFiles(
22+
getDefaultProguardFile("proguard-android-optimize.txt"),
23+
"proguard-rules.pro"
24+
)
25+
}
26+
}
27+
compileOptions {
28+
sourceCompatibility = JavaVersion.VERSION_1_8
29+
targetCompatibility = JavaVersion.VERSION_1_8
30+
}
31+
kotlinOptions {
32+
jvmTarget = "1.8"
33+
}
34+
}
35+
36+
dependencies {
37+
38+
implementation("androidx.core:core-ktx:1.12.0")
39+
implementation("com.google.android.material:material:1.11.0")
40+
}
41+
42+
afterEvaluate {
43+
publishing {
44+
publications {
45+
create<MavenPublication>("release"){
46+
from(components["release"])
47+
48+
groupId = "com.github.Pranathi-pellakuru"
49+
artifactId = "Letter-Avatar-Generator"
50+
version = "1.0"
51+
}
52+
}
53+
}
54+
}
55+

LetterAvatar/consumer-rules.pro

Whitespace-only changes.

LetterAvatar/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.pranathicodes.letteravatar
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.pranathicodes.letteravatar.test", appContext.packageName)
23+
}
24+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
</manifest>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.pranathicodes.letteravatar
2+
3+
import android.content.Context
4+
import android.graphics.Bitmap
5+
import android.graphics.Bitmap.Config.ARGB_8888
6+
import android.graphics.Canvas
7+
import android.graphics.Color
8+
import android.graphics.Paint
9+
import android.graphics.Rect
10+
import android.graphics.RectF
11+
import android.graphics.Typeface
12+
import android.text.TextPaint
13+
14+
class AvatarCreator(private val context: Context) {
15+
16+
private var textSize = 25
17+
private var size = 180
18+
private var name = ' '
19+
private var font = Typeface.SANS_SERIF
20+
private var letterColor = Color.WHITE
21+
private var backgroundColor = Color.GRAY
22+
23+
24+
fun setTextSize(textSize: Int) = apply {
25+
this.textSize = textSize
26+
}
27+
28+
fun setAvatarSize(int: Int) = apply {
29+
this.size = int
30+
}
31+
32+
fun setLetter(label: Char) = apply {
33+
this.name = label
34+
}
35+
36+
fun setFont(fontFamily: Typeface) = apply {
37+
this.font = fontFamily
38+
}
39+
40+
fun setLetterColor(color: Int) = apply {
41+
this.letterColor = color
42+
}
43+
44+
fun setBackgroundColor(color: Int) = apply {
45+
this.backgroundColor = color
46+
}
47+
48+
fun build(): Bitmap {
49+
return avatarImageGenerate(
50+
size,
51+
name.toString(),
52+
textSize,
53+
font,
54+
letterColor,
55+
backgroundColor
56+
)
57+
}
58+
59+
private fun avatarImageGenerate(
60+
size: Int,
61+
name: String,
62+
textSize: Int,
63+
typeface: Typeface,
64+
letterColor: Int,
65+
backgroundColor: Int
66+
): Bitmap {
67+
val painter = Paint()
68+
val label = name.uppercase().ifEmpty { "-" }
69+
val textPaint = textPainter(letterColor, typeface, textSize)
70+
painter.color = backgroundColor
71+
72+
val areaRect = Rect(0, 0, size, size)
73+
val bitmap = Bitmap.createBitmap(size, size, ARGB_8888)
74+
val canvas = Canvas(bitmap)
75+
76+
val bounds = RectF(areaRect)
77+
bounds.right = textPaint.measureText(label, 0, 1)
78+
bounds.bottom = textPaint.descent() - textPaint.ascent()
79+
80+
bounds.left += (areaRect.width() - bounds.right) / 2.0f
81+
bounds.top += (areaRect.height() - bounds.bottom) / 2.0f
82+
83+
canvas.drawRect(areaRect, painter)
84+
canvas.drawText(label, bounds.left, bounds.top - textPaint.ascent(), textPaint)
85+
return bitmap
86+
87+
}
88+
89+
private fun textPainter(color: Int, typeface: Typeface, textSize: Int): TextPaint {
90+
val textPaint = TextPaint()
91+
textPaint.textSize = textSize * context.resources.displayMetrics.density
92+
textPaint.color = color
93+
textPaint.typeface = typeface
94+
return textPaint
95+
}
96+
97+
}
98+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.pranathicodes.letteravatar
2+
3+
class RandomColors {
4+
private var colorPairs: List<Pair<Int,Int>> = listOf()
5+
private var letterColors : List<Int> = listOf()
6+
private var backgroundColors : List<Int> = listOf()
7+
8+
fun getColorPair(): Pair<Int,Int> {
9+
return colorPairs.random()
10+
}
11+
12+
fun setColorPairs(colors : List<Pair<Int,Int>>){
13+
colorPairs = colors
14+
}
15+
16+
fun setLetterColors(colors : List<Int>){
17+
letterColors = colors
18+
}
19+
20+
fun setBackgroundColors(colors : List<Int>){
21+
backgroundColors = colors
22+
}
23+
24+
fun getLetterColor():Int{
25+
return letterColors.random()
26+
}
27+
28+
fun getBackgroundColor():Int {
29+
return backgroundColors.random()
30+
}
31+
32+
}
33+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.pranathicodes.letteravatar
2+
3+
import org.junit.Test
4+
5+
import org.junit.Assert.*
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* See [testing documentation](http://d.android.com/tools/testing).
11+
*/
12+
class ExampleUnitTest {
13+
@Test
14+
fun addition_isCorrect() {
15+
assertEquals(4, 2 + 2)
16+
}
17+
}

0 commit comments

Comments
 (0)