List of usage examples for android.os CountDownTimer CountDownTimer
public CountDownTimer(long millisInFuture, long countDownInterval)
From source file:edu.princeton.jrpalmer.asmlibrary.ListMyDataCursorLoader.java
public void updateList(Intent intent) { if (newFixBlinkerTimer != null) { newFixBlinkerTimer.cancel();/* w w w . j a v a2s .c om*/ } mNewFixBlinker.setVisibility(View.VISIBLE); color2 = Color.BLACK; color1 = getResources().getColor(R.color.light_yellow); newFixBlinkerTimer = new CountDownTimer(3000, 300) { public void onTick(long millisUntilFinished) { mNewFixBlinker.setTextColor(color1); int temp = color1; color1 = color2; color2 = temp; } public void onFinish() { mNewFixBlinker.setVisibility(View.INVISIBLE); } }.start(); }
From source file:net.xisberto.work_schedule.alarm.CountdownService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null) { if (ACTION_START.equals(intent.getAction())) { if (intent.hasExtra(AlarmMessageActivity.EXTRA_PERIOD_ID)) { int period_id = intent.getIntExtra(AlarmMessageActivity.EXTRA_PERIOD_ID, R.string.fstp_entrance); period = Period.getPeriod(this, period_id); } else { stopSelf();//from ww w. j a v a 2 s . c o m return super.onStartCommand(intent, flags, startId); } long millisInFuture = period.time.getTimeInMillis() - System.currentTimeMillis(); if (millisInFuture > 0) { Intent mainIntent = new Intent(this, MainActivity.class); mainIntent.setAction(MainActivity.ACTION_SET_PERIOD); mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Intent deleteIntent = new Intent(this, CountdownService.class); deleteIntent.setAction(ACTION_STOP); builder = new Builder(this).setSmallIcon(R.drawable.ic_stat_notification) .setContentTitle(getString(period.getLabelId())) .setTicker(getString(period.getLabelId())).setOnlyAlertOnce(true) .setPriority(NotificationCompat.PRIORITY_LOW).setAutoCancel(false) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentIntent(PendingIntent.getActivity(this, period.getId(), mainIntent, PendingIntent.FLAG_CANCEL_CURRENT)) .setDeleteIntent(PendingIntent.getService(this, period.getId(), deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT)); manager = ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)); manager.notify(0, builder.build()); timer = new CountDownTimer(millisInFuture, 1000) { @Override public void onTick(long millisUntilFinished) { Time t = new Time(); t.set(millisUntilFinished); builder.setContentText(getString(R.string.time_until_alarm, t.format("%M:%S"))); manager.notify(0, builder.build()); } @Override public void onFinish() { manager.cancel(0); stopSelf(); } }; timer.start(); } } else if (ACTION_STOP_SPECIFIC.equals(intent.getAction())) { if (intent.hasExtra(AlarmMessageActivity.EXTRA_PERIOD_ID)) { int period_id = intent.getIntExtra(AlarmMessageActivity.EXTRA_PERIOD_ID, R.string.fstp_entrance); if (period != null && period.getId() == period_id) { stopAndCancel(); } } else { stopSelf(); return super.onStartCommand(intent, flags, startId); } } else if (ACTION_STOP.equals(intent.getAction())) { stopAndCancel(); } } return super.onStartCommand(intent, flags, startId); }
From source file:com.guess.license.plate.Task.LoadingTaskConn.java
@Override protected void onPostExecute(ServerError result) { super.onPostExecute(result); loadingDialog.dismiss();// w ww . j ava 2 s . c o m if (result != null && !result.equals(ServerError.NO_ERROR)) { Toast toast = Toast.makeText(context, Language.GetServerErrorLanguage(result, context), Toast.LENGTH_LONG); toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); } new CountDownTimer(TIMER, 1000) { public void onTick(long millisUntilFinished) { // Do nothing } public void onFinish() { activity.onTaskFinished(); } }.start(); }
From source file:com.achie.tv.ContestantImageGrid.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; mImageManager = ImageManager.getInstance(mContext); try {// w w w . j a v a 2 s .c o m handleIntent(getIntent()); } catch (final IOException e) { e.printStackTrace(); } catch (final URISyntaxException e) { e.printStackTrace(); } catch (final JSONException e) { e.printStackTrace(); } Bundle extras = getIntent().getExtras(); if (extras != null) { String tvShowString = extras.getString("show", ""); Log.v(tag, "show string " + tvShowString); query = tvShowString; } if (!isSplashShown) { setContentView(R.layout.splash_screen_c); isSplashShown = true; CountDownTimer timer = new CountDownTimer(3000, 1000) { public void onTick(long millisUntilFinished) { } public void onFinish() { initGridView(); } }.start(); } else { initGridView(); } }
From source file:ilovezappos.zappos.kpk.ilovezappos.MainActivity.java
@Override public boolean onTouchEvent(MotionEvent event) { final BottomNavigationView bottom = (BottomNavigationView) findViewById(R.id.mainbottombar); bottom.removeAllViews();//from w w w . j a v a 2s . c om new CountDownTimer(5000, 1000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { } }.start(); return super.onTouchEvent(event); }
From source file:org.y20k.transistor.helpers.SleepTimerService.java
private void setSleepTimer(long duration) { if (mTimerRemaining > 0 && mSleepTimer != null) { mSleepTimer.cancel();//w w w. j a v a2 s . c om mSleepTimer = null; } // prepare timer mSleepTimer = new CountDownTimer(duration, 1000) { @Override public void onTick(long millisUntilFinished) { mTimerRemaining = millisUntilFinished; // send local broadcast (needed by PlayerActivityFragment) Intent i = new Intent(); i.setAction(TransistorKeys.ACTION_TIMER_RUNNING); i.putExtra(TransistorKeys.EXTRA_TIMER_REMAINING, mTimerRemaining); LocalBroadcastManager.getInstance(getApplication()).sendBroadcast(i); LogHelper.v(LOG_TAG, "Sleep timer. Remaining time: " + mTimerRemaining); } @Override public void onFinish() { mTimerRemaining = 0; // stop playback Intent intent = new Intent(getApplication(), PlayerService.class); intent.setAction(TransistorKeys.ACTION_STOP); startService(intent); // send local broadcast (needed by PlayerActivityFragment) Intent i = new Intent(); i.setAction(TransistorKeys.ACTION_TIMER_RUNNING); i.putExtra(TransistorKeys.EXTRA_TIMER_REMAINING, mTimerRemaining); LocalBroadcastManager.getInstance(getApplication()).sendBroadcast(i); LogHelper.v(LOG_TAG, "Sleep timer finished. Sweet dreams, dear user."); } }; }
From source file:com.Anderson.example.games.tanc.GameplayFragment.java
void SetTimer() { myCDT = new CountDownTimer(30000, 1000) { public void onTick(long millisUntilFinished) { mTimer.setText("Timer: " + millisUntilFinished / 1000); }//from ww w . j a v a 2 s . c o m public void onFinish() { updateUi(); } }; }
From source file:com.ibm.mobilefirst.mobileedge.recordapp.TestingActivity.java
private void handleResult(JSONObject json) { detectedLayout.setVisibility(View.VISIBLE); sensingLayout.setVisibility(View.INVISIBLE); String recognizedGesture = json.optString("recognized"); detectedGesture.setText(recognizedGesture); score.setText(String.format(getString(R.string.gesture_score), json.optString("score"))); sayText(recognizedGesture);/*from w ww. j a va 2 s. c om*/ new CountDownTimer(1500, 1500) { public void onTick(long millisUntilFinished) { } public void onFinish() { detectedLayout.setVisibility(View.INVISIBLE); sensingLayout.setVisibility(View.VISIBLE); } }.start(); }
From source file:adventure_fragments.Hiking.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.hiking_fragment, container, false); this.rootView = rootView; db = new DataBaseHelper(getActivity()); list = db.getAllItemsHiking();//w w w .ja v a 2 s.c o m adapt = new CustomAdapter2(getActivity(), R.layout.item_layout, list); listItem = (ListView) rootView.findViewById(R.id.listview_hike); listItem.setAdapter(adapt); nothingtext = (TextView) rootView.findViewById(R.id.nothing_here_hike); count = listItem.getCount(); if (count > 0) { nothingtext.setVisibility(View.GONE); } else if (count == 0) { nothingtext.setVisibility(View.VISIBLE); } final ImageButton imageButton = (ImageButton) rootView.findViewById(R.id.add_item_hiking); listItem.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { // TODO Auto-generated method stub switch (scrollState) { case 2: // SCROLL_STATE_FLING //hide button here imageButton.setVisibility(View.GONE); break; case 1: // SCROLL_STATE_TOUCH_SCROLL //hide button here imageButton.setVisibility(View.GONE); break; case 0: // SCROLL_STATE_IDLE //show button here imageButton.setVisibility(View.VISIBLE); break; default: //show button here imageButton.setVisibility(View.VISIBLE); break; } } }); imageButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { CountDownTimer timer = new CountDownTimer(4000, 1000) { @Override public void onTick(long millisUntilFinished) { imageButton.setVisibility(View.GONE); } @Override public void onFinish() { imageButton.setVisibility(View.VISIBLE); } }; timer.start(); return true; } }); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AddItemNow(); AlphaAnimation animation1 = new AlphaAnimation(0.2f, 1.0f); animation1.setDuration(500); imageButton.startAnimation(animation1); } }); return rootView; }
From source file:adventure_fragments.Running.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.running_fragment, container, false); this.rootView = rootView; db = new DataBaseHelper(getActivity()); list = db.getAllItemsRunning();//from w ww . j a v a2 s . c om adapt = new CustomAdapter4(getActivity(), R.layout.item_layout, list); listItem = (ListView) rootView.findViewById(R.id.listview_run); listItem.setAdapter(adapt); nothingtext = (TextView) rootView.findViewById(R.id.nothing_here_running); count = listItem.getCount(); if (count > 0) { nothingtext.setVisibility(View.GONE); } else if (count == 0) { nothingtext.setVisibility(View.VISIBLE); } final ImageButton imageButton = (ImageButton) rootView.findViewById(R.id.add_item_running); listItem.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { // TODO Auto-generated method stub switch (scrollState) { case 2: // SCROLL_STATE_FLING //hide button here imageButton.setVisibility(View.GONE); break; case 1: // SCROLL_STATE_TOUCH_SCROLL //hide button here imageButton.setVisibility(View.GONE); break; case 0: // SCROLL_STATE_IDLE //show button here imageButton.setVisibility(View.VISIBLE); break; default: //show button here imageButton.setVisibility(View.VISIBLE); break; } } }); imageButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { CountDownTimer timer = new CountDownTimer(4000, 1000) { @Override public void onTick(long millisUntilFinished) { imageButton.setVisibility(View.GONE); } @Override public void onFinish() { imageButton.setVisibility(View.VISIBLE); } }; timer.start(); return true; } }); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AddItemNow(); AlphaAnimation animation1 = new AlphaAnimation(0.2f, 1.0f); animation1.setDuration(500); imageButton.startAnimation(animation1); } }); return rootView; }