List of usage examples for android.os SystemClock elapsedRealtime
@CriticalNative native public static long elapsedRealtime();
From source file:eu.chainfire.opendelta.UpdateService.java
private boolean downloadFiles(List<DeltaInfo> deltas, boolean getFull, long totalDownloadSize, boolean force) { // Download all the files we do not have yet DeltaInfo lastDelta = deltas.get(deltas.size() - 1); final String[] filename = new String[] { null }; updateState(STATE_ACTION_DOWNLOADING, 0f, 0L, totalDownloadSize, null, null); final long[] last = new long[] { 0, totalDownloadSize, 0, SystemClock.elapsedRealtime() }; DeltaInfo.ProgressListener progressListener = new DeltaInfo.ProgressListener() { @Override/*from w w w. j a va 2 s .co m*/ public void onProgress(float progress, long current, long total) { current += last[0]; total = last[1]; progress = ((float) current / (float) total) * 100f; long now = SystemClock.elapsedRealtime(); if (now >= last[2] + 16L) { updateState(STATE_ACTION_DOWNLOADING, progress, current, total, filename[0], SystemClock.elapsedRealtime() - last[3]); last[2] = now; } } }; if (getFull) { filename[0] = lastDelta.getOut().getName(); if (!downloadDeltaFile(config.getUrlBaseFull(), lastDelta.getOut(), lastDelta.getOut().getOfficial(), progressListener, force)) { updateState(STATE_ERROR_UNKNOWN, null, null, null, null, null); Logger.d("download error"); return false; } } else { for (DeltaInfo di : deltas) { filename[0] = di.getUpdate().getName(); if (!downloadDeltaFile(config.getUrlBaseUpdate(), di.getUpdate(), di.getUpdate().getUpdate(), progressListener, force)) { updateState(STATE_ERROR_UNKNOWN, null, null, null, null, null); Logger.d("download error"); return false; } last[0] += di.getUpdate().getUpdate().getSize(); } if (config.getApplySignature()) { filename[0] = lastDelta.getSignature().getName(); if (!downloadDeltaFile(config.getUrlBaseUpdate(), lastDelta.getSignature(), lastDelta.getSignature().getUpdate(), progressListener, force)) { updateState(STATE_ERROR_UNKNOWN, null, null, null, null, null); Logger.d("download error"); return false; } } } updateState(STATE_ACTION_DOWNLOADING, 100f, totalDownloadSize, totalDownloadSize, null, null); return true; }
From source file:com.geotrackin.gpslogger.GpsLoggingService.java
private void SetAlarmForNextPoint() { tracer.debug("GpsLoggingService.SetAlarmForNextPoint"); Intent i = new Intent(this, GpsLoggingService.class); i.putExtra("getnextpoint", true); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); nextPointAlarmManager.cancel(pi);/* w w w . j a v a2 s . c o m*/ nextPointAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + AppSettings.getMinimumSeconds() * 1000, pi); }
From source file:com.torrenttunes.android.MusicService.java
/** * Update the current media player state, optionally showing an error message. * * @param error if not null, error message to present to the user. */// w w w.j a v a2 s. c o m private void updatePlaybackState(String error) { LogHelper.d(TAG, "updatePlaybackState, playback state=" + mPlayback.getState()); long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN; if (mPlayback != null && mPlayback.isConnected()) { position = mPlayback.getCurrentStreamPosition(); } PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder() .setActions(getAvailableActions()); setCustomAction(stateBuilder); int state = mPlayback.getState(); // If there is an error message, send it to the playback state: if (error != null) { // Error states are really only supposed to be used for errors that cause playback to // stop unexpectedly and persist until the user takes action to fix it. stateBuilder.setErrorMessage(error); state = PlaybackStateCompat.STATE_ERROR; } stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime()); // Set the activeQueueItemId if the current index is valid. if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) { MediaSessionCompat.QueueItem item = mPlayingQueue.get(mCurrentIndexOnQueue); // stateBuilder.setActiveQueueItemId(item.getQueueId()); } mSession.setPlaybackState(stateBuilder.build()); if (state == PlaybackStateCompat.STATE_PLAYING || state == PlaybackStateCompat.STATE_PAUSED) { mMediaNotificationManager.startNotification(); } }
From source file:com.horizondigital.delta.UpdateService.java
private boolean downloadFiles(List<DeltaInfo> deltas, boolean getFull, long totalDownloadSize, boolean force) { // Download all the files we do not have yet DeltaInfo lastDelta = deltas.get(deltas.size() - 1); final String[] filename = new String[] { null }; updateState(STATE_ACTION_DOWNLOADING, 0f, 0L, totalDownloadSize, null, null); final long[] last = new long[] { 0, totalDownloadSize, 0, SystemClock.elapsedRealtime() }; DeltaInfo.ProgressListener progressListener = new DeltaInfo.ProgressListener() { @Override/*from w ww . jav a 2 s . c o m*/ public void onProgress(float progress, long current, long total) { current += last[0]; total = last[1]; progress = ((float) current / (float) total) * 100f; long now = SystemClock.elapsedRealtime(); if (now >= last[2] + 16L) { updateState(STATE_ACTION_DOWNLOADING, progress, current, total, filename[0], SystemClock.elapsedRealtime() - last[3]); last[2] = now; } } }; if (getFull) { filename[0] = lastDelta.getOut().getName(); if (!downloadDeltaFile(url_base_full, lastDelta.getOut(), lastDelta.getOut().getOfficial(), progressListener, force)) { updateState(STATE_ERROR_UNKNOWN, null, null, null, null, null); Logger.d("download error"); return false; } } else { for (DeltaInfo di : deltas) { filename[0] = di.getUpdate().getName(); if (!downloadDeltaFile(url_base_update, di.getUpdate(), di.getUpdate().getUpdate(), progressListener, force)) { updateState(STATE_ERROR_UNKNOWN, null, null, null, null, null); Logger.d("download error"); return false; } last[0] += di.getUpdate().getUpdate().getSize(); } if (apply_signature) { filename[0] = lastDelta.getSignature().getName(); if (!downloadDeltaFile(url_base_update, lastDelta.getSignature(), lastDelta.getSignature().getUpdate(), progressListener, force)) { updateState(STATE_ERROR_UNKNOWN, null, null, null, null, null); Logger.d("download error"); return false; } } } updateState(STATE_ACTION_DOWNLOADING, 100f, totalDownloadSize, totalDownloadSize, null, null); return true; }
From source file:electrifierzzz.robotcontrol.PatternView.java
@Override protected void onDraw(Canvas canvas) { final ArrayList<Cell> pattern = mPattern; final int count = pattern.size(); final boolean[][] drawLookup = mPatternDrawLookup; if (mPatternDisplayMode == DisplayMode.Animate) { // figure out which circles to draw // + 1 so we pause on complete pattern final int oneCycle = (count + 1) * MILLIS_PER_CIRCLE_ANIMATING; final int spotInCycle = (int) (SystemClock.elapsedRealtime() - mAnimatingPeriodStart) % oneCycle; final int numCircles = spotInCycle / MILLIS_PER_CIRCLE_ANIMATING; clearPatternDrawLookup();/*from w w w.j av a 2 s . com*/ for (int i = 0; i < numCircles; i++) { final Cell cell = pattern.get(i); drawLookup[cell.getRow()][cell.getColumn()] = true; } // figure out in progress portion of ghosting line final boolean needToUpdateInProgressPoint = numCircles > 0 && numCircles < count; if (needToUpdateInProgressPoint) { final float percentageOfNextCircle = ((float) (spotInCycle % MILLIS_PER_CIRCLE_ANIMATING)) / MILLIS_PER_CIRCLE_ANIMATING; final Cell currentCell = pattern.get(numCircles - 1); final float centerX = getCenterXForColumn(currentCell.column); final float centerY = getCenterYForRow(currentCell.row); final Cell nextCell = pattern.get(numCircles); final float dx = percentageOfNextCircle * (getCenterXForColumn(nextCell.column) - centerX); final float dy = percentageOfNextCircle * (getCenterYForRow(nextCell.row) - centerY); mInProgressX = centerX + dx; mInProgressY = centerY + dy; } // TODO: Infinite loop here... invalidate(); } final Path currentPath = mCurrentPath; currentPath.rewind(); // draw the circles for (int i = 0; i < 3; i++) { float centerY = getCenterYForRow(i); for (int j = 0; j < 3; j++) { CellState cellState = mCellStates[i][j]; float centerX = getCenterXForColumn(j); float translationY = cellState.translationY; drawCircle(canvas, (int) centerX, (int) centerY + translationY, cellState.radius, drawLookup[i][j], cellState.alpha); } } // TODO: the path should be created and cached every time we hit-detect a cell // only the last segment of the path should be computed here // draw the path of the pattern (unless we are in stealth mode) final boolean drawPath = !mInStealthMode; if (drawPath) { mPathPaint.setColor(getCurrentColor(true /* partOfPattern */)); // Anyway other drawing sets their own alpha ignoring the original; And in this way we // can use ?colorControlNormal better. mPathPaint.setAlpha(255); boolean anyCircles = false; float lastX = 0f; float lastY = 0f; for (int i = 0; i < count; i++) { Cell cell = pattern.get(i); // only draw the part of the pattern stored in // the lookup table (this is only different in the case // of animation). if (!drawLookup[cell.row][cell.column]) { break; } anyCircles = true; float centerX = getCenterXForColumn(cell.column); float centerY = getCenterYForRow(cell.row); if (i != 0) { CellState state = mCellStates[cell.row][cell.column]; currentPath.rewind(); currentPath.moveTo(lastX, lastY); if (state.lineEndX != Float.MIN_VALUE && state.lineEndY != Float.MIN_VALUE) { currentPath.lineTo(state.lineEndX, state.lineEndY); } else { currentPath.lineTo(centerX, centerY); } canvas.drawPath(currentPath, mPathPaint); } lastX = centerX; lastY = centerY; } // draw last in progress section if ((mPatternInProgress || mPatternDisplayMode == DisplayMode.Animate) && anyCircles) { currentPath.rewind(); currentPath.moveTo(lastX, lastY); currentPath.lineTo(mInProgressX, mInProgressY); mPathPaint.setAlpha( (int) (calculateLastSegmentAlpha(mInProgressX, mInProgressY, lastX, lastY) * 255f)); canvas.drawPath(currentPath, mPathPaint); } } }
From source file:com.example.android.leanback.MediaSessionService.java
private void rewind() { // To support rewind action, the mRewindSpeedFactors must be provided through // setRewindSpeedFactors() method; if (mRewindSpeedFactors == null) { if (DEBUG) { Log.d(TAG, "RewindSpeedFactors are not set"); }/*from w w w . jav a2s. co m*/ return; } // Perform rewind operation using different speed. if (mIsRewindBegin) { // record end time stamp for previous rewind operation. mRewindEndTime = SystemClock.elapsedRealtime(); long position = mRewindStartPosition + (long) mRewindSpeedFactors[mRewindSpeedFactorIndex - 1] * (mRewindEndTime - mRewindStartTime); if (DEBUG) { Log.e(TAG, "Last Rewind Operation Position" + position); } mPlayer.seekTo((int) position); // Set new start status mRewindStartPosition = position; mRewindStartTime = mRewindEndTime; // It is still in rewind state, so mIsRewindBegin remains to be true. } // Perform rewind operation using the first speed set. if (!mIsRewindBegin) { mRewindStartPosition = getCurrentPosition(); Log.e("REWIND_BEGIN", "REWIND BEGIN PLACE " + mRewindStartPosition); mIsRewindBegin = true; mRewindStartTime = SystemClock.elapsedRealtime(); } // Toggle the flag to indicate rewind status. mIsRewinding = true; // Pause the player but won't update the UI status. mPlayer.pause(); // Update playback state, mIsRewinding will be reset to false inside of it. mMediaSession.setPlaybackState(createPlaybackStateBuilder(PlaybackStateCompat.STATE_REWINDING).build()); mRewindSpeedFactorIndex += 1; if (mRewindSpeedFactorIndex > mRewindSpeedFactors.length - 1) { mRewindSpeedFactorIndex = mRewindSpeedFactors.length - 1; } }
From source file:com.bliex.android.lockpatternlib.PatternView.java
@Override protected void onDraw(Canvas canvas) { final ArrayList<Cell> pattern = mPattern; final int count = pattern.size(); final boolean[][] drawLookup = mPatternDrawLookup; if (mPatternDisplayMode == DisplayMode.Animate) { // figure out which circles to draw // + 1 so we pause on complete pattern final int oneCycle = (count + 1) * MILLIS_PER_CIRCLE_ANIMATING; final int spotInCycle = (int) (SystemClock.elapsedRealtime() - mAnimatingPeriodStart) % oneCycle; final int numCircles = spotInCycle / MILLIS_PER_CIRCLE_ANIMATING; clearPatternDrawLookup();//ww w . jav a 2 s. com for (int i = 0; i < numCircles; i++) { final Cell cell = pattern.get(i); drawLookup[cell.getRow()][cell.getColumn()] = true; } // figure out in progress portion of ghosting line final boolean needToUpdateInProgressPoint = numCircles > 0 && numCircles < count; if (needToUpdateInProgressPoint) { final float percentageOfNextCircle = ((float) (spotInCycle % MILLIS_PER_CIRCLE_ANIMATING)) / MILLIS_PER_CIRCLE_ANIMATING; final Cell currentCell = pattern.get(numCircles - 1); final float centerX = getCenterXForColumn(currentCell.column); final float centerY = getCenterYForRow(currentCell.row); final Cell nextCell = pattern.get(numCircles); final float dx = percentageOfNextCircle * (getCenterXForColumn(nextCell.column) - centerX); final float dy = percentageOfNextCircle * (getCenterYForRow(nextCell.row) - centerY); mInProgressX = centerX + dx; mInProgressY = centerY + dy; } // TODO: Infinite loop here... invalidate(); } final Path currentPath = mCurrentPath; currentPath.rewind(); // draw the circles for (int i = 0; i < 3; i++) { float centerY = getCenterYForRow(i); for (int j = 0; j < 3; j++) { CellState cellState = mCellStates[i][j]; float centerX = getCenterXForColumn(j); float translationY = cellState.translationY; drawCircle(canvas, (int) centerX, (int) centerY + translationY, cellState.radius, drawLookup[i][j], cellState.alpha); } } // TODO: the path should be created and cached every time we hit-detect a cell // only the last segment of the path should be computed here // draw the path of the pattern (unless we are in stealth mode) final boolean drawPath = !mInStealthMode; if (drawPath) { mPathPaint.setColor(getCurrentColor(true /* partOfPattern */)); // Anyway other drawing sets their own alpha ignoring the original; And in this way we // can use ?colorControlNormal better. // mPathPaint.setAlpha(100); boolean anyCircles = false; float lastX = 0f; float lastY = 0f; for (int i = 0; i < count; i++) { Cell cell = pattern.get(i); // only draw the part of the pattern stored in // the lookup table (this is only different in the case // of animation). if (!drawLookup[cell.row][cell.column]) { break; } anyCircles = true; float centerX = getCenterXForColumn(cell.column); float centerY = getCenterYForRow(cell.row); if (i != 0) { CellState state = mCellStates[cell.row][cell.column]; currentPath.rewind(); currentPath.moveTo(lastX, lastY); if (state.lineEndX != Float.MIN_VALUE && state.lineEndY != Float.MIN_VALUE) { currentPath.lineTo(state.lineEndX, state.lineEndY); } else { currentPath.lineTo(centerX, centerY); } canvas.drawPath(currentPath, mPathPaint); } lastX = centerX; lastY = centerY; } // draw last in progress section if ((mPatternInProgress || mPatternDisplayMode == DisplayMode.Animate) && anyCircles) { currentPath.rewind(); currentPath.moveTo(lastX, lastY); currentPath.lineTo(mInProgressX, mInProgressY); // mPathPaint.setAlpha((int) (calculateLastSegmentAlpha( // mInProgressX, mInProgressY, lastX, lastY) * 255f)); canvas.drawPath(currentPath, mPathPaint); } } }
From source file:com.frostwire.android.gui.fragments.MyFilesFragment.java
private void refreshSelection() { if (adapter != null) { lastAdapterRefresh = SystemClock.elapsedRealtime(); clickFileTypeTab(adapter.getFileType()); } }
From source file:com.androzic.location.LocationService.java
@Override public void onGpsStatusChanged(int event) { switch (event) { case GpsStatus.GPS_EVENT_STARTED: updateProvider(LocationManager.GPS_PROVIDER, true); updateGpsStatus(GPS_SEARCHING, 0, 0); break;//w w w .j a va 2s . co m case GpsStatus.GPS_EVENT_FIRST_FIX: isContinous = false; break; case GpsStatus.GPS_EVENT_STOPPED: tearTrack(); updateGpsStatus(GPS_OFF, 0, 0); updateProvider(LocationManager.GPS_PROVIDER, false); break; case GpsStatus.GPS_EVENT_SATELLITE_STATUS: if (locationManager == null) return; GpsStatus gpsStatus = locationManager.getGpsStatus(null); Iterator<GpsSatellite> it = gpsStatus.getSatellites().iterator(); int tSats = 0; int fSats = 0; while (it.hasNext()) { tSats++; GpsSatellite sat = (GpsSatellite) it.next(); if (sat.usedInFix()) fSats++; } if (SystemClock.elapsedRealtime() - lastLocationMillis < 3000) { updateGpsStatus(GPS_OK, fSats, tSats); } else { tearTrack(); updateGpsStatus(GPS_SEARCHING, fSats, tSats); } break; } }
From source file:eu.chainfire.opendelta.UpdateService.java
private boolean applyPatches(List<DeltaInfo> deltas, String initialFile, boolean initialFileNeedsProcessing) { // Create storeSigned outfile from infile + deltas DeltaInfo firstDelta = deltas.get(0); DeltaInfo lastDelta = deltas.get(deltas.size() - 1); int tempFile = 0; String[] tempFiles = new String[] { config.getPathBase() + "temp1", config.getPathBase() + "temp2" }; try {// w w w . j ava 2 s . c o m long start = SystemClock.elapsedRealtime(); long current = 0L; long total = 0L; if (initialFileNeedsProcessing) total += firstDelta.getIn().getStore().getSize(); for (DeltaInfo di : deltas) total += di.getUpdate().getApplied().getSize(); if (config.getApplySignature()) total += lastDelta.getSignature().getApplied().getSize(); if (initialFileNeedsProcessing) { if (!zipadjust(initialFile, tempFiles[tempFile], start, current, total)) { updateState(STATE_ERROR_UNKNOWN, null, null, null, null, null); Logger.d("zipadjust error"); return false; } tempFile = (tempFile + 1) % 2; current += firstDelta.getIn().getStore().getSize(); } for (DeltaInfo di : deltas) { String inFile = tempFiles[(tempFile + 1) % 2]; if (!initialFileNeedsProcessing && (di == firstDelta)) inFile = initialFile; String outFile = tempFiles[tempFile]; if (!config.getApplySignature() && (di == lastDelta)) outFile = config.getPathBase() + lastDelta.getOut().getName(); if (!dedelta(inFile, config.getPathBase() + di.getUpdate().getName(), outFile, start, current, total)) { updateState(STATE_ERROR_UNKNOWN, null, null, null, null, null); Logger.d("dedelta error"); return false; } tempFile = (tempFile + 1) % 2; current += di.getUpdate().getApplied().getSize(); } if (config.getApplySignature()) { if (!dedelta(tempFiles[(tempFile + 1) % 2], config.getPathBase() + lastDelta.getSignature().getName(), config.getPathBase() + lastDelta.getOut().getName(), start, current, total)) { updateState(STATE_ERROR_UNKNOWN, null, null, null, null, null); Logger.d("dedelta error"); return false; } tempFile = (tempFile + 1) % 2; current += lastDelta.getSignature().getApplied().getSize(); } } finally { (new File(tempFiles[0])).delete(); (new File(tempFiles[1])).delete(); } return true; }