Example usage for android.os CountDownTimer CountDownTimer

List of usage examples for android.os CountDownTimer CountDownTimer

Introduction

In this page you can find the example usage for android.os CountDownTimer CountDownTimer.

Prototype

public CountDownTimer(long millisInFuture, long countDownInterval) 

Source Link

Usage

From source file:com.caseystalnaker.android.popinvideodemo.fragments.Camera2VideoFragment.java

private void startCountdownTimer() {
    mCountdownTimerWrapper.setVisibility(LinearLayout.VISIBLE);
    mCountdownTimer = new CountDownTimer(Utils.VIDEO_TIME_LIMIT, 1000) {

        public void onTick(long millisUntilFinished) {
            mCountdownText.setText("" + String.format(Utils.COUNTDOWN_TIMER_FORMAT,
                    TimeUnit.MILLISECONDS.toHours(millisUntilFinished),
                    TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)
                            - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millisUntilFinished)),
                    TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES
                            .toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))));
        }/*from   www. ja va  2 s. c  om*/

        public void onFinish() {
            stopRecordingVideo(true);
        }
    }.start();

}

From source file:com.amaze.filemanager.utils.files.FileUtils.java

public static void openFile(final File f, final MainActivity m, SharedPreferences sharedPrefs) {
    boolean useNewStack = sharedPrefs.getBoolean(PreferencesConstants.PREFERENCE_TEXTEDITOR_NEWSTACK, false);
    boolean defaultHandler = isSelfDefault(f, m);
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(m);
    final Toast[] studioCount = { null };

    if (f.getName().toLowerCase().endsWith(".apk")) {
        GeneralDialogCreation.showPackageDialog(f, m);
    } else if (defaultHandler && CompressedHelper.isFileExtractable(f.getPath())) {
        GeneralDialogCreation.showArchiveDialog(f, m);
    } else if (defaultHandler && f.getName().toLowerCase().endsWith(".db")) {
        Intent intent = new Intent(m, DatabaseViewerActivity.class);
        intent.putExtra("path", f.getPath());
        m.startActivity(intent);//from w  w w.java  2s . co m
    } else if (Icons.getTypeOfFile(f.getPath(), f.isDirectory()) == Icons.AUDIO) {
        final int studio_count = sharedPreferences.getInt("studio", 0);
        Uri uri = Uri.fromFile(f);
        final Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "audio/*");

        // Behold! It's the  legendary easter egg!
        if (studio_count != 0) {
            new CountDownTimer(studio_count, 1000) {
                @Override
                public void onTick(long millisUntilFinished) {
                    int sec = (int) millisUntilFinished / 1000;
                    if (studioCount[0] != null)
                        studioCount[0].cancel();
                    studioCount[0] = Toast.makeText(m, sec + "", Toast.LENGTH_LONG);
                    studioCount[0].show();
                }

                @Override
                public void onFinish() {
                    if (studioCount[0] != null)
                        studioCount[0].cancel();
                    studioCount[0] = Toast.makeText(m, m.getString(R.string.opening), Toast.LENGTH_LONG);
                    studioCount[0].show();
                    m.startActivity(intent);
                }
            }.start();
        } else
            m.startActivity(intent);
    } else {
        try {
            openunknown(f, m, false, useNewStack);
        } catch (Exception e) {
            Toast.makeText(m, m.getString(R.string.noappfound), Toast.LENGTH_LONG).show();
            openWith(f, m, useNewStack);
        }
    }
}

From source file:com.google.android.apps.santatracker.map.SantaMapActivity.java

/**
 * Call when Santa is to visit a location.
 *//* w w  w .j av a 2  s.  c om*/
private void visitDestination(final Destination destination, boolean playSound) {

    // Only visit this location if there is a following destination
    // Otherwise out of data or at North Pole
    if (mDestinations.isLast()) {
        // App Measurement
        MeasurementManager.recordCustomEvent(mMeasurement, getString(R.string.analytics_event_category_tracker),
                getString(R.string.analytics_tracker_action_error),
                getString(R.string.analytics_tracker_error_nodata));

        // [ANALYTICS EVENT]: Error NoData
        AnalyticsManager.sendEvent(R.string.analytics_event_category_tracker,
                R.string.analytics_tracker_action_error, R.string.analytics_tracker_error_nodata);

        Toast.makeText(this, R.string.lost_contact_with_santa, Toast.LENGTH_LONG).show();
        returnToStartupActivity();
        return;
    }

    Destination nextDestination = mDestinations.getPeekNext();
    SantaLog.d(TAG, "Arrived: " + destination.identifier + " current=" + mDestinations.getCurrent().identifier
            + " next = " + nextDestination + " next id=" + nextDestination);

    // hand out the remaining presents for this location, explicit to ensure counter is always
    // in correct state and does not depend on anything else at runtime.
    final long presentsStart = destination.presentsDelivered - destination.presentsDeliveredAtDestination
            + Math.round((destination.presentsDeliveredAtDestination) * (1.0f - FACTOR_PRESENTS_TRAVELLING));
    mPresents.init(presentsStart, destination.presentsDelivered, destination.arrival, destination.departure);

    final String destinationString = DashboardFormats.formatDestination(destination);
    setCurrentLocation(destinationString);

    mMapFragment.setSantaVisiting(destination, playSound);

    // Notify dashboard to send accessibility event
    AccessibilityUtil.announceText(String.format(ANNOUNCE_ARRIVED_AT, destination.getPrintName()),
            mRecyclerView, mAccessibilityManager);

    // cancel the countdown if it is already running
    if (mTimer != null) {
        mTimer.cancel();
    }

    // Count down until departure
    mTimer = new CountDownTimer(destination.departure - SantaPreferences.getCurrentTime(),
            DESTINATION_COUNTDOWN_UPDATEINTERVAL) {

        @Override
        public void onTick(long millisUntilFinished) {
            countdownTick(millisUntilFinished);
        }

        @Override
        public void onFinish() {
            // finished at this destination, move to the next one
            travelToDestination(mDestinations.getCurrent(), mDestinations.getNext());
        }

    };
    if (mResumed) {
        mTimer.start();
    }
}

From source file:com.cairoconfessions.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == 1) {
        String confession = data.getExtras().get("result").toString();
        String desc = data.getExtras().get("desc").toString();
        final View newConfess = addConfession(confession, desc);
        newConfess.findViewById(R.id.undoPost).setVisibility(View.VISIBLE);
        newConfess.findViewById(R.id.undoPost).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                ((LinearLayout) newConfess.getParent()).removeView(newConfess);
            }//w  ww  .  ja v  a 2s  .c  o m
        });
        new CountDownTimer(12000, 1000) {

            public void onTick(long millisUntilFinished) {
                ((TextView) newConfess.findViewById(R.id.undoPost))
                        .setText("Undo(" + ((millisUntilFinished / 1000) - 1) + ")");
            }

            public void onFinish() {
                newConfess.findViewById(R.id.undoPost).setVisibility(View.GONE);
            }
        }.start();
    }

}

From source file:com.amaze.carbonfilemanager.utils.files.Futils.java

public void openFile(final File f, final MainActivity m) {
    boolean defaultHandler = isSelfDefault(f, m);
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(m);
    if (defaultHandler && f.getName().toLowerCase().endsWith(".zip")
            || f.getName().toLowerCase().endsWith(".jar") || f.getName().toLowerCase().endsWith(".rar")
            || f.getName().toLowerCase().endsWith(".tar") || f.getName().toLowerCase().endsWith(".tar.gz")) {
        GeneralDialogCreation.showArchiveDialog(f, m);
    } else if (f.getName().toLowerCase().endsWith(".apk")) {
        GeneralDialogCreation.showPackageDialog(f, m);
    } else if (defaultHandler && f.getName().toLowerCase().endsWith(".db")) {
        Intent intent = new Intent(m, DbViewer.class);
        intent.putExtra("path", f.getPath());
        m.startActivity(intent);/*from w  w w . ja v a  2  s  . c o m*/
    } else if (Icons.isAudio(f.getPath())) {
        final int studio_count = sharedPreferences.getInt("studio", 0);
        Uri uri = Uri.fromFile(f);
        final Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "audio/*");

        // Behold! It's the  legendary easter egg!
        if (studio_count != 0) {
            new CountDownTimer(studio_count, 1000) {
                @Override
                public void onTick(long millisUntilFinished) {
                    int sec = (int) millisUntilFinished / 1000;
                    if (studioCount != null)
                        studioCount.cancel();
                    studioCount = Toast.makeText(m, sec + "", Toast.LENGTH_LONG);
                    studioCount.show();
                }

                @Override
                public void onFinish() {
                    if (studioCount != null)
                        studioCount.cancel();
                    studioCount = Toast.makeText(m, m.getString(R.string.opening), Toast.LENGTH_LONG);
                    studioCount.show();
                    m.startActivity(intent);
                }
            }.start();
        } else
            m.startActivity(intent);
    } else {
        try {
            openunknown(f, m, false);
        } catch (Exception e) {
            Toast.makeText(m, m.getResources().getString(R.string.noappfound), Toast.LENGTH_LONG).show();
            openWith(f, m);
        }
    }
}

From source file:com.wizardsofm.deskclock.alarms.AlarmActivity.java

void listenForCommand() {

    //        if (speech == null) {
    //            speech = SpeechRecognizer.createSpeechRecognizer(this);
    //            speech.setRecognitionListener(MainActivity.this);
    //        }//w  w  w. j a v a2  s . c o m
    //        speech = SpeechRecognizer.createSpeechRecognizer(this);
    //        speech.setRecognitionListener(this);

    i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say something");
    //        i.putExtra("android.speech.extra.DICTATION_MODE", true);
    //        i.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
    i.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 5000);
    try {
        startActivityForResult(i, 100);

        new CountDownTimer(5000, 1000) {

            public void onTick(long millisUntilFinished) {
                //do nothing, just let it tick
            }

            public void onFinish() {
                if (!alarmStopped) {
                    listenForCommand();
                }
            }
        }.start();

        //            speech.startListening(i);
    } catch (Exception e) {

    }
}

From source file:com.amaze.filemanager.utils.Futils.java

public void openFile(final File f, final MainActivity m) {
    boolean defaultHandler = isSelfDefault(f, m);
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(m);
    if (defaultHandler && f.getName().toLowerCase().endsWith(".zip")
            || f.getName().toLowerCase().endsWith(".jar") || f.getName().toLowerCase().endsWith(".rar")
            || f.getName().toLowerCase().endsWith(".tar") || f.getName().toLowerCase().endsWith(".tar.gz")) {
        showArchiveDialog(f, m);/*  w ww.j  a va  2  s  . co  m*/
    } else if (f.getName().toLowerCase().endsWith(".apk")) {
        showPackageDialog(f, m);
    } else if (defaultHandler && f.getName().toLowerCase().endsWith(".db")) {
        Intent intent = new Intent(m, DbViewer.class);
        intent.putExtra("path", f.getPath());
        m.startActivity(intent);
    } else if (Icons.isAudio(f.getPath())) {
        final int studio_count = sharedPreferences.getInt("studio", 0);
        Uri uri = Uri.fromFile(f);
        final Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "audio/*");

        if (studio_count != 0) {
            new CountDownTimer(studio_count, 1000) {
                @Override
                public void onTick(long millisUntilFinished) {
                    int sec = (int) millisUntilFinished / 1000;
                    if (studioCount != null)
                        studioCount.cancel();
                    studioCount = Toast.makeText(m, sec + "", Toast.LENGTH_LONG);
                    studioCount.show();
                }

                @Override
                public void onFinish() {
                    if (studioCount != null)
                        studioCount.cancel();
                    studioCount = Toast.makeText(m, "Opening..", Toast.LENGTH_LONG);
                    studioCount.show();
                    m.startActivity(intent);
                }
            }.start();
        } else
            m.startActivity(intent);
    } else {
        try {
            openunknown(f, m, false);
        } catch (Exception e) {
            Toast.makeText(m, getString(m, R.string.noappfound), Toast.LENGTH_LONG).show();
            openWith(f, m);
        }
    }
}

From source file:com.wizardsofm.deskclock.alarms.AlarmActivity.java

public void keepListening() {
    countDownTimer = new CountDownTimer(8000, 1000) {

        public void onTick(long millisUntilFinished) {
            //do nothing, just let it tick
        }//  www. ja v a  2s. c  om

        public void onFinish() {
            if (resumeCounting) {
                speech.cancel();
                speech.startListening(intent);
                keepListening();
            }
        }
    };

    countDownTimer.start();
}

From source file:org.cm.podd.report.activity.ReportActivity.java

private void startLocationSearchTimeoutCountdown() {
    countdownTextView.setText("30");
    progressBar.setVisibility(View.VISIBLE);

    ct = new CountDownTimer(30000, 1000) {
        public void onTick(long millisUntilFinished) {
            countdownTextView.setText(Long.toString(millisUntilFinished / 1000));
            if (millisUntilFinished < 15000) {
                textProgressLocationView.setText(R.string.unavailable_location_signal_text);
            }/* w  w w .  ja v a2 s  .  c  o m*/
        }

        public void onFinish() {
            countdownTextView.setText("0");
            textProgressLocationView.setText(R.string.gps_location_not_found);
            refreshLocationButton.setVisibility(View.VISIBLE);
            progressBar.setVisibility(View.GONE);
        }
    }.start();
}

From source file:com.birdeye.MainActivity.java

public void initateCounter(int timer) {

    // 900000 15 min
    new CountDownTimer(timer, 1000) { // adjust the milli seconds here
        public void onTick(long millisUntilFinished) {

            Log.e("millisUntilFinished", "" + millisUntilFinished);
            String pausedTimerValue = "" + millisUntilFinished;

            String timerText = "The app closes in "
                    + String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished),
                            TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES
                                    .toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)))
                    + " you can remove shut off timer by upgrading for only & $2.99 ";

            tv_cancel.setText(timerText + Html.fromHtml("<p><u>SUBSCRIBE</u></p>"));
            tv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override/* ww w  .  ja v a  2s  . c  o  m*/
                public void onClick(View v) {
                    removeAdsDialog();
                }
            });
            // tv_cancel.setText(timerText);
        }

        public void onFinish() {
            if (!Globals.hasPaid) {
                enabled.setChecked(false);
                enable(false);
                enabled.setChecked(false);
                initial(false);
                MainActivity.this.finish();
                System.exit(0);
                if (SharedPref.get_savedCards1(MainActivity.this).equalsIgnoreCase("true")) {
                }
            }
        }
    }.start();
}