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.mjhram.ttaxi.GpsMainActivity.java

private void startCounter(int counterTimer) {
    countDownTimer = new CountDownTimer(counterTimer * 1000, 1000) {
        public void onTick(long millisUntilFinished) {
            long minutes = (millisUntilFinished) / (60 * 1000);
            long seconds = (millisUntilFinished / 1000) % 60;
            //String timeString = String.format("%02d:%02d", minutes, seconds);
            btnPickDrop.setText(getString(R.string.gpsMainBtnCancel, minutes, seconds));
        }/*w  w  w . ja  v  a2s .  c o m*/

        public void onFinish() {
            //cancel the T-request
            cancelTRequest(Constants.TRequest_Expired);
            /*//remove the T-request
            pickdropState=0;
            btnPickDrop.setText("Pick From...");
            UploadClass upload = new UploadClass(GpsMainActivity.this);
            if(AppSettings.requestId != -1) {
                upload.setTRequestState(Integer.toString(AppSettings.requestId), AppSettings.TRequest_Expired);
                AppSettings.requestId = -1;
            }*/
            //setTRequestState(selectedTRequest.idx, selectedTRequest.passanger_id, AppSettings.TRequest_Assigned, AppSettings.getUid());
        }
    }.start();
}

From source file:com.almalence.opencam.ApplicationScreen.java

@Override
public void surfaceChanged(final SurfaceHolder holder, final int format, final int width, final int height) {
    if (!cameraPermissionGranted || !storagePermissionGranted)
        return;/*from  w  ww  . ja v a  2s.  c om*/

    Log.e("ApplicationScreen", "SURFACE CHANGED");
    mCameraSurface = holder.getSurface();

    if (isCameraConfiguring) {
        ApplicationScreen.getPluginManager().sendMessage(ApplicationInterface.MSG_SURFACE_CONFIGURED, 0);
        isCameraConfiguring = false;
    } else {
        new CountDownTimer(50, 50) {
            public void onTick(long millisUntilFinished) {
                // Not used
            }

            public void onFinish() {
                if (!ApplicationScreen.instance.mPausing && surfaceCreated
                        && (!CameraController.isCameraCreated())) {
                    ApplicationScreen.instance.findViewById(R.id.mainLayout2).setVisibility(View.VISIBLE);
                    if (!CameraController.isRemoteCamera()) {
                        if (!CameraController.isUseCamera2()) {
                            CameraController.setupCamera(holder, true);
                        } else
                            messageHandler.sendEmptyMessage(ApplicationInterface.MSG_SURFACE_READY);
                    } else {
                        // Sony camera
                    }
                }
            }
        }.start();
    }
}

From source file:com.yaniv.online.MainActivity.java

private void yanivCalled(byte[] buf) {

    boolean isGameFinished = false;

    String loser = "";

    // if a yaniv was called
    if (buf[2] == 0) {

        for (int i = 0; i < mParticipants.size(); i++) {
            if (i != buf[1]) {
                highscores[i] += getPlayerScore(mParticipants.get(i));
                if (highscores[i] == 100) {
                    highscores[i] = 50;/*from w  ww . j  a v a2 s .  c o  m*/
                } else if (highscores[i] > 100) {
                    isGameFinished = true;
                    loser += mParticipants.get(i).getDisplayName() + " lost with " + highscores[i] + " points."
                            + System.getProperty("line.separator");
                }
            }
        }
    }
    // if an asaf was called
    else {
        ArrayList<Integer> asafArray = new ArrayList<>();
        for (int i = 0; i < buf[2]; i++) {
            asafArray.add((int) buf[2 + i + 1]);
        }
        for (int i = 0; i < mParticipants.size(); i++) {
            if (i == buf[1]) {
                highscores[i] += getPlayerScore(mParticipants.get(i)) + 30;
                if (highscores[i] == 100) {
                    highscores[i] = 50;
                } else if (highscores[i] > 100) {
                    isGameFinished = true;
                    loser += mParticipants.get(i).getDisplayName() + " lost with " + highscores[i] + " points."
                            + System.getProperty("line.separator");

                }
            } else if (!asafArray.contains(i)) {
                highscores[i] += getPlayerScore(mParticipants.get(i));
                if (highscores[i] == 100) {
                    highscores[i] = 50;
                } else if (highscores[i] > 100) {
                    isGameFinished = true;
                    loser += mParticipants.get(i).getDisplayName() + " lost with " + highscores[i] + " points."
                            + System.getProperty("line.separator");
                }
            }
        }
    }

    updateParticipantsCardsOnGameOverUI();

    String winner = "";
    switch (buf[2]) {
    case 0:
        winner = "The winner is: " + mParticipants.get(buf[3]).getDisplayName() + "!";
        break;
    case 1:
        winner = "ASAF!!! the winner is: " + mParticipants.get(buf[3]).getDisplayName() + "!";
        break;
    case 2:
        winner = "ASAF!!! the winners are: " + mParticipants.get(buf[3]).getDisplayName() + ","
                + System.getProperty("line.separator") + mParticipants.get(buf[4]).getDisplayName() + "!";
        break;
    case 3:
        winner = "ASAF!!! the winners are: " + mParticipants.get(buf[3]).getDisplayName() + ","
                + System.getProperty("line.separator") + mParticipants.get(buf[4]).getDisplayName() + ","
                + System.getProperty("line.separator") + mParticipants.get(buf[5]).getDisplayName() + "!";
        break;
    }

    if (isGameFinished) {
        winner += System.getProperty("line.separator") + loser;
    }

    new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Game Over")
            .setMessage(winner).show();

    final TextView timer = (TextView) (findViewById(R.id.countDownTimer));
    final Button readyButton = (Button) (findViewById(R.id.Ready));
    if (isGameFinished) {
        timer.setText("The game is finished.");
        timer.setVisibility(View.VISIBLE);
    } else {
        timer.setText("New game starts in: 30 seconds");
        timer.setVisibility(View.VISIBLE);
        readyButton.setVisibility(View.VISIBLE);

        cdt = new CountDownTimer(30000, 1000) {

            public void onTick(long millisUntilFinished) {
                timer.setText("New game starts in: " + millisUntilFinished / 1000 + " seconds"
                        + System.getProperty("line.separator") + "or when everyone is ready.");
                if (readyToStartGame) {
                    onFinish();
                    cdt.cancel();
                }
            }

            public void onFinish() {
                cancelTimer();
                timer.setVisibility(View.GONE);
                readyButton.setVisibility(View.GONE);
                onRoomConnected(mStatusCode, mRoom);
            }
        }.start();
    }
}

From source file:com.almalence.opencam.ApplicationScreen.java

