List of usage examples for android.os SystemClock elapsedRealtime
@CriticalNative native public static long elapsedRealtime();
From source file:Main.java
public static float calculateProgressPercentage(long lastPos, long lastPosUpdateTime, long duration) { if (duration > 0) { long currentTime = SystemClock.elapsedRealtime(); long progress = currentTime - lastPosUpdateTime + lastPos; return (float) progress / duration; }//from ww w . ja va 2s. co m return 0; }
From source file:com.commonsware.android.wakecast.PollReceiver.java
static void scheduleAlarms(Context ctxt) { AlarmManager mgr = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(ctxt, PollReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + INITIAL_DELAY, PERIOD, pi);/* w ww. j av a2 s. c o m*/ }
From source file:com.achep.acdisplay.graphics.BackgroundFactory.java
@NonNull public static AsyncTask<Void, Void, Bitmap> generateAsync(final @NonNull Bitmap bitmap, final @NonNull BackgroundAsyncListener listener) { return (AsyncTask<Void, Void, Bitmap>) AsyncTaskCompat.executeParallel(new AsyncTask<Void, Void, Bitmap>() { @Override// w ww .jav a 2s.c om protected Bitmap doInBackground(Void... params) { final long start = SystemClock.elapsedRealtime(); Bitmap output; try { output = generate(bitmap); } catch (OutOfMemoryError e) { Log.e(TAG, "Out-of-memory error while blurring the background!"); output = bitmap; } if (DEBUG) { long delta = SystemClock.elapsedRealtime() - start; Log.d(TAG, "Dynamic background created in " + delta + " millis:" + " width=" + output.getWidth() + " height=" + output.getHeight()); } return output; } @Override protected void onPostExecute(Bitmap bitmap) { super.onPostExecute(bitmap); listener.onGenerated(bitmap); } }); }
From source file:MainActivity.java
public void setAlarm(View view) { Intent intentToFire = new Intent(getApplicationContext(), AlarmBroadcastReceiver.class); intentToFire.setAction(AlarmBroadcastReceiver.ACTION_ALARM); PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intentToFire, 0); AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); long thirtyMinutes = SystemClock.elapsedRealtime() + 30 * 1000; alarmManager.set(AlarmManager.ELAPSED_REALTIME, thirtyMinutes, alarmIntent); //alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, thirtyMinutes, AlarmManager.INTERVAL_HALF_HOUR, alarmIntent); }
From source file:com.commonsware.android.job.PollReceiver.java
static void scheduleExactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) { Intent i = new Intent(ctxt, PollReceiver.class).putExtra(EXTRA_PERIOD, period).putExtra(EXTRA_IS_DOWNLOAD, isDownload);/*from www . j a va 2s. c om*/ PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); alarms.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi); }
From source file:com.achep.acdisplay.graphics.IconFactory.java
@NonNull public static AsyncTask<Void, Void, Bitmap> generateAsync(final @NonNull Context context, final @NonNull OpenNotification notification, final @NonNull IconAsyncListener listener) { return (AsyncTask<Void, Void, Bitmap>) AsyncTaskCompat.executeParallel(new AsyncTask<Void, Void, Bitmap>() { @Override/*from w w w .j a v a2 s. co m*/ protected Bitmap doInBackground(Void... params) { final long start = SystemClock.elapsedRealtime(); Bitmap output = generate(context, notification); if (DEBUG) { long delta = SystemClock.elapsedRealtime() - start; Log.d(TAG, "Notification icon created in " + delta + " millis:" + " width=" + output.getWidth() + " height=" + output.getHeight()); } return output; } @Override protected void onPostExecute(Bitmap bitmap) { super.onPostExecute(bitmap); listener.onGenerated(bitmap); } }); }
From source file:com.example.android.supportv4.content.SimpleWakefulReceiver.java
@Override public void onReceive(Context context, Intent intent) { // This is the Intent to deliver to our service. Intent service = new Intent(context, SimpleWakefulService.class); // Start the service, keeping the device awake while it is launching. Log.i("SimpleWakefulReceiver", "Starting service @ " + SystemClock.elapsedRealtime()); startWakefulService(context, service); }
From source file:com.google.android.gcm.demo.model.TaskTracker.java
public static TaskTracker createPeriodic(String tag, long periodSecs, long flexSecs) { return new TaskTracker(tag, periodSecs, flexSecs, 0L, 0L, SystemClock.elapsedRealtime() / 1000); }
From source file:com.commonsware.android.deepbg.PollReceiver.java
static void scheduleExactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) { Intent i = buildBaseIntent(ctxt).putExtra(EXTRA_PERIOD, period).putExtra(EXTRA_IS_DOWNLOAD, isDownload); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { Log.e("PollReceiver", "allow while idle"); alarms.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { alarms.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi); } else {//from w w w.j a v a 2s . co m alarms.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi); } }
From source file:com.commonsware.android.job.PollReceiver.java
static void scheduleInexactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) { Intent i = new Intent(ctxt, PollReceiver.class).putExtra(EXTRA_IS_DOWNLOAD, isDownload); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); alarms.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, period, pi);//from w ww . j a va 2s .c o m }