Code Monkey home page Code Monkey logo

android-widget-ticktock's Introduction

Build Status Download Android Arsenal

TickTock Widget

This is a circular widget that can be used to display a count down timer or a count up timer.

TickTock Widget

How to include

compile 'com.bcgdv.asia.lib:ticktock:1.3'

Usage

    <com.bcgdv.asia.lib.ticktock.TickTockView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_marginTop="16dp"
        android:layout_gravity="center_horizontal"
		app:tickAutoFitText="true"
        app:tickMiddleColor="#333333"
        app:tickMoveCounterClockwise="true"
        app:tickTextColor="#CCCCCC"
        app:tickDotRadius="6dp"
        app:tickEmptyRingColor="@android:color/white"
        app:tickFillRingColor="@color/colorPrimary"
        app:tickRingThickness="3dp" />
  • tickCircleDuration - minute|total_time the circle completes a full circle every minute or the total time different between startTime and endTime. Default minute.
  • tickAutoFitText - boolean default true. The text will be automatically resized to fit in the available space.
  • tickText - Optional String static text to display in the middle.
  • tickTextColor - Optional color
  • tickTextSize - Optional dimension text size if tickAutoFitText is not used.
  • tickMiddleColor - Optional color the color of the center of the color. Color transparent by default.
  • tickFillRingColor - Optional color the color of the ring when filled. Color white by default.
  • tickEmptyRingColor - Optional color the color of the ring when empty. Color blue by default.
  • tickRingThickness - Optional dimension the tickness of the ring in DIP. 3dp by default.
  • tickDotRadius - Optional dimension the radious in DIP of the dot. 6dp by default.
  • tickMoveCounterClockwise Optional boolean false by default.
public void onCreate(Bundle savedInstanceState) {
...
    mCountDown = (TickTockView) findViewById(R.id.view_ticktock_countdown);
    mCountUp = (TickTockView) findViewById(R.id.view_ticktock_countup);
    if (mCountDown != null) {
        mCountDown.setOnTickListener(new TickTockView.OnTickListener() {
            @Override
            public String getText(long timeRemaining) {
                int seconds = (int) (timeRemaining / 1000) % 60;
                int minutes = (int) ((timeRemaining / (1000 * 60)) % 60);
                int hours = (int) ((timeRemaining / (1000 * 60 * 60)) % 24);
                int days = (int) (timeRemaining / (1000 * 60 * 60 * 24));
                boolean hasDays = days > 0;
                return String.format("%1$02d%4$s %2$02d%5$s %3$02d%6$s",
                        hasDays ? days : hours,
                        hasDays ? hours : minutes,
                        hasDays ? minutes : seconds,
                        hasDays ? "d" : "h",
                        hasDays ? "h" : "m",
                        hasDays ? "m" : "s");
            }
        });
    }

    if (mCountUp != null) {
        mCountUp.setOnTickListener(new TickTockView.OnTickListener() {
            SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss");
            Date date = new Date();
            @Override
            public String getText(long timeRemaining) {
                date.setTime(System.currentTimeMillis());
                return format.format(date);
            }
        });
    }
...
}

@Override
protected void onStart() {
    super.onStart();
    Calendar end = Calendar.getInstance();
    end.add(Calendar.MINUTE, 4);
    end.add(Calendar.SECOND, 5);

    Calendar start = Calendar.getInstance();
    start.add(Calendar.MINUTE, -1);
    if (mCountDown != null) {
        mCountDown.start(start, end);
    }

    Calendar c2= Calendar.getInstance();
    c2.add(Calendar.HOUR, 2);
    c2.set(Calendar.MINUTE, 0);
    c2.set(Calendar.SECOND, 0);
    c2.set(Calendar.MILLISECOND, 0);
    if (mCountUp != null) {
        mCountUp.start(c2);
    }
}

@Override
protected void onStop() {
    super.onStop();
    mCountDown.stop();
    mCountUp.stop();
}

Known Issues

  • Please report any through GitHub issue tracker.

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

android-widget-ticktock's People

Contributors

alphamu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-widget-ticktock's Issues

change default text to text view ?

hi, thanks for this great library,

  1. i want to ask , how can i get the text from onTickListener and set that text to regular textview ?
  2. change font style of the default text ?
  3. request : add timer picker too, like circle seekbar , that would be very helpful

Thanks :)

Text not centred in Android M

When using TickTockView in Android M the Text is not centred correctly...

Android 4.4.2 KitKat
screen shot 2016-05-29 at 10 41 36

Android 6.0 Marshmallow
screen shot 2016-05-29 at 10 40 29

the time text goes out of circle

every time when start the project the text of timer goes out of circle on the right side and on again start it come back on it right position.

Add SeekTo method on your class

this is very useful
public void seekTo(long millisUntilFinished){ if (mTimer != null) { mTimer.onTick(millisUntilFinished); } }

how to start from count up from 00:00:00 time ?

I have tried to change code be like this :
` Calendar c2= Calendar.getInstance();

    c2.add(Calendar.HOUR, 0);
    c2.set(Calendar.MINUTE, 0);
    c2.set(Calendar.SECOND, 0);
    c2.set(Calendar.MILLISECOND, 0);
    if (view_ticktock_countup != null) {
        view_ticktock_countup.start(c2);
    }`

but got error

endTime cannot be null and must be in the future at com.bcgdv.asia.lib.ticktock.TickTockView.start

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.