List of usage examples for android.os CountDownTimer CountDownTimer
public CountDownTimer(long millisInFuture, long countDownInterval)
From source file:io.lhyz.android.zhihu.daily.ui.main.LatestAdapter.java
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { final int type = getItemViewType(holder.getAdapterPosition()); if (type == TYPE_TOP) { final List<Top> topStories = mTopStories; final CarouselViewHolder carouselViewHolder = (CarouselViewHolder) holder; final ViewPager viewPager = carouselViewHolder.mViewPager; final TopAdapter adapter = new TopAdapter(topStories); adapter.setOnStoryItemClickListener(mOnStoryItemClickListener); viewPager.setOffscreenPageLimit(5); viewPager.setAdapter(adapter);//w w w .j a va2 s.c o m /** * ??3s? * * ? */ final CountDownTimer timer = new CountDownTimer(3000, 3000) { @Override public void onTick(long l) { } @Override public void onFinish() { int size = mTopStories.size(); int pos = viewPager.getCurrentItem(); if (pos == size - 1) { pos = 0; } else { pos += 1; } viewPager.setCurrentItem(pos); } }; timer.start(); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { } @Override public void onPageScrollStateChanged(int state) { //? if (state == ViewPager.SCROLL_STATE_DRAGGING) { timer.cancel(); } if (state == ViewPager.SCROLL_STATE_SETTLING) { timer.start(); } } }); } else if (type == TYPE_HEADER) { final HeaderViewHolder headerViewHolder = (HeaderViewHolder) holder; final Normal story = mStories.get(0); headerViewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mOnStoryItemClickListener.onNormalClick(story); } }); headerViewHolder.mHeader.setText(""); headerViewHolder.mTextView.setText(story.getTitle()); final String imageURL = story.getImages().get(0); if (imageURL != null) { headerViewHolder.mSimpleDraweeView.setImageURI(Uri.parse(imageURL)); } } else { final NormalViewHolder normalViewHolder = (NormalViewHolder) holder; final Normal story = mStories.get(holder.getAdapterPosition() - 1); normalViewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mOnStoryItemClickListener.onNormalClick(story); } }); normalViewHolder.mTextView.setText(story.getTitle()); final String imageURL = story.getImages().get(0); if (imageURL != null) { normalViewHolder.mSimpleDraweeView.setImageURI(Uri.parse(imageURL)); } } }
From source file:com.huzefagadi.brownbear.fragments.ImagePagerFragment.java
public void slideshow() { if (timer == null) { } else {// ww w . j a v a 2s . c o m timer.cancel(); } timer = new CountDownTimer(300000, 10000) { public void onTick(long millisUntilFinished) { if (i < imageUrls.size()) { i = viewPager.getCurrentItem() + 1; viewPager.setCurrentItem(i); System.out.println("CALLED YES " + i); } else { i = 0; viewPager.setCurrentItem(i, false); System.out.println("CALLED NO"); } } public void onFinish() { this.start(); } }.start(); }
From source file:com.manuelmazzuola.speedtogglebluetooth.service.MonitorSpeed.java
private void starTimer() { countDownTimer = new CountDownTimer(30000, 30000) { public void onTick(long millisUntilFinished) { }//ww w . j a va 2 s. c o m public void onFinish() { changeMessage(DEFAULT_MESSAGE); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.disable(); } }.start(); }
From source file:com.rks.musicx.misc.utils.Sleeptimer.java
public static void showTimerInfo(Activity c) { final String Continue = c.getString(R.string.Continue); final String cancelTimer = c.getString(R.string.cancel_timer); if (mTask.getDelay(TimeUnit.MILLISECONDS) < 0) { Stop();/*from w w w.j a v a2 s.c o m*/ return; } View view = LayoutInflater.from(c).inflate(R.layout.timer_info, null); final TextView timeLeft = ((TextView) view.findViewById(R.id.time_left)); if (PreferenceManager.getDefaultSharedPreferences(c).getBoolean("dark_theme", false)) { timeLeft.setTextColor(Color.WHITE); } else { timeLeft.setTextColor(Color.BLACK); } final String stopTimer = c.getString(R.string.stop_timer); MaterialDialog.Builder sleepdialog = new MaterialDialog.Builder(c); sleepdialog.title("SleepTimer"); sleepdialog.positiveText(Continue); sleepdialog.onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { sleepdialog.autoDismiss(true); } }); sleepdialog.negativeText(cancelTimer); sleepdialog.onNegative(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { Stop(); Toast.makeText(c, stopTimer, Toast.LENGTH_LONG).show(); } }); sleepdialog.customView(view, false); new CountDownTimer(mTask.getDelay(TimeUnit.MILLISECONDS), 1000) { @SuppressLint("StringFormatInvalid") @Override public void onTick(long seconds) { long miliseconds = seconds; miliseconds = miliseconds / 1000; timeLeft.setText(String.format(c.getString(R.string.timer_info), ((miliseconds % 3600) / 60), ((miliseconds % 3600) % 60))); } @Override public void onFinish() { sleepdialog.autoDismiss(true); } }.start(); sleepdialog.show(); }
From source file:org.thaliproject.nativetest.app.ConnectionEngine.java
/** * Starts both the connection and the discovery manager. * * @return True, if started successfully. False otherwise. *//* w w w .ja v a 2 s . c o m*/ public synchronized boolean start() { mIsShuttingDown = false; boolean shouldConnectionManagerBeRunning = mSettings.getListenForIncomingConnections(); boolean wasConnectionManagerStarted = false; if (shouldConnectionManagerBeRunning) { wasConnectionManagerStarted = mConnectionManager.startListeningForIncomingConnections(); if (!wasConnectionManagerStarted) { Log.e(TAG, "start: Failed to start the connection manager"); LogFragment.logError("Failed to start the connection manager"); } } boolean shouldDiscoveryManagerBeRunning = (mSettings.getEnableBleDiscovery() || mSettings.getEnableWifiDiscovery()); boolean wasDiscoveryManagerStarted = false; if (shouldDiscoveryManagerBeRunning) { wasDiscoveryManagerStarted = (mDiscoveryManager .getState() != DiscoveryManager.DiscoveryManagerState.NOT_STARTED || mDiscoveryManager.start(true, true)); if (!shouldDiscoveryManagerBeRunning) { Log.e(TAG, "start: Failed to start the discovery manager"); LogFragment.logError("Failed to start the discovery manager"); } } if (mCheckConnectionsTimer != null) { mCheckConnectionsTimer.cancel(); mCheckConnectionsTimer = null; } mCheckConnectionsTimer = new CountDownTimer(CHECK_CONNECTIONS_INTERVAL_IN_MILLISECONDS, CHECK_CONNECTIONS_INTERVAL_IN_MILLISECONDS) { @Override public void onTick(long l) { // Not used } @Override public void onFinish() { sendPingToAllPeers(); mCheckConnectionsTimer.start(); } }; return ((!shouldConnectionManagerBeRunning || wasConnectionManagerStarted) && (!shouldDiscoveryManagerBeRunning || wasDiscoveryManagerStarted)); }
From source file:ir.isilearning.lmsapp.fragment.QuizFragment.java
private void initProgressToolbar(View view) { final int firstUnsolvedQuizPosition = mCategory.getFirstUnsolvedQuizPosition(); final List<Quiz> quizzes = mCategory.getQuizzes(); mQuizSize = quizzes.size();// ww w. j a va 2 s . com mProgressText = (TextView) view.findViewById(R.id.progress_text); mProgressBar = ((ProgressBar) view.findViewById(R.id.progress)); mExamTimer = (TextView) view.findViewById(R.id.Timer); long millis = TimeUnit.MINUTES.toMillis(mCategory.getCategoryRemainTime()); new CountDownTimer(millis, 1000) { @SuppressLint("DefaultLocale") @Override public void onTick(long millisUntilFinished) { mExamTimer.setText(String.format("%02d:%02d", new Object[] { TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished), TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES .toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)) })); } @Override public void onFinish() { mExamTimer.setText("Time's UP!"); } }.start(); mProgressBar.setMax(mQuizSize); setProgress(firstUnsolvedQuizPosition); }
From source file:br.unicamp.busfinder.ServerOperations.java
public static void Point2Point(GeoPoint touchedpoint, MapView map, final Context c, Calendar now) { // now.setTime(new Time(12, 40, 00)); // remove this String time = pad(now.getTime().getHours()) + ":" + pad(now.getTime().getMinutes()) + ":" + pad(now.getTime().getSeconds()); // time = ""; TouchOverlay.pathlist.clearPath(map); String req = String.format( BusFinderActivity.SERVER + "Point2Point?s_lat=%f;s_lon=%f;d_lat=%f;d_lon=%f;time=%s;limit=%d", (double) BusFinderActivity.myPoint.getLatitudeE6() / 1E6, (double) BusFinderActivity.myPoint.getLongitudeE6() / 1E6, (double) touchedpoint.getLatitudeE6() / 1e6, (double) touchedpoint.getLongitudeE6() / 1e6, time, 5); JSONArray path = getJSON(req);//from w w w.java2s . c o m if (path == null) Log.d("No response", "null"); JSONObject obj = null; try { obj = path.getJSONObject(0); int source = Integer.parseInt(obj.getString("source")); int dest = Integer.parseInt(obj.getString("dest")); String departure = obj.getString("departure"); String arrival = obj.getString("arrival"); String circular = obj.getString("circular"); int timeleft = obj.getInt("time"); int distSource = obj.getInt("dist_source"); int distDest = obj.getInt("dist_dest"); String finalTime = obj.getString("final_time"); String action = obj.getString("action").replaceAll("_", ""); req = BusFinderActivity.SERVER + "getStopPosition?stopid="; JSONArray jar = getJSON(req + source); GeoPoint sourcePoint = geoFromJSON(jar.getJSONObject(0), "lat", "lon", "name"); TouchOverlay.DrawPath(BusFinderActivity.myPoint, sourcePoint, Color.GREEN, map, true); String source_ = jar.getJSONObject(0).getString("name"); if (source_ == null) source_ = "Point" + source; jar = getJSON(req + dest); GeoPoint destPoint = geoFromJSON(jar.getJSONObject(0), "lat", "lon", "name"); TouchOverlay.DrawPath(destPoint, touchedpoint, Color.BLUE, map, false); /* EDIT HERE */ String site = String.format(BusFinderActivity.SERVER + "getBusPath?line=%d&via=%d&start=%d&end=%d", (int) Integer.parseInt(obj.getString("line")), (int) Integer.parseInt(obj.getString("via")), (int) Integer.parseInt(obj.getString("source")), (int) Integer.parseInt(obj.getString("dest"))); JSONArray sitePoints = getJSON(site); GeoPoint[] points = new GeoPoint[sitePoints.length()]; for (int i = 0; i < sitePoints.length(); i++) { points[i] = ServerOperations.geoFromJSON(sitePoints.getJSONObject(i), "lat", "lon", "name"); } TouchOverlay.DrawPathList(points, Color.RED, map, false); Log.d("xxx", "URL=" + site.toString()); // get the kml (XML) doc. And parse it to get the coordinates(direction // route). /* END EDIT PathOverlay pO = new PathOverlay(sourcePoint, destPoint, 2, Color.RED); TouchOverlay.pathlist.addItem(pO, map);*/ String dest_ = jar.getJSONObject(0).getString("name"); if (dest_ == null) dest_ = "Point" + dest; Log.d("TOAST", "Take " + circular + " from " + source_ + " at " + departure + " and arrive at " + dest_ + " at " + arrival + "----YOU HAVE " + timeleft + " seconds"); BusFinderActivity.toast = Toast.makeText(c, "teste", Toast.LENGTH_SHORT); BusFinderActivity.toast.setGravity(Gravity.BOTTOM, 0, 0); //BusFinderActivity.toast.show(); BusFinderActivity.timer = new CountDownTimer(timeleft * 1000, 1000) { public void onTick(long millisUntilFinished) { //BusFinderActivity.toast.setText("Bus Leaves\n in: " // + millisUntilFinished / 1000 + " s"); //BusFinderActivity.toast.show(); BusFinderActivity.countdown.setText("Bus leaves in:" + millisUntilFinished / 1000 + " s"); } public void onFinish() { BusFinderActivity.toast.setText("Times up!"); BusFinderActivity.toast.show(); BusFinderActivity.countdown.setText("0:00"); } }; BusFinderActivity.timer.start(); BusFinderActivity.dialog = new AlertDialog.Builder(c).create(); BusFinderActivity.dialog.setMessage(String.format( "%s to %s (%d m)" + "\n\n Take %s at %s" + "\n\n Arrive at %s at %s" + "\n\n Go to your final destination (%d m) ~%s" + "", action, source + "_" + source_, distSource, circular, departure, dest + "_" + dest_, arrival, distDest, finalTime)); BusFinderActivity.dialog.setCanceledOnTouchOutside(true); BusFinderActivity.dialog.show(); BusFinderActivity.dialog.setTitle("Instructions"); return; } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } Toast.makeText(c, "Sorry No Path Found or Connection down...", Toast.LENGTH_LONG).show(); }
From source file:net.mEmoZz.PopMovies.frags.MoviesFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); helper = new DBHelper(getActivity()); if (isNetworkAvailable()) { handler.postDelayed(refreshing, 100); new CountDownTimer(400, 1000) { @Override/*from ww w . ja v a2 s .com*/ public void onTick(long millisUntilFinished) { } @Override public void onFinish() { if (conf.smallestScreenWidthDp >= 600) { cornStamp.setVisibility(VISIBLE); cornStamp.startAnimation(anim); } } }.start(); } else { noConn.setVisibility(VISIBLE); noConnTxt.setVisibility(VISIBLE); } anim = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in); anim.setDuration(200); mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { if (isNetworkAvailable()) { movies.clear(); SharedPreferences prefs = getActivity().getSharedPreferences(SORT, 0); String state = prefs.getString(SORT_SATE, "No pop!"); if (state.equals("popChecked")) { fullTask("popularity.desc"); adapter.notifyDataSetChanged(); } else if (state.equals("highChecked")) { fullTask("vote_average.desc"); adapter.notifyDataSetChanged(); } else if (state.equals("favChecked")) { dbTask(); } new CountDownTimer(400, 1000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { if (conf.smallestScreenWidthDp >= 600) { cornStamp.setVisibility(VISIBLE); cornStamp.startAnimation(anim); } } }.start(); } else { gridView.setVisibility(GONE); noConn.setVisibility(VISIBLE); noConnTxt.setVisibility(VISIBLE); mRefreshLayout.setRefreshing(false); if (conf.smallestScreenWidthDp >= 600) { cornStamp.setVisibility(VISIBLE); cornStamp.startAnimation(anim); } } } }); }
From source file:de.domjos.schooltools.activities.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.main_activity); Log4JHelper.configure(MainActivity.this); MainActivity.globals.setUserSettings(new UserSettings(this.getApplicationContext())); MainActivity.globals.setGeneralSettings(new GeneralSettings(this.getApplicationContext())); this.initControls(); this.resetDatabase(); this.initDatabase(); this.initServices(); this.hideButtons(); this.openStartModule(); this.hideWidgets(); this.addEvents(); this.addNotes(); this.addToDos(); this.addMarkLists(); this.initSavedTimeTables(); this.deleteMemoriesFromPast(); this.deleteToDosFromPast(); this.setSavedValuesForWidgets(); this.openWhatsNew(); this.countDownTimer = new CountDownTimer(Long.MAX_VALUE, 10000) { @Override//from ww w . jav a 2 s . c o m public void onTick(long millisUntilFinished) { initCurrentTimeTableEvent(); } @Override public void onFinish() { countDownTimer.start(); } }.start(); this.trMarkList.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openMarkListIntent(); } }); this.trMark.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), MarkActivity.class); startActivity(intent); } }); this.trTimeTable.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), TimeTableActivity.class); startActivity(intent); } }); this.trNotes.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), NoteActivity.class); startActivity(intent); } }); this.trTimer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), TimerActivity.class); startActivity(intent); } }); this.trLearningCards.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), LearningCardOverviewActivity.class); startActivity(intent); } }); this.trTodo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), ToDoActivity.class); startActivity(intent); } }); this.trExport.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), ApiActivity.class); startActivity(intent); } }); this.trSettings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), SettingsActivity.class); startActivity(intent); } }); this.trHelp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), HelpActivity.class); startActivity(intent); } }); this.lvCurrentNotes.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Note note = noteAdapter.getItem(position); if (note != null) { Intent intent = new Intent(getApplicationContext(), NoteActivity.class); intent.putExtra("ID", note.getID()); startActivity(intent); } } }); this.cmbSavedMarkList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { MainActivity.globals.getGeneralSettings() .setWidgetMarkListSpinner(savedMarkListAdapter.getItem(position)); MarkListSettings settings = MainActivity.globals.getSqLite() .getMarkList(savedMarkListAdapter.getItem(position)); calculateSelectedMarkList(settings); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); this.cmdRefresh.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { addEvents(); addNotes(); addToDos(); addMarkLists(); Helper.createToast(getApplicationContext(), getString(R.string.main_refreshSuccessFully)); } }); this.cmdSearch.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { lvSearchResults.setVisibility(View.GONE); return false; } }); this.cmdSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { addSearchItems(query); return false; } @Override public boolean onQueryTextChange(String newText) { addSearchItems(newText); return false; } }); }
From source file:com.partytv.server.PartyTvServer.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; /*/*from w w w . ja v a 2 s . c o m*/ if (savedInstanceState != null) { mCameraFileName = savedInstanceState.getString("mCameraFileName"); } // We create a new AuthSession so that we can use the Dropbox API. AndroidAuthSession session = buildSession(); mApi = new DropboxAPI<AndroidAuthSession>(session); checkAppKeySetup(); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert = new AlertDialog.Builder(this); alert.setTitle("Authentication"); alert.setMessage("Authentication"); alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { setLoggedIn(mApi.getSession().isLinked()); // This logs you out if you're logged in, or vice versa if (mLoggedIn) { // logOut(); } else { // Start the remote authentication mApi.getSession().startAuthentication(PartyTvServer.this); } } }); alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); alert.show(); */ /////////// mImageManager = ImageManager.getInstance(mContext); try { handleIntent(getIntent()); } 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() { initGridView(); } }.start(); } else { initGridView(); } /////// }