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.suning.mobile.ebuy.lottery.network.util.Caller.java

/**
 * //from w w  w.j ava2s . c o  m
 * @Description:
 * @param des
 * @Author:12072565 
 * @Date 2013-5-6
 * @return void
 */
private synchronized void updateDate(long des) {
    timeFirst = SystemClock.elapsedRealtime();
    mBase = mBase + des;
    SuningEBuyApplication.getApp().setDate(new Date(mBase));

}

From source file:com.example.android.mediarouter.player.MainActivity.java

private void updateProgress() {
    // Estimate content position from last status time and elapsed time.
    // (Note this might be slightly out of sync with remote side, however
    // it avoids frequent polling the MRP.)
    int progress = 0;
    PlaylistItem item = getCheckedPlaylistItem();
    if (item != null) {
        int state = item.getState();
        long duration = item.getDuration();
        if (duration <= 0) {
            if (state == MediaItemStatus.PLAYBACK_STATE_PLAYING
                    || state == MediaItemStatus.PLAYBACK_STATE_PAUSED) {
                mSessionManager.updateStatus();
            }// w ww.  java2 s.c  om
        } else {
            long position = item.getPosition();
            long timeDelta = mPaused ? 0 : (SystemClock.elapsedRealtime() - item.getTimestamp());
            progress = (int) (100.0 * (position + timeDelta) / duration);
        }
    }
    mSeekBar.setProgress(progress);
}

From source file:com.frostwire.android.gui.fragments.BrowsePeerFragment.java

private void refreshSelection() {
    if (adapter != null) {
        lastAdapterRefresh = SystemClock.elapsedRealtime();
        browseFilesButtonClick(adapter.getFileType());
    }
}

From source file:com.czh.testmpeg.videorecord.CameraActivity.java

private void startChronometer() {
    mBinding.textChrono.setVisibility(View.VISIBLE);
    final long startTime = SystemClock.elapsedRealtime();
    mBinding.textChrono.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
        @Override//  w w w  .j  a v a 2 s.  com
        public void onChronometerTick(Chronometer arg0) {
            countUp = (SystemClock.elapsedRealtime() - startTime) / 1000;
            if (countUp % 2 == 0) {
                mBinding.chronoRecordingImage.setVisibility(View.VISIBLE);
            } else {
                mBinding.chronoRecordingImage.setVisibility(View.INVISIBLE);
            }

            String asText = String.format("%02d", countUp / 60) + ":" + String.format("%02d", countUp % 60);
            mBinding.textChrono.setText(asText);
        }
    });
    mBinding.textChrono.start();
}

From source file:com.horizondigital.delta.UpdateService.java

private DeltaInfo.ProgressListener getMD5Progress(String state, String filename) {
    final long[] last = new long[] { 0, SystemClock.elapsedRealtime() };
    final String _state = state;
    final String _filename = filename;

    return new DeltaInfo.ProgressListener() {
        @Override// w  w  w  .  jav a  2  s.com
        public void onProgress(float progress, long current, long total) {
            long now = SystemClock.elapsedRealtime();
            if (now >= last[0] + 16L) {
                updateState(_state, progress, current, total, _filename,
                        SystemClock.elapsedRealtime() - last[1]);
                last[0] = now;
            }
        }
    };
}

From source file:com.negaheno.android.NotificationsController.java

