Example usage for android.content ContentValues ContentValues

List of usage examples for android.content ContentValues ContentValues

Introduction

In this page you can find the example usage for android.content ContentValues ContentValues.

Prototype

public ContentValues() 

Source Link

Document

Creates an empty set of values using the default initial size

Usage

From source file:com.manning.androidhacks.hack023.dao.TodoDAO.java

private ContentValues getTodoContentValues(Todo todo, int flag) {
    ContentValues cv = new ContentValues();
    cv.put(TodoContentProvider.COLUMN_SERVER_ID, todo.getId());
    cv.put(TodoContentProvider.COLUMN_TITLE, todo.getTitle());
    cv.put(TodoContentProvider.COLUMN_STATUS_FLAG, flag);

    return cv;// ww  w. j a  va  2 s.c  o m
}

From source file:com.manning.androidhacks.hack042.AddPoiActivity.java

public void onAddClick(View v) {
    String title = mTitleEditText.getText().toString();
    String latitude = mLatitudeEditText.getText().toString();
    String longitude = mLongitudeEditText.getText().toString();

    DatabaseHelper dbHelper = new DatabaseHelper(this);
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.put("title", title);
    cv.put("latitude", latitude);
    cv.put("longitude", longitude);

    db.insert("pois", null, cv);
    finish();//from  w  ww  .j a  va2s  .  c o  m
}

From source file:com.lambdasoup.blockvote.base.comms.BlockvoteFirebaseMessagingService.java

private ContentValues fromJson(JSONObject jsonObject, String id, String timestamp) throws JSONException {
    ContentValues cv = new ContentValues();

    cv.put(Stats.ID, id);/*from  w  ww. j a v a2s.  co  m*/
    cv.put(Stats.D30, jsonObject.getDouble("d30"));
    cv.put(Stats.D7, jsonObject.getDouble("d7"));
    cv.put(Stats.D1, jsonObject.getDouble("d1"));
    cv.put(Stats.TIME, timestamp);

    return cv;
}

From source file:com.granita.icloudcalsync.resource.LocalTaskList.java

public static Uri create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws LocalStorageException {
    final ContentProviderClient client = resolver.acquireContentProviderClient(TASKS_AUTHORITY);
    if (client == null)
        throw new LocalStorageException("No tasks provider found");

    ContentValues values = new ContentValues();
    values.put(TaskContract.TaskLists.ACCOUNT_NAME, account.name);
    values.put(TaskContract.TaskLists.ACCOUNT_TYPE, account.type);
    values.put(TaskContract.TaskLists._SYNC_ID, info.getURL());
    values.put(TaskContract.TaskLists.LIST_NAME, info.getTitle());
    values.put(TaskContract.TaskLists.LIST_COLOR, DAVUtils.CalDAVtoARGBColor(info.getColor()));
    values.put(TaskContract.TaskLists.OWNER, account.name);
    values.put(TaskContract.TaskLists.ACCESS_LEVEL, 0);
    values.put(TaskContract.TaskLists.SYNC_ENABLED, 1);
    values.put(TaskContract.TaskLists.VISIBLE, 1);

    Log.i(TAG, "Inserting task list: " + values.toString());
    try {//  w w  w. j  a v a2 s  . com
        return client.insert(taskListsURI(account), values);
    } catch (RemoteException e) {
        throw new LocalStorageException(e);
    }
}

From source file:com.onesignal.NotificationBundleProcessor.java

