Android Countdown View

Last update: Jun 19, 2022

Android Gems Android Arsenal @iwgang

中文

CountdownView

Android countdown view,use canvas draw,supports multiple styles

Download demo apk

Screenshot

Gradle

compile 'com.github.iwgang:countdownview:2.1.6'

Code

CountdownView mCvCountdownView = (CountdownView)findViewById(R.id.cv_countdownViewTest1);
mCvCountdownView.start(995550000); // Millisecond

// or
for (int time=0; time<1000; time++) {
    mCvCountdownView.updateShow(time);
}

Layout

<cn.iwgang.countdownview.CountdownView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:isHideTimeBackground="true"
    app:isShowDay="true"
    app:isShowHour="true"
    app:isShowMinute="true"
    app:isShowSecond="true"
    app:isShowMillisecond="true"
    app:timeTextColor="#000000"
    app:timeTextSize="22sp"
    app:isTimeTextBold="true"
    app:suffixGravity="bottom"
    app:suffixTextColor="#000000"
    app:suffixTextSize="12sp"
    app:suffixHour=""
    app:suffixMinute=""
    app:suffixSecond=""
    app:suffixMillisecond="毫秒" />

Customization

attr type default
isHideTimeBackground boolean true
timeBgColor color #444444
timeBgSize dimension timeSize + 2dp * 4
timeBgRadius dimension 0
isShowTimeBgDivisionLine boolean true
timeBgDivisionLineColor color #30FFFFFF
timeBgDivisionLineSize dimension 0.5dp
timeTextSize dimension 12sp
timeTextColor color #000000
isTimeTextBold boolean false
isShowDay boolean auto show (has value show if not hide)
isShowHour boolean auto show (has value show if not hide)
isShowMinute boolean true
isShowSecond boolean true
isShowMillisecond boolean false
isConvertDaysToHours boolean false
suffixTextSize dimension 12sp
suffixTextColor color #000000
isSuffixTextBold boolean false
suffixGravity 'top' or 'center' or 'bottom' 'center'
suffix string ':'
suffixDay string null
suffixHour string null
suffixMinute string null
suffixSecond string null
suffixMillisecond string null
suffixLRMargin dimension left 3dp right 3dp
suffixDayLeftMargin dimension 0
suffixDayRightMargin dimension 0
suffixHourLeftMargin dimension 0
suffixHourRightMargin dimension 0
suffixMinuteLeftMargin dimension 0
suffixMinuteRightMargin dimension 0
suffixSecondLeftMargin dimension 0
suffixSecondRightMargin dimension 0
suffixMillisecondLeftMargin dimension 0
isShowTimeBgBorder boolean false
timeBgBorderColor color #000000
timeBgBorderSize dimension 1dp
timeBgBorderRadius dimension 0

Other

  • Multiple countdownView specified value
    // step 1
    mCvCountdownView.setTag(R.id.name, uid);
    // step 2
    @Override
    public void onEnd(CountdownView cv) {
        Object nameTag = cv.getTag(R.id.uid);
        if (null != nameTag) {
            Log.i(TAG, "name = " + nameTag.toString());
        }
    }
  • Dynamic show
    dynamicShow(DynamicConfig dynamicConfig)
  • Countdown complete callback
    setOnCountdownEndListener(OnCountdownEndListener onCountdownEndListener);
  • Interval callback
    setOnCountdownIntervalListener(long interval, OnCountdownIntervalListener onCountdownIntervalListener);

GitHub

