Android Open Source - StatusShare-Android Comment Adapter

From Project

Back to project page StatusShare-Android.


The source code is released under:

Apache License

If you think the Android project StatusShare-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

 * Copyright (c) 2013, Kinvey, Inc. All rights reserved.
 */*  w ww.j  ava2  s .com*/
 * This software contains valuable confidential and proprietary information of
 * KINVEY, INC and is subject to applicable licensing agreements.
 * Unauthorized reproduction, transmission or distribution of this file and its
 * contents is a violation of applicable laws.
package com.kinvey.samples.statusshare.component;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.kinvey.samples.statusshare.R;
import com.kinvey.samples.statusshare.StatusShare;
import com.kinvey.samples.statusshare.model.CommentEntity;
import com.kinvey.samples.statusshare.model.UpdateEntity;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class CommentAdapter extends ArrayAdapter<GenericJson> {

    private LayoutInflater mInflater;
    private Typeface roboto;

    public CommentAdapter(Context context, List<GenericJson> objects,
                          LayoutInflater inf) {
        // NOTE: I pass an arbitrary textViewResourceID to the super
        // constructor-- Below I override
        // getView(...), which causes the underlying adapter to ignore this
        // field anyways, it is just needed in the constructor.
        super(context, 0, objects);
        this.mInflater = inf;
        roboto = Typeface.createFromAsset(context.getAssets(), "Roboto-Thin.ttf");


    public View getView(int position, View convertView, ViewGroup parent) {
        UpdateViewHolder holder = null;

        TextView comment = null;
        TextView author = null;
        TextView when = null;

        GenericJson rowData = getItem(position);

        if (null == convertView) {
            convertView = mInflater.inflate(R.layout.row_comment, null);
            holder = new UpdateViewHolder(convertView);
        holder = (UpdateViewHolder) convertView.getTag();

        if (rowData.get("text") != null){
            comment = holder.getBlurb();

        if (rowData.get("author") != null){
            author = holder.getAuthor();


        ParsePosition pp = new ParsePosition(0);
        Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US).parse(((ArrayMap)rowData.get("_kmd")).get("ect").toString(), pp);
        String since = StatusShare.getSince(date, Calendar.getInstance());
        if (since != null){
            when = holder.getWhen();


        return convertView;

     * This pattern is used as an optimization for Android ListViews.
     * <p/>
     * Since every row uses the same layout, the View object itself can be
     * recycled, only the data/content of the row has to be updated.
     * <p/>
     * This allows for Android to only inflate enough Row Views to fit on
     * screen, and then they are recycled. This allows us to avoid creating
     * a new view for every single row, which can have a negative effect on
     * performance (especially with large lists on large screen devices).
    private class UpdateViewHolder {
        private View rowView;

        private TextView blurb = null;
        private TextView author = null;
        private TextView when = null;

        public UpdateViewHolder(View row) {
            rowView = row;

        public TextView getWhen() {
            if (null == when) {
                when = (TextView) rowView.findViewById(;
            return when;

        public TextView getAuthor() {
            if (null == author) {
                author = (TextView) rowView.findViewById(;
            return author;

        public TextView getBlurb() {
            if (null == blurb) {
                blurb = (TextView) rowView.findViewById(;
            return blurb;


Java Source Code List