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.achie.tv.ShowImageGrid.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;

    mImageManager = ImageManager.getInstance(mContext);

    try {//from w ww . j a  va 2  s .  c o m
        handleIntent(getIntent());
        startSearch();
    } catch (final IOException e) {
        e.printStackTrace();
    } catch (final URISyntaxException e) {
        e.printStackTrace();
    } catch (final JSONException e) {
        e.printStackTrace();
    }

    if (!isSplashShown) {
        setContentView(R.layout.splash_screen);
        isSplashShown = true;
        CountDownTimer timer = new CountDownTimer(3000, 1000) {
            public void onTick(long millisUntilFinished) {
            }

            public void onFinish() {
                //startSearch();
                //initGridView();
            }
        }.start();
    } else {
        //initGridView();
        //startSearch();
    }
}

From source file:com.ibm.mil.readyapps.summit.views.AutoInfiniteViewPager.java

@Override
public void setAdapter(PagerAdapter adapter) {
    super.setAdapter(adapter);

    this.pages = this.getAdapter().getCount();
    this.currentPage = super.getCurrentItem();

    this.mTouchListener = new AutoInfiniteTouchListener(this);
    super.setOnTouchListener(mTouchListener);

    this.mPageListener = new AutoInfinitePageChangeListener(this);
    super.setOnPageChangeListener(mPageListener);

    this.pagesDidMove = false;

    // Define new abstract class CountDownTimer inline
    this.mTimer = new CountDownTimer(AUTO_PAGE_TIME_MS, AUTO_PAGE_TIME_MS) {

        @Override// ww w  .  j  a  v  a  2s . co m
        public void onTick(long millisUntilFinished) {
            // Nothing to do on tick...
        }

        @Override
        public void onFinish() {
            nextPage();
        }
    };

    // Start timer
    this.mTimer.start();
}

From source file:com.perm.DoomPlay.SleepDialog.java

private void enableSpleep(int time, int tracks) {

    if (time != 0) {
        disableTime();//from  ww  w  .  j a v  a 2s.  c om
        timer = new CountDownTimer((long) time * 60000, 10000000) {
            @Override
            public void onTick(long millisUntilFinished) {
            }

            @Override
            public void onFinish() {
                MyApplication.getInstance().sendBroadcast(new Intent(AbstractReceiver.actionKill));
                disableTracks();
            }
        };
        timer.start();
    }

    if (tracks != 0) {
        PlayingService.setSleepTrack(tracks);
    } else
        disableTracks();
}

From source file:com.learnit.LearnIt.activities.EditWord.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.edit_menu_cancel:
        finishActivity();//from w  w w .j  a  v a  2 s.  c  o m
        return true;
    case R.id.edit_menu_done:
        Log.d(LOG_TAG,
                "update word = " + edtWord.getText().toString() + " trans = " + edtTrans.getText().toString());
        if (StringUtils.isStringEmpty(edtWord.getText().toString())
                || StringUtils.isStringEmpty(edtTrans.getText().toString())) {
            Crouton.makeText(this, getString(R.string.crouton_empty_input), Style.ALERT).show();
        } else {
            dbHelper.deleteWord(oldWord);
            int exitCode = dbHelper.writeToDB(edtWord.getText().toString(), edtTrans.getText().toString());
            if (exitCode == DBHelper.EXIT_CODE_OK) {
                Crouton.makeText(this, getString(R.string.crouton_word_saved, edtWord.getText().toString()),
                        Style.CONFIRM).show();
            } else if (exitCode == DBHelper.EXIT_CODE_WORD_ALREADY_IN_DB) {
                Crouton.makeText(this,
                        getString(R.string.crouton_word_already_present, edtWord.getText().toString()),
                        Style.ALERT).show();
            }
            // TODO: this code is shitty. Rewrite when have time.
            new CountDownTimer(2000, 2000) {

                public void onTick(long millisUntilFinished) {
                }

                public void onFinish() {
                    finishActivity();
                }
            }.start();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.barcamppenang2013.tabfragment.HomeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (scrollView != null) {
        ViewGroup parent = (ViewGroup) scrollView.getParent();
        if (parent != null)
            parent.removeView(scrollView);
    }/* ww w  . java2 s . c om*/
    scrollView = (ScrollView) inflater.inflate(R.layout.home_layout, container, false);
    LinearLayout linearLayout = (LinearLayout) scrollView.findViewById(R.id.home_linear_layout);
    // linearLayout.setBackgroundColor(Color.WHITE);
    mTextViewDay = (TextView) linearLayout.findViewById(R.id.count_down_day);
    mTextViewHour = (TextView) linearLayout.findViewById(R.id.count_down_hour);
    mImageViewClickMe = (Button) linearLayout.findViewById(R.id.map_fullscreen_button);
    mImageViewClickMe.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getActivity() == null)
                return;
            MainActivity fca = (MainActivity) getActivity();
            fca.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            fca.switchContent(new MapFragment());
        }
    });
    // mTextView.setBackgroundResource(R.drawable.info_countdown);
    Date date = new Date(113, 6, 27); // 2013/July/27
    // year the year, 0 is 1900.
    // month the month, 0 - 11.
    // day the day of the month, 1 - 31.
    long dtMili = System.currentTimeMillis();
    Date dateNow = new Date(dtMili);
    long remain = date.getTime() - dateNow.getTime();

    new CountDownTimer(remain, 1000) {

        public void onTick(long millisUntilFinished) {
            // mTextView.setText("seconds remaining: " + millisUntilFinished
            // / 1000);
            mTextViewDay.setText(timeDay(millisUntilFinished / 1000));
            mTextViewHour.setText(timeHour(millisUntilFinished / 1000));
        }

        public void onFinish() {
            // mTextView.setText("done!");
        }
    }.start();

    return scrollView;
}

