├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── merkmod
│ │ │ └── myapplication
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── merkmod
│ │ │ └── myapplication
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── merkmod
│ │ └── myapplication
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── achievementtoastlibrary
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── attrs.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── merkmod
│ │ │ └── achievementtoastlibrary
│ │ │ ├── Utils.java
│ │ │ ├── AchievementToast.java
│ │ │ └── AchievementToastView.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── merkmod
│ │ │ └── achievementtoastlibrary
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── merkmod
│ │ └── achievementtoastlibrary
│ │ └── ExampleInstrumentedTest.java
├── blobs
│ └── AchievementToast.gif
├── libs
│ ├── armeabi
│ │ ├── libusb-1.0.so
│ │ ├── libftrScanAPI.so
│ │ ├── libftrWSQAndroid.so
│ │ ├── libftrWSQAndroidJni.so
│ │ └── libftrScanApiAndroidJni.so
│ └── armeabi-v7a
│ │ ├── libusb-1.0.so
│ │ ├── libftrScanAPI.so
│ │ ├── libftrWSQAndroid.so
│ │ ├── libftrWSQAndroidJni.so
│ │ └── libftrScanApiAndroidJni.so
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/achievementtoastlibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':achievementtoastlibrary'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/achievementtoastlibrary/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/achievementtoastlibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AchievementToastlibrary
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/achievementtoastlibrary/blobs/AchievementToast.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/achievementtoastlibrary/blobs/AchievementToast.gif
--------------------------------------------------------------------------------
/achievementtoastlibrary/libs/armeabi/libusb-1.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/achievementtoastlibrary/libs/armeabi/libusb-1.0.so
--------------------------------------------------------------------------------
/achievementtoastlibrary/libs/armeabi/libftrScanAPI.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/achievementtoastlibrary/libs/armeabi/libftrScanAPI.so
--------------------------------------------------------------------------------
/achievementtoastlibrary/libs/armeabi-v7a/libusb-1.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/achievementtoastlibrary/libs/armeabi-v7a/libusb-1.0.so
--------------------------------------------------------------------------------
/achievementtoastlibrary/libs/armeabi/libftrWSQAndroid.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/achievementtoastlibrary/libs/armeabi/libftrWSQAndroid.so
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/achievementtoastlibrary/libs/armeabi-v7a/libftrScanAPI.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/achievementtoastlibrary/libs/armeabi-v7a/libftrScanAPI.so
--------------------------------------------------------------------------------
/achievementtoastlibrary/libs/armeabi-v7a/libftrWSQAndroid.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/achievementtoastlibrary/libs/armeabi-v7a/libftrWSQAndroid.so
--------------------------------------------------------------------------------
/achievementtoastlibrary/libs/armeabi/libftrWSQAndroidJni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/achievementtoastlibrary/libs/armeabi/libftrWSQAndroidJni.so
--------------------------------------------------------------------------------
/achievementtoastlibrary/libs/armeabi-v7a/libftrWSQAndroidJni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/achievementtoastlibrary/libs/armeabi-v7a/libftrWSQAndroidJni.so
--------------------------------------------------------------------------------
/achievementtoastlibrary/libs/armeabi/libftrScanApiAndroidJni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/achievementtoastlibrary/libs/armeabi/libftrScanApiAndroidJni.so
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Achievement Toast Sample
3 | With all
4 |
5 |
--------------------------------------------------------------------------------
/achievementtoastlibrary/libs/armeabi-v7a/libftrScanApiAndroidJni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkodekar/AchievementToast/HEAD/achievementtoastlibrary/libs/armeabi-v7a/libftrScanApiAndroidJni.so
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/achievementtoastlibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/merkmod/myapplication/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.merkmod.myapplication;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/achievementtoastlibrary/src/test/java/com/merkmod/achievementtoastlibrary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.merkmod.achievementtoastlibrary;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/achievementtoastlibrary/src/main/java/com/merkmod/achievementtoastlibrary/Utils.java:
--------------------------------------------------------------------------------
1 | package com.merkmod.achievementtoastlibrary;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by rkodekar on 28/11/16.
7 | */
8 |
9 | public class Utils {
10 |
11 | public static int dp2px(Context context, float dpValue) {
12 | final float scale = context.getResources().getDisplayMetrics().density;
13 | return (int) (dpValue * scale + 0.5f);
14 | }
15 |
16 | public static int sp2px(Context context, float spValue) {
17 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
18 | return (int) (spValue * fontScale + 0.5f);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /opt/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/achievementtoastlibrary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /opt/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/achievementtoastlibrary/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/merkmod/myapplication/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.merkmod.myapplication;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.merkmod.myapplication", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/achievementtoastlibrary/src/androidTest/java/com/merkmod/achievementtoastlibrary/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.merkmod.achievementtoastlibrary;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.merkmod.achievementtoastlibrary.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 |
4 | android {
5 | compileSdkVersion 25
6 | buildToolsVersion "25.0.0"
7 | defaultConfig {
8 | applicationId "com.merkmod.myapplication"
9 | minSdkVersion 17
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(include: ['*.jar'], dir: 'libs')
25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
26 | exclude group: 'com.android.support', module: 'support-annotations'
27 | })
28 | compile 'com.android.support:appcompat-v7:25.0.1'
29 | testCompile 'junit:junit:4.12'
30 | compile project(':achievementtoastlibrary')
31 | }
32 |
--------------------------------------------------------------------------------
/achievementtoastlibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 |
4 | group='com.github.mkodekar'
5 |
6 | android {
7 | compileSdkVersion 25
8 | buildToolsVersion "25.0.0"
9 |
10 | defaultConfig {
11 | minSdkVersion 17
12 | targetSdkVersion 25
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | compile fileTree(include: ['*.jar'], dir: 'libs')
28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
29 | exclude group: 'com.android.support', module: 'support-annotations'
30 | })
31 | compile 'com.android.support:appcompat-v7:25.0.1'
32 | testCompile 'junit:junit:4.12'
33 | compile 'com.nineoldandroids:library:2.4.0'
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
24 |
25 |
32 |
33 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AchievementToast
2 |
3 | Alternative to show Toast or an alert message just inside your activity.
4 |
5 | It follows any view group but wont display outside your Activity.
6 |
7 | ##Preview
8 | 
9 |
10 | ##Credits
11 |
12 | code-mc
13 | https://github.com/code-mc/loadtoast
14 |
15 | slightly based on the same concept.
16 |
17 |
18 | ##Dependency
19 |
20 | Add this in your root gradle / in simple word the project level gradle file
21 |
22 | under allprojects
23 |
24 | ```
25 | repositories {
26 | maven { url 'https://jitpack.io' }
27 | }
28 | ```
29 | and in app level gradle file under dependencies
30 |
31 | ```
32 | compile 'com.github.mkodekar:AchievementToast:0.1'
33 | ```
34 |
35 | Grab the above demo app from here :
36 |
37 | [](https://play.google.com/store/apps/details?id=com.merkmod.myapplication)
38 |
39 | ##Usage
40 | Just use it as you use toast but unlike toast it has multiple method inferences / implementation
41 | please refer to the sample app for more details.
42 |
43 |
44 | ## Contributing
45 |
46 | Please fork this repository and contribute back using
47 | [pull requests](https://github.com/mkodekar/AchievementToast/pulls).
48 |
49 | Any contributions, large or small, major features, bug fixes, are welcomed and appreciated
50 | but will be thoroughly reviewed .
51 |
52 | ## License
53 |
54 | * [Apache Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
55 |
56 | ```
57 | Copyright 2016 Mohhamad Rehan Kodekar
58 |
59 | Licensed under the Apache License, Version 2.0 (the "License");
60 | you may not use this file except in compliance with the License.
61 | You may obtain a copy of the License at
62 |
63 | http://www.apache.org/licenses/LICENSE-2.0
64 |
65 | Unless required by applicable law or agreed to in writing, software
66 | distributed under the License is distributed on an "AS IS" BASIS,
67 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
68 | See the License for the specific language governing permissions and
69 | limitations under the License.
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/merkmod/myapplication/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.merkmod.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import com.merkmod.achievementtoastlibrary.AchievementToast;
9 |
10 | public class MainActivity extends AppCompatActivity {
11 |
12 | Button all, withicon, normal, withouticon;
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 | all = (Button) findViewById(R.id.button);
19 | normal = (Button) findViewById(R.id.button2);
20 | withicon = (Button) findViewById(R.id.button3);
21 | withouticon = (Button) findViewById(R.id.button4);
22 | all.setOnClickListener(new View.OnClickListener() {
23 | @Override
24 | public void onClick(View view) {
25 | AchievementToast.makeAchievement(MainActivity.this, getResources(), R.string.with_all,
26 | AchievementToast.LENGTH_MEDIUM, android.R.color.white, R.color.colorPrimary, getResources().getDrawable(R.mipmap.ic_launcher))
27 | .show();
28 | }
29 | });
30 |
31 | normal.setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View view) {
34 | AchievementToast.makeAchievement(MainActivity.this, "normal", AchievementToast.LENGTH_SHORT).show();
35 | }
36 | });
37 |
38 | withicon.setOnClickListener(new View.OnClickListener() {
39 | @Override
40 | public void onClick(View view) {
41 | AchievementToast.makeAchievement(MainActivity.this, "with icon", AchievementToast.LENGTH_SHORT, getResources().getDrawable(R.mipmap.ic_launcher)).show();
42 | }
43 | });
44 |
45 | withouticon.setOnClickListener(new View.OnClickListener() {
46 | @Override
47 | public void onClick(View view) {
48 | AchievementToast.makeAchievement(MainActivity.this, "without icon",
49 | AchievementToast.LENGTH_MEDIUM, android.R.color.white, R.color.colorPrimary)
50 | .show();
51 | }
52 | });
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | Android > Lint > Correctness
39 |
40 |
41 | Android > Lint > Performance
42 |
43 |
44 | Android > Lint > Usability
45 |
46 |
47 | Code maturity issuesJava
48 |
49 |
50 | Code style issuesJava
51 |
52 |
53 | Error handlingJava
54 |
55 |
56 | J2ME issuesJava
57 |
58 |
59 | JUnit issuesJava
60 |
61 |
62 | Java
63 |
64 |
65 | Logging issuesJava
66 |
67 |
68 | Threading issuesJava
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/achievementtoastlibrary/src/main/java/com/merkmod/achievementtoastlibrary/AchievementToast.java:
--------------------------------------------------------------------------------
1 | package com.merkmod.achievementtoastlibrary;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.graphics.Color;
7 | import android.graphics.drawable.Drawable;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.view.ViewTreeObserver;
11 | import android.view.animation.AccelerateInterpolator;
12 | import android.view.animation.AnticipateOvershootInterpolator;
13 | import android.view.animation.DecelerateInterpolator;
14 | import android.widget.LinearLayout;
15 | import android.widget.RelativeLayout;
16 |
17 | import com.nineoldandroids.animation.Animator;
18 | import com.nineoldandroids.view.ViewHelper;
19 | import com.nineoldandroids.view.ViewPropertyAnimator;
20 |
21 | /**
22 | * Created by rkodekar on 27/11/16.
23 | */
24 |
25 | public class AchievementToast implements AchievementToastView.AnimationEndListener{
26 |
27 | public static long LENGTH_SHORT = 1000;
28 | public static long LENGTH_MEDIUM = 2000;
29 | public static long LENGTH_LONG = 3000;
30 |
31 | private AchievementToastView achievementToastView;
32 | private ViewGroup parentView;
33 | private int translationY = 0;
34 | private boolean showCalled = false;
35 | private boolean mToastCanceled = false;
36 | private boolean mInflated = false;
37 | private boolean mVisible = false;
38 |
39 | public AchievementToast setBackgroundColor(Resources resources, int color) {
40 | String strColor = String.format("#%06X", 0xFFFFFF & resources.getColor(color));
41 | System.out.println("strcolor is " + strColor);
42 | achievementToastView.setBackgroundColorRes(Color.parseColor(strColor));
43 | return this;
44 | }
45 |
46 | public AchievementToast setBackgroundColor(int color) {
47 | achievementToastView.setBackgroundColor(color);
48 | return this;
49 | }
50 |
51 | public AchievementToast setDuration(long duration) {
52 | achievementToastView.setDuration(duration);
53 | return this;
54 | }
55 |
56 |
57 | public AchievementToast setText(String text) {
58 | achievementToastView.setText(text);
59 | return this;
60 | }
61 |
62 | public AchievementToast setTextColor(Resources resources, int colorid) {
63 | String strColor = String.format("#%06X", 0xFFFFFF & resources.getColor(colorid));
64 | System.out.println("strcolor is " + strColor);
65 | achievementToastView.setTextColor(Color.parseColor(strColor));
66 | return this;
67 | }
68 |
69 | public AchievementToast setTextColor(int color) {
70 | achievementToastView.setTextColor(color);
71 | return this;
72 | }
73 |
74 | public AchievementToast setIcon(Drawable icon) {
75 | achievementToastView.setIcon(icon);
76 | return this;
77 | }
78 |
79 | public AchievementToast setTranslationY(int pixels){
80 | translationY = pixels;
81 | return this;
82 | }
83 |
84 | public AchievementToast(Context context) {
85 | achievementToastView = new AchievementToastView(context);
86 | parentView = (ViewGroup) ((Activity) context).getWindow().getDecorView().findViewById(android.R.id.content);
87 | ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
88 | parentView.addView(achievementToastView, params);
89 | ViewHelper.setAlpha(achievementToastView, 0);
90 | parentView.postDelayed(new Runnable() {
91 | @Override
92 | public void run() {
93 | ViewHelper.setTranslationX(achievementToastView, (parentView.getWidth() - achievementToastView.getWidth()) / 2);
94 | ViewHelper.setTranslationY(achievementToastView, -achievementToastView.getHeight() + translationY);
95 | mInflated = true;
96 | if(!mToastCanceled && showCalled) show();
97 | }
98 | },1);
99 |
100 | parentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
101 | @Override
102 | public void onGlobalLayout() {
103 | checkZPosition();
104 | }
105 | });
106 |
107 | achievementToastView.setAnimationEndListener(this);
108 |
109 | }
110 |
111 | public AchievementToast show(){
112 | if(!mInflated){
113 | showCalled = true;
114 | return this;
115 | }
116 | achievementToastView.show();
117 | ViewHelper.setTranslationX(achievementToastView, (parentView.getWidth() - achievementToastView.getWidth()) / 2);
118 | ViewHelper.setAlpha(achievementToastView, 0f);
119 | ViewHelper.setTranslationY(achievementToastView, -achievementToastView.getHeight() + translationY);
120 | achievementToastView.setVisibility(View.VISIBLE);
121 | ViewPropertyAnimator.animate(achievementToastView).alpha(1f).translationY(25 + translationY)
122 | .setInterpolator(new DecelerateInterpolator())
123 | .setDuration(300).setStartDelay(0).start();
124 | checkZPosition();
125 |
126 | return this;
127 | }
128 |
129 | private void checkZPosition(){
130 | // If the toast isn't visible, no point in updating all the views
131 | if(!mVisible) return;
132 |
133 | int pos = parentView.indexOfChild(achievementToastView);
134 | int count = parentView.getChildCount();
135 | if(pos != count-1){
136 | ((ViewGroup) achievementToastView.getParent()).removeView(achievementToastView);
137 | parentView.requestLayout();
138 | parentView.addView(achievementToastView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
139 | ViewGroup.LayoutParams.WRAP_CONTENT));
140 | }
141 | }
142 |
143 | private void slideUp(){
144 | ViewPropertyAnimator viewPropertyAnimator = ViewPropertyAnimator.animate(achievementToastView).setStartDelay(1000).alpha(0f)
145 | .translationY(-achievementToastView.getHeight() + translationY)
146 | .setInterpolator(new AnticipateOvershootInterpolator())
147 | .setDuration(300);
148 | viewPropertyAnimator.start();
149 | }
150 |
151 | @Override
152 | public void onAnimationEndListener() {
153 | slideUp();
154 |
155 | }
156 | // with drawable
157 | public static AchievementToast makeAchievement(Context context, Resources resources, String text, long duration, int textcolor, int bacgroundColor, Drawable icon) {
158 | return new AchievementToast(context).setText(text).setDuration(duration).setTextColor(resources,textcolor).setBackgroundColor(resources, bacgroundColor).setIcon(icon);
159 | }
160 |
161 | public static AchievementToast makeAchievement(Context context, Resources resources, int resid, long duration, int textcolor, int bacgroundColor, Drawable icon) {
162 | return new AchievementToast(context).setText(context.getResources().getString(resid)).setDuration(duration).setTextColor(resources,textcolor).setBackgroundColor(resources, bacgroundColor).setIcon(icon);
163 | }
164 |
165 |
166 | public static AchievementToast makeAchievement(Context context, String text, long duration, int textcolor, int bacgroundColor, Drawable icon) {
167 | return new AchievementToast(context).setText(text).setDuration(duration).setTextColor(context.getResources(),textcolor).setBackgroundColor(context.getResources(), bacgroundColor).setIcon(icon);
168 | }
169 |
170 | public static AchievementToast makeAchievement(Context context, int resid, long duration, int textcolor, int bacgroundColor, Drawable icon) {
171 | return new AchievementToast(context).setText(context.getResources().getString(resid)).setDuration(duration).setTextColor(context.getResources(),textcolor).setBackgroundColor(context.getResources(), bacgroundColor).setIcon(icon);
172 | }
173 |
174 |
175 | public static AchievementToast makeAchievement(Context context, String text, long duration,Drawable icon) {
176 | return new AchievementToast(context).setText(text).setDuration(duration).setIcon(icon);
177 | }
178 |
179 | public static AchievementToast makeAchievement(Context context, int resid, long duration,Drawable icon) {
180 | return new AchievementToast(context).setText(context.getResources().getString(resid)).setDuration(duration).setIcon(icon);
181 | }
182 |
183 | // without drawable
184 |
185 | public static AchievementToast makeAchievement(Context context, Resources resources, String text, long duration, int textcolor, int bacgroundColor) {
186 | return new AchievementToast(context).setText(text).setDuration(duration).setTextColor(resources,textcolor).setBackgroundColor(resources, bacgroundColor);
187 | }
188 |
189 | public static AchievementToast makeAchievement(Context context, Resources resources, int resid, long duration, int textcolor, int bacgroundColor) {
190 | return new AchievementToast(context).setText(context.getResources().getString(resid)).setDuration(duration).setTextColor(resources,textcolor).setBackgroundColor(resources, bacgroundColor);
191 | }
192 |
193 |
194 | public static AchievementToast makeAchievement(Context context, String text, long duration, int textcolor, int bacgroundColor) {
195 | return new AchievementToast(context).setText(text).setDuration(duration).setTextColor(context.getResources(),textcolor).setBackgroundColor(context.getResources(), bacgroundColor);
196 | }
197 |
198 | public static AchievementToast makeAchievement(Context context, int resid, long duration, int textcolor, int bacgroundColor) {
199 | return new AchievementToast(context).setText(context.getResources().getString(resid)).setDuration(duration).setTextColor(context.getResources(),textcolor).setBackgroundColor(context.getResources(), bacgroundColor);
200 | }
201 |
202 | public static AchievementToast makeAchievement(Context context, String text, long duration) {
203 | return new AchievementToast(context).setText(text).setDuration(duration);
204 | }
205 |
206 | public static AchievementToast makeAchievement(Context context, int resid, long duration) {
207 | return new AchievementToast(context).setText(context.getResources().getString(resid)).setDuration(duration);
208 | }
209 |
210 | }
211 |
212 |
--------------------------------------------------------------------------------
/achievementtoastlibrary/src/main/java/com/merkmod/achievementtoastlibrary/AchievementToastView.java:
--------------------------------------------------------------------------------
1 | package com.merkmod.achievementtoastlibrary;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.Path;
10 | import android.graphics.Rect;
11 | import android.graphics.RectF;
12 | import android.graphics.drawable.Drawable;
13 | import android.view.View;
14 | import android.view.animation.DecelerateInterpolator;
15 | import android.view.animation.LinearInterpolator;
16 |
17 |
18 | /**
19 | * Created by rkodekar on 27/11/16.
20 | */
21 |
22 | public class AchievementToastView extends View {
23 |
24 | private AnimationEndListener animationEndListener;
25 |
26 | private boolean outOfBounds;
27 |
28 | private String text = "";
29 |
30 | private Drawable icon;
31 |
32 | private long previousUpdate = 0;
33 |
34 | private Rect iconBounds = new Rect();
35 | private Rect textBounds = new Rect();
36 |
37 | private int TEXT_WIDTH = 140; // in DP
38 | private int TEXT_SIZE = 24;
39 | private int ICON_WIDTH = 40;
40 | private int TOAST_HEIGHT = 60;
41 | private int LINE_WIDTH = 3;
42 | private float WIDTH_SCALE = 0f;
43 | private int MARQUE_STEP = 1;
44 |
45 |
46 | private ValueAnimator valueAnimator;
47 | private Path toastPath = new Path();
48 | Paint textPaint = new Paint();
49 |
50 | private RectF iconRect = new RectF();
51 |
52 |
53 | Paint backPaint = new Paint();
54 | private int result;
55 |
56 | public void setDuration(long duration) {
57 | valueAnimator.setDuration(duration);
58 | }
59 |
60 | public void setBackgroundColorRes(int backgroundColorRes) {
61 | backPaint.setColor(backgroundColorRes);
62 | iconPaint.setColor(backgroundColorRes);
63 | }
64 |
65 |
66 | public void setTextColor(int textColor) {
67 | textPaint.setColor(textColor);
68 | }
69 |
70 | public void setText(String text) {
71 | this.text = text;
72 | calculateBounds();
73 | }
74 |
75 | public void setIcon(Drawable icon) {
76 | this.icon = icon;
77 | }
78 |
79 | public Drawable getIcon() {
80 | return icon;
81 | }
82 |
83 | Paint iconPaint = new Paint();
84 |
85 | public AchievementToastView(Context context) {
86 | super(context);
87 | textPaint.setTextSize(22);
88 | textPaint.setColor(Color.WHITE);
89 | textPaint.setAntiAlias(true);
90 |
91 | backPaint.setColor(Color.BLACK);
92 | backPaint.setAntiAlias(true);
93 |
94 | iconPaint.setColor(Color.BLACK);
95 | iconPaint.setAntiAlias(true);
96 |
97 | TEXT_WIDTH = Utils.dp2px(context, TEXT_WIDTH);
98 | TEXT_SIZE = Utils.dp2px(context, TEXT_SIZE);
99 | ICON_WIDTH = Utils.dp2px(context, ICON_WIDTH);
100 | TOAST_HEIGHT = Utils.dp2px(context, TOAST_HEIGHT);
101 | LINE_WIDTH = Utils.dp2px(context, LINE_WIDTH);
102 | MARQUE_STEP = Utils.dp2px(context, MARQUE_STEP);
103 |
104 | int padding = (TOAST_HEIGHT - ICON_WIDTH) / 2;
105 | iconBounds = new Rect(TOAST_HEIGHT + TEXT_WIDTH - padding, padding, TOAST_HEIGHT + TEXT_WIDTH - padding + ICON_WIDTH, ICON_WIDTH + padding);
106 |
107 | valueAnimator = ValueAnimator.ofFloat(0, 1);
108 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
109 | @Override
110 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
111 | postInvalidate();
112 | }
113 | });
114 |
115 | valueAnimator.addListener(new AnimatorEndListener() {
116 | @Override
117 | public void onAnimationEnd(Animator animator) {
118 | super.onAnimationEnd(animator);
119 | animationEndListener.onAnimationEndListener();
120 | }
121 | });
122 | valueAnimator.setInterpolator(new LinearInterpolator());
123 | valueAnimator.start();
124 | calculateBounds();
125 | }
126 |
127 |
128 | @Override
129 | protected void onDraw(Canvas canvas) {
130 | super.onDraw(canvas);
131 | float ws = Math.max(1f - WIDTH_SCALE, 0f);
132 | if (text.length() == 0) ws = 0;
133 |
134 | float translateLoad = (1f - ws) * (ICON_WIDTH + TEXT_WIDTH);
135 | float leftMargin = translateLoad / 2;
136 | float textOpactity = Math.max(0, ws * 10f - 9f);
137 | textPaint.setAlpha((int) (textOpactity * 255));
138 |
139 | int circleOffset = (int) (TOAST_HEIGHT * 2 * (Math.sqrt(2) - 1) / 3);
140 | int th = TOAST_HEIGHT;
141 |
142 | float totalWidth;
143 | if (icon != null) {
144 |
145 | totalWidth = leftMargin * 2 + th + ws * (ICON_WIDTH + TEXT_WIDTH) - translateLoad;
146 |
147 | } else {
148 | totalWidth = leftMargin * 2 + th + ws * (TEXT_WIDTH) - translateLoad;
149 | }
150 | toastPath.reset();
151 | toastPath.moveTo(leftMargin + th / 2, 0);
152 | if (icon != null) {
153 | toastPath.rLineTo(ws * (ICON_WIDTH + TEXT_WIDTH), 0);
154 | } else {
155 | toastPath.rLineTo(ws * (TEXT_WIDTH), 0);
156 | }
157 | toastPath.rCubicTo(circleOffset, 0, th / 2, th / 2 - circleOffset, th / 2, th / 2);
158 |
159 | toastPath.rCubicTo(0, circleOffset, circleOffset - th / 2, th / 2, -th / 2, th / 2);
160 | if (icon != null) {
161 | toastPath.rLineTo(ws * (-ICON_WIDTH - TEXT_WIDTH), 0);
162 | } else {
163 | toastPath.rLineTo(ws * (-TEXT_WIDTH), 0);
164 | }
165 | toastPath.rCubicTo(-circleOffset, 0, -th / 2, -th / 2 + circleOffset, -th / 2, -th / 2);
166 | toastPath.rCubicTo(0, -circleOffset, -circleOffset + th / 2, -th / 2, th / 2, -th / 2);
167 | canvas.drawPath(toastPath, backPaint);
168 | toastPath.reset();
169 |
170 | if (icon != null) {
171 | canvas.drawCircle(iconRect.centerX(), iconRect.centerY(), iconRect.height() / 1.9f, backPaint);
172 | icon.setBounds(iconBounds);
173 | icon.draw(canvas);
174 | toastPath.reset();
175 | }
176 |
177 | canvas.save();
178 |
179 | canvas.translate((totalWidth - TOAST_HEIGHT) / 2, 0);
180 | super.onDraw(canvas);
181 | canvas.restore();
182 | int yPos = (int) ((th / 2) - ((textPaint.descent() + textPaint.ascent()) / 2));
183 |
184 | if (outOfBounds) {
185 | float shift = 0;
186 | if (previousUpdate == 0) {
187 | previousUpdate = System.currentTimeMillis();
188 | } else {
189 | shift = ((float) (System.currentTimeMillis() - previousUpdate) / 16f) * MARQUE_STEP;
190 |
191 | if (shift - TEXT_WIDTH > textBounds.width()) {
192 | previousUpdate = 0;
193 | }
194 | }
195 | canvas.clipRect(th / 2, 0, th / 2 + TEXT_WIDTH, TOAST_HEIGHT);
196 | canvas.drawText(text, th / 2 - shift + TEXT_WIDTH, yPos, textPaint);
197 | } else {
198 | canvas.drawText(text, 0, text.length(), th / 2 + (TEXT_WIDTH - textBounds.width()) / 2, yPos, textPaint);
199 | }
200 | }
201 |
202 | private void calculateBounds() {
203 | outOfBounds = false;
204 | previousUpdate = 0;
205 | textPaint.setTextSize(TEXT_SIZE);
206 | textPaint.getTextBounds(text, 0, text.length(), textBounds);
207 | if (textBounds.width() > TEXT_WIDTH) {
208 | int textSize = TEXT_SIZE;
209 | while (textSize > Utils.dp2px(getContext(), 13) && textBounds.width() > TEXT_WIDTH) {
210 | textSize--;
211 | textPaint.setTextSize(textSize);
212 | textPaint.getTextBounds(text, 0, text.length(), textBounds);
213 | }
214 | if (textBounds.width() > TEXT_WIDTH) {
215 | outOfBounds = true;
216 | }
217 | }
218 | }
219 |
220 |
221 | @Override
222 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
223 | setMeasuredDimension(measureWidth(widthMeasureSpec),
224 | measureHeight(heightMeasureSpec));
225 | }
226 |
227 | private int measureWidth(int measureSpec) {
228 | int specMode = MeasureSpec.getMode(measureSpec);
229 | int specSize = MeasureSpec.getSize(measureSpec);
230 |
231 | if (specMode == MeasureSpec.EXACTLY) {
232 | // We were told how big to be
233 | result = specSize;
234 | } else {
235 | // Measure the text
236 |
237 | if (icon != null) {
238 | result = ICON_WIDTH + TEXT_WIDTH + TOAST_HEIGHT;
239 | } else {
240 | result = TEXT_WIDTH + TOAST_HEIGHT;
241 | }
242 | if (specMode == MeasureSpec.AT_MOST) {
243 | // Respect AT_MOST value if that was what is called for by measureSpec
244 | result = Math.min(result, specSize);
245 | }
246 | }
247 |
248 | return result;
249 | }
250 |
251 | private int measureHeight(int measureSpec) {
252 | int specMode = MeasureSpec.getMode(measureSpec);
253 | int specSize = MeasureSpec.getSize(measureSpec);
254 |
255 | if (specMode == MeasureSpec.EXACTLY) {
256 | // We were told how big to be
257 | result = specSize;
258 | } else {
259 | result = TOAST_HEIGHT;
260 | if (specMode == MeasureSpec.AT_MOST) {
261 | result = Math.min(result, specSize);
262 | }
263 | }
264 | return result;
265 | }
266 |
267 | public void show() {
268 | WIDTH_SCALE = 0f;
269 | }
270 |
271 | @Override
272 | protected void onDetachedFromWindow() {
273 | super.onDetachedFromWindow();
274 | if (valueAnimator != null) valueAnimator.removeAllUpdateListeners();
275 | }
276 |
277 |
278 | public abstract class AnimatorEndListener implements Animator.AnimatorListener {
279 |
280 | @Override
281 | public void onAnimationStart(Animator animator) {
282 |
283 | }
284 |
285 | @Override
286 | public void onAnimationEnd(Animator animator) {
287 |
288 | }
289 |
290 | @Override
291 | public void onAnimationCancel(Animator animator) {
292 |
293 | }
294 |
295 | @Override
296 | public void onAnimationRepeat(Animator animator) {
297 |
298 | }
299 | }
300 |
301 | public void setAnimationEndListener(AnimationEndListener animationEndListener) {
302 | this.animationEndListener = animationEndListener;
303 | }
304 |
305 | public interface AnimationEndListener {
306 | void onAnimationEndListener();
307 | }
308 | }
309 |
--------------------------------------------------------------------------------