FileDocCategorySizeDatePackage
TrackerDataHelper.javaAPI DocAndroid 5.1 API4986Thu Mar 12 22:22:44 GMT 2015com.android.locationtracker.data

TrackerDataHelper

public class TrackerDataHelper extends Object
Helper class for writing and retrieving data using the TrackerProvider content provider

Fields Summary
private android.content.Context
mContext
protected IFormatter
mFormatter
formats data output
public static final IFormatter
CSV_FORMATTER
formats output as Comma separated value CSV file
public static final IFormatter
KML_FORMATTER
formats output as KML file
public static final IFormatter
NO_FORMATTER
provides no formatting
Constructors Summary
public TrackerDataHelper(android.content.Context context, IFormatter formatter)
Creates instance

param
context - content context
param
formatter - formats the output from the get*Output* methods


                          
         
        mContext = context;
        mFormatter = formatter;
    
public TrackerDataHelper(android.content.Context context)
Creates a instance with no output formatting capabilities. Useful for clients that require write-only access

        this(context, NO_FORMATTER);
    
Methods Summary
public voiddeleteAll()
Deletes all tracker entries

        mContext.getContentResolver().delete(TrackerProvider.CONTENT_URI, null,
                null);
    
public java.lang.StringgetNextOutput(android.database.Cursor cursor)
Helper method which converts row referenced by given cursor to a string output

param
cursor
return
CharSequence output, null if given cursor is invalid or no more data

        if (cursor == null || cursor.isAfterLast()) {
            return null;
        }
        String output = mFormatter.getOutput(TrackerEntry.createEntry(cursor));
        cursor.moveToNext();
        return output;
    
public java.lang.StringgetOutputFooter()
Returns the output footer particular to the associated formatter

        return mFormatter.getFooter();
    
public java.lang.StringgetOutputHeader()
Returns the output header particular to the associated formatter

        return mFormatter.getHeader();
    
public android.database.Cursorquery(java.lang.String tag, int limit)
Query tracker data, filtering by given tag

param
tag
return
Cursor to data

        String selection = (tag == null ? null : TrackerEntry.TAG + "=?");
        String[] selectionArgs = (tag == null ? null : new String[] {tag});
        Cursor cursor = mContext.getContentResolver().query(
                TrackerProvider.CONTENT_URI, TrackerEntry.ATTRIBUTES,
                selection, selectionArgs, null);
        if (cursor == null) {
            return cursor;
        }
        int pos = (cursor.getCount() < limit ? 0 : cursor.getCount() - limit);
        cursor.moveToPosition(pos);
        return cursor;
    
public android.database.Cursorquery(int limit)
Retrieves a cursor that starts at the last limit rows

param
limit
return
a cursor, null if bad things happened

        return query(null, limit);
    
public android.database.Cursorquery(java.lang.String tag)
Query tracker data, filtering by given tag. mo limit to number of rows returned

param
tag
return
Cursor to data

        return query(tag, Integer.MAX_VALUE);
    
voidwriteEntry(TrackerEntry entry)
insert given TrackerEntry into content provider

        mContext.getContentResolver().insert(TrackerProvider.CONTENT_URI,
                entry.getAsContentValues());
    
public voidwriteEntry(android.location.Location loc, float distFromNetLoc)
insert given location into tracker data

        writeEntry(TrackerEntry.createEntry(loc, distFromNetLoc));
    
public voidwriteEntry(java.lang.String tag, java.lang.String logMsg)
insert given log message into tracker data

        writeEntry(TrackerEntry.createEntry(tag, logMsg));