├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── build.gradle ├── demoFile ├── 1.gif └── demo.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── rmiri │ │ └── buttonloading │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── io │ │ │ └── rmiri │ │ │ └── buttonloading │ │ │ ├── ButtonLoading.java │ │ │ ├── ButtonLoadingAttribute.java │ │ │ └── utils │ │ │ ├── DeviceScreenUtils.java │ │ │ └── FontUtils.java │ └── res │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── io │ └── rmiri │ └── buttonloading │ └── ExampleUnitTest.java ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── fonts │ │ ├── IRANSans_Light.ttf │ │ └── IRANSans_Medium.ttf │ ├── java │ └── io │ │ └── rmiri │ │ └── buttonloadingsample │ │ ├── MainActivity.java │ │ ├── SampleOne.java │ │ └── SampleTwo.java │ └── res │ ├── drawable │ └── selector_bg_rectangle_radius_high_light_gray.xml │ ├── layout │ ├── activity_main.xml │ ├── activity_sample_1.xml │ └── activity_sample_2.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 └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 39 | 40 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 88 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 115 | 116 | 117 | 118 | 119 | 1.8 120 | 121 | 126 | 127 | 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ButtonLoading 2 |

3 | Beautiful Fancy Button Loading

4 | [![](https://jitpack.io/v/rasoulmiri/buttonloading.svg)](https://jitpack.io/#rasoulmiri/buttonloading) 5 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Button%20Loading-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/6394) 6 | Minimum API 17 7 |

8 | ![Demo](https://raw.githubusercontent.com/rasoulmiri/ButtonLoading/master/demoFile/1.gif) 9 | 10 |

11 | 12 | 13 | 14 | ## Usage: 15 | #### Step 1: 16 | 17 | Add JitPack repository in your root build.gradle at the end of repositories. 18 | 19 | allprojects { 20 | repositories { 21 | ... 22 | maven { url 'https://jitpack.io' } 23 | } 24 | } 25 | 26 | Add dependency in your app level build.gradle. 27 | 28 | dependencies { 29 | compile 'com.github.rasoulmiri:buttonloading:v1.0.8' 30 | } 31 | 32 |

33 | #### Step 2: 34 | use in layout xml 35 | 36 | ```xml 37 | 38 | 42 | 43 | //... 44 | 45 | 56 | 57 | 58 | 59 | ``` 60 |

61 | #### Step 3: 62 | 63 | ```java 64 | buttonLoading.setOnButtonLoadingListener(new ButtonLoading.OnButtonLoadingListener() { 65 | @Override 66 | public void onClick() { 67 | //... 68 | } 69 | 70 | @Override 71 | public void onStart() { 72 | //... 73 | } 74 | 75 | @Override 76 | public void onFinish() { 77 | //... 78 | } 79 | }); 80 | ``` 81 |

82 | # Configure XML 83 | * **BL_backgroundColor** 84 | * **BL_circleColor** color 85 | * **BL_circleColorSecond** 86 | * **BL_stateShow:** normal,animationStart,progress,animationFinish | default value is normal 87 | * **BL_text:** text button 88 | * **BL_textColor** 89 | * **BL_textSize** 90 | * **BL_font:** address font in assets. example: file in assetst > fonts > arial.ttf ==> fonts/arial.ttf 91 |

92 | **Note: Do not use the button in LinearLayout.** 93 |

94 | ## Contributing 95 | 96 | 97 | You are welcome to contribute with issues, PRs or suggestions. 98 | 99 | 100 |


101 | ## Other Project Me 102 | 103 | # Skeleton Android 104 | Simple yet powerful skeleton animation for all view in android 105 |

106 | ![alt tag](https://github.com/rasoulmiri/Skeleton/blob/master/demoFile/1.gif) 107 |

108 | 109 | 110 |
111 | [Repository](https://github.com/rasoulmiri/Skeleton) 112 |
113 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /demoFile/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasoulmiri/ButtonLoading/8783af10abaabc3ee5225bc607b508da2a7ca7b3/demoFile/1.gif -------------------------------------------------------------------------------- /demoFile/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasoulmiri/ButtonLoading/8783af10abaabc3ee5225bc607b508da2a7ca7b3/demoFile/demo.gif -------------------------------------------------------------------------------- /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/rasoulmiri/ButtonLoading/8783af10abaabc3ee5225bc607b508da2a7ca7b3/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Oct 30 11:32:52 IRST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.3" 6 | 7 | defaultConfig { 8 | minSdkVersion 17 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | buildTypes { 17 | 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(dir: 'libs', include: ['*.jar']) 27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 28 | exclude group: 'com.android.support', module: 'support-annotations' 29 | }) 30 | compile 'com.android.support:appcompat-v7:25.3.1' 31 | testCompile 'junit:junit:4.12' 32 | } 33 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/Rasoul/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 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 | -------------------------------------------------------------------------------- /library/src/androidTest/java/io/rmiri/buttonloading/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package io.rmiri.buttonloading; 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("io.rmiri.loadingbutton.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /library/src/main/java/io/rmiri/buttonloading/ButtonLoading.java: -------------------------------------------------------------------------------- 1 | package io.rmiri.buttonloading; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.content.res.TypedArray; 7 | import android.graphics.Canvas; 8 | import android.graphics.Color; 9 | import android.graphics.Paint; 10 | import android.graphics.Path; 11 | import android.graphics.Point; 12 | import android.graphics.Rect; 13 | import android.graphics.RectF; 14 | import android.graphics.Region; 15 | import android.support.v4.view.animation.PathInterpolatorCompat; 16 | import android.util.AttributeSet; 17 | import android.util.Log; 18 | import android.view.View; 19 | import android.view.ViewGroup; 20 | import android.view.animation.Interpolator; 21 | import android.widget.ImageButton; 22 | 23 | import io.rmiri.buttonloading.utils.DeviceScreenUtils; 24 | import io.rmiri.buttonloading.utils.FontUtils; 25 | 26 | import static io.rmiri.buttonloading.ButtonLoadingAttribute.STATE_ANIMATION_FINISH; 27 | import static io.rmiri.buttonloading.ButtonLoadingAttribute.STATE_ANIMATION_START; 28 | import static io.rmiri.buttonloading.ButtonLoadingAttribute.STATE_PROGRESS; 29 | 30 | 31 | /** 32 | * Created by Rasoul Miri on 10/25/2017 . 33 | */ 34 | 35 | public class ButtonLoading extends View { 36 | 37 | private ButtonLoadingAttribute attribute = new ButtonLoadingAttribute(); 38 | private OnButtonLoadingListener onButtonLoadingListener; 39 | 40 | private int height, width; 41 | 42 | private Paint paint; 43 | private RectF rect; 44 | Rect RectBoundCanvas; 45 | Point point; 46 | 47 | private ValueAnimator valueAnimatorCircleMain; 48 | private ValueAnimator valueAnimatorCircleSecond; 49 | 50 | private int valueAnimation1 = 0; 51 | private int valueAnimation2 = 0; 52 | private float fractionAnimation1 = 0.0f; 53 | private float fractionAnimation2 = 0.0f; 54 | private float fractionAnimation3 = 0.0f; 55 | 56 | private boolean isNeedFinishAnimation; 57 | private boolean isNeedAnimationBackground; 58 | 59 | 60 | ViewGroup parentView; 61 | ViewGroup rootView; 62 | ViewGroup.LayoutParams layoutParams; 63 | ImageButton buttonGetTouch; 64 | 65 | public ButtonLoading(Context context) { 66 | super(context); 67 | initView(context, null); 68 | } 69 | 70 | public ButtonLoading(Context context, AttributeSet attrs) { 71 | super(context, attrs); 72 | initView(context, attrs); 73 | } 74 | 75 | public ButtonLoading(Context context, AttributeSet attrs, int defStyleAttr) { 76 | super(context, attrs, defStyleAttr); 77 | initView(context, attrs); 78 | } 79 | 80 | 81 | public void initView(Context context, AttributeSet attrs) { 82 | 83 | if (isInEditMode()) 84 | return; 85 | 86 | //initial Attributes 87 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.buttonLoading); 88 | attribute.setEnable(typedArray.getBoolean(R.styleable.buttonLoading_BL_enable, true)); 89 | attribute.setIdParent(typedArray.getResourceId(R.styleable.buttonLoading_BL_idParent, 0)); 90 | attribute.setFont(typedArray.getString(R.styleable.buttonLoading_BL_font)); 91 | attribute.setText(typedArray.getString(R.styleable.buttonLoading_BL_text)); 92 | attribute.setTextColor(typedArray.getColor(R.styleable.buttonLoading_BL_textColor, Color.WHITE)); 93 | attribute.setBackgroundColor(typedArray.getColor(R.styleable.buttonLoading_BL_backgroundColor, Color.parseColor("#80ffffff"))); 94 | attribute.setCircleColor(typedArray.getColor(R.styleable.buttonLoading_BL_circleColor, Color.parseColor("#00AFEF"))); 95 | attribute.setCircleColorSecond(typedArray.getColor(R.styleable.buttonLoading_BL_circleColorSecond, Color.parseColor("#8000AFEF"))); 96 | attribute.setBackgroundDisableColor(typedArray.getColor(R.styleable.buttonLoading_BL_backgroundDisableColor, Color.parseColor("#f2f2f2"))); 97 | attribute.setTextSize(typedArray.getDimensionPixelSize(R.styleable.buttonLoading_BL_textSize, 14)); 98 | attribute.setStateShow(typedArray.getInt(R.styleable.buttonLoading_BL_stateShow, ButtonLoadingAttribute.STATE_NORMAL)); 99 | typedArray.recycle(); 100 | 101 | //initial for canvas 102 | paint = new Paint(); 103 | paint.setAntiAlias(true); 104 | rect = new RectF(); 105 | point = new Point(); 106 | RectBoundCanvas = new Rect(); 107 | 108 | //view for get touch child in layout parent 109 | buttonGetTouch = new ImageButton(getContext()); 110 | buttonGetTouch.setBackgroundColor(Color.TRANSPARENT); 111 | layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 112 | buttonGetTouch.setOnClickListener(new OnClickListener() { 113 | @Override 114 | public void onClick(View view) { 115 | Log.i("setOnClickListener", "buttonGetTouch get touch"); 116 | } 117 | }); 118 | 119 | 120 | //onClickListener 121 | setOnClickListener(new OnClickListener() { 122 | @Override 123 | public void onClick(View view) { 124 | if (onButtonLoadingListener != null 125 | && attribute.isEnable() 126 | && attribute.getStateShow() == ButtonLoadingAttribute.STATE_NORMAL) { 127 | 128 | setProgress(true); 129 | onButtonLoadingListener.onClick(); 130 | } 131 | } 132 | }); 133 | } 134 | 135 | @Override 136 | protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld) { 137 | super.onSizeChanged(xNew, yNew, xOld, yOld); 138 | if (width == 0) { 139 | width = xNew; 140 | height = yNew; 141 | } 142 | } 143 | 144 | @Override 145 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 146 | super.onLayout(changed, left, top, right, bottom); 147 | if (parentView == null) { 148 | if (attribute.getIdParent() == 0) { 149 | parentView = (ViewGroup) getParent(); 150 | } else { 151 | getRootView(this); 152 | } 153 | } 154 | } 155 | 156 | @Override 157 | protected void onDraw(Canvas canvas) { 158 | super.onDraw(canvas); 159 | switch (attribute.getStateShow()) { 160 | 161 | case ButtonLoadingAttribute.STATE_NORMAL: { 162 | 163 | //circle main 164 | if (attribute.isEnable()) { 165 | paint.setColor(attribute.getCircleColor()); 166 | } else { 167 | paint.setColor(attribute.getBackgroundDisableColor()); 168 | } 169 | rect.set(0, 0, width, height); 170 | canvas.drawRoundRect(rect, height / 2, height / 2, paint); 171 | 172 | //text 173 | paintText(); 174 | canvas.drawText(attribute.getText(), getXPositionByText(canvas), getYPositionByText(canvas), paint); 175 | 176 | break; 177 | } 178 | case STATE_ANIMATION_START: { 179 | 180 | //circle main 181 | paint.setColor(attribute.getCircleColor()); 182 | point.set(canvas.getWidth() / 2, canvas.getHeight() / 2); 183 | int rectW = valueAnimation1; 184 | int rectH = height; 185 | int left = point.x - (rectW / 2); 186 | int top = point.y - (rectH / 2); 187 | int right = point.x + (rectW / 2); 188 | int bottom = point.y + (rectH / 2); 189 | rect.set(left, top, right, bottom); 190 | canvas.drawRoundRect(rect, height / 2, height / 2, paint); 191 | 192 | //text 193 | paintText(); 194 | paint.setAlpha((int) ((1 - fractionAnimation1) * 255)); 195 | canvas.drawText(attribute.getText(), getXPositionByText(canvas), getYPositionByText(canvas), paint); 196 | 197 | break; 198 | } 199 | case STATE_PROGRESS: { 200 | 201 | canvas.getClipBounds(RectBoundCanvas); 202 | RectBoundCanvas.inset(-DeviceScreenUtils.width(getContext()), -DeviceScreenUtils.height(getContext())); 203 | canvas.clipRect(RectBoundCanvas, Region.Op.REPLACE); 204 | 205 | //background 206 | paint.setColor(attribute.getBackgroundColor()); 207 | point.set(canvas.getWidth() / 2, canvas.getHeight() / 2); 208 | 209 | if (!isNeedAnimationBackground) { 210 | //draw rect 211 | rect.set(-getX(), -getY(), DeviceScreenUtils.width(getContext()), DeviceScreenUtils.height(getContext())); 212 | canvas.drawRoundRect(rect, 0, 0, paint); 213 | } else { 214 | //draw oval 215 | int rectWBackground = (int) (2 * DeviceScreenUtils.height(getContext()) * fractionAnimation3); 216 | int rectHBackground = (int) (2 * DeviceScreenUtils.height(getContext()) * fractionAnimation3); 217 | int leftBackground = point.x - (rectWBackground / 2); 218 | int topBackground = point.y - (rectHBackground / 2); 219 | int rightBackground = point.x + (rectWBackground / 2); 220 | int bottomBackground = point.y + (rectHBackground / 2); 221 | rect.set(leftBackground, topBackground, rightBackground, bottomBackground); 222 | Path ovalPath = new Path(); 223 | ovalPath.addOval(rect, Path.Direction.CW); 224 | canvas.drawPath(ovalPath, paint); 225 | } 226 | 227 | //circle second 228 | paint.setColor(attribute.getCircleColorSecond()); 229 | int rectWAlpha = (int) (height * fractionAnimation2); 230 | int rectHAlpha = (int) (height * fractionAnimation2); 231 | int leftAlpha = point.x - (rectWAlpha / 2); 232 | int topAlpha = point.y - (rectHAlpha / 2); 233 | int rightAlpha = point.x + (rectWAlpha / 2); 234 | int bottomAlpha = point.y + (rectHAlpha / 2); 235 | rect.set(leftAlpha, topAlpha, rightAlpha, bottomAlpha); 236 | canvas.drawRoundRect(rect, 100, 100, paint); 237 | 238 | //circle main 239 | paint.setColor(attribute.getCircleColor()); 240 | int rectW = valueAnimation1; 241 | int rectH = height; 242 | int left = point.x - (rectW / 2); 243 | int top = point.y - (rectH / 2); 244 | int right = point.x + (rectW / 2); 245 | int bottom = point.y + (rectH / 2); 246 | rect.set(left, top, right, bottom); 247 | canvas.scale(fractionAnimation1, fractionAnimation1, canvas.getWidth() / 2, canvas.getHeight() / 2);//scale canvas 248 | canvas.drawRoundRect(rect, height / 2, height / 2, paint); 249 | 250 | break; 251 | } 252 | case STATE_ANIMATION_FINISH: { 253 | 254 | //circle main 255 | paint.setColor(attribute.getCircleColor()); 256 | point.set(canvas.getWidth() / 2, canvas.getHeight() / 2); 257 | int rectW = valueAnimation2; 258 | int rectH = height; 259 | int left = point.x - (rectW / 2); 260 | int top = point.y - (rectH / 2); 261 | int right = point.x + (rectW / 2); 262 | int bottom = point.y + (rectH / 2); 263 | rect.set(left, top, right, bottom); 264 | canvas.drawRoundRect(rect, height / 2, height / 2, paint); 265 | 266 | 267 | //text 268 | paintText(); 269 | paint.setAlpha((int) ((fractionAnimation2) * 255)); 270 | canvas.drawText(attribute.getText(), getXPositionByText(canvas), getYPositionByText(canvas), paint); 271 | 272 | canvas.scale(fractionAnimation1, fractionAnimation1, canvas.getWidth() / 2, canvas.getHeight() / 2);//scale canvas 273 | 274 | break; 275 | } 276 | } 277 | } 278 | 279 | private void paintText() { 280 | 281 | paint.setColor(attribute.getTextColor()); 282 | paint.setTextSize(attribute.getTextSize()); 283 | 284 | if (attribute.getFont() != null && !attribute.getFont().isEmpty()) { 285 | paint.setTypeface(FontUtils.getTypeface(getContext(), attribute.getFont())); 286 | } 287 | 288 | } 289 | 290 | int getXPositionByText(Canvas canvas) { 291 | return (canvas.getWidth() / 2 - ((int) paint.measureText(attribute.getText()) / 2)); 292 | } 293 | 294 | int getYPositionByText(Canvas canvas) { 295 | return (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)); 296 | } 297 | 298 | public void setProgress(boolean isProgressing) { 299 | 300 | if (isProgressing) { 301 | if (attribute.getStateShow() != ButtonLoadingAttribute.STATE_NORMAL) 302 | return; 303 | animationStart(); 304 | parentView.addView(buttonGetTouch, layoutParams);//add view for disable touch children 305 | } else { 306 | if (attribute.getStateShow() == ButtonLoadingAttribute.STATE_NORMAL) 307 | return; 308 | isNeedFinishAnimation = true; 309 | } 310 | 311 | } 312 | 313 | void animationStart() { 314 | 315 | attribute.setStateShow(STATE_ANIMATION_START); 316 | if (onButtonLoadingListener != null) 317 | onButtonLoadingListener.onStart(); 318 | 319 | ValueAnimator valueAnimatorLoading = ValueAnimator.ofInt(width, height); 320 | valueAnimatorLoading.setInterpolator(PathInterpolatorCompat.create(0.645f, 0.045f, 0.355f, 1f)); 321 | valueAnimatorLoading.setDuration(225); 322 | valueAnimatorLoading.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 323 | @Override 324 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 325 | valueAnimation1 = (int) (Integer) valueAnimator.getAnimatedValue(); 326 | fractionAnimation1 = valueAnimator.getAnimatedFraction(); 327 | invalidate(); 328 | } 329 | }); 330 | valueAnimatorLoading.start(); 331 | 332 | valueAnimatorLoading.addListener(new Animator.AnimatorListener() { 333 | @Override 334 | public void onAnimationStart(Animator animation) { 335 | 336 | } 337 | 338 | @Override 339 | public void onAnimationEnd(Animator animation) { 340 | animationProgress(); 341 | } 342 | 343 | @Override 344 | public void onAnimationCancel(Animator animation) { 345 | 346 | } 347 | 348 | @Override 349 | public void onAnimationRepeat(Animator animation) { 350 | 351 | } 352 | }); 353 | 354 | } 355 | 356 | void animationProgress() { 357 | 358 | attribute.setStateShow(STATE_PROGRESS); 359 | 360 | fractionAnimation1 = 0.0f; 361 | fractionAnimation2 = 0.0f; 362 | fractionAnimation3 = 0.0f; 363 | 364 | isNeedAnimationBackground = true; 365 | 366 | bringToFront(); //push view to top all views 367 | 368 | final int[] countRepeat = {0}; 369 | 370 | Interpolator pathInterpolatorCompat = PathInterpolatorCompat.create(0.455f, 0.030f, 0.515f, 0.955f); 371 | 372 | //circle Main 373 | valueAnimatorCircleMain = ValueAnimator.ofFloat(1.0f, 0.6f); 374 | valueAnimatorCircleMain.setRepeatCount(ValueAnimator.INFINITE); 375 | valueAnimatorCircleMain.setRepeatMode(ValueAnimator.REVERSE); 376 | valueAnimatorCircleMain.setInterpolator(pathInterpolatorCompat); 377 | valueAnimatorCircleMain.setDuration(525); 378 | valueAnimatorCircleMain.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 379 | @Override 380 | public void onAnimationUpdate(ValueAnimator animation) { 381 | fractionAnimation1 = (Float) animation.getAnimatedValue(); 382 | invalidate(); 383 | } 384 | }); 385 | valueAnimatorCircleMain.start(); 386 | 387 | valueAnimatorCircleMain.addListener(new Animator.AnimatorListener() { 388 | @Override 389 | public void onAnimationStart(Animator animator) { 390 | 391 | } 392 | 393 | @Override 394 | public void onAnimationEnd(Animator animator) { 395 | 396 | } 397 | 398 | @Override 399 | public void onAnimationCancel(Animator animator) { 400 | 401 | } 402 | 403 | @Override 404 | public void onAnimationRepeat(Animator animator) { 405 | //don't allow animation hearth for Circle 406 | if (countRepeat[0] % 2 != 0 && isNeedAnimationBackground) { 407 | isNeedAnimationBackground = false; 408 | } 409 | } 410 | }); 411 | 412 | //circle second 413 | valueAnimatorCircleSecond = ValueAnimator.ofFloat(0.6f, 1.4f); 414 | valueAnimatorCircleSecond.setRepeatCount(ValueAnimator.INFINITE); 415 | valueAnimatorCircleSecond.setRepeatMode(ValueAnimator.REVERSE); 416 | valueAnimatorCircleSecond.setStartDelay(525); 417 | valueAnimatorCircleSecond.setInterpolator(pathInterpolatorCompat); 418 | valueAnimatorCircleSecond.setDuration(525); 419 | valueAnimatorCircleSecond.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 420 | @Override 421 | public void onAnimationUpdate(ValueAnimator animation) { 422 | fractionAnimation2 = (Float) animation.getAnimatedValue(); 423 | fractionAnimation3 = animation.getAnimatedFraction(); 424 | } 425 | }); 426 | valueAnimatorCircleSecond.start(); 427 | 428 | 429 | valueAnimatorCircleMain.addListener(new Animator.AnimatorListener() { 430 | @Override 431 | public void onAnimationStart(Animator animator) { 432 | 433 | } 434 | 435 | @Override 436 | public void onAnimationEnd(Animator animator) { 437 | } 438 | 439 | @Override 440 | public void onAnimationCancel(Animator animator) { 441 | } 442 | 443 | @Override 444 | public void onAnimationRepeat(Animator animator) { 445 | countRepeat[0]++; 446 | if (countRepeat[0] % 2 != 0 & isNeedFinishAnimation) { 447 | animationFinish(); 448 | } else if (countRepeat[0] % 2 == 0 & isNeedFinishAnimation) { 449 | isNeedAnimationBackground = true; 450 | } 451 | } 452 | }); 453 | 454 | } 455 | 456 | void animationFinish() { 457 | 458 | //remove all animation for loading 459 | valueAnimatorCircleMain.removeAllListeners(); 460 | valueAnimatorCircleMain.end(); 461 | valueAnimatorCircleMain.cancel(); 462 | valueAnimatorCircleSecond.removeAllListeners(); 463 | valueAnimatorCircleSecond.end(); 464 | valueAnimatorCircleSecond.cancel(); 465 | 466 | attribute.setStateShow(STATE_ANIMATION_FINISH); 467 | 468 | fractionAnimation1 = 0.0f; 469 | 470 | ValueAnimator valueAnimatorFinish = ValueAnimator.ofInt(height, width); 471 | valueAnimatorFinish.setInterpolator(PathInterpolatorCompat.create(0.645f, 0.045f, 0.355f, 1f)); 472 | valueAnimatorFinish.setDuration(225); 473 | valueAnimatorFinish.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 474 | @Override 475 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 476 | valueAnimation2 = (int) (Integer) valueAnimator.getAnimatedValue(); 477 | fractionAnimation2 = valueAnimator.getAnimatedFraction(); 478 | invalidate(); 479 | } 480 | }); 481 | valueAnimatorFinish.start(); 482 | 483 | 484 | valueAnimatorFinish.addListener(new Animator.AnimatorListener() { 485 | @Override 486 | public void onAnimationStart(Animator animation) { 487 | 488 | } 489 | 490 | @Override 491 | public void onAnimationEnd(Animator animation) { 492 | attribute.setStateShow(ButtonLoadingAttribute.STATE_NORMAL); 493 | parentView.removeView(buttonGetTouch); 494 | isNeedFinishAnimation = false; 495 | if (onButtonLoadingListener != null) 496 | onButtonLoadingListener.onFinish(); 497 | } 498 | 499 | @Override 500 | public void onAnimationCancel(Animator animation) { 501 | 502 | } 503 | 504 | @Override 505 | public void onAnimationRepeat(Animator animation) { 506 | 507 | } 508 | }); 509 | 510 | } 511 | 512 | public void getRootView(View v) { 513 | while (v.getParent() != null && v.getParent() instanceof ViewGroup) { 514 | ViewGroup viewGroup = (ViewGroup) v.getParent(); 515 | v = viewGroup; 516 | rootView = viewGroup; 517 | } 518 | setParentView(rootView); 519 | } 520 | 521 | private void setParentView(View v) { 522 | ViewGroup viewgroup = (ViewGroup) v; 523 | if (viewgroup.getId() == attribute.getIdParent()) { 524 | parentView = viewgroup; 525 | } 526 | for (int i = 0; i < viewgroup.getChildCount(); i++) { 527 | View v1 = viewgroup.getChildAt(i); 528 | if (v1 instanceof ViewGroup) setParentView(v1); 529 | } 530 | } 531 | 532 | public void setText(String text) { 533 | attribute.setText(text); 534 | requestLayout(); 535 | } 536 | 537 | 538 | public String getText() { 539 | return attribute.getText(); 540 | } 541 | 542 | 543 | public void setEnable(boolean isEnable) { 544 | 545 | if (attribute.isEnable() == isEnable) 546 | return; 547 | 548 | attribute.setEnable(isEnable); 549 | requestLayout(); 550 | 551 | } 552 | 553 | //============================================================================================== 554 | //listener 555 | public void setOnButtonLoadingListener(OnButtonLoadingListener onButtonLoadingListener) { 556 | this.onButtonLoadingListener = onButtonLoadingListener; 557 | } 558 | 559 | public int getState() { 560 | return attribute.getStateShow(); 561 | } 562 | 563 | public boolean isLoadingState() { 564 | return attribute.getStateShow() != ButtonLoadingAttribute.STATE_NORMAL; 565 | } 566 | 567 | public interface OnButtonLoadingListener { 568 | void onClick(); 569 | 570 | void onStart(); 571 | 572 | void onFinish(); 573 | } 574 | 575 | } 576 | -------------------------------------------------------------------------------- /library/src/main/java/io/rmiri/buttonloading/ButtonLoadingAttribute.java: -------------------------------------------------------------------------------- 1 | package io.rmiri.buttonloading; 2 | 3 | /** 4 | * Created by Rasoul Miri on 8/20/17. 5 | */ 6 | 7 | public class ButtonLoadingAttribute { 8 | 9 | 10 | private boolean isEnable; 11 | 12 | private int idParent; 13 | 14 | private String font; 15 | 16 | private String text; 17 | 18 | private int textColor; 19 | 20 | private int backgroundColor; 21 | private int circleColor; 22 | private int circleColorSecond; 23 | 24 | private int backgroundDisableColor; 25 | 26 | private int textSize; 27 | 28 | private int stateShow; 29 | static final int STATE_NORMAL = 1; 30 | static final int STATE_ANIMATION_START = 2; 31 | static final int STATE_PROGRESS = 3; 32 | static final int STATE_ANIMATION_FINISH = 4; 33 | 34 | 35 | //============================================================================================== 36 | /* getter and setter */ 37 | 38 | public boolean isEnable() { 39 | return isEnable; 40 | } 41 | 42 | public void setEnable(boolean enable) { 43 | isEnable = enable; 44 | } 45 | 46 | public int getIdParent() { 47 | return idParent; 48 | } 49 | 50 | public void setIdParent(int idParent) { 51 | this.idParent = idParent; 52 | } 53 | 54 | public String getFont() { 55 | return font; 56 | } 57 | 58 | public void setFont(String font) { 59 | this.font = font; 60 | } 61 | 62 | public String getText() { 63 | return text; 64 | } 65 | 66 | public void setText(String text) { 67 | this.text = text; 68 | } 69 | 70 | public int getTextColor() { 71 | return textColor; 72 | } 73 | 74 | public void setTextColor(int textColor) { 75 | this.textColor = textColor; 76 | } 77 | 78 | public int getBackgroundColor() { 79 | return backgroundColor; 80 | } 81 | 82 | public void setBackgroundColor(int backgroundColor) { 83 | this.backgroundColor = backgroundColor; 84 | } 85 | 86 | public int getCircleColor() { 87 | return circleColor; 88 | } 89 | 90 | public void setCircleColor(int circleColor) { 91 | this.circleColor = circleColor; 92 | } 93 | 94 | public int getCircleColorSecond() { 95 | return circleColorSecond; 96 | } 97 | 98 | public void setCircleColorSecond(int circleColorSecond) { 99 | this.circleColorSecond = circleColorSecond; 100 | } 101 | 102 | public int getTextSize() { 103 | return textSize; 104 | } 105 | 106 | public void setTextSize(int textSize) { 107 | this.textSize = textSize; 108 | } 109 | 110 | public int getStateShow() { 111 | return stateShow; 112 | } 113 | 114 | public void setStateShow(int stateShow) { 115 | this.stateShow = stateShow; 116 | } 117 | 118 | public int getBackgroundDisableColor() { 119 | return backgroundDisableColor; 120 | } 121 | 122 | public void setBackgroundDisableColor(int backgroundDisableColor) { 123 | this.backgroundDisableColor = backgroundDisableColor; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /library/src/main/java/io/rmiri/buttonloading/utils/DeviceScreenUtils.java: -------------------------------------------------------------------------------- 1 | package io.rmiri.buttonloading.utils; 2 | 3 | import android.content.Context; 4 | import android.content.res.Configuration; 5 | import android.util.DisplayMetrics; 6 | import android.view.WindowManager; 7 | 8 | /** 9 | * Created by Rasoul on 7/11/17. 10 | */ 11 | 12 | public class DeviceScreenUtils { 13 | 14 | private static int deviceScreenUtilsWidth; 15 | private static int deviceScreenUtilsHeight; 16 | 17 | public static boolean isLandscape(Context context) { 18 | return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; 19 | } 20 | 21 | public static boolean isPortrait(Context context) { 22 | return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; 23 | } 24 | 25 | public static int height(Context context) { 26 | if (deviceScreenUtilsHeight == 0) { 27 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 28 | DisplayMetrics displayMetrics = new DisplayMetrics(); 29 | windowManager.getDefaultDisplay().getMetrics(displayMetrics); 30 | deviceScreenUtilsHeight = displayMetrics.heightPixels; 31 | } 32 | return deviceScreenUtilsHeight; 33 | } 34 | 35 | public static int width(Context context) { 36 | if (deviceScreenUtilsWidth == 0) { 37 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 38 | DisplayMetrics displayMetrics = new DisplayMetrics(); 39 | windowManager.getDefaultDisplay().getMetrics(displayMetrics); 40 | deviceScreenUtilsWidth = displayMetrics.widthPixels; 41 | } 42 | return deviceScreenUtilsWidth; 43 | } 44 | 45 | public static boolean isTablet(Context context) { 46 | return (context.getResources().getConfiguration().screenLayout 47 | & Configuration.SCREENLAYOUT_SIZE_MASK) 48 | >= Configuration.SCREENLAYOUT_SIZE_LARGE; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /library/src/main/java/io/rmiri/buttonloading/utils/FontUtils.java: -------------------------------------------------------------------------------- 1 | package io.rmiri.buttonloading.utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.Typeface; 5 | 6 | import java.util.Hashtable; 7 | 8 | 9 | /** 10 | * Created by R.Miri on 7/20/2016. 11 | */ 12 | 13 | public class FontUtils { 14 | 15 | private static Hashtable fontCache = new Hashtable<>(); 16 | 17 | public static Typeface getTypeface(Context context,String fontName) { 18 | Typeface tf = fontCache.get(fontName); 19 | if (tf == null) { 20 | try { 21 | tf = Typeface.createFromAsset(context.getAssets(), fontName); 22 | } catch (Exception e) { 23 | e.printStackTrace(); 24 | return null; 25 | } 26 | fontCache.put(fontName, tf); 27 | } 28 | return tf; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ButtonLoading 3 | 4 | -------------------------------------------------------------------------------- /library/src/test/java/io/rmiri/buttonloading/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package io.rmiri.buttonloading; 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 | } -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion '25.0.3' 6 | defaultConfig { 7 | applicationId "io.rmiri.buttonloadingsample" 8 | minSdkVersion 17 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | 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 project(':library') 29 | compile 'com.android.support:appcompat-v7:25.3.1' 30 | compile 'com.android.support:cardview-v7:25.3.1' 31 | compile 'com.android.support:design:25.3.1' 32 | 33 | } 34 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/Rasoul/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 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 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /sample/src/main/assets/fonts/IRANSans_Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasoulmiri/ButtonLoading/8783af10abaabc3ee5225bc607b508da2a7ca7b3/sample/src/main/assets/fonts/IRANSans_Light.ttf -------------------------------------------------------------------------------- /sample/src/main/assets/fonts/IRANSans_Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rasoulmiri/ButtonLoading/8783af10abaabc3ee5225bc607b508da2a7ca7b3/sample/src/main/assets/fonts/IRANSans_Medium.ttf -------------------------------------------------------------------------------- /sample/src/main/java/io/rmiri/buttonloadingsample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package io.rmiri.buttonloadingsample; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.widget.Button; 8 | 9 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 10 | 11 | Button sampleOne, sampleTwo; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | 18 | sampleOne = (Button) findViewById(R.id.sampleOne); 19 | sampleTwo = (Button) findViewById(R.id.sampleTwo); 20 | 21 | sampleOne.setOnClickListener(this); 22 | sampleTwo.setOnClickListener(this); 23 | 24 | } 25 | 26 | 27 | @Override 28 | public void onClick(View v) { 29 | switch (v.getId()) { 30 | case R.id.sampleOne: 31 | startActivity(new Intent(this, SampleOne.class)); 32 | break; 33 | case R.id.sampleTwo: 34 | startActivity(new Intent(this, SampleTwo.class)); 35 | break; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sample/src/main/java/io/rmiri/buttonloadingsample/SampleOne.java: -------------------------------------------------------------------------------- 1 | package io.rmiri.buttonloadingsample; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.widget.Toast; 7 | 8 | import io.rmiri.buttonloading.ButtonLoading; 9 | 10 | public class SampleOne extends AppCompatActivity { 11 | 12 | ButtonLoading buttonLoading; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_sample_1); 18 | 19 | buttonLoading = (ButtonLoading) findViewById(R.id.buttonLoading); 20 | 21 | buttonLoading.setOnButtonLoadingListener(new ButtonLoading.OnButtonLoadingListener() { 22 | @Override 23 | public void onClick() { 24 | Toast.makeText(SampleOne.this, "onClick", Toast.LENGTH_SHORT).show(); 25 | finishLoading(); 26 | } 27 | 28 | @Override 29 | public void onStart() { 30 | Toast.makeText(SampleOne.this, "onStart", Toast.LENGTH_SHORT).show(); 31 | } 32 | 33 | @Override 34 | public void onFinish() { 35 | Toast.makeText(SampleOne.this, "onFinish", Toast.LENGTH_SHORT).show(); 36 | } 37 | }); 38 | 39 | } 40 | 41 | void finishLoading() { 42 | //call setProgress(false) after 5 second 43 | new Handler().postDelayed(new Runnable() { 44 | @Override 45 | public void run() { 46 | buttonLoading.setProgress(false); 47 | } 48 | }, 5000); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /sample/src/main/java/io/rmiri/buttonloadingsample/SampleTwo.java: -------------------------------------------------------------------------------- 1 | package io.rmiri.buttonloadingsample; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.widget.Toast; 7 | 8 | import io.rmiri.buttonloading.ButtonLoading; 9 | 10 | public class SampleTwo extends AppCompatActivity { 11 | 12 | ButtonLoading buttonLoading; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_sample_2); 18 | 19 | buttonLoading = (ButtonLoading) findViewById(R.id.buttonLoading); 20 | buttonLoading.setOnButtonLoadingListener(new ButtonLoading.OnButtonLoadingListener() { 21 | @Override 22 | public void onClick() { 23 | Toast.makeText(SampleTwo.this, "onClick", Toast.LENGTH_SHORT).show(); 24 | finishLoading(); 25 | } 26 | 27 | @Override 28 | public void onStart() { 29 | Toast.makeText(SampleTwo.this, "onStart", Toast.LENGTH_SHORT).show(); 30 | } 31 | 32 | @Override 33 | public void onFinish() { 34 | Toast.makeText(SampleTwo.this, "onFinish", Toast.LENGTH_SHORT).show(); 35 | } 36 | }); 37 | 38 | } 39 | 40 | void finishLoading() { 41 | //call setProgress(false) after 5 second 42 | new Handler().postDelayed(new Runnable() { 43 | @Override 44 | public void run() { 45 | buttonLoading.setProgress(false); 46 | } 47 | }, 5000); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/selector_bg_rectangle_radius_high_light_gray.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 15 | 16 |