Example usage for android.text.format DateUtils getRelativeTimeSpanString

List of usage examples for android.text.format DateUtils getRelativeTimeSpanString

Introduction

In this page you can find the example usage for android.text.format DateUtils getRelativeTimeSpanString.

Prototype

public static CharSequence getRelativeTimeSpanString(long time, long now, long minResolution, int flags) 

Source Link

Document

Returns a string describing 'time' as a time relative to 'now'.

Usage

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 . 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.example.xyzreader.ui.articlelist.ArticleListAdapter.java

@Override
public void onBindViewHolder(final ViewHolder viewHolder, Cursor cursor) {

    // set up the animation per the xml files
    int position = cursor.getPosition();
    Animation animation = AnimationUtils.loadAnimation(mContext,
            (position > mLastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
    viewHolder.itemView.startAnimation(animation);
    mLastPosition = position;/* www .j  a  v a2 s.  c  o  m*/

    //show the thumb image (with progress spinner) or the "not found" image
    viewHolder.mArticleListImageProgressBar.setVisibility(View.VISIBLE);
    Picasso.with(mContext).load(cursor.getString(ArticleLoader.Query.THUMB_URL))
            .into(viewHolder.mArticleListImageView, new Callback() {
                @Override
                public void onSuccess() {
                    viewHolder.mArticleListImageProgressBar.setVisibility(View.GONE);
                }

                @Override
                public void onError() {
                    viewHolder.mArticleListImageView.setImageResource(R.mipmap.ic_launcher);
                }
            });

    // show the title and byline
    viewHolder.mArticleListItemTitle.setText(cursor.getString(ArticleLoader.Query.TITLE));
    String byLine = DateUtils
            .getRelativeTimeSpanString(cursor.getLong(ArticleLoader.Query.PUBLISHED_DATE),
                    System.currentTimeMillis(), DateUtils.HOUR_IN_MILLIS, DateUtils.FORMAT_ABBREV_ALL)
            .toString() + " by " + cursor.getString(ArticleLoader.Query.AUTHOR);
    viewHolder.mArticleListItemByLine.setText(byLine);
}

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.  jav a 2s. 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));
}

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  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, 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:com.example.xyzreader.ui.DetailFragment.java

private void bindViews() {
    if (mRootView == null) {
        return;/*from   w w  w . j  a v  a 2 s.c  o m*/
    }

    TextView titleView = (TextView) mRootView.findViewById(R.id.article_title);
    TextView bylineView = (TextView) mRootView.findViewById(R.id.article_byline);
    TextView bodyView = (TextView) mRootView.findViewById(R.id.article_body);

    if (mCursor != null) {

        String title = mCursor.getString(ArticleLoader.Query.TITLE);
        final String shareText = getString(R.string.share_text) + " "
                + mCursor.getString(ArticleLoader.Query.TITLE);

        mRootView.findViewById(R.id.share_fab).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(
                        Intent.createChooser(ShareCompat.IntentBuilder.from(getActivity()).setType("text/plain")
                                .setText(shareText).getIntent(), getString(R.string.action_share)));
            }
        });

        titleView.setText(title);

        bylineView.setText(Html.fromHtml(DateUtils
                .getRelativeTimeSpanString(mCursor.getLong(ArticleLoader.Query.PUBLISHED_DATE),
                        System.currentTimeMillis(), DateUtils.HOUR_IN_MILLIS, DateUtils.FORMAT_ABBREV_ALL)
                .toString() + " by <font color='#000000'>" + mCursor.getString(ArticleLoader.Query.AUTHOR)
                + "</font>"));
        bodyView.setText(Html.fromHtml(mCursor.getString(ArticleLoader.Query.BODY)));

        Picasso.with(getActivity()).load(mCursor.getString(ArticleLoader.Query.PHOTO_URL)).into(mPhotoView);
        mPhotoView.setContentDescription(mCursor.getString(ArticleLoader.Query.TITLE));

    } else {
        titleView.setText("N/A");
        bylineView.setText("N/A");
        bodyView.setText("N/A");
    }

}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.PlusStreamRowViewBinder.java

