Java Code Examples for android.database.DatabaseUtils#cursorRowToContentValues()

The following examples show how to use android.database.DatabaseUtils#cursorRowToContentValues() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskValueDelegate.java    From opentasks with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 2
Source File: AlarmClockActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 3
Source File: AlarmDatabaseAdapter.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 4
Source File: ExportPlacesTask.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 5
Source File: SipProfileState.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
/** 
 * 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);
}
 
Example 6
Source File: SipProfile.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 7
Source File: ContactsUtils3.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example 8
Source File: ContactsUtils14.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example 9
Source File: Filter.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
public void createFromDb(Cursor c) {
	ContentValues args = new ContentValues();
	DatabaseUtils.cursorRowToContentValues(c, args);
	
	createFromContentValue(args);
}
 
Example 10
Source File: SipMessage.java    From CSipSimple with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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);
}