diff --git a/app/build.gradle b/app/build.gradle index ce7aca2..5f3ace8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 22 - buildToolsVersion "22.0.1" + compileSdkVersion 29 defaultConfig { applicationId "com.github.glomadrian.materialanimatedswitch.sample" - minSdkVersion 9 - targetSdkVersion 22 + minSdkVersion 14 + targetSdkVersion 29 versionCode 1 versionName "1.0" } @@ -20,7 +19,7 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:22.2.0' - compile project (':materialanimatedswitch') + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "androidx.appcompat:appcompat:1.1.0" + implementation project (':materialanimatedswitch') } diff --git a/app/src/androidTest/java/com/github/glomadrian/materialanimatedswitch/ApplicationTest.java b/app/src/androidTest/java/com/github/glomadrian/materialanimatedswitch/ApplicationTest.java deleted file mode 100644 index 043f960..0000000 --- a/app/src/androidTest/java/com/github/glomadrian/materialanimatedswitch/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.glomadrian.materialanimatedswitch; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 643f33b..075eb61 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,23 +1,20 @@ + package="com.github.glomadrian.materialanimatedswitch.sample"> - - - - - - - - + android:theme="@style/AppTheme"> + + + + + + + diff --git a/app/src/main/java/com/github/glomadrian/materialanimatedswitch/sample/MainActivity.java b/app/src/main/java/com/github/glomadrian/materialanimatedswitch/sample/MainActivity.java index c7c086e..411ea14 100644 --- a/app/src/main/java/com/github/glomadrian/materialanimatedswitch/sample/MainActivity.java +++ b/app/src/main/java/com/github/glomadrian/materialanimatedswitch/sample/MainActivity.java @@ -1,9 +1,11 @@ package com.github.glomadrian.materialanimatedswitch.sample; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; + import com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch; public class MainActivity extends AppCompatActivity { @@ -15,23 +17,25 @@ public class MainActivity extends AppCompatActivity { private MaterialAnimatedSwitch materialAnimatedSwitch4; private MaterialAnimatedSwitch masterSwitch; - @Override protected void onCreate(Bundle savedInstanceState) { + @Override + protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mainView = findViewById(R.id.main); - materialAnimatedSwitch = (MaterialAnimatedSwitch) findViewById(R.id.pin); - materialAnimatedSwitch2 = (MaterialAnimatedSwitch) findViewById(R.id.pin2); - materialAnimatedSwitch3 = (MaterialAnimatedSwitch) findViewById(R.id.pin3); - materialAnimatedSwitch4 = (MaterialAnimatedSwitch) findViewById(R.id.pin4); - masterSwitch = (MaterialAnimatedSwitch) findViewById(R.id.masterSwitch); + materialAnimatedSwitch = findViewById(R.id.pin); + materialAnimatedSwitch2 = findViewById(R.id.pin2); + materialAnimatedSwitch3 = findViewById(R.id.pin3); + materialAnimatedSwitch4 = findViewById(R.id.pin4); + masterSwitch = findViewById(R.id.masterSwitch); materialAnimatedSwitch.setOnCheckedChangeListener( - new MaterialAnimatedSwitch.OnCheckedChangeListener() { - @Override public void onCheckedChanged(boolean isChecked) { - Toast.makeText(MainActivity.this, materialAnimatedSwitch.isChecked() + "", - Toast.LENGTH_SHORT).show(); - materialAnimatedSwitch2.toggle(); - } - }); + new MaterialAnimatedSwitch.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(boolean isChecked) { + Toast.makeText(MainActivity.this, materialAnimatedSwitch.isChecked() + "", + Toast.LENGTH_SHORT).show(); + materialAnimatedSwitch2.toggle(); + } + }); } } diff --git a/app/src/main/java/com/github/glomadrian/materialanimatedswitch/sample/Utils.java b/app/src/main/java/com/github/glomadrian/materialanimatedswitch/sample/Utils.java index 1b7f14f..090d19f 100644 --- a/app/src/main/java/com/github/glomadrian/materialanimatedswitch/sample/Utils.java +++ b/app/src/main/java/com/github/glomadrian/materialanimatedswitch/sample/Utils.java @@ -13,7 +13,7 @@ public class Utils { */ public static int dpToPx(float dp, Resources resources) { float px = - TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); + TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); return (int) px; } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index eceef21..4011383 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,87 +1,81 @@ - - - - - + tools:context=".MainActivity"> + app:ball_release_color="@color/md_teal_500" + app:base_press_color="@color/md_teal_50" + app:base_release_color="@color/md_teal_900" + app:icon_press="@drawable/ic_radio_button_on_teal_500_36dp" + app:icon_release="@drawable/ic_radio_button_off_white_36dp" /> - + android:layout_height="wrap_content" + android:layout_centerInParent="true" + android:orientation="vertical" + android:weightSum="4"> - - + + + + + + + + diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 24672e5..4777610 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -2,8 +2,9 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"> - + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 9134163..6936a88 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,305 +1,305 @@ - #E57373 - #B39DDB - #F44336 - #673AB7 + #E57373 + #B39DDB + #F44336 + #673AB7 - + - - #FFEBEE - #FFCDD2 - #EF9A9A - #E57373 - #EF5350 - #F44336 - #E53935 - #D32F2F - #C62828 - #B71C1C - #FF8A80 - #FF5252 - #FF1744 - #D50000 + + #FFEBEE + #FFCDD2 + #EF9A9A + #E57373 + #EF5350 + #F44336 + #E53935 + #D32F2F + #C62828 + #B71C1C + #FF8A80 + #FF5252 + #FF1744 + #D50000 - - #FCE4EC - #F8BBD0 - #F48FB1 - #F06292 - #EC407A - #E91E63 - #D81B60 - #C2185B - #AD1457 - #880E4F - #FF80AB - #FF4081 - #F50057 - #C51162 + + #FCE4EC + #F8BBD0 + #F48FB1 + #F06292 + #EC407A + #E91E63 + #D81B60 + #C2185B + #AD1457 + #880E4F + #FF80AB + #FF4081 + #F50057 + #C51162 - - #F3E5F5 - #E1BEE7 - #CE93D8 - #BA68C8 - #AB47BC - #9C27B0 - #8E24AA - #7B1FA2 - #6A1B9A - #4A148C - #EA80FC - #E040FB - #D500F9 - #AA00FF + + #F3E5F5 + #E1BEE7 + #CE93D8 + #BA68C8 + #AB47BC + #9C27B0 + #8E24AA + #7B1FA2 + #6A1B9A + #4A148C + #EA80FC + #E040FB + #D500F9 + #AA00FF - - #EDE7F6 - #D1C4E9 - #B39DDB - #9575CD - #7E57C2 - #673AB7 - #5E35B1 - #512DA8 - #4527A0 - #311B92 - #B388FF - #7C4DFF - #651FFF - #6200EA + + #EDE7F6 + #D1C4E9 + #B39DDB + #9575CD + #7E57C2 + #673AB7 + #5E35B1 + #512DA8 + #4527A0 + #311B92 + #B388FF + #7C4DFF + #651FFF + #6200EA - - #E8EAF6 - #C5CAE9 - #9FA8DA - #7986CB - #5C6BC0 - #3F51B5 - #3949AB - #303F9F - #283593 - #1A237E - #8C9EFF - #536DFE - #3D5AFE - #304FFE + + #E8EAF6 + #C5CAE9 + #9FA8DA + #7986CB + #5C6BC0 + #3F51B5 + #3949AB + #303F9F + #283593 + #1A237E + #8C9EFF + #536DFE + #3D5AFE + #304FFE - - #E3F2FD - #BBDEFB - #90CAF9 - #64B5F6 - #42A5F5 - #2196F3 - #1E88E5 - #1976D2 - #1565C0 - #0D47A1 - #82B1FF - #448AFF - #2979FF - #2962FF + + #E3F2FD + #BBDEFB + #90CAF9 + #64B5F6 + #42A5F5 + #2196F3 + #1E88E5 + #1976D2 + #1565C0 + #0D47A1 + #82B1FF + #448AFF + #2979FF + #2962FF - - #E1F5FE - #B3E5FC - #81D4fA - #4fC3F7 - #29B6FC - #03A9F4 - #039BE5 - #0288D1 - #0277BD - #01579B - #80D8FF - #40C4FF - #00B0FF - #0091EA + + #E1F5FE + #B3E5FC + #81D4fA + #4fC3F7 + #29B6FC + #03A9F4 + #039BE5 + #0288D1 + #0277BD + #01579B + #80D8FF + #40C4FF + #00B0FF + #0091EA - - #E0F7FA - #B2EBF2 - #80DEEA - #4DD0E1 - #26C6DA - #00BCD4 - #00ACC1 - #0097A7 - #00838F - #006064 - #84FFFF - #18FFFF - #00E5FF - #00B8D4 + + #E0F7FA + #B2EBF2 + #80DEEA + #4DD0E1 + #26C6DA + #00BCD4 + #00ACC1 + #0097A7 + #00838F + #006064 + #84FFFF + #18FFFF + #00E5FF + #00B8D4 - - #E0F2F1 - #B2DFDB - #80CBC4 - #4DB6AC - #26A69A - #009688 - #00897B - #00796B - #00695C - #004D40 - #A7FFEB - #64FFDA - #1DE9B6 - #00BFA5 + + #E0F2F1 + #B2DFDB + #80CBC4 + #4DB6AC + #26A69A + #009688 + #00897B + #00796B + #00695C + #004D40 + #A7FFEB + #64FFDA + #1DE9B6 + #00BFA5 - - #E8F5E9 - #C8E6C9 - #A5D6A7 - #81C784 - #66BB6A - #4CAF50 - #43A047 - #388E3C - #2E7D32 - #1B5E20 - #B9F6CA - #69F0AE - #00E676 - #00C853 + + #E8F5E9 + #C8E6C9 + #A5D6A7 + #81C784 + #66BB6A + #4CAF50 + #43A047 + #388E3C + #2E7D32 + #1B5E20 + #B9F6CA + #69F0AE + #00E676 + #00C853 - - #F1F8E9 - #DCEDC8 - #C5E1A5 - #AED581 - #9CCC65 - #8BC34A - #7CB342 - #689F38 - #558B2F - #33691E - #CCFF90 - #B2FF59 - #76FF03 - #64DD17 + + #F1F8E9 + #DCEDC8 + #C5E1A5 + #AED581 + #9CCC65 + #8BC34A + #7CB342 + #689F38 + #558B2F + #33691E + #CCFF90 + #B2FF59 + #76FF03 + #64DD17 - - #F9FBE7 - #F0F4C3 - #E6EE9C - #DCE775 - #D4E157 - #CDDC39 - #C0CA33 - #A4B42B - #9E9D24 - #827717 - #F4FF81 - #EEFF41 - #C6FF00 - #AEEA00 + + #F9FBE7 + #F0F4C3 + #E6EE9C + #DCE775 + #D4E157 + #CDDC39 + #C0CA33 + #A4B42B + #9E9D24 + #827717 + #F4FF81 + #EEFF41 + #C6FF00 + #AEEA00 - - #FFFDE7 - #FFF9C4 - #FFF590 - #FFF176 - #FFEE58 - #FFEB3B - #FDD835 - #FBC02D - #F9A825 - #F57F17 - #FFFF82 - #FFFF00 - #FFEA00 - #FFD600 + + #FFFDE7 + #FFF9C4 + #FFF590 + #FFF176 + #FFEE58 + #FFEB3B + #FDD835 + #FBC02D + #F9A825 + #F57F17 + #FFFF82 + #FFFF00 + #FFEA00 + #FFD600 - - #FFF8E1 - #FFECB3 - #FFE082 - #FFD54F - #FFCA28 - #FFC107 - #FFB300 - #FFA000 - #FF8F00 - #FF6F00 - #FFE57F - #FFD740 - #FFC400 - #FFAB00 + + #FFF8E1 + #FFECB3 + #FFE082 + #FFD54F + #FFCA28 + #FFC107 + #FFB300 + #FFA000 + #FF8F00 + #FF6F00 + #FFE57F + #FFD740 + #FFC400 + #FFAB00 - - #FFF3E0 - #FFE0B2 - #FFCC80 - #FFB74D - #FFA726 - #FF9800 - #FB8C00 - #F57C00 - #EF6C00 - #E65100 - #FFD180 - #FFAB40 - #FF9100 - #FF6D00 + + #FFF3E0 + #FFE0B2 + #FFCC80 + #FFB74D + #FFA726 + #FF9800 + #FB8C00 + #F57C00 + #EF6C00 + #E65100 + #FFD180 + #FFAB40 + #FF9100 + #FF6D00 - - #FBE9E7 - #FFCCBC - #FFAB91 - #FF8A65 - #FF7043 - #FF5722 - #F4511E - #E64A19 - #D84315 - #BF360C - #FF9E80 - #FF6E40 - #FF3D00 - #DD2600 + + #FBE9E7 + #FFCCBC + #FFAB91 + #FF8A65 + #FF7043 + #FF5722 + #F4511E + #E64A19 + #D84315 + #BF360C + #FF9E80 + #FF6E40 + #FF3D00 + #DD2600 - - #EFEBE9 - #D7CCC8 - #BCAAA4 - #A1887F - #8D6E63 - #795548 - #6D4C41 - #5D4037 - #4E342E - #3E2723 + + #EFEBE9 + #D7CCC8 + #BCAAA4 + #A1887F + #8D6E63 + #795548 + #6D4C41 + #5D4037 + #4E342E + #3E2723 - - #FAFAFA - #F5F5F5 - #EEEEEE - #E0E0E0 - #BDBDBD - #9E9E9E - #757575 - #616161 - #424242 - #212121 - #000000 - #ffffff + + #FAFAFA + #F5F5F5 + #EEEEEE + #E0E0E0 + #BDBDBD + #9E9E9E + #757575 + #616161 + #424242 + #212121 + #000000 + #ffffff - - #ECEFF1 - #CFD8DC - #B0BBC5 - #90A4AE - #78909C - #607D8B - #546E7A - #455A64 - #37474F - #263238 + + #ECEFF1 + #CFD8DC + #B0BBC5 + #90A4AE + #78909C + #607D8B + #546E7A + #455A64 + #37474F + #263238 \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index acf94cc..47c8224 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,5 +1,5 @@ - - 16dp - 16dp + + 16dp + 16dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a498d3c..40f03a5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,6 @@ - MaterialAnimatedSwitch + MaterialAnimatedSwitch - Hello world! - Settings + Hello world! + Settings diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 1355d09..766ab99 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,8 +1,8 @@ - - + + diff --git a/build.gradle b/build.gradle index df1607e..d840f1d 100644 --- a/build.gradle +++ b/build.gradle @@ -2,10 +2,11 @@ buildscript { repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.2.3' + classpath 'com.android.tools.build:gradle:3.6.0' classpath 'com.github.dcendents:android-maven-plugin:1.2' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1' // NOTE: Do not place your application dependencies here; they belong @@ -16,5 +17,6 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/gradle.properties b/gradle.properties index 1d3591c..ccd5dda 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,5 @@ # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true \ No newline at end of file +# org.gradle.parallel=true +android.useAndroidX=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0c71e76..b842417 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/materialanimatedswitch/build.gradle b/materialanimatedswitch/build.gradle index e2fc85d..faf9312 100644 --- a/materialanimatedswitch/build.gradle +++ b/materialanimatedswitch/build.gradle @@ -1,25 +1,30 @@ apply plugin: 'com.android.library' +ext { + PUBLISH_GROUP_ID = 'com.github.glomadrian' + PUBLISH_ARTIFACT_ID = 'materialanimatedswitch' + PUBLISH_VERSION = '1.2' +} android { - compileSdkVersion 22 - buildToolsVersion "22.0.1" + compileSdkVersion 29 - defaultConfig { - minSdkVersion 9 - targetSdkVersion 22 - versionCode 1 - versionName "1.1" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + defaultConfig { + minSdkVersion 14 + targetSdkVersion 29 + versionCode 1 + versionName "1.1" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } } - } } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:22.2.0' - compile 'com.nineoldandroids:library:2.4.0' -} \ No newline at end of file + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.1.0' +} + +apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle' \ No newline at end of file diff --git a/materialanimatedswitch/src/androidTest/java/com/github/glomadrian/materialanimatedswitch/ApplicationTest.java b/materialanimatedswitch/src/androidTest/java/com/github/glomadrian/materialanimatedswitch/ApplicationTest.java index 043f960..a583d37 100644 --- a/materialanimatedswitch/src/androidTest/java/com/github/glomadrian/materialanimatedswitch/ApplicationTest.java +++ b/materialanimatedswitch/src/androidTest/java/com/github/glomadrian/materialanimatedswitch/ApplicationTest.java @@ -7,7 +7,7 @@ * Testing Fundamentals */ public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } + public ApplicationTest() { + super(Application.class); + } } \ No newline at end of file diff --git a/materialanimatedswitch/src/androidTest/java/com/github/glomadrian/materialanimatedswitch/RangeTest.java b/materialanimatedswitch/src/androidTest/java/com/github/glomadrian/materialanimatedswitch/RangeTest.java index 8e91e96..eb07e21 100644 --- a/materialanimatedswitch/src/androidTest/java/com/github/glomadrian/materialanimatedswitch/RangeTest.java +++ b/materialanimatedswitch/src/androidTest/java/com/github/glomadrian/materialanimatedswitch/RangeTest.java @@ -7,31 +7,31 @@ */ public class RangeTest extends AndroidTestCase { - /** - * Formula testing Result := ((Input - InputLow) / (InputHigh - InputLow)) * (OutputHigh - - * OutputLow) + OutputLow; - * - * the to range is 0-20 - * the form gange is 0-10 - * the result must be 10 - * - * @throws Exception - */ - public void testRange() throws Exception { - int value = convertRange(5, 0, 20, 0, 10); - - int value2 = convert(5, 0,35,0,255); - - assertTrue(value == 10); - assertTrue(value2 == 10); - - } - - private int convertRange(int value, int fromLow, int fromHigh, int toLow, int toHigh) { - return ((value - fromLow) / (fromHigh - fromLow)) * (toHigh - toLow) + toLow; - } - - private int convert(int value, int min1, int max1, int min2, int max2) { - return min2 + ((value - min1) / (max1 - min1)) * (max2 - min2); - } + /** + * Formula testing Result := ((Input - InputLow) / (InputHigh - InputLow)) * (OutputHigh - + * OutputLow) + OutputLow; + *

+ * the to range is 0-20 + * the form gange is 0-10 + * the result must be 10 + * + * @throws Exception + */ + public void testRange() throws Exception { + int value = convertRange(5, 0, 20, 0, 10); + + int value2 = convert(5, 0, 35, 0, 255); + + assertTrue(value == 10); + assertTrue(value2 == 10); + + } + + private int convertRange(int value, int fromLow, int fromHigh, int toLow, int toHigh) { + return ((value - fromLow) / (fromHigh - fromLow)) * (toHigh - toLow) + toLow; + } + + private int convert(int value, int min1, int max1, int min2, int max2) { + return min2 + ((value - min1) / (max1 - min1)) * (max2 - min2); + } } diff --git a/materialanimatedswitch/src/main/AndroidManifest.xml b/materialanimatedswitch/src/main/AndroidManifest.xml index 9607480..4f761ae 100644 --- a/materialanimatedswitch/src/main/AndroidManifest.xml +++ b/materialanimatedswitch/src/main/AndroidManifest.xml @@ -1,10 +1,10 @@ - + - + diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/MaterialAnimatedSwitch.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/MaterialAnimatedSwitch.java index dfd70a4..402a411 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/MaterialAnimatedSwitch.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/MaterialAnimatedSwitch.java @@ -198,6 +198,15 @@ public void toggle() { } } + public void setOnCheckedChangeListener(OnCheckedChangeListener onCheckedChangeListener) { + this.onCheckedChangeListener = onCheckedChangeListener; + } + + public interface OnCheckedChangeListener { + + void onCheckedChanged(boolean isChecked); + } + /** * Avoid click when ball is still in movement * Call listener when state is updated @@ -221,15 +230,6 @@ public void update(Observable observable, Object data) { } } - public void setOnCheckedChangeListener(OnCheckedChangeListener onCheckedChangeListener) { - this.onCheckedChangeListener = onCheckedChangeListener; - } - - public interface OnCheckedChangeListener { - - void onCheckedChanged(boolean isChecked); - } - private class CancelTask implements Runnable { @Override diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/MaterialAnimatedSwitchState.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/MaterialAnimatedSwitchState.java index 295171c..21297f3 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/MaterialAnimatedSwitchState.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/MaterialAnimatedSwitchState.java @@ -4,5 +4,5 @@ * @author Adrián García Lomas */ public enum MaterialAnimatedSwitchState { - INIT, RELEASE, PRESS + INIT, RELEASE, PRESS } diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/Utils.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/Utils.java index d9fc0bd..324c87e 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/Utils.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/Utils.java @@ -8,12 +8,12 @@ */ public class Utils { - /** - * Convert Dp to Pixel - */ - public static int dpToPx(float dp, Resources resources) { - float px = - TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); - return (int) px; - } + /** + * Convert Dp to Pixel + */ + public static int dpToPx(float dp, Resources resources) { + float px = + TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); + return (int) px; + } } diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/observer/BallFinishObservable.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/observer/BallFinishObservable.java index 2ad7a85..bdd52db 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/observer/BallFinishObservable.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/observer/BallFinishObservable.java @@ -7,19 +7,19 @@ */ public class BallFinishObservable extends Observable { - private BallState state; + private BallState state; - public void setBallState(BallState state) { - this.state = state; - setChanged(); - notifyObservers(); - } + public void setBallState(BallState state) { + this.state = state; + setChanged(); + notifyObservers(); + } - public BallState getState() { - return state; - } + public BallState getState() { + return state; + } - public static enum BallState { - RELEASE, PRESS, MOVE - } + public static enum BallState { + RELEASE, PRESS, MOVE + } } diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/observer/BallMoveObservable.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/observer/BallMoveObservable.java index 25d3483..4030a4c 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/observer/BallMoveObservable.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/observer/BallMoveObservable.java @@ -10,26 +10,26 @@ public class BallMoveObservable extends Observable { private int ballAnimationValue; private int ballPosition; - public void setBallAnimationValue(int val) { - this.ballAnimationValue = val; - setChanged(); - notifyObservers(); - } - - public void update() { - setChanged(); - notifyObservers(); - } - - public int getBallAnimationValue() { - return ballAnimationValue; - } - - public void setBallPosition(int ballPosition) { - this.ballPosition = ballPosition; - } - - public int getBallPosition() { - return ballPosition; - } + public void update() { + setChanged(); + notifyObservers(); + } + + public int getBallAnimationValue() { + return ballAnimationValue; + } + + public void setBallAnimationValue(int val) { + this.ballAnimationValue = val; + setChanged(); + notifyObservers(); + } + + public int getBallPosition() { + return ballPosition; + } + + public void setBallPosition(int ballPosition) { + this.ballPosition = ballPosition; + } } diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/BallPainter.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/BallPainter.java index 6233b9d..1621700 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/BallPainter.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/BallPainter.java @@ -1,163 +1,179 @@ package com.github.glomadrian.materialanimatedswitch.painter; +import android.animation.Animator; +import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; + import com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitchState; import com.github.glomadrian.materialanimatedswitch.R; import com.github.glomadrian.materialanimatedswitch.observer.BallFinishObservable; import com.github.glomadrian.materialanimatedswitch.observer.BallMoveObservable; -import com.nineoldandroids.animation.Animator; -import com.nineoldandroids.animation.ValueAnimator; /** * @author Adrián García Lomas */ public class BallPainter implements SwitchInboxPinnedPainter { - protected Paint paint; - protected Paint toBgPainter; - protected int padding; - protected int height; - protected int width; - protected int radius; - protected int ballPositionX; - protected int ballStartPositionX; - protected int ballMovementRange; - private ValueAnimator moveAnimator; - private ValueAnimator colorAnimator; - private MaterialAnimatedSwitchState actualState; - private BallFinishObservable ballFinishObservable; - private BallMoveObservable ballMoveObservable; - private Context context; - private int middle; - private int bgColor; - private int toBgColor; - - public BallPainter(int bgColor, int toBgColor, int padding, - BallFinishObservable ballFinishObservable, BallMoveObservable ballMoveObservable, - Context context) { - this.bgColor = bgColor; - this.toBgColor = toBgColor; - this.padding = padding; - this.ballFinishObservable = ballFinishObservable; - this.ballMoveObservable = ballMoveObservable; - this.context = context; - init(); - } - - private void init() { - paint = new Paint(); - paint.setColor(bgColor); - paint.setStyle(Paint.Style.FILL); - paint.setAntiAlias(true); - toBgPainter = new Paint(); - toBgPainter.setColor(toBgColor); - toBgPainter.setStyle(Paint.Style.FILL); - toBgPainter.setAntiAlias(true); - toBgPainter.setAlpha(0); - radius = (int) context.getResources().getDimension(R.dimen.ball_radius); - ballStartPositionX = (int) context.getResources().getDimension(R.dimen.ball_start_position); - ballPositionX = padding; - } - - private void initAnimator() { - int from = padding; - int to = width - padding; - ballMovementRange = to - from; - moveAnimator = ValueAnimator.ofInt(from, to); - moveAnimator.addUpdateListener(new BallAnimatorListener()); - moveAnimator.addListener(new BallAnimatorFinishListener()); - } - - private void initColorAnimator() { - colorAnimator = ValueAnimator.ofInt(0, 255); - colorAnimator.setDuration(ballMovementRange); - colorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override public void onAnimationUpdate(ValueAnimator animation) { - toBgPainter.setAlpha((Integer) animation.getAnimatedValue()); - } - }); - } - - @Override public void draw(Canvas canvas) { - canvas.drawCircle(ballPositionX, middle, radius, paint); - canvas.drawCircle(ballPositionX, middle, radius, toBgPainter); - } - - @Override public void setColor(int color) { - this.bgColor = color; - } - - @Override public int getColor() { - return bgColor; - } - - @Override public void onSizeChanged(int height, int width) { - this.height = height; - this.width = width; - middle = height / 2; - initAnimator(); - initColorAnimator(); - } - - @Override public void setState(MaterialAnimatedSwitchState state) { - switch (state) { - case PRESS: - actualState = MaterialAnimatedSwitchState.PRESS; - moveAnimator.start(); - break; - case RELEASE: - actualState = MaterialAnimatedSwitchState.RELEASE; - moveAnimator.reverse(); + protected Paint paint; + protected Paint toBgPainter; + protected int padding; + protected int height; + protected int width; + protected int radius; + protected int ballPositionX; + protected int ballStartPositionX; + protected int ballMovementRange; + private ValueAnimator moveAnimator; + private ValueAnimator colorAnimator; + private MaterialAnimatedSwitchState actualState; + private BallFinishObservable ballFinishObservable; + private BallMoveObservable ballMoveObservable; + private Context context; + private int middle; + private int bgColor; + private int toBgColor; + + public BallPainter(int bgColor, int toBgColor, int padding, + BallFinishObservable ballFinishObservable, BallMoveObservable ballMoveObservable, + Context context) { + this.bgColor = bgColor; + this.toBgColor = toBgColor; + this.padding = padding; + this.ballFinishObservable = ballFinishObservable; + this.ballMoveObservable = ballMoveObservable; + this.context = context; + init(); } - } - private class BallAnimatorFinishListener implements ValueAnimator.AnimatorListener { + private void init() { + paint = new Paint(); + paint.setColor(bgColor); + paint.setStyle(Paint.Style.FILL); + paint.setAntiAlias(true); + toBgPainter = new Paint(); + toBgPainter.setColor(toBgColor); + toBgPainter.setStyle(Paint.Style.FILL); + toBgPainter.setAntiAlias(true); + toBgPainter.setAlpha(0); + radius = (int) context.getResources().getDimension(R.dimen.ball_radius); + ballStartPositionX = (int) context.getResources().getDimension(R.dimen.ball_start_position); + ballPositionX = padding; + } - @Override public void onAnimationStart(Animator animation) { - ballFinishObservable.setBallState(BallFinishObservable.BallState.MOVE); + private void initAnimator() { + int from = padding; + int to = width - padding; + ballMovementRange = to - from; + moveAnimator = ValueAnimator.ofInt(from, to); + moveAnimator.addUpdateListener(new BallAnimatorListener()); + moveAnimator.addListener(new BallAnimatorFinishListener()); } - @Override public void onAnimationEnd(Animator animation) { - if (actualState.equals(MaterialAnimatedSwitchState.PRESS)) { - ballFinishObservable.setBallState(BallFinishObservable.BallState.PRESS); - } else { - ballFinishObservable.setBallState(BallFinishObservable.BallState.RELEASE); - } + private void initColorAnimator() { + colorAnimator = ValueAnimator.ofInt(0, 255); + colorAnimator.setDuration(ballMovementRange); + colorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + toBgPainter.setAlpha((Integer) animation.getAnimatedValue()); + } + }); } - @Override public void onAnimationCancel(Animator animation) { - //Empty + @Override + public void draw(Canvas canvas) { + canvas.drawCircle(ballPositionX, middle, radius, paint); + canvas.drawCircle(ballPositionX, middle, radius, toBgPainter); } - @Override public void onAnimationRepeat(Animator animation) { - //Empty + @Override + public int getColor() { + return bgColor; } - } - - private class BallAnimatorListener implements ValueAnimator.AnimatorUpdateListener { - - @Override public void onAnimationUpdate(ValueAnimator animation) { - int value = (int) animation.getAnimatedValue(); - //Move the ball - ballPositionX = value; - //1- Get pixel of movement from 0 to movementRange - int pixelMove = value - padding; - //Transform the range movement to a 0 - 100 range - int rangeValue = getAnimatedRange(pixelMove); - //Change the color animation to the actual range value (duration is 100) - colorAnimator.setCurrentPlayTime(rangeValue); - //Set ball position to - ballMoveObservable.setBallPosition(ballPositionX); - //Put this value on a observable the listeners know the state of the movement in a range of 0 - //to 100 - ballMoveObservable.setBallAnimationValue(rangeValue); + + @Override + public void setColor(int color) { + this.bgColor = color; + } + + @Override + public void onSizeChanged(int height, int width) { + this.height = height; + this.width = width; + middle = height / 2; + initAnimator(); + initColorAnimator(); + } + + @Override + public void setState(MaterialAnimatedSwitchState state) { + switch (state) { + case PRESS: + actualState = MaterialAnimatedSwitchState.PRESS; + if (moveAnimator != null) { + moveAnimator.start(); + } + break; + case RELEASE: + actualState = MaterialAnimatedSwitchState.RELEASE; + if (moveAnimator != null) { + moveAnimator.reverse(); + } + } + } + + private class BallAnimatorFinishListener implements ValueAnimator.AnimatorListener { + + @Override + public void onAnimationStart(Animator animation) { + ballFinishObservable.setBallState(BallFinishObservable.BallState.MOVE); + } + + @Override + public void onAnimationEnd(Animator animation) { + if (actualState.equals(MaterialAnimatedSwitchState.PRESS)) { + ballFinishObservable.setBallState(BallFinishObservable.BallState.PRESS); + } else { + ballFinishObservable.setBallState(BallFinishObservable.BallState.RELEASE); + } + } + + @Override + public void onAnimationCancel(Animator animation) { + //Empty + } + + @Override + public void onAnimationRepeat(Animator animation) { + //Empty + } } - private int getAnimatedRange(int value) { - return ((value * 100) / ballMovementRange); + private class BallAnimatorListener implements ValueAnimator.AnimatorUpdateListener { + + @Override + public void onAnimationUpdate(ValueAnimator animation) { + int value = (int) animation.getAnimatedValue(); + //Move the ball + ballPositionX = value; + //1- Get pixel of movement from 0 to movementRange + int pixelMove = value - padding; + //Transform the range movement to a 0 - 100 range + int rangeValue = getAnimatedRange(pixelMove); + //Change the color animation to the actual range value (duration is 100) + colorAnimator.setCurrentPlayTime(rangeValue); + //Set ball position to + ballMoveObservable.setBallPosition(ballPositionX); + //Put this value on a observable the listeners know the state of the movement in a range of 0 + //to 100 + ballMoveObservable.setBallAnimationValue(rangeValue); + } + + private int getAnimatedRange(int value) { + return ((value * 100) / ballMovementRange); + } } - } } diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/BallShadowPainter.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/BallShadowPainter.java index 80a4971..6caed4e 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/BallShadowPainter.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/BallShadowPainter.java @@ -3,8 +3,7 @@ import android.content.Context; import android.graphics.BlurMaskFilter; import android.graphics.Canvas; -import android.view.View; -import com.github.glomadrian.materialanimatedswitch.Utils; + import com.github.glomadrian.materialanimatedswitch.observer.BallFinishObservable; import com.github.glomadrian.materialanimatedswitch.observer.BallMoveObservable; @@ -13,15 +12,16 @@ */ public class BallShadowPainter extends BallPainter { - public BallShadowPainter(int bgColor, int toBgColor, int padding, int shadowColor, - BallFinishObservable ballFinishObservable, BallMoveObservable ballMoveObservable, - Context context) { - super(bgColor, toBgColor, padding, ballFinishObservable, ballMoveObservable, context); - paint.setColor(shadowColor); - paint.setMaskFilter(new BlurMaskFilter(3, BlurMaskFilter.Blur.NORMAL)); - } + public BallShadowPainter(int bgColor, int toBgColor, int padding, int shadowColor, + BallFinishObservable ballFinishObservable, BallMoveObservable ballMoveObservable, + Context context) { + super(bgColor, toBgColor, padding, ballFinishObservable, ballMoveObservable, context); + paint.setColor(shadowColor); + paint.setMaskFilter(new BlurMaskFilter(3, BlurMaskFilter.Blur.NORMAL)); + } - @Override public void draw(Canvas canvas) { - canvas.drawCircle(ballPositionX, (height / 2) + 2, radius , paint); - } + @Override + public void draw(Canvas canvas) { + canvas.drawCircle(ballPositionX, (height / 2) + 2, radius, paint); + } } diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/BasePainter.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/BasePainter.java index dc1fe45..843f8b0 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/BasePainter.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/BasePainter.java @@ -1,10 +1,11 @@ package com.github.glomadrian.materialanimatedswitch.painter; +import android.animation.ValueAnimator; import android.graphics.Canvas; import android.graphics.Paint; + import com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitchState; import com.github.glomadrian.materialanimatedswitch.observer.BallMoveObservable; -import com.nineoldandroids.animation.ValueAnimator; import java.util.Observable; import java.util.Observer; @@ -14,77 +15,84 @@ */ public class BasePainter implements SwitchInboxPinnedPainter, Observer { - private Paint paint; - private int bgColor; - private int toBgColor; - private int padding; - private int height; - private int width; - private Paint toBgPainter; - private ValueAnimator colorAnimator; - private BallMoveObservable ballMoveObservable; - - public BasePainter(int bgColor, int toBgColor, int padding, - BallMoveObservable ballMoveObservable) { - this.bgColor = bgColor; - this.toBgColor = toBgColor; - this.padding = padding; - this.ballMoveObservable = ballMoveObservable; - init(); - } - - private void init() { - paint = new Paint(); - paint.setColor(bgColor); - paint.setStrokeCap(Paint.Cap.ROUND); - paint.setAntiAlias(true); - - toBgPainter = new Paint(); - toBgPainter.setColor(toBgColor); - toBgPainter.setStrokeCap(Paint.Cap.ROUND); - toBgPainter.setAntiAlias(true); - toBgPainter.setAlpha(0); - - initColorAnimator(); - ballMoveObservable.addObserver(this); - } - - private void initColorAnimator() { - colorAnimator = ValueAnimator.ofInt(0, 255); - colorAnimator.setDuration(100); - colorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override public void onAnimationUpdate(ValueAnimator animation) { - toBgPainter.setAlpha((Integer) animation.getAnimatedValue()); - } - }); - } - - @Override public void draw(Canvas canvas) { - canvas.drawLine(padding, height / 2, width - padding, height / 2, paint); - canvas.drawLine(padding, height / 2, width - padding, height / 2, toBgPainter); - } - - @Override public int getColor() { - return bgColor; - } - - @Override public void setColor(int color) { - - } - - @Override public void onSizeChanged(int height, int width) { - this.height = height; - this.width = width; - paint.setStrokeWidth(height / 2); - toBgPainter.setStrokeWidth(height / 2); - } - - @Override public void setState(MaterialAnimatedSwitchState state) { - //Empty - } - - @Override public void update(Observable observable, Object data) { - int value = ((BallMoveObservable) observable).getBallAnimationValue(); - colorAnimator.setCurrentPlayTime(value); - } + private Paint paint; + private int bgColor; + private int toBgColor; + private int padding; + private int height; + private int width; + private Paint toBgPainter; + private ValueAnimator colorAnimator; + private BallMoveObservable ballMoveObservable; + + public BasePainter(int bgColor, int toBgColor, int padding, + BallMoveObservable ballMoveObservable) { + this.bgColor = bgColor; + this.toBgColor = toBgColor; + this.padding = padding; + this.ballMoveObservable = ballMoveObservable; + init(); + } + + private void init() { + paint = new Paint(); + paint.setColor(bgColor); + paint.setStrokeCap(Paint.Cap.ROUND); + paint.setAntiAlias(true); + + toBgPainter = new Paint(); + toBgPainter.setColor(toBgColor); + toBgPainter.setStrokeCap(Paint.Cap.ROUND); + toBgPainter.setAntiAlias(true); + toBgPainter.setAlpha(0); + + initColorAnimator(); + ballMoveObservable.addObserver(this); + } + + private void initColorAnimator() { + colorAnimator = ValueAnimator.ofInt(0, 255); + colorAnimator.setDuration(100); + colorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + toBgPainter.setAlpha((Integer) animation.getAnimatedValue()); + } + }); + } + + @Override + public void draw(Canvas canvas) { + canvas.drawLine(padding, height / 2, width - padding, height / 2, paint); + canvas.drawLine(padding, height / 2, width - padding, height / 2, toBgPainter); + } + + @Override + public int getColor() { + return bgColor; + } + + @Override + public void setColor(int color) { + + } + + @Override + public void onSizeChanged(int height, int width) { + this.height = height; + this.width = width; + paint.setStrokeWidth(height / 2); + toBgPainter.setStrokeWidth(height / 2); + } + + @Override + public void setState(MaterialAnimatedSwitchState state) { + //Empty + } + + @Override + public void update(Observable observable, Object data) { + int value = ((BallMoveObservable) observable).getBallAnimationValue(); + colorAnimator.setCurrentPlayTime(value); + } } diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/IconPainter.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/IconPainter.java index 1f550cb..6ebc0df 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/IconPainter.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/IconPainter.java @@ -4,6 +4,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; + import com.github.glomadrian.materialanimatedswitch.R; /** @@ -11,46 +12,48 @@ */ public abstract class IconPainter implements SwitchInboxPinnedPainter { - protected Bitmap iconBitmap; - protected Context context; - protected Paint paint; - protected int width; - protected int height; - protected int imageHeight; - protected int imageWidth; - protected boolean isVisible = false; - protected int iconXPosition; - protected int iconYPosition; - protected int margin; - - public IconPainter(Context context, Bitmap bitmap, int margin) { - this.context = context; - this.iconBitmap = bitmap; - this.margin = margin; - init(); - } - - private void init() { - paint = new Paint(); - paint.setAntiAlias(true); - initBitmap(); - } - - protected void initBitmap() { - int iconSize = (int) context.getResources().getDimension(R.dimen.icon_size); - iconBitmap = Bitmap.createScaledBitmap(iconBitmap, iconSize, iconSize, false); - imageHeight = iconBitmap.getHeight(); - imageWidth = iconBitmap.getWidth(); - } - - @Override public void draw(Canvas canvas) { - if (isVisible) { - canvas.drawBitmap(iconBitmap, iconXPosition, iconYPosition, paint); + protected Bitmap iconBitmap; + protected Context context; + protected Paint paint; + protected int width; + protected int height; + protected int imageHeight; + protected int imageWidth; + protected boolean isVisible = false; + protected int iconXPosition; + protected int iconYPosition; + protected int margin; + + public IconPainter(Context context, Bitmap bitmap, int margin) { + this.context = context; + this.iconBitmap = bitmap; + this.margin = margin; + init(); + } + + private void init() { + paint = new Paint(); + paint.setAntiAlias(true); + initBitmap(); + } + + protected void initBitmap() { + int iconSize = (int) context.getResources().getDimension(R.dimen.icon_size); + iconBitmap = Bitmap.createScaledBitmap(iconBitmap, iconSize, iconSize, false); + imageHeight = iconBitmap.getHeight(); + imageWidth = iconBitmap.getWidth(); + } + + @Override + public void draw(Canvas canvas) { + if (isVisible) { + canvas.drawBitmap(iconBitmap, iconXPosition, iconYPosition, paint); + } } - } - @Override public void onSizeChanged(int height, int width) { - this.height = height; - this.width = width; - } + @Override + public void onSizeChanged(int height, int width) { + this.height = height; + this.width = width; + } } diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/IconPressPainter.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/IconPressPainter.java index 594c551..5803116 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/IconPressPainter.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/IconPressPainter.java @@ -1,12 +1,13 @@ package com.github.glomadrian.materialanimatedswitch.painter; +import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Bitmap; -import com.github.glomadrian.materialanimatedswitch.R; + import com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitchState; +import com.github.glomadrian.materialanimatedswitch.R; import com.github.glomadrian.materialanimatedswitch.observer.BallFinishObservable; import com.github.glomadrian.materialanimatedswitch.observer.BallMoveObservable; -import com.nineoldandroids.animation.ValueAnimator; import java.util.Observable; import java.util.Observer; @@ -16,119 +17,127 @@ */ public class IconPressPainter extends IconPainter { - private ValueAnimator enterAnimator; - private ValueAnimator exitAnimator; - private BallFinishObservable ballFinishObservable; - private int enterAnimationStartValue; - private int exitAnimationExitValue; - private int middle; - private int iconMargin; - private int ballRadius; - private BallMoveObservable ballMoveObservable; - - public IconPressPainter(Context context, Bitmap bitmap, BallFinishObservable ballFinishObservable, - BallMoveObservable ballMoveObservable, int margin) { - super(context, bitmap, margin); - initValueAnimator(); - this.ballFinishObservable = ballFinishObservable; - this.ballMoveObservable = ballMoveObservable; - initObserver(); - } - - private void initValueAnimator() { - int movementAnimationDuration = context.getResources().getInteger(R.integer.animation_duration); - int exitAnimationDuration = context.getResources().getInteger(R.integer.exitAnimator); - - enterAnimator = ValueAnimator.ofInt(); - enterAnimator.setDuration(movementAnimationDuration); - enterAnimator.addUpdateListener(new EnterValueAnimatorListener()); - - exitAnimator = ValueAnimator.ofInt(); - exitAnimator.setDuration(exitAnimationDuration); - exitAnimator.addUpdateListener(new ExitValueAnimatorListener()); - } - - @Override public void onSizeChanged(int height, int width) { - super.onSizeChanged(height, width); - initValues(); - int iconCenterY = middle - (iconMargin); - initAnimationValues(); - enterAnimator.setIntValues(enterAnimationStartValue, iconCenterY); - exitAnimator.setIntValues(iconCenterY, iconCenterY + exitAnimationExitValue); - } - - private void initValues() { - middle = height / 2; - iconMargin = imageWidth / 2; - ballRadius = (int) context.getResources().getDimension(R.dimen.ball_radius); - iconXPosition = (width - ballRadius) + iconMargin; - } - - private void initAnimationValues() { - enterAnimationStartValue = - (int) context.getResources().getDimension(R.dimen.enterAnimationStartValue); - exitAnimationExitValue = - (int) context.getResources().getDimension(R.dimen.exitAnimationExitValue); - } - - @Override public void setColor(int color) { - //Empty - } - - @Override public int getColor() { - return 0; - } - - private void initObserver() { - ballFinishObservable.addObserver(new BallFinishListener()); - ballMoveObservable.addObserver(new BallMoveListener()); - } - - @Override public void setState(MaterialAnimatedSwitchState state) { - switch (state) { - case PRESS: - isVisible = true; - enterAnimator.start(); - break; - case RELEASE: - exitAnimator.start(); + private ValueAnimator enterAnimator; + private ValueAnimator exitAnimator; + private BallFinishObservable ballFinishObservable; + private int enterAnimationStartValue; + private int exitAnimationExitValue; + private int middle; + private int iconMargin; + private int ballRadius; + private BallMoveObservable ballMoveObservable; + + public IconPressPainter(Context context, Bitmap bitmap, BallFinishObservable ballFinishObservable, + BallMoveObservable ballMoveObservable, int margin) { + super(context, bitmap, margin); + initValueAnimator(); + this.ballFinishObservable = ballFinishObservable; + this.ballMoveObservable = ballMoveObservable; + initObserver(); + } + + private void initValueAnimator() { + int movementAnimationDuration = context.getResources().getInteger(R.integer.animation_duration); + int exitAnimationDuration = context.getResources().getInteger(R.integer.exitAnimator); + + enterAnimator = ValueAnimator.ofInt(); + enterAnimator.setDuration(movementAnimationDuration); + enterAnimator.addUpdateListener(new EnterValueAnimatorListener()); + + exitAnimator = ValueAnimator.ofInt(); + exitAnimator.setDuration(exitAnimationDuration); + exitAnimator.addUpdateListener(new ExitValueAnimatorListener()); } - } - private class BallFinishListener implements Observer { + @Override + public void onSizeChanged(int height, int width) { + super.onSizeChanged(height, width); + initValues(); + int iconCenterY = middle - (iconMargin); + initAnimationValues(); + enterAnimator.setIntValues(enterAnimationStartValue, iconCenterY); + exitAnimator.setIntValues(iconCenterY, iconCenterY + exitAnimationExitValue); + } + + private void initValues() { + middle = height / 2; + iconMargin = imageWidth / 2; + ballRadius = (int) context.getResources().getDimension(R.dimen.ball_radius); + iconXPosition = (width - ballRadius) + iconMargin; + } - @Override public void update(Observable observable, Object data) { - BallFinishObservable.BallState ballState = ((BallFinishObservable) observable).getState(); - switch (ballState) { - case RELEASE: - isVisible = false; - break; - } + private void initAnimationValues() { + enterAnimationStartValue = + (int) context.getResources().getDimension(R.dimen.enterAnimationStartValue); + exitAnimationExitValue = + (int) context.getResources().getDimension(R.dimen.exitAnimationExitValue); } - } - /** - * Listener for move the icon with the ball movement - */ - private class BallMoveListener implements Observer { + @Override + public int getColor() { + return 0; + } + + @Override + public void setColor(int color) { + //Empty + } + + private void initObserver() { + ballFinishObservable.addObserver(new BallFinishListener()); + ballMoveObservable.addObserver(new BallMoveListener()); + } + + @Override + public void setState(MaterialAnimatedSwitchState state) { + switch (state) { + case PRESS: + isVisible = true; + enterAnimator.start(); + break; + case RELEASE: + exitAnimator.start(); + } + } + + private class BallFinishListener implements Observer { + + @Override + public void update(Observable observable, Object data) { + BallFinishObservable.BallState ballState = ((BallFinishObservable) observable).getState(); + switch (ballState) { + case RELEASE: + isVisible = false; + break; + } + } + } - @Override public void update(Observable observable, Object data) { - BallMoveObservable ballMoveObservable = (BallMoveObservable) observable; - int ballPositionX = ballMoveObservable.getBallPosition(); - iconXPosition = ballPositionX - iconMargin; + /** + * Listener for move the icon with the ball movement + */ + private class BallMoveListener implements Observer { + + @Override + public void update(Observable observable, Object data) { + BallMoveObservable ballMoveObservable = (BallMoveObservable) observable; + int ballPositionX = ballMoveObservable.getBallPosition(); + iconXPosition = ballPositionX - iconMargin; + } } - } - private class EnterValueAnimatorListener implements ValueAnimator.AnimatorUpdateListener { - @Override public void onAnimationUpdate(ValueAnimator animation) { - iconYPosition = (int) animation.getAnimatedValue(); + private class EnterValueAnimatorListener implements ValueAnimator.AnimatorUpdateListener { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + iconYPosition = (int) animation.getAnimatedValue(); + } } - } - private class ExitValueAnimatorListener implements ValueAnimator.AnimatorUpdateListener { + private class ExitValueAnimatorListener implements ValueAnimator.AnimatorUpdateListener { - @Override public void onAnimationUpdate(ValueAnimator animation) { - iconYPosition = (int) animation.getAnimatedValue(); + @Override + public void onAnimationUpdate(ValueAnimator animation) { + iconYPosition = (int) animation.getAnimatedValue(); + } } - } } diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/IconReleasePainter.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/IconReleasePainter.java index a41a70a..c910e05 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/IconReleasePainter.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/IconReleasePainter.java @@ -1,12 +1,13 @@ package com.github.glomadrian.materialanimatedswitch.painter; +import android.animation.Animator; +import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Bitmap; + import com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitchState; import com.github.glomadrian.materialanimatedswitch.R; import com.github.glomadrian.materialanimatedswitch.observer.BallFinishObservable; -import com.nineoldandroids.animation.Animator; -import com.nineoldandroids.animation.ValueAnimator; import java.util.Observable; import java.util.Observer; @@ -16,183 +17,196 @@ */ public class IconReleasePainter extends IconPainter { - private ValueAnimator enterXAnimator; - private ValueAnimator enterYAnimator; - private ValueAnimator exitXAnimator; - private ValueAnimator exitYAnimator; - private ValueAnimator exitAlphaAnimator; - private int enterYAnimationStart; - private int exitYAnimatorFinish; - private int exitXAnimationStart; - private BallFinishObservable ballFinishObservable; - private MaterialAnimatedSwitchState actualState; - private int iconMargin; - private int middle; - private boolean alphaEnterTrigger = false; - - public IconReleasePainter(Context context, Bitmap bitmap, - BallFinishObservable ballFinishObservable, int margin) { - super(context, bitmap, margin); - initValueAnimator(); - this.ballFinishObservable = ballFinishObservable; - initObserver(); - } - - @Override protected void initBitmap() { - super.initBitmap(); - } - - private void initValueAnimator() { - int movementAnimationDuration = context.getResources().getInteger(R.integer.animation_duration); - int alphaAnimationDuration = - context.getResources().getInteger(R.integer.alpha_animation_duration); - int curveCompensation = - context.getResources().getInteger(R.integer.animation_curvature_compensation); - - enterXAnimator = ValueAnimator.ofInt(0, width); - enterXAnimator.setDuration(movementAnimationDuration); - enterXAnimator.addUpdateListener(new EnterXAnimationListener()); - - exitXAnimator = ValueAnimator.ofInt(); - exitXAnimator.setDuration(movementAnimationDuration); - exitXAnimator.addUpdateListener(new EnterXAnimationListener()); - - enterYAnimator = ValueAnimator.ofInt(width, 0); - enterYAnimator.setDuration(movementAnimationDuration - curveCompensation); - enterYAnimator.addUpdateListener(new EnterYAnimationListener()); - - exitYAnimator = ValueAnimator.ofInt(); - exitYAnimator.setDuration(movementAnimationDuration); - exitYAnimator.addUpdateListener(new EnterYAnimationListener()); - - exitAlphaAnimator = ValueAnimator.ofInt(0, 255); - exitAlphaAnimator.setDuration(alphaAnimationDuration); - exitAlphaAnimator.addUpdateListener(new AlphaAnimatorUpdateListener()); - exitAlphaAnimator.addListener(new AlphaAnimatorStateListener()); - } - - @Override public void setColor(int color) { - //Empty - } - - @Override public int getColor() { - return 0; - } - - @Override public void setState(MaterialAnimatedSwitchState state) { - this.actualState = state; - switch (state) { - case INIT: - isVisible = true; - break; - case PRESS: - exitYAnimator.start(); - exitXAnimator.reverse(); - exitAlphaAnimator.reverse(); - break; - case RELEASE: - isVisible = true; - enterXAnimator.reverse(); - enterYAnimator.start(); - break; + private ValueAnimator enterXAnimator; + private ValueAnimator enterYAnimator; + private ValueAnimator exitXAnimator; + private ValueAnimator exitYAnimator; + private ValueAnimator exitAlphaAnimator; + private int enterYAnimationStart; + private int exitYAnimatorFinish; + private int exitXAnimationStart; + private BallFinishObservable ballFinishObservable; + private MaterialAnimatedSwitchState actualState; + private int iconMargin; + private int middle; + private boolean alphaEnterTrigger = false; + + public IconReleasePainter(Context context, Bitmap bitmap, + BallFinishObservable ballFinishObservable, int margin) { + super(context, bitmap, margin); + initValueAnimator(); + this.ballFinishObservable = ballFinishObservable; + initObserver(); } - } - private void initObserver() { - ballFinishObservable.addObserver(new BallFinishListener()); - } + @Override + protected void initBitmap() { + super.initBitmap(); + } - private class BallFinishListener implements Observer { + private void initValueAnimator() { + int movementAnimationDuration = context.getResources().getInteger(R.integer.animation_duration); + int alphaAnimationDuration = + context.getResources().getInteger(R.integer.alpha_animation_duration); + int curveCompensation = + context.getResources().getInteger(R.integer.animation_curvature_compensation); + + enterXAnimator = ValueAnimator.ofInt(0, width); + enterXAnimator.setDuration(movementAnimationDuration); + enterXAnimator.addUpdateListener(new EnterXAnimationListener()); + + exitXAnimator = ValueAnimator.ofInt(); + exitXAnimator.setDuration(movementAnimationDuration); + exitXAnimator.addUpdateListener(new EnterXAnimationListener()); + + enterYAnimator = ValueAnimator.ofInt(width, 0); + enterYAnimator.setDuration(movementAnimationDuration - curveCompensation); + enterYAnimator.addUpdateListener(new EnterYAnimationListener()); + + exitYAnimator = ValueAnimator.ofInt(); + exitYAnimator.setDuration(movementAnimationDuration); + exitYAnimator.addUpdateListener(new EnterYAnimationListener()); + + exitAlphaAnimator = ValueAnimator.ofInt(0, 255); + exitAlphaAnimator.setDuration(alphaAnimationDuration); + exitAlphaAnimator.addUpdateListener(new AlphaAnimatorUpdateListener()); + exitAlphaAnimator.addListener(new AlphaAnimatorStateListener()); + } - @Override public void update(Observable observable, Object data) { - BallFinishObservable.BallState ballState = ((BallFinishObservable) observable).getState(); - switch (ballState) { - case PRESS: - isVisible = false; - break; - } + @Override + public int getColor() { + return 0; } - } - - @Override public void onSizeChanged(int height, int width) { - super.onSizeChanged(height, width); - initValues(); - initAnimationsValues(); - iconYPosition = middle - (iconMargin); - iconXPosition = margin - iconMargin; - enterXAnimator.setIntValues(0, width); - enterYAnimator.setIntValues(enterYAnimationStart, middle); - exitYAnimator.setIntValues(middle, exitYAnimatorFinish); - exitXAnimator.setIntValues(exitXAnimationStart, 0); - } - - private void initValues() { - iconMargin = imageWidth / 2; - middle = height / 2; - } - - private void initAnimationsValues() { - exitXAnimationStart = (int) context.getResources().getDimension(R.dimen.exitXAnimationStart); - exitYAnimatorFinish = (int) context.getResources().getDimension(R.dimen.exitYAnimatorFinish); - enterYAnimationStart = (int) context.getResources().getDimension(R.dimen.enterYAnimationStart); - } - - /** - * Update the icon position in the x axis - */ - private class EnterXAnimationListener implements ValueAnimator.AnimatorUpdateListener { - - @Override public void onAnimationUpdate(ValueAnimator animation) { - iconXPosition = ((int) animation.getAnimatedValue()) - iconMargin + margin; + + @Override + public void setColor(int color) { + //Empty } - } - - /** - * Move the icon in the y axis and perform a trigger - */ - private class EnterYAnimationListener implements ValueAnimator.AnimatorUpdateListener { - - @Override public void onAnimationUpdate(ValueAnimator animation) { - iconYPosition = ((int) animation.getAnimatedValue() - iconMargin); - - if (animation.getCurrentPlayTime() > animation.getDuration() / 2 - && !alphaEnterTrigger - && actualState.equals(MaterialAnimatedSwitchState.RELEASE)) { - exitAlphaAnimator.start(); - alphaEnterTrigger = true; - } + + @Override + public void setState(MaterialAnimatedSwitchState state) { + this.actualState = state; + switch (state) { + case INIT: + isVisible = true; + break; + case PRESS: + exitYAnimator.start(); + exitXAnimator.reverse(); + exitAlphaAnimator.reverse(); + break; + case RELEASE: + isVisible = true; + enterXAnimator.reverse(); + enterYAnimator.start(); + break; + } } - } - /** - * Update the alpha - */ - private class AlphaAnimatorUpdateListener implements ValueAnimator.AnimatorUpdateListener { + private void initObserver() { + ballFinishObservable.addObserver(new BallFinishListener()); + } - @Override public void onAnimationUpdate(ValueAnimator animation) { - paint.setAlpha((Integer) animation.getAnimatedValue()); + @Override + public void onSizeChanged(int height, int width) { + super.onSizeChanged(height, width); + initValues(); + initAnimationsValues(); + iconYPosition = middle - (iconMargin); + iconXPosition = margin - iconMargin; + enterXAnimator.setIntValues(0, width); + enterYAnimator.setIntValues(enterYAnimationStart, middle); + exitYAnimator.setIntValues(middle, exitYAnimatorFinish); + exitXAnimator.setIntValues(exitXAnimationStart, 0); } - } - /** - * Set alpha trigger to false on animation end - */ - private class AlphaAnimatorStateListener implements ValueAnimator.AnimatorListener { + private void initValues() { + iconMargin = imageWidth / 2; + middle = height / 2; + } - @Override public void onAnimationStart(Animator animation) { - //Empty + private void initAnimationsValues() { + exitXAnimationStart = (int) context.getResources().getDimension(R.dimen.exitXAnimationStart); + exitYAnimatorFinish = (int) context.getResources().getDimension(R.dimen.exitYAnimatorFinish); + enterYAnimationStart = (int) context.getResources().getDimension(R.dimen.enterYAnimationStart); } - @Override public void onAnimationEnd(Animator animation) { - alphaEnterTrigger = false; + private class BallFinishListener implements Observer { + + @Override + public void update(Observable observable, Object data) { + BallFinishObservable.BallState ballState = ((BallFinishObservable) observable).getState(); + switch (ballState) { + case PRESS: + isVisible = false; + break; + } + } } - @Override public void onAnimationCancel(Animator animation) { - //Empty + /** + * Update the icon position in the x axis + */ + private class EnterXAnimationListener implements ValueAnimator.AnimatorUpdateListener { + + @Override + public void onAnimationUpdate(ValueAnimator animation) { + iconXPosition = ((int) animation.getAnimatedValue()) - iconMargin + margin; + } + } + + /** + * Move the icon in the y axis and perform a trigger + */ + private class EnterYAnimationListener implements ValueAnimator.AnimatorUpdateListener { + + @Override + public void onAnimationUpdate(ValueAnimator animation) { + iconYPosition = ((int) animation.getAnimatedValue() - iconMargin); + + if (animation.getCurrentPlayTime() > animation.getDuration() / 2 + && !alphaEnterTrigger + && actualState.equals(MaterialAnimatedSwitchState.RELEASE)) { + exitAlphaAnimator.start(); + alphaEnterTrigger = true; + } + } + } + + /** + * Update the alpha + */ + private class AlphaAnimatorUpdateListener implements ValueAnimator.AnimatorUpdateListener { + + @Override + public void onAnimationUpdate(ValueAnimator animation) { + paint.setAlpha((Integer) animation.getAnimatedValue()); + } } - @Override public void onAnimationRepeat(Animator animation) { - //Empty + /** + * Set alpha trigger to false on animation end + */ + private class AlphaAnimatorStateListener implements ValueAnimator.AnimatorListener { + + @Override + public void onAnimationStart(Animator animation) { + //Empty + } + + @Override + public void onAnimationEnd(Animator animation) { + alphaEnterTrigger = false; + } + + @Override + public void onAnimationCancel(Animator animation) { + //Empty + } + + @Override + public void onAnimationRepeat(Animator animation) { + //Empty + } } - } } diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/Painter.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/Painter.java index a93b3fc..4c13d45 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/Painter.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/Painter.java @@ -11,13 +11,13 @@ public interface Painter { - void draw(Canvas canvas); + void draw(Canvas canvas); - void setColor(int color); + int getColor(); - int getColor(); + void setColor(int color); - void onSizeChanged(int height, int width); + void onSizeChanged(int height, int width); - void setState(T state); + void setState(T state); } diff --git a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/ShaderPainter.java b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/ShaderPainter.java index ac579ee..0e17edb 100644 --- a/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/ShaderPainter.java +++ b/materialanimatedswitch/src/main/java/com/github/glomadrian/materialanimatedswitch/painter/ShaderPainter.java @@ -6,6 +6,7 @@ import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; + import com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitchState; /** @@ -13,47 +14,52 @@ */ public class ShaderPainter implements SwitchInboxPinnedPainter { - private Paint maskPaint; - private int height; - private int width; - private Bitmap mask; - - public ShaderPainter() { - maskPaint = new Paint(); - maskPaint.setColor(Color.TRANSPARENT); - maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); - maskPaint.setStyle(Paint.Style.FILL); - } - - @Override public void draw(Canvas canvas) { - canvas.drawLine(0, height / 2, width, height / 2, maskPaint); - } - - @Override public void setColor(int color) { - //Empty - } - - @Override public int getColor() { - return 0; - } - - @Override public void onSizeChanged(int height, int width) { - this.height = height; - this.width = width; - createMask(height, width, 10); - } - - @Override public void setState(MaterialAnimatedSwitchState state) { - //Empty - } - - private void createMask(int w, int h, int radius) { - if (mask != null) { - mask.recycle(); + private Paint maskPaint; + private int height; + private int width; + private Bitmap mask; + + public ShaderPainter() { + maskPaint = new Paint(); + maskPaint.setColor(Color.TRANSPARENT); + maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); + maskPaint.setStyle(Paint.Style.FILL); + } + + @Override + public void draw(Canvas canvas) { + canvas.drawLine(0, height / 2, width, height / 2, maskPaint); + } + + @Override + public int getColor() { + return 0; + } + + @Override + public void setColor(int color) { + //Empty + } + + @Override + public void onSizeChanged(int height, int width) { + this.height = height; + this.width = width; + createMask(height, width, 10); } - mask = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); - Canvas maskCanvas = new Canvas(mask); - maskCanvas.drawCircle(w, h, radius, maskPaint); - } + @Override + public void setState(MaterialAnimatedSwitchState state) { + //Empty + } + + private void createMask(int w, int h, int radius) { + if (mask != null) { + mask.recycle(); + } + + mask = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); + Canvas maskCanvas = new Canvas(mask); + maskCanvas.drawCircle(w, h, radius, maskPaint); + } } diff --git a/materialanimatedswitch/src/main/res/values/attrs.xml b/materialanimatedswitch/src/main/res/values/attrs.xml index e6aaa00..26a9b85 100644 --- a/materialanimatedswitch/src/main/res/values/attrs.xml +++ b/materialanimatedswitch/src/main/res/values/attrs.xml @@ -1,17 +1,11 @@ - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/materialanimatedswitch/src/main/res/values/dimen.xml b/materialanimatedswitch/src/main/res/values/dimen.xml index e85f170..eea362a 100644 --- a/materialanimatedswitch/src/main/res/values/dimen.xml +++ b/materialanimatedswitch/src/main/res/values/dimen.xml @@ -1,12 +1,12 @@ - -15dp - 34dp - -30dp - -25dp - 25dp - 11dp - 14dp - 11dp - 12dp + -15dp + 34dp + -30dp + -25dp + 25dp + 11dp + 14dp + 11dp + 12dp \ No newline at end of file diff --git a/materialanimatedswitch/src/main/res/values/integers.xml b/materialanimatedswitch/src/main/res/values/integers.xml index e11fb9c..f3014f9 100644 --- a/materialanimatedswitch/src/main/res/values/integers.xml +++ b/materialanimatedswitch/src/main/res/values/integers.xml @@ -1,7 +1,7 @@ - 400 - 200 - 14 - 200 + 400 + 200 + 14 + 200 \ No newline at end of file diff --git a/materialanimatedswitch/src/main/res/values/strings.xml b/materialanimatedswitch/src/main/res/values/strings.xml index 1de4d56..fb68af3 100644 --- a/materialanimatedswitch/src/main/res/values/strings.xml +++ b/materialanimatedswitch/src/main/res/values/strings.xml @@ -1,3 +1,3 @@ - MaterialAnimatedSwitch + MaterialAnimatedSwitch