Example usage for android.content ContentValues put

List of usage examples for android.content ContentValues put

Introduction

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

Prototype

public void put(String key, byte[] value) 

Source Link

Document

Adds a value to the set.

Usage

From source file:com.ubuntuone.android.files.provider.MetaUtilities.java

public static void setState(final String resourcePath, final String state) {
    final ContentValues values = new ContentValues();
    values.put(Nodes.NODE_RESOURCE_STATE, state);
    final String where = Nodes.NODE_RESOURCE_PATH + "=?";
    final String[] selectionArgs = new String[] { resourcePath };
    sResolver.update(Nodes.CONTENT_URI, values, where, selectionArgs);
}

From source file:com.ubuntuone.android.files.provider.MetaUtilities.java

public static void setStateAndData(final String resourcePath, final String state, final String data) {
    final String[] selectionArgs = new String[] { resourcePath };
    final ContentValues values = new ContentValues();
    values.put(Nodes.NODE_RESOURCE_STATE, state);
    values.put(Nodes.NODE_DATA, data);/*from  ww w . j av a2s  .  c  o m*/
    sResolver.update(Nodes.CONTENT_URI, values, sSelection, selectionArgs);
}

From source file:com.ubuntuone.android.files.provider.MetaUtilities.java

public static int resetFailedTransfers(String method) {
    String ongoing;/*from  w  ww.j  av  a2  s .c  o m*/
    String failed;
    if (HttpPost.METHOD_NAME.equals(method)) {
        ongoing = ResourceState.STATE_POSTING;
        failed = ResourceState.STATE_POSTING_FAILED;
    } else if (HttpGet.METHOD_NAME.equals(method)) {
        ongoing = ResourceState.STATE_GETTING;
        failed = ResourceState.STATE_GETTING_FAILED;
    } else {
        Log.e(TAG, "Bad method name: " + method);
        return 0;
    }

    final ContentValues values = new ContentValues(1);
    values.put(Nodes.NODE_RESOURCE_STATE, failed);
    final String where = Nodes.NODE_RESOURCE_STATE + "=?";
    final String[] selectionArgs = new String[] { ongoing };
    return sResolver.update(Nodes.CONTENT_URI, values, where, selectionArgs);
}

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

@SuppressLint("InlinedApi")
public static Uri create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws LocalStorageException {
    final ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
    if (client == null)
        throw new LocalStorageException("No Calendar Provider found (Calendar app disabled?)");

    ContentValues values = new ContentValues();
    values.put(Calendars.ACCOUNT_NAME, account.name);
    values.put(Calendars.ACCOUNT_TYPE, account.type);
    values.put(Calendars.NAME, info.getURL());
    values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
    values.put(Calendars.CALENDAR_COLOR, DAVUtils.CalDAVtoARGBColor(info.getColor()));
    values.put(Calendars.OWNER_ACCOUNT, account.name);
    values.put(Calendars.SYNC_EVENTS, 1);
    values.put(Calendars.VISIBLE, 1);//  www . j  a va  2s  .co  m
    values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT);

    if (info.isReadOnly())
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
    else {
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
        values.put(Calendars.CAN_ORGANIZER_RESPOND, 1);
        values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1);
    }

    if (android.os.Build.VERSION.SDK_INT >= 15) {
        values.put(Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE
                + "," + Events.AVAILABILITY_TENTATIVE);
        values.put(Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + ","
                + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE);
    }

    if (info.getTimezone() != null)
        values.put(Calendars.CALENDAR_TIME_ZONE, info.getTimezone());

    Log.i(TAG, "Inserting calendar: " + values.toString());
    try {
        return client.insert(calendarsURI(account), values);
    } catch (RemoteException e) {
        throw new LocalStorageException(e);
    }
}

From source file:com.smarthome.deskclock.Alarms.java

private static ContentValues createContentValues(Alarm alarm) {
    ContentValues values = new ContentValues(8);
    // Set the alarm_time value if this alarm does not repeat. This will be
    // used later to disable expire alarms.
    long time = 0;
    if (!alarm.daysOfWeek.isRepeatSet()) {
        time = calculateAlarm(alarm);/*w w w  .  j a  va2 s. co  m*/
    }

    values.put(Alarm.Columns.ENABLED, alarm.enabled ? 1 : 0);
    values.put(Alarm.Columns.HOUR, alarm.hour);
    values.put(Alarm.Columns.MINUTES, alarm.minutes);
    values.put(Alarm.Columns.ALARM_TIME, alarm.time);
    values.put(Alarm.Columns.DAYS_OF_WEEK, alarm.daysOfWeek.getCoded());
    values.put(Alarm.Columns.VIBRATE, alarm.vibrate);
    values.put(Alarm.Columns.MESSAGE, alarm.label);

    // A null alert Uri indicates a silent alarm.
    values.put(Alarm.Columns.ALERT, alarm.alert == null ? ALARM_ALERT_SILENT : alarm.alert.toString());

    values.put(Alarm.Columns.OPERATION, alarm.operation);
    values.put(Alarm.Columns.MUSIC, alarm.musicPath);

    return values;
}

