Giter Site home page Giter Site logo

countdownview-1's Introduction

CountDownView

What is it? It's a custom View that displays a simple countdown. It looks like this:

CountDownView

CountDownView is backed by CountDownTimer so that you don't have to worry about lifting any boxes...

It also uses Android-RobotoTextView for API levels below 11 to keep consistency.

Interested? Here's how to use it

First, specify the following in your AndroidManifest.xml. This library uses a Service to handle the CountDownTimer.

<service android:name="com.alexfu.countdownview.core.TimerService"/>

Sample layout...

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.alexfu.countdownview.widget.CountDownView
        android:id="@+id/countdownview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</FrameLayout>

By default, the above wont show you anything. Choose to display hours or minutes or seconds or milliseconds, or all 4.

Show only hours:

<com.alexfu.countdownview.widget.CountDownView
    android:id="@+id/countdownview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    custom:showHour="true"/>

Show hours and minutes:

<com.alexfu.countdownview.widget.CountDownView
    android:id="@+id/countdownview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    custom:showHour="true"
    custom:showMin="true"/>

You can also set text colors for digits and units:

<com.alexfu.countdownview.widget.CountDownView
    android:id="@+id/countdownview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    custom:showHour="true"
    custom:showMin="true"
    custom:numberColor="@color/black"
    custom:unitColor="@color/grey"/>

In code:

CountDownView cdv = (CountDownView) findViewById(R.id.countdownview);
cdv.setInitialTime(30000); // Initial time of 30 seconds.
cdv.start();
cdv.stop();
cdv.reset();

To get notified when timer reaches zero implement TimerListener in your activity and override timerElapsed

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ......
        .....
        cdv.setListener(this);
    }

@Override
    public void timerElapsed() {
        //Do something here
    }

TODO

  • Implement an event listener when timer is done/reaches zero.
  • Add support for different text sizes.
  • Add more TODO items.

countdownview-1's People

Contributors

alexfu avatar

Stargazers

Kanthon avatar Haseeb avatar Halim Bimantara avatar Mohamed avatar

Watchers

James Cloos avatar Lerist avatar  avatar

Forkers

halimbimantara

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.