├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── compiler.xml
├── deploymentTargetDropDown.xml
├── gradle.xml
├── kotlinc.xml
├── migrations.xml
├── misc.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── cn
│ │ │ └── leo
│ │ │ └── countdowntextview
│ │ │ ├── CountDownTextView.kt
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── cn
│ └── leo
│ └── countdowntextview
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/CountDownTextView/22f79353cae162284c7bd0eb98bd22449f79b134/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetDropDown.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/migrations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### CountDownTextView
2 |
3 | 倒计时文本控件,适合做短信验证码倒计时,启动页/广告页倒计时等等
4 | 已做防内存泄漏处理,并可设置在倒计时期间无法点击 ;
5 | 可设置页面关闭后再次开启,倒计时依然精确运行
6 | 可正向计时和倒计时,
7 | 一个文件复制使用,就不用浪费时间依赖了
8 |
9 | ```
10 | binding.tvCountDown
11 | .setNormalText("获取验证码")
12 | .setCountDownText("重新获取(%sS)")
13 | .setCloseKeepCountDown(true) //关闭页面保持倒计时开关
14 | .setCountDownClickable(false) //倒计时期间点击事件是否生效开关
15 | .setShowFormatTime(false) //是否格式化时间
16 | .setIntervalUnit(TimeUnit.SECONDS)
17 | .setOnCountDownStartListener {
18 | Toast.makeText(
19 | this@MainActivity,
20 | "开始计时",
21 | Toast.LENGTH_SHORT
22 | ).show()
23 | }
24 | .setOnCountDownTickListener { untilFinished ->
25 | Log.d(
26 | "countdown",
27 | "onTick: $untilFinished"
28 | )
29 | }
30 | .setOnCountDownFinishListener {
31 | Toast.makeText(
32 | this@MainActivity,
33 | "倒计时完毕",
34 | Toast.LENGTH_SHORT
35 | ).show()
36 | }
37 | .setOnClickListener {
38 | Toast.makeText(this@MainActivity, "短信已发送", Toast.LENGTH_SHORT).show()
39 | binding.tvCountDown.startCountDown(60)
40 | }
41 |
42 | ```
43 |
44 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'org.jetbrains.kotlin.android'
3 |
4 | android {
5 | namespace 'cn.leo.countdowntextview'
6 | compileSdkVersion 33
7 | defaultConfig {
8 | applicationId "cn.leo.countdowntextview"
9 | minSdkVersion 16
10 | targetSdkVersion 33
11 | versionCode 2
12 | versionName "1.1"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | //开启ViewBinding
22 | buildFeatures {
23 | viewBinding true
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 | //导入constraint-layout依赖
31 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
32 | //导入AndroidX依赖
33 | implementation 'androidx.appcompat:appcompat:1.6.1'
34 | //导入lifecycle-common依赖
35 | implementation 'androidx.lifecycle:lifecycle-common:2.6.1'
36 |
37 | testImplementation 'junit:junit:4.13.2'
38 | androidTestImplementation 'androidx.test:runner:1.5.2'
39 | }
40 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/leo/countdowntextview/CountDownTextView.kt:
--------------------------------------------------------------------------------
1 | package cn.leo.countdowntextview
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Context
5 | import android.os.CountDownTimer
6 | import android.text.TextUtils
7 | import android.util.AttributeSet
8 | import android.view.View
9 | import androidx.appcompat.widget.AppCompatTextView
10 | import androidx.fragment.app.FragmentActivity
11 | import androidx.lifecycle.DefaultLifecycleObserver
12 | import androidx.lifecycle.LifecycleOwner
13 | import java.util.Calendar
14 | import java.util.concurrent.TimeUnit
15 |
16 | /**
17 | * create by : Jarry Leo
18 | * date : 2018/7/26 10:19
19 | * update : 2023/8/25 11:49
20 | */
21 | @SuppressLint("UNUSED")
22 | class CountDownTextView @JvmOverloads constructor(
23 | context: Context,
24 | attrs: AttributeSet? = null,
25 | defStyleAttr: Int = 0
26 | ) : AppCompatTextView(context, attrs, defStyleAttr), DefaultLifecycleObserver,
27 | View.OnClickListener {
28 | private var mCountDownTimer: CountDownTimer? = null
29 | private var mOnCountDownStartListener: OnCountDownStartListener? = null
30 | private var mOnCountDownTickListener: OnCountDownTickListener? = null
31 | private var mOnCountDownFinishListener: OnCountDownFinishListener? = null
32 | private var mNormalText: String? = null
33 | private var mCountDownText: String? = null
34 | private var mOnClickListener: OnClickListener? = null
35 |
36 | /**
37 | * 倒计时期间是否允许点击
38 | */
39 | private var mClickable = false
40 |
41 | /**
42 | * 页面关闭后倒计时是否保持,再次开启倒计时继续;
43 | */
44 | private var mCloseKeepCountDown = false
45 |
46 | /**
47 | * 是否把时间格式化成时分秒
48 | */
49 | private var mShowFormatTime = false
50 |
51 | /**
52 | * 倒计时间隔
53 | */
54 | private var mIntervalUnit = TimeUnit.SECONDS
55 |
56 | init {
57 | init(context)
58 | }
59 |
60 | private fun init(context: Context) {
61 | autoBindLifecycle(context)
62 | }
63 |
64 | /**
65 | * 控件自动绑定生命周期,宿主可以是activity或者fragment
66 | */
67 | private fun autoBindLifecycle(context: Context) {
68 | if (context is FragmentActivity) {
69 | val fm = context.supportFragmentManager
70 | fm.fragments.find {
71 | it.view?.findViewById(id) === this
72 | }?.lifecycle?.addObserver(this)
73 | }
74 | if (context is LifecycleOwner) {
75 | (context as LifecycleOwner).lifecycle.addObserver(this)
76 | }
77 | }
78 |
79 | override fun onResume(owner: LifecycleOwner) {
80 | super.onResume(owner)
81 | if (mCountDownTimer == null) {
82 | checkLastCountTimestamp()
83 | }
84 | }
85 |
86 | private fun onDestroy() {
87 | if (mCountDownTimer != null) {
88 | mCountDownTimer?.cancel()
89 | mCountDownTimer = null
90 | }
91 | }
92 |
93 | override fun onDestroy(owner: LifecycleOwner) {
94 | super.onDestroy(owner)
95 | onDestroy()
96 | }
97 |
98 | override fun onDetachedFromWindow() {
99 | super.onDetachedFromWindow()
100 | onDestroy()
101 | }
102 |
103 | /**
104 | * 非倒计时状态文本
105 | *
106 | * @param normalText 文本
107 | */
108 | fun setNormalText(normalText: String?): CountDownTextView {
109 | mNormalText = normalText
110 | text = normalText
111 | return this
112 | }
113 |
114 | /**
115 | * 设置倒计时文本内容
116 | *
117 | * @param front 倒计时文本前部分
118 | * @param latter 倒计时文本后部分
119 | */
120 | fun setCountDownText(front: String, latter: String): CountDownTextView {
121 | mCountDownText = "$front%1\$s$latter"
122 | return this
123 | }
124 |
125 | /**
126 | * 设置倒计时文本内容
127 | *
128 | * @param text 倒计时文本,需包含%s作为倒计时文本占位符
129 | */
130 | fun setCountDownText(text: String): CountDownTextView {
131 | mCountDownText = text
132 | return this
133 | }
134 |
135 | /**
136 | * 设置倒计时间隔
137 | *
138 | * @param intervalUnit
139 | */
140 | fun setIntervalUnit(intervalUnit: TimeUnit): CountDownTextView {
141 | mIntervalUnit = intervalUnit
142 | return this
143 | }
144 |
145 | /**
146 | * 顺序计时,非倒计时
147 | *
148 | * @param second 计时时间秒
149 | */
150 | fun startCount(second: Long) {
151 | startCount(second, TimeUnit.SECONDS)
152 | }
153 |
154 | fun startCount(time: Long, timeUnit: TimeUnit) {
155 | if (mCloseKeepCountDown && checkLastCountTimestamp()) {
156 | return
157 | }
158 | count(time, 0, timeUnit, false)
159 | }
160 |
161 | /**
162 | * 默认按秒倒计时
163 | *
164 | * @param second 多少秒
165 | */
166 | fun startCountDown(second: Long) {
167 | startCountDown(second, TimeUnit.SECONDS)
168 | }
169 |
170 | fun startCountDown(time: Long, timeUnit: TimeUnit) {
171 | if (mCloseKeepCountDown && checkLastCountTimestamp()) {
172 | return
173 | }
174 | count(time, 0, timeUnit, true)
175 | }
176 |
177 | /**
178 | * 计时方案
179 | *
180 | * @param time 计时时长
181 | * @param timeUnit 时间单位
182 | * @param isCountDown 是否是倒计时,false正向计时
183 | */
184 | private fun count(time: Long, offset: Long, timeUnit: TimeUnit, isCountDown: Boolean) {
185 | mCountDownTimer?.cancel()
186 | mCountDownTimer = null
187 | isEnabled = mClickable
188 | val millisInFuture = timeUnit.toMillis(time) + 500
189 | val interval = TimeUnit.MILLISECONDS.convert(1, mIntervalUnit)
190 | if (mCloseKeepCountDown && offset == 0L) {
191 | setLastCountTimestamp(millisInFuture, interval, isCountDown)
192 | }
193 | if (offset == 0L) {
194 | mOnCountDownStartListener?.onStart()
195 | }
196 | if (TextUtils.isEmpty(mCountDownText)) {
197 | mCountDownText = text.toString()
198 | }
199 | mCountDownTimer = object : CountDownTimer(millisInFuture, interval) {
200 | override fun onTick(millisUntilFinished: Long) {
201 | val count =
202 | if (isCountDown) millisUntilFinished else millisInFuture - millisUntilFinished + offset
203 | val l = timeUnit.convert(count, TimeUnit.MILLISECONDS)
204 | val showTime: String = if (mShowFormatTime) {
205 | generateTime(count)
206 | } else {
207 | l.toString()
208 | }
209 | text = try {
210 | val countDownText = mCountDownText
211 | if (countDownText.isNullOrBlank()){
212 | showTime
213 | } else {
214 | String.format(countDownText, showTime)
215 | }
216 | } catch (e: Exception) {
217 | e.printStackTrace()
218 | showTime
219 | }
220 | mOnCountDownTickListener?.onTick(l)
221 | }
222 |
223 | override fun onFinish() {
224 | isEnabled = true
225 | mCountDownTimer = null
226 | text = mNormalText
227 | mOnCountDownFinishListener?.onFinish()
228 | }
229 | }
230 | mCountDownTimer?.start()
231 | }
232 |
233 | fun setOnCountDownStartListener(onCountDownStartListener: OnCountDownStartListener?): CountDownTextView {
234 | mOnCountDownStartListener = onCountDownStartListener
235 | return this
236 | }
237 |
238 | fun setOnCountDownTickListener(onCountDownTickListener: OnCountDownTickListener?): CountDownTextView {
239 | mOnCountDownTickListener = onCountDownTickListener
240 | return this
241 | }
242 |
243 | fun setOnCountDownFinishListener(onCountDownFinishListener: OnCountDownFinishListener?): CountDownTextView {
244 | mOnCountDownFinishListener = onCountDownFinishListener
245 | return this
246 | }
247 |
248 | /**
249 | * 倒计时期间,点击事件是否响应
250 | *
251 | * @param clickable 是否响应
252 | */
253 | fun setCountDownClickable(clickable: Boolean): CountDownTextView {
254 | mClickable = clickable
255 | return this
256 | }
257 |
258 | /**
259 | * 关闭页面是否保持倒计时
260 | *
261 | * @param keep 是否保持
262 | */
263 | fun setCloseKeepCountDown(keep: Boolean): CountDownTextView {
264 | mCloseKeepCountDown = keep
265 | return this
266 | }
267 |
268 | /**
269 | * 是否格式化时间
270 | *
271 | * @param formatTime 是否格式化
272 | */
273 | fun setShowFormatTime(formatTime: Boolean): CountDownTextView {
274 | mShowFormatTime = formatTime
275 | return this
276 | }
277 |
278 | fun interface OnCountDownStartListener {
279 | /**
280 | * 计时开始回调;反序列化时不会回调
281 | */
282 | fun onStart()
283 | }
284 |
285 | fun interface OnCountDownTickListener {
286 | /**
287 | * 计时回调
288 | *
289 | * @param untilFinished 剩余时间,单位为开始计时传入的单位
290 | */
291 | fun onTick(untilFinished: Long)
292 | }
293 |
294 | fun interface OnCountDownFinishListener {
295 | /**
296 | * 计时结束回调
297 | */
298 | fun onFinish()
299 | }
300 |
301 | override fun setOnClickListener(l: OnClickListener?) {
302 | mOnClickListener = l
303 | super.setOnClickListener(this)
304 | }
305 |
306 | override fun onClick(v: View) {
307 | if (mCountDownTimer != null && !mClickable) {
308 | return
309 | }
310 | mOnClickListener?.onClick(v)
311 | }
312 |
313 | /**
314 | * 持久化
315 | *
316 | * @param time 倒计时时长
317 | * @param interval 倒计时间隔
318 | * @param isCountDown 是否是倒计时而不是正向计时
319 | */
320 | @SuppressLint("ApplySharedPref")
321 | private fun setLastCountTimestamp(time: Long, interval: Long, isCountDown: Boolean) {
322 | context
323 | .getSharedPreferences(SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE)
324 | .edit()
325 | .putLong(SHARED_PREFERENCES_FIELD_TIME + id, time)
326 | .putLong(
327 | SHARED_PREFERENCES_FIELD_TIMESTAMP + id,
328 | Calendar.getInstance().timeInMillis + time
329 | )
330 | .putLong(SHARED_PREFERENCES_FIELD_INTERVAL + id, interval)
331 | .putBoolean(SHARED_PREFERENCES_FIELD_COUNTDOWN + id, isCountDown)
332 | .commit()
333 | }
334 |
335 | /**
336 | * 检查持久化参数
337 | *
338 | * @return 是否要保持持久化计时
339 | */
340 | private fun checkLastCountTimestamp(): Boolean {
341 | val sp = context.getSharedPreferences(SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE)
342 | val lastCountTimestamp = sp.getLong(SHARED_PREFERENCES_FIELD_TIMESTAMP + id, -1)
343 | val nowTimeMillis = Calendar.getInstance().timeInMillis
344 | val diff = lastCountTimestamp - nowTimeMillis
345 | if (diff <= 0) {
346 | return false
347 | }
348 | val time = sp.getLong(SHARED_PREFERENCES_FIELD_TIME + id, -1)
349 | val interval = sp.getLong(SHARED_PREFERENCES_FIELD_INTERVAL + id, -1)
350 | val isCountDown = sp.getBoolean(SHARED_PREFERENCES_FIELD_COUNTDOWN + id, true)
351 | for (timeUnit in TimeUnit.values()) {
352 | val convert = timeUnit.convert(interval, TimeUnit.MILLISECONDS)
353 | if (convert == 1L) {
354 | val last = timeUnit.convert(diff, TimeUnit.MILLISECONDS)
355 | val offset = time - diff
356 | count(last, offset, timeUnit, isCountDown)
357 | return true
358 | }
359 | }
360 | return false
361 | }
362 |
363 | companion object {
364 | private const val SHARED_PREFERENCES_FILE = "CountDownTextView"
365 | private const val SHARED_PREFERENCES_FIELD_TIME = "last_count_time"
366 | private const val SHARED_PREFERENCES_FIELD_TIMESTAMP = "last_count_timestamp"
367 | private const val SHARED_PREFERENCES_FIELD_INTERVAL = "count_interval"
368 | private const val SHARED_PREFERENCES_FIELD_COUNTDOWN = "is_countdown"
369 |
370 | /**
371 | * 将毫秒转时分秒
372 | */
373 | @SuppressLint("DefaultLocale")
374 | fun generateTime(time: Long): String {
375 | val format: String
376 | val totalSeconds = (time / 1000).toInt()
377 | val seconds = totalSeconds % 60
378 | val minutes = totalSeconds / 60 % 60
379 | val hours = totalSeconds / 3600
380 | format = if (hours > 0) {
381 | String.format("%02d时%02d分%02d秒", hours, minutes, seconds)
382 | } else if (minutes > 0) {
383 | String.format("%02d分%02d秒", minutes, seconds)
384 | } else {
385 | String.format("%2d秒", seconds)
386 | }
387 | return format
388 | }
389 | }
390 | }
--------------------------------------------------------------------------------
/app/src/main/java/cn/leo/countdowntextview/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package cn.leo.countdowntextview
2 |
3 | import android.os.Bundle
4 | import android.util.Log
5 | import android.widget.Toast
6 | import androidx.appcompat.app.AppCompatActivity
7 | import cn.leo.countdowntextview.databinding.ActivityMainBinding
8 | import java.util.concurrent.TimeUnit
9 |
10 | class MainActivity : AppCompatActivity() {
11 | private val binding by lazy { ActivityMainBinding.inflate(layoutInflater) }
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | super.onCreate(savedInstanceState)
14 | setContentView(binding.root)
15 | count()
16 | }
17 |
18 | private fun count() {
19 | binding.tvCountDown
20 | .setNormalText("获取验证码")
21 | .setCountDownText("重新获取(%sS)")
22 | .setCloseKeepCountDown(true) //关闭页面保持倒计时开关
23 | .setCountDownClickable(false) //倒计时期间点击事件是否生效开关
24 | .setShowFormatTime(false) //是否格式化时间
25 | .setIntervalUnit(TimeUnit.SECONDS)
26 | .setOnCountDownStartListener {
27 | Toast.makeText(
28 | this@MainActivity,
29 | "开始计时",
30 | Toast.LENGTH_SHORT
31 | ).show()
32 | }
33 | .setOnCountDownTickListener { untilFinished ->
34 | Log.d(
35 | "countdown",
36 | "onTick: $untilFinished"
37 | )
38 | }
39 | .setOnCountDownFinishListener {
40 | Toast.makeText(
41 | this@MainActivity,
42 | "倒计时完毕",
43 | Toast.LENGTH_SHORT
44 | ).show()
45 | }
46 | .setOnClickListener {
47 | Toast.makeText(this@MainActivity, "短信已发送", Toast.LENGTH_SHORT).show()
48 | binding.tvCountDown.startCountDown(60)
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/CountDownTextView/22f79353cae162284c7bd0eb98bd22449f79b134/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/CountDownTextView/22f79353cae162284c7bd0eb98bd22449f79b134/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/CountDownTextView/22f79353cae162284c7bd0eb98bd22449f79b134/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/CountDownTextView/22f79353cae162284c7bd0eb98bd22449f79b134/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/CountDownTextView/22f79353cae162284c7bd0eb98bd22449f79b134/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/CountDownTextView/22f79353cae162284c7bd0eb98bd22449f79b134/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/CountDownTextView/22f79353cae162284c7bd0eb98bd22449f79b134/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/CountDownTextView/22f79353cae162284c7bd0eb98bd22449f79b134/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/CountDownTextView/22f79353cae162284c7bd0eb98bd22449f79b134/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/CountDownTextView/22f79353cae162284c7bd0eb98bd22449f79b134/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CountDownTextView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/cn/leo/countdowntextview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.leo.countdowntextview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | String reg = "^\\w{1,40}@\\w{1,40}\\.[A-Za-z]{2,3}$";
16 | String email1 = "1234567_8@qq.com";
17 | String email2 = "12345678qq.com";
18 | String email3 = "12345678@qq..com";
19 | String email4 = "12345!678@qq.com";
20 | boolean b1 = email1.matches(reg);
21 | boolean b2 = email2.matches(reg);
22 | boolean b3 = email3.matches(reg);
23 | boolean b4 = email4.matches(reg);
24 | assertEquals(true, b1);
25 | assertEquals(false, b2);
26 | assertEquals(false, b3);
27 | assertEquals(false, b4);
28 | }
29 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | ext {
6 | kotlin_version = '1.9.10'
7 | }
8 | repositories {
9 | google()
10 | mavenCentral()
11 | }
12 | dependencies {
13 | classpath 'com.android.tools.build:gradle:7.4.2'
14 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
15 |
16 |
17 | // NOTE: Do not place your application dependencies here; they belong
18 | // in the individual module build.gradle files
19 | }
20 | }
21 |
22 | allprojects {
23 | repositories {
24 | google()
25 | mavenCentral()
26 | }
27 | }
28 |
29 | tasks.register('clean', Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # use AndroidX
15 | android.useAndroidX=true
16 | android.enableJetifier=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/CountDownTextView/22f79353cae162284c7bd0eb98bd22449f79b134/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright ? 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions ?$var?, ?${var}?, ?${var:-default}?, ?${var+SET}?,
36 | # ?${var#prefix}?, ?${var%suffix}?, and ?$( cmd )?;
37 | # * compound commands having a testable exit status, especially ?case?;
38 | # * various built-in commands including ?command?, ?set?, and ?ulimit?.
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84 |
85 | APP_NAME="Gradle"
86 | APP_BASE_NAME=${0##*/}
87 |
88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 |
142 | # Increase the maximum file descriptors if we can.
143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144 | case $MAX_FD in #(
145 | max*)
146 | MAX_FD=$( ulimit -H -n ) ||
147 | warn "Could not query maximum file descriptor limit"
148 | esac
149 | case $MAX_FD in #(
150 | '' | soft) :;; #(
151 | *)
152 | ulimit -n "$MAX_FD" ||
153 | warn "Could not set maximum file descriptor limit to $MAX_FD"
154 | esac
155 | fi
156 |
157 | # Collect all arguments for the java command, stacking in reverse order:
158 | # * args from the command line
159 | # * the main class name
160 | # * -classpath
161 | # * -D...appname settings
162 | # * --module-path (only if needed)
163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
164 |
165 | # For Cygwin or MSYS, switch paths to Windows format before running java
166 | if "$cygwin" || "$msys" ; then
167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
169 |
170 | JAVACMD=$( cygpath --unix "$JAVACMD" )
171 |
172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
173 | for arg do
174 | if
175 | case $arg in #(
176 | -*) false ;; # don't mess with options #(
177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
178 | [ -e "$t" ] ;; #(
179 | *) false ;;
180 | esac
181 | then
182 | arg=$( cygpath --path --ignore --mixed "$arg" )
183 | fi
184 | # Roll the args list around exactly as many times as the number of
185 | # args, so each arg winds up back in the position where it started, but
186 | # possibly modified.
187 | #
188 | # NB: a `for` loop captures its iteration list before it begins, so
189 | # changing the positional parameters here affects neither the number of
190 | # iterations, nor the values presented in `arg`.
191 | shift # remove old arg
192 | set -- "$@" "$arg" # push replacement arg
193 | done
194 | fi
195 |
196 | # Collect all arguments for the java command;
197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
198 | # shell script including quotes and variable substitutions, so put them in
199 | # double quotes to make sure that they get re-expanded; and
200 | # * put everything else in single quotes, so that it's not re-expanded.
201 |
202 | set -- \
203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
204 | -classpath "$CLASSPATH" \
205 | org.gradle.wrapper.GradleWrapperMain \
206 | "$@"
207 |
208 | # Use "xargs" to parse quoted args.
209 | #
210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
211 | #
212 | # In Bash we could simply go:
213 | #
214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
215 | # set -- "${ARGS[@]}" "$@"
216 | #
217 | # but POSIX shell has neither arrays nor command substitution, so instead we
218 | # post-process each arg (as a line of input to sed) to backslash-escape any
219 | # character that might be a shell metacharacter, then use eval to reverse
220 | # that process (while maintaining the separation between arguments), and wrap
221 | # the whole thing up as a single "set" statement.
222 | #
223 | # This will of course break if any of these variables contains a newline or
224 | # an unmatched quote.
225 | #
226 |
227 | eval "set -- $(
228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
229 | xargs -n1 |
230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
231 | tr '\n' ' '
232 | )" '"$@"'
233 |
234 | exec "$JAVACMD" "$@"
235 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------