├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── kotlinc.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── art
├── screenshot1.png
├── screenshot2.png
└── screenshot3.png
├── build.gradle
├── example
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── org
│ │ └── fabiomsr
│ │ └── moneytextview
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── org
│ │ │ └── fabiomsr
│ │ │ └── moneytextview
│ │ │ └── example
│ │ │ └── ExampleActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_example.xml
│ │ └── activity_example2.xml
│ │ ├── 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
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── org
│ └── fabiomsr
│ └── moneytextview
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── moneytextview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── publish
│ ├── bintray.gradle
│ ├── config.gradle
│ └── install.gradle
└── src
│ ├── androidTest
│ └── java
│ │ └── org
│ │ └── fabiomsr
│ │ └── library
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── org
│ │ └── fabiomsr
│ │ └── moneytextview
│ │ └── MoneyTextView.java
│ └── res
│ └── values
│ ├── attrs.xml
│ ├── default_style.xml
│ └── strings.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | MoneyTextView
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/misc.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 |
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 | Android API 16 Platform
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [  ](https://bintray.com/fabiomsr/maven/MoneyTextView/_latestVersion)
2 |
3 | [](https://android-arsenal.com/details/1/3835)
4 | [](https://www.codacy.com/app/fabiomarcos-sr/MoneyTextView?utm_source=github.com&utm_medium=referral&utm_content=fabiomsr/MoneyTextView&utm_campaign=Badge_Grade)
5 |
6 | # MoneyTextView
7 |
8 | A custom Android TextView to display amounts of money in different formats.
9 |
10 | Minimum Android SDK supported: 14
11 |
12 | Example 1 | Example 2
13 | ---- | ----
14 |  | 
15 |
16 |
17 | ## Setup
18 |
19 | Provide the gradle dependency:
20 |
21 | ~~~groovy
22 | dependencies {
23 | compile 'org.fabiomsr:moneytextview:1.1.0'
24 | }
25 | ~~~
26 |
27 | ## Usage
28 |
29 | * Include MoneyTextView in a layout xml file:
30 |
31 | ~~~xml
32 |
33 |
39 |
40 | ~~~
41 |
42 | * Include the following code in your Activity in order to update the amount value:
43 |
44 | ~~~java
45 |
46 | moneyTextView.setAmount(156);
47 |
48 | ~~~
49 |
50 | #### More settings example
51 |
52 | ~~~xml
53 |
68 | ~~~
69 |
70 | ## Attributes
71 |
72 | Money text view offers several attributes for a deeper view configuration, the following table shows all these options and their default value.
73 |
74 | | Name | Description | Values | Default |
75 | |:-----------------------:|:-----------------------------------------------------------------------------------------------------------------------------------:|:--------------------:|:----------:|
76 | | format | String containing a DecimalFormat valid format [DecimalFormat] | string | ###,##0.00 |
77 | | amount | Amount of money to be displayed | float | 0 |
78 | | baseTextSize | Text size, if neither of decimalDigitsTextSize or symbolTextSize are specified this attribute will effect the whole text | sp | 18sp |
79 | | baseTextColor | Text size, if neither of decimalTextColor or symbolTextColor are specified this attribute will effect the whole text | color | #000000 |
80 | | gravity | Text relative position inside the view | top,bottom,center... | center |
81 | | symbol | Currency Symbol | string | $ |
82 | | symbolMargin | Separation between the currency symbol and the amount | dp | 2dp |
83 | | symbolTextSize | Currency symbol text size | sp | 18sp |
84 | | symbolGravity | Currency symbol gravity attribute | start,end,top,bottom | top,start |
85 | | symbolTextColor | Currency symbol Color | color | #000000 |
86 | | decimalSeparator | Decimal part separator character | string | ' |
87 | | decimalMargin | Separator between the integer part and the decimal | dp | 2dp |
88 | | decimalDigitsTextSize | Decimal part text size | sp | 18sp |
89 | | decimalGravity | Decimal part gravity attribute | top,bottom | top |
90 | | decimalTextColor | Decimal part color | color | #000000 |
91 | | decimalUnderline | Enables decimal part underlining | boolean | false |
92 | | includeDecimalSeparator | Hides/Shows the decimal part separator | boolean | true |
93 | | fontPath | Path to a custom font | string | |
94 |
95 |
96 |
97 |
98 | License
99 | -------
100 |
101 | Copyright 2016 Fabio Santana (fabiomsr)
102 |
103 | Licensed under the Apache License, Version 2.0 (the "License");
104 | you may not use this file except in compliance with the License.
105 | You may obtain a copy of the License at
106 |
107 | http://www.apache.org/licenses/LICENSE-2.0
108 |
109 | Unless required by applicable law or agreed to in writing, software
110 | distributed under the License is distributed on an "AS IS" BASIS,
111 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
112 | See the License for the specific language governing permissions and
113 | limitations under the License.
114 |
115 | [DecimalFormat]:https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html
116 |
--------------------------------------------------------------------------------
/art/screenshot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fabiomsr/MoneyTextView/c5beb6042daeeab9975800c461859483512d254c/art/screenshot1.png
--------------------------------------------------------------------------------
/art/screenshot2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fabiomsr/MoneyTextView/c5beb6042daeeab9975800c461859483512d254c/art/screenshot2.png
--------------------------------------------------------------------------------
/art/screenshot3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fabiomsr/MoneyTextView/c5beb6042daeeab9975800c461859483512d254c/art/screenshot3.png
--------------------------------------------------------------------------------
/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:2.3.0'
9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4'
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 |
21 |
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | applicationId "org.fabiomsr.moneytextview.example"
9 | minSdkVersion 15
10 | targetSdkVersion 25
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(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:25.1.0'
26 |
27 | compile project(':moneytextview')
28 | }
29 |
--------------------------------------------------------------------------------
/example/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 /Users/fabio/Library/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 |
--------------------------------------------------------------------------------
/example/src/androidTest/java/org/fabiomsr/moneytextview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package org.fabiomsr.moneytextview;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/example/src/main/java/org/fabiomsr/moneytextview/example/ExampleActivity.java:
--------------------------------------------------------------------------------
1 | package org.fabiomsr.moneytextview.example;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 |
7 | public class ExampleActivity extends AppCompatActivity {
8 |
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_example);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_example.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
29 |
30 |
45 |
46 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_example2.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
28 |
29 |
40 |
41 |
52 |
53 |
65 |
66 |
75 |
76 |
88 |
89 |
101 |
102 |
103 |
104 |
110 |
111 |
121 |
122 |
133 |
134 |
145 |
146 |
158 |
159 |
168 |
169 |
182 |
183 |
195 |
196 |
197 |
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fabiomsr/MoneyTextView/c5beb6042daeeab9975800c461859483512d254c/example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fabiomsr/MoneyTextView/c5beb6042daeeab9975800c461859483512d254c/example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fabiomsr/MoneyTextView/c5beb6042daeeab9975800c461859483512d254c/example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fabiomsr/MoneyTextView/c5beb6042daeeab9975800c461859483512d254c/example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fabiomsr/MoneyTextView/c5beb6042daeeab9975800c461859483512d254c/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #333333
4 | #333333
5 | #FF4081
6 |
7 | #E21B5A
8 | #FBFFE3
9 |
10 |
--------------------------------------------------------------------------------
/example/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MoneyTextView
3 |
4 |
--------------------------------------------------------------------------------
/example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
14 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/example/src/test/java/org/fabiomsr/moneytextview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package org.fabiomsr.moneytextview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fabiomsr/MoneyTextView/c5beb6042daeeab9975800c461859483512d254c/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Mar 07 20:56:22 CET 2017
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-3.3-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 | # 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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/moneytextview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/moneytextview/build.gradle:
--------------------------------------------------------------------------------
1 |
2 | apply plugin: 'com.android.library'
3 |
4 |
5 |
6 |
7 | android {
8 | compileSdkVersion 25
9 | buildToolsVersion "25.0.2"
10 |
11 | defaultConfig {
12 | minSdkVersion 14
13 | targetSdkVersion 25
14 | versionCode 3
15 | versionName "1.1.0"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 |
28 | }
29 |
30 | apply from: 'publish/config.gradle'
31 | apply from: 'publish/install.gradle'
32 | apply from: 'publish/bintray.gradle'
33 |
--------------------------------------------------------------------------------
/moneytextview/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 /Users/fabio/Library/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 |
--------------------------------------------------------------------------------
/moneytextview/publish/bintray.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.jfrog.bintray'
2 |
3 | version = libraryVersion
4 |
5 | if (project.hasProperty("android")) { // Android libraries
6 | task sourcesJar(type: Jar) {
7 | classifier = 'sources'
8 | from android.sourceSets.main.java.srcDirs
9 | }
10 |
11 | task javadoc(type: Javadoc) {
12 | source = android.sourceSets.main.java.srcDirs
13 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
14 | }
15 | } else { // Java libraries
16 | task sourcesJar(type: Jar, dependsOn: classes) {
17 | classifier = 'sources'
18 | from sourceSets.main.allSource
19 | }
20 | }
21 |
22 | task javadocJar(type: Jar, dependsOn: javadoc) {
23 | classifier = 'javadoc'
24 | from javadoc.destinationDir
25 | }
26 |
27 | artifacts {
28 | archives javadocJar
29 | archives sourcesJar
30 | }
31 |
32 |
33 | bintray {
34 | user = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
35 | key = project.hasProperty('BINTRAY_API_KEY') ? project.property('BINTRAY_API_KEY') : System.getenv('BINTRAY_API_KEY')
36 |
37 |
38 | configurations = ['archives']
39 | pkg {
40 | repo = bintrayRepo
41 | name = bintrayName
42 | desc = libraryDescription
43 | websiteUrl = siteUrl
44 | vcsUrl = gitUrl
45 | licenses = allLicenses
46 | publish = true
47 | publicDownloadNumbers = true
48 | version {
49 | desc = libraryDescription
50 | gpg {
51 | sign = true
52 | passphrase = project.hasProperty('BINTRAY_GPG') ? project.property('BINTRAY_GPG') : System.getenv('BINTRAY_GPG')
53 | }
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/moneytextview/publish/config.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | bintrayRepo = 'maven'
3 | bintrayName = 'MoneyTextView'
4 |
5 | publishedGroupId = 'org.fabiomsr'
6 | libraryName = 'MoneyTextView'
7 | artifact = 'moneytextview'
8 |
9 | libraryDescription = 'A custom Android TextView to display amounts of money in different formats'
10 |
11 | siteUrl = 'https://github.com/fabiomsr/MoneyTextView'
12 | gitUrl = 'https://github.com/fabiomsr/MoneyTextView.git'
13 |
14 | libraryVersion = '1.1.0'
15 |
16 | developerId = project.property('DEVELOPER_ID')
17 | developerName = project.property('DEVELOPER_NAME')
18 | developerEmail = project.property('DEVELOPER_EMAIL')
19 |
20 | licenseName = 'The Apache Software License, Version 2.0'
21 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
22 | allLicenses = ["Apache-2.0"]
23 | }
--------------------------------------------------------------------------------
/moneytextview/publish/install.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.github.dcendents.android-maven'
2 |
3 | group = publishedGroupId // Maven Group ID for the artifact
4 |
5 | install {
6 | repositories.mavenInstaller {
7 | // This generates POM.xml with proper parameters
8 | pom {
9 | project {
10 | packaging 'aar'
11 | groupId publishedGroupId
12 | artifactId artifact
13 |
14 | // Add your description here
15 | name libraryName
16 | description libraryDescription
17 | url siteUrl
18 |
19 | // Set your license
20 | licenses {
21 | license {
22 | name licenseName
23 | url licenseUrl
24 | }
25 | }
26 | developers {
27 | developer {
28 | id developerId
29 | name developerName
30 | email developerEmail
31 | }
32 | }
33 | scm {
34 | connection gitUrl
35 | developerConnection gitUrl
36 | url siteUrl
37 |
38 | }
39 | }
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/moneytextview/src/androidTest/java/org/fabiomsr/library/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package org.fabiomsr.library;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/moneytextview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/moneytextview/src/main/java/org/fabiomsr/moneytextview/MoneyTextView.java:
--------------------------------------------------------------------------------
1 | package org.fabiomsr.moneytextview;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.content.res.TypedArray;
7 | import android.graphics.Canvas;
8 | import android.graphics.Paint;
9 | import android.graphics.Rect;
10 | import android.graphics.Typeface;
11 | import android.os.Build;
12 | import android.text.TextPaint;
13 | import android.text.TextUtils;
14 | import android.util.AttributeSet;
15 | import android.util.TypedValue;
16 | import android.view.View;
17 |
18 | import java.text.DecimalFormat;
19 | import java.text.DecimalFormatSymbols;
20 | import java.util.Locale;
21 |
22 | /**
23 | * Created by Fabiomsr on 20/5/16.
24 | */
25 | public class MoneyTextView extends View {
26 |
27 | private static final int GRAVITY_START = 1;
28 | private static final int GRAVITY_END = 2;
29 | private static final int GRAVITY_TOP = 4;
30 | private static final int GRAVITY_BOTTOM = 8;
31 | private static final int GRAVITY_CENTER_VERTICAL = 16;
32 | private static final int GRAVITY_CENTER_HORIZONTAL = 32;
33 | private static final float MIN_PADDING = 2;
34 |
35 | private TextPaint mTextPaint;
36 | private DecimalFormat mDecimalFormat;
37 | private Section mSymbolSection;
38 | private Section mIntegerSection;
39 | private Section mDecimalSection;
40 | private char mDecimalSeparator;
41 | private float mAmount;
42 | private int mGravity;
43 | private int mSymbolGravity;
44 | private int mDecimalGravity;
45 | private float mSymbolMargin;
46 | private float mDecimalMargin;
47 | private boolean mIncludeDecimalSeparator;
48 | private int mWidth;
49 | private int mHeight;
50 | private float mTextPaintRoomSize;
51 |
52 | public MoneyTextView(Context context) {
53 | super(context);
54 | init(context, null);
55 | }
56 |
57 | public MoneyTextView(Context context, AttributeSet attrs) {
58 | super(context, attrs);
59 | init(context, attrs);
60 | }
61 |
62 | public MoneyTextView(Context context, AttributeSet attrs, int defStyleAttr) {
63 | super(context, attrs, defStyleAttr);
64 | init(context, attrs);
65 | }
66 |
67 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
68 | public MoneyTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
69 | super(context, attrs, defStyleAttr, defStyleRes);
70 | init(context, attrs);
71 | }
72 |
73 |
74 | private void init(Context context, AttributeSet attrs) {
75 |
76 | mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
77 | mSymbolSection = new Section();
78 | mIntegerSection = new Section();
79 | mDecimalSection = new Section();
80 |
81 | Resources r = getResources();
82 | mTextPaintRoomSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTextPaint.density, r.getDisplayMetrics());
83 |
84 | TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MoneyTextView,
85 | 0, R.style.MoneyTextViewDefaultStyle);
86 |
87 |
88 | try {
89 | mSymbolSection.text = typedArray.getString(R.styleable.MoneyTextView_symbol);
90 | mAmount = typedArray.getFloat(R.styleable.MoneyTextView_amount, 0);
91 | mGravity = typedArray.getInt(R.styleable.MoneyTextView_gravity, GRAVITY_CENTER_VERTICAL | GRAVITY_CENTER_HORIZONTAL);
92 | mSymbolGravity = typedArray.getInt(R.styleable.MoneyTextView_symbolGravity, GRAVITY_TOP | GRAVITY_START);
93 | mDecimalGravity = typedArray.getInt(R.styleable.MoneyTextView_decimalGravity, GRAVITY_TOP);
94 | mIncludeDecimalSeparator = typedArray.getBoolean(R.styleable.MoneyTextView_includeDecimalSeparator, true);
95 | mSymbolMargin = typedArray.getDimensionPixelSize(R.styleable.MoneyTextView_symbolMargin, 0);
96 | mDecimalMargin = typedArray.getDimensionPixelSize(R.styleable.MoneyTextView_decimalMargin, 0);
97 | mIntegerSection.textSize = typedArray.getDimension(R.styleable.MoneyTextView_baseTextSize, 12f);
98 | mSymbolSection.textSize = typedArray.getDimension(R.styleable.MoneyTextView_symbolTextSize, mIntegerSection.textSize);
99 | mDecimalSection.textSize = typedArray.getDimension(R.styleable.MoneyTextView_decimalDigitsTextSize, mIntegerSection.textSize);
100 | mIntegerSection.color = typedArray.getInt(R.styleable.MoneyTextView_baseTextColor, 0);
101 | mSymbolSection.color = typedArray.getInt(R.styleable.MoneyTextView_symbolTextColor, mIntegerSection.color);
102 | mDecimalSection.color = typedArray.getInt(R.styleable.MoneyTextView_decimalTextColor, mIntegerSection.color);
103 | mDecimalSection.drawUnderline = typedArray.getBoolean(R.styleable.MoneyTextView_decimalUnderline, false);
104 |
105 | String format = typedArray.getString(R.styleable.MoneyTextView_format);
106 | String decimalSeparator = typedArray.getString(R.styleable.MoneyTextView_decimalSeparator);
107 | String fontPath = typedArray.getString(R.styleable.MoneyTextView_fontPath);
108 | if (fontPath != null) {
109 | Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontPath);
110 | mTextPaint.setTypeface(typeface);
111 | }
112 |
113 | if (format == null) {
114 | format = context.getString(R.string.default_format);
115 | }
116 |
117 | mDecimalFormat = new DecimalFormat(format);
118 | DecimalFormatSymbols decimalFormatSymbol = new DecimalFormatSymbols(Locale.getDefault());
119 |
120 | if (!TextUtils.isEmpty(decimalSeparator)) {
121 | mDecimalSeparator = decimalSeparator.charAt(0);
122 | } else {
123 | mDecimalSeparator = context.getString(R.string.default_decimal_separator).charAt(0);
124 | }
125 |
126 | decimalFormatSymbol.setDecimalSeparator(mDecimalSeparator);
127 | mDecimalFormat.setDecimalFormatSymbols(decimalFormatSymbol);
128 |
129 | setAmount(mAmount);
130 | } finally {
131 | typedArray.recycle();
132 | }
133 | }
134 |
135 | @Override
136 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
137 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
138 |
139 | setPadding(getMinPadding(getPaddingLeft()), getMinVerticalPadding(getPaddingTop()),
140 | getMinPadding(getPaddingRight()), getMinVerticalPadding(getPaddingBottom()));
141 |
142 | createTextFromAmount();
143 | calculateBounds(widthMeasureSpec, heightMeasureSpec);
144 | calculatePositions();
145 | setMeasuredDimension(mWidth, mHeight);
146 | }
147 |
148 | public void setAmount(float amount) {
149 | mAmount = amount;
150 | requestLayout();
151 | }
152 |
153 | private void createTextFromAmount() {
154 | String formattedAmount = mDecimalFormat.format(mAmount);
155 |
156 | int separatorIndex = formattedAmount.lastIndexOf(mDecimalSeparator);
157 |
158 | if (separatorIndex > -1) {
159 | mIntegerSection.text = formattedAmount.substring(0, separatorIndex);
160 | mDecimalSection.text = formattedAmount.substring(mIncludeDecimalSeparator ? separatorIndex :
161 | separatorIndex + 1);
162 | } else {
163 | mIntegerSection.text = formattedAmount;
164 | mDecimalSection.text = "";
165 | }
166 | }
167 |
168 | private void calculateBounds(int widthMeasureSpec, int heightMeasureSpec) {
169 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
170 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
171 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
172 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
173 |
174 | mSymbolSection.calculateBounds(mTextPaint);
175 | mIntegerSection.calculateBounds(mTextPaint);
176 | mDecimalSection.calculateBounds(mTextPaint);
177 |
178 | mDecimalSection.calculateNumbersHeight(mTextPaint);
179 | mIntegerSection.calculateNumbersHeight(mTextPaint);
180 |
181 |
182 | switch (widthMode) {
183 | case MeasureSpec.EXACTLY:
184 | mWidth = widthSize;
185 | break;
186 | case MeasureSpec.AT_MOST:
187 | case MeasureSpec.UNSPECIFIED:
188 | mWidth = (int) (mIntegerSection.width + mDecimalSection.width + mSymbolSection.width
189 | + mSymbolMargin + mDecimalMargin + getPaddingLeft() + getPaddingRight());
190 | break;
191 | default:break;
192 | }
193 |
194 | switch (heightMode) {
195 | case MeasureSpec.EXACTLY:
196 | mHeight = heightSize;
197 | break;
198 | case MeasureSpec.AT_MOST:
199 | case MeasureSpec.UNSPECIFIED:
200 | mHeight = getPaddingTop() + getPaddingBottom()
201 | + Math.max(mIntegerSection.height, Math.max(mDecimalSection.height, mSymbolSection.height));
202 | break;
203 | default:break;
204 | }
205 | }
206 |
207 | private void calculatePositions() {
208 | int symbolGravityXAxis = mSymbolGravity & GRAVITY_START;
209 | int symbolGravityYAxis = mSymbolGravity & GRAVITY_TOP;
210 | int fromY;
211 | int fromX;
212 | int width = (int) (mIntegerSection.width + mDecimalSection.width + mSymbolSection.width
213 | + mSymbolMargin + mDecimalMargin);
214 |
215 | if ((mGravity & GRAVITY_START) == GRAVITY_START) {
216 | fromX = getPaddingLeft();
217 | } else if ((mGravity & GRAVITY_END) == GRAVITY_END) {
218 | fromX = mWidth - width - getPaddingRight();
219 | } else {
220 | fromX = (mWidth >> 1) - (width >> 1);
221 | }
222 |
223 | if ((mGravity & GRAVITY_TOP) == GRAVITY_TOP) {
224 | fromY = getPaddingTop() + mIntegerSection.height;
225 | } else if ((mGravity & GRAVITY_BOTTOM) == GRAVITY_BOTTOM) {
226 | fromY = mHeight - getPaddingBottom();
227 | } else {
228 | fromY = (mHeight >> 1) + (mIntegerSection.height >> 1);
229 | }
230 |
231 | calculateY(fromY, symbolGravityYAxis);
232 | calculateX(fromX, symbolGravityXAxis);
233 | }
234 |
235 |
236 | private void calculateY(int from, int symbolGravityYAxis) {
237 | mIntegerSection.y = from;
238 | mSymbolSection.y = from - (symbolGravityYAxis == GRAVITY_TOP ?
239 | mIntegerSection.height - mSymbolSection.height + mSymbolSection.bounds.bottom : 0);
240 | mDecimalSection.y = from - (mDecimalGravity == GRAVITY_TOP ?
241 | mIntegerSection.height - mDecimalSection.height : 0);
242 | }
243 |
244 | private void calculateX(int from, int symbolGravityXAxis) {
245 | if (symbolGravityXAxis == GRAVITY_START) {
246 | mSymbolSection.x = from;
247 | mIntegerSection.x = (int) (mSymbolSection.x + mSymbolSection.width + mSymbolMargin);
248 | mDecimalSection.x = (int) (mIntegerSection.x + mIntegerSection.width + mDecimalMargin);
249 | } else {
250 | mIntegerSection.x = from;
251 | mDecimalSection.x = (int) (mIntegerSection.x + mIntegerSection.width + mDecimalMargin);
252 | mSymbolSection.x = (int) (mDecimalSection.x + mDecimalSection.width + mSymbolMargin);
253 | }
254 | }
255 |
256 |
257 | @Override
258 | public void draw(Canvas canvas) {
259 | super.draw(canvas);
260 |
261 | drawSection(canvas, mIntegerSection);
262 | drawSection(canvas, mDecimalSection);
263 | drawSection(canvas, mSymbolSection);
264 | }
265 |
266 |
267 | private void drawSection(Canvas canvas, Section section) {
268 | mTextPaint.setTextSize(section.textSize);
269 | mTextPaint.setColor(section.color);
270 | mTextPaint.setUnderlineText(section.drawUnderline);
271 |
272 | canvas.drawText(section.text, section.x - mTextPaintRoomSize*2, section.y-mTextPaintRoomSize/2, mTextPaint);
273 | }
274 |
275 |
276 | ///
277 | /// SETTERS
278 | ///
279 |
280 | public void setAmount(float amount, String symbol) {
281 | mAmount = amount;
282 | mSymbolSection.text = symbol;
283 | requestLayout();
284 | }
285 |
286 | public void setDecimalFormat(DecimalFormat decimalFormat) {
287 | mDecimalFormat = decimalFormat;
288 | requestLayout();
289 | }
290 |
291 | public void setDecimalSeparator(char decimalSeparator) {
292 | mDecimalSeparator = decimalSeparator;
293 | requestLayout();
294 | }
295 |
296 | public void setSymbolMargin(float symbolMargin) {
297 | mSymbolMargin = symbolMargin;
298 | requestLayout();
299 | }
300 |
301 | public void setDecimalMargin(float decimalMargin) {
302 | mDecimalMargin = decimalMargin;
303 | requestLayout();
304 | }
305 |
306 | public void setIncludeDecimalSeparator(boolean includeDecimalSeparator) {
307 | mIncludeDecimalSeparator = includeDecimalSeparator;
308 | requestLayout();
309 | }
310 |
311 | public void setBaseTextSize(float textSize) {
312 | mIntegerSection.textSize = textSize;
313 | requestLayout();
314 | }
315 |
316 | public void setSymbol(String symbol) {
317 | mSymbolSection.text = symbol;
318 | requestLayout();
319 | }
320 |
321 | public void setSymbolTextSize(float textSize) {
322 | mSymbolSection.textSize = textSize;
323 | requestLayout();
324 | }
325 |
326 | public void setDecimalsTextSize(float textSize) {
327 | mDecimalSection.textSize = textSize;
328 | requestLayout();
329 | }
330 |
331 | public void setBaseColor(int color) {
332 | mIntegerSection.color = color;
333 | invalidate();
334 | }
335 |
336 | public void setSymbolColor(int color) {
337 | mSymbolSection.color = color;
338 | invalidate();
339 | }
340 |
341 | public void setDecimalsColor(int color) {
342 | mDecimalSection.color = color;
343 | invalidate();
344 | }
345 |
346 | public float getAmount() {
347 | return mAmount;
348 | }
349 |
350 | private int getMinPadding(int padding) {
351 | if(padding == 0){
352 | return (int) (MIN_PADDING * Resources.getSystem().getDisplayMetrics().density);
353 | }
354 |
355 | return padding;
356 | }
357 |
358 | private int getMinVerticalPadding(int padding){
359 |
360 | float maxTextSize = Math.max(mIntegerSection.textSize, mDecimalSection.textSize);
361 | mTextPaint.setTextSize(maxTextSize);
362 | float maximumDistanceLowestGlyph = mTextPaint.getFontMetrics().bottom;
363 |
364 | if(padding < maximumDistanceLowestGlyph) {
365 | return (int) maximumDistanceLowestGlyph;
366 | }
367 |
368 | return padding;
369 | }
370 |
371 | private static class Section {
372 | public int x;
373 | public int y;
374 | public Rect bounds;
375 | public String text;
376 | public float textSize;
377 | public int color;
378 | public int width;
379 | public int height;
380 | public boolean drawUnderline;
381 |
382 | public Section() {
383 | bounds = new Rect();
384 | }
385 |
386 | public void calculateBounds(TextPaint paint) {
387 | paint.setTextSize(textSize);
388 | paint.getTextBounds(text, 0, text.length(), bounds);
389 | width = bounds.width();
390 | height = bounds.height();
391 | }
392 |
393 | public void calculateNumbersHeight(TextPaint paint) {
394 | String numbers = text.replaceAll("[^0-9]", "");
395 | paint.setTextSize(textSize);
396 | paint.getTextBounds(numbers, 0, numbers.length(), bounds);
397 | height = bounds.height();
398 | }
399 | }
400 |
401 | }
402 |
--------------------------------------------------------------------------------
/moneytextview/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 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/moneytextview/src/main/res/values/default_style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
17 |
22 |
23 |
26 |
27 |
28 |
29 |
33 |
34 |
38 |
39 |
40 |
41 |
45 |
46 |
50 |
51 |
52 |
53 |
57 |
58 |
62 |
63 |
64 |
65 |
68 |
69 |
72 |
73 |
74 |
80 |
81 |
84 |
85 |
88 |
89 |
92 |
--------------------------------------------------------------------------------
/moneytextview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ###,##0.00
3 | \'
4 |
5 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':example', ':moneytextview'
2 |
--------------------------------------------------------------------------------