RssContentProviderpublic class RssContentProvider extends android.content.ContentProvider
Fields Summary |
---|
private Logger | mLogger | private android.database.sqlite.SQLiteDatabase | mDb | private DatabaseHelper | mDbHelper | private static final String | DATABASE_NAME | private static final String | DATABASE_TABLE_NAME | private static final int | DB_VERSION | private static final int | ALL_MESSAGES | private static final int | SPECIFIC_MESSAGE | private static final android.content.UriMatcher | URI_MATCHER | public static final android.net.Uri | CONTENT_URI | public static final String | ID | public static final String | URL | public static final String | TITLE | public static final String | HAS_BEEN_READ | public static final String | CONTENT | public static final String | LAST_UPDATED | public static final String | DEFAULT_SORT_ORDER |
Methods Summary |
---|
public int | delete(android.net.Uri uri, java.lang.String where)
// NOTE Argument checking code omitted. Check your parameters!
int rowCount = mDb.delete(DATABASE_TABLE_NAME, ID + " = " + uri.getPathLeafId());
// Notify any listeners and return the deleted row count.
getContext().getContentResolver().notifyDelete(uri, null);
return rowCount;
| public java.lang.String | getType(android.net.Uri uri)
switch (URI_MATCHER.match(uri)){
case ALL_MESSAGES:
return "vnd.android.cursor.dir/rssitem"; // List of items.
case SPECIFIC_MESSAGE:
return "vnd.android.cursor.item/rssitem"; // Specific item.
default:
return null;
}
| public android.net.Uri | insert(android.net.Uri requestUri, android.content.ContentValues initialValues)
// NOTE Argument checking code omitted. Check your parameters! Check that
// your row addition request succeeded!
long rowId = -1;
rowId = mDb.insert(DATABASE_TABLE_NAME, "rawcontent", initialValues);
Uri newUri = CONTENT_URI.addId(rowId);
// Notify any listeners and return the URI of the new row.
getContext().getContentResolver().notifyInsert(CONTENT_URI, null);
return newUri;
| public boolean | onCreate()
// First we need to open the database. If this is our first time,
// the attempt to retrieve a database will throw
// FileNotFoundException, and we will then create the database.
final Context con = getContext();
try{
mDb = mDbHelper.openDatabase(getContext(), DATABASE_NAME, null, DB_VERSION);
mLogger.info("RssContentProvider.onCreate(): Opened a database");
} catch (Exception ex) {
return false;
}
if(mDb == null){
return false;
} else {
return true;
}
| public android.database.Cursor | query(android.net.Uri uri, java.lang.String[] projection, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String groupBy, java.lang.String having, java.lang.String sortOrder)
// We won't bother checking the validity of params here, but you should!
// SQLiteQueryBuilder is the helper class that creates the
// proper SQL syntax for us.
SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder();
// Set the table we're querying.
qBuilder.setTables(DATABASE_TABLE_NAME);
// If the query ends in a specific record number, we're
// being asked for a specific record, so set the
// WHERE clause in our query.
if((URI_MATCHER.match(uri)) == SPECIFIC_MESSAGE){
qBuilder.appendWhere("_id=" + uri.getPathLeafId());
}
// Set sort order. If none specified, use default.
if(TextUtils.isEmpty(sortOrder)){
sortOrder = DEFAULT_SORT_ORDER;
}
// Make the query.
Cursor c = qBuilder.query(mDb,
projection,
selection,
selectionArgs,
groupBy,
having,
sortOrder);
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
| public int | update(android.net.Uri uri, android.content.ContentValues values, java.lang.String whereClause)
// NOTE Argument checking code omitted. Check your parameters!
int updateCount = mDb.update(DATABASE_TABLE_NAME, values, whereClause);
// Notify any listeners and return the updated row count.
getContext().getContentResolver().notifyUpdate(uri, null);
return updateCount;
|
|