Skip to content

Timer button is a countdown enabled button which can be used to disable user interactions while showing a timer on top of it.

Notifications You must be signed in to change notification settings

dhruvtaneja/timer-button

Repository files navigation

Timer Button

Android Arsenal

Timer button is a countdown enabled button which can be used to disable user interactions while showing a timer on top of it.

Gradle

To include this library in your gradle project

dependencies {
	// ... other dependencies here
    implementation 'com.dt:timerbutton:0.1'
}

Maven

To include this library in your maven project

<dependency>
  <groupId>com.dt</groupId>
  <artifactId>timerbutton</artifactId>
  <version>0.1</version>
  <type>pom</type>
</dependency>

Usage

Put this button in your layout file like this

<com.dhruv.timerbutton.TimerButton
        android:id="@+id/timer_button"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        app:animationBackground="@color/colorAccentTrans"
        app:animationCompleteText="@string/resend_otp"
        app:buttonBackground="@drawable/selector_button"
        app:defaultText="@string/send_otp"
        app:dynamicString="@string/resend_otp_formatted"
        app:textColor="@color/colorPrimaryDark"/>

The various attributes that are available are

<declare-styleable name="TimerButton">
        <!--text to be displayed after animation is complete-->
        <attr name="animationCompleteText" format="string|reference"/>
        <!--text to be displayed in pre-animation state-->
        <attr name="defaultText" format="string|reference"/>
        <!--text to be displayed during animation-->
        <attr name="dynamicString" format="reference"/>
        <!--the overlay that animates over the button. Can be a drawable, a gradient, etc-->
        <attr name="animationBackground" format="reference"/>
        <!--the background of the button-->
        <attr name="buttonBackground" format="reference"/>
        <!--color of the text-->
        <attr name="textColor" format="reference|color"/>
        <!--size of the text-->
        <attr name="textSize" format="reference|dimension"/>
    </declare-styleable>

Now in your java code, start, stop or reset the animation with something like this

TimerButton timerButton = findViewById(R.id.timer_button);
timerButton.setDuration(6000L);

//  Start the animation
timerButton.start();

//  Stop the animation
timerButton.stop();

//  Reset the animation
timerButton.reset();

Issues and pull requests are most welcome

About

Timer button is a countdown enabled button which can be used to disable user interactions while showing a timer on top of it.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages