本文整理匯總了Java中android.database.DatabaseUtils.cursorRowToContentValues方法的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseUtils.cursorRowToContentValues方法的具體用法?Java DatabaseUtils.cursorRowToContentValues怎麽用?Java DatabaseUtils.cursorRowToContentValues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.database.DatabaseUtils
的用法示例。
在下文中一共展示了DatabaseUtils.cursorRowToContentValues方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: performSelect
import android.database.DatabaseUtils; //導入方法依賴的package包/類
private List<ContentValues> performSelect(String query, String[] bindArgs) {
List<ContentValues> ret = new ArrayList<>();
SQLiteDatabase db = getReadableDatabase();
Cursor result = db.rawQuery(query, bindArgs);
while(result.moveToNext()) {
ContentValues cv = new ContentValues();
DatabaseUtils.cursorRowToContentValues(result, cv);
ret.add(cv);
}
result.close();
return ret;
}
示例2: copyData
import android.database.DatabaseUtils; //導入方法依賴的package包/類
/** copies data from Android's media db to ours */
private static int copyData (ContentResolver cr, String minId) {
int imported = 0;
String where = WHERE_ALL;
String[] whereArgs = null;
if (minId != null) {
where = WHERE_MIN_ID;
whereArgs = new String[] { minId };
}
Cursor allFiles = CustomCursor.wrap(cr.query(MediaStore.Files.getContentUri("external"),
FILES_PROJECTION, where, whereArgs, BaseColumns._ID));
if (allFiles != null) {
int count = allFiles.getCount();
int ccount = allFiles.getColumnCount();
if (count > 0) {
// transaction size limited, acts like buffered output stream and auto-flushes queue
BulkInserter inserter = new BulkInserter(MusicStoreInternal.FILES_IMPORT, cr, 2000);
if (DBG) Log.d(TAG, "found items to import:" + count);
while (allFiles.moveToNext()) {
ContentValues cv = new ContentValues(ccount);
DatabaseUtils.cursorRowToContentValues(allFiles, cv);
inserter.add(cv);
}
imported = inserter.execute();
}
allFiles.close();
}
return imported;
}
示例3: copyData
import android.database.DatabaseUtils; //導入方法依賴的package包/類
/** copies data from Android's media db to ours */
private static int copyData (ContentResolver cr, String minId) {
int imported = 0;
String where = WHERE_ALL;
String[] whereArgs = null;
if (minId != null) {
where = WHERE_MIN_ID;
whereArgs = new String[] { minId };
}
Cursor allFiles = CustomCursor.wrap(cr.query(MediaStore.Files.getContentUri("external"),
FILES_PROJECTION, where, whereArgs, BaseColumns._ID));
if (allFiles != null) {
int count = allFiles.getCount();
int ccount = allFiles.getColumnCount();
if (count > 0) {
// transaction size limited, acts like buffered output stream and auto-flushes queue
BulkInserter inserter = new BulkInserter(VideoStoreInternal.FILES_IMPORT, cr, 2000);
if (DBG) Log.d(TAG, "found items to import:" + count);
while (allFiles.moveToNext()) {
try {
ContentValues cv = new ContentValues(ccount);
DatabaseUtils.cursorRowToContentValues(allFiles, cv);
inserter.add(cv);
} catch (IllegalStateException ignored) {} //we silently ignore empty lines - it means content has been deleted while scanning
}
imported = inserter.execute();
}
allFiles.close();
}
return imported;
}
示例4: testBlob
import android.database.DatabaseUtils; //導入方法依賴的package包/類
@MediumTest
public void testBlob() throws Exception {
// create table
mDatabase.execSQL(
"CREATE TABLE test (_id INTEGER PRIMARY KEY, s TEXT, d REAL, l INTEGER, b BLOB);");
// insert blob
Object[] args = new Object[4];
byte[] blob = new byte[1000];
byte value = 99;
Arrays.fill(blob, value);
args[3] = blob;
String s = new String("text");
args[0] = s;
Double d = 99.9;
args[1] = d;
Long l = (long)1000;
args[2] = l;
String sql = "INSERT INTO test (s, d, l, b) VALUES (?,?,?,?)";
mDatabase.execSQL(sql, args);
// use cursor to access blob
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
c.moveToNext();
ContentValues cv = new ContentValues();
DatabaseUtils.cursorRowToContentValues(c, cv);
int bCol = c.getColumnIndexOrThrow("b");
int sCol = c.getColumnIndexOrThrow("s");
int dCol = c.getColumnIndexOrThrow("d");
int lCol = c.getColumnIndexOrThrow("l");
byte[] cBlob = c.getBlob(bCol);
assertTrue(Arrays.equals(blob, cBlob));
assertEquals(s, c.getString(sCol));
assertEquals((double)d, c.getDouble(dCol));
assertEquals((long)l, c.getLong(lCol));
}
示例5: a
import android.database.DatabaseUtils; //導入方法依賴的package包/類
private static jqu[] a(Context paramContext, Uri paramUri)
{
jqu localjqu = new jqu();
localjqu.a = 3;
ContentResolver localContentResolver = paramContext.getContentResolver();
if (a(localContentResolver, paramUri) == null) {
return null;
}
Cursor localCursor = localContentResolver.query(paramUri, a(localContentResolver, paramUri), null, null, null);
if (localCursor != null) {}
try
{
if (localCursor.moveToFirst())
{
ContentValues localContentValues = new ContentValues();
DatabaseUtils.cursorRowToContentValues(localCursor, localContentValues);
localjqu.b = new ContentValues[] { localContentValues };
}
if (localCursor != null) {
localCursor.close();
}
return new jqu[] { localjqu };
}
finally
{
if (localCursor != null) {
localCursor.close();
}
}
}
示例6: PinSpec
import android.database.DatabaseUtils; //導入方法依賴的package包/類
PinSpec(@NonNull Cursor cursor) {
ContentValues contentValues = new ContentValues();
DatabaseUtils.cursorRowToContentValues(cursor, contentValues);
setId(contentValues.getAsLong(PinDatabase.COLUMN_ID));
setTitle(contentValues.getAsString(PinDatabase.COLUMN_TITLE));
setContent(contentValues.getAsString(PinDatabase.COLUMN_CONTENT));
setVisibility(contentValues.getAsInteger(PinDatabase.COLUMN_VISIBILITY));
setPriority(contentValues.getAsInteger(PinDatabase.COLUMN_PRIORITY));
setPersistent(contentValues.getAsInteger(PinDatabase.COLUMN_PERSISTENT) != 0);
setShowActions(contentValues.getAsInteger(PinDatabase.COLUMN_SHOW_ACTIONS) != 0);
}
示例7: onClick
import android.database.DatabaseUtils; //導入方法依賴的package包/類
@Override
public void onClick(View v) {
ContentValues tContentValues = new ContentValues();
String[] tProj = {ArticleTableM.COLUMN_INTERNAL_BOOKMARK};
String tSel = BaseColumns._ID + "=" + getArguments().getLong(ARG_ID);
Cursor tCr = getActivity().getContentResolver().query(
ContentProviderM.ARTICLE_CONTENT_URI,
null, tSel, null, ConstsU.COMMON_SORT_ORDER);
if(tCr != null && tCr.getCount() > 0){
tCr.moveToFirst();
DatabaseUtils.cursorRowToContentValues(tCr, tContentValues);
//-ContentValues are updated
long tPrevFavoriteWithTimeLg = UtilitiesU.getFavoriteTime(getActivity(), getArguments().getLong(ARG_ID));
long tNewFavoriteWithTimeLg;
if(tPrevFavoriteWithTimeLg == ArticleTableM.NOT_BOOKMARKED){
tNewFavoriteWithTimeLg = Calendar.getInstance().getTimeInMillis();
}else{
tNewFavoriteWithTimeLg = ArticleTableM.NOT_BOOKMARKED;
}
tContentValues.put(ArticleTableM.COLUMN_INTERNAL_BOOKMARK,
tNewFavoriteWithTimeLg);
getActivity().getContentResolver().update(
ContentProviderM.ARTICLE_CONTENT_URI,
tContentValues, tSel, null);
tCr.close();
}
updateGuiBookmark((RelativeLayout)v);
}
示例8: copyTable
import android.database.DatabaseUtils; //導入方法依賴的package包/類
/**
* Copies a table <b>between</b> database files.
*
* This method assumes that the source table and destination table already exist in the
* source and destination databases, respectively.
*
* The table is copied row-by-row in a single transaction.
*
* @param source The source database that the table will be copied from.
* @param sourceTableName The name of the source table.
* @param destination The destination database that the table will be copied to.
* @param destinationTableName The name of the destination table.
* @return true if all rows were copied; false otherwise.
*/
public static boolean copyTable(SQLiteDatabase source, String sourceTableName,
SQLiteDatabase destination, String destinationTableName) {
Cursor cursor = null;
try {
destination.beginTransaction();
cursor = source.query(sourceTableName, null, null, null, null, null, null);
Log.d(LOGTAG, "Trying to copy " + cursor.getCount() + " rows from " + sourceTableName + " to " + destinationTableName);
final ContentValues contentValues = new ContentValues();
while (cursor.moveToNext()) {
contentValues.clear();
DatabaseUtils.cursorRowToContentValues(cursor, contentValues);
destination.insert(destinationTableName, null, contentValues);
}
destination.setTransactionSuccessful();
Log.d(LOGTAG, "Successfully copied " + cursor.getCount() + " rows from " + sourceTableName + " to " + destinationTableName);
return true;
} catch (Exception e) {
Log.w(LOGTAG, "Got exception copying rows from " + sourceTableName + " to " + destinationTableName + "; ignoring.", e);
return false;
} finally {
destination.endTransaction();
if (cursor != null) {
cursor.close();
}
}
}
示例9: createFromDb
import android.database.DatabaseUtils; //導入方法依賴的package包/類
/**
* Fill account state object from cursor.
* @param c cursor on the database queried from {@link SipProfile#ACCOUNT_STATUS_URI}
*/
public final void createFromDb(Cursor c) {
ContentValues args = new ContentValues();
DatabaseUtils.cursorRowToContentValues(c, args);
createFromContentValue(args);
}
示例10: createFromDb
import android.database.DatabaseUtils; //導入方法依賴的package包/類
/**
* Create account wrapper with cursor datas.
*
* @param c cursor on the database
*/
private final void createFromDb(Cursor c) {
ContentValues args = new ContentValues();
DatabaseUtils.cursorRowToContentValues(c, args);
createFromContentValue(args);
}
示例11: findCallerInfo
import android.database.DatabaseUtils; //導入方法依賴的package包/類
@Override
public CallerInfo findCallerInfo(Context ctxt, String number) {
Uri searchUri = Uri
.withAppendedPath(Phones.CONTENT_FILTER_URL, Uri.encode(number));
CallerInfo callerInfo = new CallerInfo();
Cursor cursor = ctxt.getContentResolver().query(searchUri, null, null, null, null);
if (cursor != null) {
try {
if (cursor.getCount() > 0) {
cursor.moveToFirst();
ContentValues cv = new ContentValues();
DatabaseUtils.cursorRowToContentValues(cursor, cv);
callerInfo.contactExists = true;
if (cv.containsKey(Phones.DISPLAY_NAME)) {
callerInfo.name = cv.getAsString(Phones.DISPLAY_NAME);
}
callerInfo.phoneNumber = cv.getAsString(Phones.NUMBER);
if (cv.containsKey(Phones.TYPE)
&& cv.containsKey(Phones.LABEL)) {
callerInfo.numberType = cv.getAsInteger(Phones.TYPE);
callerInfo.numberLabel = cv.getAsString(Phones.LABEL);
callerInfo.phoneLabel = Phones.getDisplayLabel(ctxt,
callerInfo.numberType, callerInfo.numberLabel)
.toString();
}
if (cv.containsKey(Phones.PERSON_ID)) {
callerInfo.personId = cv.getAsLong(Phones.PERSON_ID);
callerInfo.contactContentUri = ContentUris.withAppendedId(
People.CONTENT_URI, callerInfo.personId);
}
if (cv.containsKey(Phones.CUSTOM_RINGTONE)) {
String ringtoneUriString = cv.getAsString(Phones.CUSTOM_RINGTONE);
if (!TextUtils.isEmpty(ringtoneUriString)) {
callerInfo.contactRingtoneUri = Uri.parse(ringtoneUriString);
}
}
if (callerInfo.name != null && callerInfo.name.length() == 0) {
callerInfo.name = null;
}
}
} catch (Exception e) {
Log.e(THIS_FILE, "Exception while retrieving cursor infos", e);
} finally {
cursor.close();
}
}
// if no query results were returned with a viable number,
// fill in the original number value we used to query with.
if (TextUtils.isEmpty(callerInfo.phoneNumber)) {
callerInfo.phoneNumber = number;
}
return callerInfo;
}
示例12: findSelfInfo
import android.database.DatabaseUtils; //導入方法依賴的package包/類
@Override
public CallerInfo findSelfInfo(Context ctxt) {
CallerInfo callerInfo = new CallerInfo();
String[] projection = new String[] {
Profile._ID,
Profile.DISPLAY_NAME,
Profile.PHOTO_ID,
Profile.PHOTO_URI
};
Cursor cursor = ctxt.getContentResolver().query(Profile.CONTENT_URI, projection, null, null, null);
if(cursor != null) {
try {
if(cursor.getCount() > 0) {
cursor.moveToFirst();
ContentValues cv = new ContentValues();
DatabaseUtils.cursorRowToContentValues(cursor, cv);
callerInfo.contactExists = true;
if(cv.containsKey(Profile.DISPLAY_NAME) ) {
callerInfo.name = cv.getAsString(Profile.DISPLAY_NAME);
}
if(cv.containsKey(Profile._ID) ) {
callerInfo.personId = cv.getAsLong(Profile._ID);
callerInfo.contactContentUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, callerInfo.personId);
}
if(cv.containsKey(Profile.PHOTO_ID)) {
Long photoId = cv.getAsLong(Profile.PHOTO_ID);
if(photoId != null) {
callerInfo.photoId = photoId;
}
}
if(cv.containsKey(Profile.PHOTO_URI)) {
String photoUri = cv.getAsString(Profile.PHOTO_URI);
if(!TextUtils.isEmpty(photoUri)) {
callerInfo.photoUri = Uri.parse(photoUri);
}
}
if(callerInfo.name != null && callerInfo.name.length() == 0) {
callerInfo.name = null;
}
}
}catch(Exception e) {
Log.e(THIS_FILE, "Exception while retrieving cursor infos", e);
}finally {
cursor.close();
}
}
return callerInfo;
}
示例13: createFromDb
import android.database.DatabaseUtils; //導入方法依賴的package包/類
public void createFromDb(Cursor c) {
ContentValues args = new ContentValues();
DatabaseUtils.cursorRowToContentValues(c, args);
createFromContentValue(args);
}
示例14: onLoadFinished
import android.database.DatabaseUtils; //導入方法依賴的package包/類
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
if (data.moveToFirst()) {
Vector<ContentValues> cVVector = new Vector<ContentValues>(data.getCount());
do {
ContentValues cv = new ContentValues();
DatabaseUtils.cursorRowToContentValues(data, cv);
cVVector.add(cv);
} while (data.moveToNext());
mMovieAdapter.swapCursor(data);
// if (mPosition != RecyclerView.NO_POSITION) {
// mRecyclerView.smoothScrollToPosition(mPosition);
//// mPosition = RecyclerView.NO_POSITION;
// }
updateEmptyView();
/*
* interesting code left over from the Advanced version of sunshine -
*/
if (data.getCount() > 0) {
mRecyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
// Since we know we're going to get items, we keep the listener around until
// we see Children.
if (mRecyclerView.getChildCount() > 0) {
mRecyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
// let's see if our position needs to be updated after a mode change:
GridLayoutManager mlm = (GridLayoutManager) mRecyclerView.getLayoutManager();
int position = mlm.findFirstCompletelyVisibleItemPosition();
if (mPosition == RecyclerView.NO_POSITION) {
Timber.i("yup they are equal" + mPosition + " " + RecyclerView.NO_POSITION);
}
if ((mPosition != RecyclerView.NO_POSITION) && (position != mPosition)) {
mRecyclerView.scrollToPosition(mPosition);
}
// if we are entering Favorites mode and in two pane mode,
// then click on item 0 to insure we really have a favorite selected
if (do_click_on_item_zero) {
int itemPosition = 0;
RecyclerView.ViewHolder vh = mRecyclerView.findViewHolderForAdapterPosition(itemPosition);
if (vh == null) { // if this position doesn't exist in the new layout then
itemPosition = 0;
vh = mRecyclerView.findViewHolderForAdapterPosition(itemPosition);
}
if (null != vh && mAutoSelectView) {
mMovieAdapter.selectView(vh);
// mRecyclerView.smoothScrollToPosition(mPosition);
}
return true;
}
}
return false;
}
});
}
}
}
示例15: a
import android.database.DatabaseUtils; //導入方法依賴的package包/類
public static jqu a(Context paramContext, int paramInt, ArrayList<String> paramArrayList, ArrayList<Long> paramArrayList1)
{
int m = 1;
int n = 0;
jqu localjqu = new jqu();
localjqu.a = 2;
if ((paramArrayList.isEmpty()) && (paramArrayList1.isEmpty())) {
return localjqu;
}
SQLiteDatabase localSQLiteDatabase = ((hrz)mbb.a(paramContext, hrz.class)).b(paramContext, paramInt).getReadableDatabase();
String[] arrayOfString = a(localSQLiteDatabase);
StringBuilder localStringBuilder = new StringBuilder();
int i1;
if (!paramArrayList.isEmpty())
{
i1 = m;
if (paramArrayList1.isEmpty()) {
break label244;
}
}
for (;;)
{
if (i1 != 0) {
a(localStringBuilder, "fingerprint", paramArrayList);
}
if ((i1 != 0) && (m != 0)) {
localStringBuilder.append(" OR ");
}
if (m != 0) {
a(localStringBuilder, "photo_id", paramArrayList1);
}
Cursor localCursor = localSQLiteDatabase.query("all_photos", arrayOfString, localStringBuilder.toString(), null, null, null, null);
try
{
ContentValues[] arrayOfContentValues = new ContentValues[localCursor.getCount()];
while (localCursor.moveToNext())
{
ContentValues localContentValues = new ContentValues();
DatabaseUtils.cursorRowToContentValues(localCursor, localContentValues);
arrayOfContentValues[n] = localContentValues;
n++;
}
localjqu.b = arrayOfContentValues;
return localjqu;
}
finally
{
localCursor.close();
}
i1 = 0;
break;
label244:
m = 0;
}
}