Code Monkey home page Code Monkey logo

amoskorir / avatarimagegenerator Goto Github PK

View Code? Open in Web Editor NEW
70.0 2.0 21.0 493 KB

Android library to generate image avatar from the first letter of a username. Letter avatar like Gmail Android best practice

Home Page: https://medium.com/@koriramos/android-first-letter-avatar-image-generator-91c1f314eeb4

License: Apache License 2.0

Kotlin 100.00%
avatarview avatar-generator avatar-placeholder picasso glide bitmap letter-like-gmail first-letter

avatarimagegenerator's Introduction

AvatarImageGenerator

CircleCI Download ](https://bintray.com/skyways/AvatarGenerator/AvatarGenerator/1.4/link)

Generate first letter avatar Image like gmail's contact avatar. It generates an drawable that can be be set to an ImageView.

Installation

Note: Before you can install AvatarImageGenerator you must first add JitPack as a maven repository in settings.gradle

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

Add the Following to your gradle file.

implementation 'com.github.amoskorir:avatarimagegenerator:VERSION'

Usage

New Builder pattern

 AvatarGenerator.AvatarBuilder(context)
                .setLabel(users[position].login)
                .setAvatarSize(120)
                .setTextSize(30)
                .toSquare()
                .toCircle()
                .setBackgroundColor(Color.RED)
                .build()

Supports

Using glide or Picasso you can set the drawable to an imageView as a placeholder.

  1. Picasso
  2. Glide

Picasso

 Picasso.get()
    .load("https://brokenfortest")
    .resize(50, 50)
    .placeholder(AvatarGenerator.avatarImage(this, 200, AvatarConstants.CIRCLE, "Android"))
    .into(imageView2)

Glide

 Glide.with(this)
    .load("http://brokenfortest")
    .placeholder(AvatarGenerator.avatarImage(this, 200, AvatarConstants.CIRCLE, "Kotjav"))
    .into(imageView3)

Without any Library

imageView.setImageDrawable(
    AvatarGenerator.avatarImage(
      this,
      200,
      AvatarConstants.RECTANGLE,
      "Skyways"
    )

Shape

  1. Circle
  2. Square
.toSquare(),
.toCircle()

avatarimagegenerator's People

Contributors

amoskorir avatar funkymuse avatar gitter-badger avatar peavers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

avatarimagegenerator's Issues

Memory Leak.

┬───
│ GC Root: Thread object

├─ android.os.HandlerThread instance
│ Leaking: NO (PathClassLoader↓ is not leaking)
│ Thread name: 'queued-work-looper'
│ ↓ Thread.contextClassLoader
├─ dalvik.system.PathClassLoader instance
│ Leaking: NO (AvatarGenerator↓ is not leaking and A ClassLoader is never
│ leaking)
│ ↓ ClassLoader.runtimeInternalObjects
├─ java.lang.Object[] array
│ Leaking: NO (AvatarGenerator↓ is not leaking)
│ ↓ Object[4493]
├─ com.avatarfirst.avatargenlib.AvatarGenerator class
│ Leaking: NO (a class is never leaking)
│ ↓ static AvatarGenerator.uiContext
│ ~~~~~~~~~
├─ dagger.hilt.android.internal.managers.
│ ViewComponentManager$FragmentContextWrapper instance
│ Leaking: YES (ViewComponentManager$FragmentContextWrapper wraps an
│ Activity with Activity.mDestroyed true)
│ Retaining 7.9 MB in 95470 objects
│ mBase instance of com.akshay.stockbubbles.ui.MainActivity with mDestroyed
│ = true
│ ↓ ContextWrapper.mBase
╰→ com.akshay.stockbubbles.ui.MainActivity instance
​ Leaking: YES (ObjectWatcher was watching this because com.akshay.
​ stockbubbles.ui.MainActivity received Activity#onDestroy() callback and
​ Activity#mDestroyed is true)
​ Retaining 7.9 MB in 95467 objects
​ key = e40fdba2-213f-4e58-800c-9a15d7d65240
​ watchDurationMillis = 7353
​ retainedDurationMillis = 2340
​ mApplication instance of com.akshay.stockbubbles.util.
​ StockBubblesApplication
​ mBase instance of androidx.appcompat.view.ContextThemeWrapper

METADATA

Build.VERSION.SDK_INT: 33
Build.MANUFACTURER: OnePlus
LeakCanary version: 2.12
App process name: com.akshay.stockbubbles
Class count: 30724
Instance count: 319177
Primitive array count: 179928
Object array count: 44291
Thread count: 76
Heap total bytes: 38676449
Bitmap count: 89
Bitmap total bytes: 10398041
Large bitmap count: 0
Large bitmap total bytes: 0
Db 1: open /data/user/0/com.akshay.stockbubbles/databases/com.google.android.
datatransport.events
Db 2: closed /data/user/0/com.akshay.
stockbubbles/databases/google_app_measurement_local.db
Db 3: closed /data/user/0/com.akshay.
stockbubbles/databases/google_app_measurement_local.db
Count of retained yet cleared: 6 KeyedWeakReference instances
Stats: LruCache[maxSize=3000,hits=150111,misses=307300,hitRate=32%]
RandomAccess[bytes=16577902,reads=307300,travel=119892018418,range=44820383,size
=56078207]
Analysis duration: 103056 ms

notification

Hey, nice libary.
How to use it to get the image in notifications?

i use it like this way but its crashing

On all Activities this is working exept in notifications

return try {
// Here, use glide or do your things on UiThread
val profileImg = GlideApp.with(this)
.asBitmap()
.load(strURL)
.placeholder(AvatarGenerator.avatarImage(this, 200, AvatarConstants.CIRCLE, Prefs.getUserName))
.transform(DkcGlide.circleCrop)
.submit(_40_DP, _40_DP)
.get()
profileImg
} catch (e: IOException) {
e.printStackTrace()
null
}

Moving to mavenCentral()

Hi,
I am facing issue after removing JCenter() because everything has been moved to mavenCentral(). Do you have any plans for working on compatibility of this library with mavenCentral()?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.