Search in sources :

Example 16 with CountDownTimer

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();
}
Also used : CountDownTimer(android.os.CountDownTimer)

Example 17 with CountDownTimer

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();
}
Also used : CountDownTimer(android.os.CountDownTimer) Test(org.junit.Test)

Example 18 with CountDownTimer

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);
}
Also used : CountDownTimer(android.os.CountDownTimer) Before(org.junit.Before)

Example 19 with 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();
}
Also used : CountDownTimer(android.os.CountDownTimer)

Example 20 with CountDownTimer

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();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SharedPreferences(android.content.SharedPreferences) CheckBox(android.widget.CheckBox) CountDownTimer(android.os.CountDownTimer) HmsPicker(com.doomonafireball.betterpickers.hmspicker.HmsPicker) View(android.view.View) HmsView(com.doomonafireball.betterpickers.hmspicker.HmsView) HmsView(com.doomonafireball.betterpickers.hmspicker.HmsView)

Aggregations

CountDownTimer (android.os.CountDownTimer)24 TextView (android.widget.TextView)4 Test (org.junit.Test)2 SharedPreferences (android.content.SharedPreferences)1 TypedArray (android.content.res.TypedArray)1 View (android.view.View)1 WebSettingsClassic (android.webkit.WebSettingsClassic)1 CheckBox (android.widget.CheckBox)1 EditText (android.widget.EditText)1 SweetAlertDialog (cn.pedant.SweetAlert.SweetAlertDialog)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 AVException (com.avos.avoscloud.AVException)1 RequestMobileCodeCallback (com.avos.avoscloud.RequestMobileCodeCallback)1 HmsPicker (com.doomonafireball.betterpickers.hmspicker.HmsPicker)1 HmsView (com.doomonafireball.betterpickers.hmspicker.HmsView)1 MarkerUpdate (com.omkarmoghe.pokemap.models.events.MarkerUpdate)1 Timer (java.util.Timer)1 Before (org.junit.Before)1