├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── in
│ │ └── shadowfax
│ │ └── proswipebutton_app
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── in
│ │ │ └── shadowfax
│ │ │ └── proswipebutton_app
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── in
│ └── shadowfax
│ └── proswipebutton_app
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── proSwipeButton_demo.gif
├── proswipebutton
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── in
│ │ └── shadowfax
│ │ └── proswipebutton
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── in
│ │ │ └── shadowfax
│ │ │ └── proswipebutton
│ │ │ ├── Constants.java
│ │ │ ├── ProSwipeButton.java
│ │ │ └── UiUtils.java
│ └── res
│ │ ├── anim
│ │ ├── fade_in.xml
│ │ └── fade_out.xml
│ │ ├── drawable
│ │ ├── ic_cancel_full_24dp.xml
│ │ ├── ic_check_circle_36dp.xml
│ │ └── ic_swipe_right_caret.xml
│ │ ├── layout
│ │ └── view_proswipebtn.xml
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── in
│ └── shadowfax
│ └── proswipebutton
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | <<<<<<< HEAD
39 | .idea/libraries
40 | .idea/*
41 | # Keystore files
42 | *.jks
43 |
44 | # OS generated files #
45 | *.DS_Store
46 |
47 | # Custom Scripts
48 | *.sh
49 | =======
50 | .idea/tasks.xml
51 | .idea/gradle.xml
52 | .idea/dictionaries
53 | .idea/libraries
54 |
55 | # Keystore files
56 | *.jks
57 |
58 | # External native build folder generated in Android Studio 2.2 and later
59 | .externalNativeBuild
60 |
61 | # Google Services (e.g. APIs or Firebase)
62 | google-services.json
63 |
64 | # Freeline
65 | freeline.py
66 | freeline/
67 | freeline_project_description.json
68 | >>>>>>> 98cedaa00402d50dccbcc2562b1978e7b0351e6b
69 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 shadowfaxtech
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DEPRECATED
2 | Pls use an alternative like https://github.com/cortinico/slidetoact
3 |
4 | # ProSwipeButton
5 | A swipe button for Android with a circular progress bar for async operations
6 |
7 | 
8 |
9 | # Gradle
10 | ```
11 | dependencies {
12 | ...
13 | compile 'in.shadowfax:proswipebutton:1.2.2'
14 | }
15 | ```
16 |
17 | # Usage
18 | 1. In your XML layout file, add this custom view
19 | ```xml
20 |
27 | ```
28 |
29 | 2. React to successful swipe on the button by adding a swipe listener
30 | ```java
31 | ProSwipeButton proSwipeBtn = (ProSwipeButton) findViewById(R.id.awesome_btn);
32 | proSwipeBtn.setOnSwipeListener(new ProSwipeButton.OnSwipeListener() {
33 | @Override
34 | public void onSwipeConfirm() {
35 | // user has swiped the btn. Perform your async operation now
36 | new Handler().postDelayed(new Runnable() {
37 | @Override
38 | public void run() {
39 | // task success! show TICK icon in ProSwipeButton
40 | proSwipeBtn.showResultIcon(true); // false if task failed
41 | }
42 | }, 2000);
43 | }
44 | });
45 | ```
46 |
47 | 3. After the async task is completed, tell the ProSwipeButton to show a result icon.
48 | Either a tick for a successful async operation or cross for a failed async operation.
49 |
50 | ```java
51 | proSwipeBtn.showResultIcon(true); //if task succeeds
52 | proSwipeBtn.showResultIcon(false); //if task fails
53 | ```
54 |
55 | # Customizations
56 |
57 | You can customize the button via XML or programatically.
58 |
59 | ```XML
60 |
71 | ```
72 | New: set distance the user must swipe to activate the button.
73 |
74 | ```JAVA
75 | proswipebutton.setSwipeDistance(0.6f);
76 | ```
77 |
78 | Feel free to raise feature requests via the issue tracker for more customizations or just send in a PR :)
79 |
80 | # Sample
81 | Clone the repository and check out the `app` module.
82 |
83 | # License
84 |
85 | ```
86 | MIT License
87 |
88 | Copyright (c) 2017 Shadowfax Technologies
89 |
90 | Permission is hereby granted, free of charge, to any person obtaining a copy
91 | of this software and associated documentation files (the "Software"), to deal
92 | in the Software without restriction, including without limitation the rights
93 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
94 | copies of the Software, and to permit persons to whom the Software is
95 | furnished to do so, subject to the following conditions:
96 |
97 | The above copyright notice and this permission notice shall be included in all
98 | copies or substantial portions of the Software.
99 |
100 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
101 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
102 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
103 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
104 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
105 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
106 | SOFTWARE.
107 | ```
108 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "in.shadowfax.proswipebutton"
7 | minSdkVersion 15
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
24 | exclude group: 'com.android.support', module: 'support-annotations'
25 | })
26 | compile 'com.android.support:appcompat-v7:26.1.0'
27 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
28 | compile project(":proswipebutton")
29 | testCompile 'junit:junit:4.12'
30 | }
31 |
--------------------------------------------------------------------------------
/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 /home/shadow-admin/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/in/shadowfax/proswipebutton_app/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package in.shadowfax.proswipebutton_app;
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("in.shadowfax.proswipebutton", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/in/shadowfax/proswipebutton_app/MainActivity.java:
--------------------------------------------------------------------------------
1 | package in.shadowfax.proswipebutton_app;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | import in.shadowfax.proswipebutton.ProSwipeButton;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_main);
15 |
16 | final ProSwipeButton proSwipeBtn = findViewById(R.id.proswipebutton_main);
17 | final ProSwipeButton proSwipeBtnError = findViewById(R.id.proswipebutton_main_error);
18 | proSwipeBtn.setSwipeDistance(0.5f);
19 |
20 | proSwipeBtn.setOnSwipeListener(new ProSwipeButton.OnSwipeListener() {
21 | @Override
22 | public void onSwipeConfirm() {
23 | // user has swiped the btn. Perform your async operation now
24 | new Handler().postDelayed(new Runnable() {
25 | @Override
26 | public void run() {
27 | proSwipeBtn.showResultIcon(true, false);
28 | }
29 | }, 2000);
30 | }
31 | });
32 |
33 | proSwipeBtnError.setOnSwipeListener(new ProSwipeButton.OnSwipeListener() {
34 | @Override
35 | public void onSwipeConfirm() {
36 | // user has swiped the btn. Perform your async operation now
37 | new Handler().postDelayed(new Runnable() {
38 | @Override
39 | public void run() {
40 | proSwipeBtnError.showResultIcon(false, true);
41 | }
42 | }, 2000);
43 | }
44 | });
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shadowfaxtech/proSwipeButton/99d9e3673e80f6bd5f1b2e7f9cba77dc2d2cd866/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shadowfaxtech/proSwipeButton/99d9e3673e80f6bd5f1b2e7f9cba77dc2d2cd866/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shadowfaxtech/proSwipeButton/99d9e3673e80f6bd5f1b2e7f9cba77dc2d2cd866/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shadowfaxtech/proSwipeButton/99d9e3673e80f6bd5f1b2e7f9cba77dc2d2cd866/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shadowfaxtech/proSwipeButton/99d9e3673e80f6bd5f1b2e7f9cba77dc2d2cd866/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shadowfaxtech/proSwipeButton/99d9e3673e80f6bd5f1b2e7f9cba77dc2d2cd866/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shadowfaxtech/proSwipeButton/99d9e3673e80f6bd5f1b2e7f9cba77dc2d2cd866/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shadowfaxtech/proSwipeButton/99d9e3673e80f6bd5f1b2e7f9cba77dc2d2cd866/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shadowfaxtech/proSwipeButton/99d9e3673e80f6bd5f1b2e7f9cba77dc2d2cd866/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shadowfaxtech/proSwipeButton/99d9e3673e80f6bd5f1b2e7f9cba77dc2d2cd866/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ProSwipeButton
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/in/shadowfax/proswipebutton_app/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package in.shadowfax.proswipebutton_app;
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.0.1'
10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | jcenter()
21 | maven { url "https://maven.google.com" }
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shadowfaxtech/proSwipeButton/99d9e3673e80f6bd5f1b2e7f9cba77dc2d2cd866/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Feb 22 12:35:34 IST 2018
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-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/proSwipeButton_demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shadowfaxtech/proSwipeButton/99d9e3673e80f6bd5f1b2e7f9cba77dc2d2cd866/proSwipeButton_demo.gif
--------------------------------------------------------------------------------
/proswipebutton/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/proswipebutton/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | ext {
4 | bintrayRepo = 'proswipebutton'
5 | bintrayName = 'proswipebutton'
6 |
7 | publishedGroupId = 'in.shadowfax'
8 | libraryName = 'proswipebutton'
9 | artifact = 'proswipebutton'
10 |
11 | libraryDescription = 'A swipe button with progress indicator for Android'
12 |
13 | siteUrl = 'https://github.com/shadowfaxtech/proSwipeButton'
14 | gitUrl = 'https://github.com/shadowfaxtech/proSwipeButton.git'
15 |
16 | libraryVersion = '1.2'
17 |
18 | developerId = 'developerId'
19 | developerName = 'Ishaan Garg'
20 | developerEmail = 'ishaan.garg@shadowfax.in'
21 |
22 | licenseName = 'The MIT License (MIT)'
23 | licenseUrl = 'https://opensource.org/licenses/MIT'
24 | allLicenses = ["MIT"]
25 | }
26 |
27 | android {
28 | compileSdkVersion 26
29 |
30 | defaultConfig {
31 | minSdkVersion 15
32 | targetSdkVersion 26
33 | versionCode 6
34 | versionName "1.2"
35 | vectorDrawables.useSupportLibrary = true
36 |
37 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
38 |
39 | }
40 | buildTypes {
41 | release {
42 | minifyEnabled false
43 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
44 | }
45 | }
46 | }
47 |
48 | dependencies {
49 | implementation fileTree(dir: 'libs', include: ['*.jar'])
50 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
51 | exclude group: 'com.android.support', module: 'support-annotations'
52 | })
53 | implementation 'com.android.support:appcompat-v7:26.1.0'
54 | testImplementation 'junit:junit:4.12'
55 | }
56 |
57 | apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/installv.gradle'
58 | apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/bintrayv.gradle'
59 |
--------------------------------------------------------------------------------
/proswipebutton/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/shadow-admin/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/proswipebutton/src/androidTest/java/in/shadowfax/proswipebutton/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package in.shadowfax.proswipebutton;
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("in.shadowfax.proswipebutton.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/java/in/shadowfax/proswipebutton/Constants.java:
--------------------------------------------------------------------------------
1 | package in.shadowfax.proswipebutton;
2 |
3 | import static in.shadowfax.proswipebutton.UiUtils.dpToPx;
4 |
5 | /**
6 | * Created by shadow-admin on 22/2/18.
7 | */
8 |
9 | public class Constants {
10 |
11 | public static final float DEFAULT_TEXT_SIZE = dpToPx(14);
12 | public static final float DEFAULT_SWIPE_DISTANCE = 0.85f;
13 | public static final int BTN_INIT_RADIUS = dpToPx(2);
14 | public static final int BTN_MORPHED_RADIUS = dpToPx(100);
15 | public static final int MORPH_ANIM_DURATION = 500;
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/java/in/shadowfax/proswipebutton/ProSwipeButton.java:
--------------------------------------------------------------------------------
1 | package in.shadowfax.proswipebutton;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.content.res.TypedArray;
8 | import android.graphics.PorterDuff;
9 | import android.graphics.drawable.GradientDrawable;
10 | import android.os.Build;
11 | import android.os.Handler;
12 | import android.support.annotation.ColorInt;
13 | import android.support.annotation.Dimension;
14 | import android.support.annotation.Nullable;
15 | import android.support.v4.content.ContextCompat;
16 | import android.support.v7.widget.AppCompatImageView;
17 | import android.util.AttributeSet;
18 | import android.util.TypedValue;
19 | import android.view.LayoutInflater;
20 | import android.view.MotionEvent;
21 | import android.view.View;
22 | import android.view.ViewGroup;
23 | import android.view.animation.AccelerateDecelerateInterpolator;
24 | import android.view.animation.Animation;
25 | import android.view.animation.TranslateAnimation;
26 | import android.widget.ImageView;
27 | import android.widget.LinearLayout;
28 | import android.widget.ProgressBar;
29 | import android.widget.RelativeLayout;
30 | import android.widget.TextView;
31 |
32 | import static in.shadowfax.proswipebutton.Constants.BTN_INIT_RADIUS;
33 | import static in.shadowfax.proswipebutton.Constants.BTN_MORPHED_RADIUS;
34 | import static in.shadowfax.proswipebutton.Constants.DEFAULT_SWIPE_DISTANCE;
35 | import static in.shadowfax.proswipebutton.Constants.DEFAULT_TEXT_SIZE;
36 | import static in.shadowfax.proswipebutton.Constants.MORPH_ANIM_DURATION;
37 | import static in.shadowfax.proswipebutton.UiUtils.animateFadeHide;
38 | import static in.shadowfax.proswipebutton.UiUtils.animateFadeShow;
39 | import static in.shadowfax.proswipebutton.UiUtils.dpToPx;
40 |
41 | /**
42 | * Created by shadow-admin on 24/10/17.
43 | */
44 |
45 | public class ProSwipeButton extends RelativeLayout {
46 |
47 | private Context context;
48 | private View view;
49 | private GradientDrawable gradientDrawable;
50 | private RelativeLayout contentContainer;
51 | private TextView contentTv;
52 | private ImageView arrow1;
53 | private ImageView arrow2;
54 | private LinearLayout arrowHintContainer;
55 | private ProgressBar progressBar;
56 |
57 | //// TODO: 26/10/17 Add touch blocking
58 |
59 | /*
60 | User configurable settings
61 | */
62 | private CharSequence btnText = "BUTTON";
63 | @ColorInt
64 | private int textColorInt;
65 | @ColorInt
66 | private int bgColorInt;
67 | @ColorInt
68 | private int arrowColorInt;
69 | private float btnRadius = BTN_INIT_RADIUS;
70 | @Dimension
71 | private float textSize = DEFAULT_TEXT_SIZE;
72 | @Nullable
73 | private OnSwipeListener swipeListener = null;
74 | private float swipeDistance = DEFAULT_SWIPE_DISTANCE;
75 |
76 | public ProSwipeButton(Context context) {
77 | super(context);
78 | this.context = context;
79 | init();
80 | }
81 |
82 | public ProSwipeButton(Context context, AttributeSet attrs) {
83 | super(context, attrs);
84 | this.context = context;
85 | setAttrs(context, attrs);
86 | init();
87 | }
88 |
89 | public ProSwipeButton(Context context, AttributeSet attrs, int defStyleAttr) {
90 | super(context, attrs, defStyleAttr);
91 | this.context = context;
92 | setAttrs(context, attrs);
93 | init();
94 | }
95 |
96 | private void setAttrs(Context context, AttributeSet attrs) {
97 | TypedArray a = context.getTheme().obtainStyledAttributes(
98 | attrs,
99 | R.styleable.ProSwipeButton,
100 | 0, 0);
101 | try {
102 | final String btnString = a.getString(R.styleable.ProSwipeButton_btn_text);
103 | if (btnString != null)
104 | btnText = btnString;
105 | textColorInt = a.getColor(R.styleable.ProSwipeButton_text_color, ContextCompat.getColor(context, android.R.color.white));
106 | bgColorInt = a.getColor(R.styleable.ProSwipeButton_bg_color, ContextCompat.getColor(context, R.color.proswipebtn_red));
107 | arrowColorInt = a.getColor(R.styleable.ProSwipeButton_arrow_color, ContextCompat.getColor(context, R.color.proswipebtn_translucent_white));
108 | btnRadius = a.getFloat(R.styleable.ProSwipeButton_btn_radius, BTN_INIT_RADIUS);
109 | textSize = a.getDimensionPixelSize(R.styleable.ProSwipeButton_text_size, (int) DEFAULT_TEXT_SIZE);
110 | } finally {
111 | a.recycle();
112 | }
113 | }
114 |
115 | public void init() {
116 | LayoutInflater inflater = LayoutInflater.from(context);
117 | view = inflater.inflate(R.layout.view_proswipebtn, this, true);
118 | }
119 |
120 | @Override
121 | protected void onFinishInflate() {
122 | super.onFinishInflate();
123 |
124 | contentContainer = view.findViewById(R.id.relativeLayout_swipeBtn_contentContainer);
125 | arrowHintContainer = view.findViewById(R.id.linearLayout_swipeBtn_hintContainer);
126 | contentTv = view.findViewById(R.id.tv_btnText);
127 | arrow1 = view.findViewById(R.id.iv_arrow1);
128 | arrow2 = view.findViewById(R.id.iv_arrow2);
129 |
130 | tintArrowHint();
131 | contentTv.setText(btnText);
132 | contentTv.setTextColor(textColorInt);
133 | contentTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
134 | gradientDrawable = new GradientDrawable();
135 | gradientDrawable.setShape(GradientDrawable.RECTANGLE);
136 | gradientDrawable.setCornerRadius(btnRadius);
137 | setBackgroundColor(bgColorInt);
138 | updateBackground();
139 | setupTouchListener();
140 | }
141 |
142 | private void setupTouchListener() {
143 | setOnTouchListener(new OnTouchListener() {
144 | @Override
145 | public boolean onTouch(View v, MotionEvent event) {
146 | switch (event.getAction()) {
147 | case MotionEvent.ACTION_DOWN:
148 | return true;
149 | case MotionEvent.ACTION_MOVE:
150 | // Movement logic here
151 | if (event.getX() > arrowHintContainer.getWidth() / 2 &&
152 | event.getX() + arrowHintContainer.getWidth() / 2 < getWidth() &&
153 | (event.getX() < arrowHintContainer.getX() + arrowHintContainer.getWidth() || arrowHintContainer.getX() != 0)) {
154 | // snaps the hint to user touch, only if the touch is within hint width or if it has already been displaced
155 | arrowHintContainer.setX(event.getX() - arrowHintContainer.getWidth() / 2);
156 | }
157 |
158 | if (arrowHintContainer.getX() + arrowHintContainer.getWidth() > getWidth() &&
159 | arrowHintContainer.getX() + arrowHintContainer.getWidth() / 2 < getWidth()) {
160 | // allows the hint to go up to a max of btn container width
161 | arrowHintContainer.setX(getWidth() - arrowHintContainer.getWidth());
162 | }
163 |
164 | if (event.getX() < arrowHintContainer.getWidth() / 2 &&
165 | arrowHintContainer.getX() > 0) {
166 | // allows the hint to go up to a min of btn container starting
167 | arrowHintContainer.setX(0);
168 | }
169 |
170 | return true;
171 | case MotionEvent.ACTION_UP:
172 | //Release logic here
173 | if (arrowHintContainer.getX() + arrowHintContainer.getWidth() > getWidth() * swipeDistance) {
174 | // swipe completed, fly the hint away!
175 | performSuccessfulSwipe();
176 | } else if (arrowHintContainer.getX() <= 0) {
177 | // upon click without swipe
178 | startFwdAnim();
179 | } else {
180 | // swipe not completed, pull back the hint
181 | animateHintBack();
182 | }
183 | return true;
184 | }
185 |
186 | return false;
187 | }
188 | });
189 | }
190 |
191 | private void performSuccessfulSwipe() {
192 | if (swipeListener != null)
193 | swipeListener.onSwipeConfirm();
194 | morphToCircle();
195 | }
196 |
197 | @Override
198 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
199 | super.onSizeChanged(w, h, oldw, oldh);
200 | startFwdAnim();
201 | }
202 |
203 | private void animateHintBack() {
204 | final ValueAnimator positionAnimator =
205 | ValueAnimator.ofFloat(arrowHintContainer.getX(), 0);
206 | positionAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
207 | positionAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
208 | @Override
209 | public void onAnimationUpdate(ValueAnimator animation) {
210 | float x = (Float) positionAnimator.getAnimatedValue();
211 | arrowHintContainer.setX(x);
212 | }
213 | });
214 |
215 | positionAnimator.setDuration(200);
216 | positionAnimator.start();
217 | }
218 |
219 | private void startFwdAnim() {
220 | if (isEnabled()) {
221 | TranslateAnimation animation = new TranslateAnimation(0, getMeasuredWidth(), 0, 0);
222 | animation.setInterpolator(new AccelerateDecelerateInterpolator());
223 | animation.setDuration(1000);
224 | animation.setAnimationListener(new Animation.AnimationListener() {
225 | @Override
226 | public void onAnimationStart(Animation animation) {
227 |
228 | }
229 |
230 | @Override
231 | public void onAnimationEnd(Animation animation) {
232 | startHintInitAnim();
233 | }
234 |
235 | @Override
236 | public void onAnimationRepeat(Animation animation) {
237 |
238 | }
239 | });
240 | arrowHintContainer.startAnimation(animation);
241 | }
242 | }
243 |
244 | /**
245 | * animate entry of hint from the left-most edge
246 | */
247 | private void startHintInitAnim() {
248 | TranslateAnimation anim = new TranslateAnimation(-arrowHintContainer.getWidth(), 0, 0, 0);
249 | anim.setDuration(500);
250 | arrowHintContainer.startAnimation(anim);
251 | }
252 |
253 | /**
254 | * Just like performOnClick() in a standard button,
255 | * this will call the attached OnSwipeListener
256 | * and morph the btn to a circle
257 | */
258 | public void performOnSwipe() {
259 | performSuccessfulSwipe();
260 | }
261 |
262 | public void morphToCircle() {
263 | animateFadeHide(context, arrowHintContainer);
264 | setOnTouchListener(null);
265 | ObjectAnimator cornerAnimation =
266 | ObjectAnimator.ofFloat(gradientDrawable, "cornerRadius", BTN_INIT_RADIUS, BTN_MORPHED_RADIUS);
267 |
268 | animateFadeHide(context, contentTv);
269 | ValueAnimator widthAnimation;
270 | widthAnimation = ValueAnimator.ofInt(getWidth(), dpToPx(50));
271 | widthAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
272 | @Override
273 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
274 | int val = (Integer) valueAnimator.getAnimatedValue();
275 | ViewGroup.LayoutParams layoutParams = contentContainer.getLayoutParams();
276 | layoutParams.width = val;
277 | contentContainer.setLayoutParams(layoutParams);
278 | }
279 | });
280 | ValueAnimator heightAnimation = ValueAnimator.ofInt(getHeight(), dpToPx(50));
281 | heightAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
282 | @Override
283 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
284 | int val = (Integer) valueAnimator.getAnimatedValue();
285 | ViewGroup.LayoutParams layoutParams = contentContainer.getLayoutParams();
286 | layoutParams.height = val;
287 | contentContainer.setLayoutParams(layoutParams);
288 | }
289 | });
290 |
291 | AnimatorSet animatorSet = new AnimatorSet();
292 | animatorSet.setDuration(MORPH_ANIM_DURATION);
293 | animatorSet.playTogether(cornerAnimation, widthAnimation, heightAnimation);
294 | animatorSet.start();
295 |
296 | showProgressBar();
297 | }
298 |
299 | private void morphToRect() {
300 | setupTouchListener();
301 | ObjectAnimator cornerAnimation =
302 | ObjectAnimator.ofFloat(gradientDrawable, "cornerRadius", BTN_MORPHED_RADIUS, BTN_INIT_RADIUS);
303 |
304 | ValueAnimator widthAnimation;
305 | widthAnimation = ValueAnimator.ofInt(dpToPx(50), getWidth());
306 | widthAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
307 | @Override
308 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
309 | int val = (Integer) valueAnimator.getAnimatedValue();
310 | ViewGroup.LayoutParams layoutParams = contentContainer.getLayoutParams();
311 | layoutParams.width = val;
312 | contentContainer.setLayoutParams(layoutParams);
313 | }
314 | });
315 | ValueAnimator heightAnimation = ValueAnimator.ofInt(dpToPx(50), getWidth());
316 | heightAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
317 | @Override
318 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
319 | int val = (Integer) valueAnimator.getAnimatedValue();
320 | ViewGroup.LayoutParams layoutParams = contentContainer.getLayoutParams();
321 | layoutParams.height = val;
322 | contentContainer.setLayoutParams(layoutParams);
323 | }
324 | });
325 |
326 | AnimatorSet animatorSet = new AnimatorSet();
327 | animatorSet.setDuration(MORPH_ANIM_DURATION);
328 | animatorSet.playTogether(cornerAnimation, widthAnimation, heightAnimation);
329 | animatorSet.start();
330 | }
331 |
332 | public void updateBackground() {
333 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
334 | contentContainer.setBackground(gradientDrawable);
335 | } else {
336 | // noinspection deprecation
337 | contentContainer.setBackgroundDrawable(gradientDrawable);
338 | }
339 | }
340 |
341 | @Override
342 | public void setEnabled(boolean enabled) {
343 | super.setEnabled(enabled);
344 | if (!enabled) {
345 | gradientDrawable.setColor(ContextCompat.getColor(context, R.color.proswipebtn_disabled_grey));
346 | updateBackground();
347 | this.setAlpha(0.5f);
348 | } else {
349 | setBackgroundColor(getBackgroundColor());
350 | this.setAlpha(1f);
351 | }
352 | }
353 |
354 | private void showProgressBar() {
355 | progressBar = new ProgressBar(context);
356 | progressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, android.R.color.white), android.graphics.PorterDuff.Mode.SRC_IN);
357 | animateFadeHide(context, contentTv);
358 | contentContainer.addView(progressBar);
359 | }
360 |
361 | public void showResultIcon(boolean isSuccess, boolean shouldReset) {
362 | animateFadeHide(context, progressBar);
363 |
364 | final AppCompatImageView failureIcon = new AppCompatImageView(context);
365 | RelativeLayout.LayoutParams icLayoutParams =
366 | new RelativeLayout.LayoutParams(dpToPx(50), dpToPx(50));
367 | failureIcon.setLayoutParams(icLayoutParams);
368 | failureIcon.setVisibility(GONE);
369 | int icon;
370 | if (isSuccess)
371 | icon = R.drawable.ic_check_circle_36dp;
372 | else
373 | icon = R.drawable.ic_cancel_full_24dp;
374 | failureIcon.setImageResource(icon);
375 | contentContainer.addView(failureIcon);
376 | animateFadeShow(context, failureIcon);
377 |
378 | if (shouldReset) {
379 | // expand the btn again
380 | new Handler().postDelayed(new Runnable() {
381 | @Override
382 | public void run() {
383 | animateFadeHide(context, failureIcon);
384 | morphToRect();
385 | arrowHintContainer.setX(0);
386 | animateFadeShow(context, arrowHintContainer);
387 | animateFadeShow(context, contentTv);
388 | }
389 | }, 1000);
390 | }
391 | }
392 |
393 | public void showResultIcon(boolean isSuccess) {
394 | showResultIcon(isSuccess, !isSuccess);
395 | }
396 |
397 | private void tintArrowHint() {
398 | arrow1.setColorFilter(arrowColorInt, PorterDuff.Mode.MULTIPLY);
399 | arrow2.setColorFilter(arrowColorInt, PorterDuff.Mode.MULTIPLY);
400 | }
401 |
402 | public interface OnSwipeListener {
403 | void onSwipeConfirm();
404 | }
405 |
406 | public void setText(CharSequence text) {
407 | this.btnText = text;
408 | contentTv.setText(text);
409 | }
410 |
411 | public CharSequence getText() {
412 | return this.btnText;
413 | }
414 |
415 | public void setTextColor(@ColorInt int textColor) {
416 | this.textColorInt = textColor;
417 | contentTv.setTextColor(textColor);
418 | }
419 |
420 | @ColorInt
421 | public int getTextColor() {
422 | return this.textColorInt;
423 | }
424 |
425 | public void setBackgroundColor(@ColorInt int bgColor) {
426 | this.bgColorInt = bgColor;
427 | gradientDrawable.setColor(bgColor);
428 | updateBackground();
429 | }
430 |
431 | @ColorInt
432 | public int getBackgroundColor() {
433 | return this.bgColorInt;
434 | }
435 |
436 | public void setCornerRadius(float cornerRadius) {
437 | this.btnRadius = cornerRadius;
438 | }
439 |
440 | public float getCornerRadius() {
441 | return this.btnRadius;
442 | }
443 |
444 | public int getArrowColorRes() {
445 | return this.arrowColorInt;
446 | }
447 |
448 | /**
449 | * Include alpha in arrowColor for transparency (ex: #33FFFFFF)
450 | */
451 | public void setArrowColor(int arrowColor) {
452 | this.arrowColorInt = arrowColor;
453 | tintArrowHint();
454 | }
455 |
456 | public void setTextSize(@Dimension float textSize) {
457 | this.textSize = textSize;
458 | contentTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
459 | }
460 |
461 | @Dimension
462 | public float getTextSize() {
463 | return this.textSize;
464 | }
465 |
466 | /**
467 | * How much of the button must the user swipe to trigger the OnSwipeListener successfully
468 | *
469 | * @param swipeDistance float from 0.0 to 1.0 where 1.0 means user must swipe the button fully from end to end. Default is 0.85.
470 | */
471 | public void setSwipeDistance(@Dimension float swipeDistance) {
472 | if (swipeDistance > 1.0f) {
473 | swipeDistance = 1.0f;
474 | }
475 | if (swipeDistance < 0.0f) {
476 | swipeDistance = 0.0f;
477 | }
478 | this.swipeDistance = swipeDistance;
479 | }
480 |
481 | @Dimension
482 | public float getSwipeDistance() {
483 | return this.swipeDistance;
484 | }
485 |
486 | public void setOnSwipeListener(@Nullable OnSwipeListener customSwipeListener) {
487 | this.swipeListener = customSwipeListener;
488 | }
489 |
490 | }
491 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/java/in/shadowfax/proswipebutton/UiUtils.java:
--------------------------------------------------------------------------------
1 | package in.shadowfax.proswipebutton;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.view.View;
6 | import android.view.animation.Animation;
7 | import android.view.animation.AnimationUtils;
8 |
9 | /**
10 | * Created by shadow-admin on 24/10/17.
11 | */
12 |
13 | public class UiUtils {
14 |
15 | public static void animateFadeHide(Context context, View view) {
16 | if (view != null && view.getVisibility() == View.VISIBLE) {
17 | Animation animFadeOut = AnimationUtils.loadAnimation(context, R.anim.fade_out);
18 |
19 | view.startAnimation(animFadeOut);
20 | view.setVisibility(View.GONE);
21 | }
22 | }
23 |
24 | public static void animateFadeShow(Context context, View view) {
25 | if (view.getVisibility() != View.VISIBLE) {
26 | Animation animFadeIn = AnimationUtils.loadAnimation(context, R.anim.fade_in);
27 |
28 | view.startAnimation(animFadeIn);
29 | view.setVisibility(View.VISIBLE);
30 | }
31 | }
32 |
33 | public static int dpToPx(int dp) {
34 | return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/res/anim/fade_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/res/anim/fade_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/res/drawable/ic_cancel_full_24dp.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
18 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/res/drawable/ic_check_circle_36dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/res/drawable/ic_swipe_right_caret.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/res/layout/view_proswipebtn.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
30 |
31 |
32 |
33 |
38 |
39 |
44 |
45 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #33ffffff
4 | #F15824
5 | #939393
6 |
--------------------------------------------------------------------------------
/proswipebutton/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ProSwipeButton
3 |
4 |
--------------------------------------------------------------------------------
/proswipebutton/src/test/java/in/shadowfax/proswipebutton/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package in.shadowfax.proswipebutton;
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 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':proswipebutton'
2 |
--------------------------------------------------------------------------------