List of usage examples for android.text.format DateUtils WEEK_IN_MILLIS
long WEEK_IN_MILLIS
To view the source code for android.text.format DateUtils WEEK_IN_MILLIS.
Click Source Link
From source file:org.tigase.mobile.chat.ChatAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder holder = (ViewHolder) view.getTag(); if (holder == null) { holder = new ViewHolder(); view.setTag(holder);/*from ww w.j a va 2 s. com*/ holder.nickname = (TextView) view.findViewById(R.id.chat_item_nickname); holder.webview = (TextView) view.findViewById(R.id.chat_item_body); holder.timestamp = (TextView) view.findViewById(R.id.chat_item_timestamp); holder.avatar = (ImageView) view.findViewById(R.id.user_avatar); holder.msgStatus = (ImageView) view.findViewById(R.id.msgStatus); } final int state = cursor.getInt(cursor.getColumnIndex(ChatTableMetaData.FIELD_STATE)); if (state == ChatTableMetaData.STATE_INCOMING || state == ChatTableMetaData.STATE_INCOMING_UNREAD) { final BareJID account = BareJID .bareJIDInstance(cursor.getString(cursor.getColumnIndex(ChatTableMetaData.FIELD_ACCOUNT))); final BareJID jid = BareJID .bareJIDInstance(cursor.getString(cursor.getColumnIndex(ChatTableMetaData.FIELD_JID))); setAvatarForJid(holder.avatar, jid, cursor); JaxmppCore jaxmpp = ((MessengerApplication) context.getApplicationContext()).getMultiJaxmpp() .get(account); RosterItem ri = jaxmpp.getRoster().get(jid); holder.nickname.setText(ri == null ? jid.toString() : RosterDisplayTools.getDisplayName(ri)); holder.nickname.setTextColor(context.getResources().getColor(R.color.message_his_text)); holder.webview.setTextColor(context.getResources().getColor(R.color.message_his_text)); holder.timestamp.setTextColor(context.getResources().getColor(R.color.message_his_text)); view.setBackgroundColor(context.getResources().getColor(R.color.message_his_background)); holder.msgStatus.setVisibility(View.GONE); } else if (state == ChatTableMetaData.STATE_OUT_NOT_SENT || state == ChatTableMetaData.STATE_OUT_SENT) { final BareJID jid = BareJID .bareJIDInstance(cursor.getString(cursor.getColumnIndex(ChatTableMetaData.FIELD_AUTHOR_JID))); setAvatarForJid(holder.avatar, jid, cursor); holder.nickname.setText(this.nickname == null ? jid.getLocalpart() : this.nickname); holder.nickname.setTextColor(context.getResources().getColor(R.color.message_mine_text)); holder.webview.setTextColor(context.getResources().getColor(R.color.message_mine_text)); holder.timestamp.setTextColor(context.getResources().getColor(R.color.message_mine_text)); if (state == ChatTableMetaData.STATE_OUT_SENT) { int recpt = cursor.getInt(cursor.getColumnIndex(ChatTableMetaData.FIELD_RECEIPT_STATUS)); if (recpt == 1) { holder.msgStatus.setImageResource(R.drawable.message_sent); holder.msgStatus.setVisibility(View.GONE); } else if (recpt == 2) { holder.msgStatus.setImageResource(R.drawable.message_delivered); holder.msgStatus.setVisibility(View.VISIBLE); } else holder.msgStatus.setVisibility(View.GONE); } else if (state == ChatTableMetaData.STATE_OUT_NOT_SENT) { holder.msgStatus.setImageResource(R.drawable.message_not_sent); holder.msgStatus.setVisibility(View.VISIBLE); } view.setBackgroundColor(context.getResources().getColor(R.color.message_mine_background)); } else { holder.msgStatus.setVisibility(View.GONE); holder.nickname.setText("?"); } // java.text.DateFormat df = DateFormat.getTimeFormat(context); final String txt = EscapeUtils .escape(cursor.getString(cursor.getColumnIndex(ChatTableMetaData.FIELD_BODY))); Spanned sp = Html.fromHtml(txt.replace("\n", "<br/>")); holder.webview.setText(sp); // webview.setMinimumHeight(webview.getMeasuredHeight()); // Date t = new // Date(cursor.getLong(cursor.getColumnIndex(ChatTableMetaData.FIELD_TIMESTAMP))); // holder.timestamp.setText(df.format(t)); long ts = cursor.getLong(cursor.getColumnIndex(ChatTableMetaData.FIELD_TIMESTAMP)); CharSequence tsStr = // DateUtils.isToday(ts) // ? DateUtils.getRelativeTimeSpanString(ts, System.currentTimeMillis(), // DateUtils.MINUTE_IN_MILLIS) : DateUtils.getRelativeDateTimeString(mContext, ts, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0); holder.timestamp.setText(tsStr); }
From source file:org.tigase.mobile.muc.MucAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder holder = (ViewHolder) view.getTag(); if (holder == null) { holder = new ViewHolder(); view.setTag(holder);//from w w w . j a va 2 s .com holder.nickname = (TextView) view.findViewById(R.id.chat_item_nickname); holder.body = (TextView) view.findViewById(R.id.chat_item_body); holder.bodySelf = (TextView) view.findViewById(R.id.chat_item_body_self); holder.timestamp = (TextView) view.findViewById(R.id.chat_item_timestamp); holder.avatar = (ImageView) view.findViewById(R.id.user_avatar); } holder.nickname.setOnClickListener(nickameClickListener); final int state = cursor.getInt(cursor.getColumnIndex(ChatTableMetaData.FIELD_STATE)); // byte[] avatarData = // cursor.getBlob(cursor.getColumnIndex(VCardsCacheTableMetaData.FIELD_DATA)); holder.avatar.setVisibility(View.GONE); // final BareJID account = // BareJID.bareJIDInstance(cursor.getString(cursor.getColumnIndex(ChatTableMetaData.FIELD_ACCOUNT))); final String nick = cursor.getString(cursor.getColumnIndex(ChatTableMetaData.FIELD_AUTHOR_NICKNAME)); // JaxmppCore jaxmpp = ((MessengerApplication) // context.getApplicationContext()).getMultiJaxmpp().get(account); holder.nickname.setText(nick); final String bd = cursor.getString(cursor.getColumnIndex(ChatTableMetaData.FIELD_BODY)); if (nick != null && nick.equals(room.getNickname())) { holder.nickname.setTextColor(context.getResources().getColor(R.color.mucmessage_mine_nickname)); holder.body.setTextColor(context.getResources().getColor(R.color.mucmessage_mine_text)); holder.bodySelf.setTextColor(context.getResources().getColor(R.color.mucmessage_mine_text)); holder.timestamp.setTextColor(context.getResources().getColor(R.color.mucmessage_mine_text)); view.setBackgroundColor(context.getResources().getColor(R.color.mucmessage_mine_background)); } else { int colorRes = getOccupantColor(nick); if (bd.contains(room.getNickname())) { view.setBackgroundColor(context.getResources().getColor(R.color.mucmessage_his_background_marked)); } else { view.setBackgroundColor(context.getResources().getColor(R.color.mucmessage_his_background)); } holder.nickname.setTextColor(context.getResources().getColor(colorRes)); holder.body.setTextColor(context.getResources().getColor(R.color.mucmessage_his_text)); holder.bodySelf.setTextColor(context.getResources().getColor(colorRes)); holder.timestamp.setTextColor(context.getResources().getColor(R.color.mucmessage_his_text)); } // java.text.DateFormat df = DateFormat.getTimeFormat(context); if (bd != null && bd.startsWith("/me ")) { holder.body.setVisibility(View.GONE); holder.bodySelf.setVisibility(View.VISIBLE); String t = bd.substring(4); final String txt = EscapeUtils.escape(t); holder.bodySelf.setText(Html.fromHtml( txt.replace("\n", "<br/>").replace(room.getNickname(), "<b>" + room.getNickname() + "</b>"))); } else { holder.body.setVisibility(View.VISIBLE); holder.bodySelf.setVisibility(View.GONE); final String txt = EscapeUtils.escape(bd); holder.body.setText(Html.fromHtml( txt.replace("\n", "<br/>").replace(room.getNickname(), "<b>" + room.getNickname() + "</b>"))); } // webview.setMinimumHeight(webview.getMeasuredHeight()); // Date t = new // Date(cursor.getLong(cursor.getColumnIndex(ChatTableMetaData.FIELD_TIMESTAMP))); // holder.timestamp.setText(df.format(t)); long ts = cursor.getLong(cursor.getColumnIndex(ChatTableMetaData.FIELD_TIMESTAMP)); CharSequence tsStr = // DateUtils.isToday(ts) // ? DateUtils.getRelativeTimeSpanString(ts, System.currentTimeMillis(), // DateUtils.MINUTE_IN_MILLIS) : DateUtils.getRelativeDateTimeString(mContext, ts, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0); holder.timestamp.setText(tsStr); }
From source file:io.github.hidroh.materialistic.AppUtils.java
public static String getAbbreviatedTimeSpan(long timeMillis) { long span = Math.max(System.currentTimeMillis() - timeMillis, 0); if (span >= DateUtils.YEAR_IN_MILLIS) { return (span / DateUtils.YEAR_IN_MILLIS) + ABBR_YEAR; }/*from ww w .ja v a 2s . co m*/ if (span >= DateUtils.WEEK_IN_MILLIS) { return (span / DateUtils.WEEK_IN_MILLIS) + ABBR_WEEK; } if (span >= DateUtils.DAY_IN_MILLIS) { return (span / DateUtils.DAY_IN_MILLIS) + ABBR_DAY; } if (span >= DateUtils.HOUR_IN_MILLIS) { return (span / DateUtils.HOUR_IN_MILLIS) + ABBR_HOUR; } return (span / DateUtils.MINUTE_IN_MILLIS) + ABBR_MINUTE; }
From source file:com.kncwallet.wallet.ui.ReceiveFragment.java
private void updateBalanceView() { if (!isAdded()) return;/*from www . j a v a 2s. c o m*/ final boolean showProgress; if (bestChainDate != null) { final long blockchainLag = System.currentTimeMillis() - bestChainDate.getTime(); final boolean blockchainUptodate = blockchainLag < Constants.BLOCKCHAIN_UPTODATE_THRESHOLD_MS; final boolean downloadOk = download == BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK; showProgress = !(blockchainUptodate || !replaying); final String downloading = getString(downloadOk ? R.string.blockchain_state_progress_downloading : R.string.blockchain_state_progress_stalled); if (blockchainLag < 2 * DateUtils.DAY_IN_MILLIS) { final long hours = blockchainLag / DateUtils.HOUR_IN_MILLIS; viewProgress.setText(getString(R.string.blockchain_state_progress_hours, downloading, hours)); } else if (blockchainLag < 2 * DateUtils.WEEK_IN_MILLIS) { final long days = blockchainLag / DateUtils.DAY_IN_MILLIS; viewProgress.setText(getString(R.string.blockchain_state_progress_days, downloading, days)); } else if (blockchainLag < 90 * DateUtils.DAY_IN_MILLIS) { final long weeks = blockchainLag / DateUtils.WEEK_IN_MILLIS; viewProgress.setText(getString(R.string.blockchain_state_progress_weeks, downloading, weeks)); } else { final long months = blockchainLag / (30 * DateUtils.DAY_IN_MILLIS); viewProgress.setText(getString(R.string.blockchain_state_progress_months, downloading, months)); } } else { showProgress = false; } if (!showProgress) { viewBalance.setVisibility(View.VISIBLE); if (balance != null) { final String precision = prefs.getString(Constants.PREFS_KEY_BTC_PRECISION, Constants.PREFS_DEFAULT_BTC_PRECISION); final int btcPrecision = precision.charAt(0) - '0'; final int btcShift = precision.length() == 3 ? precision.charAt(2) - '0' : 0; final String prefix = DenominationUtil.getCurrencyCode(btcShift); viewBalanceBtc.setVisibility(View.VISIBLE); viewBalanceBtc.setPrecision(btcPrecision, btcShift); viewBalanceBtc.setSuffix(prefix); viewBalanceBtc.setAmount(balance); } else { viewBalanceBtc.setVisibility(View.INVISIBLE); } viewProgress.setVisibility(View.GONE); } else { viewProgress.setVisibility(View.VISIBLE); viewBalance.setVisibility(View.INVISIBLE); } if (exchangeRate != null && exchangeRate.rate != null && balance != null) { final BigInteger localValue = WalletUtils.localValue(balance, exchangeRate.rate); viewBalanceLocal.setSuffix(exchangeRate.currencyCode); viewBalanceLocal.setAmount(localValue); viewBalanceLocal.setTextColor(getResources().getColor(R.color.knc_highlight)); } }
From source file:com.kncwallet.wallet.ui.HomeFragment.java
private void updateBalanceView() { if (!isAdded()) return;/* w w w .j a va 2 s. c o m*/ final boolean showProgress; if (bestChainDate != null) { final long blockchainLag = System.currentTimeMillis() - bestChainDate.getTime(); final boolean blockchainUptodate = blockchainLag < Constants.BLOCKCHAIN_UPTODATE_THRESHOLD_MS; final boolean downloadOk = download == BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK; showProgress = !(blockchainUptodate || !replaying); final String downloading = getString(downloadOk ? R.string.blockchain_state_progress_downloading : R.string.blockchain_state_progress_stalled); if (blockchainLag < 2 * DateUtils.DAY_IN_MILLIS) { final long hours = blockchainLag / DateUtils.HOUR_IN_MILLIS; viewProgress.setText(getString(R.string.blockchain_state_progress_hours, downloading, hours)); } else if (blockchainLag < 2 * DateUtils.WEEK_IN_MILLIS) { final long days = blockchainLag / DateUtils.DAY_IN_MILLIS; viewProgress.setText(getString(R.string.blockchain_state_progress_days, downloading, days)); } else if (blockchainLag < 90 * DateUtils.DAY_IN_MILLIS) { final long weeks = blockchainLag / DateUtils.WEEK_IN_MILLIS; viewProgress.setText(getString(R.string.blockchain_state_progress_weeks, downloading, weeks)); } else { final long months = blockchainLag / (30 * DateUtils.DAY_IN_MILLIS); viewProgress.setText(getString(R.string.blockchain_state_progress_months, downloading, months)); } } else { showProgress = false; } if (!showProgress) { viewBalance.setVisibility(View.VISIBLE); if (balance != null) { final String precision = prefs.getString(Constants.PREFS_KEY_BTC_PRECISION, Constants.PREFS_DEFAULT_BTC_PRECISION); final int btcPrecision = precision.charAt(0) - '0'; final int btcShift = precision.length() == 3 ? precision.charAt(2) - '0' : 0; final String prefix = DenominationUtil.getCurrencyCode(btcShift); if (viewBalanceLocal.getVisibility() != View.VISIBLE) { viewBalanceBtc.setVisibility(View.VISIBLE); } viewBalanceBtc.setPrecision(btcPrecision, btcShift); viewBalanceBtc.setSuffix(prefix); viewBalanceBtc.setAmount(balance); } else { viewBalanceBtc.setVisibility(View.INVISIBLE); } viewProgress.setVisibility(View.GONE); } else { viewProgress.setVisibility(View.VISIBLE); viewBalance.setVisibility(View.INVISIBLE); } if (exchangeRate != null && exchangeRate.rate != null && balance != null) { final BigInteger localValue = WalletUtils.localValue(balance, exchangeRate.rate); viewBalanceLocal.setSuffix(exchangeRate.currencyCode); viewBalanceLocal.setAmount(localValue); viewBalanceLocal.setTextColor(getResources().getColor(R.color.knc_highlight)); } }
From source file:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {//from w w w.j ava 2 s . c om Context context = getContext(); App.getApiManager().getEarthquakeService().getData().enqueue(new Callback<EarthquakeObject>() { @Override public void onResponse(Call<EarthquakeObject> call, Response<EarthquakeObject> response) { EarthquakeObject earthquake = response.body(); Vector<ContentValues> cVVector = new Vector<>(earthquake.getFeatures().size()); double currentBiggest = 0.0; ContentValues notifyValues = null; for (Feature each : earthquake.getFeatures()) { ContentValues earthquakeValues = new ContentValues(); earthquakeValues.put(EarthquakeColumns.PLACE, each.getProperties().getPlace()); earthquakeValues.put(EarthquakeColumns.ID_EARTH, each.getId()); earthquakeValues.put(EarthquakeColumns.MAG, each.getProperties().getMag()); earthquakeValues.put(EarthquakeColumns.TYPE, each.getProperties().getType()); earthquakeValues.put(EarthquakeColumns.ALERT, each.getProperties().getAlert()); earthquakeValues.put(EarthquakeColumns.TIME, each.getProperties().getTime()); earthquakeValues.put(EarthquakeColumns.URL, each.getProperties().getUrl()); earthquakeValues.put(EarthquakeColumns.DETAIL, each.getProperties().getDetail()); earthquakeValues.put(EarthquakeColumns.DEPTH, each.getGeometry().getCoordinates().get(2)); earthquakeValues.put(EarthquakeColumns.LONGITUDE, each.getGeometry().getCoordinates().get(0)); earthquakeValues.put(EarthquakeColumns.LATITUDE, each.getGeometry().getCoordinates().get(1)); LatLng latLng = new LatLng(each.getGeometry().getCoordinates().get(1), each.getGeometry().getCoordinates().get(0)); LatLng location = LocationUtils.getLocation(context); earthquakeValues.put(EarthquakeColumns.DISTANCE, LocationUtils.getDistance(latLng, location)); cVVector.add(earthquakeValues); if (each.getProperties().getMag() != null && each.getProperties().getMag() > currentBiggest) { currentBiggest = each.getProperties().getMag(); notifyValues = new ContentValues(earthquakeValues); notifyValues.put(EarthquakeColumns.PLACE, Utilities.formatEarthquakePlace(each.getProperties().getPlace())); } } int inserted = 0; // add to database ContentResolver resolver = context.getContentResolver(); if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = resolver.bulkInsert(EarthquakeColumns.CONTENT_URI, cvArray); } // Set the date to day minus one to delete old data from the database Date date = new Date(); date.setTime(date.getTime() - DateUtils.DAY_IN_MILLIS); int deleted = resolver.delete(EarthquakeColumns.CONTENT_URI, EarthquakeColumns.TIME + " <= ?", new String[] { String.valueOf(date.getTime()) }); Log.v(TAG, "Service Complete. " + inserted + " Inserted, " + deleted + " deleted"); sendNotification(notifyValues); } @Override public void onFailure(Call<EarthquakeObject> call, Throwable t) { Log.e(TAG, "onFailure: " + t.toString()); } }); App.getNewsManager().getNewsService().getNews().enqueue(new Callback<Rss>() { @Override public void onResponse(Call<Rss> call, Response<Rss> response) { Channel news = response.body().getChannel(); Vector<ContentValues> cVVector = new Vector<>(news.getItem().size()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.getDefault()); Date date = new Date(); for (Item each : news.getItem()) { ContentValues weatherValues = new ContentValues(); try { date = simpleDateFormat.parse(each.getPubDate()); } catch (ParseException e) { Log.e(TAG, "e:" + e); } weatherValues.put(NewsColumns.DATE, date.getTime()); weatherValues.put(NewsColumns.TITLE, each.getTitle()); weatherValues.put(NewsColumns.DESCRIPTION, Html.toHtml(new SpannedString(each.getDescription()))); weatherValues.put(NewsColumns.URL, each.getLink()); weatherValues.put(NewsColumns.GUID, each.getGuid().getContent()); cVVector.add(weatherValues); } int inserted = 0; // add to database ContentResolver resolver = getContext().getContentResolver(); if (cVVector.size() > 0) { // Student: call bulkInsert to add the weatherEntries to the database here ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = resolver.bulkInsert(NewsColumns.CONTENT_URI, cvArray); } // Set the date to day minus two to delete old data from the database date = new Date(); date.setTime(date.getTime() - DateUtils.DAY_IN_MILLIS * 3); int deleted = resolver.delete(NewsColumns.CONTENT_URI, NewsColumns.DATE + " <= ?", new String[] { String.valueOf(date.getTime()) }); } @Override public void onFailure(Call<Rss> call, Throwable t) { Log.e(TAG, "onFailure: " + t.toString()); } }); // TODO: 4/22/16 possible refactoring //checking the last update and notify if it' the first of the day SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String lastNotificationKey = context.getString(R.string.sharedprefs_key_last_countupdate); long lastSync = prefs.getLong(lastNotificationKey, DateUtils.DAY_IN_MILLIS); if (System.currentTimeMillis() - lastSync >= Utilities.getSyncIntervalPrefs(context) * DateUtils.SECOND_IN_MILLIS) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US); Date date = new Date(System.currentTimeMillis()); String startTime[] = new String[] { simpleDateFormat.format(date.getTime() - DateUtils.YEAR_IN_MILLIS), simpleDateFormat.format(date.getTime() - DateUtils.DAY_IN_MILLIS * 30), simpleDateFormat.format(date.getTime() - DateUtils.WEEK_IN_MILLIS), simpleDateFormat.format(date.getTime() - DateUtils.DAY_IN_MILLIS) }; String endTime = simpleDateFormat.format(date); int iterator = 1; while (iterator < CountColumns.ALL_COLUMNS.length) { final int round = iterator; App.getApiManager().getEarthquakeService().getEarthquakeStats(startTime[round - 1], endTime) .enqueue(new Callback<CountEarthquakes>() { @Override public void onResponse(Call<CountEarthquakes> call, Response<CountEarthquakes> response) { ContentValues count = new ContentValues(); count.put(CountColumns.ALL_COLUMNS[round], response.body().getCount()); ContentResolver contentResolver = context.getContentResolver(); Cursor cursor = contentResolver.query(CountColumns.CONTENT_URI, null, null, null, null); if (cursor != null) { if (cursor.getCount() < 1) { long inserted = ContentUris .parseId(contentResolver.insert(CountColumns.CONTENT_URI, count)); //Log.d(TAG, "inserted:" + inserted); } else { int updated = contentResolver.update(CountColumns.CONTENT_URI, count, CountColumns._ID + " = ?", new String[] { "1" }); //Log.d(TAG, "updated: " + updated); } cursor.close(); } } @Override public void onFailure(Call<CountEarthquakes> call, Throwable t) { Log.e(TAG, "Error: " + t); } }); iterator++; } //refreshing last sync prefs.edit().putLong(lastNotificationKey, System.currentTimeMillis()).apply(); } // notify PagerActivity that data has been updated context.getContentResolver().notifyChange(EarthquakeColumns.CONTENT_URI, null, false); context.getContentResolver().notifyChange(NewsColumns.CONTENT_URI, null, false); context.getContentResolver().notifyChange(CountColumns.CONTENT_URI, null, false); updateWidgets(); }
From source file:com.android.exchange.eas.EasSync.java
private void addOneCollectionToRequest(final Serializer s, final int collectionType, final String mailboxServerId, final String mailboxSyncKey, final List<MessageStateChange> stateChanges) throws IOException { s.start(Tags.SYNC_COLLECTION);// w ww . ja va 2 s. co m if (getProtocolVersion() < Eas.SUPPORTED_PROTOCOL_EX2007_SP1_DOUBLE) { s.data(Tags.SYNC_CLASS, Eas.getFolderClass(collectionType)); } s.data(Tags.SYNC_SYNC_KEY, mailboxSyncKey); s.data(Tags.SYNC_COLLECTION_ID, mailboxServerId); if (getProtocolVersion() >= Eas.SUPPORTED_PROTOCOL_EX2007_DOUBLE) { // Exchange 2003 doesn't understand the concept of setting this flag to false. The // documentation indicates that its presence alone, with no value, requests a two-way // sync. // TODO: handle downsync here so we don't need this at all s.data(Tags.SYNC_GET_CHANGES, "0"); } s.start(Tags.SYNC_COMMANDS); for (final MessageStateChange change : stateChanges) { s.start(Tags.SYNC_CHANGE); s.data(Tags.SYNC_SERVER_ID, change.getServerId()); s.start(Tags.SYNC_APPLICATION_DATA); final int newFlagRead = change.getNewFlagRead(); if (newFlagRead != MessageStateChange.VALUE_UNCHANGED) { s.data(Tags.EMAIL_READ, Integer.toString(newFlagRead)); } final int newFlagFavorite = change.getNewFlagFavorite(); if (newFlagFavorite != MessageStateChange.VALUE_UNCHANGED) { // "Flag" is a relatively complex concept in EAS 12.0 and above. It is not only // the boolean "favorite" that we think of in Gmail, but it also represents a // follow up action, which can include a subject, start and due dates, and even // recurrences. We don't support any of this as yet, but EAS 12.0 and higher // require that a flag contain a status, a type, and four date fields, two each // for start date and end (due) date. if (newFlagFavorite != 0) { // Status 2 = set flag s.start(Tags.EMAIL_FLAG).data(Tags.EMAIL_FLAG_STATUS, "2"); // "FollowUp" is the standard type s.data(Tags.EMAIL_FLAG_TYPE, "FollowUp"); final long now = System.currentTimeMillis(); final Calendar calendar = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT")); calendar.setTimeInMillis(now); // Flags are required to have a start date and end date (duplicated) // First, we'll set the current date/time in GMT as the start time String utc = formatDateTime(calendar); s.data(Tags.TASK_START_DATE, utc).data(Tags.TASK_UTC_START_DATE, utc); // And then we'll use one week from today for completion date calendar.setTimeInMillis(now + DateUtils.WEEK_IN_MILLIS); utc = formatDateTime(calendar); s.data(Tags.TASK_DUE_DATE, utc).data(Tags.TASK_UTC_DUE_DATE, utc); s.end(); } else { s.tag(Tags.EMAIL_FLAG); } } s.end().end(); // SYNC_APPLICATION_DATA, SYNC_CHANGE } s.end().end(); // SYNC_COMMANDS, SYNC_COLLECTION }
From source file:com.vuze.android.remote.activity.RcmActivity.java
@Override public void onExtraViewVisibilityChange(final View view, int visibility) { {/*from ww w . j a v a 2s . com*/ if (visibility != View.VISIBLE) { if (pullRefreshHandler != null) { pullRefreshHandler.removeCallbacksAndMessages(null); pullRefreshHandler = null; } return; } if (pullRefreshHandler != null) { pullRefreshHandler.removeCallbacks(null); pullRefreshHandler = null; } pullRefreshHandler = new Handler(Looper.getMainLooper()); pullRefreshHandler.postDelayed(new Runnable() { @Override public void run() { if (isFinishing()) { return; } long sinceMS = System.currentTimeMillis() - lastUpdated; String since = DateUtils.getRelativeDateTimeString(RcmActivity.this, lastUpdated, DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0).toString(); String s = getResources().getString(R.string.last_updated, since); TextView tvSwipeText = (TextView) view.findViewById(R.id.swipe_text); tvSwipeText.setText(s); if (pullRefreshHandler == null) { return; } pullRefreshHandler.postDelayed(this, sinceMS < DateUtils.MINUTE_IN_MILLIS ? DateUtils.SECOND_IN_MILLIS : sinceMS < DateUtils.HOUR_IN_MILLIS ? DateUtils.MINUTE_IN_MILLIS : DateUtils.HOUR_IN_MILLIS); } }, 0); } }
From source file:com.xandy.calendar.month.MonthByWeekFragment.java
@Override protected void setMonthDisplayed(Time time, boolean updateHighlight) { super.setMonthDisplayed(time, updateHighlight); if (!mIsMiniMonth) { boolean useSelected = false; if (time.year == mDesiredDay.year && time.month == mDesiredDay.month) { mSelectedDay.set(mDesiredDay); mAdapter.setSelectedDay(mDesiredDay); useSelected = true;/*from ww w .jav a 2 s . c o m*/ } else { mSelectedDay.set(time); mAdapter.setSelectedDay(time); } CalendarController controller = CalendarController.getInstance(mContext); if (mSelectedDay.minute >= 30) { mSelectedDay.minute = 30; } else { mSelectedDay.minute = 0; } long newTime = mSelectedDay.normalize(true); if (newTime != controller.getTime() && mUserScrolled) { long offset = useSelected ? 0 : DateUtils.WEEK_IN_MILLIS * mNumWeeks / 3; controller.setTime(newTime + offset); } controller.sendEvent(this, EventType.UPDATE_TITLE, time, time, time, -1, ViewType.CURRENT, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_MONTH_DAY | DateUtils.FORMAT_SHOW_YEAR, null, null); } }
From source file:com.vuze.android.remote.fragment.TorrentListFragment.java
private LastUpdatedInfo getLastUpdatedString() { FragmentActivity activity = getActivity(); if (activity == null) { return null; }//from w w w .jav a 2s. c om long lastUpdated = sessionInfo == null ? 0 : sessionInfo.getLastTorrentListReceivedOn(); long sinceMS = System.currentTimeMillis() - lastUpdated; String since = DateUtils.getRelativeDateTimeString(activity, lastUpdated, DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0).toString(); String s = activity.getResources().getString(R.string.last_updated, since); return new LastUpdatedInfo(sinceMS, s); }