List of usage examples for android.text.format DateUtils FORMAT_ABBREV_RELATIVE
int FORMAT_ABBREV_RELATIVE
To view the source code for android.text.format DateUtils FORMAT_ABBREV_RELATIVE.
Click Source Link
From source file:Main.java
/** * Twitter human friendly date./*from w ww . j a v a 2 s . c o m*/ * * @return the string */ public static CharSequence humanFriendlyDate(Long created) { return DateUtils.getRelativeTimeSpanString(created, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); }
From source file:org.pixmob.droidlink.ui.EventCursorAdapter.java
@Override public void bindView(View v, Context context, Cursor cursor) { final int state = cursor.getInt(cursor.getColumnIndexOrThrow(STATE)); final String name = cursor.getString(cursor.getColumnIndexOrThrow(NAME)); String number = cursor.getString(cursor.getColumnIndexOrThrow(NUMBER)); final long date = cursor.getLong(cursor.getColumnIndexOrThrow(CREATED)); if (number != null) { number = PhoneNumberUtils.formatNumber(number); }/*from ww w . j a va2 s . c o m*/ final int type = cursor.getInt(cursor.getColumnIndexOrThrow(TYPE)); final Integer typeResourceId = EVENT_ICONS.get(type); final CharSequence eventDate = DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); final String message = cursor.getString(cursor.getColumnIndexOrThrow(MESSAGE)); final String eventName; final String eventNumber; if (number == null) { eventName = context.getString(R.string.unknown_number); eventNumber = EMPTY; } else if (name == null) { eventName = number; eventNumber = EMPTY; } else { eventName = name; eventNumber = number; } TextView tv = (TextView) v.findViewById(R.id.event_name); tv.setText(eventName); tv = (TextView) v.findViewById(R.id.event_number); tv.setText(eventNumber); tv = (TextView) v.findViewById(R.id.event_date); tv.setText(eventDate); tv = (TextView) v.findViewById(R.id.event_message); tv.setText(message); ImageView iv = (ImageView) v.findViewById(R.id.event_icon); if (typeResourceId != null) { iv.setImageResource(typeResourceId); iv.setVisibility(View.VISIBLE); } else { iv.setVisibility(View.INVISIBLE); } iv = (ImageView) v.findViewById(R.id.event_state); if (state == EventsContract.PENDING_DELETE_STATE) { iv.setImageResource(R.drawable.pending_delete); iv.setVisibility(View.VISIBLE); } else if (state == EventsContract.PENDING_UPLOAD_STATE) { iv.setImageResource(R.drawable.pending_upload); iv.setVisibility(View.VISIBLE); } else { iv.setVisibility(View.GONE); } v.setTag(TAG_ID, cursor.getString(cursor.getColumnIndex(_ID))); }
From source file:com.csipsimple.ui.messages.MessageAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { final MessageListItemViews tagView = (MessageListItemViews) view.getTag(); SipMessage msg = new SipMessage(cursor); String number = msg.getRemoteNumber(); long date = msg.getDate(); String subject = msg.getBodyContent(); String errorTxt = msg.getErrorContent(); String mimeType = msg.getMimeType(); int type = msg.getType(); String timestamp = ""; if (System.currentTimeMillis() - date > 1000 * 60 * 60 * 24) { // If it was recieved one day ago or more display relative // timestamp - SMS like behavior int flags = DateUtils.FORMAT_ABBREV_RELATIVE; timestamp = (String) DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags); } else {/*from w ww .j a v a 2 s. co m*/ // If it has been recieved recently show time of reception - IM // like behavior timestamp = dateFormatter.format(new Date(date)); } tagView.dateView.setText(timestamp); // Delivery state if (type == SipMessage.MESSAGE_TYPE_QUEUED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.ic_email_pending); tagView.deliveredIndicator.setContentDescription(mContext.getString(R.string.status_pending)); } else if (type == SipMessage.MESSAGE_TYPE_FAILED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.ic_sms_mms_not_delivered); tagView.deliveredIndicator .setContentDescription(mContext.getString(R.string.undelivered_msg_dialog_title)); } else { tagView.deliveredIndicator.setVisibility(View.GONE); tagView.deliveredIndicator.setContentDescription(""); } if (TextUtils.isEmpty(errorTxt)) { tagView.errorView.setVisibility(View.GONE); } else { tagView.errorView.setVisibility(View.VISIBLE); tagView.errorView.setText(errorTxt); } // Subject tagView.contentView.setText(formatMessage(number, subject, mimeType)); if (msg.isOutgoing()) { setPhotoSide(tagView, ArrowPosition.LEFT); // Photo tagView.quickContactView.assignContactUri(personalInfo.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), personalInfo, R.drawable.ic_contact_picture_holo_dark); } else { setPhotoSide(tagView, ArrowPosition.RIGHT); // Contact CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, msg.getFullFrom()); // Photo tagView.quickContactView.assignContactUri(info.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); } }
From source file:ca.mudar.snoozy.ui.widget.HistoryCursorAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { super.bindView(view, context, cursor); /*/* w ww . j a va2 s . c o m*/ Get current cursor values */ final boolean isPowerOn = (1 == cursor.getInt(HistoryQuery.IS_POWER_ON)); final long timestamp = cursor.getLong(HistoryQuery.TIME_STAMP); final boolean isFirst = (1 == cursor.getInt(HistoryQuery.IS_FIRST)); final boolean isLast = (1 == cursor.getInt(HistoryQuery.IS_LAST)); final int batteryLevel = cursor.getInt(HistoryQuery.BATTERY_LEVEL); /* Prepare the data */ final String sPowerStatus = mResources.getString( isPowerOn ? R.string.history_item_power_connected : R.string.history_item_power_disconnected); final String sBatteryLevel = String.format(mResources.getString(R.string.history_item_battery_level), batteryLevel); final int resPowerStatusColor = mResources .getColor(isPowerOn ? R.color.card_row_highlight_color : R.color.card_row_color); String sTimestamp; String sDay; if (DateUtils.isToday(timestamp)) { sDay = mResources.getString(R.string.history_item_day_today); sTimestamp = (String) DateUtils.formatSameDayTime(timestamp, mMillis, 0, DateFormat.SHORT); // sTimestamp = (String) DateUtils.getRelativeTimeSpanString(timestamp,now, 0, 0); } else { sDay = (String) DateUtils.getRelativeTimeSpanString(timestamp, mMillis, DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); // sDay = sDay.substring(0,1).toUpperCase() + sDay.substring(1); sTimestamp = mTimeFormat.format(new Date(timestamp)); } sDay = sDay.substring(0, 1).toUpperCase() + sDay.substring(1); /* Set UI values */ ((TextView) view.findViewById(R.id.history_is_power_on)).setText(sPowerStatus); ((TextView) view.findViewById(R.id.history_is_power_on)).setTextColor(resPowerStatusColor); ((TextView) view.findViewById(R.id.history_timestamp)).setText(sTimestamp); ((TextView) view.findViewById(R.id.history_battery_level)).setText(sBatteryLevel); if (isFirst && isLast) { ((TextView) view.findViewById(R.id.history_day)).setText(sDay); view.findViewById(R.id.history_header).setVisibility(View.VISIBLE); view.setBackgroundResource(R.drawable.bg_cards_top_bottom); } else if (isLast) { ((TextView) view.findViewById(R.id.history_day)).setText(sDay); view.findViewById(R.id.history_header).setVisibility(View.VISIBLE); view.setBackgroundResource(R.drawable.bg_cards_top); } else if (isFirst) { view.findViewById(R.id.history_header).setVisibility(View.GONE); view.setBackgroundResource(R.drawable.bg_cards_bottom); } else { view.findViewById(R.id.history_header).setVisibility(View.GONE); view.setBackgroundResource(R.drawable.bg_cards_middle); } }
From source file:com.abcvoipsip.ui.messages.MessageAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { final MessageListItemViews tagView = (MessageListItemViews) view.getTag(); SipMessage msg = new SipMessage(cursor); String number = msg.getRemoteNumber(); long date = msg.getDate(); String subject = msg.getBodyContent(); String errorTxt = msg.getErrorContent(); String mimeType = msg.getMimeType(); int type = msg.getType(); String timestamp = ""; if (System.currentTimeMillis() - date > 1000 * 60 * 60 * 24) { // If it was recieved one day ago or more display relative // timestamp - SMS like behavior int flags = DateUtils.FORMAT_ABBREV_RELATIVE; timestamp = (String) DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags); } else {/*from w ww .j a v a 2 s. co m*/ // If it has been recieved recently show time of reception - IM // like behavior timestamp = dateFormatter.format(new Date(date)); } tagView.dateView.setText(timestamp); // Delivery state if (type == SipMessage.MESSAGE_TYPE_QUEUED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.ic_email_pending); tagView.deliveredIndicator.setContentDescription(mContext.getString(R.string.status_pending)); } else if (type == SipMessage.MESSAGE_TYPE_FAILED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.ic_sms_mms_not_delivered); tagView.deliveredIndicator .setContentDescription(mContext.getString(R.string.undelivered_msg_dialog_title)); } else { tagView.deliveredIndicator.setVisibility(View.GONE); tagView.deliveredIndicator.setContentDescription(""); } if (TextUtils.isEmpty(errorTxt)) { tagView.errorView.setVisibility(View.GONE); } else { tagView.errorView.setVisibility(View.VISIBLE); tagView.errorView.setText(errorTxt); } // Subject tagView.contentView.setText(formatMessage(number, subject, mimeType)); if (msg.isOutgoing()) { setPhotoSide(tagView, ArrowPosition.LEFT); // Photo tagView.quickContactView.assignContactUri(personalInfo.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), personalInfo, SipHome.USE_LIGHT_THEME ? R.drawable.ic_contact_picture_holo_light : R.drawable.ic_contact_picture_holo_dark); } else { setPhotoSide(tagView, ArrowPosition.RIGHT); // Contact CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, msg.getFullFrom()); // 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 source file:com.newcell.calltext.ui.messages.MessageAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { final MessageListItemViews tagView = (MessageListItemViews) view.getTag(); SipMessage msg = new SipMessage(cursor); String number = msg.getRemoteNumber(); long date = msg.getDate(); String subject = msg.getBodyContent(); String errorTxt = msg.getErrorContent(); String mimeType = msg.getMimeType(); int type = msg.getType(); String timestamp = ""; if (System.currentTimeMillis() - date > 1000 * 60 * 60 * 24) { // If it was received one day ago or more display relative // timestamp - SMS like behavior int flags = DateUtils.FORMAT_ABBREV_RELATIVE; timestamp = (String) DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, flags); } else {/*from w w w . j a v a 2s. co m*/ // If it has been received recently show time of reception - IM // like behavior timestamp = dateFormatter.format(new Date(date)); } tagView.dateView.setText(timestamp); // Delivery state if (type == SipMessage.MESSAGE_TYPE_QUEUED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.ic_email_pending); tagView.deliveredIndicator.setContentDescription(mContext.getString(R.string.status_pending)); } else if (type == SipMessage.MESSAGE_TYPE_FAILED) { tagView.deliveredIndicator.setVisibility(View.VISIBLE); tagView.deliveredIndicator.setImageResource(R.drawable.ic_sms_mms_not_delivered); tagView.deliveredIndicator .setContentDescription(mContext.getString(R.string.undelivered_msg_dialog_title)); } else { tagView.deliveredIndicator.setVisibility(View.GONE); tagView.deliveredIndicator.setContentDescription(""); } if (TextUtils.isEmpty(errorTxt)) { tagView.errorView.setVisibility(View.GONE); } else { tagView.errorView.setVisibility(View.VISIBLE); tagView.errorView.setText(errorTxt); } // Subject tagView.contentView.setText(formatMessage(number, subject, mimeType)); if (msg.isOutgoing()) { setPhotoSide(tagView, ArrowPosition.LEFT); // Photo tagView.quickContactView.assignContactUri(personalInfo.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), personalInfo, R.drawable.ic_contact_picture_holo_dark); } else { setPhotoSide(tagView, ArrowPosition.RIGHT); // Contact CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, msg.getFullFrom()); // Photo tagView.quickContactView.assignContactUri(info.contactContentUri); ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, tagView.quickContactView.getImageView(), info, R.drawable.ic_contact_picture_holo_dark); } }
From source file:com.todoroo.astrid.notes.CommentsController.java
/** Helper method to set the contents and visibility of each field */ private void bindView(View view, NoteOrUpdate item) { // name//w w w . j a va 2 s .c o m final TextView nameView = (TextView) view.findViewById(R.id.title); { nameView.setText(item.title); Linkify.addLinks(nameView, Linkify.ALL); } // date final TextView date = (TextView) view.findViewById(R.id.date); { CharSequence dateString = DateUtils.getRelativeTimeSpanString(item.createdAt, DateUtilities.now(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); date.setText(dateString); } // picture final ImageView commentPictureView = (ImageView) view.findViewById(R.id.comment_picture); setupImagePopupForCommentView(view, commentPictureView, item.commentBitmap, activity); }
From source file:com.bubblegum.traceratops.app.ui.adapters.plugins.AbsAdapterPlugin.java
private String systemTimeInMillisToSystemDateFormat(Context context, long millis) { return DateUtils.getRelativeDateTimeString(context, millis, DateUtils.SECOND_IN_MILLIS, 2 * DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString(); }
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;/* www . ja v a 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, 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 ww .j av a2 s . co 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_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)); }