Skip to content

Commit

Permalink
release v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranathi-pellakuru committed Mar 5, 2024
0 parents commit 029e549
Show file tree
Hide file tree
Showing 57 changed files with 1,354 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions LetterAvatar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
55 changes: 55 additions & 0 deletions LetterAvatar/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("maven-publish")
}

android {
namespace = "com.pranathicodes.letteravatar"
compileSdk = 34

defaultConfig {
minSdk = 24

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {

implementation("androidx.core:core-ktx:1.12.0")
implementation("com.google.android.material:material:1.11.0")
}

afterEvaluate {
publishing {
publications {
create<MavenPublication>("release"){
from(components["release"])

groupId = "com.github.Pranathi-pellakuru"
artifactId = "Letter-Avatar-Generator"
version = "1.0"
}
}
}
}

Empty file added LetterAvatar/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions LetterAvatar/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.pranathicodes.letteravatar

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.pranathicodes.letteravatar.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions LetterAvatar/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.pranathicodes.letteravatar

import android.content.Context
import android.graphics.Bitmap
import android.graphics.Bitmap.Config.ARGB_8888
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.RectF
import android.graphics.Typeface
import android.text.TextPaint

class AvatarCreator(private val context: Context) {

private var textSize = 25
private var size = 180
private var name = ' '
private var font = Typeface.SANS_SERIF
private var letterColor = Color.WHITE
private var backgroundColor = Color.GRAY


fun setTextSize(textSize: Int) = apply {
this.textSize = textSize
}

fun setAvatarSize(int: Int) = apply {
this.size = int
}

fun setLetter(label: Char) = apply {
this.name = label
}

fun setFont(fontFamily: Typeface) = apply {
this.font = fontFamily
}

fun setLetterColor(color: Int) = apply {
this.letterColor = color
}

fun setBackgroundColor(color: Int) = apply {
this.backgroundColor = color
}

fun build(): Bitmap {
return avatarImageGenerate(
size,
name.toString(),
textSize,
font,
letterColor,
backgroundColor
)
}

private fun avatarImageGenerate(
size: Int,
name: String,
textSize: Int,
typeface: Typeface,
letterColor: Int,
backgroundColor: Int
): Bitmap {
val painter = Paint()
val label = name.uppercase().ifEmpty { "-" }
val textPaint = textPainter(letterColor, typeface, textSize)
painter.color = backgroundColor

val areaRect = Rect(0, 0, size, size)
val bitmap = Bitmap.createBitmap(size, size, ARGB_8888)
val canvas = Canvas(bitmap)

val bounds = RectF(areaRect)
bounds.right = textPaint.measureText(label, 0, 1)
bounds.bottom = textPaint.descent() - textPaint.ascent()

bounds.left += (areaRect.width() - bounds.right) / 2.0f
bounds.top += (areaRect.height() - bounds.bottom) / 2.0f

canvas.drawRect(areaRect, painter)
canvas.drawText(label, bounds.left, bounds.top - textPaint.ascent(), textPaint)
return bitmap

}

private fun textPainter(color: Int, typeface: Typeface, textSize: Int): TextPaint {
val textPaint = TextPaint()
textPaint.textSize = textSize * context.resources.displayMetrics.density
textPaint.color = color
textPaint.typeface = typeface
return textPaint
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.pranathicodes.letteravatar

class RandomColors {
private var colorPairs: List<Pair<Int,Int>> = listOf()
private var letterColors : List<Int> = listOf()
private var backgroundColors : List<Int> = listOf()

fun getColorPair(): Pair<Int,Int> {
return colorPairs.random()
}

fun setColorPairs(colors : List<Pair<Int,Int>>){
colorPairs = colors
}

fun setLetterColors(colors : List<Int>){
letterColors = colors
}

fun setBackgroundColors(colors : List<Int>){
backgroundColors = colors
}

fun getLetterColor():Int{
return letterColors.random()
}

fun getBackgroundColor():Int {
return backgroundColors.random()
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.pranathicodes.letteravatar

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
Loading

0 comments on commit 029e549

Please sign in to comment.