CountDownView countdown control source code analysis, countdownview Control
Project Implementation Effect
Gradle
Compile 'com. github. iwgang: countdownview: 2.1.6'
Custom Attributes
Whether isHideTimeBackground hides the time background. The default value is true.
TimeBgColor: the default time background color is #444444.
TimeBgSize: Default Value: timeSize + 2dp * 4
TimeBgRadius time background rounded corner size defaults to 0
IsShowTimeBgDivisionLine defaults to true
TimeBgDivisionLineColor: #30 FFFFFF by default
TimeBgDivisionLineSize: 0.5dp by default
TimeTextSize: the default text size is 12sp.
The default color of timeTextColor is #000000.
Whether the isTimeTextBold time text is bold or not. The default value is false.
Whether isShowDay is displayed as a day
Whether isShowHour is displayed as an hour
IsShowMinute: whether to display the score. The default value is true.
Whether isShowSecond is displayed. The default value is true.
IsShowMillisecond: millisecond display; default value: false
IsConvertDaysToHours: whether to convert the number of days to the number of hours. The default value is false.
SuffixTextSize delimiter text size 12sp by default
The default text color of suffixTextColor separator is #000000.
Whether the text of the isSuffixTextBold separator is in bold is false by default.
SuffixGravity separator location 'top' or 'center' or 'bottom'
The default suffix Delimiter is:
The default value of suffixDay is null.
The default value of suffixHour delimiter day is null.
The default value of suffixMinute delimiter day is null.
The default value of suffixSecond delimiter day is null.
SuffixMillisecond delimiter day default is null
The default value of the suffixLRMargin delimiter between the left and right margin is 3dp.
The default value of suffixDayLeftMargin between the day of the delimiter and the left-side margin is 0dp.
The default value of suffixDayRightMargin between the day of the delimiter and the margin on the right is 0dp.
The default value of suffixHourLeftMargin, which is an hour away from the left-side margin, is 0dp.
The suffixHourRightMargin Delimiter is between the hour and the margin on the right. The default value is 0dp.
The default value of the suffixMinuteLeftMargin delimiter to the left is 0dp.
The default value of the suffixMinuteRightMargin separator to the right is 0dp.
SuffixSecondLeftMargin: the default interval between the second and the left margin is 0dp.
The default value of suffixSecondRightMargin between the second separator and the right margin is 0dp.
The suffixMillisecondLeftMargin Delimiter is separated by milliseconds from the left-side margin. The default value is 0dp.
IsShowTimeBgBorder: whether to display the time background border; default value: false
TimeBgBorderColor: the default color of the time background border is #000000.
TimeBgBorderSize the default value of the time background border is 1dp.
TimeBgBorderRadius time background border angle: 0dp by default
Important Interfaces
1. Interface callback for CountDownView countdown completion
SetOnCountdownEndListener (OnCountdownEndListener onCountdownEndListener );
2. Interface callback for CountDownView countdown at intervals
SetOnCountdownIntervalListener (long interval, OnCountdownIntervalListener onCountdownIntervalListener );
Simple effect implementation
Sample Code
// Layout File Code
// Test the Activity code public class MainActivity extends AppCompatActivity {private CountdownView countdownView; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); countdownView = findViewById (R. id. countdownView); countdownView. start (1000*60*60*5); // countdown one hour countdownView. setOnCountdownEndListener (new CountdownView. onCountdownEndListener () {@ Override public void onEnd (CountdownView cv) {Log. e ("CountdownView", "Countdown to completion ");}});}}
To achieve special effects, you can modify the custom attributes of the CountdownView control as required by the project.