Skip to content

hearsilent/CatPawSwitch

CatPawSwitch

JitPack license

A MaterialSwitch that proactively tries to turn itself off using a cat's paw animation.

Screenshot

demo.mp4

Usage

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)
        }
    }
}

Dependency

  1. 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") }
    }
}
  1. Add the dependency to your app/build.gradle.kts:
dependencies {
    implementation("com.github.hearsilent:CatPawSwitch:latest-version")
}

Minimum SDK

  • Android SDK 24 (Android 7.0)

Inspiration

This project was inspired by the Proactive Toggle by Cod Lin.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A MaterialSwitch that proactively tries to turn itself off using a cat's paw animation.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Contributors

Languages