android.database.DatabaseUtils#cursorRowToContentValues ( )源码实例Demo

下面列出了android.database.DatabaseUtils#cursorRowToContentValues ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: opentasks   文件: TaskValueDelegate.java
/**
 * Copy the properties from the give original task to the new task.
 *
 * @param db
 *         The {@link SQLiteDatabase}
 * @param originalId
 *         The ID of the task of which to copy the properties
 * @param newId
 *         The ID of the task to copy the properties to.
 */
private void copyProperties(SQLiteDatabase db, long originalId, long newId)
{
    // for each property of the original task
    try (Cursor c = db.query(TaskDatabaseHelper.Tables.PROPERTIES, null /* all */,
            String.format(Locale.ENGLISH, "%s = %d", TaskContract.Properties.TASK_ID, originalId), null, null, null, null))
    {
        // load the property and insert it for the new task
        ContentValues values = new ContentValues(c.getColumnCount());
        while (c.moveToNext())
        {
            values.clear();
            DatabaseUtils.cursorRowToContentValues(c, values);
            PropertyHandler ph = PropertyHandlerFactory.get(values.getAsString(TaskContract.Properties.MIMETYPE));
            ph.insert(db, newId, ph.cloneForNewTask(newId, values), false);
        }
    }
}
 
源代码2 项目: SuntimesWidget   文件: AlarmClockActivity.java
@Override
protected AlarmClockAdapter doInBackground(String... strings)
{
    ArrayList<AlarmClockItem> items = new ArrayList<>();

    db.open();
    Cursor cursor = db.getAllAlarms(0, true);
    while (!cursor.isAfterLast())
    {
        ContentValues entryValues = new ContentValues();
        DatabaseUtils.cursorRowToContentValues(cursor, entryValues);

        AlarmClockItem item = new AlarmClockItem(contextRef.get(), entryValues);
        if (!item.enabled) {
            AlarmNotifications.updateAlarmTime(contextRef.get(), item);
        }
        items.add(item);
        publishProgress(item);

        cursor.moveToNext();
    }
    db.close();

    Context context = contextRef.get();
    if (context != null)
        return new AlarmClockAdapter(context, items, theme);
    else return null;
}
 
源代码3 项目: SuntimesWidget   文件: AlarmDatabaseAdapter.java
@Override
protected AlarmClockItem doInBackground(Long... rowIDs)
{
    AlarmClockItem item = null;
    if (rowIDs.length > 0)
    {
        db.open();
        Cursor cursor0 = db.getAlarm(rowIDs[0]);
        if (cursor0 != null)
        {
            cursor0.moveToFirst();
            if (!cursor0.isAfterLast())
            {
                ContentValues itemValues = new ContentValues();
                DatabaseUtils.cursorRowToContentValues(cursor0, itemValues);
                item = new AlarmClockItem(contextRef.get(), itemValues);

                Cursor cursor1 = db.getAlarmState(rowIDs[0]);
                if (cursor1 != null)
                {
                    cursor1.moveToFirst();
                    if (!cursor1.isAfterLast())
                    {
                        ContentValues stateValues = new ContentValues();
                        DatabaseUtils.cursorRowToContentValues(cursor1, stateValues);
                        item.state = new AlarmState(stateValues);
                    }
                    cursor1.close();
                }
            }
            cursor0.close();
        }
        db.close();
    }
    return item;
}
 
源代码4 项目: SuntimesWidget   文件: ExportPlacesTask.java
/**
 * @param db a GetFixDatabaseAdapter helper
 * @param cursor a database Cursor pointing to records to export
 * @param out a BufferedOutputStream (open and ready) to export to
 * @return true export was successful, false otherwise
 * @throws IOException if failed to write to out
 */
private boolean exportDatabase( GetFixDatabaseAdapter db, Cursor cursor, BufferedOutputStream out ) throws IOException
{
    if (cursor == null)
    {
        Log.w("ExportPlaces", "Canceling export; the database returned a null cursor.");
        return false;
    }

    String csvHeader = db.addPlaceCSV_header() + newLine;
    out.write(csvHeader.getBytes());

    int i = 0;
    cursor.moveToFirst();
    while (!cursor.isAfterLast())
    {
        ContentValues entryValues = new ContentValues();
        DatabaseUtils.cursorRowToContentValues(cursor, entryValues);

        String csvRow = db.addPlaceCSV_row(entryValues) + newLine;
        out.write(csvRow.getBytes());

        cursor.moveToNext();
        i++;

        String msg = entryValues.getAsString(GetFixDatabaseAdapter.KEY_PLACE_NAME);
        ExportProgress progressObj = new ExportProgress(i, numEntries, msg);
        publishProgress(progressObj);
    }
    out.flush();
    return true;
}
 
源代码5 项目: CSipSimple   文件: SipProfileState.java
/** 
 * 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);
}
 
源代码6 项目: CSipSimple   文件: SipProfile.java
/**
 * 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);
}
 
源代码7 项目: CSipSimple   文件: ContactsUtils3.java
@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;
}
 
源代码8 项目: CSipSimple   文件: ContactsUtils14.java
@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;
}
 
源代码9 项目: CSipSimple   文件: Filter.java
public void createFromDb(Cursor c) {
	ContentValues args = new ContentValues();
	DatabaseUtils.cursorRowToContentValues(c, args);
	
	createFromContentValue(args);
}
 
源代码10 项目: CSipSimple   文件: SipMessage.java
/**
 * Construct a sip message wrapper from a cursor retrieved with a
 * {@link ContentProvider} query on {@link #MESSAGES_TABLE_NAME}.
 * 
 * @param c the cursor to unpack
 */
public SipMessage(Cursor c) {
    ContentValues args = new ContentValues();
    DatabaseUtils.cursorRowToContentValues(c, args);
    createFromContentValue(args);
}