A MaterialSwitch that proactively tries to turn itself off using a cat's paw animation.
demo.mp4
Add the CatPawSwitch to your layout:
<com.hearsilent.catpawswitch.views.CatPawSwitch
android:id="@+id/catPawSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false" />In your Activity or Fragment (using View Binding):
binding.catPawSwitch.apply {
onPushToggle = {
// Reset the switch state when the paw pushes it
isChecked = false
}
onAnimationEnd = {
// Optional: Perform action after the animation finishes
}
setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
// Trigger the animation after a short delay
postDelayed({
startPawAnimation()
}, 500L)
}
}
}- Add the JitPack repository to your
settings.gradle.kts:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}- Add the dependency to your
app/build.gradle.kts:
dependencies {
implementation("com.github.hearsilent:CatPawSwitch:latest-version")
}- Android SDK 24 (Android 7.0)
This project was inspired by the Proactive Toggle by Cod Lin.
This project is licensed under the MIT License - see the LICENSE file for details.