private void scheduleNotificationRepeat() {
    try {/*www . j  ava  2 s. c o  m*/
        AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext
                .getSystemService(Context.ALARM_SERVICE);
        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) {
            alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + minutes * 60 * 1000,
                    pintent);
        } else {
            alarm.cancel(pintent);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:com.gmail.walles.johan.batterylogger.BatteryPlotFragment.java

/**
 * Animate minX and maxX to new values./* w w  w.j  ava 2 s .  c om*/
 *
 * @return true if an animation was started, false if we're already at the target values
 */
private boolean animateXrange(final XYPlot plot, double targetMinX, double targetMaxX) {
    // Cancel any running animation
    if (animator != null) {
        animator.cancel();
    }

    if (targetMinX < originalMinX) {
        targetMinX = originalMinX;
    }
    if (targetMaxX > originalMaxX) {
        targetMaxX = originalMaxX;
    }
    if (targetMaxX <= targetMinX) {
        throw new IllegalArgumentException("Max target must be > min target");
    }
    if (targetMaxX == maxX && targetMinX == minX) {
        // We're already there, nothing to animate
        return false;
    }

    animator = ValueAnimator.ofPropertyValuesHolder(
            PropertyValuesHolder.ofFloat("minX", (float) minX, (float) targetMinX),
            PropertyValuesHolder.ofFloat("maxX", (float) maxX, (float) targetMaxX));
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.setDuration(ANIMATION_DURATION_MS);
    final int nFrames[] = new int[1];
    final long longestGapMs[] = new long[1];
    final int longestGapBeforeFrame[] = new int[1];
    final long lastFrameStart[] = new long[1];
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            long frameStart = SystemClock.elapsedRealtime();
            if (lastFrameStart[0] > 0) {
                long gapMs = frameStart - lastFrameStart[0];
                if (gapMs > longestGapMs[0]) {
                    longestGapMs[0] = gapMs;
                    longestGapBeforeFrame[0] = nFrames[0];
                }
            }
            lastFrameStart[0] = frameStart;

            nFrames[0]++;
            minX = (double) (Float) animation.getAnimatedValue("minX");
            maxX = (double) (Float) animation.getAnimatedValue("maxX");

            plot.setDomainBoundaries(minX, maxX, BoundaryMode.FIXED);
            redrawPlot(plot);
        }
    });
    final double finalMinX = targetMinX;
    final double finalMaxX = targetMaxX;
    animator.addListener(new AnimatorListenerAdapter() {
        boolean cancelled = false;
        long t0;

        @Override
        public void onAnimationCancel(Animator animation) {
            cancelled = true;
        }

        @Override
        public void onAnimationStart(Animator animation) {
            t0 = SystemClock.elapsedRealtime();
            disableDrainDots(plot);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            enableDrainDots(plot);
            if (cancelled) {
                return;
            }

            long t1 = SystemClock.elapsedRealtime();
            long durationMs = t1 - t0;
            if (nFrames[0] == 0 || durationMs == 0) {
                Log.w(TAG,
                        "Animation had " + nFrames[0] + " frames, done in " + durationMs
                                + "ms, longest gap was " + longestGapMs[0] + "ms at frames "
                                + (longestGapBeforeFrame[0] - 1) + "-" + longestGapBeforeFrame[0]);
            } else {
                double fps = nFrames[0] / (durationMs / 1000.0);
                double msPerFrame = durationMs / ((double) nFrames[0]);
                Log.i(TAG, String.format(
                        "Animation of %d frames took %dms at %.1ffps or %.1fms/frame, longest time was %dms at frames %d-%d",
                        nFrames[0], durationMs, fps, msPerFrame, longestGapMs[0],
                        (longestGapBeforeFrame[0] - 1), longestGapBeforeFrame[0]));
            }

            // Avoid any float -> double rounding errors
            minX = finalMinX;
            maxX = finalMaxX;
        }
    });
    animator.start();

    return true;
}

From source file:com.example.android.classical.BluetoothChatFragment.java