public static void bindActivityView(final View rootView, Activity activity, ImageLoader imageLoader,
        boolean singleSourceMode) {
    // Prepare view holder.
    ViewHolder tempViews = (ViewHolder) rootView.getTag();
    final ViewHolder views;
    if (tempViews != null) {
        views = tempViews;/*from   www .  j  av  a  2  s .  c  om*/
    } else {
        views = new ViewHolder();
        rootView.setTag(views);

        // Author and metadata box
        views.authorContainer = rootView.findViewById(R.id.stream_author_container);
        views.userImage = (ImageView) rootView.findViewById(R.id.stream_user_image);
        views.userName = (TextView) rootView.findViewById(R.id.stream_user_name);
        views.time = (TextView) rootView.findViewById(R.id.stream_time);

        // Author's content
        views.content = (TextView) rootView.findViewById(R.id.stream_content);

        // Original share box
        views.originalContainer = rootView.findViewById(R.id.stream_original_container);
        views.originalAuthor = (TextView) rootView.findViewById(R.id.stream_original_author);
        views.originalContent = (TextView) rootView.findViewById(R.id.stream_original_content);

        // Media box
        views.mediaContainer = rootView.findViewById(R.id.stream_media_container);
        views.mediaBackground = (ImageView) rootView.findViewById(R.id.stream_media_background);
        views.mediaOverlay = (ImageView) rootView.findViewById(R.id.stream_media_overlay);
        views.mediaTitle = (TextView) rootView.findViewById(R.id.stream_media_title);
        views.mediaSubtitle = (TextView) rootView.findViewById(R.id.stream_media_subtitle);

        // Interactions box
        views.interactionsContainer = rootView.findViewById(R.id.stream_interactions_container);
        views.plusOnes = (TextView) rootView.findViewById(R.id.stream_plus_ones);
        views.shares = (TextView) rootView.findViewById(R.id.stream_shares);
        views.comments = (TextView) rootView.findViewById(R.id.stream_comments);
    }

    final Context context = rootView.getContext();
    final Resources res = context.getResources();

    // Determine if this is a reshare (affects how activity fields are to be interpreted).
    Activity.PlusObject.Actor originalAuthor = activity.getObject().getActor();
    boolean isReshare = "share".equals(activity.getVerb()) && originalAuthor != null;

    // Author and metadata box
    views.authorContainer.setVisibility(singleSourceMode ? View.GONE : View.VISIBLE);
    views.userName.setText(activity.getActor().getDisplayName());

    // Find user profile image url
    String userImageUrl = null;
    if (activity.getActor().getImage() != null) {
        userImageUrl = activity.getActor().getImage().getUrl();
    }

    // Load image from network in background thread using Volley library
    imageLoader.get(userImageUrl, views.userImage, PLACEHOLDER_USER_IMAGE);

    long thenUTC = activity.getUpdated().getValue() + activity.getUpdated().getTimeZoneShift() * 60000;
    views.time.setText(DateUtils.getRelativeTimeSpanString(thenUTC, System.currentTimeMillis(),
            DateUtils.SECOND_IN_MILLIS, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_ABBREV_RELATIVE));

    // Author's additional content
    String selfContent = isReshare ? activity.getAnnotation() : activity.getObject().getContent();
    views.content.setMaxLines(singleSourceMode ? 1000 : 5);
    if (!TextUtils.isEmpty(selfContent)) {
        views.content.setVisibility(View.VISIBLE);
        views.content.setText(Html.fromHtml(selfContent));
    } else {
        views.content.setVisibility(View.GONE);
    }

    // Original share box
    if (isReshare) {
        views.originalContainer.setVisibility(View.VISIBLE);

        // Set original author text, highlight author name
        final String author = res.getString(R.string.stream_originally_shared, originalAuthor.getDisplayName());
        final SpannableStringBuilder spannableAuthor = new SpannableStringBuilder(author);
        spannableAuthor.setSpan(new StyleSpan(Typeface.BOLD),
                author.length() - originalAuthor.getDisplayName().length(), author.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        views.originalAuthor.setText(spannableAuthor, TextView.BufferType.SPANNABLE);

        String originalContent = activity.getObject().getContent();
        views.originalContent.setMaxLines(singleSourceMode ? 1000 : 3);
        if (!TextUtils.isEmpty(originalContent)) {
            views.originalContent.setVisibility(View.VISIBLE);
            views.originalContent.setText(Html.fromHtml(originalContent));
        } else {
            views.originalContent.setVisibility(View.GONE);
        }
    } else {
        views.originalContainer.setVisibility(View.GONE);
    }

    // Media box

    // Set media content.
    List<Activity.PlusObject.Attachments> attachments = activity.getObject().getAttachments();
    if (attachments != null && attachments.size() > 0) {
        Activity.PlusObject.Attachments attachment = attachments.get(0);
        String objectType = attachment.getObjectType();
        String imageUrl = attachment.getImage() != null ? attachment.getImage().getUrl() : null;
        if (imageUrl == null && attachment.getThumbnails() != null && attachment.getThumbnails().size() > 0) {
            Thumbnails thumb = attachment.getThumbnails().get(0);
            imageUrl = thumb.getImage() != null ? thumb.getImage().getUrl() : null;
        }

        // Load image from network in background thread using Volley library
        imageLoader.get(imageUrl, views.mediaBackground, PLACEHOLDER_MEDIA_IMAGE);

        boolean overlayStyle = false;

        views.mediaOverlay.setImageDrawable(null);
        if (("photo".equals(objectType) || "video".equals(objectType) || "album".equals(objectType))
                && !TextUtils.isEmpty(imageUrl)) {
            overlayStyle = true;
            views.mediaOverlay
                    .setImageResource("video".equals(objectType) ? R.drawable.ic_stream_media_overlay_video
                            : R.drawable.ic_stream_media_overlay_photo);

        } else if ("article".equals(objectType) || "event".equals(objectType)) {
            overlayStyle = false;
            views.mediaTitle.setText(attachment.getDisplayName());
            if (!TextUtils.isEmpty(attachment.getUrl())) {
                Uri uri = Uri.parse(attachment.getUrl());
                views.mediaSubtitle.setText(uri.getHost());
            } else {
                views.mediaSubtitle.setText("");
            }
        }

        views.mediaContainer.setVisibility(View.VISIBLE);
        views.mediaContainer.setBackgroundResource(
                overlayStyle ? R.color.plus_stream_media_background : android.R.color.black);
        if (overlayStyle) {
            views.mediaBackground.clearColorFilter();
        } else {
            views.mediaBackground.setColorFilter(res.getColor(R.color.plus_media_item_tint));
        }
        views.mediaOverlay.setVisibility(overlayStyle ? View.VISIBLE : View.GONE);
        views.mediaTitle.setVisibility(overlayStyle ? View.GONE : View.VISIBLE);
        views.mediaSubtitle.setVisibility(overlayStyle ? View.GONE : View.VISIBLE);
    } else {
        views.mediaContainer.setVisibility(View.GONE);
        views.mediaBackground.setImageDrawable(null);
        views.mediaOverlay.setImageDrawable(null);
    }

    // Interactions box
    final int plusOneCount = (activity.getObject().getPlusoners() != null)
            ? activity.getObject().getPlusoners().getTotalItems().intValue()
            : 0;
    if (plusOneCount > 0) {
        views.plusOnes.setVisibility(View.VISIBLE);
        views.plusOnes.setText(getPlusOneString(plusOneCount));
    } else {
        views.plusOnes.setVisibility(View.GONE);
    }

    final int commentCount = (activity.getObject().getReplies() != null)
            ? activity.getObject().getReplies().getTotalItems().intValue()
            : 0;
    if (commentCount > 0) {
        views.comments.setVisibility(View.VISIBLE);
        views.comments.setText(Integer.toString(commentCount));
    } else {
        views.comments.setVisibility(View.GONE);
    }

    final int resharerCount = (activity.getObject().getResharers() != null)
            ? activity.getObject().getResharers().getTotalItems().intValue()
            : 0;
    if (resharerCount > 0) {
        views.shares.setVisibility(View.VISIBLE);
        views.shares.setText(Integer.toString(resharerCount));
    } else {
        views.shares.setVisibility(View.GONE);
    }

    views.interactionsContainer.setVisibility(
            (plusOneCount > 0 || commentCount > 0 || resharerCount > 0) ? View.VISIBLE : View.GONE);
}

From source file:io.bunnyblue.noticedog.app.tools.UIUtilities.java

public static String formatTimestamp(long timestamp) {
    long now = System.currentTimeMillis();
    if (timestamp == 0) {
        return "";
    }//from w  w  w .  j a  v  a  2 s  .  co  m
    return DateUtils.getRelativeTimeSpanString(timestamp, now, 1000,
            AccessibilityEventCompat.TYPE_GESTURE_DETECTION_END).toString();
}

From source file:com.roamprocess1.roaming4world.ui.messages.ConversationsAdapter.java

@SuppressLint("SdCardPath")
@Override/*from  w  w w .java  2 s .com*/
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));

}

From source file:com.roamprocess1.roaming4world.ui.messages.MessageAdapter.java

@SuppressLint("SdCardPath")
@Override/*from w  ww .j av a  2 s  .  c o m*/
public void bindView(View view, Context context, Cursor cursor) {
    System.out.println("MessageAdapter.java in bindView() ");
    final MessageListItemViews tagView = (MessageListItemViews) view.getTag();
    v = view;
    this.context = context;
    SipMessage msg = new SipMessage(cursor);
    // System.out.println("msg:"+msg);

    System.out.println("Cursor row count:" + cursor.getCount());

    String number = msg.getRemoteNumber();
    long date = msg.getDate();
    String message = msg.getBodyContent();
    subject = message;
    System.out.println("subject--" + subject);
    if (message.contains("[Offline message -") && !number.equals("sip:registrar@kamailio.org")) {
        System.out.println("offline message");
        String[] finalMessage = message.split("]");
        subject = finalMessage[finalMessage.length - 1];
    } else {
        subject = message;
    }

    String errorTxt = msg.getErrorContent();
    String mimeType = msg.getMimeType();
    int type = msg.getType();

    Log.setLogLevel(6);
    Log.d("Col count", cursor.getColumnCount() + " @");

    String[] columnname = cursor.getColumnNames();
    for (int i = 0; i < columnname.length; i++) {
        Log.d("columnname " + i, columnname[i] + " @");
        Log.d(columnname[i], cursor.getString(cursor.getColumnIndex(columnname[i])) + " @");

    }

    tv_msg_info = (TextView) view.findViewById(R.id.tv_msg_info);
    pb_uploading = (ProgressBar) view.findViewById(R.id.pb_uploading);

    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.error_watch_not_send);
        tagView.deliveredIndicator.setContentDescription("");
    } else if (type == SipMessage.MESSAGE_TYPE_FAILED) {
        tagView.deliveredIndicator.setVisibility(View.VISIBLE);
        tagView.deliveredIndicator.setImageResource(R.drawable.error_watch_not_send);
        tagView.deliveredIndicator.setContentDescription("");
    } else {
        tagView.deliveredIndicator.setVisibility(View.VISIBLE);
        tagView.deliveredIndicator.setImageResource(R.drawable.todo_send);
        tagView.deliveredIndicator.setContentDescription("");
    }

    if (TextUtils.isEmpty(errorTxt)) {
        tagView.errorView.setVisibility(View.GONE);
    } else {
        tagView.errorView.setVisibility(View.GONE);
        tagView.errorView.setText(errorTxt);
    }

    // Subject
    tagView.contentView.setText(formatMessage(number, subject, mimeType));
    if (msg.isOutgoing()) {
        setPhotoSide(tagView, ArrowPosition.LEFT);
        LinearLayout linerLayout = (LinearLayout) view.findViewById(R.id.message_block);
        linerLayout.setBackgroundResource(R.drawable.chatedittextdesign);
        text_view = (TextView) view.findViewById(R.id.text_view);
        text_view.setTextColor(Color.BLACK);

        // Photo
        tagView.quickContactView.assignContactUri(personalInfo.contactContentUri);
        /*
        ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, 
            tagView.quickContactView.getImageView(),
            personalInfo,
            R.drawable.ic_contact_picture_holo_dark);
         */

        System.out.println("msg adp out - 0");
        String path = "/sdcard/R4W/ProfilePic/ProfilePic.png";
        File user_imageFile = new File(path);
        if (user_imageFile.exists()) {
            try {
                if (bm != null) {
                    //      bm = null;
                }
                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(), personalInfo,
                            R.drawable.ic_contact_picture_holo_dark);
                    // TODO: handle exception
                }
            }
        } else {
            ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext,
                    tagView.quickContactView.getImageView(), personalInfo,
                    R.drawable.ic_contact_picture_holo_dark);

        }

        outgoingImage(number);

    } else {

        setPhotoSide(tagView, ArrowPosition.RIGHT);
        LinearLayout linerLayout = (LinearLayout) view.findViewById(R.id.message_block);
        linerLayout.setBackgroundResource(R.drawable.messagebodyleft);

        // Contact
        CallerInfo info = CallerInfo.getCallerInfoFromSipUri(mContext, msg.getFullFrom());

        text_view = (TextView) view.findViewById(R.id.text_view);
        text_view.setTextColor(Color.BLACK);
        pb_uploading.setVisibility(ProgressBar.GONE);

        // Photo
        tagView.quickContactView.assignContactUri(info.contactContentUri);
        /*
        ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, 
            tagView.quickContactView.getImageView(),
            info,
            R.drawable.ic_contact_picture_holo_dark);
           */
        System.out.println("msg adp in - 1");
        String nu = stripNumber(number);
        String path = "/sdcard/R4W/ProfilePic/" + nu + ".png";
        System.out.println("msg adp out - path=" + path);
        File user_imageFile = new File(path);
        if (user_imageFile.exists()) {
            try {
                if (bm != null) {
                    //      bm = null;
                }
                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);
        }
        incomingImage();
    }

}

From source file:com.jpventura.xyzreader.ui.ArticleDetailFragment.java

private void bindViews() {
    if (mRootView == null) {
        return;/*from   www  .j a v a2 s . c  o  m*/
    }

    mTitleView = (TextView) mRootView.findViewById(R.id.article_title);
    mSubitleView = (TextView) mRootView.findViewById(R.id.article_byline);
    mSubitleView.setMovementMethod(new LinkMovementMethod());
    mBodyView = (TextView) mRootView.findViewById(R.id.article_body);

    if (null == mCursor) {
        mRootView.setVisibility(View.GONE);
        mTitleView.setText("N/A");
        mSubitleView.setText("N/A");
        mBodyView.setText("N/A");
        return;
    }

    mRootView.setAlpha(0);
    mRootView.setVisibility(View.VISIBLE);
    mRootView.animate().alpha(1);
    mTitleView.setText(mCursor.getString(ArticleLoader.Query.TITLE));
    mSubitleView.setText(Html.fromHtml(DateUtils
            .getRelativeTimeSpanString(mCursor.getLong(ArticleLoader.Query.PUBLISHED_DATE),
                    System.currentTimeMillis(), DateUtils.HOUR_IN_MILLIS, DateUtils.FORMAT_ABBREV_ALL)
            .toString() + " by <font color='#ffffff'>" + mCursor.getString(ArticleLoader.Query.AUTHOR)
            + "</font>"));
    mBodyView.setText(Html.fromHtml(mCursor.getString(ArticleLoader.Query.BODY)));

    Picasso.with(getActivity()).load(mCursor.getString(ArticleLoader.Query.PHOTO_URL)).into(mPhotoView, this);
}