本文整理汇总了Java中android.support.v4.database.DatabaseUtilsCompat类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseUtilsCompat类的具体用法?Java DatabaseUtilsCompat怎么用?Java DatabaseUtilsCompat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseUtilsCompat类属于android.support.v4.database包,在下文中一共展示了DatabaseUtilsCompat类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateLoader
import android.support.v4.database.DatabaseUtilsCompat; //导入依赖的package包/类
@Override
public Loader<List<com.rks.musicx.data.model.Album>> onCreateLoader(int id, Bundle args) {
if (id == albumLoaders) {
AlbumLoader albumLoader = new AlbumLoader(getContext());
String[] selectargs = getSelectionArgs();
String selection = getSelection();
if (artist.getName() != null) {
selection = DatabaseUtilsCompat.concatenateWhere(selection, MediaStore.Audio.Albums.ARTIST + " = ?");
selectargs = DatabaseUtilsCompat.appendSelectionArgs(selectargs, new String[]{artist.getName()});
}
albumLoader.setSortOrder(Extras.getInstance().getArtistAlbumSort());
albumLoader.filterartistsong(selection, selectargs);
return albumLoader;
}
return null;
}
示例2: getCursor
import android.support.v4.database.DatabaseUtilsCompat; //导入依赖的package包/类
@Nullable
protected Cursor getCursor(Uri musicUri, String[] projection, String selection, String[] selectionArgs, String filteredFieldName, String filter, String orderBy) {
if (!Utils.checkPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE)) {
return null;
}
Cursor cursor;
if (filter != null) {
if (filter.equals("")) {
return null; // empty filter means that we don't want any result
}
selection = DatabaseUtilsCompat.concatenateWhere(selection, filteredFieldName + " LIKE ?");
selectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[]{"%" + filter + "%"});
}
cursor = getContext().getContentResolver().query(musicUri, projection,
selection, selectionArgs,
orderBy);
return cursor;
}
示例3: getAlbumCursor
import android.support.v4.database.DatabaseUtilsCompat; //导入依赖的package包/类
private Cursor getAlbumCursor() {
Uri musicUri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
String selection = getSelectionString();
String[] selectionArgs = getSelectionArgs();
if (mArtist != null) {
selection = DatabaseUtilsCompat.concatenateWhere(selection, MediaStore.Audio.Albums.ARTIST + " = ?");
selectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[]{mArtist});
}
String fieldName = MediaStore.Audio.Albums.ALBUM;
String filter = getFilter();
return getCursor(musicUri, sProjection, selection, selectionArgs, fieldName, filter);
}
示例4: getCursor
import android.support.v4.database.DatabaseUtilsCompat; //导入依赖的package包/类
@Nullable
private Cursor getCursor(Uri musicUri, String[] projection, String selection, String[] selectionArgs, String filteredFieldName, String filter, String orderBy) {
if (!Permissions.checkPermission(getContext())) {
return null;
}
if (filter != null) {
if ("".equals(filter)) {
return null; // empty filter means that we don't want any result
}
selection = DatabaseUtilsCompat.concatenateWhere(selection, filteredFieldName + " LIKE ?");
selectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[]{"%" + filter + "%"});
}
return getContext().getContentResolver().query(musicUri, projection, selection, selectionArgs, orderBy);
}
示例5: delete
import android.support.v4.database.DatabaseUtilsCompat; //导入依赖的package包/类
@Override
public int delete(Uri uri, String selection, String[] selectionArgs)
{
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
int count = 0;
int matched = URI_MATCHER.match(uri);
boolean isMatch = false;
int length = tableInfos.length;
for (int i = 0; i < length; i++)
{
TableInfo tableInfo = tableInfos[i];
if (matched == tableInfo.table)
{
count = db.delete(tableInfo.tableName, selection, selectionArgs);
isMatch = true;
break;
}
else if (matched == tableInfo.table_id)
{
String finalWhere = DatabaseUtilsCompat.concatenateWhere(tableInfo.field_id + " = " + ContentUris.parseId(uri), selection);
count = db.delete(tableInfo.tableName, finalWhere, selectionArgs);
isMatch = true;
break;
}
}
if (!isMatch)
{
throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri);
}
return count;
}
示例6: update
import android.support.v4.database.DatabaseUtilsCompat; //导入依赖的package包/类
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs)
{
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
int count = 0;
int matched = URI_MATCHER.match(uri);
boolean isMatch = false;
int length = tableInfos.length;
for (int i = 0; i < length; i++)
{
TableInfo tableInfo = tableInfos[i];
if (matched == tableInfo.table)
{
count = db.update(tableInfo.tableName, values, selection, selectionArgs);
isMatch = true;
break;
}
else if (matched == tableInfo.table_id)
{
String finalWhere = DatabaseUtilsCompat.concatenateWhere(tableInfo.field_id + " = " + ContentUris.parseId(uri), selection);
count = db.update(tableInfo.tableName, values, finalWhere, selectionArgs);
isMatch = true;
break;
}
}
if (!isMatch)
{
throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri);
}
return count;
}
示例7: query
import android.support.v4.database.DatabaseUtilsCompat; //导入依赖的package包/类
/**
* Handle incoming queries.
*/
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
// Constructs a new query builder and sets its table name
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(MainTable.TABLE_NAME);
switch (mUriMatcher.match(uri)) {
case MAIN:
// If the incoming URI is for main table.
qb.setProjectionMap(mNotesProjectionMap);
break;
case MAIN_ID:
// The incoming URI is for a single row.
qb.setProjectionMap(mNotesProjectionMap);
qb.appendWhere(MainTable._ID + "=?");
selectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,
new String[] { uri.getLastPathSegment() });
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (TextUtils.isEmpty(sortOrder)) {
sortOrder = MainTable.DEFAULT_SORT_ORDER;
}
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs,
null /* no group */, null /* no filter */, sortOrder);
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
示例8: delete
import android.support.v4.database.DatabaseUtilsCompat; //导入依赖的package包/类
/**
* Handle deleting data.
*/
@Override
public int delete(Uri uri, String where, String[] whereArgs) {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
String finalWhere;
int count;
switch (mUriMatcher.match(uri)) {
case MAIN:
// If URI is main table, delete uses incoming where clause and args.
count = db.delete(MainTable.TABLE_NAME, where, whereArgs);
break;
// If the incoming URI matches a single note ID, does the delete based on the
// incoming data, but modifies the where clause to restrict it to the
// particular note ID.
case MAIN_ID:
// If URI is for a particular row ID, delete is based on incoming
// data but modified to restrict to the given ID.
finalWhere = DatabaseUtilsCompat.concatenateWhere(
MainTable._ID + " = " + ContentUris.parseId(uri), where);
count = db.delete(MainTable.TABLE_NAME, finalWhere, whereArgs);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return count;
}
示例9: update
import android.support.v4.database.DatabaseUtilsCompat; //导入依赖的package包/类
/**
* Handle updating data.
*/
@Override
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
int count;
String finalWhere;
switch (mUriMatcher.match(uri)) {
case MAIN:
// If URI is main table, update uses incoming where clause and args.
count = db.update(MainTable.TABLE_NAME, values, where, whereArgs);
break;
case MAIN_ID:
// If URI is for a particular row ID, update is based on incoming
// data but modified to restrict to the given ID.
finalWhere = DatabaseUtilsCompat.concatenateWhere(
MainTable._ID + " = " + ContentUris.parseId(uri), where);
count = db.update(MainTable.TABLE_NAME, values, finalWhere, whereArgs);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return count;
}