Java Code Examples for android.os.CountDownTimer#start()
The following examples show how to use
android.os.CountDownTimer#start() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FloatWaitView.java From ClockView with Apache License 2.0 | 6 votes |
private void createTimer() { timer = new CountDownTimer(duration, duration / (ovalNum + 1)) { @Override public void onTick(long millisUntilFinished) { if (position < ovalNum) { Oval oval = mOvals.get(position++); oval.mAnimator.start(); } } @Override public void onFinish() { } }; timer.start(); }
Example 2
Source File: WelcomeActivity.java From LinkedME-Android-Deep-Linking-Demo with GNU General Public License v3.0 | 6 votes |
private void startCountDownTime(long time) { timer = new CountDownTimer(time * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { //每隔countDownInterval秒会回调一次onTick()方法 down_timer.setText(String.format(getString(R.string.count_down_str), millisUntilFinished / 1000)); } @Override public void onFinish() { openDemo(); } }; timer.start();// 开始计时 }
Example 3
Source File: msf_shell.java From styT with Apache License 2.0 | 6 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { // 第一个参数是总时间, 第二个参数是间隔 mCodeTimer = new CountDownTimer(60000, 1000) { @Override public void onTick(long millisUntilFinished) { // 广播剩余时间 broadcastUpdate(IN_RUNNING, millisUntilFinished / 1000 + ""); } @Override public void onFinish() { // 广播倒计时结束 broadcastUpdate(END_RUNNING); // 停止服务 stopSelf(); } }; // 开始倒计时 mCodeTimer.start(); return super.onStartCommand(intent, flags, startId); }
Example 4
Source File: Reg.java From stynico with MIT License | 6 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { // 第一个参数是总时间, 第二个参数是间隔 mCodeTimer = new CountDownTimer(129000, 1000) { @Override public void onTick(long millisUntilFinished) { // 广播剩余时间 broadcastUpdate(IN_RUNNING, millisUntilFinished / 1000 + ""); } @Override public void onFinish() { // 广播倒计时结束 broadcastUpdate(END_RUNNING); // 停止服务 stopSelf(); } }; // 开始倒计时 mCodeTimer.start(); return super.onStartCommand(intent, flags, startId); }
Example 5
Source File: msf_shell.java From stynico with MIT License | 6 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { // 第一个参数是总时间, 第二个参数是间隔 mCodeTimer = new CountDownTimer(60000, 1000) { @Override public void onTick(long millisUntilFinished) { // 广播剩余时间 broadcastUpdate(IN_RUNNING, millisUntilFinished / 1000 + ""); } @Override public void onFinish() { // 广播倒计时结束 broadcastUpdate(END_RUNNING); // 停止服务 stopSelf(); } }; // 开始倒计时 mCodeTimer.start(); return super.onStartCommand(intent, flags, startId); }
Example 6
Source File: PocketProtector.java From Huochexing12306 with Apache License 2.0 | 6 votes |
@Override public boolean start(Object obj) { try{ mSensorManger = (SensorManager)getmServiceContext().getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManger.getDefaultSensor(Sensor.TYPE_PROXIMITY); mSensorListener = new MySensorListener(); request(AntiTheftService.REQUEST_SHOW_MSG, getName() + "防护已开启,将在10秒后正式生效" + SF.TIP); mCDTimer = new CountDownTimer(10000, 1000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { mSensorManger.registerListener(mSensorListener, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } }; setNeedDelay(true); mCDTimer.start(); return true; }catch(Exception e){ request(AntiTheftService.REQUEST_SHOW_MSG, "开启\"" + getName() + "\"防护失败,可能您的设备不支持距离传感器!"); return false; } }
Example 7
Source File: MonitorActivity.java From haven with GNU General Public License v3.0 | 6 votes |
private void initTimer() { txtTimer.setTextColor(getResources().getColor(R.color.colorAccent)); cTimer = new CountDownTimer((preferences.getTimerDelay()) * 1000, 1000) { public void onTick(long millisUntilFinished) { mOnTimerTicking = true; txtTimer.setText(getTimerText(millisUntilFinished)); } public void onFinish() { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); txtTimer.setText(R.string.status_on); initMonitor(); mOnTimerTicking = false; } }; cTimer.start(); }
Example 8
Source File: BaseRecordingActivity.java From fritz-examples with MIT License | 6 votes |
private void showStartRecordingViews() { videoRecordingProgress.setVisibility(View.VISIBLE); videoRecordingProgress.setMax(NUM_PROGRESS_INTERVALS); videoRecordingProgress.setProgress(0); chooseModelBtn.setVisibility(View.GONE); mCountDownTimer = new CountDownTimer(MAX_RECORDING_TIME_MS, TIME_BETWEEN_RECORDING_INTERVAL_MS) { @Override public void onTick(long millisUntilFinished) { int progress = (int) (NUM_PROGRESS_INTERVALS - millisUntilFinished / TIME_BETWEEN_RECORDING_INTERVAL_MS); videoRecordingProgress.setProgress(progress); } @Override public void onFinish() { // finish recording when MAX_RECORDING_TIME_MS is met if (isRecording.compareAndSet(true, false)) { videoRecordingProgress.setProgress(NUM_PROGRESS_INTERVALS); showFinishRecordingViews(); } } }; mCountDownTimer.start(); }
Example 9
Source File: RestProtector.java From Huochexing12306 with Apache License 2.0 | 5 votes |
@Override public boolean start(Object obj) { mSpeedThreshold = setSP.getAntiTheftRestSensitivity(); try{ mSensorManger = (SensorManager)getmServiceContext().getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManger.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mSensorListener = new MySensorListener(); request(AntiTheftService.REQUEST_SHOW_MSG, getName() + "防护已开启,将在10秒后正式生效" + SF.TIP); mCDTimer = new CountDownTimer(10000, 1000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { mSensorManger.registerListener(mSensorListener, mSensor, SensorManager.SENSOR_DELAY_NORMAL); } }; setNeedDelay(true); mCDTimer.start(); return true; }catch(Exception e){ request(AntiTheftService.REQUEST_SHOW_MSG, "开启\"" + getName() + "\"防护失败,可能您的设备不支持近距离传感器!"); return false; } }
Example 10
Source File: CrashActivity.java From AndroidCrashHelper with MIT License | 5 votes |
private void sendToQQ() { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("crash_log", stackTrace); clipboard.setPrimaryClip(clip); Toast.makeText(this, "错误日志已复制,请粘贴发送!", Toast.LENGTH_LONG).show(); try { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); Uri uri = Uri.parse("mqqwpa://im/chat?chat_type=wpa&uin=" + AppConfig.DEVELOPER_QQ + "&version=1"); intent.setData(uri); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } catch (Exception e) { e.printStackTrace(); } //延迟杀掉软件,以便Toast显示完毕 CountDownTimer timer = new CountDownTimer(3000, 1000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { exitApp(); } }; timer.start(); }
Example 11
Source File: FragmentRegisterViewModel.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
private void dialogWaitTimeVerifyPassword(long time) { boolean wrapInScrollView = true; final MaterialDialog dialogWait = new MaterialDialog.Builder(G.fragmentActivity).title(R.string.error_check_password).customView(R.layout.dialog_remind_time, wrapInScrollView).positiveText(R.string.B_ok).autoDismiss(true).canceledOnTouchOutside(true).onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { dialog.dismiss(); } }).show(); View v = dialogWait.getCustomView(); final TextView remindTime = (TextView) v.findViewById(R.id.remindTime); CountDownTimer countWaitTimer = new CountDownTimer(time * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { int seconds = (int) ((millisUntilFinished) / 1000); int minutes = seconds / 60; seconds = seconds % 60; remindTime.setText("" + String.format("%02d", minutes) + ":" + String.format("%02d", seconds)); } @Override public void onFinish() { remindTime.setText("00:00"); } }; countWaitTimer.start(); }
Example 12
Source File: FragmentRegisterViewModel.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
private void counterTimer(TextView txtTimer, TextView btnResondCode) { long time = 0; if (BuildConfig.DEBUG) { time = 2 * DateUtils.SECOND_IN_MILLIS; } else if (FragmentRegister.smsPermission) { time = Config.COUNTER_TIMER; } else { time = 5 * DateUtils.SECOND_IN_MILLIS; } CountDownTimer countDownTimer = new CountDownTimer(time, Config.COUNTER_TIMER_DELAY) { // wait for verify sms public void onTick(long millisUntilFinished) { int seconds = (int) ((millisUntilFinished) / 1000); int minutes = seconds / 60; seconds = seconds % 60; txtTimer.setText("" + String.format("%02d", minutes) + ":" + String.format("%02d", seconds)); } public void onFinish() { txtTimer.setVisibility(View.INVISIBLE); btnResondCode.setEnabled(true); btnResondCode.setTextColor(G.context.getResources().getColor(R.color.green)); } }; countDownTimer.start(); }
Example 13
Source File: FragmentSecurityViewModel.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
private void dialogWaitTime(long time) { boolean wrapInScrollView = true; final MaterialDialog dialogWait = new MaterialDialog.Builder(G.fragmentActivity).title(R.string.error_check_password).customView(R.layout.dialog_remind_time, wrapInScrollView).positiveText(R.string.B_ok).autoDismiss(true).canceledOnTouchOutside(true).onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { dialog.dismiss(); } }).show(); View v = dialogWait.getCustomView(); final TextView remindTime = (TextView) v.findViewById(R.id.remindTime); CountDownTimer countWaitTimer = new CountDownTimer(time * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { int seconds = (int) ((millisUntilFinished) / 1000); int minutes = seconds / 60; seconds = seconds % 60; remindTime.setText("" + String.format("%02d", minutes) + ":" + String.format("%02d", seconds)); } @Override public void onFinish() { remindTime.setText("00:00"); } }; countWaitTimer.start(); }
Example 14
Source File: EmailNextActivity.java From Huochexing12306 with Apache License 2.0 | 5 votes |
private void initViews() { strReSend = this.getIntent().getStringExtra(RESEND_STR); strVerifyNum = this.getIntent().getStringExtra(VERIFY_NUM); strTempAuthCode = this.getIntent().getStringExtra(AUTH_CODE); strOperate = this.getIntent().getStringExtra(OPERATE); tvVerifyNum = (TextView) findViewById(R.id.verifyNum); etAuthCode = (EditText)findViewById(R.id.code); Button btnOK = (Button)findViewById(R.id.ok); btnOK.setOnClickListener(this); btnReSendKey = (Button)findViewById(R.id.resend); btnReSendKey.setOnClickListener(this); tvVerifyNum.setText(strVerifyNum); btnReSendKey.setEnabled(false); CountDownTimer cdTimer = new CountDownTimer(60000, 1000){ @Override public void onFinish() { btnReSendKey.setEnabled(true); btnReSendKey.setText("重新发送验证码"); } @Override public void onTick(long millisUntilFinished) { btnReSendKey.setText("重新发送(" + millisUntilFinished/1000 + "秒)"); } }; cdTimer.start(); }
Example 15
Source File: AntiTheftService.java From Huochexing12306 with Apache License 2.0 | 5 votes |
/** * 开始报警. */ private void startAlarm(final int protectType) { final BaseProtector protector = protectors.get(protectType); if (protector == null) { return; } if (hasAlarmTriggered()) { return; } protector.setAlarmTriggered(true); mIsAlarmRunning = true; if (setSP.getAntiTheftDelayTime() != 0) { CountDownTimer cdTimer = new CountDownTimer( setSP.getAntiTheftDelayTime(), 1000) { @Override public void onTick(long millisUntilFinished) { if (mOnProgressListener != null) { L.i("millisUntilFinished:" + millisUntilFinished); mOnProgressListener .onProgress( MSG_DELAY_ON_TICK, String.valueOf(getSenond(millisUntilFinished) - 1)); } } @Override public void onFinish() { runAlarm(protectType); } }; cdTimer.start(); } else { runAlarm(protectType); } }
Example 16
Source File: A6OrderAty.java From Huochexing12306 with Apache License 2.0 | 5 votes |
private void tipLostTime() { try { TicketInfo tInfo = mLstODBInfos.get(0).getTickets().get(0); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS", Locale.CHINA); Date nowTime = new Date(); Date loseTime = sdf1.parse(tInfo.getLose_time()); long diffSS = loseTime.getTime() - nowTime.getTime(); if (diffSS >= 0) { CountDownTimer cdTimer = new CountDownTimer(diffSS, 1000) { @Override public void onFinish() { btnPay.setText("订单信息已过期"); btnPay.setEnabled(false); } @Override public void onTick(long millisUntilFinished) { String str1 = TimeUtil .getFmt_M_S_Str(millisUntilFinished / 1000); // tvPay.setText("立即支付(" + str1+")"); btnPay.setText("剩余时间(" + str1 + ")"); } }; cdTimer.start(); } } catch (Exception e) { e.printStackTrace(); } }
Example 17
Source File: SosActivity.java From NaviBee with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sos); // If activity is called by fall detection boolean isDetected = getIntent().getBooleanExtra("fall_detection", false); if (isDetected) { TextView textView = findViewById(R.id.sos_countdown_pre_text); textView.setText(R.string.sos_pre_text); } checkPhoneCallPermission(); mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this); countDownView = findViewById(R.id.sos_progress); countDownText = findViewById(R.id.sos_progress_text); countDownView.setMax(10 * 1000); countDownView.setProgress(10 * 1000); countDownView.setAnimationInterpolator(new LinearInterpolator()); countDownTimer = new CountDownTimer(10 * 1000, 1000) { @SuppressLint("SetTextI18n") @Override public void onTick(long l) { countDownText.setText(Long.toString(l / 1000 + 1)); countDownView.setProgress(l, true, 1000); } @Override public void onFinish() { triggerSOS(); } }; countDownTimer.start(); }
Example 18
Source File: IrrigationDeviceCardController.java From arcusandroid with Apache License 2.0 | 5 votes |
protected void showWateringTimer() { if (mModel == null) { return; } wateringCountdown = new CountDownTimer(TimeUnit.SECONDS.toMillis(mModel.getWateringSecondsRemaining()), 1000) { @Override public void onFinish() {} @Override public void onTick(long millisUntilFinished) { IrrigationDeviceControlCard deviceCard = (IrrigationDeviceControlCard) getCard(); if (mModel == null || deviceCard == null) { return; } int hoursRemaining = (int) TimeUnit.MILLISECONDS.toHours(millisUntilFinished); int minutesRemaining = (int) TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) % 60; minutesRemaining += TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) % 60 > 0 ? 1 : 0; if (minutesRemaining == 60) { hoursRemaining += 1; minutesRemaining = 0; } String hours = getContext().getResources().getQuantityString(R.plurals.care_hours_plural, hoursRemaining, hoursRemaining); String mins = getContext().getResources().getQuantityString(R.plurals.care_minutes_plural, minutesRemaining, minutesRemaining); if (hoursRemaining != 0) { if (minutesRemaining == 0) { deviceCard.setScheduleMode(String.format("%s Remaining", hours)); } else { deviceCard.setScheduleMode(String.format("%s %s Remaining", hours, mins)); } } else { deviceCard.setScheduleMode(String.format("%s Remaining", mins)); } } }; wateringCountdown.start(); }
Example 19
Source File: IrrigationFragment.java From arcusandroid with Apache License 2.0 | 4 votes |
protected void showWateringTimer() { if (controllerDetailsModel == null) { return; } if (eventImage != null) { eventImage.setVisibility(View.VISIBLE); } wateringCountdown = new CountDownTimer(TimeUnit.SECONDS.toMillis(controllerDetailsModel.getWateringSecondsRemaining()), 1000) { @Override public void onFinish() {} @Override public void onTick(long millisUntilFinished) { if (eventStatusTime == null || eventStatusText == null || controllerDetailsModel == null) { return; } int hoursRemaining = (int) TimeUnit.MILLISECONDS.toHours(millisUntilFinished); int minutesRemaining = (int) TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) % 60; minutesRemaining += TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) % 60 > 0 ? 1 : 0; if (minutesRemaining == 60) { hoursRemaining += 1; minutesRemaining = 0; } eventStatusText.setText(controllerDetailsModel.getZoneNameWatering()); String hours = getResources().getQuantityString(R.plurals.care_hours_plural, hoursRemaining, hoursRemaining); String mins = getResources().getQuantityString(R.plurals.care_minutes_plural, minutesRemaining, minutesRemaining); if (hoursRemaining != 0) { if (minutesRemaining == 0) { eventStatusTime.setText(String.format("%s Remaining", hours)); } else { eventStatusTime.setText(String.format("%s %s Remaining", hours, mins)); } } else { eventStatusTime.setText(String.format("%s Remaining", mins)); } } }; wateringCountdown.start(); }
Example 20
Source File: MainActivity.java From wear-os-samples with Apache License 2.0 | 4 votes |
@Override public void onUIStateChanged(UIAnimation.UIState state) { Log.d(TAG, "UI State is: " + state); if (mUiState == state) { return; } switch (state) { case MUSIC_UP: mState = AppState.PLAYING_MUSIC; mUiState = state; playMusic(); break; case MIC_UP: mState = AppState.RECORDING; mUiState = state; mSoundRecorder.startRecording(); setProgressBar(COUNT_DOWN_MS); mCountDownTimer = new CountDownTimer(COUNT_DOWN_MS, MILLIS_IN_SECOND) { @Override public void onTick(long millisUntilFinished) { mProgressBar.setVisibility(View.VISIBLE); setProgressBar(millisUntilFinished); Log.d(TAG, "Time Left: " + millisUntilFinished / MILLIS_IN_SECOND); } @Override public void onFinish() { mProgressBar.setProgress(0); mProgressBar.setVisibility(View.INVISIBLE); mSoundRecorder.stopRecording(); mUIAnimation.transitionToHome(); mUiState = UIAnimation.UIState.HOME; mState = AppState.READY; mCountDownTimer = null; } }; mCountDownTimer.start(); break; case SOUND_UP: mState = AppState.PLAYING_VOICE; mUiState = state; mSoundRecorder.startPlay(); break; case HOME: switch (mState) { case PLAYING_MUSIC: mState = AppState.READY; mUiState = state; stopMusic(); break; case PLAYING_VOICE: mState = AppState.READY; mUiState = state; mSoundRecorder.stopPlaying(); break; case RECORDING: mState = AppState.READY; mUiState = state; mSoundRecorder.stopRecording(); if (mCountDownTimer != null) { mCountDownTimer.cancel(); mCountDownTimer = null; } mProgressBar.setVisibility(View.INVISIBLE); setProgressBar(COUNT_DOWN_MS); break; } break; } }