List of usage examples for android.text.format DateUtils MINUTE_IN_MILLIS
long MINUTE_IN_MILLIS
To view the source code for android.text.format DateUtils MINUTE_IN_MILLIS.
Click Source Link
From source file:com.battlelancer.seriesguide.util.Utils.java
/** * Run the notification service delayed by a minute to display and (re)schedule upcoming episode * alarms./*from w w w. j a va 2 s.co m*/ */ public static void runNotificationServiceDelayed(Context context) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, OnAlarmReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1 * DateUtils.MINUTE_IN_MILLIS, pi); }
From source file:com.fututel.ui.messages.ConversationsAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { super.bindView(view, context, cursor); final ConversationListItemViews tagView = (ConversationListItemViews) view.getTag(); String nbr = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM)); String fromFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL)); String to_number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO)); //int read = cursor.getInt(cursor.getColumnIndex(SipMessage.FIELD_READ)); long date = cursor.getLong(cursor.getColumnIndex(SipMessage.FIELD_DATE)); tagView.fromFull = fromFull;/*w w w .j av a 2 s . c o m*/ tagView.to = to_number; tagView.from = nbr; tagView.position = cursor.getPosition(); /* Drawable background = (read == 0)? context.getResources().getDrawable(R.drawable.conversation_item_background_unread) : context.getResources().getDrawable(R.drawable.conversation_item_background_read); view.setBackgroundDrawable(background); */ String number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL)); CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, number); /* final Uri lookupUri = info.contactContentUri; final String name = info.name; final int ntype = info.numberType; final String label = info.phoneLabel; CharSequence formattedNumber = SipUri.getCanonicalSipContact(number, false); */ // Photo tagView.quickContactView.assignContactUri(info.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_light); // From tagView.fromView.setText(formatMessage(cursor)); //Date // Set the date/time field by mixing relative and absolute times. int flags = DateUtils.FORMAT_ABBREV_RELATIVE; tagView.dateView.setText(DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags)); }
From source file:com.csipsimple.ui.messages.ConversationsAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { super.bindView(view, context, cursor); final ConversationListItemViews tagView = (ConversationListItemViews) view.getTag(); String nbr = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM)); String fromFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL)); String to_number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO)); //int read = cursor.getInt(cursor.getColumnIndex(SipMessage.FIELD_READ)); long date = cursor.getLong(cursor.getColumnIndex(SipMessage.FIELD_DATE)); tagView.fromFull = fromFull;//from w w w . j a va2 s . c om tagView.to = to_number; tagView.from = nbr; tagView.position = cursor.getPosition(); /* Drawable background = (read == 0)? context.getResources().getDrawable(R.drawable.conversation_item_background_unread) : context.getResources().getDrawable(R.drawable.conversation_item_background_read); view.setBackgroundDrawable(background); */ String number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL)); CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, number); /* final Uri lookupUri = info.contactContentUri; final String name = info.name; final int ntype = info.numberType; final String label = info.phoneLabel; CharSequence formattedNumber = SipUri.getCanonicalSipContact(number, false); */ // Photo tagView.quickContactView.assignContactUri(info.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); // From tagView.fromView.setText(formatMessage(cursor)); //Date // Set the date/time field by mixing relative and absolute times. int flags = DateUtils.FORMAT_ABBREV_RELATIVE; tagView.dateView.setText(DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags)); }
From source file:com.abcvoipsip.ui.messages.ConverstationsAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { super.bindView(view, context, cursor); final ConversationListItemViews tagView = (ConversationListItemViews) view.getTag(); String nbr = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM)); String fromFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL)); String to_number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO)); //int read = cursor.getInt(cursor.getColumnIndex(SipMessage.FIELD_READ)); long date = cursor.getLong(cursor.getColumnIndex(SipMessage.FIELD_DATE)); tagView.fromFull = fromFull;/*from ww w.j ava 2s . c o m*/ tagView.to = to_number; tagView.from = nbr; tagView.position = cursor.getPosition(); /* Drawable background = (read == 0)? context.getResources().getDrawable(R.drawable.conversation_item_background_unread) : context.getResources().getDrawable(R.drawable.conversation_item_background_read); view.setBackgroundDrawable(background); */ String number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL)); CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, number); /* final Uri lookupUri = info.contactContentUri; final String name = info.name; final int ntype = info.numberType; final String label = info.phoneLabel; CharSequence formattedNumber = SipUri.getCanonicalSipContact(number, false); */ // Photo tagView.quickContactView.assignContactUri(info.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, SipHome.USE_LIGHT_THEME ? R.drawable.ic_contact_picture_holo_light : R.drawable.ic_contact_picture_holo_dark); // From tagView.fromView.setText(formatMessage(cursor)); //Date // Set the date/time field by mixing relative and absolute times. int flags = DateUtils.FORMAT_ABBREV_RELATIVE; tagView.dateView.setText(DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags)); }
From source file:dev.drsoran.moloko.sync.SyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/*w ww .j a v a 2 s. co m*/ if (shouldProcessRequest(extras)) { MolokoApp.Log.i(TAG, "Precessing sync with extras " + extras); ensureTransactionSupport(provider); this.syncResult = syncResult; context.sendBroadcast(Intents.createSyncStartedIntent()); String authToken = null; Service service = null; try { authToken = checkAccount(account); MolokoApp.Log.d(TAG, "Retrieved auth token " + authToken); if (authToken != null) { service = createService(account, authToken); molokoSyncResult = new MolokoSyncResult(context, syncResult); if (isSettingsOnlySync(extras)) { performSettingsSync(provider, service); } else { performFullSync(provider, service); } } else { invalidateAccount(authToken); } } catch (SyncException e) { if (syncResult.stats.numAuthExceptions > 0) { MolokoApp.Log.e(TAG, syncResult.stats.numAuthExceptions + " authentication exceptions. Invalidating auth token."); invalidateAccount(authToken); } MolokoApp.Log.e(TAG, "Applying sync operations batch failed. " + syncResult); clearSyncResult(syncResult); } finally { if (service != null) service.shutdown(); if (syncResult.stats.numIoExceptions > 0) MolokoApp.get(context.getApplicationContext()).getPeriodicSyncHander().delayNextSync(syncResult, (5 * DateUtils.MINUTE_IN_MILLIS) / 1000); this.syncResult = null; molokoSyncResult = null; context.sendBroadcast(Intents.createSyncFinishedIntent()); } } else { MolokoApp.Log.i(TAG, "Didn't processed sync with extras " + extras); } }
From source file:com.davidmiguel.gobees.apiary.ApiaryInfoFragment.java
@SuppressWarnings("ConstantConditions") @Override//from www .java2 s . c o m public void showInfo(Apiary apiary, Date lastRevisionDate) { // GENERAL INFO // Location if (apiary.hasLocation()) { String latLetter = (apiary.getLocationLat() > 0) ? "N" : "S"; String lonLetter = (apiary.getLocationLong() > 0) ? "E" : "W"; location.setText(apiary.getLocationLat() + latLetter + " / " + apiary.getLocationLong() + lonLetter); } // Num hives int num = apiary.getHives().size(); numHives.setText(getResources().getQuantityString(R.plurals.num_hives_plurals, num, num)); // Last revision if (lastRevisionDate != null) { lastRevision.setText(DateUtils.getRelativeTimeSpanString(lastRevisionDate.getTime(), (new Date()).getTime(), DateUtils.MINUTE_IN_MILLIS)); } // Notes if (Strings.isNullOrEmpty(apiary.getNotes())) { notes.setText(getString(R.string.no_notes)); } else { notes.setText(apiary.getNotes()); } // WEATHER // Hide card if no weather data exists if (apiary.getCurrentWeather() == null) { weatherCard.setVisibility(View.GONE); return; } // Weather Icon String iconId = apiary.getCurrentWeather().getWeatherConditionIcon(); weatherIcon.setImageResource(WeatherUtils.getWeatherIconResourceId(iconId)); // Temperature double temp = apiary.getCurrentWeather().getTemperature(); temperature.setText(WeatherUtils.formatTemperature(getContext(), temp)); // City String cityName = apiary.getCurrentWeather().getCityName(); city.setText(cityName); // Weather condition String weatherCondition = WeatherUtils.getStringForWeatherCondition(getContext(), apiary.getCurrentWeather().getWeatherCondition()); condition.setText(weatherCondition); // Humidity double hum = apiary.getCurrentWeather().getHumidity(); humidity.setText(WeatherUtils.formatHumidity(getContext(), hum)); // Pressure double pre = apiary.getCurrentWeather().getPressure(); pressure.setText(WeatherUtils.formatPressure(getContext(), pre)); // Wind double windSpeed = apiary.getCurrentWeather().getWindSpeed(); double windDegrees = apiary.getCurrentWeather().getWindDegrees(); wind.setText(WeatherUtils.formatWind(getContext(), windSpeed, windDegrees)); // Rain double rainVol = apiary.getCurrentWeather().getRain(); rain.setText(WeatherUtils.formatRainSnow(getContext(), rainVol)); // Snow double snowVol = apiary.getCurrentWeather().getSnow(); snow.setText(WeatherUtils.formatRainSnow(getContext(), snowVol)); // Last update String date = (String) DateUtils.getRelativeTimeSpanString( apiary.getCurrentWeather().getTimestamp().getTime(), (new Date()).getTime(), DateUtils.MINUTE_IN_MILLIS); updated.setText(date); }
From source file:android.support.v7.app.TwilightManager.java
private void updateState(@NonNull Location location) { final TwilightState state = sTwilightState; final long now = System.currentTimeMillis(); final TwilightCalculator calculator = TwilightCalculator.getInstance(); // calculate yesterday's twilight calculator.calculateTwilight(now - DateUtils.DAY_IN_MILLIS, location.getLatitude(), location.getLongitude());/* ww w.ja v a 2 s.com*/ final long yesterdaySunset = calculator.sunset; // calculate today's twilight calculator.calculateTwilight(now, location.getLatitude(), location.getLongitude()); final boolean isNight = (calculator.state == TwilightCalculator.NIGHT); final long todaySunrise = calculator.sunrise; final long todaySunset = calculator.sunset; // calculate tomorrow's twilight calculator.calculateTwilight(now + DateUtils.DAY_IN_MILLIS, location.getLatitude(), location.getLongitude()); final long tomorrowSunrise = calculator.sunrise; // Set next update long nextUpdate = 0; if (todaySunrise == -1 || todaySunset == -1) { // In the case the day or night never ends the update is scheduled 12 hours later. nextUpdate = now + 12 * DateUtils.HOUR_IN_MILLIS; } else { if (now > todaySunset) { nextUpdate += tomorrowSunrise; } else if (now > todaySunrise) { nextUpdate += todaySunset; } else { nextUpdate += todaySunrise; } // add some extra time to be on the safe side. nextUpdate += DateUtils.MINUTE_IN_MILLIS; } // Update the twilight state state.isNight = isNight; state.yesterdaySunset = yesterdaySunset; state.todaySunrise = todaySunrise; state.todaySunset = todaySunset; state.tomorrowSunrise = tomorrowSunrise; state.nextUpdate = nextUpdate; }
From source file:com.nextgis.firereporter.GetFiresService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); if (intent == null) return START_REDELIVER_INTENT; int nCommnad = intent.getIntExtra(COMMAND, SERVICE_START); SharedPreferences prefs = getSharedPreferences(MainActivity.PREFERENCES, MODE_PRIVATE | MODE_MULTI_PROCESS); long nUpdateInterval = prefs.getLong(SettingsActivity.KEY_PREF_INTERVAL + "_long", 30 * DateUtils.MINUTE_IN_MILLIS); //15 boolean bEnergyEconomy = prefs.getBoolean(SettingsActivity.KEY_PREF_SERVICE_BATT_SAVE, true); Log.d(MainActivity.TAG, "Received intent - id " + startId + ": " + intent + ", command:" + nCommnad); if ((nCommnad & SERVICE_START) != 0) { mUserNasaReceiver = intent.getParcelableExtra(RECEIVER); if (mUserNasaReceiver != null) { mnFilter = intent.getIntExtra(SOURCE, MainActivity.SRC_NASA | MainActivity.SRC_USER); if (mnCurrentExec < 1) { mUserNasaReceiver.send(SERVICE_START, new Bundle()); }//from w w w .ja va2 s .co m Log.d(MainActivity.TAG, "GetFiresService service started"); if ((mnFilter & MainActivity.SRC_NASA) != 0) { mnCurrentExec++; GetNasaData(false); } if ((mnFilter & MainActivity.SRC_USER) != 0) { mnCurrentExec++; GetUserData(false); } } // plan next start ScheduleNextUpdate(this, SERVICE_START | SERVICE_SCANEXSTART, nUpdateInterval, bEnergyEconomy); } if ((nCommnad & SERVICE_SCANEXSTART) != 0) { mScanexReceiver = intent.getParcelableExtra(RECEIVER_SCANEX); if (mScanexReceiver != null) { if (mnCurrentExec < 1) { mScanexReceiver.send(SERVICE_SCANEXSTART, new Bundle()); } Log.d(MainActivity.TAG, "GetFiresService service started"); GetScanexData(false); } // plan next start ScheduleNextUpdate(this, SERVICE_START | SERVICE_SCANEXSTART, nUpdateInterval, bEnergyEconomy); } if ((nCommnad & SERVICE_STOP) != 0) { Log.d(MainActivity.TAG, "GetFiresService service stopped"); ScheduleNextUpdate(this, SERVICE_DESTROY, 150, true); stopSelf(); } if ((nCommnad & SERVICE_DESTROY) != 0) { stopSelf(); } if ((nCommnad & SERVICE_DATA) != 0) { mUserNasaReceiver = intent.getParcelableExtra(RECEIVER); for (FireItem item : mmoFires.values()) { SendItem(item); } } if ((nCommnad & SERVICE_SCANEXDATA) != 0) { mScanexReceiver = intent.getParcelableExtra(RECEIVER_SCANEX); for (ScanexSubscriptionItem Item : mmoSubscriptions.values()) { SendScanexItem(Item); } } if ((nCommnad & SERVICE_SCANEXDATAUPDATE) != 0) { long nSubscirbeId = intent.getLongExtra(SUBSCRIPTION_ID, -1); long nNotificationId = intent.getLongExtra(NOTIFICATION_ID, -1); ScanexSubscriptionItem subscribe = mmoSubscriptions.get(nSubscirbeId); if (subscribe != null) { ScanexNotificationItem notification = subscribe.GetItems().get(nNotificationId); if (notification != null) { notification.setWatched(true); } } } if ((nCommnad & SERVICE_NOTIFY_DISMISSED) != 0) { nUserCount = 0; nNasaCount = 0; nScanexCount = 0; mInboxStyle = new NotificationCompat.InboxStyle(); mInboxStyle.setBigContentTitle(getString(R.string.stNewFireNotificationDetailes)); ScheduleNextUpdate(this, SERVICE_START | SERVICE_SCANEXSTART, nUpdateInterval, bEnergyEconomy); } return START_REDELIVER_INTENT; }
From source file:net.niyonkuru.koodroid.service.SessionService.java
@Override public void onHandleIntent(Intent intent) { if (DEBUG)//from w ww. ja v a 2 s . c om Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")"); int request = intent.getIntExtra(EXTRA_REQUEST, REQUEST_LOGIN); if (request == REQUEST_LOGOUT) { logout(); return; } final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER); final String email = intent.getStringExtra(EXTRA_EMAIL); final String password = intent.getStringExtra(EXTRA_PASSWORD); boolean broadcast = intent.getBooleanExtra(EXTRA_BROADCAST, false); /* totally ignore this request until full credentials are provided */ if (email == null || password == null) return; final long startLogin = System.currentTimeMillis(); final long lastLogin = mSettings.lastLogin(); /* if the last successful login is within the last 15 minutes */ if (startLogin - lastLogin <= DateUtils.MINUTE_IN_MILLIS * 15) { /* do a credentials check again the local data store */ if (email.equals(mSettings.email()) && password.equals(mSettings.password())) { if (broadcast) IntentUtils.callWidget(this, LOGIN_FINISHED); announce(receiver, STATUS_FINISHED); return; } } try { if (NetworkUtils.isConnected(this)) { /* announce to the caller that we are now running */ announce(receiver, STATUS_RUNNING); } else throw new ServiceException(getString(R.string.error_network_down)); if (mSettings.email() == null) { /* this is likely a new user */ Crittercism.leaveBreadcrumb(TAG + ": first_time_login"); } login(email, password); saveCookies(); if (DEBUG) Log.d(TAG, "login took " + (System.currentTimeMillis() - startLogin) + "ms"); } catch (IOException e) { if (DEBUG) Log.e(TAG, "Problem while logging in", e); /* if the exception was simply from an abort */ if (mPostRequest != null && mPostRequest.isAborted()) return; if (receiver != null) { // Pass back error to surface listener final Bundle bundle = new Bundle(); bundle.putString(Intent.EXTRA_TEXT, e.toString()); receiver.send(STATUS_ERROR, bundle); } return; /* do not announce success below */ } if (broadcast) IntentUtils.callWidget(this, LOGIN_FINISHED); announce(receiver, STATUS_FINISHED); }
From source file:com.roamprocess1.roaming4world.ui.messages.ConversationsAdapter.java
@SuppressLint("SdCardPath") @Override//w ww.j a v a2s. c om public void bindView(View view, Context context, Cursor cursor) { super.bindView(view, context, cursor); System.out.println("Conversationlist:bindView"); final ConversationListItemViews tagView = (ConversationListItemViews) view.getTag(); String nbr = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM)); String fromFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL)); String to_number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO)); int read = cursor.getInt(cursor.getColumnIndex(SipMessage.FIELD_READ)); long date = cursor.getLong(cursor.getColumnIndex(SipMessage.FIELD_DATE)); DBProvider db = new DBProvider(); Cursor cr = db.allMessage(to_number, fromFull, context); cr.moveToLast(); SipMessage msg1 = new SipMessage(cr); String lastMessage = msg1.getBodyContent(); if (lastMessage.contains("[Offline message -") && !nbr.equals("sip:registrar@kamailio.org")) { System.out.println("offline message"); String[] finalMessage = lastMessage.split("]"); lastMessage = finalMessage[finalMessage.length - 1]; } TextView txtview = (TextView) view.findViewById(R.id.subject); if (lastMessage.startsWith("R4WIMGTOCONTACTCHATSEND@@")) { txtview.setText("Image"); } else { txtview.setText(lastMessage); } tagView.fromFull = fromFull; tagView.to = to_number; tagView.from = nbr; tagView.position = cursor.getPosition(); /* Drawable background = (read == 0)? context.getResources().getDrawable(R.drawable.conversation_item_background_unread) : context.getResources().getDrawable(R.drawable.conversation_item_background_read); view.setBackgroundDrawable(background); */ String number = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL)); CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, number); // Photo tagView.quickContactView.assignContactUri(info.contactContentUri); Log.setLogLevel(6); Log.d("Conversation adapter number", number); String nu = StaticValues.getStripNumber(number); String path = "/sdcard/R4W/ProfilePic/" + nu + ".png"; System.out.println("msg adp out - path=" + path); File imageFile = new File(path); if (imageFile.exists()) { try { Bitmap bm = BitmapFactory.decodeFile(path); bm = ImageHelperCircular.getRoundedCornerBitmap(bm, bm.getWidth()); tagView.quickContactView.getImageView().setImageBitmap(bm); } catch (Exception e) { // TODO: handle exception try { tagView.quickContactView.getImageView().setImageURI(Uri.parse(path)); } catch (Exception e2) { ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); // TODO: handle exception } } } else { ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); } // From System.out.println("formatMessage(cursor):" + formatMessage(cursor)); tagView.fromView.setText(formatMessage(cursor)); //Date // Set the date/time field by mixing relative and absolute times. int flags = DateUtils.FORMAT_ABBREV_RELATIVE; tagView.dateView.setText(DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags)); }