From source file:com.miljin.setminder.TimerService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    //keep CPU on while timer is ticking
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
            "MyWakelockTag");
    wakeLock.acquire();/*from   w  ww  . j  a v  a  2s  .c  o  m*/

    seconds = intent.getLongExtra(MainActivity.EXTRA_START_TIME, 0);

    Intent getActivityIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, getActivityIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    //make notification
    notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder
            .setContentTitle(getResources().getString(com.miljin.setminder.R.string.notification_title));
    if (seconds >= 120) {
        notificationBuilder.setContentText(Long.toString(seconds / 60)
                + getResources().getString(com.miljin.setminder.R.string.notification_text_plural));
    } else {
        notificationBuilder.setContentText(
                getResources().getString(com.miljin.setminder.R.string.notification_text_minute));
    }
    notificationBuilder.setSmallIcon(com.miljin.setminder.R.drawable.ic_notification);
    notificationBuilder.setContentIntent(pendingIntent);
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notifyID, notificationBuilder.build());

    myCountDownTimer = new CountDownTimer(seconds * 1000, 100) {
        public void onTick(long millisUntilFinished) {
            timerServiceTicking = true;
            broadcastTime(millisUntilFinished);
            sendNotification(millisUntilFinished);
        }

        public void onFinish() {
            timerServiceTicking = false;
            broadcastDone();
            wakeLock.release();
        }
    };
    myCountDownTimer.start();

    return START_NOT_STICKY;
}

From source file:info.guardianproject.iocipher.camera.StillCameraActivity.java

private void notifyUserImageWasSavedSuccessfully() {
    final Toast toast = Toast.makeText(getApplicationContext(), "image saved successfully!",
            Toast.LENGTH_SHORT);//from w  ww .java2 s.  c  o m
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();

    final int DURATION = 500;
    new CountDownTimer(DURATION, DURATION) {
        public void onTick(long millisUntilFinished) {
            toast.show();
        }

        public void onFinish() {
            toast.cancel();
        }
    }.start();
}

