Java Code Examples for android.text.format.DateUtils#FORMAT_ABBREV_RELATIVE
The following examples show how to use
android.text.format.DateUtils#FORMAT_ABBREV_RELATIVE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConversationsAdapter.java From CSipSimple with GNU General Public License v3.0 | 4 votes |
@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; 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)); }
Example 2
Source File: MessageAdapter.java From CSipSimple with GNU General Public License v3.0 | 4 votes |
@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 { // 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); } }
Example 3
Source File: MainActivity.java From samples with MIT License | 4 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { final long min; switch (item.getItemId()) { case R.id.min_0: min = 0l; break; case R.id.min_min: min = DateUtils.MINUTE_IN_MILLIS; break; case R.id.min_hour: min = DateUtils.HOUR_IN_MILLIS; break; case R.id.min_day: min = DateUtils.DAY_IN_MILLIS; break; default: min = -1; break; } if (min >= 0) { item.setChecked(true); mAdapter.setMinResolution(min); return true; } item.setChecked(!item.isChecked()); final int flag; switch (item.getItemId()) { case R.id.FORMAT_SHOW_TIME: flag = DateUtils.FORMAT_SHOW_TIME; break; case R.id.FORMAT_SHOW_WEEKDAY: flag = DateUtils.FORMAT_SHOW_WEEKDAY; break; case R.id.FORMAT_SHOW_YEAR: flag = DateUtils.FORMAT_SHOW_YEAR; break; case R.id.FORMAT_NO_YEAR: flag = DateUtils.FORMAT_NO_YEAR; break; case R.id.FORMAT_SHOW_DATE: flag = DateUtils.FORMAT_SHOW_DATE; break; case R.id.FORMAT_NO_MONTH_DAY: flag = DateUtils.FORMAT_NO_MONTH_DAY; break; case R.id.FORMAT_NO_NOON: flag = DateUtils.FORMAT_NO_NOON; break; case R.id.FORMAT_NO_MIDNIGHT: flag = DateUtils.FORMAT_NO_MIDNIGHT; break; case R.id.FORMAT_ABBREV_TIME: flag = DateUtils.FORMAT_ABBREV_TIME; break; case R.id.FORMAT_ABBREV_WEEKDAY: flag = DateUtils.FORMAT_ABBREV_WEEKDAY; break; case R.id.FORMAT_ABBREV_MONTH: flag = DateUtils.FORMAT_ABBREV_MONTH; break; case R.id.FORMAT_NUMERIC_DATE: flag = DateUtils.FORMAT_NUMERIC_DATE; break; case R.id.FORMAT_ABBREV_RELATIVE: flag = DateUtils.FORMAT_ABBREV_RELATIVE; break; case R.id.FORMAT_ABBREV_ALL: flag = DateUtils.FORMAT_ABBREV_ALL; break; default: throw new UnsupportedOperationException("unknown id"); } if (item.isChecked()) { mAdapter.addFlag(flag); } else { mAdapter.removeFlag(flag); } return true; }