use of android.os.CountDownTimer in project android_frameworks_base by ParanoidAndroid.
the class KeyguardAbsKeyInputView method handleAttemptLockout.
// Prevent user from using the PIN/Password entry until scheduled deadline.
protected void handleAttemptLockout(long elapsedRealtimeDeadline) {
mPasswordEntry.setEnabled(false);
long elapsedRealtime = SystemClock.elapsedRealtime();
new CountDownTimer(elapsedRealtimeDeadline - elapsedRealtime, 1000) {
@Override
public void onTick(long millisUntilFinished) {
int secondsRemaining = (int) (millisUntilFinished / 1000);
mSecurityMessageDisplay.setMessage(R.string.kg_too_many_failed_attempts_countdown, true, secondsRemaining);
}
@Override
public void onFinish() {
mSecurityMessageDisplay.setMessage("", false);
resetState();
}
}.start();
}
use of android.os.CountDownTimer in project robolectric by robolectric.
the class ShadowCountDownTimerTest method testCancel.
@Test
public void testCancel() {
CountDownTimer timer = shadowCountDownTimer.start();
assertThat(timer).isNotNull();
assertThat(shadowCountDownTimer.hasStarted()).isTrue();
shadowCountDownTimer.cancel();
assertThat(shadowCountDownTimer.hasStarted()).isFalse();
}
use of android.os.CountDownTimer in project robolectric by robolectric.
the class ShadowCountDownTimerTest method setUp.
@Before
public void setUp() throws Exception {
countDownTimer = new CountDownTimer(millisInFuture, countDownInterval) {
@Override
public void onFinish() {
msg = "onFinish() is called";
}
@Override
public void onTick(long millisUnitilFinished) {
msg = "onTick() is called";
}
};
shadowCountDownTimer = Shadows.shadowOf(countDownTimer);
}
use of android.os.CountDownTimer in project platform_frameworks_base by android.
the class KeyguardAbsKeyInputView method handleAttemptLockout.
// Prevent user from using the PIN/Password entry until scheduled deadline.
protected void handleAttemptLockout(long elapsedRealtimeDeadline) {
setPasswordEntryEnabled(false);
long elapsedRealtime = SystemClock.elapsedRealtime();
new CountDownTimer(elapsedRealtimeDeadline - elapsedRealtime, 1000) {
@Override
public void onTick(long millisUntilFinished) {
int secondsRemaining = (int) (millisUntilFinished / 1000);
mSecurityMessageDisplay.setMessage(R.string.kg_too_many_failed_attempts_countdown, true, secondsRemaining);
}
@Override
public void onFinish() {
mSecurityMessageDisplay.setMessage("", false);
resetState();
}
}.start();
}
use of android.os.CountDownTimer in project Shuttle by timusus.
the class SleepTimer method createTimer.
/**
* Constructor for <code>SleepTimer</code>
*
* @param context The {@link Activity} to use
* @param active True if the timer is active, false otherwise
* @param remaining The remaining time of the current track
*/
public static void createTimer(final Context context, boolean active, final long remaining) {
final View view = LayoutInflater.from(context).inflate(R.layout.dialog_timer, null);
final HmsPicker hmsPicker = (HmsPicker) view.findViewById(R.id.hms_picker);
final HmsView hmsView = (HmsView) view.findViewById(R.id.hms_view);
ThemeUtils.themeHmsPicker(hmsPicker);
ThemeUtils.themeHmsView(hmsView);
final long timeMillis = remaining - System.currentTimeMillis();
final int minutes = (int) ((timeMillis / (1000 * 60)) % 60);
final int hours = (int) ((timeMillis / (1000 * 60 * 60)) % 24);
int minutesFirstDigit = 0;
int minuteSecondDigit = 0;
if (minutes > 0) {
minutesFirstDigit = minutes / 10;
minuteSecondDigit = minutes % 10;
}
hmsView.setTime(hours, minutesFirstDigit, minuteSecondDigit);
final SharedPreferences mPrefs;
mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
final CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox);
checkBox.setChecked(mPrefs.getBoolean("sleep_timer_wait_til_end", true));
checkBox.setOnCheckedChangeListener((compoundButton, b) -> mPrefs.edit().putBoolean("sleep_timer_wait_til_end", b).apply());
final MaterialDialog.Builder builder = DialogUtils.getBuilder(context).customView(view, false).negativeText(R.string.close);
if (active) {
hmsView.setVisibility(View.VISIBLE);
hmsPicker.setVisibility(View.GONE);
builder.positiveText(R.string.timer_stop).onPositive((materialDialog, dialogAction) -> MusicUtils.stopTimer());
} else {
hmsView.setVisibility(View.GONE);
hmsPicker.setVisibility(View.VISIBLE);
builder.positiveText(R.string.timer_set).onPositive((materialDialog, dialogAction) -> {
if (hmsPicker.getTime() != 0) {
MusicUtils.setTimer(hmsPicker.getTime() * 1000);
}
hmsPicker.setVisibility(View.GONE);
hmsView.setVisibility(View.VISIBLE);
});
}
builder.show();
new CountDownTimer(timeMillis, 1000) {
@Override
public void onTick(long millisUntilFinished) {
final long timeMillis = remaining - System.currentTimeMillis();
final int minutes = (int) ((timeMillis / (1000 * 60)) % 60);
final int hours = (int) ((timeMillis / (1000 * 60 * 60)) % 24);
int minutesFirstDigit = 0;
int minuteSecondDigit = 0;
if (minutes > 0) {
minutesFirstDigit = minutes / 10;
minuteSecondDigit = minutes % 10;
}
hmsView.setTime(hours, minutesFirstDigit, minuteSecondDigit);
}
@Override
public void onFinish() {
}
}.start();
}
Aggregations