From source file:com.stockita.popularmovie.utility.Utilities.java

/**
 * This is the method that will do the parsing and bulk inserting to tables,
 * MovieEntry, GenreEntry./*from ww  w . jav a 2 s .  co  m*/
 *
 */
public static void parseFeed(final Context context, String dataFetch, String key, String sortGroup) {

    // Instantiate the Content Resolver.
    sContentResolver = context.getContentResolver();

    // Timestamp.
    sCurrentTime = System.currentTimeMillis();

    // A container for MovieEntry for bulk insert
    ArrayList<ContentValues> lValuesMovieEntry = new ArrayList<>();

    // Lets rock n roll.
    try {

        // String to the root of JSONObject, the argument s is a String in JSON format.
        JSONObject rootObject = new JSONObject(dataFetch);

        // Call the rootObjet and get the key assign to String variable
        String rootObj = rootObject.get("results").toString();

        // Now the rootObj has the value of "result" which is a JSON Array
        // then assign it as argument into JSONArray object
        JSONArray ar = new JSONArray(rootObj);
        final int arSize = ar.length();

        // Iterate for each element in the JSONArray
        for (int i = 0; i < arSize; i++) {

            // Convert each element in ar into JSONOject
            // and pass the argument [i] which [i] is the index of each element.
            JSONObject obj = ar.getJSONObject(i);

            // Add Temp variable so we pass it to parseGenre() argument later.
            String movieIdHolder = obj.getString("id");

            // For MovieEntry
            ContentValues contentMovieValues = new ContentValues();
            contentMovieValues.put(ContractMovies.MovieEntry.COLUMN_BACKDROP_PATH,
                    obj.getString("backdrop_path"));
            contentMovieValues.put(ContractMovies.MovieEntry.COLUMN_MOVIE_ID, String.valueOf(movieIdHolder));
            contentMovieValues.put(ContractMovies.MovieEntry.COLUMN_ORIGINAL_LANGUAGE,
                    obj.getString("original_language"));
            contentMovieValues.put(ContractMovies.MovieEntry.COLUMN_MOVIE_TITLE,
                    obj.getString("original_title"));
            contentMovieValues.put(ContractMovies.MovieEntry.COLUMN_OVERVIEW, obj.getString("overview"));
            contentMovieValues.put(ContractMovies.MovieEntry.COLUMN_RELEASE_DATE,
                    obj.getString("release_date"));
            contentMovieValues.put(ContractMovies.MovieEntry.COLUMN_POSTER_PATH, obj.getString("poster_path"));
            contentMovieValues.put(ContractMovies.MovieEntry.COLUMN_POPULARITY, obj.getInt("popularity"));
            contentMovieValues.put(ContractMovies.MovieEntry.COLUMN_AVERAGE_VOTE,
                    obj.getDouble("vote_average"));
            contentMovieValues.put(ContractMovies.MovieEntry.COLUMN_VOTE_COUNT, obj.getInt("vote_count"));
            contentMovieValues.put(ContractMovies.MovieEntry.COLUMN_POSTING_TIME, sCurrentTime);
            contentMovieValues.put(ContractMovies.MovieEntry.COLUMN_SORT_GROUP, sortGroup);

            // Pack the object contentMovieValues into ArrayList<ContentValues> lValuesMovieEntry
            lValuesMovieEntry.add(contentMovieValues);

            // Begin of GenreEntry insert.
            // for extract sub array/field genre_ids
            JSONArray genre = obj.getJSONArray("genre_ids");
            parseGenre(context, movieIdHolder, genre, sCurrentTime, sortGroup);

        } // end for loop

        // MovieEntry
        // Bulk insert for MovieEntry.
        try {
            // Bulk insert
            ContentValues[] lInsertData = new ContentValues[lValuesMovieEntry.size()];
            lValuesMovieEntry.toArray(lInsertData);
            int lInsertedData = context.getContentResolver().bulkInsert(ContractMovies.MovieEntry.CONTENT_URI,
                    lInsertData);

        } catch (Exception e) {
            Log.e(LOG_TAG, e.toString());
        }

        // Store the current time millis in SharedPreference so we can use it
        // the next time.
        setTimeStamp(context, key, sCurrentTime);

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

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

@SuppressLint("InlinedApi")
public static Uri create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws LocalStorageException {
    @Cleanup("release")
    final ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
    if (client == null)
        throw new LocalStorageException("No Calendar Provider found (Calendar app disabled?)");

    ContentValues values = new ContentValues();
    values.put(Calendars.ACCOUNT_NAME, account.name);
    values.put(Calendars.ACCOUNT_TYPE, account.type);
    values.put(Calendars.NAME, info.getURL());
    values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
    values.put(Calendars.CALENDAR_COLOR, info.getColor() != null ? info.getColor() : DAVUtils.calendarGreen);
    values.put(Calendars.OWNER_ACCOUNT, account.name);
    values.put(Calendars.SYNC_EVENTS, 1);
    values.put(Calendars.VISIBLE, 1);/* w w  w .  jav a  2 s.  c  o m*/
    values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT);

    if (info.isReadOnly())
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
    else {
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
        values.put(Calendars.CAN_ORGANIZER_RESPOND, 1);
        values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1);
    }

    if (android.os.Build.VERSION.SDK_INT >= 15) {
        values.put(Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE
                + "," + Events.AVAILABILITY_TENTATIVE);
        values.put(Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + ","
                + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE);
    }

    if (info.getTimezone() != null)
        values.put(Calendars.CALENDAR_TIME_ZONE, DateUtils.findAndroidTimezoneID(info.getTimezone()));

    Log.i(TAG, "Inserting calendar: " + values.toString());
    try {
        return client.insert(calendarsURI(account), values);
    } catch (RemoteException e) {
        throw new LocalStorageException(e);
    }
}

