List of usage examples for android.os SystemClock elapsedRealtime
@CriticalNative native public static long elapsedRealtime();
From source file:com.example.feedback.ActivityFeedback.java
/** * Set broadcast receiver of type FeedbackBroadcastReceiver and create an alarm to test internet * connection repeatedly until feedback is sent. * * @param context application context of calling activity *//* w ww .j a v a 2s . c o m*/ public void setAlarm(Context context) { intent = new Intent(this, FeedbackBroadcastReceiver.class); pending = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarm.cancel(pending); // Set alarm to start immediately and repeat every fifteen minutes, approximately. alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pending); }
From source file:com.torrenttunes.android.ui.FullScreenPlayerActivity.java
private void updateProgress() { if (mLastPlaybackState == null) { return;/*from w w w . j a va2 s .c om*/ } long currentPosition = mLastPlaybackState.getPosition(); if (mLastPlaybackState.getState() != PlaybackStateCompat.STATE_PAUSED) { // Calculate the elapsed time between the last position update and now and unless // paused, we can assume (delta * speed) + current position is approximately the // latest position. This ensure that we do not repeatedly call the getPlaybackState() // on MediaController. long timeDelta = SystemClock.elapsedRealtime() - mLastPlaybackState.getLastPositionUpdateTime(); currentPosition += (int) timeDelta * mLastPlaybackState.getPlaybackSpeed(); } mSeekbar.setProgress((int) currentPosition); }
From source file:com.android.nobug.view.pattern.PatternView.java
/** * Set the display mode of the current pattern. This can be useful, for * instance, after detecting a pattern to tell this view whether change the * in progress result to correct or wrong. * @param displayMode The display mode./*ww w .j a v a 2 s . c o m*/ */ public void setDisplayMode(DisplayMode displayMode) { mPatternDisplayMode = displayMode; if (displayMode == DisplayMode.Animate) { if (mPattern.size() == 0) { throw new IllegalStateException( "you must have a pattern to " + "animate if you want to set the display mode to animate"); } mAnimatingPeriodStart = SystemClock.elapsedRealtime(); final Cell first = mPattern.get(0); mInProgressX = getCenterXForColumn(first.getColumn()); mInProgressY = getCenterYForRow(first.getRow()); clearPatternDrawLookup(); } invalidate(); }
From source file:cat.terrones.devops.radiofx.ui.FullScreenPlayerActivity.java
private void updateProgress() { if (mLastPlaybackState == null) { return;// w w w . ja v a 2s . com } long currentPosition = mLastPlaybackState.getPosition(); if (mLastPlaybackState.getState() != PlaybackStateCompat.STATE_PAUSED) { // Calculate the elapsed time between the last position update and now and unless // paused, we can assume (delta * speed) + current position is approximately the // latest position. This ensure that we do not repeatedly call the getPlaybackState() // on MediaControllerCompat. long timeDelta = SystemClock.elapsedRealtime() - mLastPlaybackState.getLastPositionUpdateTime(); currentPosition += (int) timeDelta * mLastPlaybackState.getPlaybackSpeed(); } mSeekbar.setProgress((int) currentPosition); }
From source file:at.vcity.androidimsocket.services.IMService.java
public void authenticationResult(Object... args) { this.authenticatedUser = true; try {//from w ww.ja v a2s . co m JSONObject param = new JSONObject(args[0].toString()); String result = param.getString("result"); if (result.equals(NetworkCommand.SUCCESSFUL)) { //currentUserId=param.getString("userId"); FriendInfo f = new FriendInfo(); f.userName = username; f.userId = param.getString("userId"); Chatting.setCurrentUser(f); // getFriendList(); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, IMService.class); intent.putExtra("myToken", socketOperator.getToken()); intent.putExtra("username", username); intent.putExtra("password", password); PendingIntent pintent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + WAKE_TIME_PERIOD, WAKE_TIME_PERIOD, pintent); Intent loginintent = new Intent(TRY_LOGIN); loginintent.putExtra("AUTHENTICATION_RESULT", NetworkCommand.SUCCESSFUL); sendBroadcast(loginintent); // Start heartbeat heartIsBeating = true; startHeartbeat(); } else { Toast.makeText(this, "Wrong user name", Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { } ; }
From source file:com.appdevper.mediaplayer.activity.FullScreenPlayerActivity.java
private void updateProgress() { if (mLastPlaybackState == null) { return;/*from w w w . j a v a 2 s. c o m*/ } long currentPosition = mLastPlaybackState.getPosition(); if (mLastPlaybackState.getState() != PlaybackState.STATE_PAUSED) { long timeDelta = SystemClock.elapsedRealtime() - mLastPlaybackState.getLastPositionUpdateTime(); currentPosition += (int) timeDelta * mLastPlaybackState.getPlaybackSpeed(); } mSeekbar.setProgress((int) currentPosition); }
From source file:edu.missouri.bas.service.SensorService.java
@SuppressWarnings("deprecation") @Override//from w ww . j a v a 2s. c o m public void onCreate() { super.onCreate(); Log.d(TAG, "Starting sensor service"); mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100); soundsMap = new HashMap<Integer, Integer>(); soundsMap.put(SOUND1, mSoundPool.load(this, R.raw.bodysensor_alarm, 1)); soundsMap.put(SOUND2, mSoundPool.load(this, R.raw.voice_notification, 1)); serviceContext = this; mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothMacAddress = mBluetoothAdapter.getAddress(); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); //Get location manager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); activityRecognition = new ActivityRecognitionScan(getApplicationContext()); activityRecognition.startActivityRecognitionScan(); mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); serviceWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SensorServiceLock"); serviceWakeLock.acquire(); //Initialize start time stime = System.currentTimeMillis(); //Setup calendar object Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(stime); /* * Setup notification manager */ notification = new Notification(R.drawable.icon2, "Recorded", System.currentTimeMillis()); notification.defaults = 0; notification.flags |= Notification.FLAG_ONGOING_EVENT; notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent notifyIntent = new Intent(Intent.ACTION_MAIN); notifyIntent.setClass(this, MainActivity.class); /* * Display notification that service has started */ notification.tickerText = "Sensor Service Running"; PendingIntent contentIntent = PendingIntent.getActivity(SensorService.this, 0, notifyIntent, Notification.FLAG_ONGOING_EVENT); notification.setLatestEventInfo(SensorService.this, getString(R.string.app_name), "Recording service started at: " + cal.getTime().toString(), contentIntent); notificationManager.notify(SensorService.SERVICE_NOTIFICATION_ID, notification); // locationControl = new LocationControl(this, mLocationManager, 1000 * 60, 200, 5000); IntentFilter activityResultFilter = new IntentFilter(XMLSurveyActivity.INTENT_ACTION_SURVEY_RESULTS); SensorService.this.registerReceiver(alarmReceiver, activityResultFilter); IntentFilter sensorDataFilter = new IntentFilter(SensorService.ACTION_SENSOR_DATA); SensorService.this.registerReceiver(alarmReceiver, sensorDataFilter); Log.d(TAG, "Sensor service created."); try { prepareIO(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } prepareAlarms(); Intent startSensors = new Intent(SensorService.ACTION_START_SENSORS); this.sendBroadcast(startSensors); Intent scheduleCheckConnection = new Intent(SensorService.ACTION_SCHEDULE_CHECK); scheduleCheck = PendingIntent.getBroadcast(serviceContext, 0, scheduleCheckConnection, 0); mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000 * 60 * 5, 1000 * 60 * 5, scheduleCheck); mLocationClient = new LocationClient(this, this, this); }
From source file:com.saulcintero.moveon.fragments.Main.java
private void startPractice() { MoveOnService.startPractice(SystemClock.elapsedRealtime() + 1000); UIFunctionUtils.showMessage(mContext, true, mContext.getString(R.string.practice_started)); enablePathColor();// ww w. java 2 s. c o m start_button.setVisibility(View.INVISIBLE); start_text.setVisibility(View.INVISIBLE); pauseresume_button.setVisibility(View.VISIBLE); pauseresume_text.setVisibility(View.VISIBLE); stop_button.setVisibility(View.VISIBLE); stop_text.setText(getString(R.string.stop)); stop_text.setVisibility(View.VISIBLE); pauseresume_text.setText(getString(R.string.play_1)); pauseOrResumeStatus += 1; stopStatus = 0; pictureCounter = 1; mLatitude = ""; mLongitude = ""; chronoBaseValue = 0; launchPractice = true; hasBeenResumed = false; paintedPath.clear(); chrono.setBase(SystemClock.elapsedRealtime()); chrono.start(); showCalculatedData(); }
From source file:com.mobileglobe.android.customdialer.common.model.AccountTypeManager.java
/** * Loads account list and corresponding account types (potentially with data sets). Always * called on a background thread./*from w w w . ja va 2 s . co m*/ */ protected void loadAccountsInBackground() { if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) { Log.d(Constants.PERFORMANCE_TAG, "AccountTypeManager.loadAccountsInBackground start"); } TimingLogger timings = new TimingLogger(TAG, "loadAccountsInBackground"); final long startTime = SystemClock.currentThreadTimeMillis(); final long startTimeWall = SystemClock.elapsedRealtime(); // Account types, keyed off the account type and data set concatenation. final Map<AccountTypeWithDataSet, AccountType> accountTypesByTypeAndDataSet = Maps.newHashMap(); // The same AccountTypes, but keyed off {@link RawContacts#ACCOUNT_TYPE}. Since there can // be multiple account types (with different data sets) for the same type of account, each // type string may have multiple AccountType entries. final Map<String, List<AccountType>> accountTypesByType = Maps.newHashMap(); final List<AccountWithDataSet> allAccounts = Lists.newArrayList(); final List<AccountWithDataSet> contactWritableAccounts = Lists.newArrayList(); final List<AccountWithDataSet> groupWritableAccounts = Lists.newArrayList(); final Set<String> extensionPackages = Sets.newHashSet(); final AccountManager am = mAccountManager; final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes(); final AuthenticatorDescription[] auths = am.getAuthenticatorTypes(); // First process sync adapters to find any that provide contact data. for (SyncAdapterType sync : syncs) { if (!ContactsContract.AUTHORITY.equals(sync.authority)) { // Skip sync adapters that don't provide contact data. continue; } // Look for the formatting details provided by each sync // adapter, using the authenticator to find general resources. final String type = sync.accountType; final AuthenticatorDescription auth = findAuthenticator(auths, type); if (auth == null) { Log.w(TAG, "No authenticator found for type=" + type + ", ignoring it."); continue; } AccountType accountType; if (GoogleAccountType.ACCOUNT_TYPE.equals(type)) { accountType = new GoogleAccountType(mContext, auth.packageName); } else if (ExchangeAccountType.isExchangeType(type)) { accountType = new ExchangeAccountType(mContext, auth.packageName, type); } else if (SamsungAccountType.isSamsungAccountType(mContext, type, auth.packageName)) { accountType = new SamsungAccountType(mContext, auth.packageName, type); } else { Log.d(TAG, "Registering external account type=" + type + ", packageName=" + auth.packageName); accountType = new ExternalAccountType(mContext, auth.packageName, false); } if (!accountType.isInitialized()) { if (accountType.isEmbedded()) { throw new IllegalStateException( "Problem initializing embedded type " + accountType.getClass().getCanonicalName()); } else { // Skip external account types that couldn't be initialized. continue; } } accountType.accountType = auth.type; accountType.titleRes = auth.labelId; accountType.iconRes = auth.iconId; addAccountType(accountType, accountTypesByTypeAndDataSet, accountTypesByType); // Check to see if the account type knows of any other non-sync-adapter packages // that may provide other data sets of contact data. extensionPackages.addAll(accountType.getExtensionPackageNames()); } // If any extension packages were specified, process them as well. if (!extensionPackages.isEmpty()) { Log.d(TAG, "Registering " + extensionPackages.size() + " extension packages"); for (String extensionPackage : extensionPackages) { ExternalAccountType accountType = new ExternalAccountType(mContext, extensionPackage, true); if (!accountType.isInitialized()) { // Skip external account types that couldn't be initialized. continue; } if (!accountType.hasContactsMetadata()) { Log.w(TAG, "Skipping extension package " + extensionPackage + " because" + " it doesn't have the CONTACTS_STRUCTURE metadata"); continue; } if (TextUtils.isEmpty(accountType.accountType)) { Log.w(TAG, "Skipping extension package " + extensionPackage + " because" + " the CONTACTS_STRUCTURE metadata doesn't have the accountType" + " attribute"); continue; } Log.d(TAG, "Registering extension package account type=" + accountType.accountType + ", dataSet=" + accountType.dataSet + ", packageName=" + extensionPackage); addAccountType(accountType, accountTypesByTypeAndDataSet, accountTypesByType); } } timings.addSplit("Loaded account types"); Account[] accounts = mAccountManager.getAccounts(); for (Account account : accounts) { boolean syncable = ContentResolver.getIsSyncable(account, ContactsContract.AUTHORITY) > 0; if (syncable) { List<AccountType> accountTypes = accountTypesByType.get(account.type); if (accountTypes != null) { // Add an account-with-data-set entry for each account type that is // authenticated by this account. for (AccountType accountType : accountTypes) { AccountWithDataSet accountWithDataSet = new AccountWithDataSet(account.name, account.type, accountType.dataSet); allAccounts.add(accountWithDataSet); if (accountType.areContactsWritable()) { contactWritableAccounts.add(accountWithDataSet); } if (accountType.isGroupMembershipEditable()) { groupWritableAccounts.add(accountWithDataSet); } } } } } Collections.sort(allAccounts, ACCOUNT_COMPARATOR); Collections.sort(contactWritableAccounts, ACCOUNT_COMPARATOR); Collections.sort(groupWritableAccounts, ACCOUNT_COMPARATOR); timings.addSplit("Loaded accounts"); synchronized (this) { mAccountTypesWithDataSets = accountTypesByTypeAndDataSet; mAccounts = allAccounts; mContactWritableAccounts = contactWritableAccounts; mGroupWritableAccounts = groupWritableAccounts; mInvitableAccountTypes = findAllInvitableAccountTypes(mContext, allAccounts, accountTypesByTypeAndDataSet); } timings.dumpToLog(); final long endTimeWall = SystemClock.elapsedRealtime(); final long endTime = SystemClock.currentThreadTimeMillis(); Log.i(TAG, "Loaded meta-data for " + mAccountTypesWithDataSets.size() + " account types, " + mAccounts.size() + " accounts in " + (endTimeWall - startTimeWall) + "ms(wall) " + (endTime - startTime) + "ms(cpu)"); if (mInitializationLatch != null) { mInitializationLatch.countDown(); mInitializationLatch = null; } if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) { Log.d(Constants.PERFORMANCE_TAG, "AccountTypeManager.loadAccountsInBackground finish"); } // Check filter validity since filter may become obsolete after account update. It must be // done from UI thread. mMainThreadHandler.post(mCheckFilterValidityRunnable); }
From source file:com.murati.oszk.audiobook.ui.FullScreenPlayerActivity.java
private void updateProgress() { if (mLastPlaybackState == null) { return;//from w w w. jav a2s. c o m } //TODO: fix current position long currentPosition = mLastPlaybackState.getPosition(); if (mLastPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING) { // Calculate the elapsed time between the last position update and now and unless // paused, we can assume (delta * speed) + current position is approximately the // latest position. This ensure that we do not repeatedly call the getPlaybackState() // on MediaControllerCompat. long timeDelta = SystemClock.elapsedRealtime() - mLastPlaybackState.getLastPositionUpdateTime(); currentPosition += (long) timeDelta * mLastPlaybackState.getPlaybackSpeed(); } mSeekbar.setProgress((int) currentPosition); try { if (mSeekbar.getMax() < currentPosition) { mSeekbar.setMax((int) currentPosition + 30000); mEnd.setText(DateUtils.formatElapsedTime(mSeekbar.getMax() / 1000)); } } catch (Exception ex) { //TODO: fix length detection } }