https://github.com/iwgang/CountdownView
Comments
  • 1. 有点问题需要请教

    您好作者,在RecyclerView中使用倒计时的时候,上下滑动 倒计时会暂停 ,多滑动几次就,变成0了,下拉刷新 时间又重置了,怎么解决这个问题啊 ,我Adapter继承的是BaseQuickAdapter com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.15这个里面的BaseAdapter

    Reviewed by ljackChen001 at 2017-05-25 06:00
  • 2. About Handler

    Since this Handler is declared as an inner class, it may prevent the outer class from being garbage collected. If the Handler is using a Looper or MessageQueue for a thread other than the main thread, then there is no issue. If the Handler is using the Looper or MessageQueue of the main thread, you need to fix your Handler declaration, as follows: Declare the Handler as a static class; In the outer class, instantiate a WeakReference to the outer class and pass this object to your Handler when you instantiate the Handler; Make all references to members of the outer class using the WeakReference object.

    Reviewed by NicodeLee at 2016-01-05 09:09
  • 3. countUp on orientation change

    hi thank before to awesome libraries i want to make app to count down but i will to count up when phone orientation change . like hourglass timed. can i do it with countdownVIew ? i not find that in documentation thanks for help

    Reviewed by yudikarma at 2019-01-03 08:19
  • 4. How to use Interval

    Hi, thanks for your great library. I want show some time in my application and i want when lasted 5s show me toast. For example : I want how 17s countTimer, when this timer receive to 5s show me toast "just 5s".

    how can i it? please help me

    Reviewed by bahramnooraii at 2017-06-06 04:27
  • 5. 为什么天数转成小时要依赖于实现隐藏控件背景?

    class CountdownView extends View {
    
        public CountdownView(Context context, AttributeSet attrs, int defStyleAttr) {
    	super(context, attrs, defStyleAttr);
    	TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CountdownView);
    	isHideTimeBackground = ta.getBoolean(R.styleable.CountdownView_isHideTimeBackground, true);
    	mCountdown = isHideTimeBackground ? new BaseCountdown() : new BackgroundCountdown();
    	// 初始化属性
    	mCountdown.initStyleAttr(context,ta);
    	ta.recycle();
    	mCountdown.initialize();
        }
    }
    
    class BaseCountdown {
    
        public void initStyleAttr(Context context, TypedArray ta) {
    	...省略若干代码...
    	// 为什么天数转成小时要依赖于实现隐藏控件背景?
    	if (ta.getBoolean(R.styleable.CountdownView_isHideTimeBackground, true)) {
    		isConvertDaysToHours = ta.getBoolean(R.styleable.CountdownView_isConvertDaysToHours, false);
    	}
        }
    }
    
    Reviewed by Love667767 at 2017-07-06 04:40
  • 6. DynamicConfig

    DynamicConfig constructor is a private access , so I can't get a instance , I want to config DynamicShow , due to countDownView.dynamicShow() method need a DynamicConfig type parameter,can you update DynamicConfig constructor permission modifier is public ?

    Reviewed by xinpengfei520 at 2017-03-21 08:39
  • 7. isShowTimeBgBorder无效,边框没显示

                    <cn.iwgang.countdownview.CountdownView
                        android:id="@+id/countDown"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="4dp"
                        app:isShowDay="true"
                        app:isShowHour="true"
                        app:isShowMinute="true"
                        app:isShowSecond="true"
                        app:isShowTimeBgBorder="true"
                        app:suffixDay="天"
                        app:suffixGravity="bottom"
                        app:suffixHour="时"
                        app:suffixMinute="分"
                        app:suffixSecond="秒"
                        app:suffixTextColor="#ff383838"
                        app:suffixTextSize="10sp"
                        app:timeBgBorderColor="#ff383838"
                        app:timeBgBorderRadius="2dp"
                        app:timeBgBorderSize="2dp"
                        app:timeTextColor="#ff383838"
                        app:timeTextSize="12sp" />
    

    版本 'com.github.iwgang:countdownview:2.1.6'

    Reviewed by DanteAndroid at 2021-05-28 09:46
  • 8. 为什么设置了isShowDay="true",天数小于0的时候,不隐藏"00天"呢?

    <cn.iwgang.countdownview.CountdownView android:id="@+id/cv_countdownViewTest1" android:layout_width="wrap_content" android:layout_height="wrap_content" app:isHideTimeBackground="true" app:isShowDay="true" app:isShowHour="true" app:isShowMinute="true" app:isShowSecond="true" app:isTimeTextBold="true" app:suffixGravity="bottom" app:suffixDay="天" app:suffixHour="时" app:suffixMinute="分" app:suffixSecond="秒" app:suffixTextColor="#000000" app:suffixTextSize="12sp" app:timeTextColor="#000000" app:timeTextSize="22sp" />

    Reviewed by roybill at 2021-01-28 06:57
FloatingView can make the target view floating above the anchor view with cool animation
FloatingView can make the target view floating above the anchor view with cool animation

FloatingView FloatingView can make the target view floating above the anchor view with cool animation Links 中文版 README Blog about FloatingView demo.ap

Jun 18, 2022
用于做Path动画的自定义View。 I have a path.I have a view. (Oh~),Path(Anim)View.
用于做Path动画的自定义View。 I have a path.I have a view. (Oh~),Path(Anim)View.