private static void saveNotification(Context context, Bundle bundle, boolean opened, int notificationId) {
    try {/*from w  w w  . j  a v  a2  s.co  m*/
        JSONObject customJSON = new JSONObject(bundle.getString("custom"));

        OneSignalDbHelper dbHelper = new OneSignalDbHelper(context);
        SQLiteDatabase writableDb = dbHelper.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(NotificationTable.COLUMN_NAME_NOTIFICATION_ID, customJSON.getString("i"));
        if (bundle.containsKey("grp"))
            values.put(NotificationTable.COLUMN_NAME_GROUP_ID, bundle.getString("grp"));

        values.put(NotificationTable.COLUMN_NAME_OPENED, opened ? 1 : 0);
        if (!opened)
            values.put(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, notificationId);

        if (bundle.containsKey("title"))
            values.put(NotificationTable.COLUMN_NAME_TITLE, bundle.getString("title"));
        values.put(NotificationTable.COLUMN_NAME_MESSAGE, bundle.getString("alert"));

        values.put(NotificationTable.COLUMN_NAME_FULL_DATA, bundleAsJSONObject(bundle).toString());

        writableDb.insert(NotificationTable.TABLE_NAME, null, values);

        // Clean up old records that have been dismissed or opened already after 1 week.
        writableDb.delete(NotificationTable.TABLE_NAME,
                NotificationTable.COLUMN_NAME_CREATED_TIME + " < "
                        + ((System.currentTimeMillis() / 1000) - 604800) + " AND " + "("
                        + NotificationTable.COLUMN_NAME_DISMISSED + " = 1 OR "
                        + NotificationTable.COLUMN_NAME_OPENED + " = 1" + ")",
                null);

        writableDb.close();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.goliathonline.android.kegbot.io.RemoteUserHandler.java

private static ContentValues queryUserDetails(Uri uri, ContentResolver resolver) {
    final ContentValues values = new ContentValues();
    final Cursor cursor = resolver.query(uri, UserQuery.PROJECTION, null, null, null);
    try {/*from   w  w  w  .j ava2 s  .  c  om*/
        if (cursor.moveToFirst()) {
            values.put(SyncColumns.UPDATED, cursor.getLong(UserQuery.UPDATED));
        } else {
            values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER);
        }
    } finally {
        cursor.close();
    }
    return values;
}

From source file:net.bible.service.db.mynote.MyNoteDBAdapter.java

public MyNoteDto insertMyNote(MyNoteDto mynote) {
    // Create a new row of values to insert.
    Log.d(TAG, "about to insertMyNote: " + mynote.getVerse());
    Verse verse = mynote.getVerse();/*from w  w  w  . ja v  a2  s. co  m*/
    String v11nName = getVersification(verse);
    // Gets the current system time in milliseconds
    Long now = Long.valueOf(System.currentTimeMillis());

    ContentValues newValues = new ContentValues();
    newValues.put(MyNoteColumn.KEY, verse.getOsisID());
    newValues.put(MyNoteColumn.VERSIFICATION, v11nName);
    newValues.put(MyNoteColumn.MYNOTE, mynote.getNoteText());
    newValues.put(MyNoteColumn.LAST_UPDATED_ON, now);
    newValues.put(MyNoteColumn.CREATED_ON, now);

    long newId = db.insert(Table.MYNOTE, null, newValues);
    MyNoteDto newMyNote = getMyNoteDto(newId);
    return newMyNote;
}

From source file:com.manning.androidhacks.hack043.service.SQLContentProviderService.java

@Override
protected void onHandleIntent(Intent intent) {
    Builder builder = null;/*from   w ww  . ja  va  2  s . c  o  m*/
    ContentResolver contentResolver = getContentResolver();
    ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();

    builder = ContentProviderOperation.newDelete(MySQLContentProvider.CONTENT_URI);
    operations.add(builder.build());

    for (int i = 1; i <= 100; i++) {
        ContentValues cv = new ContentValues();
        cv.put(MySQLContentProvider.COLUMN_TEXT, "" + i);

        builder = ContentProviderOperation.newInsert(MySQLContentProvider.CONTENT_URI);
        builder.withValues(cv);

        operations.add(builder.build());
    }

    try {
        contentResolver.applyBatch(MySQLContentProvider.AUTHORITY, operations);
    } catch (RemoteException e) {
        Log.e(TAG, "Couldn't apply batch: " + e.getMessage());
    } catch (OperationApplicationException e) {
        Log.e(TAG, "Couldn't apply batch: " + e.getMessage());
    }

}

From source file:at.bitfire.davdroid.resource.LocalTaskList.java

public static Uri create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws LocalStorageException {
    @Cleanup("release")
    final ContentProviderClient client = resolver.acquireContentProviderClient(TASKS_AUTHORITY);
    if (client == null)
        throw new LocalStorageException("No tasks provider found");

    ContentValues values = new ContentValues();
    values.put(TaskContract.TaskLists.ACCOUNT_NAME, account.name);
    values.put(TaskContract.TaskLists.ACCOUNT_TYPE, account.type);
    values.put(TaskContract.TaskLists._SYNC_ID, info.getURL());
    values.put(TaskContract.TaskLists.LIST_NAME, info.getTitle());
    values.put(TaskContract.TaskLists.LIST_COLOR,
            info.getColor() != null ? info.getColor() : DAVUtils.calendarGreen);
    values.put(TaskContract.TaskLists.OWNER, account.name);
    values.put(TaskContract.TaskLists.ACCESS_LEVEL, 0);
    values.put(TaskContract.TaskLists.SYNC_ENABLED, 1);
    values.put(TaskContract.TaskLists.VISIBLE, 1);

    Log.i(TAG, "Inserting task list: " + values.toString());
    try {//www.j  a  v  a 2  s . c  om
        return client.insert(taskListsURI(account), values);
    } catch (RemoteException e) {
        throw new LocalStorageException(e);
    }
}

From source file:com.clevertrail.mobile.Database_SavedTrails.java

public long insert(String sName, String sJSON) {
    ContentValues contentValues = new ContentValues();
    contentValues.put("name", sName.replace("_", " "));
    contentValues.put("json", sJSON);
    return sqLiteDatabase.insert(MYDATABASE_TABLE, null, contentValues);
}