Example usage for android.os SystemClock elapsedRealtime

List of usage examples for android.os SystemClock elapsedRealtime

Introduction

In this page you can find the example usage for android.os SystemClock elapsedRealtime.

Prototype

@CriticalNative
native public static long elapsedRealtime();

Source Link

Document

Returns milliseconds since boot, including time spent in sleep.

Usage

From source file:com.andrew.apollo.MusicPlaybackService.java

private void scheduleDelayedShutdown() {
    if (mAlarmManager != null && mShutdownIntent != null) {

        if (mShutdownScheduled) {
            cancelShutdown();//from   w  w w.  j  a  va 2s  .c o m
        }

        if (isPlaying()) {
            LOG.info("scheduleDelayedShutdown() aborted, audio is playing.");
            mShutdownScheduled = true;
            return;
        }

        if (D)
            LOG.info("Scheduling shutdown in " + IDLE_DELAY + " ms");
        mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + IDLE_DELAY,
                mShutdownIntent);
        mShutdownScheduled = true;
    } else {
        mShutdownScheduled = false;
    }
}

From source file:com.b44t.messenger.NotificationsController.java

private void scheduleNotificationRepeat() {
    try {/*from  www. j  av a  2s . 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", 0);
        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("messenger", e);
    }
}

From source file:com.horizondigital.delta.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[] { path_base + "temp1", path_base + "temp2" };
    try {/*from w  w w .  jav  a2s .  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 (apply_signature)
            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 (!apply_signature && (di == lastDelta))
                outFile = path_base + lastDelta.getOut().getName();

            if (!dedelta(inFile, path_base + 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 (apply_signature) {
            if (!dedelta(tempFiles[(tempFile + 1) % 2], path_base + lastDelta.getSignature().getName(),
                    path_base + 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;
}

From source file:com.example.android.leanback.MediaSessionService.java

private void resetSpeedAndPlay() {

    if (mIsRewindBegin) {
        mIsRewindBegin = false;// w w  w  . ja  va2 s .c om
        mRewindEndTime = SystemClock.elapsedRealtime();

        long position = mRewindStartPosition
                + (long) mRewindSpeedFactors[mRewindSpeedFactorIndex] * (mRewindEndTime - mRewindStartTime);

        // Seek to the computed position for seamless playing.
        mPlayer.seekTo((int) position);
    }

    // Reset the state to normal state.
    mFastForwardSpeedFactorIndex = 0;
    mRewindSpeedFactorIndex = 0;
    mPlayer.setPlaybackParams(
            mPlayer.getPlaybackParams().setSpeed(mFastForwardSpeedFactors[mFastForwardSpeedFactorIndex]));

    // Update the playback status from rewinding/ fast forwardindg to STATE_PLAYING.
    // Which indicates current media item is played in the normal speed.
    mMediaSession.setPlaybackState(createPlaybackStateBuilder(PlaybackStateCompat.STATE_PLAYING).build());
}

From source file:com.crearo.gpslogger.GpsLoggingService.java

@TargetApi(23)
private void setAlarmForNextPoint() {
    LOG.debug("Set alarm for " + preferenceHelper.getMinimumLoggingInterval() + " seconds");

    Intent i = new Intent(this, GpsLoggingService.class);
    i.putExtra(IntentConstants.GET_NEXT_POINT, true);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    nextPointAlarmManager.cancel(pi);// w  ww .  j a v  a  2 s . c om

    if (Systems.isDozing(this)) {
        //Only invoked once per 15 minutes in doze mode
        LOG.debug("Device is dozing, using infrequent alarm");
        nextPointAlarmManager.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + preferenceHelper.getMinimumLoggingInterval() * 1000, pi);
    } else {
        nextPointAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + preferenceHelper.getMinimumLoggingInterval() * 1000, pi);
    }
}

From source file:com.affectiva.affdexme.MainActivity.java

/**
 * FPS measurement simply uses SystemClock to measure how many frames were processed since
 * the FPS variables were last reset.//  w ww .  j a  va2  s .c  o m
 * The constants 1000L and 1000f appear because .elapsedRealtime() measures time in milliseconds.
 * Note that if 20 frames per second are processed, this method could run for 1.5 years without being reset
 * before numberOfFrames overflows.
 */
void performFPSCalculations() {
    numberOfFrames += 1;
    long currentTime = SystemClock.elapsedRealtime();
    if (currentTime > timeToUpdate) {
        float framesPerSecond = (numberOfFrames / (float) (currentTime - firstSystemTime)) * 1000f;
        fpsPct.setText(String.format(" %.1f", framesPerSecond));
        timeToUpdate = currentTime + 1000L;
    }
}

From source file:com.android.nobug.view.pattern.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();//w  ww  .  j  av a 2s. c o m
        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 < mRowCount; i++) {
        float centerY = getCenterYForRow(i);
        for (int j = 0; j < mColumnCount; 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.mendhak.gpslogger.GpsLoggingService.java

@TargetApi(23)
private void setAlarmForNextPoint() {
    LOG.debug("Set alarm for " + preferenceHelper.getMinimumLoggingInterval() + " seconds");

    Intent i = new Intent(this, GpsLoggingService.class);
    i.putExtra(IntentConstants.GET_NEXT_POINT, true);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    nextPointAlarmManager.cancel(pi);//  w ww  .j av a 2s  .c o m

    if (Systems.isDozing(this)) {
        //Only invoked once per 15 minutes in doze mode
        LOG.warn("Device is dozing, using infrequent alarm");
        nextPointAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + preferenceHelper.getMinimumLoggingInterval() * 1000, pi);
    } else {
        nextPointAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + preferenceHelper.getMinimumLoggingInterval() * 1000, pi);
    }
}

From source file:com.raddapp.radika.raddappv001.GpsLoggingService.java

private void SetAlarmForNextPoint() {
    Log.d("GPSLOGSERV 101", "SetAlarmForNextPoint");

    //tracer.debug("Set alarm for " + 3 + " seconds");//AppSettings.getMinimumLoggingInterval()

    Intent i = new Intent(this, GpsLoggingService.class);
    i.putExtra(IntentConstants.GET_NEXT_POINT, true);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    nextPointAlarmManager.cancel(pi);//w w  w .  j a  v a2s  .com

    nextPointAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1 * 1000,
            pi); //AppSettings.getMinimumLoggingInterval()
}

From source file:com.zwj.customview.gesturelock.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();/*  w  w w . j  av a  2s .  c  o m*/
        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 < mRowCount; i++) {
        float centerY = getCenterYForRow(i);
        for (int j = 0; j < mColumnCount; j++) {
            CellState cellState = mCellStates[i][j];
            float centerX = getCenterXForColumn(j);
            float translationY = cellState.translationY;

            // TODO 
            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);
        }
    }
}