LocalProviderpublic class LocalProvider extends ContentProvider Simple test provider that runs in the local process. |
Fields Summary |
---|
private static final String | TAG | private android.database.sqlite.SQLiteOpenHelper | mOpenHelper | private static final int | DATA | private static final int | DATA_ID | private static final android.content.UriMatcher | sURLMatcher |
Constructors Summary |
---|
public LocalProvider()
|
Methods Summary |
---|
public int | delete(android.net.Uri url, java.lang.String where, java.lang.String[] whereArgs)
throw new UnsupportedOperationException("delete not supported");
| public java.lang.String | getType(android.net.Uri url)
int match = sURLMatcher.match(url);
switch (match) {
case DATA:
return "vnd.android.cursor.dir/vnd.google.unit_tests.local";
case DATA_ID:
return "vnd.android.cursor.item/vnd.google.unit_tests.local";
default:
throw new IllegalArgumentException("Unknown URL");
}
| public android.net.Uri | insert(android.net.Uri url, ContentValues initialValues)
return null;
| public boolean | onCreate()
mOpenHelper = new DatabaseHelper(getContext());
return true;
| public android.database.Cursor | query(android.net.Uri url, java.lang.String[] projectionIn, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sort)
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
// Generate the body of the query
int match = sURLMatcher.match(url);
switch (match) {
case DATA:
qb.setTables("data");
break;
case DATA_ID:
qb.setTables("data");
qb.appendWhere("_id=");
qb.appendWhere(url.getPathSegments().get(1));
break;
default:
throw new IllegalArgumentException("Unknown URL " + url);
}
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor ret = qb.query(db, projectionIn, selection, selectionArgs,
null, null, sort);
if (ret == null) {
if (false) Log.d(TAG, "Alarms.query: failed");
} else {
ret.setNotificationUri(getContext().getContentResolver(), url);
}
return ret;
| public int | update(android.net.Uri url, ContentValues values, java.lang.String where, java.lang.String[] whereArgs)
int count;
long rowId = 0;
int match = sURLMatcher.match(url);
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
switch (match) {
case DATA_ID: {
String segment = url.getPathSegments().get(1);
rowId = Long.parseLong(segment);
count = db.update("data", values, "_id=" + rowId, null);
break;
}
default: {
throw new UnsupportedOperationException(
"Cannot update URL: " + url);
}
}
if (false) Log.d(TAG, "*** notifyChange() rowId: " + rowId);
getContext().getContentResolver().notifyChange(url, null);
return count;
|
|