├── .gitignore ├── README.md ├── art ├── dribbble.png └── preview.gif ├── build.gradle ├── demo ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── bitvale │ │ └── pacbutton │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── bitvale │ │ │ └── pacbutton │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable │ │ ├── circle_shape.xml │ │ ├── ic_photo.xml │ │ ├── ic_photo_cam.xml │ │ ├── ic_video.xml │ │ ├── ic_video_cam.xml │ │ └── splash_screen.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── bitvale │ └── pacbutton │ └── ExampleUnitTest.kt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── bitvale │ │ └── pacbutton │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── bitvale │ │ │ └── pacbutton │ │ │ ├── BitmapUtil.kt │ │ │ ├── Extensions.kt │ │ │ └── PacButton.kt │ └── res │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── style.xml │ └── test │ └── java │ └── com │ └── bitvale │ └── pacbutton │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /captures 3 | 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # Files for the ART/Dalvik VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # Generated files 15 | bin/ 16 | gen/ 17 | out/ 18 | 19 | # Gradle files 20 | .gradle/ 21 | build/ 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | 26 | # Proguard folder generated by Eclipse 27 | proguard/ 28 | 29 | # Log Files 30 | *.log 31 | 32 | # Android Studio Navigation editor temp files 33 | .navigation/ 34 | 35 | # Android Studio captures folder 36 | captures/ 37 | 38 | # Intellij 39 | *.iml 40 | /.idea 41 | .idea/workspace.xml 42 | .idea/tasks.xml 43 | .idea/gradle.xml 44 | .idea/dictionaries 45 | .idea/libraries 46 | 47 | # Keystore 48 | *.jks 49 | keystore.properties 50 | 51 | # External native build folder generated in Android Studio 2.2 and later 52 | .externalNativeBuild 53 | 54 | # Google Services (e.g. APIs or Firebase) 55 | google-services.json 56 | 57 | # Freeline 58 | freeline.py 59 | freeline/ 60 | freeline_project_description.json 61 | 62 | # Custom -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PacButton 2 | 3 | sample 4 | 5 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 6 | [![Platform](https://img.shields.io/badge/platform-android-green.svg)](http://developer.android.com/index.html) 7 | [![API](https://img.shields.io/badge/API-19%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=19) 8 | 9 | Created this cool [video/photo switch animation](https://dribbble.com/shots/5487871-Video-Photo-Switcher-Exploration) from [Oleg Frolov](https://dribbble.com/Volorf) as android library. 10 | 11 | 12 | Design on Dribbble 13 | 14 | 15 | USAGE 16 | ----- 17 | 18 | Just add PacButton view in your layout XML and PacButton library in your project via Gradle: 19 | 20 | ```gradle 21 | dependencies { 22 | implementation 'com.bitvale:pacbutton:1.0.0' 23 | } 24 | ``` 25 | 26 | XML 27 | ----- 28 | 29 | ```xml 30 | 40 | ``` 41 | 42 | You must use the following properties in your XML to change your PacButton. 43 | 44 | 45 | ##### Properties: 46 | 47 | * `app:topIcon` (drawable) -> default none 48 | * `app:bottomIcon` (drawable) -> default none 49 | * `app:iconHeight` (dimension) -> default none 50 | * `app:iconWidth` (dimension) -> default none 51 | * `app:pacColor` (color) -> default none 52 | * `app:pacGradientColor_1` (color) -> default #7651F8 53 | * `app:pacGradientColor_2` (color) -> default #E74996 54 | 55 | You can use solid color with pacColor property or gradient with pacGradientColor properties. 56 | 57 | Kotlin 58 | ----- 59 | 60 | ```kotlin 61 | pac_button.setSelectAction { 62 | if (it) some_image.setImageResource(R.drawable.ic_video_cam) 63 | else some_image.setImageResource(R.drawable.ic_photo_cam) 64 | } 65 | 66 | pac_button.setAnimationUpdateListener { progress -> 67 | some_image.alpha = 1 - progress 68 | } 69 | ``` 70 | 71 | LICENCE 72 | ----- 73 | 74 | PacButton by [Alexander Kolpakov](https://play.google.com/store/apps/dev?id=7044571013168957413) is licensed under an [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0). -------------------------------------------------------------------------------- /art/dribbble.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitvale/PacButton/2d78fd9001d3b6b5a803809b3e8f99540bfccc8b/art/dribbble.png -------------------------------------------------------------------------------- /art/preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitvale/PacButton/2d78fd9001d3b6b5a803809b3e8f99540bfccc8b/art/preview.gif -------------------------------------------------------------------------------- /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.2.71' 5 | repositories { 6 | google() 7 | jcenter() 8 | 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.4.0-alpha02' 12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } 29 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /demo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 28 9 | defaultConfig { 10 | applicationId "com.bitvale.pacbutton" 11 | minSdkVersion 19 12 | targetSdkVersion 28 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | vectorDrawables.useSupportLibrary = true 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: 'libs', include: ['*.jar']) 28 | implementation project(':library') 29 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 30 | implementation 'androidx.appcompat:appcompat:1.0.0' 31 | implementation 'androidx.core:core-ktx:1.0.0' 32 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 33 | } 34 | -------------------------------------------------------------------------------- /demo/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 | -------------------------------------------------------------------------------- /demo/src/androidTest/java/com/bitvale/pacbutton/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.bitvale.pacbutton 2 | 3 | import androidx.test.InstrumentationRegistry 4 | import androidx.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.bitvale.pacbutton", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /demo/src/main/java/com/bitvale/pacbutton/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.bitvale.pacbutton 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import kotlinx.android.synthetic.main.activity_main.* 6 | 7 | class MainActivity : AppCompatActivity() { 8 | 9 | override fun onCreate(savedInstanceState: Bundle?) { 10 | setTheme(R.style.AppTheme) 11 | super.onCreate(savedInstanceState) 12 | setContentView(R.layout.activity_main) 13 | pac_button.setSelectAction { 14 | if (it) icon.setImageResource(R.drawable.ic_video_cam) 15 | else icon.setImageResource(R.drawable.ic_photo_cam) 16 | } 17 | pac_button.setAnimationUpdateListener { progress -> 18 | icon.alpha = 1 - progress 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/circle_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 10 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/ic_photo.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 13 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/ic_photo_cam.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/ic_video.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/ic_video_cam.xml: -------------------------------------------------------------------------------- 1 | 6 | 10 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/splash_screen.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 24 | 25 | 34 | 35 | 44 | 45 | 55 | 56 | 65 | 66 | 75 | 76 | -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitvale/PacButton/2d78fd9001d3b6b5a803809b3e8f99540bfccc8b/demo/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitvale/PacButton/2d78fd9001d3b6b5a803809b3e8f99540bfccc8b/demo/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitvale/PacButton/2d78fd9001d3b6b5a803809b3e8f99540bfccc8b/demo/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitvale/PacButton/2d78fd9001d3b6b5a803809b3e8f99540bfccc8b/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitvale/PacButton/2d78fd9001d3b6b5a803809b3e8f99540bfccc8b/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #0A0734 4 | #080626 5 | #7651F8 6 | 7 | #100D42 8 | 9 | #33DEDDDD 10 | #99DEDDDD 11 | 12 | -------------------------------------------------------------------------------- /demo/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4dp 5 | 8dp 6 | 16dp 7 | 24dp 8 | 9 | 10 | @dimen/space_small 11 | 12 | 13 | @dimen/space_tiny 14 | @dimen/space_small 15 | @dimen/space_normal 16 | @dimen/space_medium 17 | 18 | 72dp 19 | 32dp 20 | 21 | 56dp 22 | 23 | -------------------------------------------------------------------------------- /demo/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | PacButton 3 | 4 | -------------------------------------------------------------------------------- /demo/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 13 | 14 | -------------------------------------------------------------------------------- /demo/src/test/java/com/bitvale/pacbutton/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.bitvale.pacbutton 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitvale/PacButton/2d78fd9001d3b6b5a803809b3e8f99540bfccc8b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Nov 04 16:43:15 EET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion 28 6 | 7 | defaultConfig { 8 | minSdkVersion 19 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(dir: 'libs', include: ['*.jar']) 25 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 26 | implementation 'androidx.appcompat:appcompat:1.0.0' 27 | implementation 'androidx.core:core-ktx:1.0.0' 28 | } 29 | -------------------------------------------------------------------------------- /library/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 | -------------------------------------------------------------------------------- /library/src/androidTest/java/com/bitvale/pacbutton/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.bitvale.pacbutton; 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 | * 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.bitvale.pacbutton.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /library/src/main/java/com/bitvale/pacbutton/BitmapUtil.kt: -------------------------------------------------------------------------------- 1 | package com.bitvale.pacbutton 2 | 3 | import android.graphics.Bitmap 4 | import android.graphics.Canvas 5 | import android.graphics.drawable.BitmapDrawable 6 | import android.graphics.drawable.Drawable 7 | import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat 8 | 9 | /** 10 | * Created by Alexander Kolpakov on 11/4/2018 11 | */ 12 | object BitmapUtil { 13 | fun getBitmapFromDrawable(drawable: Drawable?): Bitmap? { 14 | return if (drawable == null) null 15 | else when (drawable::class) { 16 | VectorDrawableCompat::class -> getBitmapFromVector(drawable as VectorDrawableCompat) 17 | BitmapDrawable::class -> (drawable as BitmapDrawable).bitmap 18 | else -> throw ClassCastException(drawable.toString() + " is not supported!") 19 | } 20 | } 21 | 22 | private fun getBitmapFromVector(vectorDrawable: VectorDrawableCompat): Bitmap { 23 | val bitmap = Bitmap.createBitmap(vectorDrawable.intrinsicWidth, 24 | vectorDrawable.intrinsicHeight, Bitmap.Config.ARGB_8888) 25 | val canvas = Canvas(bitmap) 26 | vectorDrawable.setBounds(0, 0, canvas.width, canvas.height) 27 | vectorDrawable.draw(canvas) 28 | return bitmap 29 | } 30 | } -------------------------------------------------------------------------------- /library/src/main/java/com/bitvale/pacbutton/Extensions.kt: -------------------------------------------------------------------------------- 1 | package com.bitvale.pacbutton 2 | 3 | import android.content.Context 4 | import android.content.res.Resources 5 | import android.graphics.LinearGradient 6 | import android.graphics.Shader 7 | import androidx.annotation.DrawableRes 8 | import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat 9 | 10 | /** 11 | * Created by Alexander Kolpakov on 11/4/2018 12 | */ 13 | fun Context.getVectorDrawable(@DrawableRes resId: Int): VectorDrawableCompat? { 14 | return try { 15 | return VectorDrawableCompat.create(resources, resId, null) 16 | } catch (e: Resources.NotFoundException) { 17 | null 18 | } 19 | } 20 | 21 | fun lerp(a: Float, b: Float, t: Float): Float { 22 | return a + (b - a) * t 23 | } -------------------------------------------------------------------------------- /library/src/main/java/com/bitvale/pacbutton/PacButton.kt: -------------------------------------------------------------------------------- 1 | package com.bitvale.pacbutton 2 | 3 | import android.animation.ValueAnimator 4 | import android.content.Context 5 | import android.graphics.* 6 | import android.os.Bundle 7 | import android.os.Parcelable 8 | import android.util.AttributeSet 9 | import android.view.View 10 | import androidx.annotation.ColorInt 11 | import androidx.core.animation.doOnEnd 12 | import androidx.core.graphics.withTranslation 13 | import androidx.interpolator.view.animation.FastOutSlowInInterpolator 14 | 15 | 16 | /** 17 | * Created by Alexander Kolpakov on 11/4/2018 18 | */ 19 | class PacButton @JvmOverloads constructor( 20 | context: Context, 21 | attrs: AttributeSet? = null, 22 | defStyleAttr: Int = 0 23 | ) : View(context, attrs, defStyleAttr) { 24 | 25 | companion object { 26 | private const val ANIMATION_DURATION = 350L 27 | private const val ANIMATION_REPEAT_COUNT = 1 28 | private const val PAC_STATE = "pac_state" 29 | private const val KEY_IS_CHECKED = "is_checked" 30 | } 31 | 32 | private val buttonRect = RectF(0f, 0f, 0f, 0f) 33 | private val buttonPaint = Paint(Paint.ANTI_ALIAS_FLAG) 34 | 35 | @ColorInt 36 | private var gradientColor1 = 0 37 | @ColorInt 38 | private var gradientColor2 = 0 39 | @ColorInt 40 | private var pacColor = 0 41 | 42 | private var topIconRect = RectF(0f, 0f, 0f, 0f) 43 | private var bottomIconRect = RectF(0f, 0f, 0f, 0f) 44 | private val iconPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG) 45 | 46 | private var bottomIcon: Bitmap? = null 47 | private var topIcon: Bitmap? = null 48 | 49 | private var iconHeight = 0f 50 | private var iconWidth = 0f 51 | 52 | private var radius = 0f 53 | private var startHeight = 0f 54 | private var heightOffset = 2f 55 | private var bottomIconTop = 0f 56 | private var bottomIconBottom = 0f 57 | private var animateOffset = 0f 58 | private var useGradient = true 59 | private var reverseStep = false 60 | private var isTopSelected = false 61 | set(value) { 62 | if (field != value) { 63 | field = value 64 | listener?.invoke(value) 65 | } 66 | } 67 | 68 | private var progressAnimator: ValueAnimator? = null 69 | private var progress = 0f 70 | set(value) { 71 | if (field != value) { 72 | field = value 73 | buttonRect.top = startHeight - lerp(0f, startHeight, value) 74 | if (reverseStep) { 75 | animateOffset = lerp(radius * 2f, 0f, value) 76 | bottomIconRect.top = bottomIconTop + animateOffset 77 | bottomIconRect.bottom = bottomIconBottom + animateOffset 78 | } 79 | if (useGradient) { 80 | setGradient(buttonRect.bottom, buttonRect.top) 81 | } 82 | postInvalidateOnAnimation() 83 | } 84 | } 85 | 86 | private var listener: ((isTopSelected: Boolean) -> Unit)? = null 87 | private var animationListener: ((animatedValue: Float) -> Unit)? = null 88 | 89 | init { 90 | setOnClickListener { animatePac() } 91 | attrs?.let { retrieveAttributes(attrs, defStyleAttr) } 92 | } 93 | 94 | private fun retrieveAttributes(attrs: AttributeSet, defStyleAttr: Int) { 95 | 96 | val typedArray = context.obtainStyledAttributes(attrs, R.styleable.PacButton, defStyleAttr, R.style.PacButton) 97 | 98 | gradientColor1 = typedArray.getColor(R.styleable.PacButton_pacGradientColor_1, 0) 99 | gradientColor2 = typedArray.getColor(R.styleable.PacButton_pacGradientColor_2, 0) 100 | pacColor = typedArray.getColor(R.styleable.PacButton_pacColor, 0) 101 | 102 | if (pacColor != 0) useGradient = false 103 | 104 | iconHeight = typedArray.getDimension(R.styleable.PacButton_iconHeight, 0f) 105 | iconWidth = typedArray.getDimension(R.styleable.PacButton_iconWidth, 0f) 106 | 107 | var drawableResId = typedArray.getResourceId(R.styleable.PacButton_bottomIcon, 0) 108 | var drawable = context.getVectorDrawable(drawableResId) 109 | bottomIcon = BitmapUtil.getBitmapFromDrawable(drawable) 110 | 111 | drawableResId = typedArray.getResourceId(R.styleable.PacButton_topIcon, 0) 112 | drawable = context.getVectorDrawable(drawableResId) 113 | topIcon = BitmapUtil.getBitmapFromDrawable(drawable) 114 | 115 | typedArray.recycle() 116 | } 117 | 118 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { 119 | val w = MeasureSpec.getSize(widthMeasureSpec) 120 | val h = MeasureSpec.getSize(heightMeasureSpec) 121 | setMeasuredDimension(w, (h * heightOffset).toInt()) 122 | } 123 | 124 | override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { 125 | super.onSizeChanged(w, h, oldw, oldh) 126 | 127 | radius = Math.min(width, height).toFloat() / 2f 128 | startHeight = (height - width).toFloat() 129 | 130 | buttonRect.top = startHeight 131 | buttonRect.right = width.toFloat() 132 | buttonRect.bottom = height.toFloat() 133 | 134 | if (iconHeight == 0f) iconHeight = radius 135 | if (iconWidth == 0f) iconWidth = radius 136 | 137 | bottomIcon?.let { 138 | val widthOffset = iconWidth / 2f 139 | val heightOffset = iconHeight / 2f 140 | 141 | bottomIconTop = (height - radius) - heightOffset 142 | bottomIconBottom = (height - radius) + heightOffset 143 | 144 | topIconRect.left = radius - widthOffset 145 | topIconRect.top = bottomIconTop 146 | topIconRect.right = radius + widthOffset 147 | topIconRect.bottom = bottomIconBottom 148 | 149 | bottomIconRect.set(topIconRect.left, topIconRect.top, topIconRect.right, topIconRect.bottom) 150 | } 151 | 152 | if (useGradient) { 153 | setGradient(buttonRect.bottom, buttonRect.top) 154 | } else { 155 | buttonPaint.color = pacColor 156 | } 157 | } 158 | 159 | private fun setGradient(y0: Float, y1: Float) { 160 | buttonPaint.shader = LinearGradient( 161 | 0f, 162 | y0, 163 | 0f, 164 | y1, 165 | gradientColor1, 166 | gradientColor2, 167 | Shader.TileMode.MIRROR 168 | ) 169 | } 170 | 171 | override fun onDraw(canvas: Canvas?) { 172 | if (reverseStep) { 173 | bottomIcon?.let { 174 | canvas?.withTranslation( 175 | y = -radius * 2f 176 | ) { 177 | canvas.drawBitmap(it, null, topIconRect, iconPaint) 178 | } 179 | } 180 | } 181 | 182 | canvas?.drawRoundRect( 183 | buttonRect, 184 | radius, 185 | radius, 186 | buttonPaint 187 | ) 188 | 189 | topIcon?.let { 190 | canvas?.withTranslation( 191 | y = -radius * 2f + animateOffset 192 | ) { 193 | canvas.drawBitmap(it, null, topIconRect, iconPaint) 194 | } 195 | } 196 | 197 | bottomIcon?.let { 198 | canvas?.drawBitmap(it, null, bottomIconRect, iconPaint) 199 | } 200 | } 201 | 202 | /** 203 | * Animate button 204 | */ 205 | private fun animatePac() { 206 | progressAnimator?.cancel() 207 | 208 | progressAnimator = ValueAnimator.ofFloat(0f, 1f).apply { 209 | addUpdateListener { 210 | progress = it.animatedValue as Float 211 | if (progress >= 0.98f && !reverseStep) { 212 | isTopSelected = !isTopSelected 213 | reverseStep = true 214 | } 215 | animationListener?.invoke(progress) 216 | } 217 | doOnEnd { 218 | reverseStep = false 219 | bottomIconRect.top = bottomIconTop 220 | bottomIconRect.bottom = bottomIconBottom 221 | swapIcons() 222 | animateOffset = 0f 223 | } 224 | interpolator = FastOutSlowInInterpolator() 225 | repeatCount = ANIMATION_REPEAT_COUNT 226 | repeatMode = ValueAnimator.REVERSE 227 | duration = ANIMATION_DURATION 228 | start() 229 | } 230 | } 231 | 232 | private fun swapIcons() { 233 | val tmp = bottomIcon 234 | bottomIcon = topIcon 235 | topIcon = tmp 236 | } 237 | 238 | /** 239 | * @return true if the top icon is selected (became bottom) otherwise false. 240 | */ 241 | fun isTopSelected() = isTopSelected 242 | 243 | /** 244 | * Register a callback to be invoked when the top icon is selected. 245 | * 246 | * @param action The callback that will run 247 | */ 248 | fun setSelectAction(action: (isTopSelected: Boolean) -> Unit) { 249 | this.listener = action 250 | } 251 | 252 | /** 253 | * Adds a listener that is sent update events through the life of 254 | * an animation. This method is called for every frame of the animation, 255 | * after the values for the animation have been calculated. 256 | * 257 | * @param listener the listener to be added for pac button animation. 258 | */ 259 | fun setAnimationUpdateListener(listener: (animatedValue: Float) -> Unit) { 260 | this.animationListener = listener 261 | } 262 | 263 | override fun onSaveInstanceState(): Parcelable { 264 | super.onSaveInstanceState() 265 | return Bundle().apply { 266 | putBoolean(KEY_IS_CHECKED, isTopSelected) 267 | putParcelable(PAC_STATE, super.onSaveInstanceState()) 268 | } 269 | } 270 | 271 | override fun onRestoreInstanceState(state: Parcelable?) { 272 | if (state is Bundle) { 273 | super.onRestoreInstanceState(state.getParcelable(PAC_STATE)) 274 | isTopSelected = state.getBoolean(KEY_IS_CHECKED) 275 | if (isTopSelected) swapIcons() 276 | } 277 | } 278 | } -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /library/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #7651F8 4 | #E74996 5 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | PacButton 3 | 4 | -------------------------------------------------------------------------------- /library/src/main/res/values/style.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /library/src/test/java/com/bitvale/pacbutton/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.bitvale.pacbutton; 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 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':demo', ':library' 2 | --------------------------------------------------------------------------------