CoolSwitch Android Library

repository·master·Indexed 19 days ago

https://github.com/serchinastico/coolswitch

An Android library providing a custom view with a reveal animation to switch between two different UI states. Version 1.0.1 requires wrapping the disabledView and enabledView within a TargetFrameLayout or TargetLinearLayout to enable the animation.

Tokens
823
Snippets
2
Records
2
Agent score
16%

What's inside CoolSwitch

  1. Implement CoolSwitch in your Android layout

    master

    CoolSwitch provides a custom view with a reveal animation for switching between two states. To implement it, follow these two steps:

    1. Include the CoolSwitch view

    Add the com.serchinastico.coolswitch.CoolSwitch view to your layout. You must specify which views will be displayed for each state using the following custom attributes:

    • coolswitch:disabledView: The ID of the view to show when the switch is in the disabled state.
    • coolswitch:enabledView: The ID of the view to show when the switch is in the enabled state.

    Important: If either view is undefined, the animation will not play.

    2. Wrap animated views in a Target container

    To enable the animation, you must wrap the views being switched (the disabledView and enabledView) inside either a TargetFrameLayout or a TargetLinearLayout.

    <!-- 1. The Switch View -->
    <com.serchinastico.coolswitch.CoolSwitch
    	android:id="@+id/cool_switch_foo"
    	android:layout_height="35dp"
    	android:layout_width="60dp"
    	coolswitch:disabledView="@id/disabled_view_foo"
    	coolswitch:enabledView="@id/enabled_view_foo"/>
    
    <!-- 2. The Container and the Views to be animated -->
    <com.serchinastico.coolswitch.TargetFrameLayout
    		android:layout_width="match_parent"
    		android:layout_height="match_parent">
    
    	<LinearLayout
    			android:id="@+id/disabled_view_foo"
    			android:layout_width="match_parent"
    			android:layout_height="match_parent"
    			android:background="#FF0000"/>
    
    	<LinearLayout
    			android:id="@+id/enabled_view_foo"
    			android:layout_width="match_parent"
    			android:layout_height="match_parent"
    			android:background="#00FF00"/>
    
    </com.serchinastico.coolswitch.TargetFrameLayout>
  2. Add CoolSwitch dependency to your project

    master

    To use CoolSwitch, add the dependency to your build system. The library is available via Maven Central, JCenter, or your local artifact repository.

    Maven

    Add the following to your pom.xml:

    Gradle

    Add the following to your dependencies block:

    Note: The current version is 1.0.1.

    <dependency>
    	groupId>com.github.serchinastico</groupId>
    	artifactId>coolswitch</artifactId>
    	version>1.0.1</version>
    	type>aar</type>
    </dependency>
    dependencies {
    	compile 'com.github.serchinastico:coolswitch:1.0.1'
    }