├── .gitignore
├── LICENSE
├── README.md
├── TextDrawable.iml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── library.iml
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── amulyakhare
│ └── textdrawable
│ ├── TextDrawable.java
│ └── util
│ └── ColorGenerator.java
├── sample
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── sample.iml
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── amulyakhare
│ │ └── td
│ │ └── sample
│ │ ├── ListActivity.java
│ │ ├── MainActivity.java
│ │ └── sample
│ │ ├── DataItem.java
│ │ ├── DataSource.java
│ │ └── DrawableProvider.java
│ └── res
│ ├── drawable-hdpi
│ ├── check_alpha.png
│ ├── check_sm.9.png
│ ├── check_sm1.9.png
│ ├── ic_action_next_item.png
│ └── ic_launcher.png
│ ├── drawable-ldpi
│ └── check_sm.9.png
│ ├── drawable-mdpi
│ ├── check_sm.9.png
│ ├── ic_action_next_item.png
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ ├── check_sm.9.png
│ ├── ic_action_next_item.png
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ ├── check_sm.9.png
│ ├── ic_action_next_item.png
│ └── ic_launcher.png
│ ├── layout
│ ├── activity_check_box.xml
│ ├── activity_list.xml
│ ├── activity_main.xml
│ └── list_item_layout.xml
│ ├── menu
│ ├── check_box.xml
│ ├── list.xml
│ └── main.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── screens
├── screen1-material.png
├── screen1.png
├── screen2-material.png
├── screen2.png
├── screen3.png
├── screen4.png
├── screen5.png
├── screen6.png
└── screen7.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | #built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Windows thumbnail db
19 | Thumbs.db
20 |
21 | # OSX files
22 | .DS_Store
23 |
24 | # Eclipse project files
25 | .classpath
26 | .project
27 |
28 | # Android Studio
29 | .idea
30 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
31 | .gradle
32 | build/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Amulya Khare
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ###TextDrawable
2 | This light-weight library provides images with letter/text like the Gmail app. It extends the `Drawable` class thus can be used with existing/custom/network `ImageView` classes. Also included is a [fluent interface](http://en.wikipedia.org/wiki/Fluent_interface) for creating drawables and a customizable `ColorGenerator`.
3 |
4 |
5 |
6 |
7 |
8 | ###How to use
9 |
10 | #### Import with Gradle:
11 |
12 | ```groovy
13 | repositories{
14 | maven {
15 | url 'http://dl.bintray.com/amulyakhare/maven'
16 | }
17 | }
18 |
19 | dependencies {
20 | compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
21 | }
22 | ```
23 |
24 | ####1. Create simple tile:
25 |
26 |
27 |
28 |
29 | ```xml
30 |
33 | ```
34 | **Note:** Specify width/height for the `ImageView` and the `drawable` will auto-scale to fit the size.
35 | ```java
36 | TextDrawable drawable = TextDrawable.builder()
37 | .buildRect("A", Color.RED);
38 |
39 | ImageView image = (ImageView) findViewById(R.id.image_view);
40 | image.setImageDrawable(drawable);
41 | ```
42 |
43 | ####2. Create rounded corner or circular tiles:
44 |
45 |
46 |
47 |
48 | ```java
49 | TextDrawable drawable1 = TextDrawable.builder()
50 | .buildRoundRect("A", Color.RED, 10); // radius in px
51 |
52 | TextDrawable drawable2 = TextDrawable.builder()
53 | .buildRound("A", Color.RED);
54 | ```
55 |
56 | ####3. Add border:
57 |
58 |
59 |
60 |
61 | ```java
62 | TextDrawable drawable = TextDrawable.builder()
63 | .beginConfig()
64 | .withBorder(4) /* thickness in px */
65 | .endConfig()
66 | .buildRoundRect("A", Color.RED, 10);
67 | ```
68 |
69 | ####4. Modify font style:
70 |
71 | ```java
72 | TextDrawable drawable = TextDrawable.builder()
73 | .beginConfig()
74 | .textColor(Color.BLACK)
75 | .useFont(Typeface.DEFAULT)
76 | .fontSize(30) /* size in px */
77 | .bold()
78 | .toUpperCase()
79 | .endConfig()
80 | .buildRect("a", Color.RED)
81 | ```
82 |
83 | ####5. Built-in color generator:
84 |
85 | ```java
86 | ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT
87 | // generate random color
88 | int color1 = generator.getRandomColor();
89 | // generate color based on a key (same key returns the same color), useful for list/grid views
90 | int color2 = generator.getColor("user@gmail.com")
91 |
92 | // declare the builder object once.
93 | TextDrawable.IBuilder builder = TextDrawable.builder()
94 | .beginConfig()
95 | .withBorder(4)
96 | .endConfig()
97 | .rect();
98 |
99 | // reuse the builder specs to create multiple drawables
100 | TextDrawable ic1 = builder.build("A", color1);
101 | TextDrawable ic2 = builder.build("B", color2);
102 | ```
103 |
104 | ####6. Specify the width / height:
105 |
106 | ```xml
107 |
110 | ```
111 | **Note:** The `ImageView` could use `wrap_content` width/height. You could set the width/height of the `drawable` using code.
112 |
113 | ```java
114 | TextDrawable drawable = TextDrawable.builder()
115 | .beginConfig()
116 | .width(60) // width in px
117 | .height(60) // height in px
118 | .endConfig()
119 | .buildRect("A", Color.RED);
120 |
121 | ImageView image = (ImageView) findViewById(R.id.image_view);
122 | image.setImageDrawable(drawable);
123 | ```
124 |
125 | ####7. Other features:
126 |
127 | 1. Mix-match with other drawables. Use it in conjunction with `LayerDrawable`, `InsetDrawable`, `AnimationDrawable`, `TransitionDrawable` etc.
128 |
129 | 2. Compatible with other views (not just `ImageView`). Use it as background drawable, compound drawable for `TextView`, `Button` etc.
130 |
131 | 3. Use multiple letters or `unicode` characters to create interesting tiles.
132 |
133 | 
134 |
--------------------------------------------------------------------------------
/TextDrawable.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.0.0'
9 | // NOTE: Do not place your application dependencies here; they belong
10 | // in the individual module build.gradle files
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | jcenter()
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Settings specified in this file will override any Gradle settings
5 | # configured through the IDE.
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
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jan 04 21:42:37 SGT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 10
9 | targetSdkVersion 21
10 | versionCode 2
11 | versionName "1.1"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | }
24 |
25 | sourceSets {
26 | main {
27 | java {
28 | srcDir 'src/main/java'
29 | }
30 | resources {
31 | srcDir 'src/main/res'
32 | }
33 | }
34 | }
35 |
36 | task sourcesJar(type: Jar) {
37 | classifier = 'sources'
38 | from sourceSets.main.java, sourceSets.main.resources
39 | }
40 |
--------------------------------------------------------------------------------
/library/library.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/library/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 /home/gardev/android/adt-bundle-linux/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 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/java/com/amulyakhare/textdrawable/TextDrawable.java:
--------------------------------------------------------------------------------
1 | package com.amulyakhare.textdrawable;
2 |
3 | import android.graphics.*;
4 | import android.graphics.drawable.ShapeDrawable;
5 | import android.graphics.drawable.shapes.OvalShape;
6 | import android.graphics.drawable.shapes.RectShape;
7 | import android.graphics.drawable.shapes.RoundRectShape;
8 |
9 | /**
10 | * @author amulya
11 | * @datetime 14 Oct 2014, 3:53 PM
12 | */
13 | public class TextDrawable extends ShapeDrawable {
14 |
15 | private final Paint textPaint;
16 | private final Paint borderPaint;
17 | private static final float SHADE_FACTOR = 0.9f;
18 | private final String text;
19 | private final int color;
20 | private final RectShape shape;
21 | private final int height;
22 | private final int width;
23 | private final int fontSize;
24 | private final float radius;
25 | private final int borderThickness;
26 |
27 | private TextDrawable(Builder builder) {
28 | super(builder.shape);
29 |
30 | // shape properties
31 | shape = builder.shape;
32 | height = builder.height;
33 | width = builder.width;
34 | radius = builder.radius;
35 |
36 | // text and color
37 | text = builder.toUpperCase ? builder.text.toUpperCase() : builder.text;
38 | color = builder.color;
39 |
40 | // text paint settings
41 | fontSize = builder.fontSize;
42 | textPaint = new Paint();
43 | textPaint.setColor(builder.textColor);
44 | textPaint.setAntiAlias(true);
45 | textPaint.setFakeBoldText(builder.isBold);
46 | textPaint.setStyle(Paint.Style.FILL);
47 | textPaint.setTypeface(builder.font);
48 | textPaint.setTextAlign(Paint.Align.CENTER);
49 | textPaint.setStrokeWidth(builder.borderThickness);
50 |
51 | // border paint settings
52 | borderThickness = builder.borderThickness;
53 | borderPaint = new Paint();
54 | borderPaint.setColor(getDarkerShade(color));
55 | borderPaint.setStyle(Paint.Style.STROKE);
56 | borderPaint.setStrokeWidth(borderThickness);
57 |
58 | // drawable paint color
59 | Paint paint = getPaint();
60 | paint.setColor(color);
61 |
62 | }
63 |
64 | private int getDarkerShade(int color) {
65 | return Color.rgb((int)(SHADE_FACTOR * Color.red(color)),
66 | (int)(SHADE_FACTOR * Color.green(color)),
67 | (int)(SHADE_FACTOR * Color.blue(color)));
68 | }
69 |
70 | @Override
71 | public void draw(Canvas canvas) {
72 | super.draw(canvas);
73 | Rect r = getBounds();
74 |
75 |
76 | // draw border
77 | if (borderThickness > 0) {
78 | drawBorder(canvas);
79 | }
80 |
81 | int count = canvas.save();
82 | canvas.translate(r.left, r.top);
83 |
84 | // draw text
85 | int width = this.width < 0 ? r.width() : this.width;
86 | int height = this.height < 0 ? r.height() : this.height;
87 | int fontSize = this.fontSize < 0 ? (Math.min(width, height) / 2) : this.fontSize;
88 | textPaint.setTextSize(fontSize);
89 | canvas.drawText(text, width / 2, height / 2 - ((textPaint.descent() + textPaint.ascent()) / 2), textPaint);
90 |
91 | canvas.restoreToCount(count);
92 |
93 | }
94 |
95 | private void drawBorder(Canvas canvas) {
96 | RectF rect = new RectF(getBounds());
97 | rect.inset(borderThickness/2, borderThickness/2);
98 |
99 | if (shape instanceof OvalShape) {
100 | canvas.drawOval(rect, borderPaint);
101 | }
102 | else if (shape instanceof RoundRectShape) {
103 | canvas.drawRoundRect(rect, radius, radius, borderPaint);
104 | }
105 | else {
106 | canvas.drawRect(rect, borderPaint);
107 | }
108 | }
109 |
110 | @Override
111 | public void setAlpha(int alpha) {
112 | textPaint.setAlpha(alpha);
113 | }
114 |
115 | @Override
116 | public void setColorFilter(ColorFilter cf) {
117 | textPaint.setColorFilter(cf);
118 | }
119 |
120 | @Override
121 | public int getOpacity() {
122 | return PixelFormat.TRANSLUCENT;
123 | }
124 |
125 | @Override
126 | public int getIntrinsicWidth() {
127 | return width;
128 | }
129 |
130 | @Override
131 | public int getIntrinsicHeight() {
132 | return height;
133 | }
134 |
135 | public static IShapeBuilder builder() {
136 | return new Builder();
137 | }
138 |
139 | public static class Builder implements IConfigBuilder, IShapeBuilder, IBuilder {
140 |
141 | private String text;
142 |
143 | private int color;
144 |
145 | private int borderThickness;
146 |
147 | private int width;
148 |
149 | private int height;
150 |
151 | private Typeface font;
152 |
153 | private RectShape shape;
154 |
155 | public int textColor;
156 |
157 | private int fontSize;
158 |
159 | private boolean isBold;
160 |
161 | private boolean toUpperCase;
162 |
163 | public float radius;
164 |
165 | private Builder() {
166 | text = "";
167 | color = Color.GRAY;
168 | textColor = Color.WHITE;
169 | borderThickness = 0;
170 | width = -1;
171 | height = -1;
172 | shape = new RectShape();
173 | font = Typeface.create("sans-serif-light", Typeface.NORMAL);
174 | fontSize = -1;
175 | isBold = false;
176 | toUpperCase = false;
177 | }
178 |
179 | public IConfigBuilder width(int width) {
180 | this.width = width;
181 | return this;
182 | }
183 |
184 | public IConfigBuilder height(int height) {
185 | this.height = height;
186 | return this;
187 | }
188 |
189 | public IConfigBuilder textColor(int color) {
190 | this.textColor = color;
191 | return this;
192 | }
193 |
194 | public IConfigBuilder withBorder(int thickness) {
195 | this.borderThickness = thickness;
196 | return this;
197 | }
198 |
199 | public IConfigBuilder useFont(Typeface font) {
200 | this.font = font;
201 | return this;
202 | }
203 |
204 | public IConfigBuilder fontSize(int size) {
205 | this.fontSize = size;
206 | return this;
207 | }
208 |
209 | public IConfigBuilder bold() {
210 | this.isBold = true;
211 | return this;
212 | }
213 |
214 | public IConfigBuilder toUpperCase() {
215 | this.toUpperCase = true;
216 | return this;
217 | }
218 |
219 | @Override
220 | public IConfigBuilder beginConfig() {
221 | return this;
222 | }
223 |
224 | @Override
225 | public IShapeBuilder endConfig() {
226 | return this;
227 | }
228 |
229 | @Override
230 | public IBuilder rect() {
231 | this.shape = new RectShape();
232 | return this;
233 | }
234 |
235 | @Override
236 | public IBuilder round() {
237 | this.shape = new OvalShape();
238 | return this;
239 | }
240 |
241 | @Override
242 | public IBuilder roundRect(int radius) {
243 | this.radius = radius;
244 | float[] radii = {radius, radius, radius, radius, radius, radius, radius, radius};
245 | this.shape = new RoundRectShape(radii, null, null);
246 | return this;
247 | }
248 |
249 | @Override
250 | public TextDrawable buildRect(String text, int color) {
251 | rect();
252 | return build(text, color);
253 | }
254 |
255 | @Override
256 | public TextDrawable buildRoundRect(String text, int color, int radius) {
257 | roundRect(radius);
258 | return build(text, color);
259 | }
260 |
261 | @Override
262 | public TextDrawable buildRound(String text, int color) {
263 | round();
264 | return build(text, color);
265 | }
266 |
267 | @Override
268 | public TextDrawable build(String text, int color) {
269 | this.color = color;
270 | this.text = text;
271 | return new TextDrawable(this);
272 | }
273 | }
274 |
275 | public interface IConfigBuilder {
276 | public IConfigBuilder width(int width);
277 |
278 | public IConfigBuilder height(int height);
279 |
280 | public IConfigBuilder textColor(int color);
281 |
282 | public IConfigBuilder withBorder(int thickness);
283 |
284 | public IConfigBuilder useFont(Typeface font);
285 |
286 | public IConfigBuilder fontSize(int size);
287 |
288 | public IConfigBuilder bold();
289 |
290 | public IConfigBuilder toUpperCase();
291 |
292 | public IShapeBuilder endConfig();
293 | }
294 |
295 | public static interface IBuilder {
296 |
297 | public TextDrawable build(String text, int color);
298 | }
299 |
300 | public static interface IShapeBuilder {
301 |
302 | public IConfigBuilder beginConfig();
303 |
304 | public IBuilder rect();
305 |
306 | public IBuilder round();
307 |
308 | public IBuilder roundRect(int radius);
309 |
310 | public TextDrawable buildRect(String text, int color);
311 |
312 | public TextDrawable buildRoundRect(String text, int color, int radius);
313 |
314 | public TextDrawable buildRound(String text, int color);
315 | }
316 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/amulyakhare/textdrawable/util/ColorGenerator.java:
--------------------------------------------------------------------------------
1 | package com.amulyakhare.textdrawable.util;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 | import java.util.Random;
6 |
7 | /**
8 | * @author amulya
9 | * @datetime 14 Oct 2014, 5:20 PM
10 | */
11 | public class ColorGenerator {
12 |
13 | public static ColorGenerator DEFAULT;
14 |
15 | public static ColorGenerator MATERIAL;
16 |
17 | static {
18 | DEFAULT = create(Arrays.asList(
19 | 0xfff16364,
20 | 0xfff58559,
21 | 0xfff9a43e,
22 | 0xffe4c62e,
23 | 0xff67bf74,
24 | 0xff59a2be,
25 | 0xff2093cd,
26 | 0xffad62a7,
27 | 0xff805781
28 | ));
29 | MATERIAL = create(Arrays.asList(
30 | 0xffe57373,
31 | 0xfff06292,
32 | 0xffba68c8,
33 | 0xff9575cd,
34 | 0xff7986cb,
35 | 0xff64b5f6,
36 | 0xff4fc3f7,
37 | 0xff4dd0e1,
38 | 0xff4db6ac,
39 | 0xff81c784,
40 | 0xffaed581,
41 | 0xffff8a65,
42 | 0xffd4e157,
43 | 0xffffd54f,
44 | 0xffffb74d,
45 | 0xffa1887f,
46 | 0xff90a4ae
47 | ));
48 | }
49 |
50 | private final List mColors;
51 | private final Random mRandom;
52 |
53 | public static ColorGenerator create(List colorList) {
54 | return new ColorGenerator(colorList);
55 | }
56 |
57 | private ColorGenerator(List colorList) {
58 | mColors = colorList;
59 | mRandom = new Random(System.currentTimeMillis());
60 | }
61 |
62 | public int getRandomColor() {
63 | return mColors.get(mRandom.nextInt(mColors.size()));
64 | }
65 |
66 | public int getColor(Object key) {
67 | return mColors.get(Math.abs(key.hashCode()) % mColors.size());
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.1"
6 |
7 | defaultConfig {
8 | applicationId "com.amulyakhare.td"
9 | minSdkVersion 10
10 | targetSdkVersion 21
11 | versionCode 2
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(dir: 'libs', include: ['*.jar'])
24 | compile project(':library')
25 | compile 'com.android.support:appcompat-v7:21.0.3'
26 | }
--------------------------------------------------------------------------------
/sample/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 /home/gardev/android/adt-bundle-linux/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 |
--------------------------------------------------------------------------------
/sample/sample.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/amulyakhare/td/sample/ListActivity.java:
--------------------------------------------------------------------------------
1 | package com.amulyakhare.td.sample;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.v7.app.ActionBarActivity;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.BaseAdapter;
10 | import android.widget.ImageView;
11 | import android.widget.ListView;
12 | import android.widget.TextView;
13 |
14 | import com.amulyakhare.td.R;
15 | import com.amulyakhare.td.sample.sample.DrawableProvider;
16 | import com.amulyakhare.textdrawable.TextDrawable;
17 | import com.amulyakhare.textdrawable.util.ColorGenerator;
18 |
19 | import java.util.Arrays;
20 | import java.util.List;
21 |
22 | public class ListActivity extends ActionBarActivity {
23 |
24 | private static final int HIGHLIGHT_COLOR = 0x999be6ff;
25 |
26 | // list of data items
27 | private List mDataList = Arrays.asList(
28 | new ListData("Iron Man"),
29 | new ListData("Captain America"),
30 | new ListData("James Bond"),
31 | new ListData("Harry Potter"),
32 | new ListData("Sherlock Holmes"),
33 | new ListData("Black Widow"),
34 | new ListData("Hawk Eye"),
35 | new ListData("Iron Man"),
36 | new ListData("Guava"),
37 | new ListData("Tomato"),
38 | new ListData("Pineapple"),
39 | new ListData("Strawberry"),
40 | new ListData("Watermelon"),
41 | new ListData("Pears"),
42 | new ListData("Kiwi"),
43 | new ListData("Plums")
44 | );
45 |
46 | // declare the color generator and drawable builder
47 | private ColorGenerator mColorGenerator = ColorGenerator.MATERIAL;
48 | private TextDrawable.IBuilder mDrawableBuilder;
49 |
50 | @Override
51 | protected void onCreate(Bundle savedInstanceState) {
52 | super.onCreate(savedInstanceState);
53 | setContentView(R.layout.activity_list);
54 |
55 | Intent intent = getIntent();
56 | int type = intent.getIntExtra(MainActivity.TYPE, DrawableProvider.SAMPLE_RECT);
57 |
58 | // initialize the builder based on the "TYPE"
59 | switch (type) {
60 | case DrawableProvider.SAMPLE_RECT:
61 | mDrawableBuilder = TextDrawable.builder()
62 | .rect();
63 | break;
64 | case DrawableProvider.SAMPLE_ROUND_RECT:
65 | mDrawableBuilder = TextDrawable.builder()
66 | .roundRect(10);
67 | break;
68 | case DrawableProvider.SAMPLE_ROUND:
69 | mDrawableBuilder = TextDrawable.builder()
70 | .round();
71 | break;
72 | case DrawableProvider.SAMPLE_RECT_BORDER:
73 | mDrawableBuilder = TextDrawable.builder()
74 | .beginConfig()
75 | .withBorder(4)
76 | .endConfig()
77 | .rect();
78 | break;
79 | case DrawableProvider.SAMPLE_ROUND_RECT_BORDER:
80 | mDrawableBuilder = TextDrawable.builder()
81 | .beginConfig()
82 | .withBorder(4)
83 | .endConfig()
84 | .roundRect(10);
85 | break;
86 | case DrawableProvider.SAMPLE_ROUND_BORDER:
87 | mDrawableBuilder = TextDrawable.builder()
88 | .beginConfig()
89 | .withBorder(4)
90 | .endConfig()
91 | .round();
92 | break;
93 | }
94 |
95 | // init the list view and its adapter
96 | ListView listView = (ListView) findViewById(R.id.listView);
97 | listView.setAdapter(new SampleAdapter());
98 | }
99 |
100 | private class SampleAdapter extends BaseAdapter {
101 |
102 | @Override
103 | public int getCount() {
104 | return mDataList.size();
105 | }
106 |
107 | @Override
108 | public ListData getItem(int position) {
109 | return mDataList.get(position);
110 | }
111 |
112 | @Override
113 | public long getItemId(int position) {
114 | return position;
115 | }
116 |
117 | @Override
118 | public View getView(final int position, View convertView, ViewGroup parent) {
119 | final ViewHolder holder;
120 | if (convertView == null) {
121 | convertView = View.inflate(ListActivity.this, R.layout.list_item_layout, null);
122 | holder = new ViewHolder(convertView);
123 | convertView.setTag(holder);
124 | } else {
125 | holder = (ViewHolder) convertView.getTag();
126 | }
127 |
128 | ListData item = getItem(position);
129 |
130 | // provide support for selected state
131 | updateCheckedState(holder, item);
132 | holder.imageView.setOnClickListener(new View.OnClickListener() {
133 | @Override
134 | public void onClick(View v) {
135 | // when the image is clicked, update the selected state
136 | ListData data = getItem(position);
137 | data.setChecked(!data.isChecked);
138 | updateCheckedState(holder, data);
139 | }
140 | });
141 | holder.textView.setText(item.data);
142 |
143 | return convertView;
144 | }
145 |
146 | private void updateCheckedState(ViewHolder holder, ListData item) {
147 | if (item.isChecked) {
148 | holder.imageView.setImageDrawable(mDrawableBuilder.build(" ", 0xff616161));
149 | holder.view.setBackgroundColor(HIGHLIGHT_COLOR);
150 | holder.checkIcon.setVisibility(View.VISIBLE);
151 | }
152 | else {
153 | TextDrawable drawable = mDrawableBuilder.build(String.valueOf(item.data.charAt(0)), mColorGenerator.getColor(item.data));
154 | holder.imageView.setImageDrawable(drawable);
155 | holder.view.setBackgroundColor(Color.TRANSPARENT);
156 | holder.checkIcon.setVisibility(View.GONE);
157 | }
158 | }
159 | }
160 |
161 | private static class ViewHolder {
162 |
163 | private View view;
164 |
165 | private ImageView imageView;
166 |
167 | private TextView textView;
168 |
169 | private ImageView checkIcon;
170 |
171 | private ViewHolder(View view) {
172 | this.view = view;
173 | imageView = (ImageView) view.findViewById(R.id.imageView);
174 | textView = (TextView) view.findViewById(R.id.textView);
175 | checkIcon = (ImageView) view.findViewById(R.id.check_icon);
176 | }
177 | }
178 |
179 | private static class ListData {
180 |
181 | private String data;
182 |
183 | private boolean isChecked;
184 |
185 | public ListData(String data) {
186 | this.data = data;
187 | }
188 |
189 | public void setChecked(boolean isChecked) {
190 | this.isChecked = isChecked;
191 | }
192 | }
193 | }
194 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/amulyakhare/td/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.amulyakhare.td.sample;
2 |
3 | import android.content.Intent;
4 | import android.graphics.drawable.AnimationDrawable;
5 | import android.graphics.drawable.Drawable;
6 | import android.os.Bundle;
7 | import android.support.v7.app.ActionBarActivity;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.*;
11 |
12 | import com.amulyakhare.td.R;
13 | import com.amulyakhare.td.sample.sample.DataItem;
14 | import com.amulyakhare.td.sample.sample.DataSource;
15 |
16 | public class MainActivity extends ActionBarActivity implements AdapterView.OnItemClickListener {
17 |
18 | public static final String TYPE = "TYPE";
19 | private DataSource mDataSource;
20 | private ListView mListView;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 |
27 | mListView = (ListView) findViewById(R.id.listView);
28 | mDataSource = new DataSource(this);
29 | mListView.setAdapter(new SampleAdapter());
30 | mListView.setOnItemClickListener(this);
31 | }
32 |
33 | @Override
34 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
35 | DataItem item = (DataItem) mListView.getItemAtPosition(position);
36 |
37 | // if navigation is supported, open the next activity
38 | if (item.getNavigationInfo() != DataSource.NO_NAVIGATION) {
39 | Intent intent = new Intent(this, ListActivity.class);
40 | intent.putExtra(TYPE, item.getNavigationInfo());
41 | startActivity(intent);
42 | }
43 | }
44 |
45 | private class SampleAdapter extends BaseAdapter {
46 |
47 | @Override
48 | public int getCount() {
49 | return mDataSource.getCount();
50 | }
51 |
52 | @Override
53 | public DataItem getItem(int position) {
54 | return mDataSource.getItem(position);
55 | }
56 |
57 | @Override
58 | public long getItemId(int position) {
59 | return position;
60 | }
61 |
62 | @Override
63 | public View getView(int position, View convertView, ViewGroup parent) {
64 | ViewHolder holder;
65 | if (convertView == null) {
66 | convertView = View.inflate(MainActivity.this, R.layout.list_item_layout, null);
67 | holder = new ViewHolder(convertView);
68 | convertView.setTag(holder);
69 | } else {
70 | holder = (ViewHolder) convertView.getTag();
71 | }
72 |
73 | DataItem item = getItem(position);
74 |
75 | final Drawable drawable = item.getDrawable();
76 | holder.imageView.setImageDrawable(drawable);
77 | holder.textView.setText(item.getLabel());
78 |
79 | // if navigation is supported, show the ">" navigation icon
80 | if (item.getNavigationInfo() != DataSource.NO_NAVIGATION) {
81 | holder.textView.setCompoundDrawablesWithIntrinsicBounds(null,
82 | null,
83 | getResources().getDrawable(R.drawable.ic_action_next_item),
84 | null);
85 | }
86 | else {
87 | holder.textView.setCompoundDrawablesWithIntrinsicBounds(null,
88 | null,
89 | null,
90 | null);
91 | }
92 |
93 | // fix for animation not playing for some below 4.4 devices
94 | if (drawable instanceof AnimationDrawable) {
95 | holder.imageView.post(new Runnable() {
96 | @Override
97 | public void run() {
98 | ((AnimationDrawable) drawable).stop();
99 | ((AnimationDrawable) drawable).start();
100 | }
101 | });
102 | }
103 |
104 | return convertView;
105 | }
106 | }
107 |
108 | private static class ViewHolder {
109 |
110 | private ImageView imageView;
111 |
112 | private TextView textView;
113 |
114 | private ViewHolder(View view) {
115 | imageView = (ImageView) view.findViewById(R.id.imageView);
116 | textView = (TextView) view.findViewById(R.id.textView);
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/amulyakhare/td/sample/sample/DataItem.java:
--------------------------------------------------------------------------------
1 | package com.amulyakhare.td.sample.sample;
2 |
3 | import android.graphics.drawable.Drawable;
4 |
5 | /**
6 | * @author amulya
7 | * @datetime 17 Oct 2014, 3:50 PM
8 | */
9 | public class DataItem {
10 |
11 | private String label;
12 |
13 | private Drawable drawable;
14 |
15 | private int navigationInfo;
16 |
17 | public DataItem(String label, Drawable drawable, int navigationInfo) {
18 | this.label = label;
19 | this.drawable = drawable;
20 | this.navigationInfo = navigationInfo;
21 | }
22 |
23 | public String getLabel() {
24 | return label;
25 | }
26 |
27 | public Drawable getDrawable() {
28 | return drawable;
29 | }
30 |
31 | public int getNavigationInfo() {
32 | return navigationInfo;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/amulyakhare/td/sample/sample/DataSource.java:
--------------------------------------------------------------------------------
1 | package com.amulyakhare.td.sample.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 |
6 | import java.util.ArrayList;
7 |
8 | /**
9 | * @author amulya
10 | * @datetime 17 Oct 2014, 3:49 PM
11 | */
12 | public class DataSource {
13 |
14 | public static final int NO_NAVIGATION = -1;
15 |
16 | private ArrayList mDataSource;
17 | private DrawableProvider mProvider;
18 |
19 | public DataSource(Context context) {
20 | mProvider = new DrawableProvider(context);
21 | mDataSource = new ArrayList();
22 | mDataSource.add(itemFromType(DrawableProvider.SAMPLE_RECT));
23 | mDataSource.add(itemFromType(DrawableProvider.SAMPLE_ROUND_RECT));
24 | mDataSource.add(itemFromType(DrawableProvider.SAMPLE_ROUND));
25 | mDataSource.add(itemFromType(DrawableProvider.SAMPLE_RECT_BORDER));
26 | mDataSource.add(itemFromType(DrawableProvider.SAMPLE_ROUND_RECT_BORDER));
27 | mDataSource.add(itemFromType(DrawableProvider.SAMPLE_ROUND_BORDER));
28 | mDataSource.add(itemFromType(DrawableProvider.SAMPLE_MULTIPLE_LETTERS));
29 | mDataSource.add(itemFromType(DrawableProvider.SAMPLE_FONT));
30 | mDataSource.add(itemFromType(DrawableProvider.SAMPLE_SIZE));
31 | mDataSource.add(itemFromType(DrawableProvider.SAMPLE_ANIMATION));
32 | mDataSource.add(itemFromType(DrawableProvider.SAMPLE_MISC));
33 | }
34 |
35 | public int getCount() {
36 | return mDataSource.size();
37 | }
38 |
39 | public DataItem getItem(int position) {
40 | return mDataSource.get(position);
41 | }
42 |
43 | private DataItem itemFromType(int type) {
44 | String label = null;
45 | Drawable drawable = null;
46 | switch (type) {
47 | case DrawableProvider.SAMPLE_RECT:
48 | label = "Rectangle with Text";
49 | drawable = mProvider.getRect("A");
50 | break;
51 | case DrawableProvider.SAMPLE_ROUND_RECT:
52 | label = "Round Corner with Text";
53 | drawable = mProvider.getRoundRect("B");
54 | break;
55 | case DrawableProvider.SAMPLE_ROUND:
56 | label = "Round with Text";
57 | drawable = mProvider.getRound("C");
58 | break;
59 | case DrawableProvider.SAMPLE_RECT_BORDER:
60 | label = "Rectangle with Border";
61 | drawable = mProvider.getRectWithBorder("D");
62 | break;
63 | case DrawableProvider.SAMPLE_ROUND_RECT_BORDER:
64 | label = "Round Corner with Border";
65 | drawable = mProvider.getRoundRectWithBorder("E");
66 | break;
67 | case DrawableProvider.SAMPLE_ROUND_BORDER:
68 | label = "Round with Border";
69 | drawable = mProvider.getRoundWithBorder("F");
70 | break;
71 | case DrawableProvider.SAMPLE_MULTIPLE_LETTERS:
72 | label = "Support multiple letters";
73 | drawable = mProvider.getRectWithMultiLetter();
74 | type = NO_NAVIGATION;
75 | break;
76 | case DrawableProvider.SAMPLE_FONT:
77 | label = "Support variable font styles";
78 | drawable = mProvider.getRoundWithCustomFont();
79 | type = NO_NAVIGATION;
80 | break;
81 | case DrawableProvider.SAMPLE_SIZE:
82 | label = "Support for custom size";
83 | drawable = mProvider.getRectWithCustomSize();
84 | type = NO_NAVIGATION;
85 | break;
86 | case DrawableProvider.SAMPLE_ANIMATION:
87 | label = "Support for animations";
88 | drawable = mProvider.getRectWithAnimation();
89 | type = NO_NAVIGATION;
90 | break;
91 | case DrawableProvider.SAMPLE_MISC:
92 | label = "Miscellaneous";
93 | drawable = mProvider.getRect("\u03c0");
94 | type = NO_NAVIGATION;
95 | break;
96 | }
97 | return new DataItem(label, drawable, type);
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/amulyakhare/td/sample/sample/DrawableProvider.java:
--------------------------------------------------------------------------------
1 | package com.amulyakhare.td.sample.sample;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.graphics.Color;
6 | import android.graphics.Typeface;
7 | import android.graphics.drawable.AnimationDrawable;
8 | import android.graphics.drawable.Drawable;
9 | import android.graphics.drawable.InsetDrawable;
10 | import android.graphics.drawable.LayerDrawable;
11 | import android.util.TypedValue;
12 |
13 | import com.amulyakhare.textdrawable.TextDrawable;
14 | import com.amulyakhare.textdrawable.util.ColorGenerator;
15 |
16 | /**
17 | * @author amulya
18 | * @datetime 17 Oct 2014, 4:02 PM
19 | */
20 | public class DrawableProvider {
21 |
22 | public static final int SAMPLE_RECT = 1;
23 | public static final int SAMPLE_ROUND_RECT = 2;
24 | public static final int SAMPLE_ROUND = 3;
25 | public static final int SAMPLE_RECT_BORDER = 4;
26 | public static final int SAMPLE_ROUND_RECT_BORDER = 5;
27 | public static final int SAMPLE_ROUND_BORDER = 6;
28 | public static final int SAMPLE_MULTIPLE_LETTERS = 7;
29 | public static final int SAMPLE_FONT = 8;
30 | public static final int SAMPLE_SIZE = 9;
31 | public static final int SAMPLE_ANIMATION = 10;
32 | public static final int SAMPLE_MISC = 11;
33 |
34 | private final ColorGenerator mGenerator;
35 | private final Context mContext;
36 |
37 | public DrawableProvider(Context context) {
38 | mGenerator = ColorGenerator.DEFAULT;
39 | mContext = context;
40 | }
41 |
42 | public TextDrawable getRect(String text) {
43 | return TextDrawable.builder()
44 | .buildRect(text, mGenerator.getColor(text));
45 | }
46 |
47 | public TextDrawable getRound(String text) {
48 | return TextDrawable.builder()
49 | .buildRound(text, mGenerator.getColor(text));
50 | }
51 |
52 | public TextDrawable getRoundRect(String text) {
53 | return TextDrawable.builder()
54 | .buildRoundRect(text, mGenerator.getColor(text), toPx(10));
55 | }
56 |
57 | public TextDrawable getRectWithBorder(String text) {
58 | return TextDrawable.builder()
59 | .beginConfig()
60 | .withBorder(toPx(2))
61 | .endConfig()
62 | .buildRect(text, mGenerator.getColor(text));
63 | }
64 |
65 | public TextDrawable getRoundWithBorder(String text) {
66 | return TextDrawable.builder()
67 | .beginConfig()
68 | .withBorder(toPx(2))
69 | .endConfig()
70 | .buildRound(text, mGenerator.getColor(text));
71 | }
72 |
73 | public TextDrawable getRoundRectWithBorder(String text) {
74 | return TextDrawable.builder()
75 | .beginConfig()
76 | .withBorder(toPx(2))
77 | .endConfig()
78 | .buildRoundRect(text, mGenerator.getColor(text), toPx(10));
79 | }
80 |
81 | public TextDrawable getRectWithMultiLetter() {
82 | String text = "AK";
83 | return TextDrawable.builder()
84 | .beginConfig()
85 | .fontSize(toPx(20))
86 | .toUpperCase()
87 | .endConfig()
88 | .buildRect(text, mGenerator.getColor(text));
89 | }
90 |
91 | public TextDrawable getRoundWithCustomFont() {
92 | String text = "Bold";
93 | return TextDrawable.builder()
94 | .beginConfig()
95 | .useFont(Typeface.DEFAULT)
96 | .fontSize(toPx(15))
97 | .textColor(0xfff58559)
98 | .bold()
99 | .endConfig()
100 | .buildRect(text, Color.DKGRAY /*toPx(5)*/);
101 | }
102 |
103 | public Drawable getRectWithCustomSize() {
104 | String leftText = "I";
105 | String rightText = "J";
106 |
107 | TextDrawable.IBuilder builder = TextDrawable.builder()
108 | .beginConfig()
109 | .width(toPx(29))
110 | .withBorder(toPx(2))
111 | .endConfig()
112 | .rect();
113 |
114 | TextDrawable left = builder
115 | .build(leftText, mGenerator.getColor(leftText));
116 |
117 | TextDrawable right = builder
118 | .build(rightText, mGenerator.getColor(rightText));
119 |
120 | Drawable[] layerList = {
121 | new InsetDrawable(left, 0, 0, toPx(31), 0),
122 | new InsetDrawable(right, toPx(31), 0, 0, 0)
123 | };
124 | return new LayerDrawable(layerList);
125 | }
126 |
127 | public Drawable getRectWithAnimation() {
128 | TextDrawable.IBuilder builder = TextDrawable.builder()
129 | .rect();
130 |
131 | AnimationDrawable animationDrawable = new AnimationDrawable();
132 | for (int i = 10; i > 0; i--) {
133 | TextDrawable frame = builder.build(String.valueOf(i), mGenerator.getRandomColor());
134 | animationDrawable.addFrame(frame, 1200);
135 | }
136 | animationDrawable.setOneShot(false);
137 | animationDrawable.start();
138 |
139 | return animationDrawable;
140 | }
141 |
142 | public int toPx(int dp) {
143 | Resources resources = mContext.getResources();
144 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/check_alpha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-hdpi/check_alpha.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/check_sm.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-hdpi/check_sm.9.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/check_sm1.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-hdpi/check_sm1.9.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/ic_action_next_item.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-hdpi/ic_action_next_item.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-ldpi/check_sm.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-ldpi/check_sm.9.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-mdpi/check_sm.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-mdpi/check_sm.9.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-mdpi/ic_action_next_item.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-mdpi/ic_action_next_item.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/check_sm.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-xhdpi/check_sm.9.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/ic_action_next_item.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-xhdpi/ic_action_next_item.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/check_sm.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-xxhdpi/check_sm.9.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/ic_action_next_item.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-xxhdpi/ic_action_next_item.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/sample/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_check_box.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_list.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/list_item_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
13 |
14 |
18 |
19 |
25 |
26 |
27 |
33 |
34 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/check_box.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/list.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | TextDrawable Sample
5 | Hello world!
6 | Settings
7 | TextDrawable Sample
8 | TextDrawable Sample
9 |
10 |
11 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/screens/screen1-material.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/screens/screen1-material.png
--------------------------------------------------------------------------------
/screens/screen1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/screens/screen1.png
--------------------------------------------------------------------------------
/screens/screen2-material.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/screens/screen2-material.png
--------------------------------------------------------------------------------
/screens/screen2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/screens/screen2.png
--------------------------------------------------------------------------------
/screens/screen3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/screens/screen3.png
--------------------------------------------------------------------------------
/screens/screen4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/screens/screen4.png
--------------------------------------------------------------------------------
/screens/screen5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/screens/screen5.png
--------------------------------------------------------------------------------
/screens/screen6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/screens/screen6.png
--------------------------------------------------------------------------------
/screens/screen7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amulyakhare/TextDrawable/558677ea316e60346948b381e5e274f49b00d370/screens/screen7.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample'
2 |
3 | include 'library'
4 | project(':library').projectDir = new File('library')
5 |
--------------------------------------------------------------------------------