List of usage examples for android.os SystemClock elapsedRealtime
@CriticalNative native public static long elapsedRealtime();
From source file:com.fallahpoor.infocenter.fragments.GeneralFragment.java
private String getFormattedUptime() { String uptimeStr;/*from www .j a va2 s .c o m*/ long uptimeLong = SystemClock.elapsedRealtime(); uptimeStr = String.format(Utils.getLocale(), "%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(uptimeLong), TimeUnit.MILLISECONDS.toMinutes(uptimeLong) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(uptimeLong)), TimeUnit.MILLISECONDS.toSeconds(uptimeLong) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(uptimeLong))); return uptimeStr; }
From source file:com.lastsoft.plog.adapter.PlayerAdapter.java
@Override public void onBindViewHolder(ViewHolder viewHolder, final int position) { String drawable = "R.drawable." + players.get(position).defaultColor; int id;/* w w w. j av a 2 s .com*/ if (players.get(position).playerPhoto == null) { if (players.get(position).defaultColor == null) { id = mActivity.getResources().getIdentifier("none", "drawable", mActivity.getPackageName()); } else { id = mActivity.getResources().getIdentifier(players.get(position).defaultColor.toLowerCase(), "drawable", mActivity.getPackageName()); } viewHolder.getImageView().setImageResource(id); } viewHolder.getNameView().setText(players.get(position).playerName); viewHolder.getWinsView().setText(mActivity.getString(R.string.wins) + players.get(position).totalWins); viewHolder.getPlaysView().setText(mActivity.getString(R.string.plays) + players.get(position).totalPlays); if (players.get(position).playerPhoto != null) { ImageLoader.getInstance().displayImage(players.get(position).playerPhoto, viewHolder.getImageView(), options); } viewHolder.getView().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (SystemClock.elapsedRealtime() - mLastClickTime < 1000) { return; } mLastClickTime = SystemClock.elapsedRealtime(); ((MainActivity) mActivity).openAddPlayer(mFragment, players.get(position).getId()); } }); viewHolder.getOverflowLayout().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { playerPopup(view, position); } }); }
From source file:com.sean.takeastand.alarmprocess.ScheduledRepeatingAlarm.java
@Override public void pause() { //Cancel previous PendingIntent pendingIntent = createPendingIntent(mContext, mCurrentAlarmSchedule); AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); am.cancel(pendingIntent);//from ww w . j a v a 2 s . c o m endAlarmService(); int totalPauseTime = Utils.getDefaultPauseAmount(mContext); long delayTimeInMillis = totalPauseTime * Constants.secondsInMinute * Constants.millisecondsInSecond; long triggerTime = SystemClock.elapsedRealtime() + delayTimeInMillis; PendingIntent pausePendingIntent = createPausePendingIntent(mContext, mCurrentAlarmSchedule); am.set(AlarmManager.ELAPSED_REALTIME, triggerTime, pausePendingIntent); Calendar pausedUntilTime = Calendar.getInstance(); pausedUntilTime.add(Calendar.MINUTE, Utils.getDefaultPauseAmount(mContext)); Utils.setPausedTime(pausedUntilTime, mContext); Utils.setImageStatus(mContext, Constants.SCHEDULE_PAUSED); }
From source file:com.android.nfc.beam.BeamTransferManager.java
public BeamTransferManager(Context context, Callback callback, BeamTransferRecord pendingTransfer, boolean incoming) { mContext = context;/*from w ww.j a v a 2 s .c o m*/ mCallback = callback; mRemoteDevice = pendingTransfer.remoteDevice; mIncoming = incoming; mTransferId = pendingTransfer.id; mBluetoothTransferId = -1; mDataLinkType = pendingTransfer.dataLinkType; mRemoteActivating = pendingTransfer.remoteActivating; mStartTime = 0L; // For incoming transfers, count can be set later mTotalCount = (pendingTransfer.uris != null) ? pendingTransfer.uris.length : 0; mLastUpdate = SystemClock.elapsedRealtime(); mProgress = 0.0f; mState = STATE_NEW; mUris = pendingTransfer.uris == null ? new ArrayList<Uri>() : new ArrayList<Uri>(Arrays.asList(pendingTransfer.uris)); mTransferMimeTypes = new ArrayList<String>(); mMimeTypes = new HashMap<String, String>(); mPaths = new ArrayList<String>(); mMediaUris = new HashMap<String, Uri>(); mCancelIntent = buildCancelIntent(); mUrisScanned = 0; mCurrentCount = 0; mSuccessCount = 0; mOutgoingUris = pendingTransfer.uris; mHandler = new Handler(Looper.getMainLooper(), this); mHandler.sendEmptyMessageDelayed(MSG_TRANSFER_TIMEOUT, ALIVE_CHECK_MS); mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); }
From source file:dess15proj5.fau.cs.osr_amos.mobiletimerecording.ui.SelectedProjectFragment.java
/** * This method is called in the android lifecycle when the application is resumed. * * methodtype command method//from w w w. j ava 2s . c o m */ @Override public void onResume() { super.onResume(); addSessionsToAdapter(); SharedPreferences sharedPref = getActivity().getSharedPreferences("selectedProject", Context.MODE_PRIVATE); boolean isRecording = sharedPref.getBoolean("isRecording", false); if (isRecording) { long sessionId = sharedPref.getLong("sessionId", 0L); try { SessionsDAO sessionsDAO = DataAccessObjectFactory.getInstance().createSessionsDAO(getActivity()); session = sessionsDAO.load(sessionId); Date startTime = session.getStartTime(); Date stopTime = session.getStopTime(); if (startTime.equals(stopTime)) { startStopBtn.setImageDrawable( ContextCompat.getDrawable(getActivity(), R.drawable.ic_stop_white_24dp)); long elapsedRealTimeOffset = System.currentTimeMillis() - SystemClock.elapsedRealtime(); Long difference = startTime.getTime() - elapsedRealTimeOffset; timer.start(); timer.setBase(difference); } } catch (CursorIndexOutOfBoundsException e) { Toast.makeText(getActivity(), "Could not load session due to database errors!", Toast.LENGTH_LONG) .show(); } catch (SQLException e) { Toast.makeText(getActivity(), "Could not load session due to database errors!", Toast.LENGTH_LONG) .show(); } } }
From source file:com.app.easyblood.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();/*from w w w . j a va 2s. 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); 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()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { type = extras.getString("Type"); intType = Integer.parseInt(type); switch (intType) { case 1: verifyUserId = extras.getString("UserId"); break; case 2: askedby = extras.getString("AskedBy"); category = extras.getString("Category"); repliedby = extras.getString("RepliedBy"); replymessage = extras.getString("ReplyMessage"); userid_questions = extras.getString("UserId"); questionmessage = extras.getString("QuestionMessage"); asked_time_questions = extras.getString("AskedTime"); imagepath = extras.getString("UserProfilePhotoServerPath"); questionid = extras.getString("QuestionId"); userprofession_questions = extras.getString("UserProfession"); break; case 3: //New Request Notification message = extras.getString("message"); requestId = extras.getString("requestId"); username = extras.getString("userName"); break; case 4://New Response Notification message = extras.getString("ResponseMessage"); username = extras.getString("ResponseUserName"); requestId = extras.getString("RequestId"); userId = extras.getString("ResponseUserId"); responseId = extras.getString("ResponseId"); responseUserProfession = extras.getString("Profession"); responseUserProfilePath = extras.getString("ProfilePhotoUrl"); break; case 5: chatChatId = extras.getString("ChatId"); chatMessage = extras.getString("Message"); chatMessageTime = extras.getString("SentOn"); chatSenderId = extras.getString("SenderId"); chatSenderName = extras.getString("UserName"); break; } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. 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.davidmiguel.gobees.monitoring.MonitoringService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); // START action if (intent.getAction().equals(START_ACTION)) { // Calculate start time (to be use in chronometer) Date now = new Date(); long elapsedRealTimeOffset = System.currentTimeMillis() - SystemClock.elapsedRealtime(); startTime = now.getTime() - elapsedRealTimeOffset; // Get monitoring config monitoringSettings = (MonitoringSettings) intent.getSerializableExtra(ARGUMENT_MON_SETTINGS); // Get apiary apiary = goBeesRepository.getApiaryBlocking(monitoringSettings.getApiaryId()); // Configurations configBeeCounter();//from w ww.ja va 2 s .com configCamera(); Notification not = notificationsHelper.getMonitoringNotification(monitoringSettings.getApiaryId(), monitoringSettings.getHiveId()); configOpenCv(); // Start service in foreground startForeground(NOTIFICATION_ID, not); // STOP action } else if (intent.getAction().equals(STOP_ACTION)) { // Release camera androidCamera.release(); // Save records if (!records.isEmpty()) { // Clean records cleanRecords(); // Save records on db goBeesRepository.saveRecords(monitoringSettings.getHiveId(), records, new SaveRecordingCallback() { @Override public void onRecordingTooShort() { stopService(); callback.onRecordingTooShort(); } @Override public void onSuccess() { stopService(); callback.onSuccess(); } @Override public void onFailure() { stopService(); callback.onFailure(); } }); } else { stopService(); callback.onRecordingTooShort(); } } return START_STICKY; }
From source file:com.teachmate.teachmate.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();//from w ww . ja va 2s . co m GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); 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()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { type = extras.getString("Type"); intType = Integer.parseInt(type); switch (intType) { case 1: verifyUserId = extras.getString("UserId"); break; case 2: askedby = extras.getString("AskedBy"); category = extras.getString("Category"); repliedby = extras.getString("RepliedBy"); replymessage = extras.getString("ReplyMessage"); userid_questions = extras.getString("UserId"); questionmessage = extras.getString("QuestionMessage"); asked_time_questions = extras.getString("AskedTime"); imagepath = extras.getString("UserProfilePhotoServerPath"); questionid = extras.getString("QuestionId"); userprofession_questions = extras.getString("UserProfession"); break; case 3: //New Request Notification message = extras.getString("message"); requestId = extras.getString("requestId"); username = extras.getString("userName"); break; case 4://New Response Notification message = extras.getString("ResponseMessage"); username = extras.getString("ResponseUserName"); requestId = extras.getString("RequestId"); userId = extras.getString("ResponseUserId"); responseId = extras.getString("ResponseId"); responseUserProfession = extras.getString("Profession"); responseUserProfilePath = extras.getString("ProfilePhotoUrl"); break; case 5: chatChatId = extras.getString("ChatId"); chatMessage = extras.getString("Message"); chatMessageTime = extras.getString("SentOn"); chatSenderId = extras.getString("SenderId"); chatSenderName = extras.getString("UserName"); break; } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. String info = ""; try { info = DeviceInfoDBHandler.GetValueForKey(getApplication().getApplicationContext(), "DND"); } catch (Exception e) { e.printStackTrace(); } //if(!info.equals("true")){ 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.llf.android.launcher3.MemoryTracker.java
@Override public void onCreate() { mAm = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); // catch up in case we crashed but other processes are still running List<ActivityManager.RunningServiceInfo> svcs = mAm.getRunningServices(256); for (ActivityManager.RunningServiceInfo svc : svcs) { if (svc.service.getPackageName().equals(getPackageName())) { Log.v(TAG, "discovered running service: " + svc.process + " (" + svc.pid + ")"); startTrackingProcess(svc.pid, svc.process, System.currentTimeMillis() - (SystemClock.elapsedRealtime() - svc.activeSince)); }//from w w w .jav a2s . c o m } List<ActivityManager.RunningAppProcessInfo> procs = mAm.getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo proc : procs) { final String pname = proc.processName; if (pname.startsWith(getPackageName())) { Log.v(TAG, "discovered other running process: " + pname + " (" + proc.pid + ")"); startTrackingProcess(proc.pid, pname, System.currentTimeMillis()); } } }
From source file:cc.softwarefactory.lokki.android.androidServices.LocationService.java
private void setTemporalTimer() { AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE); Intent alarmIntent = new Intent(this, LocationService.class); alarmIntent.putExtra(ALARM_TIMER, 1); PendingIntent alarmCallback = PendingIntent.getService(this, 0, alarmIntent, 0); alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + INTERVAL_1_MIN, alarmCallback);// www . ja v a 2 s.c o m Log.d(TAG, "Time created."); }