Android Open Source - legacy_bluetrack Session Cursor Adapter

From Project

Back to project page legacy_bluetrack.


The source code is released under:

GNU General Public License

If you think the Android project legacy_bluetrack 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

package org.jonblack.bluetrack.adapters;
/*from   w  w  w.ja  va 2s .c  o m*/
import org.joda.time.DateTime;
import org.joda.time.Period;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.PeriodFormat;
import org.jonblack.bluetrack.R;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class SessionCursorAdapter extends CursorAdapter
  public SessionCursorAdapter(Context context, Cursor c, int flags)
    super(context, c, flags);
  public View newView(Context context, Cursor cursor, ViewGroup parent)
    LayoutInflater inflater = LayoutInflater.from(context);
    return inflater.inflate(R.layout.session_list_row, parent, false);
  public void bindView(View view, Context context, Cursor cursor)
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    // Format start date time for locale
    int idStartDateTime = cursor.getColumnIndexOrThrow("start_date_time");
    String startDateTimeStr = cursor.getString(idStartDateTime);
    assert(startDateTimeStr != null);
    DateTime startDateTime = fmt.parseDateTime(startDateTimeStr);
    assert(startDateTime != null);
    TextView tvStartDateTime = (TextView) view.findViewById(;
    tvStartDateTime.setText(startDateTime.toString("EEE dd MMM, YYYY @ HH:mm:ss", null));
    // Calculate duration
    int idEndDateTime = cursor.getColumnIndexOrThrow("end_date_time");
    String endDateTimeStr = cursor.getString(idEndDateTime);
    if (endDateTimeStr != null)
      DateTime endDateTime = fmt.parseDateTime(endDateTimeStr);
      assert(endDateTime != null);
      Period period = new Period(startDateTime, endDateTime);
      TextView tvDuration = (TextView) view.findViewById(;

Java Source Code List