@Override
public void onClick(View v) {
    if (mChatService.delegate == null) {
        Toast.makeText(getActivity(), "basketball do not connect", Toast.LENGTH_SHORT).show();
        return;/*  ww  w  .  j av  a2  s. c  o m*/
    }
    GlobalVar.SERVER_ADDRESS = et_ip.getText().toString();
    if (!RegexUtil.isValidIp(GlobalVar.SERVER_ADDRESS)) {
        Toast.makeText(getActivity(), "please use right ip format", Toast.LENGTH_SHORT).show();
        return;
    }
    String msg = null;
    switch (v.getId()) {
    case R.id.btn_start_dribbling:
        if (isStartShooting || isStartRawStream) {
            showToastForHintOtherRequestIsStart();
            return;
        }
        if (!isStartDribbling) {
            mChatService.delegate.startDribblingActivity();
            isStartDribbling = true;
        } else {
            //mChatService.delegate.setEndDribblingListener(new EndDribblingListener() {
            //    @Override public void onResponse(boolean isOk) {
            //        if (isOk) {
            //            isStartDribbling = !isStartDribbling;
            //            getActivity().runOnUiThread(new Runnable() {
            //                @Override public void run() {
            //                    if (isStartDribbling) {
            //                        mStartDribblingButton.setText(getString(R.string.stop));
            //                    } else {
            //                        mStartDribblingButton.setText(
            //                                getString(R.string.start_dribbling));
            //                    }
            //                }
            //            });
            //
            //        }
            //    }
            //});

            //mChatService.delegate.endDribblingActivity();
            mChatService.delegate.endDribblingActivity();
            //isStartDribbling = !isStartDribbling;
            //getActivity().runOnUiThread(new Runnable() {
            //    @Override public void run() {
            //        if (isStartDribbling) {
            //            mStartDribblingButton.setText(getString(R.string.stop));
            //        } else {
            //            mStartDribblingButton.setText(
            //                    getString(R.string.start_dribbling));
            //        }
            //    }
            //});
            isStartDribbling = !isStartDribbling;
        }

        if (isStartDribbling) {
            mStartDribblingButton.setText(getString(R.string.stop));
        } else {
            mStartDribblingButton.setText(getString(R.string.start_dribbling));
        }

        break;

    case R.id.btn_start_shooting:
        if (isStartDribbling || isStartRawStream) {
            showToastForHintOtherRequestIsStart();
            return;
        }
        if (!isStartShooting) {
            mChatService.delegate.startShootingActivity();
            isStartShooting = true;
        } else {
            //mChatService.delegate.setEndShootingListener(new EndShootingListener() {
            //    @Override public void onResponse(boolean isOk) {
            //        if (isOk) {
            //            isStartShooting = !isStartShooting;
            //            getActivity().runOnUiThread(new Runnable() {
            //                @Override public void run() {
            //                    if (isStartShooting) {
            //                        mStartShootingButton.setText(getString(R.string.stop));
            //                    } else {
            //                        mStartShootingButton.setText(
            //                                getString(R.string.start_shooting));
            //                    }
            //                }
            //            });
            //
            //        }
            //    }
            //});
            //mChatService.delegate.endShootingActivity();
            mChatService.delegate.endShootingActivity();
            isStartShooting = !isStartShooting;
        }
        if (isStartShooting) {
            mStartShootingButton.setText(getString(R.string.stop));
        } else {
            mStartShootingButton.setText(getString(R.string.start_shooting));
        }
        break;

    case R.id.btn_start_raw_stream:
        if (isStartDribbling || isStartShooting) {
            return;
        }
        if (!isStartRawStream) {
            time.setBase(SystemClock.elapsedRealtime());
            time.start();
            FileUtil.createFile();
            mChatService.delegate.startRawStream();
            isStartRawStream = true;
        } else {
            //mChatService.delegate.setEndRawStreamListener(new EndRawStreamListener() {
            //    @Override public void onResponse(boolean isOk) {
            //        if (isOk) {
            //            isStartRawStream = !isStartRawStream;
            //            getActivity().runOnUiThread(new Runnable() {
            //                @Override public void run() {
            //                    time.stop();
            //                    DialogUtil.showDialog(getActivity());
            //
            //                    if (isStartRawStream) {
            //                        mStartRawStream.setText(getString(R.string.stop));
            //                    } else {
            //                        mStartRawStream.setText(
            //                                getString(R.string.start_raw_stream));
            //                    }
            //                }
            //            });
            //        }
            //    }
            //});
            mChatService.delegate.endRawStream();
            mChatService.delegate.endRawStream();
            isStartRawStream = !isStartRawStream;
        }

        if (isStartRawStream) {
            mStartRawStream.setText(getString(R.string.stop));
        } else {
            mStartRawStream.setText(getString(R.string.start_raw_stream));
        }

        break;
    }
}

From source file:com.inrista.loggliest.Loggly.java

private static void postLogs() {
    mLastUpload = SystemClock.elapsedRealtime() / 1000;
    mLogCounter = 0;//w w  w  .  java 2  s . c o m

    File dir = mContext.getDir(LOG_FOLDER, Context.MODE_PRIVATE);
    for (File logFile : dir.listFiles()) {
        StringBuilder builder = new StringBuilder();

        try {
            // Read log files and build body of newline-separated json log entries                
            FileInputStream fis = new FileInputStream(logFile);
            BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
                builder.append('\n');
            }
            reader.close();
        } catch (FileNotFoundException e) {
            return;
        } catch (IOException e) {
            return;
        }

        String json = builder.toString();
        if (json.isEmpty())
            return;

        try {
            // Blocking POST
            TypedInput body = new TypedByteArray("application/json", json.getBytes());
            Response answer = mBulkLogService.log(mToken, mLogglyTag, body);

            // Successful post
            if (answer.getStatus() == 200) {
                logFile.delete();
                mRecentLogFile = null;
            }
        }

        // Post failed for some reason, keep log files and retry later
        catch (RetrofitError error) {
        }
    }
}