From source file:com.nbos.phonebook.sync.platform.ContactManager.java

/**
  * Add a list of status messages to the contacts provider.
  * /*from   w  ww  . ja  v a  2 s  .co  m*/
  * @param context the context to use
  * @param accountName the username of the logged in user
  * @param statuses the list of statuses to store
  */
public static void insertStatuses(Context context, String username, List<User.Status> list) {
    final ContentValues values = new ContentValues();
    final ContentResolver resolver = context.getContentResolver();
    final BatchOperation batchOperation = new BatchOperation(context);
    for (final User.Status status : list) {
        // Look up the user's sample SyncAdapter data row
        final long userId = status.getUserId();
        final long profileId = lookupProfile(resolver, userId);

        // Insert the activity into the stream
        if (profileId > 0) {
            values.put(StatusUpdates.DATA_ID, profileId);
            values.put(StatusUpdates.STATUS, status.getStatus());
            values.put(StatusUpdates.PROTOCOL, Im.PROTOCOL_CUSTOM);
            values.put(StatusUpdates.CUSTOM_PROTOCOL, CUSTOM_IM_PROTOCOL);
            values.put(StatusUpdates.IM_ACCOUNT, username);
            values.put(StatusUpdates.IM_HANDLE, status.getUserId());
            values.put(StatusUpdates.STATUS_RES_PACKAGE, context.getPackageName());
            values.put(StatusUpdates.STATUS_ICON, R.drawable.icon);
            values.put(StatusUpdates.STATUS_LABEL, R.string.label);

            batchOperation.add(
                    ContactOperations.newInsertCpo(StatusUpdates.CONTENT_URI, true).withValues(values).build());
            // A sync adapter should batch operations on multiple contacts,
            // because it will make a dramatic performance difference.
            if (batchOperation.size() >= 50) {
                batchOperation.execute();
            }
        }
    }
    batchOperation.execute();
}

From source file:edu.mit.mobile.android.locast.data.JsonSyncableItem.java

/**
 * @param columnName the name of the key in cv to store the resulting list
 * @param cv a {@link ContentValues} to store the resulting list in
 * @param list/*from  ww w . ja v  a 2  s .c om*/
 * @return the same ContentValues that were passed in
 * @see #toListString(Collection)
 */
public static ContentValues putList(String columnName, ContentValues cv, Collection<String> list) {
    cv.put(columnName, toListString(list));
    return cv;
}

From source file:com.android.contacts.common.model.ContactLoader.java

private static void processOneRecord(RawContact rawContact, JSONObject item, String mimetype)
        throws JSONException {
    final ContentValues itemValues = new ContentValues();
    itemValues.put(Data.MIMETYPE, mimetype);
    itemValues.put(Data._ID, -1);

    final Iterator iterator = item.keys();
    while (iterator.hasNext()) {
        String name = (String) iterator.next();
        final Object o = item.get(name);
        if (o instanceof String) {
            itemValues.put(name, (String) o);
        } else if (o instanceof Integer) {
            itemValues.put(name, (Integer) o);
        }//from www .  j  ava 2  s.  c om
    }
    rawContact.addDataItemValues(itemValues);
}