├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── github
│ │ └── nikartm
│ │ └── stripedprocessbutton
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── nikartm
│ │ │ └── stripedprocessbutton
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── btn_rounded.xml
│ │ ├── ic_launcher_background.xml
│ │ └── ripple.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ └── com
│ └── github
│ └── nikartm
│ └── stripedprocessbutton
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ └── gradle-wrapper.jar
├── gradlew
├── gradlew.bat
├── screenshots
└── sct_ex.gif
├── scripts
├── publish-module.gradle
└── publish-root.gradle
├── settings.gradle
└── support
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── github
│ │ └── nikartm
│ │ └── support
│ │ ├── AnimatedStripedDrawable.kt
│ │ ├── AttributeController.kt
│ │ ├── StripedDrawable.kt
│ │ ├── StripedProcessButton.kt
│ │ ├── Util.kt
│ │ └── constant
│ │ └── Constants.kt
└── res
│ └── values
│ ├── attr.xml
│ └── strings.xml
└── test
└── java
└── com
└── github
└── nikartm
└── support
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | /build
6 | /captures
7 | .externalNativeBuild
8 | app.properties
9 | gradle-wrapper.properties
10 | *.log
11 |
12 | # Build application files
13 | *.apk
14 | *.ap_
15 | *.dex
16 |
17 | # Java class files
18 | *.class
19 |
20 | # Generated files
21 | bin/
22 | gen/
23 |
24 | # Windows thumbnail db
25 | Thumbs.db
26 |
27 | # Eclipse project files
28 | .classpath
29 | .project
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://search.maven.org/search?q=g:%22io.github.nikartm%22%20AND%20a:%22process-button%22) [](https://android-arsenal.com/api?level=21) []( https://android-arsenal.com/details/1/7623 )
2 |
3 | # StripedProcessButton
4 | Library for creating process loading button with stripes
5 |
6 | ## Download
7 | Add to gradle root:
8 | ```
9 | allprojects {
10 | repositories {
11 | mavenCentral()
12 | }
13 | }
14 | ```
15 |
16 | #### After migrating to MavenCentral, use Groove:
17 | ```
18 | implementation 'io.github.nikartm:process-button:$LAST_VERSION'
19 | ```
20 | Or Kotlin DSL:
21 | ```
22 | implementation("io.github.nikartm:process-button:$LAST_VERSION")
23 | ```
24 |
25 | ## Screenshots
26 | 
27 | ## How to use?
28 | Adjust the xml view [More examples.](https://github.com/nikartm/StripedProcessButton/blob/master/app/src/main/res/layout/activity_main.xml):
29 | ```
30 |
51 | ```
52 | Adjust programmatically (shortly):
53 | ```
54 | stripedButton.setCornerRadius(50)
55 | .setStripeAlpha(0.7f)
56 | .setStripeRevert(true)
57 | .setStripeGradient(false)
58 | .setTilt(15)
59 | .start()
60 | ```
61 |
62 | ## License
63 | Copyright 2022 Ivan Vodyasov
64 |
65 | Licensed under the Apache License, Version 2.0 (the "License");
66 | you may not use this file except in compliance with the License.
67 | You may obtain a copy of the License at
68 |
69 | http://www.apache.org/licenses/LICENSE-2.0
70 |
71 | Unless required by applicable law or agreed to in writing, software
72 | distributed under the License is distributed on an "AS IS" BASIS,
73 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
74 | See the License for the specific language governing permissions and
75 | limitations under the License.
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion rootProject.ext.compileSdkVersion
6 | defaultConfig {
7 | applicationId "com.github.nikartm.stripedprocessbutton"
8 | minSdkVersion rootProject.ext.minSdkVersion
9 | targetSdkVersion rootProject.ext.targetSdkVersion
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 |
22 | kotlinOptions {
23 | jvmTarget = rootProject.ext.javaVersion
24 | }
25 |
26 | compileOptions {
27 | targetCompatibility rootProject.ext.javaVersion
28 | sourceCompatibility rootProject.ext.javaVersion
29 | }
30 |
31 | buildFeatures {
32 | viewBinding = true
33 | }
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(dir: 'libs', include: ['*.jar'])
38 | testImplementation 'junit:junit:4.13.2'
39 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
40 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
41 | implementation 'androidx.appcompat:appcompat:1.5.1'
42 | implementation rootProject.ext.dependencies.coreKtx
43 | implementation project(':support')
44 | }
45 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/github/nikartm/stripedprocessbutton/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.github.nikartm.stripedprocessbutton;
2 |
3 | import android.content.Context;
4 | import androidx.test.InstrumentationRegistry;
5 | import androidx.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 | * Instrumented 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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.github.nikartm.strippedprogressbutton", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/nikartm/stripedprocessbutton/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.github.nikartm.stripedprocessbutton
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import com.github.nikartm.stripedprocessbutton.databinding.ActivityMainBinding
6 |
7 | class MainActivity : AppCompatActivity() {
8 |
9 | private lateinit var binding: ActivityMainBinding
10 |
11 | override fun onCreate(savedInstanceState: Bundle?) {
12 | super.onCreate(savedInstanceState)
13 | binding = ActivityMainBinding.inflate(layoutInflater)
14 | setContentView(binding.root)
15 | bindView()
16 | }
17 |
18 | private fun bindView() = with(binding) {
19 | initStartStripedButton()
20 | btnStart.setOnClickListener {
21 | btnStart.start()
22 | btn2.start()
23 | btn3.start()
24 | btn4.start()
25 | }
26 | btnStop.setOnClickListener {
27 | btnStart.stop()
28 | btn2.stop()
29 | btn3.stop()
30 | btn4.stop()
31 | }
32 | }
33 |
34 | private fun initStartStripedButton() = with(binding.btnStart) {
35 | text = "Start process"
36 | setCornerRadius(50f)
37 | setStripeAlpha(0.7f)
38 | setStripeRevert(true)
39 | setStripeGradient(false)
40 | setTilt(15f)
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/btn_rounded.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ripple.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
35 |
36 |
48 |
49 |
71 |
72 |
93 |
94 |
115 |
116 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nikartx/StripedProcessButton/b4c6ab44ce2423bc1d1eb5c591e762274c6d9d54/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nikartx/StripedProcessButton/b4c6ab44ce2423bc1d1eb5c591e762274c6d9d54/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nikartx/StripedProcessButton/b4c6ab44ce2423bc1d1eb5c591e762274c6d9d54/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nikartx/StripedProcessButton/b4c6ab44ce2423bc1d1eb5c591e762274c6d9d54/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nikartx/StripedProcessButton/b4c6ab44ce2423bc1d1eb5c591e762274c6d9d54/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nikartx/StripedProcessButton/b4c6ab44ce2423bc1d1eb5c591e762274c6d9d54/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nikartx/StripedProcessButton/b4c6ab44ce2423bc1d1eb5c591e762274c6d9d54/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nikartx/StripedProcessButton/b4c6ab44ce2423bc1d1eb5c591e762274c6d9d54/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nikartx/StripedProcessButton/b4c6ab44ce2423bc1d1eb5c591e762274c6d9d54/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nikartx/StripedProcessButton/b4c6ab44ce2423bc1d1eb5c591e762274c6d9d54/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #009688
4 | #00796B
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | StripedProcessButton
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/github/nikartm/stripedprocessbutton/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.github.nikartm.stripedprocessbutton;
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() {
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 | ext.kotlin_version = '1.7.20'
5 |
6 | repositories {
7 | maven { url "https://plugins.gradle.org/m2/" }
8 | google()
9 | mavenCentral()
10 | }
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:7.3.1'
13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14 | classpath 'io.github.gradle-nexus:publish-plugin:1.1.0'
15 |
16 | // NOTE: Do not place your application dependencies here; they belong
17 | // in the individual module build.gradle files
18 | }
19 | }
20 |
21 | apply plugin: 'io.github.gradle-nexus.publish-plugin'
22 | apply from: "${rootDir}/scripts/publish-root.gradle"
23 |
24 | allprojects {
25 | repositories {
26 | google()
27 | mavenCentral()
28 | }
29 | }
30 |
31 | task clean(type: Delete) {
32 | delete rootProject.buildDir
33 | }
34 |
35 | ext {
36 | compileSdkVersion = 33
37 | minSdkVersion = 21
38 | targetSdkVersion = compileSdkVersion
39 |
40 | javaVersion = 11
41 |
42 | dependencies = [:]
43 | dependencies.coreKtx = 'androidx.core:core-ktx:1.9.0'
44 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 | # Use AndroidX
16 | android.enableJetifier=true
17 | android.useAndroidX=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nikartx/StripedProcessButton/b4c6ab44ce2423bc1d1eb5c591e762274c6d9d54/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/screenshots/sct_ex.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nikartx/StripedProcessButton/b4c6ab44ce2423bc1d1eb5c591e762274c6d9d54/screenshots/sct_ex.gif
--------------------------------------------------------------------------------
/scripts/publish-module.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven-publish'
2 | apply plugin: 'signing'
3 |
4 | task androidSourcesJar(type: Jar) {
5 | archiveClassifier.set('sources')
6 | if (project.plugins.findPlugin("com.android.library")) {
7 | from android.sourceSets.main.java.srcDirs
8 | } else {
9 | from sourceSets.main.java.srcDirs
10 | }
11 | }
12 |
13 | artifacts {
14 | archives androidSourcesJar
15 | }
16 |
17 | group = PUBLISH_GROUP_ID
18 | version = PUBLISH_VERSION
19 |
20 | afterEvaluate {
21 | publishing {
22 | publications {
23 | release(MavenPublication) {
24 |
25 | groupId PUBLISH_GROUP_ID
26 | artifactId PUBLISH_ARTIFACT_ID
27 | version PUBLISH_VERSION
28 |
29 | if (project.plugins.findPlugin("com.android.library")) {
30 | from components.release
31 | } else {
32 | artifact("$buildDir/libs/${project.getName()}-${version}.jar")
33 | }
34 |
35 | artifact androidSourcesJar
36 |
37 | pom {
38 | name = PUBLISH_ARTIFACT_ID
39 | description = PUBLISH_DESCRIPTION
40 | url = PUBLISH_URL
41 |
42 | licenses {
43 | license {
44 | name = PUBLISH_LICENSE_NAME
45 | url = PUBLISH_LICENSE_URL
46 | }
47 | }
48 |
49 | developers {
50 | developer {
51 | id = PUBLISH_DEVELOPER_ID
52 | name = PUBLISH_DEVELOPER_NAME
53 | email = PUBLISH_DEVELOPER_EMAIL
54 | }
55 | }
56 |
57 | scm {
58 | connection = PUBLISH_SCM_CONNECTION
59 | developerConnection = PUBLISH_SCM_DEVELOPER_CONNECTION
60 | url = PUBLISH_SCM_URL
61 | }
62 | }
63 | }
64 | }
65 | }
66 | }
67 |
68 | ext["signing.keyId"] = rootProject.ext["signing.keyId"]
69 | ext["signing.password"] = rootProject.ext["signing.password"]
70 | ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"]
71 |
72 | signing {
73 | sign publishing.publications
74 | }
--------------------------------------------------------------------------------
/scripts/publish-root.gradle:
--------------------------------------------------------------------------------
1 | ext["signing.keyId"] = ''
2 | ext["signing.password"] = ''
3 | ext["signing.secretKeyRingFile"] = ''
4 | ext["ossrhUsername"] = ''
5 | ext["ossrhPassword"] = ''
6 | ext["sonatypeStagingProfileId"] = ''
7 |
8 | File secretPropsFile = project.rootProject.file('local.properties')
9 | if (secretPropsFile.exists()) {
10 | Properties p = new Properties()
11 | new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
12 | p.each { name, value -> ext[name] = value }
13 | } else {
14 | ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
15 | ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
16 | ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
17 | ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
18 | ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
19 | ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
20 | }
21 |
22 | nexusPublishing {
23 | repositories {
24 | sonatype {
25 | stagingProfileId = sonatypeStagingProfileId
26 | username = ossrhUsername
27 | password = ossrhPassword
28 | nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
29 | snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':support'
2 |
--------------------------------------------------------------------------------
/support/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/support/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | ext {
5 | PUBLISH_GROUP_ID = 'io.github.nikartm'
6 | PUBLISH_VERSION = '3.1.0'
7 | PUBLISH_ARTIFACT_ID = 'process-button'
8 | PUBLISH_DESCRIPTION = 'Android library. Animated striped button to show loading process.'
9 | PUBLISH_URL = 'https://github.com/nikartm/StripedProcessButton'
10 | PUBLISH_LICENSE_NAME = 'The Apache Software License, Version 2.0'
11 | PUBLISH_LICENSE_URL = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
12 | PUBLISH_DEVELOPER_ID = 'ivanv'
13 | PUBLISH_DEVELOPER_NAME = 'Ivan Vodyasov'
14 | PUBLISH_DEVELOPER_EMAIL = 'jvissun@gmail.com'
15 | PUBLISH_SCM_CONNECTION = 'scm:git:github.com/nikartm/StripedProcessButton.git'
16 | PUBLISH_SCM_DEVELOPER_CONNECTION = 'scm:git:ssh://github.com/nikartm/StripedProcessButton.git'
17 | PUBLISH_SCM_URL = 'https://github.com/nikartm/StripedProcessButton/tree/master'
18 | }
19 |
20 | apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"
21 |
22 | android {
23 | compileSdkVersion rootProject.ext.compileSdkVersion
24 | defaultConfig {
25 | minSdkVersion rootProject.ext.minSdkVersion
26 | targetSdkVersion rootProject.ext.targetSdkVersion
27 | }
28 |
29 | buildTypes {
30 | release {
31 | minifyEnabled false
32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33 | }
34 | }
35 |
36 | kotlinOptions {
37 | jvmTarget = rootProject.ext.javaVersion
38 | }
39 |
40 | compileOptions {
41 | targetCompatibility rootProject.ext.javaVersion
42 | sourceCompatibility rootProject.ext.javaVersion
43 | }
44 | }
45 |
46 | dependencies {
47 | implementation fileTree(dir: 'libs', include: ['*.jar'])
48 | testImplementation 'junit:junit:4.13.2'
49 | implementation 'androidx.appcompat:appcompat:1.5.1'
50 | implementation rootProject.ext.dependencies.coreKtx
51 | }
52 |
--------------------------------------------------------------------------------
/support/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/support/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/support/src/main/java/com/github/nikartm/support/AnimatedStripedDrawable.kt:
--------------------------------------------------------------------------------
1 | package com.github.nikartm.support
2 |
3 | import android.animation.ValueAnimator
4 | import android.graphics.*
5 | import android.graphics.drawable.Drawable
6 | import androidx.core.animation.doOnRepeat
7 |
8 | /**
9 | * Animated striped drawable
10 | * @author Ivan V on 30.03.2018.
11 | * @version 2.0
12 | */
13 | internal class AnimatedStripedDrawable(private val stripedDrawable: StripedDrawable) : Drawable() {
14 |
15 | private var viewHeight = 0
16 | private var viewWidth = 0
17 | private var tiltLeft = 0f
18 | private var tiltRight = 0f
19 | private var animator: ValueAnimator? = null
20 | private var stripesShader: Shader? = null
21 |
22 | override fun onBoundsChange(bounds: Rect) {
23 | super.onBoundsChange(bounds)
24 | with(bounds) {
25 | viewHeight = height()
26 | viewWidth = width()
27 | }
28 | adjustStripes()
29 | }
30 |
31 | private fun adjustStripes() = with(stripedDrawable) {
32 | tiltLeft = if (!isStripeRevert) tilt else 0f
33 | tiltRight = if (isStripeRevert) tilt else 0f
34 | }
35 |
36 | private fun initAnimator() = with(stripedDrawable) {
37 | if (animator == null) {
38 | animator = ValueAnimator.ofInt(0, 1).apply {
39 | repeatCount = ValueAnimator.INFINITE
40 | duration = stripeDuration.toLong()
41 | doOnRepeat {
42 | shiftColor(colorMain, colorSub)
43 | invalidateSelf()
44 | }
45 | }
46 | }
47 | }
48 |
49 | override fun getIntrinsicWidth(): Int {
50 | return if (viewWidth > 0) viewWidth else super.getIntrinsicWidth()
51 | }
52 |
53 | override fun getIntrinsicHeight(): Int {
54 | return if (viewHeight > 0) viewHeight else super.getIntrinsicHeight()
55 | }
56 |
57 | override fun setAlpha(alpha: Int) {}
58 |
59 | override fun setColorFilter(colorFilter: ColorFilter?) {}
60 |
61 | override fun getOpacity(): Int = PixelFormat.TRANSLUCENT
62 |
63 | override fun draw(canvas: Canvas) {
64 | drawStripes(canvas)
65 | startStripesAnimation()
66 | }
67 |
68 | private fun startStripesAnimation() {
69 | if (isRunning()) start() else stop()
70 | }
71 |
72 | private fun drawStripes(canvas: Canvas) = with(stripedDrawable) {
73 | val paintBack = Paint(Paint.ANTI_ALIAS_FLAG)
74 | val paintStripes = Paint(Paint.ANTI_ALIAS_FLAG)
75 | val rect = Rect(0, 0, viewWidth, viewHeight)
76 | val rectF = RectF(rect)
77 | val stripesAlpha = Util.computeAlpha(stripeAlpha)
78 | stripesShader = if (isStripeGradient) createGradientShader() else createShader()
79 | paintBack.color = colorBack
80 | val cornerRadius = cornerRadius
81 | canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, paintBack)
82 | if (isShowStripes) {
83 | paintStripes.alpha = stripesAlpha
84 | paintStripes.shader = stripesShader
85 | canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, paintStripes)
86 | }
87 | }
88 |
89 | private fun createShader(): LinearGradient = with(stripedDrawable) {
90 | val position = .5f
91 | return LinearGradient(
92 | stripeWidth,
93 | tiltLeft,
94 | 0f,
95 | tiltRight,
96 | intArrayOf(colorMain, colorSub),
97 | floatArrayOf(position, position),
98 | Shader.TileMode.REPEAT
99 | )
100 | }
101 |
102 | private fun createGradientShader(): LinearGradient = with(stripedDrawable) {
103 | return LinearGradient(
104 | stripeWidth, tiltLeft, 0f, tiltRight,
105 | colorMain, colorSub, Shader.TileMode.REPEAT
106 | )
107 | }
108 |
109 | private fun shiftColor(mainColor: Int, subColor: Int) = with(stripedDrawable) {
110 | colorMain = subColor
111 | colorSub = mainColor
112 | }
113 |
114 | // Start stripes animation
115 | fun start() {
116 | if (isRunning()) return
117 | initAnimator()
118 | animator?.start()
119 | stripedDrawable.isShowStripes = true
120 | invalidateSelf()
121 | }
122 |
123 | // Stop stripes animation
124 | fun stop() {
125 | if (!isRunning()) return
126 | animator?.cancel()
127 | animator = null
128 | stripedDrawable.isShowStripes = false
129 | invalidateSelf()
130 | }
131 |
132 | // Check if stripes animation running
133 | fun isRunning(): Boolean {
134 | return animator?.isStarted == true
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/support/src/main/java/com/github/nikartm/support/AttributeController.kt:
--------------------------------------------------------------------------------
1 | package com.github.nikartm.support
2 |
3 | import android.content.Context
4 | import android.util.AttributeSet
5 | import com.github.nikartm.support.constant.Constants
6 |
7 | /**
8 | * Controller attrs of striped process button
9 | * @author Ivan V on 29.03.2018.
10 | * @version 2.0
11 | */
12 | internal class AttributeController(private val context: Context, private val attrs: AttributeSet?) {
13 |
14 | /**
15 | * Get [StripedDrawable] when attrs initialized
16 | * @return initialized [StripedDrawable]
17 | */
18 | var stripedDrawable: StripedDrawable = StripedDrawable()
19 | private set
20 |
21 | init {
22 | initAttrs()
23 | }
24 |
25 | private fun initAttrs() {
26 | val typedArray = context.obtainStyledAttributes(attrs, R.styleable.StripedProcessButton)
27 | try {
28 | val stripeWidth = typedArray.getDimension(
29 | R.styleable.StripedProcessButton_spb_stripeWidth,
30 | Constants.STRIPE_WIDTH
31 | )
32 | val stripeAlpha = typedArray.getFloat(
33 | R.styleable.StripedProcessButton_spb_stripeAlpha,
34 | Constants.STRIPE_ALPHA
35 | )
36 | val stripeTilt = typedArray.getInt(
37 | R.styleable.StripedProcessButton_spb_stripeTilt,
38 | Constants.STRIPE_TILT
39 | )
40 | val stripeDuration = typedArray.getInt(
41 | R.styleable.StripedProcessButton_spb_stripeDuration,
42 | Constants.DURATION
43 | )
44 | val background = typedArray.getColor(
45 | R.styleable.StripedProcessButton_spb_background,
46 | Constants.DEF_BACKGROUND
47 | )
48 | val mainStripeColor = typedArray.getColor(
49 | R.styleable.StripedProcessButton_spb_mainStripColor,
50 | Constants.DEF_MAIN_STRIPE
51 | )
52 | val subStripeColor = typedArray.getColor(
53 | R.styleable.StripedProcessButton_spb_subStripeColor,
54 | Constants.DEF_SUB_STRIPE
55 | )
56 | val cornerRadius = typedArray.getFloat(
57 | R.styleable.StripedProcessButton_spb_cornerRadius,
58 | Constants.CORNER.toFloat()
59 | )
60 | val stripeRevert = typedArray.getBoolean(
61 | R.styleable.StripedProcessButton_spb_stripeRevert,
62 | Constants.REVERT
63 | )
64 | val showStripes = typedArray.getBoolean(
65 | R.styleable.StripedProcessButton_spb_showStripes,
66 | Constants.SHOW_STRIPES
67 | )
68 | val stripeGradient = typedArray.getBoolean(
69 | R.styleable.StripedProcessButton_spb_stripeGradient,
70 | Constants.GRADIENT
71 | )
72 | val loadingText = typedArray.getString(R.styleable.StripedProcessButton_spb_loadingText)
73 |
74 | // Apply drawable state
75 | stripedDrawable = stripedDrawable.copy(
76 | stripeWidth = stripeWidth,
77 | stripeAlpha = stripeAlpha,
78 | tilt = stripeTilt.toFloat(),
79 | stripeDuration = stripeDuration,
80 | colorBack = background,
81 | colorMain = mainStripeColor,
82 | colorSub = subStripeColor,
83 | cornerRadius = cornerRadius,
84 | isStripeRevert = stripeRevert,
85 | isShowStripes = showStripes,
86 | isStripeGradient = stripeGradient,
87 | loadingText = loadingText
88 | )
89 | } finally {
90 | typedArray.recycle()
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/support/src/main/java/com/github/nikartm/support/StripedDrawable.kt:
--------------------------------------------------------------------------------
1 | package com.github.nikartm.support
2 |
3 | /**
4 | * @author Ivan V on 07.04.2018.
5 | * @version 2.0
6 | */
7 | internal data class StripedDrawable(
8 | /**
9 | * Get width of stripes
10 | */
11 | var stripeWidth: Float = 0f,
12 |
13 | /**
14 | * Get drawable background color
15 | */
16 | var colorBack: Int = 0,
17 |
18 | /**
19 | * Get color the main stripe
20 | */
21 | var colorMain: Int = 0,
22 |
23 | /**
24 | * Get color the sub stripe
25 | */
26 | var colorSub: Int = 0,
27 |
28 | /**
29 | * Get alpha stripes
30 | */
31 | var stripeAlpha: Float = 0f,
32 |
33 | /**
34 | * Get drawable corner radius
35 | */
36 | var cornerRadius: Float = 0f,
37 |
38 | /**
39 | * Get duration of stripes animation
40 | */
41 | var stripeDuration: Int = 0,
42 |
43 | /**
44 | * Get tilt of stripes
45 | */
46 | var tilt: Float = 0f,
47 |
48 | /**
49 | * Get state of tilt stripes. If true - tilt to left, false - tilt to right.
50 | */
51 | var isStripeRevert: Boolean = false,
52 |
53 | /**
54 | * Get states of showing stripes
55 | */
56 | var isShowStripes: Boolean = false,
57 |
58 | /**
59 | * Get states of stripes appearance
60 | */
61 | var isStripeGradient: Boolean = false,
62 |
63 | /**
64 | * Get text when button has loading state
65 | * @return loading text
66 | */
67 | var loadingText: String? = null
68 | )
--------------------------------------------------------------------------------
/support/src/main/java/com/github/nikartm/support/StripedProcessButton.kt:
--------------------------------------------------------------------------------
1 | package com.github.nikartm.support
2 |
3 | import android.content.Context
4 | import android.graphics.Canvas
5 | import android.graphics.drawable.Animatable
6 | import android.util.AttributeSet
7 | import androidx.appcompat.widget.AppCompatButton
8 | import com.github.nikartm.support.Util.Animation.animateView
9 | import com.github.nikartm.support.constant.Constants.DEF_START_ANIM_DURATION
10 | import com.github.nikartm.support.constant.Constants.DEF_STOP_ANIM_DURATION
11 | import com.github.nikartm.support.constant.Constants.NO_INIT
12 |
13 | /**
14 | * Striped process button
15 | * @author Ivan V on 29.03.2018.
16 | * @version 1.0
17 | */
18 | class StripedProcessButton @JvmOverloads constructor(
19 | context: Context,
20 | attrs: AttributeSet? = null,
21 | ) : AppCompatButton(context, attrs), Animatable {
22 |
23 | private lateinit var stripedDrawable: StripedDrawable
24 | private lateinit var animatedDrawable: AnimatedStripedDrawable
25 | private var state = State.STOP
26 |
27 | /**
28 | * Get current start animation duration
29 | * @return start duration in ms
30 | */
31 | var startAnimDuration = NO_INIT
32 | private set
33 |
34 | /**
35 | * Get current stop animation duration
36 | * @return stop duration in ms
37 | */
38 | var stopAnimDuration = NO_INIT
39 | private set
40 |
41 | /**
42 | * Get button stripe animation state
43 | * @return true if button can be animated
44 | */
45 | var isButtonAnimated = true
46 | private set
47 |
48 | private var defaultText: String = ""
49 | private var density = 0f
50 |
51 | init {
52 | initAttrs(attrs)
53 | }
54 |
55 | private fun initAttrs(attrs: AttributeSet?) {
56 | density = context.resources.displayMetrics.density
57 | val attrController = AttributeController(context, attrs)
58 | stripedDrawable = attrController.stripedDrawable
59 | animatedDrawable = AnimatedStripedDrawable(stripedDrawable)
60 | }
61 |
62 | override fun onAttachedToWindow() {
63 | super.onAttachedToWindow()
64 | initView()
65 | }
66 |
67 | private fun initView() {
68 | defaultText = text.toString()
69 | when (state) {
70 | State.START -> start()
71 | State.STOP -> stop()
72 | }
73 | }
74 |
75 | override fun onDraw(canvas: Canvas) {
76 | background = animatedDrawable
77 | isEnabled = !isRunning
78 | super.onDraw(canvas)
79 | }
80 |
81 | override fun start() {
82 | state = State.START
83 | if (isRunning || !isAttachedToWindow) return
84 | isEnabled = isRunning
85 | animatedDrawable.start()
86 | animateButton(isRunning)
87 | }
88 |
89 | override fun stop() {
90 | state = State.STOP
91 | if (!isRunning || !isAttachedToWindow) return
92 | isEnabled = isRunning
93 | animatedDrawable.stop()
94 | animateButton(isRunning)
95 | }
96 |
97 | override fun isRunning(): Boolean {
98 | return isAttachedToWindow && animatedDrawable.isRunning()
99 | }
100 |
101 | /**
102 | * Set start animation duration in ms
103 | */
104 | fun setStartAnimDuration(startAnimDuration: Long): StripedProcessButton {
105 | this.startAnimDuration = startAnimDuration
106 | invalidate()
107 | return this
108 | }
109 |
110 | /**
111 | * Set stop animation duration in ms
112 | */
113 | fun setStopAnimDuration(stopAnimDuration: Long): StripedProcessButton {
114 | this.stopAnimDuration = stopAnimDuration
115 | invalidate()
116 | return this
117 | }
118 |
119 | /**
120 | * Get text when button has loading state
121 | * @return loading text
122 | */
123 | val loadingText: String?
124 | get() = stripedDrawable.loadingText
125 |
126 | /**
127 | * Set text when button has loading state
128 | * @param loadingText text when loading started
129 | */
130 | fun setLoadingText(loadingText: String?): StripedProcessButton {
131 | stripedDrawable.loadingText = loadingText
132 | invalidate()
133 | return this
134 | }
135 |
136 | /**
137 | * Set button stripe animation state
138 | * @param buttonAnimated if tru button can be animated
139 | */
140 | fun setButtonAnimated(buttonAnimated: Boolean): StripedProcessButton {
141 | isButtonAnimated = buttonAnimated
142 | invalidate()
143 | return this
144 | }
145 |
146 | /**
147 | * Get width of stripes
148 | */
149 | val stripeWidth: Float
150 | get() = stripedDrawable.stripeWidth
151 |
152 | /**
153 | * Set width of stripes
154 | * @param stripeWidth on view
155 | */
156 | fun setStripeWidth(stripeWidth: Float): StripedProcessButton {
157 | stripedDrawable.stripeWidth = stripeWidth * density
158 | invalidate()
159 | return this
160 | }
161 |
162 | /**
163 | * Get drawable background color
164 | */
165 | val colorBack: Int
166 | get() = stripedDrawable.colorBack
167 |
168 | /**
169 | * Set drawable background color
170 | * @param colorBack background color
171 | */
172 | fun setColorBack(colorBack: Int): StripedProcessButton {
173 | stripedDrawable.colorBack = colorBack
174 | invalidate()
175 | return this
176 | }
177 |
178 | /**
179 | * Get color the main stripe
180 | */
181 | val colorMain: Int
182 | get() = stripedDrawable.colorMain
183 |
184 | /**
185 | * Set color the main stripe
186 | * @param colorMain color of main stripe
187 | */
188 | fun setColorMain(colorMain: Int): StripedProcessButton {
189 | stripedDrawable.colorMain = colorMain
190 | invalidate()
191 | return this
192 | }
193 |
194 | /**
195 | * Get color the sub stripe
196 | */
197 | val colorSecond: Int
198 | get() = stripedDrawable.colorSub
199 |
200 | /**
201 | * Set color the sub stripe
202 | * @param colorSecond color of sub stripe
203 | */
204 | fun setColorSecond(colorSecond: Int): StripedProcessButton {
205 | stripedDrawable.colorSub = colorSecond
206 | invalidate()
207 | return this
208 | }
209 |
210 | /**
211 | * Get alpha stripes
212 | */
213 | val stripeAlpha: Float
214 | get() = stripedDrawable.stripeAlpha
215 |
216 | /**
217 | * Set alpha drawable stripes
218 | * @param alpha stripes
219 | */
220 | fun setStripeAlpha(alpha: Float): StripedProcessButton {
221 | stripedDrawable.stripeAlpha = alpha
222 | invalidate()
223 | return this
224 | }
225 |
226 | /**
227 | * Get drawable corner radius
228 | */
229 | val cornerRadius: Float
230 | get() = stripedDrawable.cornerRadius
231 |
232 | /**
233 | * Set drawable corner radius
234 | * @param cornerRadius radius
235 | */
236 | fun setCornerRadius(cornerRadius: Float): StripedProcessButton {
237 | stripedDrawable.cornerRadius = cornerRadius * density
238 | invalidate()
239 | return this
240 | }
241 |
242 | /**
243 | * Get duration of stripes animation
244 | */
245 | val stripeDuration: Int
246 | get() = stripedDrawable.stripeDuration
247 |
248 | /**
249 | * Set duration of stripes animation
250 | */
251 | fun setStripeDuration(stripeDuration: Int): StripedProcessButton {
252 | stripedDrawable.stripeDuration = stripeDuration
253 | invalidate()
254 | return this
255 | }
256 |
257 | /**
258 | * Get tilt of stripes
259 | */
260 | val tilt: Float
261 | get() = stripedDrawable.tilt
262 |
263 | /**
264 | * Set tilt of stripes
265 | * @param tilt of stripes
266 | */
267 | fun setTilt(tilt: Float): StripedProcessButton {
268 | stripedDrawable.tilt = tilt
269 | invalidate()
270 | return this
271 | }
272 |
273 | /**
274 | * Get state of tilt stripes. If true - tilt to left, false - tilt to right.
275 | */
276 | val isStripeRevert: Boolean
277 | get() = stripedDrawable.isStripeRevert
278 |
279 | /**
280 | * Get state of tilt stripes.
281 | * @param stripeRevert If true - tilt to left, false - tilt to right.
282 | */
283 | fun setStripeRevert(stripeRevert: Boolean): StripedProcessButton {
284 | stripedDrawable.isStripeRevert = stripeRevert
285 | invalidate()
286 | return this
287 | }
288 |
289 | /**
290 | * Get states of showing stripes
291 | */
292 | val isShowStripes: Boolean
293 | get() = stripedDrawable.isShowStripes
294 |
295 | /**
296 | * Set states of showing stripes
297 | * @param showStripes If true - stripes showing, false - stripes gone.
298 | */
299 | fun setShowStripes(showStripes: Boolean): StripedProcessButton {
300 | stripedDrawable.isShowStripes = showStripes
301 | invalidate()
302 | return this
303 | }
304 |
305 | /**
306 | * Get states of stripes appearance
307 | */
308 | val isStripeGradient: Boolean
309 | get() = stripedDrawable.isStripeGradient
310 |
311 | /**
312 | * Set the state of striped appearance of drawable
313 | * @param stripeGradient if true stripes has gradient style, false - flat strips
314 | */
315 | fun setStripeGradient(stripeGradient: Boolean): StripedProcessButton {
316 | stripedDrawable.isStripeGradient = stripeGradient
317 | invalidate()
318 | return this
319 | }
320 |
321 | private fun animateButton(startAnim: Boolean) {
322 | if (isButtonAnimated) {
323 | val duration = if (startAnim) {
324 | if (startAnimDuration == NO_INIT) DEF_START_ANIM_DURATION else startAnimDuration
325 | } else {
326 | if (stopAnimDuration == NO_INIT) DEF_STOP_ANIM_DURATION else stopAnimDuration
327 | }
328 | setCurrentText(startAnim)
329 | animateView(this, startAnim, duration)
330 | }
331 | }
332 |
333 | private fun setCurrentText(startAnim: Boolean) = with(stripedDrawable) {
334 | val currentText = when {
335 | startAnim -> if (!loadingText.isNullOrBlank()) loadingText else defaultText
336 | else -> defaultText
337 | }
338 | text = currentText
339 | }
340 |
341 | /**
342 | * State of launch methods with delay
343 | */
344 | private enum class State {
345 | START, STOP
346 | }
347 | }
348 |
--------------------------------------------------------------------------------
/support/src/main/java/com/github/nikartm/support/Util.kt:
--------------------------------------------------------------------------------
1 | package com.github.nikartm.support
2 |
3 | import android.view.View
4 | import android.view.ViewAnimationUtils
5 |
6 | /**
7 | * @author Ivan V on 29.03.2018.
8 | * @version 2.0
9 | */
10 | internal object Util {
11 |
12 | private const val MAX_PERCENT = 100f
13 | private const val MAX_ALPHA = 255
14 | private const val MIN_ALPHA = 0
15 |
16 | fun computeAlpha(value: Float): Int {
17 | return if (compute(value) >= MAX_ALPHA) {
18 | MAX_ALPHA
19 | } else if (value < MIN_ALPHA) {
20 | MIN_ALPHA
21 | } else {
22 | compute(value).toInt()
23 | }
24 | }
25 |
26 | private fun compute(value: Float): Float {
27 | return MAX_ALPHA * (value * MAX_PERCENT) / MAX_PERCENT
28 | }
29 |
30 | /**
31 | * Animation for the striped process button
32 | */
33 | internal object Animation {
34 | @JvmStatic
35 | fun animateView(view: View, start: Boolean, duration: Long) {
36 | val cX = if (start) view.width / 2 else 0
37 | val cY = view.height / 2
38 | val finalRadius = Math.max(view.width, view.height)
39 | ViewAnimationUtils
40 | .createCircularReveal(view, cX, cY, 0f, finalRadius.toFloat())
41 | .apply {
42 | this.duration = duration
43 | start()
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/support/src/main/java/com/github/nikartm/support/constant/Constants.kt:
--------------------------------------------------------------------------------
1 | package com.github.nikartm.support.constant
2 |
3 | import android.graphics.Color
4 |
5 | /**
6 | * Constants of stripped process button
7 | * @author Ivan V on 29.03.2018.
8 | * @version 2.0
9 | */
10 | object Constants {
11 | const val STRIPE_WIDTH = 36f
12 | const val STRIPE_ALPHA = 0.3f
13 | const val CORNER = 0
14 | const val STRIPE_TILT = 25
15 | const val DURATION = 250
16 | const val REVERT = false
17 | const val SHOW_STRIPES = false
18 | const val GRADIENT = true
19 | const val NO_INIT = -1L
20 | const val DEF_START_ANIM_DURATION: Long = 700
21 | const val DEF_STOP_ANIM_DURATION: Long = 300
22 |
23 | @JvmField
24 | val DEF_BACKGROUND = Color.parseColor("#4CAF50")
25 | @JvmField
26 | val DEF_MAIN_STRIPE = Color.parseColor("#4CAF50")
27 | @JvmField
28 | val DEF_SUB_STRIPE = Color.parseColor("#CFD8DC")
29 | }
30 |
--------------------------------------------------------------------------------
/support/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/support/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | support
3 |
4 |
--------------------------------------------------------------------------------
/support/src/test/java/com/github/nikartm/support/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.github.nikartm.support;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------