Skip to content

Commit 9b4b2db

Browse files
author
Tsur Yohananov
committed
setDate(Date date)
2 parents 258076e + 0dd8534 commit 9b4b2db

4 files changed

Lines changed: 78 additions & 4 deletions

File tree

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,63 @@
1+
[![Release](https://jitpack.io/v/tsuryo/NumberPicker.svg)](https://jitpack.io/#tsuryo/Android-Countdown-Timer)
12
# Android-Countdown-Timer
3+
Android library provide a simple to use Countdown Timer View.
24

5+
<img width="175" alt="Android Countdown timer" src="https://user-images.githubusercontent.com/42518244/61465838-8b08dd00-a981-11e9-9663-a1f0f21724b4.png">
36

7+
### Prerequisites
8+
Android 5.0+ API 21+
9+
# Features
10+
11+
* Customizable fonts (color, size, fonts resources).
12+
* Choose maximum time unit to show.
13+
* Built in fonts to choose,
14+
app:counter_font="DIGITAL|DIGITAL_BOLD|DIGITAL_ITALIC|DIGITAL_ITALIC_BOLD|REGULAR"
15+
16+
# Usage
17+
// Java
18+
```
19+
mCounter = findViewById(R.id.counter);
20+
mCounter.setDate("2019-07-19T18:33:00"); //countdown starts
21+
/*
22+
* Additional attributes:
23+
* */
24+
mCounter.setIsShowingTextDesc(true);
25+
mCounter.setTextColor(R.color.colorPrimary);
26+
mCounter.setMaxTimeUnit(TimeUnits.DAY);
27+
mCounter.setTextSize(30);
28+
mCounter.setTypeFace(ResourcesCompat.getFont(this, R.font.batmfa__));
29+
```
30+
//XML
31+
```
32+
<com.tsuryo.androidcountdown.Counter
33+
android:id="@+id/counter"
34+
android:layout_width="wrap_content"
35+
android:layout_height="wrap_content"
36+
android:layout_marginBottom="8dp"
37+
app:layout_constraintBottom_toTopOf="@+id/gdH50"
38+
app:layout_constraintLeft_toLeftOf="parent"
39+
app:layout_constraintRight_toRightOf="parent"
40+
app:layout_constraintTop_toTopOf="parent"
41+
app:max_time_unit="HOUR"
42+
app:text_color="@color/colorPrimary"
43+
app:text_size="36dp"
44+
app:custom_font="@font/batmfa__" />
45+
46+
<com.tsuryo.androidcountdown.Counter
47+
android:id="@+id/counte1"
48+
android:layout_width="wrap_content"
49+
android:layout_height="wrap_content"
50+
app:layout_constraintBottom_toBottomOf="parent"
51+
app:layout_constraintLeft_toLeftOf="parent"
52+
app:layout_constraintRight_toRightOf="parent"
53+
app:layout_constraintTop_toBottomOf="@+id/gdH50"
54+
app:max_time_unit="DAY"
55+
app:text_color="#2196F3"
56+
app:text_size="36dp"
57+
app:textual_description="true"
58+
app:counter_font="DIGITAL_BOLD" />
59+
60+
```
461
### Installing
562

663
Add the JitPack repository to your build file.
@@ -17,6 +74,6 @@ allprojects {
1774
Add the dependency
1875
```
1976
dependencies {
20-
implementation 'com.github.tsuryo:Android-Countdown-Timer:1'
77+
implementation 'com.github.tsuryo:Android-Countdown-Timer:1.1'
2178
}
2279
```

androidcountdown/src/main/java/com/tsuryo/androidcountdown/Counter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ public void setDate(String date) {
113113
refresh();
114114
}
115115

116+
/**
117+
* @param date {@link Date}
118+
*/
119+
public void setDate(Date date) {
120+
SimpleDateFormat dateFormat = new SimpleDateFormat(
121+
"yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
122+
mDate = dateFormat.format(date);
123+
refresh();
124+
}
125+
116126
public void setTextColor(Integer textColor) {
117127
mTextColor = textColor;
118128
refresh();

app/src/main/java/com/tsuryo/countdowntimer/MainActivity.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,15 @@ protected void onCreate(Bundle savedInstanceState) {
3333
@Override
3434
protected void onStart() {
3535
super.onStart();
36-
mCounter.setDate("2019-07-19T18:33:00");
37-
mCounter1.setDate("2019-07-19T18:33:00");
36+
SimpleDateFormat format = new SimpleDateFormat(
37+
"yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
38+
try {
39+
Date date = format.parse("2019-07-22T18:33:00");
40+
mCounter.setDate(date);
41+
} catch (ParseException e) {
42+
e.printStackTrace();
43+
}
44+
mCounter1.setDate("2019-07-22T18:33:00");
3845

3946

4047
// mCounter.setIsShowingTextDesc(true);

0 commit comments

Comments
 (0)