List of usage examples for android.os SystemClock elapsedRealtime
@CriticalNative native public static long elapsedRealtime();
From source file:co.taqat.call.CallActivity.java
private void registerCallDurationTimer(View v, LinphoneCall call) { int callDuration = call.getDuration(); if (callDuration == 0 && call.getState() != State.StreamsRunning) { return;/*from w ww . ja va2 s.c om*/ } Chronometer timer; if (v == null) { timer = (Chronometer) findViewById(R.id.current_call_timer); } else { timer = (Chronometer) v.findViewById(R.id.call_timer); } if (timer == null) { throw new IllegalArgumentException("no callee_duration view found"); } timer.setBase(SystemClock.elapsedRealtime() - 1000 * callDuration); timer.start(); }
From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SETTINGS_CODE) { alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), NotifierService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000, notification_period, alarmIntent); }/*from w w w . jav a 2s .c om*/ if (requestCode == OPTION_CODE) { String json = ""; // Get Options getOptions(); /*************************************** * Save qBittorrent's options remotely * ****************************************/ // Maximum global number of simultaneous connections json += "\"max_connec\":" + global_max_num_connections; // Maximum number of simultaneous connections per torrent json += ",\"max_connec_per_torrent\":" + max_num_conn_per_torrent; // Maximum number of upload slots per torrent json += ",\"max_uploads_per_torrent\":" + max_num_upslots_per_torrent; // Global upload speed limit in KiB/s; -1 means no limit is applied json += ",\"up_limit\":" + global_upload; // Global download speed limit in KiB/s; -1 means no limit is // applied json += ",\"dl_limit\":" + global_download; // alternative global upload speed limit in KiB/s json += ",\"alt_up_limit\":" + alt_upload; // alternative global upload speed limit in KiB/s json += ",\"alt_dl_limit\":" + alt_download; // Is torrent queuing enabled ? json += ",\"queueing_enabled\":" + torrent_queueing; // Maximum number of active simultaneous downloads json += ",\"max_active_downloads\":" + max_act_downloads; // Maximum number of active simultaneous uploads json += ",\"max_active_uploads\":" + max_act_uploads; // Maximum number of active simultaneous downloads and uploads json += ",\"max_active_torrents\":" + max_act_torrents; // Schedule alternative rate limits json += ",\"scheduler_enabled\":" + schedule_alternative_rate_limits; // Scheduler starting hour json += ",\"schedule_from_hour\":" + alt_from_hour; // Scheduler starting min json += ",\"schedule_from_min\":" + alt_from_min; // Scheduler ending hour json += ",\"schedule_to_hour\":" + alt_to_hour; // Scheduler ending min json += ",\"schedule_to_min\":" + alt_to_min; // Scheduler scheduler days json += ",\"scheduler_days\":" + scheduler_days; // Put everything in an json object json = "{" + json + "}"; // Set preferences using this json object setQBittorrentPrefefrences(json); // Now it can be refreshed canrefresh = true; } if (requestCode == HELP_CODE) { // Now it can be refreshed canrefresh = true; swipeRefresh(); } if (requestCode == SETTINGS_CODE && resultCode == RESULT_OK) { // Change current server (from settings or drawer menu) changeCurrentServer(); } }
From source file:mp.teardrop.PlaybackService.java
@Override public boolean handleMessage(Message message) { switch (message.what) { case CALL_GO: if (message.arg1 == 0) playPause();/*from w ww . j a v a2 s. c om*/ else setCurrentSong(message.arg1, false); break; case SAVE_STATE: // For unexpected terminations: crashes, task killers, etc. // In most cases onDestroy will handle this saveState(0); break; case PROCESS_SONG: processSong((Song) message.obj, (message.arg1 == FORCE_PLAYBACK)); break; case QUERY: runQuery((QueryTask) message.obj); break; case CLOUD_SONGS: runDropboxQuery((ArrayList<CloudSongMetadata>) message.obj, message.arg1); break; case IDLE_TIMEOUT: if ((mState & FLAG_PLAYING) != 0) { mHandler.sendMessage(mHandler.obtainMessage(FADE_OUT, 0)); } break; case FADE_OUT: if (mFadeOut <= 0.0f) { mIdleStart = SystemClock.elapsedRealtime(); unsetFlag(FLAG_PLAYING); } else { mFadeOut -= 0.01f; mHandler.sendMessageDelayed(mHandler.obtainMessage(FADE_OUT, 0), 50); } refreshReplayGainValues(); /* Updates the volume using the new mFadeOut value */ break; case PROCESS_STATE: processNewState(message.arg1, message.arg2); break; case BROADCAST_CHANGE: broadcastChange(message.arg1, (Song) message.obj, message.getWhen()); break; case RELEASE_WAKE_LOCK: if (mWakeLock != null && mWakeLock.isHeld()) mWakeLock.release(); break; case SKIP_BROKEN_SONG: /* Advance to next song if the user didn't already change. * But we are restoring the Playing state in ANY case as we are most * likely still stopped due to the error * Note: This is somewhat racy with user input but also is the - by far - simplest * solution */ if (getTimelinePosition() == message.arg1) { setCurrentSong(1, true); } break; default: return false; } return true; }
From source file:com.hichinaschool.flashcards.anki.Reviewer.java
private void restartTimer() { // Restart visible timer and card timer if (mCurrentCard != null) { mCardTimer.setBase(SystemClock.elapsedRealtime() - mCurrentCard.timeTaken()); mCardTimer.start();/* w ww .j a v a 2 s . c o m*/ mCurrentCard.resumeTimer(); } }
From source file:com.goftagram.telegram.messenger.NotificationsController.java
private void scheduleNotificationRepeat() { try {/*from www .j av a 2 s . c o m*/ PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); int minutes = preferences.getInt("repeat_messages", 60); if (minutes > 0 && personal_count > 0) { alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + minutes * 60 * 1000, pintent); } else { alarmManager.cancel(pintent); } } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.saulcintero.moveon.fragments.Main.java
private void showCalculatedData(TextView tv, int option, Chronometer arg0) { DisplayTypes whichDisplay = DisplayTypes.values()[option]; switch (whichDisplay) { case TIME:/*from w ww . j a va2 s . c o m*/ tv.setText(FunctionUtils.longFormatTime((SystemClock.elapsedRealtime() - arg0.getBase()) / 1000)); break; case AVG_SPEED: tv.setText(FunctionUtils.calculateAvg(mContext, ((SystemClock.elapsedRealtime() - arg0.getBase()) / 1000), mDistance, isMetric)); break; case RITM: tv.setText(FunctionUtils.calculateRitm(mContext, ((SystemClock.elapsedRealtime() - arg0.getBase()) / 1000), mDistance, isMetric, false)); break; case KCAL: tv.setText(String.valueOf(MoveOnService.getCalories())); break; default: break; } }
From source file:mp.teardrop.PlaybackService.java
/** * Resets the idle timeout countdown. Should be called by a user action * has been triggered (new song chosen or playback toggled). * * If an idle fade out is currently in progress, aborts it and resets the * volume./* w w w . ja v a 2s . co m*/ */ public void userActionTriggered() { mHandler.removeMessages(FADE_OUT); mHandler.removeMessages(IDLE_TIMEOUT); if (mIdleTimeout != 0) mHandler.sendEmptyMessageDelayed(IDLE_TIMEOUT, mIdleTimeout * 1000); if (mFadeOut != 1.0f) { mFadeOut = 1.0f; refreshReplayGainValues(); } long idleStart = mIdleStart; if (idleStart != -1 && SystemClock.elapsedRealtime() - idleStart < IDLE_GRACE_PERIOD) { mIdleStart = -1; setFlag(FLAG_PLAYING); } }
From source file:com.saulcintero.moveon.fragments.Main.java
private long calculateChronoBaseValue(boolean callFromResume) { if ((Integer.valueOf(prefs.getString("auto_pause", "0")) > 0) && (MoveOnService.getLengthChrono() > 0)) { // auto-Pause // enabled // and/*from ww w .j av a 2s .com*/ // practice // has // been // paused // at // least // once if (!MoveOnService.getIsPracticePaused()) { chronoBaseValue = (SystemClock.elapsedRealtime() - ((SystemClock.elapsedRealtime() - MoveOnService.getTime()) + (MoveOnService.getAccumulatedTime() * 1000))); } else { chronoBaseValue = (SystemClock.elapsedRealtime() - (((((MoveOnService.getAccumulatedTime() * 1000) + MoveOnService.getLengthChrono()) - MoveOnService.getTime()) / 1000) * 1000)); } } else { if (MoveOnService.getIsPracticePaused() && callFromResume) { chronoBaseValue = (SystemClock.elapsedRealtime() - (((((MoveOnService.getAccumulatedTime() * 1000) + MoveOnService.getLengthChrono()) - MoveOnService.getTime()) / 1000) * 1000)); } else if (MoveOnService.getIsPracticePaused() || !hasBeenResumed) { chronoBaseValue = (SystemClock.elapsedRealtime() - ((SystemClock.elapsedRealtime() - MoveOnService.getTime()) + (MoveOnService.getAccumulatedTime() * 1000))); } else { hasBeenResumed = false; chronoBaseValue = chrono.getBase(); } } return chronoBaseValue; }
From source file:com.saulcintero.moveon.fragments.Main.java
private void showHiitTrainingDataInDisplay(Chronometer arg0) { int interval_spent_time = (int) (SystemClock.elapsedRealtime() - arg0.getBase()) / 1000; if (interval_spent_time < hiit_total_time) { if (hiit_passedRounds == 1) { hiit_actionSecondsByRound = hiit_prepSeconds + hiit_actionSeconds; hiit_lastRoundsSeconds = hiit_prepSeconds; } else {/*www . j a va 2s. com*/ hiit_actionSecondsByRound = hiit_prepSeconds + (hiit_actionSeconds * (hiit_passedRounds - 1)) + hiit_actionSeconds; hiit_lastRoundsSeconds = hiit_prepSeconds + (hiit_actionSeconds * (hiit_passedRounds - 1)); } if ((interval_spent_time <= hiit_prepSeconds) && (hiit_prepSeconds > 0)) { display5_label.setTextColor(res.getColor(R.color.gray)); int countDownTime = hiit_prepSeconds - interval_spent_time; hiit_information = getString(R.string.warm_up_description) + " " + FunctionUtils.shortFormatTime(countDownTime); hiit_label = hiit_name; } else if ((interval_spent_time <= hiit_actionSecondsByRound) && (interval_spent_time < (hiit_total_time - hiit_coolDownSeconds))) { int action = hiit_intervals.size(), accum_intervals = 0; int[] accum_intervals_array = new int[hiit_intervals.size()]; for (int m = 0; m <= (hiit_intervals.size() - 1); m++) { accum_intervals = accum_intervals + hiit_intervals.get(m)[1]; accum_intervals_array[m] = accum_intervals; if (interval_spent_time <= (hiit_lastRoundsSeconds + accum_intervals)) { action -= 1; } } hiit_information = ""; switch (hiit_intervals.get(action)[0]) { case 1: display5_label.setTextColor(res.getColor(R.color.green)); hiit_information = getString(R.string.hiit_type_description1).toLowerCase(Locale.getDefault()) + " (" + hiit_passedRounds + "/" + hiit_rounds + ") "; break; case 2: display5_label.setTextColor(res.getColor(R.color.yellow)); hiit_information = getString(R.string.hiit_type_description2).toLowerCase(Locale.getDefault()) + " (" + hiit_passedRounds + "/" + hiit_rounds + ") "; break; case 3: display5_label.setTextColor(res.getColor(R.color.orange)); hiit_information = getString(R.string.hiit_type_description3).toLowerCase(Locale.getDefault()) + " (" + hiit_passedRounds + "/" + hiit_rounds + ") "; break; case 4: display5_label.setTextColor(res.getColor(R.color.red)); hiit_information = getString(R.string.hiit_type_description4).toLowerCase(Locale.getDefault()) + " (" + hiit_passedRounds + "/" + hiit_rounds + ") "; break; } accum_intervals = 0; for (int j = 0; j <= action; j++) { accum_intervals = accum_intervals + hiit_intervals.get(j)[1]; } int countDownTime; if (hiit_passedRounds == 1) { countDownTime = ((hiit_prepSeconds + accum_intervals) - hiit_lastRoundsSeconds) - (interval_spent_time - hiit_lastRoundsSeconds); hiit_information = hiit_information + FunctionUtils.shortFormatTime(countDownTime); } else { countDownTime = ((hiit_lastRoundsSeconds + accum_intervals) - interval_spent_time); hiit_information = hiit_information + FunctionUtils.shortFormatTime(countDownTime); } hiit_label = hiit_name; } else { display5_label.setTextColor(res.getColor(R.color.blue)); hiit_information = getString(R.string.cool_down) + " " + FunctionUtils.shortFormatTime(hiit_total_time - interval_spent_time); hiit_label = hiit_name; } if ((hiit_prepSeconds + (hiit_passedRounds * hiit_actionSeconds)) <= interval_spent_time) { hiit_passedRounds += 1; } } else { display5_label.setTextColor(res.getColor(R.color.white)); hiit_information = getString(R.string.practice_completed); hiit_label = hiit_name; } showObjetiveData(display5_image, display5_label, display5_text1, hiit_information, hiit_label); }
From source file:com.xorcode.andtweet.AndTweetService.java
/** * Starts the repeating Alarm that sends the fetch Intent. *///from ww w.ja v a 2s . co m private boolean scheduleRepeatingAlarm() { final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); final PendingIntent pIntent = getRepeatingIntent(); final int frequencyMs = getFetchFrequencyS(); final long firstTime = SystemClock.elapsedRealtime() + frequencyMs; am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, frequencyMs, pIntent); MyLog.d(TAG, "Started repeating alarm in a " + frequencyMs + "ms rhythm."); return true; }