From source file:com.barcamppenang2014.tabfragment.HomeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (scrollView != null) {
        ViewGroup parent = (ViewGroup) scrollView.getParent();
        if (parent != null)
            parent.removeView(scrollView);
    }/*from w  w  w.  j a  va 2 s  . c o m*/
    scrollView = (ScrollView) inflater.inflate(R.layout.home_layout, container, false);
    LinearLayout linearLayout = (LinearLayout) scrollView.findViewById(R.id.home_linear_layout);
    // linearLayout.setBackgroundColor(Color.WHITE);
    mTextViewDay = (TextView) linearLayout.findViewById(R.id.count_down_day);
    mTextViewHour = (TextView) linearLayout.findViewById(R.id.count_down_hour);
    mImageViewClickMe = (Button) linearLayout.findViewById(R.id.map_fullscreen_button);
    mImageViewClickMe.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getActivity() == null)
                return;
            MainActivity fca = (MainActivity) getActivity();
            fca.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            fca.switchContent(new MapFragment());
        }
    });
    // mTextView.setBackgroundResource(R.drawable.info_countdown);
    @SuppressWarnings("deprecation")
    Date date = new Date(114, 4, 17, 9, 0, 0); // 2014/May/17 9am
    // year the year, 0 is 1900.
    // month the month, 0 - 11.
    // day the day of the month, 1 - 31.
    long dtMili = System.currentTimeMillis();
    Date dateNow = new Date(dtMili);
    long remain = date.getTime() - dateNow.getTime();

    new CountDownTimer(remain, 1000) {

        public void onTick(long millisUntilFinished) {
            //mTextView.setText("seconds remaining: " + millisUntilFinished/ 1000);

            String day = timeDay(millisUntilFinished / 1000);
            String hour = timeHour(millisUntilFinished / 1000);
            mTextViewDay.setText(day);
            mTextViewHour.setText(hour);
            /*if(Integer.parseInt(day)>9 && Integer.parseInt(hour)<=9){
               LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mTextViewDay.getLayoutParams();
               params.rightMargin = 85;
               mTextViewDay.setLayoutParams(params);
            }
            if(Integer.parseInt(day)<=9 && Integer.parseInt(hour)<=9 ){
               LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mTextViewDay.getLayoutParams();
               params.rightMargin = 145;
               mTextViewDay.setLayoutParams(params);
            }
            if(Integer.parseInt(day)<=9 && Integer.parseInt(hour)>9 ){
               LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mTextViewDay.getLayoutParams();
               params.rightMargin = 125;
               mTextViewDay.setLayoutParams(params);
            }*/
        }

        public void onFinish() {
            // mTextView.setText("done!");
        }
    }.start();

    return scrollView;
}

From source file:com.somethoughts.chinmay.game.Coin.CoinTossMainFragment.java

private void toss_it(final Boolean userChoice) {

    if (inProgress) {
        Toast.makeText(getActivity(), "Please Wait", Toast.LENGTH_SHORT).show();
        return;// w  w  w . j  a  v a  2s  .  co m
    }
    final TextView textViewResult = (TextView) view.findViewById(R.id.coin_result_textview);
    final TextView textViewStatus = (TextView) view.findViewById(R.id.coin_status_textView);
    final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.coin_progressBar);

    Random random = new Random();
    progressBar.setVisibility(View.VISIBLE);
    progressBar.setMax(2500);
    progressBar.setIndeterminate(false);
    final Boolean b = random.nextBoolean();
    countDownTimer = new CountDownTimer(3000, 125) {
        @Override
        public void onTick(long l) {
            inProgress = true;
            Random random = new Random();
            progressBar.setProgress(3000 - (int) l);
            Log.v("Progress", Integer.toString(progressBar.getProgress()));
            textViewStatus.setVisibility(View.VISIBLE);
            textViewStatus.setText(toss[random.nextInt(2)]);
            textViewResult.setText(getResources().getText(R.string.Waiting));
        }

        @Override
        public void onFinish() {
            inProgress = false;
            if ((b && userChoice) || (!b && !userChoice)) {

                textViewStatus.setText(getResources().getText(R.string.Voila));
                view.setBackgroundColor(getColor(getActivity().getBaseContext(), R.color.colorWin));
                if (userChoice)
                    textViewResult.setText(toss[0]);
                else
                    textViewResult.setText(toss[1]);
            } else {
                textViewStatus.setText(getResources().getText(R.string.oops));
                view.setBackgroundColor(getColor(getActivity().getBaseContext(), R.color.colorLose));
                if (userChoice)
                    textViewResult.setText(toss[1]);
                else
                    textViewResult.setText(toss[0]);
            }
            progressBar.setProgress(3000);
        }
    }.start();
}

From source file:com.example.android.wearable.speaker.MainActivity.java

@Override
public void onUIStateChanged(UIAnimation.UIState state) {
    Log.d(TAG, "UI State is: " + state);
    if (mUiState == state) {
        return;/*from  w w  w .  j  ava2 s  .c om*/
    }
    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;
    }
}