protected void onCameraConfigured() {
    ApplicationScreen.getPluginManager().setupCameraParameters();

    if (!CameraController.isRemoteCamera()) {
        if (!CameraController.isUseCamera2()) {
            Camera.Parameters cp = CameraController.getCameraParameters();
            try {
                // Nexus 5 is giving preview which is too dark without this
                if (CameraController.isNexus5) {
                    cp.setPreviewFpsRange(7000, 30000);
                    CameraController.setCameraParameters(cp);
                    cp = CameraController.getCameraParameters();
                }/*from w  w  w  . j av a  2  s . c om*/
            } catch (RuntimeException e) {
                Log.d("ApplicationScreen",
                        "ApplicationScreen.onCameraConfigured() unable to setParameters " + e.getMessage());
            }

            if (cp != null) {
                SharedPreferences prefs = PreferenceManager
                        .getDefaultSharedPreferences(ApplicationScreen.getMainContext());
                int antibanding = Integer.parseInt(prefs.getString(ApplicationScreen.sAntibandingPref, "3"));
                switch (antibanding) {
                case 0:
                    cp.setAntibanding("off");
                    break;
                case 1:
                    cp.setAntibanding("50hz");
                    break;
                case 2:
                    cp.setAntibanding("60hz");
                    break;
                case 3:
                    cp.setAntibanding("auto");
                    break;
                default:
                    cp.setAntibanding("auto");
                    break;
                }
                CameraController.setCameraParameters(cp);

                previewWidth = cp.getPreviewSize().width;
                previewHeight = cp.getPreviewSize().height;
            }
        }

        try {
            Util.initialize(mainContext);
            Util.initializeMeteringMatrix();
        } catch (Exception e) {
            Log.e("Main setup camera", "Util.initialize failed!");
        }

        prepareMeteringAreas();

        if (!CameraController.isUseCamera2()) {
            guiManager.onCameraCreate();
            ApplicationScreen.getPluginManager().onCameraParametersSetup();
            guiManager.onPluginsInitialized();
        }
    } else {
        guiManager.onCameraCreate();
        ApplicationScreen.getPluginManager().onCameraParametersSetup();
        guiManager.onPluginsInitialized();
    }

    // ----- Start preview and setup frame buffer if needed

    // call camera release sequence from onPause somewhere ???
    new CountDownTimer(10, 10) {
        @Override
        public void onFinish() {
            if (!CameraController.isRemoteCamera()) {
                if (!CameraController.isUseCamera2()) {
                    if (!CameraController.isCameraCreated())
                        return;
                    // exceptions sometimes happen here when resuming after
                    // processing
                    try {
                        CameraController.startCameraPreview();
                    } catch (RuntimeException e) {
                        e.printStackTrace();
                        Toast.makeText(ApplicationScreen.instance, "Unable to start camera", Toast.LENGTH_LONG)
                                .show();
                        return;
                    }

                    CameraController.setPreviewCallbackWithBuffer();
                } else {
                    guiManager.onCameraCreate();
                    ApplicationScreen.getPluginManager().onCameraParametersSetup();
                    guiManager.onPluginsInitialized();
                }
            } else {
                guiManager.onCameraCreate();
                ApplicationScreen.getPluginManager().onCameraParametersSetup();
                guiManager.onPluginsInitialized();
            }

            ApplicationScreen.getPluginManager().onCameraSetup();
            guiManager.onCameraSetup();
            ApplicationScreen.mApplicationStarted = true;

            if (ApplicationScreen.isForceClose)
                ApplicationScreen.getPluginManager().sendMessage(ApplicationInterface.MSG_APPLICATION_STOP, 0);
        }

        @Override
        public void onTick(long millisUntilFinished) {
            // Not used
        }
    }.start();
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void endshiftCode() {
    pdialog = ProgressDialog.show(HomeScreen.this, "Please wait", "Ending shift ...", true);

    //send end shift code
    send_event("93");

    ToastMessage.displayToastFromResource(HomeScreen.this, 5, Gravity.CENTER,
            (ViewGroup) findViewById(R.id.toast_layout_root));

    //if tour module installed then clear out any current tour
    if (GTConstants.isTour) {
        //if tour started but not completed write to the trp file
        //touritemNumber > 0 indicates that at least one tag has been scanned
        if (GTConstants.trpfilename.length() > 1 && touritemNumber >= 0)
            endtrpFile(false);//  w  ww  .  j  a v a 2  s .c o  m
        else
            cleantourInfo();
    }

    //write to dar, transfer file to send directory
    Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.darfileName,
            "End shift;" + GTConstants.currentBatteryPercent + ";" + Utility.getLocalTime() + ";"
                    + Utility.getLocalDate() + "\r\n",
            true);

    //write the event 19 information to the file
    String GM = Utility.getHeaderMessage("$GM") + ",19," + getCellID();
    Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.darfileName,
            GM + "\r\n", true);

    //give time for file write before moving file
    Utility.initializeGeneralTimer(2000);
    do {
        Utility.Sleep(1000);
    } while (!Utility.fileAccessComplete() && !Utility.getgeneraltimerFlag());

    //move the dar file to the send file folder 
    File from = new File(GTConstants.dardestinationFolder, GTConstants.darfileName);

    //change the file name to match the $GM time and date
    String parse[] = GM.split(",");
    String newFile = GTConstants.LICENSE_ID.substring(7) + "_" + parse[10] + "_" + parse[2] + ".dar";

    File to = new File(GTConstants.sendfileFolder, newFile);
    from.renameTo(to);

    //write to srp file
    if (GTConstants.srpfileName.length() > 1) {
        Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.srpfileName,
                "End account;" + GTConstants.accountName + ";" + Utility.getLocalTime() + ";"
                        + Utility.getLocalDate() + "\r\n",
                true);

        //write the event 19 information to the file
        GM = Utility.getHeaderMessage("$GM") + ",19," + getCellID();
        Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.srpfileName,
                GM + "\r\n", true);

        //give time for file write before moving file
        Utility.initializeGeneralTimer(2000);
        do {
            Utility.Sleep(100);
        } while (!Utility.fileAccessComplete() && !Utility.getgeneraltimerFlag());

        //move the srp file to the send file folder 
        from = new File(GTConstants.dardestinationFolder, GTConstants.srpfileName);

        //change the file name to match the $GM time and date
        String _parse[] = GM.split(",");
        newFile = GTConstants.LICENSE_ID.substring(7) + "_" + _parse[10] + "_" + _parse[2] + "_srp.srp";

        to = new File(GTConstants.sendfileFolder, newFile);
        from.renameTo(to);

        //end account
        GTConstants.srpfileName = " ";
        GTConstants.accountID = "";
        GTConstants.accountName = "";
    }
    //set flag for sending
    Utility.setUploadAvailable();

    //pause the GPS location service after ending a shift
    MainService.pauseLocationListener();

    //wait for end shift string to reach server (or timeout occurs) before dismissing wait dialog
    new CountDownTimer(5000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            if (!GTConstants.sendData) {
                //pdialog.dismiss();
            }
        }

        @Override
        public void onFinish() {
            if (!(pdialog == null)) {
                pdialog.dismiss();

                //set spinner back to start shift
                spinner.setSelection(0);

                //clear the warning text window
                setwarningText("");

                //set the current state
                Utility.setcurrentState(GTConstants.offShift);
                setuserBanner();

                btn_send.setEnabled(true);

                if (Utility.getpostorderAvailable()) {
                    restartsyncTimer = true;
                    showAlert("Sync Update", "Update of sync file required", true);
                }
            }
        }
    }.start();
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void doCountdown() {
    mCountdownStarted = true;//from  w w w. j  av  a  2  s .c om
    mPlayPauseButton.setEnabled(false);
    // Start the countdown
    if (mCountdown == null) {
        mCountdown = (TextView) findViewById(R.id.countdown_text);
    }
    mCountdown.setVisibility(View.VISIBLE);
    mCountdown.setTextColor(Color.WHITE);
    mCountdown.setText("3");
    mCountDownTimer = new CountDownTimer(3500, 100) {
        @Override
        public void onTick(long millisUntilFinished) {
            int time = (int) ((millisUntilFinished + 500) / 1000);
            if (time == 3) {
                mCountdown.setText("3");
            } else if (time == 2) {
                mCountdown.setText("2");
            } else if (time == 1) {
                mCountdown.setText("1");
            } else if (time == 0) {
                mCountdown.setText("Go!");
            }
        }

        @Override
        public void onFinish() {
            mCountdownStarted = false;
            mPlayPauseButton.setEnabled(true);
            play();
            mCountdown.setVisibility(View.GONE);
        }
    };
    mCountDownTimer.start();
}

