List of usage examples for android.os SystemClock elapsedRealtime
@CriticalNative native public static long elapsedRealtime();
From source file:com.ayaseya.nolnotification.GcmIntentService.java
@Override protected void onHandleIntent(final Intent intent) { extras = intent.getExtras();/*from w ww.jav a2 s .c o m*/ GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); // displayMessage(this, extras.toString()); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { // sendNotification("Send error: " + extras.toString()); Log.v(TAG, "Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { // sendNotification("Deleted messages on server: " + extras.toString()); Log.v(TAG, "Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. // ?????IntentService???????? // ????????? new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { // Log.v(TAG, "doInBackground()"); // soundPool????? soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); // soundPool??Listener?????? soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(final SoundPool soundPool, int sampleId, int status) { if (status == 0) { if (notificationPermission) {// ???????? // Notification???? sendNotification("?????" + extras.get("INDEX") + "????", intent); //?????????? if (isPlugged) {// ??????? Log.v(TAG, "??????"); if (ringerMode) {// Log.v(TAG, ""); if (checkbox_sound) { soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F); } if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (vibrateMode) {// Log.v(TAG, ""); if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (silentMode) {// Log.v(TAG, ""); if (checkbox_sound) { soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F); } } } else {// ????????? Log.v(TAG, "??????"); if (ringerMode) {// Log.v(TAG, ""); if (checkbox_sound) { soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F); } if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (vibrateMode) {// Log.v(TAG, ""); if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (silentMode) {// Log.v(TAG, ""); } } } // ?soundPool???? new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(30000); } catch (InterruptedException e) { } // Log.v(TAG, "soundPool.release()"); soundPool.release(); } }).start(); } } }); // soundPool????? se = soundPool.load(GcmIntentService.this, R.raw.notification_sound, 1); return null; } }.execute(null, null, null); // sendNotification("??????" + extras.get("INDEX") + "???", intent); // sendNotification("Received: " + extras.toString()); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.baseproject.volley.toolbox.LruDiskBasedCache.java
/** * Prunes the cache to fit the numbers of files. *//* w w w.j av a 2 s . c o m*/ private void pruneFileNumbersIfNeeded() { if (mMaxCacheFileNumbers <= 0) {// user do not set mMaxCacheFileNumbers,so don't check file numbers return; } if (mCacheTotalFiles < mMaxCacheFileNumbers) { return; } if (VolleyLog.DEBUG) { VolleyLog.v("pruneFileNumbers Pruning extra cache entries."); } int delNumbers = mMaxCacheFileNumbers < 10 ? mMaxCacheFileNumbers : 10;// the numbers of one delete time long before = mTotalSize; int prunedFiles = 0; long startTime = SystemClock.elapsedRealtime(); Iterator<Map.Entry<String, CacheHeader>> iterator = mEntries.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, CacheHeader> entry = iterator.next(); CacheHeader e = entry.getValue(); boolean deleted = getFileForKey(e.key).delete(); if (deleted) { mTotalSize -= e.size; mCacheTotalFiles--; } else { VolleyLog.d("pruneFileNumbersIfNeeded: Could not delete cache entry for key=%s, filename=%s", e.key, getFilenameForKey(e.key)); } iterator.remove(); prunedFiles++; if (prunedFiles == delNumbers) { break; } } if (VolleyLog.DEBUG) { VolleyLog.v("pruneFileNumbersIfNeeded: pruned %d files, %d bytes, %d ms", prunedFiles, (mTotalSize - before), SystemClock.elapsedRealtime() - startTime); } }
From source file:com.achep.acdisplay.services.activemode.ActiveModeService.java
/** * {@inheritDoc} */ @Override public void pingConsumingSensors() { mConsumingPingTimestamp = SystemClock.elapsedRealtime(); pingConsumingSensorsInternal(); }
From source file:com.mars.framework.volley.request.Request.java
/** * Notifies the request queue that this request has finished (successfully or with error). * * <p>Also dumps all events from this request's event log; for debugging.</p> *//*from ww w. j av a 2 s. co m*/ public void finish(final String tag) { if (mRequestQueue != null) { mRequestQueue.finish(this); } if (MarkerLog.ENABLED) { final long threadId = Thread.currentThread().getId(); if (Looper.myLooper() != Looper.getMainLooper()) { // If we finish marking off of the main thread, we need to // actually do it on the main thread to ensure correct ordering. Handler mainThread = new Handler(Looper.getMainLooper()); mainThread.post(new Runnable() { @Override public void run() { mEventLog.add(tag, threadId); mEventLog.finish(this.toString()); } }); return; } mEventLog.add(tag, threadId); mEventLog.finish(this.toString()); } else { long requestTime = SystemClock.elapsedRealtime() - mRequestBirthTime; if (requestTime >= SLOW_REQUEST_THRESHOLD_MS) { VolleyLog.d("%d ms: %s", requestTime, this.toString()); } } }
From source file:com.google.android.gcm.demo.ui.NetworkSchedulerFragment.java
private void addOneOff(long winStartSecs, long winEndSecs, int connectivity, boolean charging) { if (winStartSecs > winEndSecs) { Toast.makeText(getActivity(), getString(R.string.scheduler_error_window), Toast.LENGTH_SHORT).show(); return;//w ww . j av a2 s . c o m } String tag = Long.toString(SystemClock.currentThreadTimeMillis()); final long elapsedNowSeconds = SystemClock.elapsedRealtime() / 1000; final TaskTracker taskTracker = TaskTracker.createOneoff(tag, elapsedNowSeconds + winStartSecs, elapsedNowSeconds + winEndSecs); OneoffTask oneOff = new OneoffTask.Builder().setService(TaskSchedulerService.class).setTag(tag) .setExecutionWindow(winStartSecs, winEndSecs).setRequiredNetwork(connectivity) // Persistence not yet support for Oneoffs. .setRequiresCharging(charging).build(); mScheduler.schedule(oneOff); mTasks.updateTask(taskTracker); }
From source file:com.android.volley.toolbox.DiskBasedCache.java
/** * Prunes the cache to fit the amount of bytes specified. * @param neededSpace The amount of bytes we are trying to fit into the cache. *///from www. ja v a 2s . c o m private void pruneIfNeeded(int neededSpace) { if ((mTotalSize + neededSpace) < mMaxCacheSizeInBytes) { return; } if (VolleyLog.DEBUG) { VolleyLog.v("Pruning old cache entries."); } long before = mTotalSize; int prunedFiles = 0; long startTime = SystemClock.elapsedRealtime(); Iterator<Map.Entry<String, CacheHeader>> iterator = mEntries.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, CacheHeader> entry = iterator.next(); CacheHeader e = entry.getValue(); boolean deleted = getFileForKey(e.key).delete(); if (deleted) { mTotalSize -= e.size; } else { VolleyLog.d("Could not delete cache entry for key=%s, filename=%s", e.key, getFilenameForKey(e.key)); } iterator.remove(); prunedFiles++; if ((mTotalSize + neededSpace) < mMaxCacheSizeInBytes * HYSTERESIS_FACTOR) { break; } } if (VolleyLog.DEBUG) { VolleyLog.v("pruned %d files, %d bytes, %d ms", prunedFiles, (mTotalSize - before), SystemClock.elapsedRealtime() - startTime); } }
From source file:com.android.volley.toolbox.BasicNetwork.java
protected void logError(String what, String url, long start) { long now = SystemClock.elapsedRealtime(); VolleyLog.v("HTTP ERROR(%s) %d ms to fetch %s", what, (now - start), url); }
From source file:org.djodjo.comm.jus.toolbox.BasicNetwork.java
protected void logError(String what, String url, long start) { long now = SystemClock.elapsedRealtime(); JusLog.v("HTTP ERROR(%s) %d ms to fetch %s", what, (now - start), url); }
From source file:com.github.jvanhie.discogsscrobbler.util.NowPlayingService.java
private void play(final int trackNumber) { //do we even have something to play? if (trackList == null || trackList.size() == 0) return;// w w w. ja v a2 s. co m track = trackList.get(trackNumber); //don't play headings, on to the next! (if there is a next) if (track.type.equals("heading")) { if (trackNumber + 1 < trackList.size()) { play(trackNumber + 1); } else { stop(); } return; } isPlaying = true; artist = track.artist; album = track.album; currentTrack = trackNumber; mNotificationBuilder.setContentTitle(track.title).setContentText(track.artist + " - " + track.album) .setWhen(System.currentTimeMillis()).setSmallIcon(android.R.drawable.ic_media_play); //fetch the duration (will return immediately when available) and start the alarm for when it's done mLastfm.getDuration(track, new Lastfm.LastfmWaiter() { @Override public void onResult(boolean success) { //set nowplaying, scrobbling happens on the alarm callback mLastfm.updateNowPlaying(track, new Lastfm.LastfmWaiter() { @Override public void onResult(boolean success) { //the user already sees the notification, no need for extras notifications atm. } }); //notify user startForeground(NOTIFICATION_ID, mNotificationBuilder.build()); //update listeners to track change sendBroadcast(new Intent(TRACK_CHANGE)); Intent intent = new Intent(NowPlayingService.this, NowPlayingAlarm.class); if (trackNumber < trackList.size() - 1) { intent.putExtra(NEXT_TRACK_ID, (trackNumber + 1)); intent.putExtra(NEXT_TRACK_TITLE, trackList.get(trackNumber + 1).title); } else { //this is the last track, alarm will be used to stop the service (by issuing pos = -1 and title = first song title) intent.putExtra(NEXT_TRACK_ID, -1); intent.putExtra(NEXT_TRACK_TITLE, trackList.get(0).title); } mTrackStart = SystemClock.elapsedRealtime(); int duration = Track.formatDurationToSeconds(track.duration); if (duration == 0) duration = Lastfm.DEFAULT_TRACK_DURATION; if (mTrackDone != 0) duration -= mTrackDone; mAlarmIntent = PendingIntent.getBroadcast(NowPlayingService.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, mTrackStart + duration * 1000, mAlarmIntent); } }); }
From source file:biz.bokhorst.bpt.BPTService.java
protected synchronized void startLocating() { // Start activity recognition if (activityRecognitionClient == null) activityRecognitionClient = new GoogleApiClient.Builder(this).addApi(ActivityRecognition.API) .addConnectionCallbacks(BPTService.this).build(); // Connect activity recognition if (!activityRecognitionClient.isConnected() && !activityRecognitionClient.isConnecting()) { sendActivity(getString(R.string.connecting), -1, new Date().getTime()); activityRecognitionClient.connect(); }/*ww w . j a v a2 s. c o m*/ // Schedule next alarm long interval = Integer.parseInt( preferences.getString(Preferences.PREF_TRACKINTERVAL, Preferences.PREF_TRACKINTERVAL_DEFAULT)) * 60L * 1000L; long alarmTime = SystemClock.elapsedRealtime() + interval; alarmManager.cancel(pendingAlarmIntent); alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, alarmTime, pendingAlarmIntent); // Prepare user feedback nextTrackTime = new Date(System.currentTimeMillis() + interval); // Use activity recognition? boolean recognition = preferences.getBoolean(Preferences.PREF_ACTIVITYRECOGNITION, Preferences.PREF_ACTIVITYRECOGNITION_DEFAULT); if (recognition && !should) sendStage(String.format(getString(R.string.StageStill), TIME_FORMATTER.format(nextTrackTime))); if (!locating && (recognition ? should || once : true)) { locating = true; locationwait = false; wakeLock.acquire(); // Start waiting for fix long timeout = Integer.parseInt( preferences.getString(Preferences.PREF_FIXTIMEOUT, Preferences.PREF_FIXTIMEOUT_DEFAULT)) * 1000L; taskHandler.postDelayed(FixTimeoutTask, timeout); // Request location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this, taskHandler.getLooper()); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this, taskHandler.getLooper()); locationManager.addGpsStatusListener(this); // User feedback Date timeoutTime = new Date(System.currentTimeMillis() + timeout); boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); sendStage(String.format(getString(R.string.StageFixWait), TIME_FORMATTER.format(timeoutTime))); sendStatus(gpsEnabled ? getString(R.string.On) : getString(R.string.Off)); sendSatellites(-1, -1); } }