1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| public abstract class BaseDataHelper { private Context mContext;
public BaseDataHelper(Context context) { mContext = context; }
public Context getContext() { return mContext; }
protected abstract Uri getContentUri();
public void notifyChange() { mContext.getContentResolver().notifyChange(getContentUri(), null); }
protected final Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { return mContext.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder); }
protected final Cursor query(String[] projection, String selection, String[] selectionArgs, String sortOrder) { return mContext.getContentResolver().query(getContentUri(), projection, selection, selectionArgs, sortOrder); }
protected final Uri insert(ContentValues values) { return mContext.getContentResolver().insert(getContentUri(), values); }
protected final int bulkInsert(ContentValues[] values) { return mContext.getContentResolver() .bulkInsert(getContentUri(), values); }
protected final int update(ContentValues values, String where, String[] whereArgs) { return mContext.getContentResolver().update(getContentUri(), values, where, whereArgs); }
protected final int delete(Uri uri, String selection, String[] selectionArgs) { return mContext.getContentResolver().delete(getContentUri(), selection, selectionArgs); }
protected final Cursor getList(String[] projection, String selection, String[] selectionArgs, String sortOrder) { return mContext.getContentResolver().query(getContentUri(), projection, selection, selectionArgs, sortOrder); }
public CursorLoader getCursorLoader(Context context) { return getCursorLoader(context, null, null, null, null); }
protected final CursorLoader getCursorLoader(Context context, String[] projection, String selection, String[] selectionArgs, String sortOrder) { return new CursorLoader(context, getContentUri(), projection, selection, selectionArgs, sortOrder); } }
|