├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── dimens.xml
│ │ │ ├── styles.xml
│ │ │ ├── arrays.xml
│ │ │ ├── colors.xml
│ │ │ └── strings.xml
│ │ ├── drawable
│ │ │ ├── five.jpg
│ │ │ ├── four.jpg
│ │ │ ├── nine.jpg
│ │ │ ├── one.jpg
│ │ │ ├── six.jpg
│ │ │ ├── two.jpg
│ │ │ ├── eight.jpg
│ │ │ ├── seven.jpg
│ │ │ └── three.jpg
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ ├── layout
│ │ │ ├── activity_main.xml
│ │ │ └── list_item.xml
│ │ └── menu
│ │ │ └── menu.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── imagelettericon
│ │ └── MainActivity.java
├── proguard-rules.pro
└── build.gradle
├── imageletter
├── .gitignore
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ └── values
│ │ │ └── attrs.xml
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── akashandroid90
│ │ └── imageletter
│ │ ├── TintableImageView.java
│ │ ├── MaterialLetterIcon.java
│ │ ├── drawable
│ │ ├── TextDrawable.java
│ │ └── RoundedDrawable.java
│ │ └── RoundedImageViewWithBorder.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── images
├── one.png
├── two.png
├── four.png
└── three.png
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/imageletter/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':imageletter'
2 |
--------------------------------------------------------------------------------
/images/one.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/images/one.png
--------------------------------------------------------------------------------
/images/two.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/images/two.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | gradle
3 | /local.properties
4 | .idea
5 | /.idea
6 | /build
7 | *.iml
8 |
--------------------------------------------------------------------------------
/images/four.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/images/four.png
--------------------------------------------------------------------------------
/images/three.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/images/three.png
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 50dp
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/five.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/drawable/five.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/four.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/drawable/four.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/nine.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/drawable/nine.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/one.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/drawable/one.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/six.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/drawable/six.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/two.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/drawable/two.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/eight.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/drawable/eight.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/seven.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/drawable/seven.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/three.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/drawable/three.jpg
--------------------------------------------------------------------------------
/imageletter/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/akashjaindev/ImageLetterIcon/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - @color/color_1
5 | - @color/color_2
6 | - @color/color_3
7 | - @color/color_4
8 | - @color/color_5
9 | - @color/color_6
10 | - @color/color_7
11 | - @color/color_8
12 | - @color/color_9
13 | - @color/color_10
14 | - @color/color_11
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
13 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\ide\android\Android SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #DB4437
8 | #E91E63
9 | #FF5722
10 | #EF6C00
11 | #689F38
12 | #0097A7
13 | #4285F4
14 | #039BE5
15 | #3F51B5
16 | #673AB7
17 | #757575
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Material Icon
3 | Show countries
4 | Show alternate countries
5 | Show contacts
6 | Show alternate contacts
7 | ca-app-pub-5883105630361246/1929299012
8 | ca-app-pub-5883105630361246/4184761412
9 | Other Apps
10 | Github
11 | Play store
12 | Share
13 |
14 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion compilesdk
5 | buildToolsVersion buildtool
6 |
7 | defaultConfig {
8 | applicationId "com.imagelettericon"
9 | minSdkVersion minsdk
10 | targetSdkVersion targetsdk
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | compile 'com.android.support:recyclerview-v7:'+androidlib
25 | compile 'com.android.support:design:'+androidlib
26 | compile 'com.intuit.sdp:sdp-android:1.0.5'
27 | compile project(':imageletter')
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/imageletter/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | android {
3 | compileSdkVersion compilesdk
4 | buildToolsVersion buildtool
5 |
6 | defaultConfig {
7 | minSdkVersion minsdk
8 | targetSdkVersion targetsdk
9 | versionCode 1
10 | versionName '1.13'
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | shrinkResources false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 | configurations{
21 | compile.exclude module: 'support-media-compat'
22 | compile.exclude module: 'support-core-utils'
23 | compile.exclude module: 'support-core-ui'
24 | compile.exclude module: 'animated-vector-drawable'
25 | compile.exclude module: 'support-fragment'
26 | }
27 | dependencies {
28 | compile fileTree(include: ['*.jar'], dir: 'libs')
29 | compile 'com.android.support:appcompat-v7:'+androidlib
30 | }
31 |
--------------------------------------------------------------------------------
/imageletter/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
20 |
25 |
--------------------------------------------------------------------------------
/imageletter/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\ide\android\Android SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | #-optimizationpasses 5
20 | #-renamesourcefileattribute SourceFile
21 | #-optimizations !code/simplification/advanced,code/simplification/*
22 | #
23 | ##-keep public class * extends View {
24 | ##public (android.content.Context);
25 | ##public (android.content.Context, android.util.AttributeSet);
26 | ##public (android.content.Context, android.util.AttributeSet, int);
27 | ##public void set*(...);
28 | ##}
29 | #
30 | #-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }
31 | #
32 | #-keep class com.github.akashandroid90.imageletter.** { *; }
33 | #
34 | -keep public class * extends android.view.View {
35 | void set*(***);
36 | *** get*();
37 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/imageletter/src/main/java/com/github/akashandroid90/imageletter/TintableImageView.java:
--------------------------------------------------------------------------------
1 | package com.github.akashandroid90.imageletter;
2 |
3 | import android.content.Context;
4 | import android.content.res.ColorStateList;
5 | import android.content.res.TypedArray;
6 | import android.graphics.PorterDuff;
7 | import android.graphics.drawable.Drawable;
8 | import android.support.v4.content.ContextCompat;
9 | import android.support.v4.graphics.drawable.DrawableCompat;
10 | import android.support.v7.widget.AppCompatImageView;
11 | import android.util.AttributeSet;
12 |
13 |
14 | public class TintableImageView extends AppCompatImageView {
15 | private ColorStateList mTint, mBackgroundTint;
16 |
17 | public TintableImageView(Context context) {
18 | super(context);
19 | }
20 |
21 | public TintableImageView(Context context, AttributeSet attrs) {
22 | this(context, attrs, 0);
23 | }
24 |
25 | public TintableImageView(Context context, AttributeSet attrs, int defStyle) {
26 | super(context, attrs, defStyle);
27 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TintableImageView, defStyle, 0);
28 | mTint = a.getColorStateList(R.styleable.TintableImageView_image_tint);
29 | mBackgroundTint = a.getColorStateList(R.styleable.TintableImageView_background_tint);
30 | a.recycle();
31 | }
32 |
33 | @Override
34 | protected void drawableStateChanged() {
35 | super.drawableStateChanged();
36 | if (mTint != null) {
37 | if (mTint.isStateful())
38 | setColorFilter(mTint.getColorForState(getDrawableState(), 0));
39 | else setColorFilter(mTint);
40 | }
41 | Drawable drawable = getBackground();
42 | if (mBackgroundTint != null && drawable != null) {
43 | Drawable wrap = DrawableCompat.wrap(drawable);
44 | wrap = wrap.mutate();
45 |
46 | if (mBackgroundTint.isStateful())
47 | DrawableCompat.setTint(wrap, ContextCompat.getColor(getContext(), mBackgroundTint.getColorForState(getDrawableState(), 0)));
48 | else DrawableCompat.setTintList(wrap, mBackgroundTint);
49 |
50 | DrawableCompat.setTintMode(wrap, PorterDuff.Mode.SRC_IN);
51 | }
52 | }
53 |
54 | public void removeTint() {
55 | mTint = null;
56 | clearColorFilter();
57 | }
58 |
59 | public void setColorFilter(ColorStateList tint) {
60 | this.mTint = tint;
61 | setColorFilter(tint.getColorForState(getDrawableState(), 0));
62 | }
63 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ImageLetterIcon
2 | Material letter icon with circle background. Also supports for image for user contact.
3 |
4 | [](https://android-arsenal.com/details/1/2762)
5 |
6 | [  ](https://bintray.com/akashandroid90/maven/image-letter-icon/_latestVersion)
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | 
16 | 
17 | 
18 | 
19 | Gradle
20 | -------------------------
21 |
22 | ```
23 |
24 | dependencies {
25 | compile 'com.github.akashandroid90:imageletter:1.8@aar'
26 | }
27 |
28 | ```
29 |
30 | ChangeLog
31 | -----
32 |
33 | bug fixes
34 |
35 | vector drawable support
36 |
37 | Usage
38 | -----
39 |
40 | Declare in XML (see xml attributes below for customization):
41 |
42 | ```xml
43 |
46 | ```
47 |
48 | Or static initializer (see xml attributes below for customization):
49 |
50 | ```java
51 | MaterialLetterIcon icon = new MaterialLetterIcon.Builder(context) //
52 | .shapeColor(getResources().getColor(R.color.circle_color))
53 | .setShapeType(MaterialLetterIcon.SHAPE_CIRCLE)
54 | .letter("S")
55 | .letterColor(getResources().getColor(R.color.letter_color))
56 | .letterSize(26)
57 | .lettersNumber(1)
58 | .letterTypeface(yourTypeface)
59 | .initials(false)
60 | .initialsNumber(2)
61 | .create();
62 | ```
63 |
64 |
65 | Configure using xml attributes or setters in code:
66 |
67 | ```java
68 | app:shape_color="@color/black" // shape color
69 | app:shape_type="circle" // shape type
70 | app:letter="" // letter or string to get first letter from
71 | app:letter_color="@color/white" // letter color
72 | app:letter_size="26" // letter size SP
73 | app:letters_number="1" // number of letters to get from string
74 | app:initials="false" // turn on initials mode
75 | app:initials_number="2" // number of initials to be showed
76 | app:corner_radius="1dp" // radius of image to make at corner
77 | app:is_oval="true" // to make a circular image
78 | app:border_width="1dp" // border width around the image
79 | app:border_color="@color/black" //border color around image
80 | ```
81 |
82 | Donations
83 | ---------
84 |
85 | This project needs you! If you would like to support this project's further development, the creator of this project or the continuous maintenance of this project, feel free to donate. Your donation is highly appreciated (and I love food, coffee and beer). Thank you!
86 |
87 | **PayPal**
88 |
89 | * **[Donate $5]**: Thank's for creating this project, here's a coffee (or some beer) for you!
90 | * **[Donate $10]**: Wow, I am stunned. Let me take you to the movies!
91 | * **[Donate $15]**: I really appreciate your work, let's grab some lunch!
92 | * **[Donate $25]**: That's some awesome stuff you did right there, dinner is on me!
93 | * **[Donate $50]**: I really really want to support this project, great job!
94 | * **[Donate $100]**: You are the man! This project saved me hours (if not days) of struggle and hard work, simply awesome!
95 | * **[Donate $2799]**: Go buddy, buy Macbook Pro for yourself!
96 | Of course, you can also choose what you want to donate, all donations are awesome!
97 |
98 | Developed By
99 | --------------------
100 | Akash Jain
101 |
102 |
103 | [Donate $5]: https://www.paypal.me/akashandroid/5
104 | [Donate $10]: https://www.paypal.me/akashandroid/10
105 | [Donate $15]: https://www.paypal.me/akashandroid/15
106 | [Donate $25]: https://www.paypal.me/akashandroid/25
107 | [Donate $50]: https://www.paypal.me/akashandroid/50
108 | [Donate $100]: https://www.paypal.me/akashandroid/100
109 | [Donate $2799]: https://www.paypal.me/akashandroid/2799
110 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/imageletter/src/main/java/com/github/akashandroid90/imageletter/MaterialLetterIcon.java:
--------------------------------------------------------------------------------
1 | package com.github.akashandroid90.imageletter;
2 |
3 | import android.content.Context;
4 | import android.content.res.ColorStateList;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Color;
7 | import android.graphics.Typeface;
8 | import android.graphics.drawable.Drawable;
9 | import android.support.annotation.ColorInt;
10 | import android.text.TextUtils;
11 | import android.util.AttributeSet;
12 | import android.util.TypedValue;
13 |
14 | import com.github.akashandroid90.imageletter.drawable.TextDrawable;
15 |
16 | public class MaterialLetterIcon extends RoundedImageViewWithBorder {
17 | private TextDrawable.IShapeBuilder mBuilder;
18 | private String mText;
19 | private int mTextSize;
20 | private int mTextColor;
21 | private int mShapeColor;
22 | private int mLetterCount;
23 | private Typeface mTypeface;
24 | private boolean bold, uppercase;
25 | private boolean mOval;
26 |
27 | public MaterialLetterIcon(Context context) {
28 | this(context, null);
29 | }
30 |
31 | public MaterialLetterIcon(Context context, AttributeSet attrs) {
32 | this(context, attrs, 0);
33 | }
34 |
35 | public MaterialLetterIcon(Context context, AttributeSet attrs, int defStyle) {
36 | super(context, attrs, defStyle);
37 | mBuilder = TextDrawable.builder();
38 | TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.MaterialLetterIcon, defStyle, 0);
39 | mLetterCount = attr.getInt(R.styleable.MaterialLetterIcon_text_number, 2);
40 | mTextSize = attr.getInt(R.styleable.MaterialLetterIcon_text_size, 26);
41 | mTextColor = attr.getColor(R.styleable.MaterialLetterIcon_text_color, Color.WHITE);
42 | mShapeColor = attr.getColor(R.styleable.MaterialLetterIcon_shape_color, Color.RED);
43 | bold = attr.getBoolean(R.styleable.MaterialLetterIcon_is_bold, false);
44 | uppercase = attr.getBoolean(R.styleable.MaterialLetterIcon_is_uppercase, false);
45 |
46 | computeText(attr.getString(R.styleable.MaterialLetterIcon_text));
47 | attr.recycle();
48 | updateDrawable();
49 | }
50 |
51 | private int toPx(int dp) {
52 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
53 | }
54 |
55 | private void updateDrawable() {
56 | if (TextUtils.isEmpty(mText)) {
57 | return;
58 | }
59 | TextDrawable.IConfigBuilder iConfigBuilder = mBuilder.beginConfig().withBorder(getBorderWidth()).textColor(mTextColor).borderColor(getBorderColor());
60 | if (mTypeface != null)
61 | iConfigBuilder.useFont(mTypeface);
62 | if (mTextSize > 0)
63 | iConfigBuilder.fontSize(toPx(mTextSize));
64 | if (isBold())
65 | iConfigBuilder.bold();
66 | if (isUppercase())
67 | iConfigBuilder.toUpperCase();
68 | mBuilder = iConfigBuilder.endConfig();
69 | Drawable mDrawable;
70 | if (isOval())
71 | mDrawable = mBuilder.buildRound(mText, mShapeColor);
72 | else if (getCornerRadius() > 0)
73 | mDrawable = mBuilder.buildRoundRect(mText, mShapeColor, getCornerRadius() / 5);
74 | else mDrawable = mBuilder.buildRect(mText, mShapeColor);
75 | setImageDrawable(mDrawable);
76 | }
77 |
78 | private void computeText(String text) {
79 | if (TextUtils.isEmpty(text)) {
80 | return;
81 | }
82 | String initials[] = text.split("\\s+");
83 | StringBuilder initialsPlain = new StringBuilder(mLetterCount);
84 | for (String initial : initials) {
85 | initialsPlain.append(initial.substring(0, 1));
86 | }
87 | mText = initialsPlain.toString();
88 | mText = mText.substring(0, mLetterCount > mText.length() ? mText.length() : mLetterCount);
89 | }
90 |
91 | public String getText() {
92 | return mText;
93 | }
94 |
95 | public void setText(String text) {
96 | computeText(text);
97 | updateDrawable();
98 | }
99 |
100 | public int getTextSize() {
101 | return mTextSize;
102 | }
103 |
104 | public void setTextSize(int textSize) {
105 | mTextSize = textSize;
106 | updateDrawable();
107 | }
108 |
109 | public void setTypeface(Typeface typeface) {
110 | mTypeface = typeface;
111 | updateDrawable();
112 | }
113 |
114 | public Typeface getTypeFace() {
115 | return mTypeface;
116 | }
117 |
118 | public int getShapeColor() {
119 | return mShapeColor;
120 | }
121 |
122 | public void setShapeColor(@ColorInt int color) {
123 | mShapeColor = color;
124 | updateDrawable();
125 | }
126 |
127 | public int getTextColor() {
128 | return mTextColor;
129 | }
130 |
131 | public void setTextColor(@ColorInt int color) {
132 | mTextColor = color;
133 | updateDrawable();
134 | }
135 |
136 | public boolean isBold() {
137 | return bold;
138 | }
139 |
140 | public void setBold(boolean bold) {
141 | this.bold = bold;
142 | }
143 |
144 | public boolean isUppercase() {
145 | return uppercase;
146 | }
147 |
148 | public void setUppercase(boolean uppercase) {
149 | this.uppercase = uppercase;
150 | }
151 |
152 | public int getLetterCount() {
153 | return mLetterCount;
154 | }
155 |
156 | public void setLetterCount(int mLetterCount) {
157 | this.mLetterCount = mLetterCount;
158 | }
159 |
160 | public void setBorderColor(int color) {
161 | setBorderColors(ColorStateList.valueOf(color));
162 | }
163 | }
--------------------------------------------------------------------------------
/imageletter/src/main/java/com/github/akashandroid90/imageletter/drawable/TextDrawable.java:
--------------------------------------------------------------------------------
1 | package com.github.akashandroid90.imageletter.drawable;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Color;
5 | import android.graphics.ColorFilter;
6 | import android.graphics.Paint;
7 | import android.graphics.PixelFormat;
8 | import android.graphics.Rect;
9 | import android.graphics.RectF;
10 | import android.graphics.Typeface;
11 | import android.graphics.drawable.ShapeDrawable;
12 | import android.graphics.drawable.shapes.OvalShape;
13 | import android.graphics.drawable.shapes.RectShape;
14 | import android.graphics.drawable.shapes.RoundRectShape;
15 |
16 | public class TextDrawable extends ShapeDrawable {
17 |
18 | private static final float SHADE_FACTOR = 0.9f;
19 | private final Paint textPaint;
20 | private final Paint borderPaint;
21 | private final String text;
22 | private final int color;
23 | private final int borderColor;
24 | private final RectShape shape;
25 | private final int height;
26 | private final int width;
27 | private final int fontSize;
28 | private final float radius;
29 | private final int borderThickness;
30 |
31 | private TextDrawable(Builder builder) {
32 | super(builder.shape);
33 |
34 | // shape properties
35 | shape = builder.shape;
36 | height = builder.height;
37 | width = builder.width;
38 | radius = builder.radius;
39 |
40 | // text and color
41 | text = builder.toUpperCase ? builder.text.toUpperCase() : builder.text;
42 | color = builder.color;
43 | borderColor = builder.borderColor;
44 |
45 | // text paint settings
46 | fontSize = builder.fontSize;
47 | textPaint = new Paint();
48 | textPaint.setColor(builder.textColor);
49 | textPaint.setAntiAlias(true);
50 | textPaint.setFakeBoldText(builder.isBold);
51 | textPaint.setStyle(Paint.Style.FILL);
52 | textPaint.setTypeface(builder.font);
53 | textPaint.setTextAlign(Paint.Align.CENTER);
54 | textPaint.setStrokeWidth(builder.borderThickness);
55 |
56 | // border paint settings
57 | borderThickness = builder.borderThickness;
58 | borderPaint = new Paint();
59 | borderPaint.setColor(borderColor);
60 | borderPaint.setStyle(Paint.Style.STROKE);
61 | borderPaint.setStrokeWidth(borderThickness);
62 |
63 | // drawable paint color
64 | Paint paint = getPaint();
65 | paint.setColor(color);
66 | }
67 |
68 | private static int getDarkerShade(int color) {
69 | return Color.rgb((int) (SHADE_FACTOR * Color.red(color)),
70 | (int) (SHADE_FACTOR * Color.green(color)),
71 | (int) (SHADE_FACTOR * Color.blue(color)));
72 | }
73 |
74 | public static IShapeBuilder builder() {
75 | return new Builder();
76 | }
77 |
78 | @Override
79 | public void draw(Canvas canvas) {
80 | super.draw(canvas);
81 | Rect r = getBounds();
82 | // draw border
83 | if (borderThickness > 0) {
84 | drawBorder(canvas);
85 | }
86 |
87 | int count = canvas.save();
88 | canvas.translate(r.left, r.top);
89 |
90 | // draw text
91 | int width = this.width < 0 ? r.width() : this.width;
92 | int height = this.height < 0 ? r.height() : this.height;
93 | int fontSize = this.fontSize < 0 ? (Math.min(width, height) / 2) : this.fontSize;
94 | textPaint.setTextSize(fontSize);
95 | canvas.drawText(text, width / 2, height / 2 - ((textPaint.descent() + textPaint.ascent()) / 2), textPaint);
96 | canvas.restoreToCount(count);
97 | }
98 |
99 | private void drawBorder(Canvas canvas) {
100 | RectF rect = new RectF(getBounds());
101 | rect.inset(borderThickness / 2, borderThickness / 2);
102 |
103 | if (shape instanceof OvalShape) {
104 | canvas.drawOval(rect, borderPaint);
105 | } else if (shape instanceof RoundRectShape) {
106 | canvas.drawRoundRect(rect, radius, radius, borderPaint);
107 | } else {
108 | canvas.drawRect(rect, borderPaint);
109 | }
110 | }
111 |
112 | @Override
113 | public void setAlpha(int alpha) {
114 | textPaint.setAlpha(alpha);
115 | }
116 |
117 | @Override
118 | public void setColorFilter(ColorFilter cf) {
119 | textPaint.setColorFilter(cf);
120 | }
121 |
122 | @Override
123 | public int getOpacity() {
124 | return PixelFormat.TRANSLUCENT;
125 | }
126 |
127 | @Override
128 | public int getIntrinsicWidth() {
129 | return width;
130 | }
131 |
132 | @Override
133 | public int getIntrinsicHeight() {
134 | return height;
135 | }
136 |
137 | public interface IConfigBuilder {
138 | IConfigBuilder width(int width);
139 |
140 | IConfigBuilder height(int height);
141 |
142 | IConfigBuilder textColor(int color);
143 |
144 | IConfigBuilder borderColor(int color);
145 |
146 | IConfigBuilder withBorder(int thickness);
147 |
148 | IConfigBuilder useFont(Typeface font);
149 |
150 | IConfigBuilder fontSize(int size);
151 |
152 | IConfigBuilder bold();
153 |
154 | IConfigBuilder toUpperCase();
155 |
156 | IShapeBuilder endConfig();
157 | }
158 |
159 | public interface IBuilder {
160 | TextDrawable build(String text, int color);
161 | }
162 |
163 | public interface IShapeBuilder {
164 | IConfigBuilder beginConfig();
165 |
166 | IBuilder rect();
167 |
168 | IBuilder round();
169 |
170 | IBuilder roundRect(int radius);
171 |
172 | TextDrawable buildRect(String text, int color);
173 |
174 | TextDrawable buildRoundRect(String text, int color, int radius);
175 |
176 | TextDrawable buildRound(String text, int color);
177 | }
178 |
179 | public static class Builder implements IConfigBuilder, IShapeBuilder, IBuilder {
180 |
181 | private String text;
182 | private int color;
183 | private int borderColor;
184 | private int borderThickness;
185 | private int width;
186 | private int height;
187 | private Typeface font;
188 | private RectShape shape;
189 | private int textColor;
190 | private int fontSize;
191 | private boolean isBold;
192 | private boolean toUpperCase;
193 | private float radius;
194 |
195 | private Builder() {
196 | text = "";
197 | color = Color.GRAY;
198 | borderColor = getDarkerShade(color);
199 | textColor = Color.WHITE;
200 | borderThickness = 0;
201 | width = -1;
202 | height = -1;
203 | shape = new RectShape();
204 | font = Typeface.DEFAULT;
205 | fontSize = -1;
206 | isBold = false;
207 | toUpperCase = false;
208 | }
209 |
210 | public IConfigBuilder width(int width) {
211 | this.width = width;
212 | return this;
213 | }
214 |
215 | public IConfigBuilder height(int height) {
216 | this.height = height;
217 | return this;
218 | }
219 |
220 | public IConfigBuilder textColor(int color) {
221 | this.textColor = color;
222 | return this;
223 | }
224 |
225 | public IConfigBuilder borderColor(int color) {
226 | this.borderColor = color;
227 | return this;
228 | }
229 |
230 | public IConfigBuilder withBorder(int thickness) {
231 | this.borderThickness = thickness;
232 | return this;
233 | }
234 |
235 | public IConfigBuilder useFont(Typeface font) {
236 | this.font = font;
237 | return this;
238 | }
239 |
240 | public IConfigBuilder fontSize(int size) {
241 | this.fontSize = size;
242 | return this;
243 | }
244 |
245 | public IConfigBuilder bold() {
246 | this.isBold = true;
247 | return this;
248 | }
249 |
250 | public IConfigBuilder toUpperCase() {
251 | this.toUpperCase = true;
252 | return this;
253 | }
254 |
255 | @Override
256 | public IConfigBuilder beginConfig() {
257 | return this;
258 | }
259 |
260 | @Override
261 | public IShapeBuilder endConfig() {
262 | return this;
263 | }
264 |
265 | @Override
266 | public IBuilder rect() {
267 | this.shape = new RectShape();
268 | return this;
269 | }
270 |
271 | @Override
272 | public IBuilder round() {
273 | this.shape = new OvalShape();
274 | return this;
275 | }
276 |
277 | @Override
278 | public IBuilder roundRect(int radius) {
279 | this.radius = radius;
280 | float[] radii = {radius, radius, radius, radius, radius, radius, radius, radius};
281 | this.shape = new RoundRectShape(radii, null, null);
282 | return this;
283 | }
284 |
285 | @Override
286 | public TextDrawable buildRect(String text, int color) {
287 | rect();
288 | return build(text, color);
289 | }
290 |
291 | @Override
292 | public TextDrawable buildRoundRect(String text, int color, int radius) {
293 | roundRect(radius);
294 | return build(text, color);
295 | }
296 |
297 | @Override
298 | public TextDrawable buildRound(String text, int color) {
299 | round();
300 | return build(text, color);
301 | }
302 |
303 | @Override
304 | public TextDrawable build(String text, int color) {
305 | this.color = color;
306 | this.text = text;
307 | return new TextDrawable(this);
308 | }
309 | }
310 | }
--------------------------------------------------------------------------------
/imageletter/src/main/java/com/github/akashandroid90/imageletter/RoundedImageViewWithBorder.java:
--------------------------------------------------------------------------------
1 | package com.github.akashandroid90.imageletter;
2 |
3 | import android.content.Context;
4 | import android.content.res.ColorStateList;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Bitmap;
7 | import android.graphics.drawable.Drawable;
8 | import android.graphics.drawable.LayerDrawable;
9 | import android.net.Uri;
10 | import android.os.Build;
11 | import android.support.v7.content.res.AppCompatResources;
12 | import android.util.AttributeSet;
13 |
14 | import com.github.akashandroid90.imageletter.drawable.RoundedDrawable;
15 |
16 | import java.io.FileNotFoundException;
17 | import java.io.InputStream;
18 |
19 | public class RoundedImageViewWithBorder extends TintableImageView {
20 | public static final int DEFAULT_RADIUS = 0;
21 | public static final int DEFAULT_BORDER_WIDTH = 0;
22 | private static final ScaleType[] sScaleTypeArray = {
23 | ScaleType.MATRIX,
24 | ScaleType.FIT_XY,
25 | ScaleType.FIT_START,
26 | ScaleType.FIT_CENTER,
27 | ScaleType.FIT_END,
28 | ScaleType.CENTER,
29 | ScaleType.CENTER_CROP,
30 | ScaleType.CENTER_INSIDE
31 | };
32 | private int mCornerRadius = DEFAULT_RADIUS;
33 | private int mBorderWidth = DEFAULT_BORDER_WIDTH;
34 | private ColorStateList mBorderColor = ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR);
35 | private boolean mOval = false;
36 | private boolean mRoundBackground = false;
37 | private int mResource;
38 | private Drawable mDrawable;
39 | private Drawable mBackgroundDrawable;
40 | private ScaleType mScaleType;
41 |
42 | public RoundedImageViewWithBorder(Context context) {
43 | this(context, null);
44 | }
45 |
46 | public RoundedImageViewWithBorder(Context context, AttributeSet attrs) {
47 | this(context, attrs, 0);
48 | }
49 |
50 | public RoundedImageViewWithBorder(Context context, AttributeSet attrs, int defStyle) {
51 | super(context, attrs, defStyle);
52 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundedImageView, defStyle, 0);
53 | int index = a.getInt(R.styleable.RoundedImageView_android_scaleType, -1);
54 | if (index >= 0) {
55 | setScaleType(sScaleTypeArray[index]);
56 | }
57 | mCornerRadius = a.getDimensionPixelSize(R.styleable.RoundedImageView_corner_radius, -1);
58 | mBorderWidth = a.getDimensionPixelSize(R.styleable.RoundedImageView_border_width, -1);
59 | // don't allow negative values for radius and border
60 | if (mCornerRadius < 0) {
61 | mCornerRadius = DEFAULT_RADIUS;
62 | }
63 | if (mBorderWidth < 0) {
64 | mBorderWidth = DEFAULT_BORDER_WIDTH;
65 | }
66 | mBorderColor = a.getColorStateList(R.styleable.RoundedImageView_border_color);
67 | if (mBorderColor == null) {
68 | mBorderColor = ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR);
69 | }
70 | mRoundBackground = a.getBoolean(R.styleable.RoundedImageView_round_background, false);
71 | mOval = a.getBoolean(R.styleable.RoundedImageView_is_oval, false);
72 | updateDrawableAttrs();
73 | updateBackgroundDrawableAttrs();
74 | a.recycle();
75 | }
76 |
77 | @Override
78 | protected void drawableStateChanged() {
79 | super.drawableStateChanged();
80 | invalidate();
81 | }
82 |
83 | @Override
84 | public ScaleType getScaleType() {
85 | return mScaleType;
86 | }
87 |
88 | @Override
89 | public void setScaleType(ScaleType scaleType) {
90 | if (scaleType == null) {
91 | throw new NullPointerException();
92 | }
93 | if (mScaleType != scaleType) {
94 | mScaleType = scaleType;
95 | switch (scaleType) {
96 | case CENTER:
97 | case CENTER_CROP:
98 | case CENTER_INSIDE:
99 | case FIT_CENTER:
100 | case FIT_START:
101 | case FIT_END:
102 | case FIT_XY:
103 | super.setScaleType(ScaleType.FIT_XY);
104 | break;
105 | default:
106 | super.setScaleType(scaleType);
107 | break;
108 | }
109 | updateDrawableAttrs();
110 | updateBackgroundDrawableAttrs();
111 | invalidate();
112 | }
113 | }
114 |
115 | @Override
116 | public void setImageDrawable(Drawable drawable) {
117 | mResource = 0;
118 | mDrawable = RoundedDrawable.fromDrawable(drawable);
119 | updateDrawableAttrs();
120 | super.setImageDrawable(mDrawable);
121 | }
122 |
123 | @Override
124 | public void setImageBitmap(Bitmap bm) {
125 | mResource = 0;
126 | mDrawable = RoundedDrawable.fromBitmap(bm);
127 | updateDrawableAttrs();
128 | super.setImageDrawable(mDrawable);
129 | }
130 |
131 | @Override
132 | public void setImageURI(Uri uri) {
133 | mResource = 0;
134 | try {
135 | InputStream inputStream = getContext().getContentResolver().openInputStream(uri);
136 | mDrawable = Drawable.createFromStream(inputStream, uri.toString());
137 | } catch (FileNotFoundException e) {
138 | e.printStackTrace();
139 | }
140 | mDrawable = RoundedDrawable.fromDrawable(mDrawable);
141 | updateDrawableAttrs();
142 | super.setImageDrawable(mDrawable);
143 | }
144 |
145 | @Override
146 | public void setImageResource(int resId) {
147 | if (mResource != resId) {
148 | mResource = resId;
149 | mDrawable = resolveResource();
150 | updateDrawableAttrs();
151 | super.setImageDrawable(mDrawable);
152 | }
153 | }
154 |
155 | private Drawable resolveResource() {
156 | Drawable d = null;
157 | if (mResource != 0) {
158 | try {
159 | d = AppCompatResources.getDrawable(getContext(), mResource);
160 | } catch (Exception e) {
161 | mResource = 0;
162 | }
163 | }
164 | return RoundedDrawable.fromDrawable(d);
165 | }
166 |
167 | @Override
168 | public void setBackground(Drawable background) {
169 | setBackgroundDrawable(background);
170 | }
171 |
172 | private void updateDrawableAttrs() {
173 | updateAttrs(mDrawable, false);
174 | }
175 |
176 | private void updateBackgroundDrawableAttrs() {
177 | updateAttrs(mBackgroundDrawable, true);
178 | }
179 |
180 | private void updateAttrs(Drawable drawable, boolean background) {
181 | if (drawable == null) {
182 | return;
183 | }
184 | if (drawable instanceof RoundedDrawable) {
185 | ((RoundedDrawable) drawable)
186 | .setScaleType(mScaleType)
187 | .setCornerRadius(background && !mRoundBackground ? 0 : mCornerRadius)
188 | .setBorderWidth(mBorderWidth)
189 | .setBorderColors(mBorderColor)
190 | .setOval(mOval);
191 | } else if (drawable instanceof LayerDrawable) {
192 | // loop through layers to and set drawable attrs
193 | LayerDrawable ld = ((LayerDrawable) drawable);
194 | int layers = ld.getNumberOfLayers();
195 | for (int i = 0; i < layers; i++) {
196 | updateAttrs(ld.getDrawable(i), background);
197 | }
198 | }
199 | }
200 |
201 | @Override
202 | public void setBackgroundDrawable(Drawable background) {
203 | mBackgroundDrawable = RoundedDrawable.fromDrawable(background);
204 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
205 | super.setBackground(mBackgroundDrawable);
206 | else
207 | super.setBackgroundDrawable(mBackgroundDrawable);
208 | }
209 |
210 | public int getCornerRadius() {
211 | return mCornerRadius;
212 | }
213 |
214 | public void setCornerRadius(int radius) {
215 | if (mCornerRadius == radius) {
216 | return;
217 | }
218 | mCornerRadius = radius;
219 | updateDrawableAttrs();
220 | updateBackgroundDrawableAttrs();
221 | }
222 |
223 | public int getBorderWidth() {
224 | return mBorderWidth;
225 | }
226 |
227 | public void setBorderWidth(int width) {
228 | if (mBorderWidth == width) {
229 | return;
230 | }
231 | mBorderWidth = width;
232 | updateDrawableAttrs();
233 | updateBackgroundDrawableAttrs();
234 | invalidate();
235 | }
236 |
237 | public int getBorderColor() {
238 | if (mBorderColor != null)
239 | return mBorderColor.getDefaultColor();
240 | else return RoundedDrawable.DEFAULT_BORDER_COLOR;
241 | }
242 |
243 | public void setBorderColor(int color) {
244 | setBorderColors(ColorStateList.valueOf(color));
245 | }
246 |
247 | public ColorStateList getBorderColors() {
248 | return mBorderColor;
249 | }
250 |
251 | public void setBorderColors(ColorStateList colors) {
252 | if (mBorderColor.equals(colors)) {
253 | return;
254 | }
255 | mBorderColor = (colors != null) ? colors : ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR);
256 | updateDrawableAttrs();
257 | updateBackgroundDrawableAttrs();
258 | if (mBorderWidth > 0) {
259 | invalidate();
260 | }
261 | }
262 |
263 | public boolean isOval() {
264 | return mOval;
265 | }
266 |
267 | public void setOval(boolean oval) {
268 | mOval = oval;
269 | updateDrawableAttrs();
270 | updateBackgroundDrawableAttrs();
271 | invalidate();
272 | }
273 |
274 | public boolean isRoundBackground() {
275 | return mRoundBackground;
276 | }
277 |
278 | public void setRoundBackground(boolean roundBackground) {
279 | if (mRoundBackground == roundBackground) {
280 | return;
281 | }
282 | mRoundBackground = roundBackground;
283 | updateBackgroundDrawableAttrs();
284 | invalidate();
285 | }
286 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/app/src/main/java/com/imagelettericon/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.imagelettericon;
2 |
3 | import android.content.Context;
4 | import android.content.DialogInterface;
5 | import android.content.Intent;
6 | import android.graphics.Color;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.support.v7.app.AlertDialog;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.support.v7.widget.LinearLayoutManager;
12 | import android.support.v7.widget.RecyclerView;
13 | import android.util.TypedValue;
14 | import android.view.LayoutInflater;
15 | import android.view.Menu;
16 | import android.view.MenuInflater;
17 | import android.view.MenuItem;
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import android.widget.RelativeLayout;
21 | import android.widget.TextView;
22 | import com.github.akashandroid90.imageletter.MaterialLetterIcon;
23 |
24 | import java.util.Arrays;
25 | import java.util.List;
26 | import java.util.Random;
27 | public class MainActivity extends AppCompatActivity {
28 | private static final String[] desuNoto = {
29 | "Alane Avey", "Belen Brewster", "Brandon Brochu", "Carli Carrol", "Della Delrio",
30 | "Esther Echavarria", "Etha Edinger", "Felipe Flecha", "Ilse Island", "Kecia Keltz",
31 | "Lourie Lucas", "Lucille Leachman", "Mandi Mcqueeney", "Murray Matchett", "Nadia Nero",
32 | "Nannie Nipp", "Ozella Otis", "Pauletta Poehler", "Roderick Rippy", "Sherril Sager",
33 | "Taneka Tenorio", "Treena Trentham", "Ulrike Uhlman", "Virgina Viau", "Willis Wysocki"
34 | };
35 | private static final String[] countries = {
36 | "Albania", "Australia", "Belgium", "Canada", "China", "Dominica", "Egypt", "Estonia",
37 | "Finland", "France", "Germany", "Honduras", "Italy", "Japan", "Madagascar", "Netherlands",
38 | "Norway", "Panama", "Portugal", "Romania", "Russia", "Slovakia", "Vatican", "Zimbabwe"
39 | };
40 | private static final int CONTACTS = 0;
41 | private static final int COUNTRIES = 1;
42 | private static final int ALTERNATECOUNTRIES = 2;
43 | private static final int ALTERNATECONTACTS = 3;
44 | private static final Random RANDOM = new Random();
45 | private RecyclerView recyclerView;
46 | @Override
47 | protected void onCreate(Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | setContentView(R.layout.activity_main);
50 | recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
51 | setupRecyclerView();
52 | }
53 | @Override
54 | public boolean onCreateOptionsMenu(Menu menu) {
55 | final MenuInflater inflater = getMenuInflater();
56 | inflater.inflate(R.menu.menu, menu);
57 | return super.onCreateOptionsMenu(menu);
58 | }
59 |
60 | @Override
61 | public void onBackPressed() {
62 | showDialog();
63 | }
64 |
65 | private void showDialog() {
66 | new AlertDialog.Builder(this).setMessage("Are you sure want to exit from app?").setPositiveButton("Yes", new DialogInterface.OnClickListener() {
67 | @Override
68 | public void onClick(DialogInterface dialogInterface, int i) {
69 | dialogInterface.dismiss();
70 | finish();
71 | }
72 | }).setNegativeButton("No", new DialogInterface.OnClickListener() {
73 | @Override
74 | public void onClick(DialogInterface dialogInterface, int i) {
75 | dialogInterface.dismiss();
76 | }
77 | }).setNeutralButton("Rate us", new DialogInterface.OnClickListener() {
78 | @Override
79 | public void onClick(DialogInterface dialogInterface, int i) {
80 | dialogInterface.dismiss();
81 | Intent intent = new Intent(Intent.ACTION_VIEW);
82 | intent.setData(Uri.parse("market://details?id=com.imagelettericon"));
83 | startActivity(intent);
84 | }
85 | }).create().show();
86 | }
87 |
88 | @Override
89 | public boolean onOptionsItemSelected(MenuItem item) {
90 | Intent intent;
91 | switch (item.getItemId()) {
92 | case R.id.contacts:
93 | setContactsAdapter(desuNoto);
94 | return true;
95 | case R.id.countries:
96 | setCountriesAdapter(countries);
97 | return true;
98 | case R.id.alternate_countries:
99 | setAlternateCountriesAdapter(countries);
100 | return true;
101 | case R.id.alternate_contacts:
102 | setAlternateContactsAdapter(countries);
103 | return true;
104 | case R.id.play_store:
105 | intent = new Intent(Intent.ACTION_VIEW);
106 | intent.setData(Uri.parse("market://details?id=com.imagelettericon"));
107 | startActivity(intent);
108 | return true;
109 | case R.id.other_apps:
110 | intent= new Intent(Intent.ACTION_VIEW);
111 | intent.setData(Uri.parse("market://search?q=pub:AkashJain"));
112 | startActivity(intent);
113 | return true;
114 | case R.id.github:
115 | intent = new Intent(Intent.ACTION_VIEW);
116 | intent.setData(Uri.parse("https://github.com/akashandroid90/ImageLetterIcon"));
117 | startActivity(intent);
118 | return true;
119 | case R.id.share:
120 | Intent sendIntent = new Intent();
121 | sendIntent.setAction(Intent.ACTION_SEND);
122 | sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Material Icon");
123 | sendIntent.putExtra(Intent.EXTRA_TEXT, "http://play.google.com/store/apps/details?id=com.imagelettericon");
124 | sendIntent.setType("text/plain");
125 | startActivity(sendIntent);
126 | return true;
127 | }
128 | return super.onOptionsItemSelected(item);
129 | }
130 |
131 | private void setupRecyclerView() {
132 | recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
133 | setContactsAdapter(desuNoto);
134 | }
135 |
136 | private void setContactsAdapter(String[] array) {
137 | recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(this, Arrays.asList(array), CONTACTS));
138 | }
139 |
140 | private void setCountriesAdapter(String[] array) {
141 | recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(this, Arrays.asList(array), COUNTRIES));
142 | }
143 |
144 |
145 | private void setAlternateCountriesAdapter(String[] array) {
146 | recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(this, Arrays.asList(array), ALTERNATECOUNTRIES));
147 | }
148 |
149 | private void setAlternateContactsAdapter(String[] array) {
150 | recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(this, Arrays.asList(array), ALTERNATECONTACTS));
151 | }
152 |
153 | public static class SimpleStringRecyclerViewAdapter
154 | extends RecyclerView.Adapter {
155 |
156 | private final TypedValue mTypedValue = new TypedValue();
157 | private int mBackground;
158 | private List mValues;
159 | private int[] mMaterialColors;
160 | private int[] mImageResource;
161 | private int mType;
162 |
163 | SimpleStringRecyclerViewAdapter(Context context, List items, int type) {
164 | context.getTheme().resolveAttribute(R.attr.selectableItemBackground, mTypedValue, true);
165 | mMaterialColors = context.getResources().getIntArray(R.array.colors);
166 | mImageResource = new int[]{R.drawable.one, R.drawable.two, R.drawable.three, R.drawable.four,
167 | R.drawable.five, R.drawable.six, R.drawable.seven, R.drawable.eight, R.drawable.nine};
168 | mBackground = mTypedValue.resourceId;
169 | mValues = items;
170 | mType = type;
171 | }
172 |
173 | @Override
174 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
175 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
176 | view.setBackgroundResource(mBackground);
177 | return new ViewHolder(view);
178 | }
179 |
180 | @Override
181 | public void onBindViewHolder(final ViewHolder holder, int position) {
182 | switch (mType) {
183 | case CONTACTS:
184 | // holder.mIcon.setImageDrawable(TextDrawable.builder().beginConfig().textColor(Color.WHITE).bold().toUpperCase().endConfig().buildRect("aa",Color.RED));
185 | holder.mIcon.setTextSize(18);
186 | holder.mIcon.setOval(false);
187 | holder.mIcon.setTextColor(Color.WHITE);
188 | holder.mIcon.setBorderColor(Color.BLACK);
189 | holder.mIcon.setBorderWidth(1);
190 | holder.mIcon.setShapeColor(mMaterialColors[RANDOM.nextInt(mMaterialColors.length)]);
191 | holder.mIcon.setText(mValues.get(position));
192 | break;
193 | case COUNTRIES:
194 | holder.mIcon.setLetterCount(3);
195 | holder.mIcon.setTextSize(16);
196 | holder.mIcon.setOval(true);
197 | holder.mIcon.setText(mValues.get(position));
198 | holder.mIcon.setShapeColor(mMaterialColors[RANDOM.nextInt(mMaterialColors.length)]);
199 | break;
200 | case ALTERNATECOUNTRIES:
201 | if (position % 2 == 0) {
202 | holder.mIcon.setOval(true);
203 | holder.mIcon.setImageResource(mImageResource[RANDOM.nextInt(mImageResource.length)]);
204 | } else {
205 | holder.mIcon.setOval(true);
206 | holder.mIcon.setShapeColor(mMaterialColors[RANDOM.nextInt(mMaterialColors.length)]);
207 | holder.mIcon.setText(mValues.get(position));
208 | holder.mIcon.setLetterCount(2);
209 | holder.mIcon.setTextSize(18);
210 | }
211 | break;
212 | case ALTERNATECONTACTS:
213 | holder.mIcon.setCornerRadius(holder.itemView.getResources().getDimensionPixelSize(R.dimen._50sdp));
214 | if (position % 2 == 0) {
215 | holder.mIcon.setOval(false);
216 | holder.mIcon.setImageResource(mImageResource[RANDOM.nextInt(mImageResource.length)]);
217 | } else {
218 | holder.mIcon.setOval(false);
219 | holder.mIcon.setShapeColor(mMaterialColors[RANDOM.nextInt(mMaterialColors.length)]);
220 | holder.mIcon.setText(mValues.get(position));
221 | holder.mIcon.setLetterCount(2);
222 | holder.mIcon.setTextSize(18);
223 | }
224 | break;
225 | }
226 | holder.mBoundString = mValues.get(position);
227 | holder.mTextView.setText(mValues.get(position));
228 | }
229 |
230 | @Override
231 | public int getItemCount() {
232 | return mValues.size();
233 | }
234 |
235 | public class ViewHolder extends RecyclerView.ViewHolder {
236 | public final View mView;
237 | public final MaterialLetterIcon mIcon;
238 | public final TextView mTextView;
239 | public String mBoundString;
240 |
241 | public ViewHolder(View view) {
242 | super(view);
243 | mView = view;
244 | mIcon = (MaterialLetterIcon) view.findViewById(R.id.icon);
245 | mTextView = (TextView) view.findViewById(android.R.id.text1);
246 | }
247 |
248 | @Override
249 | public String toString() {
250 | return super.toString() + " '" + mTextView.getText();
251 | }
252 | }
253 | }
254 | }
255 |
--------------------------------------------------------------------------------
/imageletter/src/main/java/com/github/akashandroid90/imageletter/drawable/RoundedDrawable.java:
--------------------------------------------------------------------------------
1 | package com.github.akashandroid90.imageletter.drawable;
2 |
3 | import android.content.res.ColorStateList;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Bitmap.Config;
6 | import android.graphics.BitmapShader;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.ColorFilter;
10 | import android.graphics.Matrix;
11 | import android.graphics.Paint;
12 | import android.graphics.PixelFormat;
13 | import android.graphics.Rect;
14 | import android.graphics.RectF;
15 | import android.graphics.Shader;
16 | import android.graphics.drawable.BitmapDrawable;
17 | import android.graphics.drawable.ColorDrawable;
18 | import android.graphics.drawable.Drawable;
19 | import android.graphics.drawable.LayerDrawable;
20 | import android.widget.ImageView.ScaleType;
21 |
22 | public class RoundedDrawable extends Drawable {
23 | public static final int DEFAULT_BORDER_COLOR = Color.BLACK;
24 | private final RectF mBounds = new RectF();
25 | private final RectF mDrawableRect = new RectF();
26 | private final RectF mBitmapRect = new RectF();
27 | private final BitmapShader mBitmapShader;
28 | private final Paint mBitmapPaint;
29 | private final int mBitmapWidth;
30 | private final int mBitmapHeight;
31 | private final RectF mBorderRect = new RectF();
32 | private final Paint mBorderPaint;
33 | private final Matrix mShaderMatrix = new Matrix();
34 | private ColorStateList mBorderColor = ColorStateList.valueOf(DEFAULT_BORDER_COLOR);
35 | private float mCornerRadius = 0;
36 | private boolean mOval = false;
37 | private float mBorderWidth = 0;
38 | private ScaleType mScaleType = ScaleType.FIT_XY;
39 |
40 | public RoundedDrawable(Bitmap bitmap) {
41 | mBitmapWidth = bitmap.getWidth();
42 | mBitmapHeight = bitmap.getHeight();
43 | mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight);
44 | mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
45 | mBitmapShader.setLocalMatrix(mShaderMatrix);
46 | mBitmapPaint = new Paint();
47 | mBitmapPaint.setStyle(Paint.Style.FILL);
48 | mBitmapPaint.setAntiAlias(true);
49 | mBitmapPaint.setShader(mBitmapShader);
50 | mBorderPaint = new Paint();
51 | mBorderPaint.setStyle(Paint.Style.STROKE);
52 | if(mBorderColor!=null){
53 | if (mBorderColor.isStateful())
54 | mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
55 | else mBorderPaint.setColor(mBorderColor.getDefaultColor());
56 | } else mBorderPaint.setColor(DEFAULT_BORDER_COLOR);
57 | mBorderPaint.setStrokeWidth(mBorderWidth);
58 | }
59 |
60 | public static Drawable fromBitmap(Bitmap bitmap) {
61 | if (bitmap != null) {
62 | return new RoundedDrawable(bitmap);
63 | } else {
64 | return null;
65 | }
66 | }
67 |
68 | public static Drawable fromDrawable(Drawable drawable) {
69 | if (drawable != null) {
70 | if (drawable instanceof RoundedDrawable) {
71 | // just return if it's already a RoundedDrawable
72 | return drawable;
73 | } else if (drawable instanceof ColorDrawable) {
74 | // FIXME we don't support ColorDrawables yet
75 | return drawable;
76 | } else if (drawable instanceof LayerDrawable) {
77 | LayerDrawable ld = (LayerDrawable) drawable;
78 | int num = ld.getNumberOfLayers();
79 | // loop through layers to and change to RoundedDrawables if possible
80 | for (int i = 0; i < num; i++) {
81 | Drawable d = ld.getDrawable(i);
82 | ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d));
83 | }
84 | return ld;
85 | }
86 | // try to get a bitmap from the drawable and
87 | Bitmap bm = drawableToBitmap(drawable);
88 | if (bm != null) {
89 | return new RoundedDrawable(bm);
90 | }
91 | }
92 | return drawable;
93 | }
94 |
95 | public static Bitmap drawableToBitmap(Drawable drawable) {
96 | if (drawable instanceof BitmapDrawable) {
97 | return ((BitmapDrawable) drawable).getBitmap();
98 | }
99 | Bitmap bitmap;
100 | int width = drawable.getIntrinsicWidth();
101 | int height = drawable.getIntrinsicHeight();
102 | if (width > 0 && height > 0) {
103 | bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
104 | Canvas canvas = new Canvas(bitmap);
105 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
106 | drawable.draw(canvas);
107 | } else {
108 | bitmap = null;
109 | }
110 | return bitmap;
111 | }
112 |
113 | @Override
114 | public boolean isStateful() {
115 | return mBorderColor.isStateful();
116 | }
117 |
118 | @Override
119 | protected boolean onStateChange(int[] state) {
120 | int newColor = mBorderColor.getColorForState(state, 0);
121 | if (mBorderPaint.getColor() != newColor) {
122 | mBorderPaint.setColor(newColor);
123 | return true;
124 | } else {
125 | return super.onStateChange(state);
126 | }
127 | }
128 |
129 | private void updateShaderMatrix() {
130 | mBorderRect.set(mBounds);
131 | mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth);
132 | float scale;
133 | float dx;
134 | float dy;
135 | switch (mScaleType) {
136 | case CENTER:
137 | mBorderRect.set(mBounds);
138 | mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth);
139 | mShaderMatrix.set(null);
140 | mShaderMatrix.setTranslate((int) ((mDrawableRect.width() - mBitmapWidth) * 0.5f + 0.5f), (int) ((mDrawableRect.height() - mBitmapHeight) * 0.5f + 0.5f));
141 | break;
142 | case CENTER_CROP:
143 | mBorderRect.set(mBounds);
144 | mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth);
145 | mShaderMatrix.set(null);
146 | dx = 0;
147 | dy = 0;
148 | if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) {
149 | scale = mDrawableRect.height() / (float) mBitmapHeight;
150 | dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;
151 | } else {
152 | scale = mDrawableRect.width() / (float) mBitmapWidth;
153 | dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;
154 | }
155 | mShaderMatrix.setScale(scale, scale);
156 | mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth, (int) (dy + 0.5f) + mBorderWidth);
157 | break;
158 | case CENTER_INSIDE:
159 | mShaderMatrix.set(null);
160 | if (mBitmapWidth <= mBounds.width() && mBitmapHeight <= mBounds.height()) {
161 | scale = 1.0f;
162 | } else {
163 | scale = Math.min(mBounds.width() / (float) mBitmapWidth,
164 | mBounds.height() / (float) mBitmapHeight);
165 | }
166 | dx = (int) ((mBounds.width() - mBitmapWidth * scale) * 0.5f + 0.5f);
167 | dy = (int) ((mBounds.height() - mBitmapHeight * scale) * 0.5f + 0.5f);
168 | mShaderMatrix.setScale(scale, scale);
169 | mShaderMatrix.postTranslate(dx, dy);
170 | mBorderRect.set(mBitmapRect);
171 | mShaderMatrix.mapRect(mBorderRect);
172 | mDrawableRect.set(mBorderRect.left + mBorderWidth, mBorderRect.top + mBorderWidth, mBorderRect.right - mBorderWidth, mBorderRect.bottom - mBorderWidth);
173 | mShaderMatrix.setRectToRect(mBitmapRect, mDrawableRect, Matrix.ScaleToFit.FILL);
174 | break;
175 | case FIT_CENTER:
176 | mBorderRect.set(mBitmapRect);
177 | mShaderMatrix.setRectToRect(mBitmapRect, mBounds, Matrix.ScaleToFit.CENTER);
178 | mShaderMatrix.mapRect(mBorderRect);
179 | mDrawableRect.set(mBorderRect.left + mBorderWidth, mBorderRect.top + mBorderWidth, mBorderRect.right - mBorderWidth, mBorderRect.bottom - mBorderWidth);
180 | mShaderMatrix.setRectToRect(mBitmapRect, mDrawableRect, Matrix.ScaleToFit.FILL);
181 | break;
182 | case FIT_END:
183 | mBorderRect.set(mBitmapRect);
184 | mShaderMatrix.setRectToRect(mBitmapRect, mBounds, Matrix.ScaleToFit.END);
185 | mShaderMatrix.mapRect(mBorderRect);
186 | mDrawableRect.set(mBorderRect.left + mBorderWidth, mBorderRect.top + mBorderWidth, mBorderRect.right - mBorderWidth, mBorderRect.bottom - mBorderWidth);
187 | mShaderMatrix.setRectToRect(mBitmapRect, mDrawableRect, Matrix.ScaleToFit.FILL);
188 | break;
189 | case FIT_START:
190 | mBorderRect.set(mBitmapRect);
191 | mShaderMatrix.setRectToRect(mBitmapRect, mBounds, Matrix.ScaleToFit.START);
192 | mShaderMatrix.mapRect(mBorderRect);
193 | mDrawableRect.set(mBorderRect.left + mBorderWidth, mBorderRect.top + mBorderWidth, mBorderRect.right - mBorderWidth, mBorderRect.bottom - mBorderWidth);
194 | mShaderMatrix.setRectToRect(mBitmapRect, mDrawableRect, Matrix.ScaleToFit.FILL);
195 | break;
196 | case FIT_XY:
197 | default:
198 | mBorderRect.set(mBounds);
199 | mDrawableRect.set(0 + mBorderWidth, 0 + mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth);
200 | mShaderMatrix.set(null);
201 | mShaderMatrix.setRectToRect(mBitmapRect, mDrawableRect, Matrix.ScaleToFit.FILL);
202 | break;
203 | }
204 | mBorderRect.inset(mBorderWidth / 2, mBorderWidth / 2);
205 | mBitmapShader.setLocalMatrix(mShaderMatrix);
206 | }
207 |
208 | @Override
209 | protected void onBoundsChange(Rect bounds) {
210 | super.onBoundsChange(bounds);
211 | mBounds.set(bounds);
212 | updateShaderMatrix();
213 | }
214 |
215 | @Override
216 | public void draw(Canvas canvas) {
217 | if (mOval) {
218 | if (mBorderWidth > 0) {
219 | canvas.drawOval(mBorderRect, mBorderPaint);
220 | canvas.drawOval(mDrawableRect, mBitmapPaint);
221 | } else {
222 | canvas.drawOval(mDrawableRect, mBitmapPaint);
223 | }
224 | } else {
225 | if (mBorderWidth > 0) {
226 | canvas.drawRoundRect(mBorderRect, mCornerRadius, mCornerRadius, mBorderPaint);
227 | canvas.drawRoundRect(mDrawableRect, Math.max(mCornerRadius - mBorderWidth, 0), Math.max(mCornerRadius - mBorderWidth, 0), mBitmapPaint);
228 | } else {
229 | canvas.drawRoundRect(mDrawableRect, mCornerRadius, mCornerRadius, mBitmapPaint);
230 | }
231 | }
232 | }
233 |
234 | @Override
235 | public int getOpacity() {
236 | return PixelFormat.TRANSLUCENT;
237 | }
238 |
239 | @Override
240 | public void setAlpha(int alpha) {
241 | mBitmapPaint.setAlpha(alpha);
242 | invalidateSelf();
243 | }
244 |
245 | @Override
246 | public void setColorFilter(ColorFilter cf) {
247 | mBitmapPaint.setColorFilter(cf);
248 | invalidateSelf();
249 | }
250 |
251 | @Override
252 | public void setDither(boolean dither) {
253 | mBitmapPaint.setDither(dither);
254 | invalidateSelf();
255 | }
256 |
257 | @Override
258 | public void setFilterBitmap(boolean filter) {
259 | mBitmapPaint.setFilterBitmap(filter);
260 | invalidateSelf();
261 | }
262 |
263 | @Override
264 | public int getIntrinsicWidth() {
265 | return mBitmapWidth;
266 | }
267 |
268 | @Override
269 | public int getIntrinsicHeight() {
270 | return mBitmapHeight;
271 | }
272 |
273 | public float getCornerRadius() {
274 | return mCornerRadius;
275 | }
276 |
277 | public RoundedDrawable setCornerRadius(float radius) {
278 | mCornerRadius = radius;
279 | return this;
280 | }
281 |
282 | public float getBorderWidth() {
283 | return mBorderWidth;
284 | }
285 |
286 | public RoundedDrawable setBorderWidth(int width) {
287 | mBorderWidth = width*5;
288 | mBorderPaint.setStrokeWidth(mBorderWidth);
289 | return this;
290 | }
291 |
292 | public int getBorderColor() {
293 | if(mBorderColor!=null)
294 | return mBorderColor.getDefaultColor();
295 | else return DEFAULT_BORDER_COLOR;
296 | }
297 |
298 | public RoundedDrawable setBorderColor(int color) {
299 | return setBorderColors(ColorStateList.valueOf(color));
300 | }
301 |
302 | public ColorStateList getBorderColors() {
303 | return mBorderColor;
304 | }
305 |
306 | public RoundedDrawable setBorderColors(ColorStateList colors) {
307 | mBorderColor = colors != null ? colors : ColorStateList.valueOf(0);
308 | if (mBorderColor.isStateful())
309 | mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
310 | else mBorderPaint.setColor(mBorderColor.getDefaultColor());
311 | return this;
312 | }
313 |
314 | public boolean isOval() {
315 | return mOval;
316 | }
317 |
318 | public RoundedDrawable setOval(boolean oval) {
319 | mOval = oval;
320 | return this;
321 | }
322 |
323 | public ScaleType getScaleType() {
324 | return mScaleType;
325 | }
326 |
327 | public RoundedDrawable setScaleType(ScaleType scaleType) {
328 | if (scaleType == null) {
329 | scaleType = ScaleType.FIT_XY;
330 | }
331 | if (mScaleType != scaleType) {
332 | mScaleType = scaleType;
333 | updateShaderMatrix();
334 | }
335 | return this;
336 | }
337 | }
--------------------------------------------------------------------------------