├── .gitignore
├── CHANGELOG.md
├── LICENSE.txt
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── AndroidManifest.xml
├── build.gradle
├── gradle.properties
├── pom.xml
├── project.properties
├── res
│ ├── layout
│ │ └── app_msg.xml
│ └── values
│ │ └── colors.xml
└── src
│ └── com
│ └── devspark
│ └── appmsg
│ ├── AppMsg.java
│ └── MsgManager.java
├── sample
├── AndroidManifest.xml
├── build.gradle
├── ic_launcher-web.png
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ ├── ic_action_cancel.png
│ │ └── ic_launcher.png
│ ├── drawable-ldpi
│ │ ├── ic_action_cancel.png
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ ├── ic_action_cancel.png
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ ├── ic_action_cancel.png
│ │ └── ic_launcher.png
│ ├── drawable
│ │ └── ic_action_cancel_inset.xml
│ ├── layout
│ │ ├── activity_main.xml
│ │ └── sticky.xml
│ ├── values-v11
│ │ └── styles.xml
│ └── values
│ │ ├── arrays.xml
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── com
│ └── devspark
│ └── appmsg
│ └── sample
│ └── MainActivity.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | #Android generated
2 | bin
3 | gen
4 |
5 | #Eclipse
6 | .project
7 | .classpath
8 | .settings
9 |
10 | #IntelliJ IDEA
11 | .idea
12 | *.iml
13 | *.ipr
14 | *.iws
15 | out
16 |
17 | #Maven
18 | target
19 | release.properties
20 | pom.xml.*
21 |
22 | #Ant
23 | build.xml
24 | local.properties
25 | proguard.cfg
26 | proguard-project.txt
27 |
28 | #Gradle
29 | .gradle
30 | build
31 |
32 | #OSX
33 | .DS_Store
34 |
35 | #Personal Files
36 | signing.properties
37 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Change Log
2 | ==========
3 |
4 |
5 | Version 1.2.0 *(2014-02-17)*
6 | ----------------------------
7 |
8 | * Added support for custom Animations.
9 | * Added support for displaying Sticky notifications closed manually.
10 | * Allow to provide a custom parent.
11 | * Allow to provide a priority, so some urgent AppMsgs can jump to the front of the queue.
12 | * Fix: Activity leaking.
13 |
14 |
15 | Version 1.1.1 *(2013-10-29)*
16 | ----------------------------
17 |
18 | * Update gradle build
19 |
20 |
21 | Version 1.1.0 *(2013-10-08)*
22 | ----------------------------
23 |
24 | * Publish an aar file to Maven Central with Gradle.
25 | * Fix: Add missing piece to the build.gradle.
26 | * Fix: Updated the version of android-maven-plugin to build with the most recent Android SDK.
27 |
28 |
29 | Version 1.0.1 *(2013-01-07)*
30 | ----------------------------
31 |
32 | * Formatting of the source code.
33 | * Bugfix.
34 |
35 |
36 | Version 1.0.0 *(2012-12-23)*
37 | ----------------------------
38 |
39 | Initial release.
40 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android AppMsg (Crouton) Library
2 | ================================
3 |
4 | Implementation of in-layout notifications. Based on [Toast](http://developer.android.com/reference/android/widget/Toast.html) notifications and article [The making of Prixing #4: in-layout notifications](http://android.cyrilmottier.com/?p=773) by [Cyril Mottier](http://www.cyrilmottier.com/).
5 |
6 |
7 | Description
8 | -----------
9 |
10 | Toast is far from being perfect and I am not entirely satisfied with it.
11 | Toast can be un-accurate in some cases. Indeed, Toast has one major drawback: it completely breaks contexts.
12 | This issue can be reproduced effortless. Let’s say a user is currently in an app firing a Toast and wants to switch to another application using the dedicated “multitask” button.
13 | The Toast will remain on screen even if the brought-to-front application has nothing do to with the previously shown app as described on the following figure:
14 | ![Example Image][1]
15 |
16 | As you can easily notice, the problem with Toasts is they are persistent.
17 | Once a Toast has been fired, it is displayed on top of any screen and remains visible for the duration specified at its creation.
18 |
19 | In order to bypass the Toast persistence problem and ensure information is displayed in the correct context, we decided to create a new notification system:
20 | Activity-bound notifications. This is what it looks like in the current version of Prixing:
21 | ![Example Image][2]
22 |
23 | Crouton overcomes the main issue of having a Toast being shown while the menu is open.
24 | It sticks to the current screen sliding with it and leaving the menu completely free of any information that would have not been related to it.
25 |
26 | Copyright (C) by Cyril Mottier
27 |
28 | Sample
29 | ------
30 |
31 | A sample application is available on Google Play:
32 |
33 |
34 |
36 |
37 |
38 | ![Example Image][3]
39 |
40 | The source code is available in this repository.
41 |
42 | Compatibility
43 | -------------
44 |
45 | This library is compatible from API 4 (Android 1.6).
46 |
47 | Installation
48 | ------------
49 |
50 | The sample project requires:
51 |
52 | * The library project
53 | * [ActionBarSherlock](https://github.com/JakeWharton/ActionBarSherlock)
54 |
55 | Usage
56 | -----
57 |
58 | Android AppMsg is presented as an [Android library project](http://developer.android.com/guide/developing/projects/projects-eclipse.html).
59 | You can include this project by [referencing it as a library project](http://developer.android.com/guide/developing/projects/projects-eclipse.html#ReferencingLibraryProject) in Eclipse or ant.
60 |
61 | To display the item you need the following code:
62 |
63 | * Show AppMsg:
64 |
65 | ``` java
66 | AppMsg.makeText(/*Activity*/, /*CharSequence*/, /*AppMsg.Style*/).show();
67 | ```
68 |
69 | Gradle
70 | ------
71 |
72 | Android-AppMsg Library is now pushed to Maven Central as a AAR, so you just need to add the following dependency to your build.gradle.
73 |
74 | ``` xml
75 | dependencies {
76 | implementation 'com.github.johnkil.android-appmsg:appmsg:1.2.0'
77 | }
78 | ```
79 |
80 | Example Gradle project using Android-AppMsg:
81 |
82 | * [Android-AppMsg-Gradle-Sample](https://github.com/johnkil/Android-AppMsg-Gradle-Sample)
83 |
84 |
85 | Contribution
86 | ------------
87 |
88 | Please fork [dev](https://github.com/johnkil/Android-AppMsg/tree/dev) repository and contribute back using [pull requests](https://github.com/johnkil/Android-AppMsg/pulls).
89 |
90 | Contributors are recommended to follow the Android [Code Style Guidelines](http://source.android.com/source/code-style.html).
91 |
92 | Any contributions, large or small, major features, bug fixes, additional language translations, unit/integration tests are welcomed and appreciated but will be thoroughly reviewed and discussed.
93 |
94 | Developed By
95 | ------------
96 | * Evgeny Shishkin -
97 |
98 | License
99 | -------
100 |
101 | Copyright 2012 Evgeny Shishkin
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 | [1]: http://cyrilmottier.com/media/2012/07/the-making-of-prixing-4-activity-tied-notifications/toast_user_flow_fail.png
116 | [2]: http://cyrilmottier.com/media/2012/07/the-making-of-prixing-4-activity-tied-notifications/in_layout_notification.png
117 | [3]: http://i46.tinypic.com/21kywit.png
118 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 |
6 | dependencies {
7 | classpath 'com.android.tools.build:gradle:1.0.0'
8 | }
9 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=1.2.0-SNAPSHOT
2 | VERSION_CODE=5
3 | GROUP=com.github.johnkil.android-appmsg
4 |
5 | POM_DESCRIPTION=In-layout android notifications
6 | POM_URL=https://github.com/johnkil/Android-AppMsg
7 | POM_SCM_URL=https://github.com/johnkil/Android-AppMsg
8 | POM_SCM_CONNECTION=scm:git@github.com:johnkil/Android-AppMsg.git
9 | POM_SCM_DEV_CONNECTION=scm:git@github.com:johnkil/Android-AppMsg.git
10 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
11 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
12 | POM_LICENCE_DIST=repo
13 | POM_DEVELOPER_ID=johnkil
14 | POM_DEVELOPER_NAME=Evgeny Shishkin
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnkil/Android-AppMsg/1fbca8f7b432894844b660cbc98a183c9b755dbf/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed May 07 11:40:46 MSK 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 4
9 | targetSdkVersion 21
10 | versionCode 5
11 | versionName "1.2.0"
12 | }
13 |
14 | sourceSets {
15 | main {
16 | manifest.srcFile 'AndroidManifest.xml'
17 | java.srcDirs = ['src']
18 | res.srcDirs = ['res']
19 | }
20 | }
21 | }
22 |
23 | // Used to push in maven
24 | apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
--------------------------------------------------------------------------------
/library/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=Android-AppMsg Library
2 | POM_ARTIFACT_ID=appmsg
3 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/library/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 | 4.0.0
7 |
8 | com.devspark
9 | appmsg
10 | 1.0.1
11 | apklib
12 |
13 |
14 |
15 | com.google.android
16 | android
17 | 4.1.1.4
18 | provided
19 |
20 |
21 |
22 |
23 | src
24 |
25 |
26 | org.apache.maven.plugins
27 | maven-pmd-plugin
28 | 2.7.1
29 |
30 | true
31 | utf-8
32 | 100
33 | 1.6
34 |
35 | **/*Bean.java
36 | **/generated/*.java
37 |
38 |
39 | target/generated-sources/stubs
40 |
41 |
42 |
43 |
44 |
45 | com.jayway.maven.plugins.android.generation2
46 | android-maven-plugin
47 | 3.6.0
48 |
49 | ${project.basedir}/AndroidManifest.xml
50 | ${project.basedir}/assets
51 | ${project.basedir}/res
52 | ${project.basedir}/src/main/native
53 |
54 | 16
55 |
56 | true
57 |
58 | true
59 |
60 |
61 |
62 | maven-compiler-plugin
63 | 2.3.2
64 |
65 | 1.6
66 | 1.6
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/library/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/library/res/layout/app_msg.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
--------------------------------------------------------------------------------
/library/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #CC0000
5 | #FF8800
6 | #669900
7 |
8 |
--------------------------------------------------------------------------------
/library/src/com/devspark/appmsg/AppMsg.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Evgeny Shishkin
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.devspark.appmsg;
18 |
19 | import android.app.Activity;
20 | import android.content.Context;
21 | import android.content.res.Resources;
22 | import android.view.LayoutInflater;
23 | import android.view.View;
24 | import android.view.View.OnClickListener;
25 | import android.view.ViewGroup;
26 | import android.view.ViewGroup.LayoutParams;
27 | import android.view.animation.Animation;
28 | import android.view.animation.AnimationUtils;
29 | import android.widget.FrameLayout;
30 | import android.widget.TextView;
31 |
32 | /**
33 | * In-layout notifications. Based on {@link android.widget.Toast} notifications
34 | * and article by Cyril Mottier (http://android.cyrilmottier.com/?p=773).
35 | *
36 | * @author e.shishkin
37 | */
38 | public class AppMsg {
39 |
40 | /**
41 | * Show the view or text notification for a short period of time. This time
42 | * could be user-definable. This is the default.
43 | *
44 | * @see #setDuration
45 | */
46 | public static final int LENGTH_SHORT = 3000;
47 |
48 | /**
49 | * Show the view or text notification for a long period of time. This time
50 | * could be user-definable.
51 | *
52 | * @see #setDuration
53 | */
54 | public static final int LENGTH_LONG = 5000;
55 |
56 | /**
57 | *
Show the view or text notification for an undefined amount of time
58 | * -Usually until an invocation of {@link #cancel()}, {@link #cancelAll(android.app.Activity)},
59 | * {@link #cancelAll()} or {@link android.app.Activity#onDestroy()}-,
60 | * stacking on top of any other {@link com.devspark.appmsg.AppMsg} with this duration.
61 | *
62 | *
Note: You are responsible
63 | * for calling {@link #cancel()} on such {@link com.devspark.appmsg.AppMsg}.
64 | *
65 | * @see #setDuration
66 | */
67 | public static final int LENGTH_STICKY = -1;
68 |
69 | /**
70 | * Lowest priority, messages with this priority will be showed after all messages with priority
71 | * {@link #PRIORITY_HIGH} and {@link #PRIORITY_NORMAL} have been shown.
72 | *
73 | * @see #setPriority(int)
74 | */
75 | public static final int PRIORITY_LOW = Integer.MIN_VALUE;
76 | /**
77 | * Normal priority, messages with this priority will be showed after all messages with priority
78 | * {@link #PRIORITY_HIGH} but before {@link #PRIORITY_LOW} have been shown.
79 | *
80 | * @see #setPriority(int)
81 | */
82 | public static final int PRIORITY_NORMAL = 0;
83 | /**
84 | * Highest priority, messages with this priority will be showed before any other message.
85 | *
86 | * @see #setPriority(int)
87 | */
88 | public static final int PRIORITY_HIGH = Integer.MAX_VALUE;
89 |
90 | /**
91 | * Show the text notification for a long period of time with a negative style.
92 | */
93 | public static final Style STYLE_ALERT = new Style(LENGTH_LONG, R.color.alert);
94 |
95 | /**
96 | * Show the text notification for a short period of time with a positive style.
97 | */
98 | public static final Style STYLE_CONFIRM = new Style(LENGTH_SHORT, R.color.confirm);
99 |
100 | /**
101 | * Show the text notification for a short period of time with a neutral style.
102 | */
103 | public static final Style STYLE_INFO = new Style(LENGTH_SHORT, R.color.info);
104 |
105 | private final Activity mActivity;
106 | private int mDuration = LENGTH_SHORT;
107 | private View mView;
108 | private ViewGroup mParent;
109 | private LayoutParams mLayoutParams;
110 | private boolean mFloating;
111 | Animation mInAnimation, mOutAnimation;
112 | int mPriority = PRIORITY_NORMAL;
113 |
114 | /**
115 | * Construct an empty AppMsg object. You must call {@link #setView} before
116 | * you can call {@link #show}.
117 | *
118 | * @param activity {@link android.app.Activity} to use.
119 | */
120 | public AppMsg(Activity activity) {
121 | mActivity = activity;
122 | }
123 |
124 | /**
125 | * Make a {@link AppMsg} that just contains a text view.
126 | *
127 | * @param context The context to use. Usually your
128 | * {@link android.app.Activity} object.
129 | * @param text The text to show. Can be formatted text.
130 | * @param style The style with a background and a duration.
131 | */
132 | public static AppMsg makeText(Activity context, CharSequence text, Style style) {
133 | return makeText(context, text, style, R.layout.app_msg);
134 | }
135 |
136 |
137 | /**
138 | * Make a {@link AppMsg} that just contains a text view.
139 | *
140 | * @param context The context to use. Usually your
141 | * {@link android.app.Activity} object.
142 | * @param text The text to show. Can be formatted text.
143 | * @param style The style with a background and a duration.
144 | */
145 | public static AppMsg makeText(Activity context, CharSequence text, Style style, OnClickListener clickListener) {
146 | return makeText(context, text, style, R.layout.app_msg);
147 | }
148 |
149 | /**
150 | * @author mengguoqiang
151 | * Make a {@link AppMsg} that just contains a text view.
152 | *
153 | * @param context The context to use. Usually your
154 | * {@link android.app.Activity} object.
155 | * @param text The text to show. Can be formatted text.
156 | * @param style The style with a background and a duration.
157 | */
158 | public static AppMsg makeText(Activity context, CharSequence text, Style style, float textSize) {
159 | return makeText(context, text, style, R.layout.app_msg, textSize);
160 | }
161 |
162 |
163 | /**
164 | * @author mengguoqiang
165 | * Make a {@link AppMsg} that just contains a text view.
166 | *
167 | * @param context The context to use. Usually your
168 | * {@link android.app.Activity} object.
169 | * @param text The text to show. Can be formatted text.
170 | * @param style The style with a background and a duration.
171 | */
172 | public static AppMsg makeText(Activity context, CharSequence text, Style style, float textSize, OnClickListener clickListener) {
173 | return makeText(context, text, style, R.layout.app_msg, textSize, clickListener);
174 | }
175 |
176 | /**
177 | * Make a {@link AppMsg} with a custom layout. The layout must have a {@link TextView} com id {@link android.R.id.message}
178 | *
179 | * @param context The context to use. Usually your
180 | * {@link android.app.Activity} object.
181 | * @param text The text to show. Can be formatted text.
182 | * @param style The style with a background and a duration.
183 | */
184 | public static AppMsg makeText(Activity context, CharSequence text, Style style, int layoutId) {
185 | LayoutInflater inflate = (LayoutInflater)
186 | context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
187 | View v = inflate.inflate(layoutId, null);
188 |
189 | return makeText(context, text, style, v, true);
190 | }
191 |
192 |
193 | /**
194 | * Make a {@link AppMsg} with a custom layout. The layout must have a {@link TextView} com id {@link android.R.id.message}
195 | *
196 | * @param context The context to use. Usually your
197 | * {@link android.app.Activity} object.
198 | * @param text The text to show. Can be formatted text.
199 | * @param style The style with a background and a duration.
200 | */
201 | public static AppMsg makeText(Activity context, CharSequence text, Style style, int layoutId, OnClickListener clickListener) {
202 | LayoutInflater inflate = (LayoutInflater)
203 | context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
204 | View v = inflate.inflate(layoutId, null);
205 |
206 | return makeText(context, text, style, v, true);
207 | }
208 |
209 |
210 |
211 | /**
212 | * @author mengguoqiang
213 | * Make a {@link AppMsg} with a custom layout. The layout must have a {@link TextView} com id {@link android.R.id.message}
214 | *
215 | * @param context The context to use. Usually your
216 | * {@link android.app.Activity} object.
217 | * @param text The text to show. Can be formatted text.
218 | * @param style The style with a background and a duration.
219 | */
220 | public static AppMsg makeText(Activity context, CharSequence text, Style style, int layoutId, float textSize, OnClickListener clickListener) {
221 | LayoutInflater inflate = (LayoutInflater)
222 | context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
223 | View v = inflate.inflate(layoutId, null);
224 |
225 | return makeText(context, text, style, v, true, textSize, clickListener);
226 | }
227 |
228 | /**
229 | * @author mengguoqiang
230 | * Make a {@link AppMsg} with a custom layout. The layout must have a {@link TextView} com id {@link android.R.id.message}
231 | *
232 | * @param context The context to use. Usually your
233 | * {@link android.app.Activity} object.
234 | * @param text The text to show. Can be formatted text.
235 | * @param style The style with a background and a duration.
236 | */
237 | public static AppMsg makeText(Activity context, CharSequence text, Style style, int layoutId, float textSize) {
238 | LayoutInflater inflate = (LayoutInflater)
239 | context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
240 | View v = inflate.inflate(layoutId, null);
241 |
242 | return makeText(context, text, style, v, true, textSize);
243 | }
244 |
245 |
246 |
247 |
248 | /**
249 | * Make a non-floating {@link AppMsg} with a custom view presented inside the layout.
250 | * It can be used to create non-floating notifications if floating is false.
251 | *
252 | * @param context The context to use. Usually your
253 | * {@link android.app.Activity} object.
254 | * @param customView
255 | * View to be used.
256 | * @param text The text to show. Can be formatted text.
257 | * @param style The style with a background and a duration.
258 | */
259 | public static AppMsg makeText(Activity context, CharSequence text, Style style, View customView) {
260 | return makeText(context, text, style, customView, false);
261 | }
262 |
263 |
264 |
265 | /**
266 | * Make a non-floating {@link AppMsg} with a custom view presented inside the layout.
267 | * It can be used to create non-floating notifications if floating is false.
268 | *
269 | * @param context The context to use. Usually your
270 | * {@link android.app.Activity} object.
271 | * @param customView
272 | * View to be used.
273 | * @param text The text to show. Can be formatted text.
274 | * @param style The style with a background and a duration.
275 | */
276 | public static AppMsg makeText(Activity context, CharSequence text, Style style, View customView, OnClickListener clickListener) {
277 | return makeText(context, text, style, customView, false, clickListener);
278 | }
279 |
280 |
281 | /**
282 | * Make a {@link AppMsg} with a custom view. It can be used to create non-floating notifications if floating is false.
283 | *
284 | * @param context The context to use. Usually your
285 | * {@link android.app.Activity} object.
286 | * @param view
287 | * View to be used.
288 | * @param text The text to show. Can be formatted text.
289 | * @param style The style with a background and a duration.
290 | * @param floating true if it'll float.
291 | */
292 | private static AppMsg makeText(Activity context, CharSequence text, Style style, View view, boolean floating) {
293 | return makeText(context, text, style, view, floating, 0);
294 | }
295 |
296 |
297 |
298 | /**
299 | * Make a {@link AppMsg} with a custom view. It can be used to create non-floating notifications if floating is false.
300 | *
301 | * @param context The context to use. Usually your
302 | * {@link android.app.Activity} object.
303 | * @param view
304 | * View to be used.
305 | * @param text The text to show. Can be formatted text.
306 | * @param style The style with a background and a duration.
307 | * @param floating true if it'll float.
308 | */
309 | private static AppMsg makeText(Activity context, CharSequence text, Style style, View view, boolean floating, OnClickListener clickListener) {
310 | return makeText(context, text, style, view, floating, 0, clickListener);
311 | }
312 |
313 | /**
314 | *
315 | * @author mengguoqiang
316 | * Make a {@link AppMsg} with a custom view. It can be used to create non-floating notifications if floating is false.
317 | *
318 | * @param context The context to use. Usually your
319 | * {@link android.app.Activity} object.
320 | * @param view
321 | * View to be used.
322 | * @param text The text to show. Can be formatted text.
323 | * @param style The style with a background and a duration.
324 | * @param floating true if it'll float.
325 | */
326 | private static AppMsg makeText(Activity context, CharSequence text, Style style, View view, boolean floating, float textSize) {
327 | AppMsg result = new AppMsg(context);
328 |
329 | view.setBackgroundResource(style.background);
330 |
331 | TextView tv = (TextView) view.findViewById(android.R.id.message);
332 | if(textSize > 0) tv.setTextSize(textSize);
333 | tv.setText(text);
334 |
335 | result.mView = view;
336 | result.mDuration = style.duration;
337 | result.mFloating = floating;
338 |
339 | return result;
340 | }
341 |
342 |
343 |
344 | /**
345 | *
346 |
347 | * Make a {@link AppMsg} with a custom view. It can be used to create non-floating notifications if floating is false.
348 | *
349 | * @param context The context to use. Usually your
350 | * {@link android.app.Activity} object.
351 | * @param view
352 | * View to be used.
353 | * @param text The text to show. Can be formatted text.
354 | * @param style The style with a background and a duration.
355 | * @param floating true if it'll float.
356 | * @param clickListener Clicklistener
357 | */
358 | private static AppMsg makeText(Activity context, CharSequence text, Style style, View view, boolean floating,
359 | float textSize, OnClickListener clickListener) {
360 | AppMsg result = new AppMsg(context);
361 |
362 | view.setBackgroundResource(style.background);
363 | view.setClickable(true);
364 |
365 | TextView tv = (TextView) view.findViewById(android.R.id.message);
366 | if(textSize > 0) tv.setTextSize(textSize);
367 | tv.setText(text);
368 |
369 | result.mView = view;
370 | result.mDuration = style.duration;
371 | result.mFloating = floating;
372 |
373 | view.setOnClickListener(clickListener);
374 |
375 | return result;
376 | }
377 |
378 |
379 |
380 |
381 |
382 |
383 | /**
384 | * Make a {@link AppMsg} with a custom view. It can be used to create non-floating notifications if floating is false.
385 | *
386 | * @param context The context to use. Usually your
387 | * {@link android.app.Activity} object.
388 | * @param resId The resource id of the string resource to use. Can be
389 | * formatted text.
390 | * @param style The style with a background and a duration.
391 | * @param floating true if it'll float.
392 | */
393 | public static AppMsg makeText(Activity context, int resId, Style style, View customView, boolean floating) {
394 | return makeText(context, context.getResources().getText(resId), style, customView, floating);
395 | }
396 |
397 | /**
398 | * Make a {@link AppMsg} that just contains a text view with the text from a
399 | * resource.
400 | *
401 | * @param context The context to use. Usually your
402 | * {@link android.app.Activity} object.
403 | * @param resId The resource id of the string resource to use. Can be
404 | * formatted text.
405 | * @param style The style with a background and a duration.
406 | * @throws Resources.NotFoundException if the resource can't be found.
407 | */
408 | public static AppMsg makeText(Activity context, int resId, Style style)
409 | throws Resources.NotFoundException {
410 | return makeText(context, context.getResources().getText(resId), style);
411 | }
412 |
413 | /**
414 | * Make a {@link AppMsg} with a custom layout using the text from a
415 | * resource. The layout must have a {@link TextView} com id {@link android.R.id.message}
416 | *
417 | * @param context The context to use. Usually your
418 | * {@link android.app.Activity} object.
419 | * @param resId The resource id of the string resource to use. Can be
420 | * formatted text.
421 | * @param style The style with a background and a duration.
422 | * @throws Resources.NotFoundException if the resource can't be found.
423 | */
424 | public static AppMsg makeText(Activity context, int resId, Style style, int layoutId)
425 | throws Resources.NotFoundException {
426 | return makeText(context, context.getResources().getText(resId), style, layoutId);
427 | }
428 |
429 | /**
430 | * Show the view for the specified duration.
431 | */
432 | public void show() {
433 | MsgManager manager = MsgManager.obtain(mActivity);
434 | manager.add(this);
435 | }
436 |
437 | /**
438 | * @return true if the {@link AppMsg} is being displayed, else false.
439 | */
440 | public boolean isShowing() {
441 | if (mFloating) {
442 | return mView != null && mView.getParent() != null;
443 | } else {
444 | return mView.getVisibility() == View.VISIBLE;
445 | }
446 | }
447 |
448 | /**
449 | * Close the view if it's showing, or don't show it if it isn't showing yet.
450 | * You do not normally have to call this. Normally view will disappear on its own
451 | * after the appropriate duration.
452 | */
453 | public void cancel() {
454 | MsgManager.obtain(mActivity).clearMsg(this);
455 |
456 | }
457 |
458 | /**
459 | * Cancels all queued {@link AppMsg}s, in all Activities. If there is a {@link AppMsg}
460 | * displayed currently, it will be the last one displayed.
461 | */
462 | public static void cancelAll() {
463 | MsgManager.clearAll();
464 | }
465 |
466 | /**
467 | * Cancels all queued {@link AppMsg}s, in given {@link android.app.Activity}.
468 | * If there is a {@link AppMsg} displayed currently, it will be the last one displayed.
469 | * @param activity
470 | */
471 | public static void cancelAll(Activity activity) {
472 | MsgManager.release(activity);
473 | }
474 |
475 | /**
476 | * Return the activity.
477 | */
478 | public Activity getActivity() {
479 | return mActivity;
480 | }
481 |
482 | /**
483 | * Set the view to show.
484 | *
485 | * @see #getView
486 | */
487 | public void setView(View view) {
488 | mView = view;
489 | }
490 |
491 | /**
492 | * Return the view.
493 | *
494 | * @see #setView
495 | */
496 | public View getView() {
497 | return mView;
498 | }
499 |
500 | /**
501 | * Set how long to show the view for.
502 | *
503 | * @see #LENGTH_SHORT
504 | * @see #LENGTH_LONG
505 | */
506 | public void setDuration(int duration) {
507 | mDuration = duration;
508 | }
509 |
510 | /**
511 | * Return the duration.
512 | *
513 | * @see #setDuration
514 | */
515 | public int getDuration() {
516 | return mDuration;
517 | }
518 |
519 | /**
520 | * Update the text in a AppMsg that was previously created using one of the makeText() methods.
521 | *
522 | * @param resId The new text for the AppMsg.
523 | */
524 | public void setText(int resId) {
525 | setText(mActivity.getText(resId));
526 | }
527 |
528 | /**
529 | * Update the text in a AppMsg that was previously created using one of the makeText() methods.
530 | *
531 | * @param s The new text for the AppMsg.
532 | */
533 | public void setText(CharSequence s) {
534 | if (mView == null) {
535 | throw new RuntimeException("This AppMsg was not created with AppMsg.makeText()");
536 | }
537 | TextView tv = (TextView) mView.findViewById(android.R.id.message);
538 | if (tv == null) {
539 | throw new RuntimeException("This AppMsg was not created with AppMsg.makeText()");
540 | }
541 | tv.setText(s);
542 | }
543 |
544 | /**
545 | * Gets the crouton's layout parameters, constructing a default if necessary.
546 | *
547 | * @return the layout parameters
548 | */
549 | public LayoutParams getLayoutParams() {
550 | if (mLayoutParams == null) {
551 | mLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
552 | }
553 | return mLayoutParams;
554 | }
555 |
556 | /**
557 | * Sets the layout parameters which will be used to display the crouton.
558 | *
559 | * @param layoutParams The layout parameters to use.
560 | * @return this, for chaining.
561 | */
562 | public AppMsg setLayoutParams(LayoutParams layoutParams) {
563 | mLayoutParams = layoutParams;
564 | return this;
565 | }
566 |
567 | /**
568 | * Constructs and sets the layout parameters to have some gravity.
569 | *
570 | * @param gravity the gravity of the Crouton
571 | * @return this, for chaining.
572 | * @see android.view.Gravity
573 | */
574 | public AppMsg setLayoutGravity(int gravity) {
575 | mLayoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, gravity);
576 | return this;
577 | }
578 |
579 | /**
580 | * Return the value of floating.
581 | *
582 | * @see #setFloating(boolean)
583 | */
584 | public boolean isFloating() {
585 | return mFloating;
586 | }
587 |
588 | /**
589 | * Sets the value of floating.
590 | *
591 | * @param mFloating
592 | */
593 | public void setFloating(boolean mFloating) {
594 | this.mFloating = mFloating;
595 | }
596 |
597 | /**
598 | * Sets the Animations to be used when displaying/removing the Crouton.
599 | * @param inAnimation the Animation resource ID to be used when displaying.
600 | * @param outAnimation the Animation resource ID to be used when removing.
601 | */
602 | public AppMsg setAnimation(int inAnimation, int outAnimation) {
603 | return setAnimation(AnimationUtils.loadAnimation(mActivity, inAnimation),
604 | AnimationUtils.loadAnimation(mActivity, outAnimation));
605 | }
606 |
607 | /**
608 | * Sets the Animations to be used when displaying/removing the Crouton.
609 | * @param inAnimation the Animation to be used when displaying.
610 | * @param outAnimation the Animation to be used when removing.
611 | */
612 | public AppMsg setAnimation(Animation inAnimation, Animation outAnimation) {
613 | mInAnimation = inAnimation;
614 | mOutAnimation = outAnimation;
615 | return this;
616 | }
617 |
618 | /**
619 | * @return
620 | * Current priority
621 | *
622 | * @see #PRIORITY_HIGH
623 | * @see #PRIORITY_NORMAL
624 | * @see #PRIORITY_LOW
625 | */
626 | public int getPriority() {
627 | return mPriority;
628 | }
629 |
630 | /**
631 | *
Set priority for this message
632 | *
Note: This only affects the order in which the messages get shown,
633 | * not the stacking order of the views.
634 | *
635 | *
Example: In the queue there are 3 messages [A, B, C],
636 | * all of them with priority {@link #PRIORITY_NORMAL}, currently message A is being shown
637 | * so we add a new message D with priority {@link #PRIORITY_HIGH}, after A goes away, given that
638 | * D has a higher priority than B an the reset, D will be shown, then once that D is gone,
639 | * B will be shown, and then finally C.
640 | *
641 | * @param priority
642 | * A value indicating priority, although you can use any integer value, usage of already
643 | * defined is highly encouraged.
644 | *
645 | * @see #PRIORITY_HIGH
646 | * @see #PRIORITY_NORMAL
647 | * @see #PRIORITY_LOW
648 | */
649 | public void setPriority(int priority) {
650 | mPriority = priority;
651 | }
652 |
653 | /**
654 | * @return
655 | * Provided parent to add {@link #getView()} to using {@link #getLayoutParams()}.
656 | */
657 | public ViewGroup getParent() {
658 | return mParent;
659 | }
660 |
661 | /**
662 | * Provide a different parent than Activity decor view
663 | * @param parent
664 | * Provided parent to add {@link #getView()} to using {@link #getLayoutParams()}.
665 | *
666 | */
667 | public void setParent(ViewGroup parent) {
668 | mParent = parent;
669 | }
670 |
671 | /**
672 | * Provide a different parent than Activity decor view
673 | *
674 | * @param parentId
675 | * Provided parent id to add {@link #getView()} to using {@link #getLayoutParams()}.
676 | *
677 | */
678 | public void setParent(int parentId) {
679 | setParent((ViewGroup) mActivity.findViewById(parentId));
680 | }
681 |
682 | /**
683 | * The style for a {@link AppMsg}.
684 | *
685 | * @author e.shishkin
686 | */
687 | public static class Style {
688 |
689 | private final int duration;
690 | private final int background;
691 |
692 | /**
693 | * Construct an {@link AppMsg.Style} object.
694 | *
695 | * @param duration How long to display the message. Either
696 | * {@link #LENGTH_SHORT} or {@link #LENGTH_LONG}
697 | * @param resId resource for AppMsg background
698 | */
699 | public Style(int duration, int resId) {
700 | this.duration = duration;
701 | this.background = resId;
702 | }
703 |
704 | /**
705 | * Return the duration in milliseconds.
706 | */
707 | public int getDuration() {
708 | return duration;
709 | }
710 |
711 | /**
712 | * Return the resource id of background.
713 | */
714 | public int getBackground() {
715 | return background;
716 | }
717 |
718 | @Override
719 | public boolean equals(Object o) {
720 | if (!(o instanceof AppMsg.Style)) {
721 | return false;
722 | }
723 | Style style = (Style) o;
724 | return style.duration == duration
725 | && style.background == background;
726 | }
727 |
728 | }
729 |
730 | }
731 |
--------------------------------------------------------------------------------
/library/src/com/devspark/appmsg/MsgManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Evgeny Shishkin
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.devspark.appmsg;
18 |
19 | import android.annotation.TargetApi;
20 | import android.app.Activity;
21 | import android.app.Application;
22 | import android.os.Bundle;
23 | import android.os.Handler;
24 | import android.os.Message;
25 | import android.view.View;
26 | import android.view.ViewGroup;
27 | import android.view.animation.Animation;
28 | import android.view.animation.AnimationUtils;
29 |
30 | import java.lang.ref.WeakReference;
31 | import java.util.Collection;
32 | import java.util.Comparator;
33 | import java.util.HashSet;
34 | import java.util.Iterator;
35 | import java.util.LinkedList;
36 | import java.util.PriorityQueue;
37 | import java.util.Queue;
38 | import java.util.WeakHashMap;
39 |
40 | import static android.app.Application.ActivityLifecycleCallbacks;
41 | import static android.os.Build.VERSION.SDK_INT;
42 | import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
43 | import static com.devspark.appmsg.AppMsg.LENGTH_STICKY;
44 |
45 | /**
46 | * @author Evgeny Shishkin
47 | */
48 | class MsgManager extends Handler implements Comparator {
49 |
50 | private static final int MESSAGE_DISPLAY = 0xc2007;
51 | private static final int MESSAGE_ADD_VIEW = 0xc20074dd;
52 | private static final int MESSAGE_REMOVE = 0xc2007de1;
53 |
54 | private static WeakHashMap sManagers;
55 | private static ReleaseCallbacks sReleaseCallbacks;
56 |
57 | private final Queue msgQueue;
58 | private final Queue stickyQueue;
59 |
60 | private MsgManager() {
61 | msgQueue = new PriorityQueue(1, this);
62 | stickyQueue = new LinkedList();
63 | }
64 |
65 | /**
66 | * @return A {@link MsgManager} instance to be used for given {@link android.app.Activity}.
67 | */
68 | static synchronized MsgManager obtain(Activity activity) {
69 | if (sManagers == null) {
70 | sManagers = new WeakHashMap(1);
71 | }
72 | MsgManager manager = sManagers.get(activity);
73 | if (manager == null) {
74 | manager = new MsgManager();
75 | ensureReleaseOnDestroy(activity);
76 | sManagers.put(activity, manager);
77 | }
78 |
79 | return manager;
80 | }
81 |
82 | static void ensureReleaseOnDestroy(Activity activity) {
83 | if (SDK_INT < ICE_CREAM_SANDWICH) {
84 | return;
85 | }
86 | if (sReleaseCallbacks == null) {
87 | sReleaseCallbacks = new ReleaseCallbacksIcs();
88 | }
89 | sReleaseCallbacks.register(activity.getApplication());
90 | }
91 |
92 |
93 | static synchronized void release(Activity activity) {
94 | if (sManagers != null) {
95 | final MsgManager manager = sManagers.remove(activity);
96 | if (manager != null) {
97 | manager.clearAllMsg();
98 | }
99 | }
100 | }
101 |
102 | static synchronized void clearAll() {
103 | if (sManagers != null) {
104 | final Iterator iterator = sManagers.values().iterator();
105 | while (iterator.hasNext()) {
106 | final MsgManager manager = iterator.next();
107 | if (manager != null) {
108 | manager.clearAllMsg();
109 | }
110 | iterator.remove();
111 | }
112 | sManagers.clear();
113 | }
114 | }
115 |
116 | /**
117 | * Inserts a {@link AppMsg} to be displayed.
118 | *
119 | * @param appMsg
120 | */
121 | void add(AppMsg appMsg) {
122 | msgQueue.add(appMsg);
123 | if (appMsg.mInAnimation == null) {
124 | appMsg.mInAnimation = AnimationUtils.loadAnimation(appMsg.getActivity(),
125 | android.R.anim.fade_in);
126 | }
127 | if (appMsg.mOutAnimation == null) {
128 | appMsg.mOutAnimation = AnimationUtils.loadAnimation(appMsg.getActivity(),
129 | android.R.anim.fade_out);
130 | }
131 | displayMsg();
132 | }
133 |
134 | /**
135 | * Removes all {@link AppMsg} from the queue.
136 | */
137 | void clearMsg(AppMsg appMsg) {
138 | if(msgQueue.contains(appMsg) || stickyQueue.contains(appMsg)){
139 | // Avoid the message from being removed twice.
140 | removeMessages(MESSAGE_DISPLAY, appMsg);
141 | removeMessages(MESSAGE_ADD_VIEW, appMsg);
142 | removeMessages(MESSAGE_REMOVE, appMsg);
143 | msgQueue.remove(appMsg);
144 | stickyQueue.remove(appMsg);
145 | removeMsg(appMsg);
146 | }
147 | }
148 |
149 | /**
150 | * Removes all {@link AppMsg} from the queue.
151 | */
152 | void clearAllMsg() {
153 | removeMessages(MESSAGE_DISPLAY);
154 | removeMessages(MESSAGE_ADD_VIEW);
155 | removeMessages(MESSAGE_REMOVE);
156 | clearShowing();
157 | msgQueue.clear();
158 | stickyQueue.clear();
159 | }
160 |
161 | void clearShowing() {
162 | final Collection showing = new HashSet();
163 | obtainShowing(msgQueue, showing);
164 | obtainShowing(stickyQueue, showing);
165 | for (AppMsg msg : showing) {
166 | clearMsg(msg);
167 | }
168 | }
169 |
170 | static void obtainShowing(Collection from, Collection appendTo) {
171 | for (AppMsg msg : from) {
172 | if (msg.isShowing()) {
173 | appendTo.add(msg);
174 | }
175 | }
176 | }
177 |
178 | /**
179 | * Displays the next {@link AppMsg} within the queue.
180 | */
181 | private void displayMsg() {
182 | if (msgQueue.isEmpty()) {
183 | return;
184 | }
185 | // First peek whether the AppMsg is being displayed.
186 | final AppMsg appMsg = msgQueue.peek();
187 | final Message msg;
188 | if (!appMsg.isShowing()) {
189 | // Display the AppMsg
190 | msg = obtainMessage(MESSAGE_ADD_VIEW);
191 | msg.obj = appMsg;
192 | sendMessage(msg);
193 | } else if (appMsg.getDuration() != LENGTH_STICKY) {
194 | msg = obtainMessage(MESSAGE_DISPLAY);
195 | sendMessageDelayed(msg, appMsg.getDuration()
196 | + appMsg.mInAnimation.getDuration() + appMsg.mOutAnimation.getDuration());
197 | }
198 | }
199 |
200 | /**
201 | * Removes the {@link AppMsg}'s view after it's display duration.
202 | *
203 | * @param appMsg The {@link AppMsg} added to a {@link ViewGroup} and should be removed.s
204 | */
205 | private void removeMsg(final AppMsg appMsg) {
206 | clearMsg(appMsg);
207 | final View view = appMsg.getView();
208 | ViewGroup parent = ((ViewGroup) view.getParent());
209 | if (parent != null) {
210 | appMsg.mOutAnimation.setAnimationListener(new OutAnimationListener(appMsg));
211 | view.clearAnimation();
212 | view.startAnimation(appMsg.mOutAnimation);
213 | }
214 |
215 | Message msg = obtainMessage(MESSAGE_DISPLAY);
216 | sendMessage(msg);
217 | }
218 |
219 | private void addMsgToView(AppMsg appMsg) {
220 | View view = appMsg.getView();
221 | if (view.getParent() == null) { // Not added yet
222 | final ViewGroup targetParent = appMsg.getParent();
223 | final ViewGroup.LayoutParams params = appMsg.getLayoutParams();
224 | if (targetParent != null) {
225 | targetParent.addView(view, params);
226 | } else {
227 | appMsg.getActivity().addContentView(view, params);
228 | }
229 | }
230 | view.clearAnimation();
231 | view.startAnimation(appMsg.mInAnimation);
232 | if (view.getVisibility() != View.VISIBLE) {
233 | view.setVisibility(View.VISIBLE);
234 | }
235 |
236 | final int duration = appMsg.getDuration();
237 | if (duration != LENGTH_STICKY) {
238 | final Message msg = obtainMessage(MESSAGE_REMOVE);
239 | msg.obj = appMsg;
240 | sendMessageDelayed(msg, duration);
241 | } else { // We are sticky, we don't get removed just yet
242 | stickyQueue.add(msgQueue.poll());
243 | }
244 | }
245 |
246 | @Override
247 | public void handleMessage(Message msg) {
248 | final AppMsg appMsg;
249 | switch (msg.what) {
250 | case MESSAGE_DISPLAY:
251 | displayMsg();
252 | break;
253 | case MESSAGE_ADD_VIEW:
254 | appMsg = (AppMsg) msg.obj;
255 | addMsgToView(appMsg);
256 | break;
257 | case MESSAGE_REMOVE:
258 | appMsg = (AppMsg) msg.obj;
259 | removeMsg(appMsg);
260 | break;
261 | default:
262 | super.handleMessage(msg);
263 | break;
264 | }
265 | }
266 |
267 | @Override
268 | public int compare(AppMsg lhs, AppMsg rhs) {
269 | return inverseCompareInt(lhs.mPriority, rhs.mPriority);
270 | }
271 |
272 | static int inverseCompareInt(int lhs, int rhs) {
273 | return lhs < rhs ? 1 : (lhs == rhs ? 0 : -1);
274 | }
275 |
276 | private static class OutAnimationListener implements Animation.AnimationListener {
277 |
278 | private final AppMsg appMsg;
279 |
280 | private OutAnimationListener(AppMsg appMsg) {
281 | this.appMsg = appMsg;
282 | }
283 |
284 | @Override
285 | public void onAnimationStart(Animation animation) {
286 |
287 | }
288 |
289 | @Override
290 | public void onAnimationEnd(Animation animation) {
291 | final View view = appMsg.getView();
292 | if (appMsg.isFloating()) {
293 | final ViewGroup parent = ((ViewGroup) view.getParent());
294 | if (parent != null) {
295 | parent.post(new Runnable() { // One does not simply removeView
296 | @Override
297 | public void run() {
298 | parent.removeView(view);
299 | }
300 | });
301 | }
302 | } else {
303 | view.setVisibility(View.GONE);
304 | }
305 | }
306 |
307 | @Override
308 | public void onAnimationRepeat(Animation animation) {
309 |
310 | }
311 | }
312 |
313 | interface ReleaseCallbacks {
314 | void register(Application application);
315 | }
316 |
317 | @TargetApi(ICE_CREAM_SANDWICH)
318 | static class ReleaseCallbacksIcs implements ActivityLifecycleCallbacks, ReleaseCallbacks {
319 | private WeakReference mLastApp;
320 | public void register(Application app) {
321 | if (mLastApp != null && mLastApp.get() == app) {
322 | return; // Already registered with this app
323 | } else {
324 | mLastApp = new WeakReference(app);
325 | }
326 | app.registerActivityLifecycleCallbacks(this);
327 | }
328 |
329 | @Override
330 | public void onActivityDestroyed(Activity activity) {
331 | release(activity);
332 | }
333 | @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) {}
334 | @Override public void onActivityStarted(Activity activity) {}
335 | @Override public void onActivityResumed(Activity activity) {}
336 | @Override public void onActivityPaused(Activity activity) {}
337 | @Override public void onActivityStopped(Activity activity) {}
338 | @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) {}
339 | }
340 | }
--------------------------------------------------------------------------------
/sample/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 7
9 | targetSdkVersion 21
10 | versionCode 5
11 | versionName "1.2.0"
12 | }
13 |
14 | sourceSets {
15 | main {
16 | manifest.srcFile 'AndroidManifest.xml'
17 | java.srcDirs = ['src']
18 | res.srcDirs = ['res']
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile project(':library')
25 | compile 'com.android.support:appcompat-v7:21.0.2'
26 | }
--------------------------------------------------------------------------------
/sample/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnkil/Android-AppMsg/1fbca8f7b432894844b660cbc98a183c9b755dbf/sample/ic_launcher-web.png
--------------------------------------------------------------------------------
/sample/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 | android.library.reference.1=../library
16 |
--------------------------------------------------------------------------------
/sample/res/drawable-hdpi/ic_action_cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnkil/Android-AppMsg/1fbca8f7b432894844b660cbc98a183c9b755dbf/sample/res/drawable-hdpi/ic_action_cancel.png
--------------------------------------------------------------------------------
/sample/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnkil/Android-AppMsg/1fbca8f7b432894844b660cbc98a183c9b755dbf/sample/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/res/drawable-ldpi/ic_action_cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnkil/Android-AppMsg/1fbca8f7b432894844b660cbc98a183c9b755dbf/sample/res/drawable-ldpi/ic_action_cancel.png
--------------------------------------------------------------------------------
/sample/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnkil/Android-AppMsg/1fbca8f7b432894844b660cbc98a183c9b755dbf/sample/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/res/drawable-mdpi/ic_action_cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnkil/Android-AppMsg/1fbca8f7b432894844b660cbc98a183c9b755dbf/sample/res/drawable-mdpi/ic_action_cancel.png
--------------------------------------------------------------------------------
/sample/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnkil/Android-AppMsg/1fbca8f7b432894844b660cbc98a183c9b755dbf/sample/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/res/drawable-xhdpi/ic_action_cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnkil/Android-AppMsg/1fbca8f7b432894844b660cbc98a183c9b755dbf/sample/res/drawable-xhdpi/ic_action_cancel.png
--------------------------------------------------------------------------------
/sample/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnkil/Android-AppMsg/1fbca8f7b432894844b660cbc98a183c9b755dbf/sample/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/res/drawable/ic_action_cancel_inset.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/sample/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
15 |
16 |
23 |
32 |
39 |
48 |
49 |
54 |
55 |
62 |
63 |
68 |
69 |
75 |
76 |
82 |
83 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/sample/res/layout/sticky.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
18 |
19 |
20 |
32 |
33 |
--------------------------------------------------------------------------------
/sample/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
--------------------------------------------------------------------------------
/sample/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | @string/alert
5 | @string/confirm
6 | @string/info
7 | @string/custom
8 | @string/sticky
9 |
10 |
11 |
12 | @string/high
13 | @string/normal
14 | @string/low
15 |
16 |
--------------------------------------------------------------------------------
/sample/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #ff0099CC
5 | #ffffcd5a
6 |
7 |
--------------------------------------------------------------------------------
/sample/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Android-AppMsg
4 | Alert
5 | Confirm
6 | Info
7 | Custom
8 | Sticky
9 | Show at bottom of screen
10 | Remove
11 | Cancel All
12 | High
13 | Normal
14 | Low
15 | Show AppMsg!
16 | Style
17 | Priority
18 | Your message here
19 | Custom parent
20 |
21 |
--------------------------------------------------------------------------------
/sample/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
--------------------------------------------------------------------------------
/sample/src/com/devspark/appmsg/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Evgeny Shishkin
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.devspark.appmsg.sample;
18 |
19 | import android.animation.LayoutTransition;
20 | import android.annotation.TargetApi;
21 | import android.os.Bundle;
22 | import android.support.v7.app.ActionBarActivity;
23 | import android.view.View;
24 | import android.view.ViewGroup;
25 | import android.widget.CheckBox;
26 | import android.widget.CompoundButton;
27 | import android.widget.EditText;
28 | import android.widget.Spinner;
29 |
30 | import com.devspark.appmsg.AppMsg;
31 |
32 | import static android.os.Build.VERSION.SDK_INT;
33 | import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
34 | import static android.os.Build.VERSION_CODES.JELLY_BEAN;
35 | import static android.text.TextUtils.isEmpty;
36 | import static android.view.Gravity.BOTTOM;
37 | import static android.view.View.GONE;
38 | import static android.view.View.VISIBLE;
39 | import static com.devspark.appmsg.AppMsg.LENGTH_SHORT;
40 | import static com.devspark.appmsg.AppMsg.LENGTH_STICKY;
41 |
42 | /**
43 | * Sample of AppMsg library.
44 | *
45 | * @author Evgeny Shishkin
46 | */
47 | public class MainActivity extends ActionBarActivity {
48 | private static final int NORMAL_POSITION = 1;
49 | private static final int INFO_POSITION = 2;
50 |
51 | private int mMsgCount;
52 | private Spinner mStyle;
53 | private Spinner mPriority;
54 | private EditText mProvidedMsg;
55 | private CheckBox mBottom;
56 | private CheckBox mParent;
57 | private ViewGroup mAltParent;
58 |
59 | @Override
60 | public void onCreate(Bundle savedInstanceState) {
61 | super.onCreate(savedInstanceState);
62 | setContentView(R.layout.activity_main);
63 |
64 | mProvidedMsg = (EditText) findViewById(R.id.provided_txt);
65 | mStyle = (Spinner) findViewById(R.id.style_spnr);
66 | mStyle.setSelection(INFO_POSITION);
67 | mPriority = (Spinner) findViewById(R.id.priority_spnr);
68 | mPriority.setSelection(NORMAL_POSITION);
69 | mBottom = (CheckBox) findViewById(R.id.bottom);
70 | mParent = (CheckBox) findViewById(R.id.parent_chk);
71 | mAltParent = (ViewGroup) findViewById(R.id.alt_parent);
72 |
73 | mParent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
74 | @Override
75 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
76 | mAltParent.setVisibility(isChecked ? VISIBLE : GONE);
77 | mBottom.setVisibility(isChecked ? GONE : VISIBLE);
78 | }
79 | });
80 |
81 | if (SDK_INT >= JELLY_BEAN) {
82 | enableChangingTransition();
83 | }
84 | }
85 |
86 | @TargetApi(JELLY_BEAN)
87 | private void enableChangingTransition() {
88 | ViewGroup animatedRoot = (ViewGroup) findViewById(R.id.animated_root);
89 | animatedRoot.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
90 | }
91 |
92 | /**
93 | * Button onClick listener.
94 | *
95 | * @param v
96 | */
97 | public void buttonClick(View v) {
98 | switch (v.getId()) {
99 | case R.id.show:
100 | showAppMsg();
101 | break;
102 | case R.id.cancel_all:
103 | AppMsg.cancelAll(this);
104 | break;
105 | default:
106 | return;
107 | }
108 | }
109 |
110 | private void showAppMsg() {
111 | mMsgCount++;
112 | final int styleSelected = mStyle.getSelectedItemPosition();
113 | final int priority = positionToPriority(mPriority.getSelectedItemPosition());
114 | final CharSequence providedMsg = mProvidedMsg.getText();
115 | final CharSequence msg = isEmpty(providedMsg)
116 | ? new StringBuilder().append(mStyle.getSelectedItem())
117 | .append(" ").append(mPriority.getSelectedItem())
118 | .append(" msg#").append(mMsgCount).toString()
119 | : providedMsg;
120 | final AppMsg.Style style;
121 | boolean customAnimations = false;
122 | AppMsg provided = null;
123 | switch (styleSelected) {
124 | case 0:
125 | style = AppMsg.STYLE_ALERT;
126 | break;
127 | case 1:
128 | style = AppMsg.STYLE_CONFIRM;
129 | break;
130 | case 3:
131 | style = new AppMsg.Style(LENGTH_SHORT, R.color.custom);
132 | customAnimations = true;
133 | break;
134 | case 4:
135 | style = new AppMsg.Style(LENGTH_STICKY, R.color.sticky);
136 | provided = AppMsg.makeText(this, msg, style, R.layout.sticky);
137 | provided.getView()
138 | .findViewById(R.id.remove_btn)
139 | .setOnClickListener(new CancelAppMsg(provided));
140 | break;
141 | default:
142 | style = AppMsg.STYLE_INFO;
143 | break;
144 | }
145 | // create {@link AppMsg} with specify type
146 | AppMsg appMsg = provided != null ? provided : AppMsg.makeText(this, msg, style);
147 | appMsg.setPriority(priority);
148 | if (mParent.isChecked()) {
149 | appMsg.setParent(mAltParent);
150 | } else {
151 | if (mBottom.isChecked()) {
152 | appMsg.setLayoutGravity(BOTTOM);
153 | }
154 | }
155 |
156 | if (customAnimations) {
157 | appMsg.setAnimation(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
158 | }
159 | appMsg.show();
160 |
161 | }
162 |
163 | private static int positionToPriority(int selectedItemPosition) {
164 | switch (selectedItemPosition) {
165 | case 0:
166 | return AppMsg.PRIORITY_HIGH;
167 | case 2:
168 | return AppMsg.PRIORITY_LOW;
169 | default:
170 | return AppMsg.PRIORITY_NORMAL;
171 | }
172 | }
173 |
174 | @Override
175 | protected void onPause() {
176 | super.onPause();
177 | // This is optional for 14+,
178 | // also you may want to call it at your later convenience, e.g. onDestroy
179 | if (SDK_INT < ICE_CREAM_SANDWICH) {
180 | AppMsg.cancelAll(this);
181 | }
182 | }
183 |
184 | static class CancelAppMsg implements View.OnClickListener {
185 | private final AppMsg mAppMsg;
186 |
187 | CancelAppMsg(AppMsg appMsg) {
188 | mAppMsg = appMsg;
189 | }
190 |
191 | @Override
192 | public void onClick(View v) {
193 | mAppMsg.cancel();
194 | }
195 | }
196 | }
197 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'library'
2 | include 'sample'
3 |
--------------------------------------------------------------------------------