57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/muddzdev/styleabletoast/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.muddzdev.styleabletoast;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.Typeface;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.Toast;
9 |
10 | import com.muddzdev.styleabletoastlibrary.StyleableToast;
11 |
12 | public class MainActivity extends AppCompatActivity {
13 | StyleableToast st;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 |
20 | }
21 |
22 |
23 | public void Toaster(View v) {
24 |
25 | switch (v.getId()) {
26 | case R.id.button1:
27 |
28 | st = new StyleableToast(this, "Updating profile", Toast.LENGTH_LONG);
29 | st.setBackgroundColor(Color.parseColor("#ff5a5f"));
30 | st.setTextColor(Color.WHITE);
31 | st.setIcon(R.drawable.ic_autorenew_black_24dp);
32 | st.spinIcon();
33 | st.setMaxAlpha();
34 | st.show();
35 |
36 | break;
37 |
38 | case R.id.button2:
39 |
40 |
41 | st = new StyleableToast(this, "Turn off fly mode", Toast.LENGTH_LONG);
42 | st.setBackgroundColor(Color.parseColor("#865aff"));
43 | st.setTextColor(Color.WHITE);
44 | st.setIcon(R.drawable.ic_airplanemode_inactive_black_24dp);
45 | st.show();
46 |
47 | break;
48 |
49 | case R.id.button3:
50 |
51 |
52 | st = new StyleableToast(this, "Profile saved", Toast.LENGTH_LONG);
53 | st.setBackgroundColor(Color.parseColor("#3b5998"));
54 | st.setMaxAlpha();
55 | st.setTextFont(Typeface.createFromAsset(getAssets(), "fonts/dosis.otf"));
56 | st.show();
57 |
58 |
59 | break;
60 |
61 | case R.id.button4:
62 |
63 | st = new StyleableToast(this.getApplicationContext(), "PHONE IS OVERHEATING!", Toast.LENGTH_LONG);
64 | st.setCornerRadius(5);
65 | st.setBackgroundColor(Color.BLACK);
66 | st.setTextColor(Color.RED);
67 | st.setBoldText();
68 | st.show();
69 |
70 | break;
71 |
72 | case R.id.button5:
73 |
74 | StyleableToast.makeText(this, "Picture saved in gallery", Toast.LENGTH_LONG, R.style.StyleableToast).show();
75 |
76 | break;
77 |
78 | case R.id.button6:
79 |
80 | st = new StyleableToast(this, "Wrong password/username", Toast.LENGTH_LONG);
81 | st.setBackgroundColor(Color.parseColor("#2187c6"));
82 | st.setBoldText();
83 | st.setTextColor(Color.WHITE);
84 | st.setCornerRadius(7);
85 | st.show();
86 | break;
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
19 |
20 |
32 |
33 |
34 |
46 |
47 |
52 |
53 |
54 |
66 |
67 |
79 |
80 |
81 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Android StyleableToast
2 |
3 | An Android library that takes the standard Android Toast and takes it to the next level with a variety of styling options that gives your app and user experience that little extra unique feeling! Style your toast either by code or in styles.xml!
4 |
5 |
6 | Currently used in:
7 | - [Quote Creator] (https://play.google.com/store/apps/details?id=org.m.muddzboy.QuoteCreator&hl=da) with +80.000 downloads!
8 | - [Shoppist] (https://play.google.com/store/apps/details?id=com.muddii.shopping_list&hl=da)
9 |
10 | *Feel free to contact me if you want your app to be included here*
11 |
12 | Download the sample .apk:
13 |
14 |
15 | ## Features
16 |
17 | - Style toasts in a styles.xml or from code.
18 | - Set background color of the toast.
19 | - Set the corner radius of the toast and archive different shapes.
20 | - Set the transparency of your toast to get full solid or transparent toast.
21 | - Set stroke width and color on your toast.
22 | - Style the toast text with a text color or bold.
23 | - Set a new font for the toast text.
24 | - Set a icon beside the toast text.
25 | - Set an spinning animation effect on your icon (see below example)
26 | - Works from Api 16+
27 |
28 | ## CASES:
29 | 
30 |
31 | ## With spinIcon(); method:
32 | 
33 |
34 |
35 | ## Usage with a style resource:
36 |
37 |
38 | **1) Style your toast in styles.xml. All available attributes:**
39 | ```xml
40 |
53 | ```
54 |
55 | **2) Pass your style resource in the constructor and call show(); and you're done!**
56 |
57 | ```java
58 | StyleableToast.makeText(context, "Saving profile", Toast.LENGTH_LONG, R.style.StyledToast).show();
59 | ```
60 | ## Usage with by code:
61 | ```java
62 | StyleableToast st = new StyleableToast(this, "Updating profile", Toast.LENGTH_SHORT);
63 | st.setBackgroundColor(Color.parseColor("#ff5a5f"));
64 | st.setTextColor(Color.WHITE);
65 | st.setIcon(R.drawable.ic_autorenew_black_24dp);
66 | st.spinIconAnimation();
67 | st.setMaxAlpha();
68 | st.show();
69 | ```
70 | -----
71 |
72 | ## Installation
73 |
74 | Add the depedency in your build.gradle. The library is distributed via jCenter
75 |
76 | ```groovy
77 | dependencies {
78 | compile 'com.muddzdev:styleabletoast:1.0.5'
79 | }
80 | ```
81 | ----
82 |
83 | ## License
84 |
85 | Copyright 2017 Muddii Walid (Muddz)
86 |
87 | Licensed under the Apache License, Version 2.0 (the "License");
88 | you may not use this file except in compliance with the License.
89 | You may obtain a copy of the License at
90 |
91 | http://www.apache.org/licenses/LICENSE-2.0
92 |
93 | Unless required by applicable law or agreed to in writing, software
94 | distributed under the License is distributed on an "AS IS" BASIS,
95 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96 | See the License for the specific language governing permissions and
97 | limitations under the License.
98 |
--------------------------------------------------------------------------------
/styleabletoast/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: "com.jfrog.bintray"
4 |
5 | version = "1.0.5"
6 |
7 | android {
8 | compileSdkVersion 25
9 | buildToolsVersion "25.0.2"
10 |
11 | defaultConfig {
12 | minSdkVersion 16
13 | targetSdkVersion 25
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
18 |
19 | }
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | }
27 |
28 | dependencies {
29 | compile fileTree(dir: 'libs', include: ['*.jar'])
30 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
31 | exclude group: 'com.android.support', module: 'support-annotations'
32 | })
33 | compile 'com.android.support:appcompat-v7:25.1.0'
34 | testCompile 'junit:junit:4.12'
35 | }
36 |
37 |
38 |
39 | def siteUrl = 'https://github.com/Muddz/StyleableToast'
40 | def gitUrl = 'https://github.com/Muddz/StyleableToast.git'
41 | group = "com.muddzdev"
42 |
43 | install {
44 | repositories.mavenInstaller {
45 | // This generates POM.xml with proper parameters
46 | pom {
47 | project {
48 | packaging 'aar'
49 |
50 | name 'com.muddzdev:styleabletoast'
51 | description = 'An Android library that takes the standard Android toast to the next level with a variety of styling options.'
52 | url siteUrl
53 |
54 | licenses {
55 | license {
56 | name 'The Apache Software License, Version 2.0'
57 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
58 | }
59 | }
60 | developers {
61 | developer {
62 | id 'muddz'
63 | name 'Muddii Walid'
64 | email 'Aux-cc@hotmail.com'
65 | }
66 | }
67 | scm {
68 | connection gitUrl
69 | developerConnection gitUrl
70 | url siteUrl
71 | }
72 | }
73 | }
74 | }
75 | }
76 |
77 | task sourcesJar(type: Jar) {
78 | from android.sourceSets.main.java.srcDirs
79 | classifier = 'sources'
80 | }
81 |
82 | task javadoc(type: Javadoc) {
83 | source = android.sourceSets.main.java.srcDirs
84 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
85 | }
86 |
87 | task javadocJar(type: Jar, dependsOn: javadoc) {
88 | classifier = 'javadoc'
89 | from javadoc.destinationDir
90 | }
91 |
92 |
93 |
94 | tasks.withType(Javadoc).all {
95 | enabled = false
96 | }
97 |
98 |
99 | artifacts {
100 | archives javadocJar
101 | archives sourcesJar
102 | }
103 |
104 | Properties properties = new Properties()
105 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
106 |
107 | bintray {
108 | user = properties.getProperty("bintray.user")
109 | key = properties.getProperty("bintray.apikey")
110 |
111 | configurations = ['archives']
112 | pkg {
113 | repo = "maven"
114 | name = "styleabletoast"
115 | websiteUrl = siteUrl
116 | vcsUrl = gitUrl
117 | licenses = ["Apache-2.0"]
118 | publish = true
119 | version {
120 | gpg {
121 | sign = false //Determines whether to GPG sign the files. The default is false
122 | passphrase = properties.getProperty("bintray.gpg.password")
123 | //Optional. The passphrase for GPG signing'
124 | }
125 | }
126 | }
127 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
--------------------------------------------------------------------------------
/styleabletoast/src/main/java/com/muddzdev/styleabletoastlibrary/StyleableToast.java:
--------------------------------------------------------------------------------
1 | package com.muddzdev.styleabletoastlibrary;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Color;
7 | import android.graphics.Typeface;
8 | import android.graphics.drawable.GradientDrawable;
9 | import android.os.Build;
10 | import android.support.annotation.ColorInt;
11 | import android.support.annotation.DrawableRes;
12 | import android.support.annotation.NonNull;
13 | import android.support.annotation.StringRes;
14 | import android.support.annotation.StyleRes;
15 | import android.util.TypedValue;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 | import android.view.animation.Animation;
19 | import android.view.animation.LinearInterpolator;
20 | import android.view.animation.RotateAnimation;
21 | import android.widget.ImageView;
22 | import android.widget.RelativeLayout;
23 | import android.widget.TextView;
24 | import android.widget.Toast;
25 |
26 | import static com.muddzdev.styleabletoastlibrary.Utils.getTypedValueInDP;
27 |
28 | // Copyright 2017 Muddii Walid (Muddz)
29 | //
30 | // Licensed under the Apache License, Version 2.0 (the "License");
31 | // you may not use this file except in compliance with the License.
32 | // You may obtain a copy of the License at
33 | //
34 | // http://www.apache.org/licenses/LICENSE-2.0
35 | //
36 | // Unless required by applicable law or agreed to in writing, software
37 | // distributed under the License is distributed on an "AS IS" BASIS,
38 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39 | // See the License for the specific language governing permissions and
40 | // limitations under the License.
41 |
42 |
43 | /**
44 | * StyleableToast is a very easy and quick way to style your toast and gives them an unique style and feeling compared
45 | * to the default boring grey ones. StyleableToast have 10 styling options.
46 | *
If a particular style option is not set, the option will fall back to the standard Android Toast style
47 | */
48 |
49 | public class StyleableToast implements OnToastFinished {
50 |
51 | private static final String TAG = "StyleableToast";
52 | private static final String DEFAULT_CONDENSED_FONT = "sans-serif-condensed";
53 | private static final int DEFAULT_BACKGROUND = Color.parseColor("#555555");
54 | private static final int DEFAULT_TEXT_COLOR = Color.WHITE;
55 | private static final int DEFAULT_TEXT_SIZE = 16;
56 | private static final int DEFAULT_CORNER_RADIUS = 25;
57 | private static final int DEFAULT_HORIZONTAL_PADDING = 25;
58 | private static final int DEFAULT_VERTICAL_PADDING = 11;
59 | private static final int DEFAULT_ALPHA = 230;
60 | private static int MAX_ALPHA = 255;
61 |
62 | private final Context context;
63 | private TextView textView;
64 | private Typeface font;
65 | private Toast toast;
66 |
67 | private float strokeWidth;
68 | private int duration, style, alpha, drawable;
69 | private int backgroundColor, textColor, strokeColor;
70 | private int cornerRadius = -1;
71 | private boolean isBold;
72 | private boolean isAnimation;
73 | private String toastMsg;
74 | private ToastDurationWatcher durationTracker;
75 |
76 |
77 | public StyleableToast(Context context) {
78 | this.context = context.getApplicationContext();
79 | }
80 |
81 |
82 | public StyleableToast(Context context, String toastMsg, int duration) {
83 | this.context = context.getApplicationContext();
84 | this.toastMsg = toastMsg;
85 | this.duration = duration;
86 |
87 |
88 | }
89 |
90 | public StyleableToast(Context context, String toastMsg, int duration, @StyleRes int styleId) {
91 | this.context = context.getApplicationContext();
92 | this.toastMsg = toastMsg;
93 | this.duration = duration;
94 | this.style = styleId;
95 |
96 | }
97 |
98 | private StyleableToast(Builder builder) {
99 | this.context = builder.context;
100 | this.toastMsg = builder.message;
101 | this.duration = builder.length;
102 | setupFromBuilder(builder);
103 | }
104 |
105 | private void setupFromBuilder(@NonNull Builder builder) {
106 | if (isValidValue(builder.bgColor)) {
107 | setBackgroundColor(builder.bgColor);
108 | }
109 | if (isValidValue(builder.textColor)) {
110 | setTextColor(builder.textColor);
111 | }
112 | if (isValidValue(builder.icon)) {
113 | setIcon(builder.icon);
114 | }
115 | if (isValidValue(builder.styleRes)) {
116 | setStyle(builder.styleRes);
117 | }
118 | if (isValidValue(builder.cornerRadius)) {
119 | setCornerRadius(builder.cornerRadius);
120 | }
121 | if (isValidValue(builder.strokeWidth) && isValidValue(builder.strokeColor)) {
122 | setToastStroke(builder.strokeWidth, builder.strokeColor);
123 | }
124 | if (builder.typeface != null) {
125 | setTextFont(builder.typeface);
126 | }
127 | if (builder.maxAlpha) {
128 | setMaxAlpha();
129 | }
130 | if (builder.boldText) {
131 | setBoldText();
132 | }
133 | if (builder.iconAnimation) {
134 | spinIcon();
135 | }
136 | }
137 |
138 | private boolean isValidValue(int value) {
139 | //builder default int values are set to -1
140 | return value >= 0;
141 | }
142 |
143 |
144 | /**
145 | * @param style Style your toast via styles.xml and pass the style id R.style.xxx
146 | *
The attributes that must be used:
147 | * android:textColor.
148 | * android:textStyle.
149 | * android:fontFamily. If custom font, just write the path to it like: "fonts/myfont.ttf"
150 | * android:colorBackground.
151 | * android:strokeWidth. API 21+
152 | * android:strokeColor. API 21+
153 | * android:radius. Corner radius
154 | * android:alpha. Value between 1-255 where 255 is full solid
155 | * android:icon.
156 | */
157 | public void setStyle(@StyleRes int style) {
158 | this.style = style;
159 | }
160 |
161 | public void setToastMsg(String toastMsg) {
162 | this.toastMsg = toastMsg;
163 | }
164 |
165 | public void setBoldText() {
166 | isBold = true;
167 | }
168 |
169 | /**
170 | * @param typeface Set a different font than the standard sans-serif-condensed
171 | */
172 | public void setTextFont(Typeface typeface) {
173 | this.font = typeface;
174 | }
175 |
176 | /**
177 | * @param textColor if not set the default color white will be used.
178 | */
179 | public void setTextColor(@ColorInt int textColor) {
180 | this.textColor = textColor;
181 | }
182 |
183 | public void setTextStyle(boolean isBold, Typeface font) {
184 | this.isBold = isBold;
185 | this.font = font;
186 | }
187 |
188 | public void setTextStyle(@ColorInt int textColor, Typeface font) {
189 | this.textColor = textColor;
190 | this.font = font;
191 | }
192 |
193 | public void setTextStyle(@ColorInt int textColor, boolean isBold) {
194 | this.textColor = textColor;
195 | this.isBold = isBold;
196 | }
197 |
198 | public void setTextStyle(@ColorInt int textColor, boolean isBold, Typeface font) {
199 | this.textColor = textColor;
200 | this.isBold = isBold;
201 | this.font = font;
202 | }
203 |
204 | /**
205 | * Enables spinning animation of the passed icon by its around its own center.
206 | */
207 | public StyleableToast spinIcon() {
208 | isAnimation = true;
209 | return this;
210 | }
211 |
212 |
213 | /**
214 | * @param backgroundColor if not set the default color grey will be used.
215 | */
216 | public void setBackgroundColor(@ColorInt int backgroundColor) {
217 | this.backgroundColor = backgroundColor;
218 | }
219 |
220 | public void setDuration(int duration) {
221 | this.duration = duration;
222 | }
223 |
224 |
225 | public void setToastStroke(int strokeWidth, @ColorInt int strokeColor) {
226 | this.strokeWidth = strokeWidth;
227 | this.strokeColor = strokeColor;
228 | }
229 |
230 | /**
231 | * @param cornerRadius Sets the corner radius of the toast shape. Pass 0 for a flat rectangle shape
232 | */
233 | public void setCornerRadius(int cornerRadius) {
234 | this.cornerRadius = cornerRadius;
235 | }
236 |
237 | /**
238 | * Makes the toast background full solid instead of the default 75% transparency.
239 | */
240 | public void setMaxAlpha() {
241 | this.alpha = MAX_ALPHA;
242 | }
243 |
244 | /**
245 | * @param drawable Sets a icon on the left side of the toast text
246 | */
247 | public void setIcon(@DrawableRes int drawable) {
248 | this.drawable = drawable;
249 | }
250 |
251 |
252 | //Returns the relative layout containing: textview, icons, shape
253 | private View getToastLayout() {
254 |
255 | getImageViewStyleAttr();
256 |
257 | int horizontalPadding = (int) getTypedValueInDP(context, DEFAULT_HORIZONTAL_PADDING);
258 | int verticalPadding = (int) getTypedValueInDP(context, DEFAULT_VERTICAL_PADDING);
259 |
260 | RelativeLayout toastLayout = new RelativeLayout(context);
261 | toastLayout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);
262 | toastLayout.setBackground(getToastShape());
263 | toastLayout.addView(getTextView());
264 |
265 | if (drawable > 0) {
266 | toastLayout.addView(getIcon());
267 | toastLayout.setPadding(0, verticalPadding, 0, verticalPadding);
268 |
269 | }
270 |
271 | return toastLayout;
272 | }
273 |
274 |
275 | /**
276 | * loads style attributes from styles.xml if a style resource is used.
277 | */
278 | @SuppressWarnings("ResourceType")
279 | private void getToastShapeAttrs() {
280 | if (style > 0) {
281 |
282 | //array entries must be alphabetic ordered
283 | int[] colorAttrs = {android.R.attr.colorBackground, android.R.attr.strokeColor};
284 | int[] floatAttrs = {android.R.attr.alpha, android.R.attr.strokeWidth};
285 | int[] dimenAttrs = {android.R.attr.radius};
286 |
287 | TypedArray colors = context.obtainStyledAttributes(style, colorAttrs);
288 | TypedArray floats = context.obtainStyledAttributes(style, floatAttrs);
289 | TypedArray dimens = context.obtainStyledAttributes(style, dimenAttrs);
290 |
291 | backgroundColor = colors.getColor(0, DEFAULT_BACKGROUND);
292 | cornerRadius = (int) dimens.getDimension(0, DEFAULT_CORNER_RADIUS);
293 | alpha = (int) floats.getFloat(0, DEFAULT_ALPHA);
294 |
295 | if (Build.VERSION.SDK_INT >= 21) {
296 | strokeWidth = floats.getFloat(1, 0);
297 | strokeColor = colors.getColor(1, Color.TRANSPARENT);
298 | }
299 |
300 | colors.recycle();
301 | floats.recycle();
302 | dimens.recycle();
303 | }
304 |
305 | }
306 |
307 | private GradientDrawable getToastShape() {
308 | getToastShapeAttrs();
309 |
310 | GradientDrawable gradientDrawable = new GradientDrawable();
311 | gradientDrawable.setCornerRadius(getShapeCornerRadius());
312 | gradientDrawable.setStroke((int) getStrokeWidth(), getStrokeColor());
313 | gradientDrawable.setColor(getBackgroundColor());
314 | gradientDrawable.setAlpha(getShapeAlpha());
315 | return gradientDrawable;
316 | }
317 |
318 |
319 | private void getTextStylesAttr() {
320 | if (style > 0) {
321 |
322 | int[] colorAttrs = {android.R.attr.textColor};
323 | int[] stringAttrs = {android.R.attr.fontFamily};
324 | int[] intsAttrs = {android.R.attr.textStyle};
325 |
326 | TypedArray colors = context.obtainStyledAttributes(style, colorAttrs);
327 | TypedArray strings = context.obtainStyledAttributes(style, stringAttrs);
328 | TypedArray ints = context.obtainStyledAttributes(style, intsAttrs);
329 |
330 | textColor = colors.getColor(0, DEFAULT_TEXT_COLOR);
331 | String passedFont = strings.getString(0);
332 |
333 | if (passedFont != null && !passedFont.isEmpty()) {
334 | if (passedFont.contains("fonts")) {
335 | font = Typeface.createFromAsset(context.getAssets(), passedFont);
336 | } else {
337 | font = Typeface.create(passedFont, Typeface.NORMAL);
338 | }
339 | }
340 | if (ints.getInt(0, 0) == 1) {
341 | isBold = true;
342 | } else {
343 | isBold = false;
344 | }
345 |
346 | colors.recycle();
347 | strings.recycle();
348 | ints.recycle();
349 | }
350 |
351 | }
352 |
353 | private TextView getTextView() {
354 | getTextStylesAttr();
355 |
356 | textView = new TextView(context);
357 | textView.setText(toastMsg);
358 | textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE);
359 | textView.setTextColor(getTextColor());
360 | textView.setTypeface(getTypeface());
361 | textView.setMaxLines(2);
362 |
363 | if (drawable > 0) {
364 |
365 | //previous: 18x2 + 8
366 | int leftPadding = (int) getTypedValueInDP(context, 18 * 2 + 5);
367 | int rightPadding = (int) getTypedValueInDP(context, 22);
368 |
369 | RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
370 | layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
371 | textView.setLayoutParams(layoutParams);
372 |
373 | //Make space between icon and textview / textview and right edge of the toast
374 | textView.setPadding(leftPadding, 0, rightPadding, 0);
375 | }
376 |
377 | return textView;
378 | }
379 |
380 | private Animation getAnimation() {
381 | if (isAnimation) {
382 | RotateAnimation anim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
383 | anim.setInterpolator(new LinearInterpolator());
384 | anim.setRepeatCount(Animation.INFINITE);
385 | anim.setDuration(1000);
386 | return anim;
387 | }
388 |
389 | return null;
390 | }
391 |
392 |
393 | private void getImageViewStyleAttr() {
394 | if (style > 0) {
395 | int[] drawableAttrSet = {android.R.attr.icon};
396 | TypedArray drawableId = context.obtainStyledAttributes(style, drawableAttrSet);
397 | drawable = drawableId.getResourceId(0, 0);
398 | drawableId.recycle();
399 | }
400 | }
401 |
402 |
403 | private ImageView getIcon() {
404 |
405 | if (drawable > 0) {
406 |
407 | //previous 18:
408 | int marginLeft = (int) getTypedValueInDP(context, 15);
409 | int maxHeightVal = (int) getTypedValueInDP(context, 20);
410 | int maxWidthVal = (int) getTypedValueInDP(context, 20);
411 |
412 | ImageView imageView = new ImageView(context);
413 | imageView.setImageDrawable(context.getResources().getDrawable(drawable));
414 | imageView.setAnimation(getAnimation());
415 | imageView.setMaxWidth(marginLeft + maxWidthVal);
416 | imageView.setMaxHeight(maxHeightVal);
417 | imageView.setAdjustViewBounds(true);
418 |
419 |
420 | RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
421 | RelativeLayout.LayoutParams.WRAP_CONTENT,
422 | RelativeLayout.LayoutParams.WRAP_CONTENT);
423 |
424 | //Push the icon 15dp from the left edge of the shape
425 | layoutParams.setMargins(marginLeft, 0, 0, 0);
426 |
427 | layoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
428 | imageView.setLayoutParams(layoutParams);
429 | return imageView;
430 | }
431 | return null;
432 | }
433 |
434 |
435 | private float getStrokeWidth() {
436 | return getTypedValueInDP(context, strokeWidth);
437 | }
438 |
439 | private int getStrokeColor() {
440 | return strokeColor;
441 | }
442 |
443 | private float getShapeCornerRadius() {
444 | if (cornerRadius >= 0) {
445 | return getTypedValueInDP(context, cornerRadius);
446 | } else {
447 | return getTypedValueInDP(context, DEFAULT_CORNER_RADIUS);
448 | }
449 | }
450 |
451 | private int getBackgroundColor() {
452 | if (backgroundColor == 0) {
453 | return DEFAULT_BACKGROUND;
454 | } else {
455 | return backgroundColor;
456 | }
457 | }
458 |
459 |
460 | private int getShapeAlpha() {
461 | if (alpha == 0) {
462 | return DEFAULT_ALPHA;
463 | } else {
464 | return alpha;
465 | }
466 |
467 | }
468 |
469 |
470 | private Typeface getTypeface() {
471 |
472 | if (isBold && font == null) {
473 | return Typeface.create(DEFAULT_CONDENSED_FONT, Typeface.BOLD);
474 | } else if (isBold && font != null) {
475 | return Typeface.create(font, Typeface.BOLD);
476 | } else if (font != null) {
477 | return Typeface.create(font, Typeface.NORMAL);
478 | } else {
479 | return Typeface.create(DEFAULT_CONDENSED_FONT, Typeface.NORMAL);
480 | }
481 |
482 | }
483 |
484 | @ColorInt
485 | private int getTextColor() {
486 | if (textColor == 0 && style <= 0) {
487 | return DEFAULT_TEXT_COLOR;
488 | } else {
489 | return textColor;
490 | }
491 | }
492 |
493 |
494 | public void show() {
495 |
496 | toast = new Toast(context);
497 | toast.setView(getToastLayout());
498 | toast.setDuration(duration);
499 | toast.show();
500 |
501 | if (isAnimation) {
502 | durationTracker = new ToastDurationWatcher(toast.getDuration(), this);
503 | }
504 | }
505 |
506 | public void cancel() {
507 | toast.cancel();
508 |
509 | }
510 |
511 |
512 | /**
513 | * A callback that automatically cancels and resets animation effect from spinIcon(); when the toast is finished showing on screen.
514 | * Users should not call this method as this is used internally in the library.
515 | */
516 | @Override
517 | public void onToastFinished() {
518 |
519 | getAnimation().cancel();
520 | getAnimation().reset();
521 | }
522 |
523 |
524 | public static StyleableToast makeText(Context context, CharSequence text, int duration, int style) {
525 |
526 | StyleableToast styleableToast = new StyleableToast(context, text.toString(), duration, style);
527 |
528 | return styleableToast;
529 | }
530 |
531 | public static final class Builder {
532 |
533 | private final Context context;
534 |
535 | private String message;
536 | private int length = Toast.LENGTH_LONG;
537 |
538 | @ColorInt
539 | private int bgColor = -1;
540 | @ColorInt
541 | private int textColor = -1;
542 | @DrawableRes
543 | private int icon = -1;
544 | @StyleRes
545 | private int styleRes = -1;
546 | @ColorInt
547 | private int strokeColor = -1;
548 |
549 | private boolean iconAnimation = false;
550 | private boolean boldText = false;
551 | private boolean maxAlpha = false;
552 | private Typeface typeface = null;
553 | private int cornerRadius = -1;
554 | private int strokeWidth = -1;
555 |
556 |
557 | public Builder(Context context, @NonNull String message) {
558 | this.context = context.getApplicationContext();
559 | this.message = message;
560 | }
561 |
562 | public Builder(Context context, @StringRes int message) {
563 | this(context, context.getString(message));
564 | }
565 |
566 | /**
567 | * @param backgroundColor if not set the default color grey will be used.
568 | */
569 | public Builder withBackgroundColor(@ColorInt int backgroundColor) {
570 | this.bgColor = backgroundColor;
571 | return this;
572 | }
573 |
574 | /**
575 | * @param textColor if not set the default color white will be used.
576 | */
577 | public Builder withTextColor(@ColorInt int textColor) {
578 | this.textColor = textColor;
579 | return this;
580 | }
581 |
582 | /**
583 | * @param duration Sets the toast's duration. Either {@linkplain Toast#LENGTH_LONG} or {@linkplain Toast#LENGTH_SHORT}
584 | */
585 | public Builder withDuration(int duration) {
586 | if (duration == Toast.LENGTH_LONG || duration == Toast.LENGTH_SHORT) {
587 | this.length = duration;
588 | }
589 | return this;
590 | }
591 |
592 | /**
593 | * @param iconRes The icon's resource which should be used within the toast
594 | */
595 | public Builder withIcon(@DrawableRes int iconRes) {
596 | return withIcon(iconRes, false);
597 | }
598 |
599 | /**
600 | * @param iconRes The icon's resource which should be used within the toast
601 | * @param spinIcon Enables spinning animation of the passed icon by its around its own center.
602 | */
603 | public Builder withIcon(@DrawableRes int iconRes, boolean spinIcon) {
604 | this.icon = iconRes;
605 | this.iconAnimation = spinIcon;
606 | return this;
607 | }
608 |
609 | /**
610 | * @param style Style your toast via styles.xml and pass the style id R.style.xxx
The attributes that must be used:
android:textColor. android:textStyle. android:fontFamily. If
611 | * custom font, just write the path to it like: "fonts/myfont.ttf" android:colorBackground. android:strokeWidth. API 21+ android:strokeColor. API 21+
612 | * android:radius. Corner radius android:alpha. Value between 1-255 where 255 is full solid android:icon.
613 | */
614 | public Builder withStyle(@StyleRes int style) {
615 | this.styleRes = style;
616 | return this;
617 | }
618 |
619 | /**
620 | * Specify the message displayed in this Toast.
621 | *
622 | * @param toastMessage The message displayed in this Toast.
623 | */
624 | public Builder withToastMessage(@NonNull String toastMessage) {
625 | this.message = toastMessage;
626 | return this;
627 | }
628 |
629 | /**
630 | * Specify whether to display the Toast's message with a bold typeface.
631 | *
632 | * @param useBoldText Whether to display the Toast's message with a bold typeface.
633 | */
634 | public Builder withBoldText(boolean useBoldText) {
635 | this.boldText = useBoldText;
636 | return this;
637 | }
638 |
639 | /**
640 | * @param typeface Set a different font than the standard sans-serif-condensed
641 | */
642 | public Builder withTextFont(@NonNull Typeface typeface) {
643 | this.typeface = typeface;
644 | return this;
645 | }
646 |
647 | /**
648 | * Specify the Stroke for this Toast
649 | *
650 | * @param strokeWidth Width of the Toast's stroke
651 | * @param strokeColor Color of the Toast's stroke
652 | */
653 | public Builder withToastStroke(int strokeWidth, @ColorInt int strokeColor) {
654 | if (strokeWidth > 0) {
655 | this.strokeWidth = strokeWidth;
656 | this.strokeColor = strokeColor;
657 | }
658 | return this;
659 | }
660 |
661 | /**
662 | * @param cornerRadius Sets the corner radius of the toast shape. Pass 0 for a flat rectangle shape
663 | */
664 | public Builder withCornerRadius(int cornerRadius) {
665 | if (cornerRadius >= 0) {
666 | this.cornerRadius = cornerRadius;
667 | }
668 | return this;
669 | }
670 |
671 | /**
672 | * Set the alpha/Transparency of the Toast background between 0-255. 255 is full opque and 0 is full transparency.
673 | */
674 | public Builder withMaxAlpha() {
675 | this.maxAlpha = true;
676 | return this;
677 | }
678 |
679 | /**
680 | * Build and returns the configured instance
681 | *
682 | * @return The configured {@link StyleableToast} instance.
683 | */
684 | public StyleableToast build() {
685 | return new StyleableToast(this);
686 | }
687 |
688 | /**
689 | * Build and displays the configured {@link StyleableToast} instance
690 | */
691 | public void show() {
692 | new StyleableToast(this).show();
693 | }
694 |
695 | }
696 |
697 | }
698 |
--------------------------------------------------------------------------------