From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java

@Override
public void onPress(final int primaryCode) {
    setVibration();//w ww  .  j  a  va 2 s  . c  o  m

    final InputConnection ic = getCurrentInputConnection();

    if (popupKeypress && (primaryCode == 32 || primaryCode == 126 || primaryCode == -5 || primaryCode == -1
            || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_1
            || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_2
            || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_3
            || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_4
            || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_5)) {

        kv.setPreviewEnabled(false);
    }

    if (oppositeCase) {
        timer = new CountDownTimer(300, 1) {
            @Override
            public void onTick(long millisUntilFinished) {

            }

            @Override
            public void onFinish() {
                if (!swipe) {
                    if (primaryCode == 46) {
                        ic.commitText(",", 1);

                        printedCommaa = true;

                        if (autoSpacing) {
                            ic.commitText(" ", 1);
                        }
                    } else if (primaryCode == 32) {
                        Intent intent = new Intent(getApplicationContext(), Home.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                    } else if (primaryCode == -5) {
                        if (voiceInput) {
                            if (mVoiceRecognitionTrigger.isInstalled()) {
                                mVoiceRecognitionTrigger.startVoiceRecognition();
                            }
                        }
                    } else {
                        char code = (char) primaryCode;

                        if (Character.isLetter(code) && caps) {
                            code = Character.toLowerCase(code);
                        } else if (Character.isLetter(code) && !caps) {
                            code = Character.toUpperCase(code);
                        }

                        ic.commitText(String.valueOf(code), 1);
                    }

                    printedDifferent = true;
                }
            }
        }.start();
    }

    if (spaceDot) {
        if (primaryCode == 32) {
            doubleSpace++;

            if (doubleSpace == 2) {
                ic.deleteSurroundingText(1, 0);
                ic.commitText(".", 1);

                if (autoSpacing) {
                    ic.commitText(" ", 1);
                }

                printedDot = true;
                doubleSpace = 0;
            } else {
                printedDot = false;
            }
        } else {
            printedDot = false;
            doubleSpace = 0;
        }
    }
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

private void startRecording() {
    //      Camera camera = CameraController.getCamera();
    //      if (null == camera)
    //         return;

    filesList = new ArrayList<File>();
    documentFilesList = new ArrayList<DocumentFile>();

    fileSaved = null;/*from   w  ww . j a  v a2 s . c o m*/
    documentFileSaved = null;

    if (shutterOff)
        return;

    stopRotateAnimation();

    if (!swChecked) {
        // RotateImageView additionalButton = (RotateImageView)
        // ApplicationScreen.instance.guiManager.getMainView().findViewById(R.id.buttonShutterAdditional);
        RotateImageView buttonSelectMode = (RotateImageView) ApplicationScreen.instance.guiManager.getMainView()
                .findViewById(R.id.buttonSelectMode);

        // additionalButton.setVisibility(View.VISIBLE);
        buttonSelectMode.setVisibility(View.GONE);
    }

    modeSwitcher.setVisibility(View.GONE);
    if (this.modeDRO()) {
        shutterOff = true;
        mRecordingStartTime = SystemClock.uptimeMillis();

        ApplicationScreen.getGUIManager().lockControls = true;
        // inform the user that recording has stopped
        isRecording = true;
        onPause = false;

        showRecordingUI(isRecording);
        PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext()).edit()
                .putBoolean("videorecording", true).commit();

        this.droEngine.startRecording(getOutputMediaFile().toString(), 300);

        new CountDownTimer(1000, 1000) {
            public void onTick(long millisUntilFinished) {
            }

            public void onFinish() {
                shutterOff = false;
                // ApplicationScreen.getGUIManager().lockControls = false;
            }
        }.start();
    } else {
        this.startVideoRecording();
    }

    View mainButtonsVideo = (View) ApplicationScreen.instance.guiManager.getMainView()
            .findViewById(R.id.mainButtonsVideo);
    mainButtonsVideo.setVisibility(View.VISIBLE);

    View mainButtons = (View) ApplicationScreen.instance.guiManager.getMainView()
            .findViewById(R.id.mainButtons);
    mainButtons.setVisibility(View.INVISIBLE);

    // change shutter icon
    pauseVideoButton.setVisibility(View.VISIBLE);
    pauseVideoButton.setImageDrawable(
            ApplicationScreen.getAppResources().getDrawable(R.drawable.plugin_capture_video_pause));

    ApplicationScreen.instance.setKeepScreenOn(true);
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

private void startVideoRecording() {
    shutterOff = true;//from  w w  w  . ja va 2s.c  o m
    mRecordingStartTime = SystemClock.uptimeMillis();

    CameraController.stopCameraPreview();
    prepareMediaRecorder();
    if (CameraController.isUseCamera2())
        CameraController.startCameraPreview();

    try {
        if (preferenceVideoMuteMode)
            muteAllSounds();

        // Camera is available and unlocked, MediaRecorder is prepared,
        // now you can start recording
        mMediaRecorder.start();
        ApplicationScreen.getGUIManager().lockControls = true;

    } catch (Exception e) {
        Log.d("Video", "Exception preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        Toast.makeText(ApplicationScreen.instance, "Failed to start video recording", Toast.LENGTH_LONG).show();

        ApplicationScreen.getGUIManager().lockControls = false;
        PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
                ApplicationInterface.MSG_CONTROL_UNLOCKED);
        CameraController.lockCamera(); // take camera access back from MediaRecorder
        CameraController.stopCameraPreview();
        CameraController.startCameraPreview();

        if (preferenceVideoMuteMode)
            unmuteAllSounds();

        return;
    }

    // inform the user that recording has started
    isRecording = true;
    showRecordingUI(isRecording);
    if (onPause) {
        onPause = false;
        showRecordingUI(isRecording);
        onPause = true;
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext());
    prefs.edit().putBoolean("videorecording", true).commit();

    new CountDownTimer(1000, 1000) {
        public void onTick(long millisUntilFinished) {
        }

        public void onFinish() {
            shutterOff = false;
            // ApplicationScreen.getGUIManager().lockControls = false;
        }
    }.start();
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

private void blinkPause() {
    if (!onPause) {
        return;//from w ww  .j a v a  2s.c  o  m
    }

    new CountDownTimer(500, 500) {
        public void onTick(long millisUntilFinished) {
        }

        public void onFinish() {
            blinkPause();
        }
    }.start();

    if (pauseBlink) {
        pauseVideoButton.setImageDrawable(ApplicationScreen.getAppResources()
                .getDrawable(R.drawable.plugin_capture_video_pause_transparent));
        pauseBlink = false;
    } else {
        pauseVideoButton.setImageDrawable(
                ApplicationScreen.getAppResources().getDrawable(R.drawable.plugin_capture_video_pause));
        pauseBlink = true;
    }
}