PathAnimView 用于做Path动画的自定义View。 I have a path.I have a view. (Oh~),Path(Anim)View. 现已经找到图片->SVG->PATH的正确姿势, Now i have a pic.I have a view. Oh~,Path(A

Jun 15, 2022
TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View

TourGuide TourGuide is an Android library. It lets you add pointer, overlay and tooltip easily, guiding users on how to use your app. Refer to the exa

Jun 15, 2022
View that imitates Ripple Effect on click which was introduced in Android L (for Android 2.3+)
View that imitates Ripple Effect on click which was introduced in Android L  (for Android 2.3+)

RippleView View that imitates Ripple Effect on click which was introduced in Android L. Usage For a working implementation, Have a look at the Sample

May 8, 2022
Snake View is a simple and animated linear chart for Android.
Snake View is a simple and animated linear chart for Android.

Snake View Snake library is a simple and animation line chart for Android. Latest Version How to use Configuring your project dependencies Add the lib

May 7, 2022
[] A simple way to "badge" any given Android view at runtime without having to cater for it in layout
[] A simple way to

Android ViewBadger A simple way to "badge" any given Android view at runtime without having to cater for it in layout. Note: If your aim is to replica

Jun 8, 2022
Android view with both path from constructed path or from svg.
Android view with both path from constructed path or from svg.

android-pathview You want to animate svg or normal Paths?<br> Change the color, pathWidth or add svg.<br> Animate the "procentage" property to make th

Jun 18, 2022
A horizontal view scroller library for Android
A horizontal view scroller library for Android

View Flow for Android ViewFlow is an Android UI widget providing a horizontally scrollable ViewGroup with items populated from an Adapter. Scroll down

Jun 15, 2022
TileView is a subclass of android.view.ViewGroup that asynchronously displays, pans and zooms tile-based images. Plugins are available for features like markers, hotspots, and path drawing.
TileView is a subclass of android.view.ViewGroup that asynchronously displays, pans and zooms tile-based images.  Plugins are available for features like markers, hotspots, and path drawing.

This project isn't maintained anymore. It is now recommended to use https://github.com/peterLaurence/MapView. MapView is maintained by Peter, one of o

Jun 7, 2022
A cool Open Source CoverFlow view for Android with several fancy effects.
A cool Open Source CoverFlow view for Android with several fancy effects.

FancyCoverFlow THIS PROJECT IS NO LONGER MAINTAINED! What is FancyCoverFlow? FancyCoverFlow is a flexible Android widget providing out of the box view

Apr 29, 2022
A simple, customizable and easy to use swipeable view stack for Android.
A simple, customizable and easy to use swipeable view stack for Android.

SwipeStack A simple, customizable and easy to use swipeable view stack for Android. QuickStart Include the Gradle dependency dependencies { compil

May 27, 2022
Custom android music player view.
Custom android music player view.

InteractivePlayerView Custom android music player view. Screen Check it on youtube Usage(XML) Define it in your xml file. <co.mobiwise.library.Intera

Apr 5, 2022
Shadow layout, shadow view for android.
Shadow layout, shadow view for android.

ShadowViewHelper Shadow layout, shadow view for android. How to use: It's very simple to use. Gradle(Check newest version): compile 'com.github.wangji

May 9, 2022
Android Quilt View Library
Android Quilt View Library

QuiltViewLibrary QuiltView displays views of different sizes in a scrollable grid. Dependencies This library depends on gridlayout_v7 ([email protected]:

May 17, 2022
A velocimeter View for Android
A velocimeter View for Android

Velocimeter A velocimeter View for Android Sample video: Youtube Velocimeter video Sample app: How to use Default colors <com.github.glomadrian.veloci

May 26, 2022
Android-ScrollBarPanel allows to attach a View to a scroll indicator like it's done in Path 2.0
Android-ScrollBarPanel allows to attach a View to a scroll indicator like it's done in Path 2.0

Path 2.0 like ScrollBarPanel for Android Android-ScrollBarPanel allows to attach a View to a scroll indicator like it's done in Path 2.0. Features Sup

Jun 14, 2022
Android library to create chat message view easily
Android library to create chat message view easily

ChatMessageView ChatMessageView helps you to create chat message view quickly like a typical chatting application. Its a container view, so you can ad

Mar 22, 2022
A drawing view for your android application.
 A drawing view for your android application.

Android Draw A drawing view for your android application Download For information : checkout Sample App Code in repository. Dependency Step 1. Add the

Jun 9, 2022
Customizable Item Setting View Android
Customizable Item Setting View Android

ItemSettingView Simple ItemSettingView and Custom Installation Add it in your root build.gradle at the end of repositories: allprojects { reposito

Jan 22, 2021