Skip to content

Instantly share code, notes, and snippets.

@ysmintor
Last active March 24, 2017 03:45
Show Gist options
  • Save ysmintor/3b5d61de2404c30b9961a8a59de11417 to your computer and use it in GitHub Desktop.
Save ysmintor/3b5d61de2404c30b9961a8a59de11417 to your computer and use it in GitHub Desktop.
CountDownTimerTask extends AsyncTask
class CountDownTask extends AsyncTask<Long, Void, Pair<String, String>> {
@Override
protected Pair<String, String> doInBackground(Long... params) {
long millisUntilFinished = params[0];
long day = millisUntilFinished / (24 * 60 * 60 * SECOND_IN_MILLIS);
long hour = (millisUntilFinished / (60 * 60 * SECOND_IN_MILLIS) - day * 24);
long min = ((millisUntilFinished / (60 * SECOND_IN_MILLIS)) - day * 24 * 60 - hour * 60);
long s = (millisUntilFinished / SECOND_IN_MILLIS - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
String timeLeft = "" + day + "天" + hour + "小时" + min + "分" + s + "秒";
String dayLeft = String.format(Locale.CHINA, "请%d天内处理,超时系统将自动同意此次售后。", day + 1);
Pair<String, String> pair = new Pair<>(timeLeft, dayLeft);
return pair;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(Pair<String, String> result) {
super.onPostExecute(result);
mBinding.tvLeftTime.setText(result.first);
mBinding.tvLimitDay.setText(result.second);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment