Android Open Source - legacy_bluetrack Session Cursor Adapter






From Project

Back to project page legacy_bluetrack.

License

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.support.v4.widget.CursorAdapter;
import android.widget.TextView;

public class SessionCursorAdapter extends CursorAdapter
{
  public SessionCursorAdapter(Context context, Cursor c, int flags)
  {
    super(context, c, flags);
  }
  
  @Override
  public View newView(Context context, Cursor cursor, ViewGroup parent)
  {
    LayoutInflater inflater = LayoutInflater.from(context);
    return inflater.inflate(R.layout.session_list_row, parent, false);
  }
  
  @Override
  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(R.id.session_row_start_date_time);
    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(R.id.session_row_duration);
      tvDuration.setText(period.toString(PeriodFormat.getDefault()));
    }
  }
}




Java Source Code List

org.jonblack.bluetrack.BluetoothClassLookup.java
org.jonblack.bluetrack.BluetrackIdentifiers.java
org.jonblack.bluetrack.DeviceDiscovery.java
org.jonblack.bluetrack.Device.java
org.jonblack.bluetrack.Session.java
org.jonblack.bluetrack.activities.DevicesFragment.java
org.jonblack.bluetrack.activities.LiveTrackingFragment.java
org.jonblack.bluetrack.activities.MainActivity.java
org.jonblack.bluetrack.activities.SessionFragment.java
org.jonblack.bluetrack.activities.SettingsActivity.java
org.jonblack.bluetrack.adapters.DeviceCursorAdapter.java
org.jonblack.bluetrack.adapters.LiveTrackingCursorAdapter.java
org.jonblack.bluetrack.adapters.SessionCursorAdapter.java
org.jonblack.bluetrack.services.BluetoothLogService.java
org.jonblack.bluetrack.storage.BluetrackContentProvider.java
org.jonblack.bluetrack.storage.BluetrackOpenHelper.java
org.jonblack.bluetrack.storage.DeviceDiscoveryTable.java
org.jonblack.bluetrack.storage.DeviceTable.java
org.jonblack.bluetrack.storage.SessionTable.java