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.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 {/*w ww  . j  ava2s  .  c o m*/
        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:totalcross.android.ConnectionManager4A.java

public static void setDefaultConfiguration(int type, String cfg) {
    if (cfg == null)
        cfg = "";

    switch (type) {
    case GPRS: {//from   w w  w.  j a v a 2 s .  com
        int id = -1;
        ContentResolver contentResolver = Launcher4A.loader.getContentResolver();
        Cursor cursor = contentResolver.query(CONTENT_URI, new String[] { "_id" },
                "apn = ? and user = ? and password = ?", new String[] { "tim.br", "tim", "tim" }, null);
        if (cursor == null || cursor.getCount() <= 0) {
            TelephonyManager tel = (TelephonyManager) Launcher4A.loader
                    .getSystemService(Context.TELEPHONY_SERVICE);
            String networkOperator = tel.getNetworkOperator();

            if (networkOperator != null && networkOperator.length() > 0) {
                int mcc = Integer.parseInt(networkOperator.substring(0, 3));
                int mnc = Integer.parseInt(networkOperator.substring(3));
                ContentValues values = new ContentValues();
                values.put("apn", "tim.br");
                values.put("user", "tim");
                values.put("password", "tim");
                values.put("mcc", mcc);
                values.put("mnc", mnc);
                values.put("numeric", mcc + "" + mnc);
                contentResolver.insert(CONTENT_URI, values);
                cursor = contentResolver.query(CONTENT_URI, new String[] { "_id" },
                        "apn = ? and user = ? and password = ?", new String[] { "tim.br", "tim", "tim" }, null);
            }
        }
        if (cursor == null)
            return;
        if (cursor.moveToFirst())
            id = cursor.getInt(0);
        cursor.close();

        if (id > -1) {
            ContentValues values = new ContentValues();
            //See /etc/apns-conf.xml. The TelephonyProvider uses this file to provide
            //content://telephony/carriers/preferapn URI mapping
            values.put("apn_id", id);
            contentResolver.update(PREFERRED_APN_URI, values, null, null);
            cursor = contentResolver.query(PREFERRED_APN_URI, new String[] { "name", "apn" }, "_id=" + id, null,
                    null);
            if (cursor != null)
                cursor.close();
        }
    }
        break;
    case WIFI:
        connWIFI = connWIFIPrefix + cfg;
        break;
    //default:
    //   throw new IllegalArgumentException("Invalid value for argument 'type'");
    }
}

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

@TargetApi(15)
public static Uri create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws CalendarStorageException {
    @Cleanup("release")
    ContentProviderClient provider = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
    if (provider == null)
        throw new CalendarStorageException(
                "Couldn't acquire ContentProviderClient for " + CalendarContract.AUTHORITY);

    ContentValues values = new ContentValues();
    values.put(Calendars.NAME, info.getUrl());
    values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle());
    values.put(Calendars.CALENDAR_COLOR, info.color != null ? info.color : defaultColor);

    if (info.isReadOnly())
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
    else {/*from   w ww  . j a  va2  s.com*/
        values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
        values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1);
        values.put(Calendars.CAN_ORGANIZER_RESPOND, 1);
    }

    values.put(Calendars.OWNER_ACCOUNT, account.name);
    values.put(Calendars.SYNC_EVENTS, 1);
    values.put(Calendars.VISIBLE, 1);
    if (!TextUtils.isEmpty(info.timezone)) {
        VTimeZone timeZone = DateUtils.parseVTimeZone(info.timezone);
        if (timeZone != null && timeZone.getTimeZoneId() != null)
            values.put(Calendars.CALENDAR_TIME_ZONE,
                    DateUtils.findAndroidTimezoneID(timeZone.getTimeZoneId().getValue()));
    }
    values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT);
    if (Build.VERSION.SDK_INT >= 15) {
        values.put(Calendars.ALLOWED_AVAILABILITY,
                StringUtils.join(new int[] { Reminders.AVAILABILITY_TENTATIVE, Reminders.AVAILABILITY_FREE,
                        Reminders.AVAILABILITY_BUSY }, ","));
        values.put(Calendars.ALLOWED_ATTENDEE_TYPES,
                StringUtils.join(new int[] { CalendarContract.Attendees.TYPE_OPTIONAL,
                        CalendarContract.Attendees.TYPE_REQUIRED, CalendarContract.Attendees.TYPE_RESOURCE },
                        ", "));
    }
    return create(account, provider, values);
}

From source file:curso.android.DAO.PerguntaDAO.java

public static void update(Pergunta ask) {
    try {//from w ww  .  java 2 s .  c  o  m

        Const.db.beginTransaction();
        // insert this row

        ContentValues values = new ContentValues();
        values.put("status", ask.isStatus() ? 1 : 0);
        Const.db.update("pergunta", values, "ask_id=" + ask.getAsk_id(), null);

        Const.db.setTransactionSuccessful();
    } finally {
        Const.db.endTransaction();
    }
}

From source file:com.ultramegatech.ey.UpdateService.java

/**
 * Add a value from a JSONObject to a ContentValues object in the appropriate data type.
 * /*from   ww  w. j  a va  2s  .c om*/
 * @param to
 * @param from
 * @param key The key of the entry to process
 * @throws JSONException 
 */
private static void addValue(ContentValues to, JSONObject from, String key) throws JSONException {
    switch (Elements.getColumnType(key)) {
    case INTEGER:
    case BOOLEAN:
        to.put(key, from.getInt(key));
        break;
    case REAL:
        to.put(key, from.getDouble(key));
        break;
    case TEXT:
        to.put(key, from.getString(key));
        break;
    }
}

From source file:com.kku.apps.pricesearch.util.Utils.java

public static void entryHistory(Context context, ListItem item) {

    final ContentValues cv = new ContentValues();
    cv.put(HistoryColumns.KEYWORDS, item.getKeywords());
    cv.put(HistoryColumns.NAME, item.getName());
    if (item.getImage() != null) {
        cv.put(HistoryColumns.IMAGE, getByteImage(item.getImage()));
    }/*from   w  w  w .j  a  v  a2 s. c  o  m*/
    cv.put(HistoryColumns.DATE, Utils.getDate());
    final AsyncQueryHandler dbHandler = new AsyncQueryHandler(context.getContentResolver()) {

        @Override
        protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
            super.onQueryComplete(token, cookie, cursor);
        }
    };
    dbHandler.startInsert(0, null, SearchContract.URI_HISTORY, cv);
}

From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java

/** Insert a new plugin provider to the provider table. */
private static long insertProviderRow(ContentResolver cr, String providerName, String providerFullName,
        String signUpUrl) {/* ww  w .  j  a v  a2  s.co  m*/
    ContentValues values = new ContentValues(3);
    values.put(Imps.Provider.NAME, providerName);
    values.put(Imps.Provider.FULLNAME, providerFullName);
    values.put(Imps.Provider.CATEGORY, ImApp.IMPS_CATEGORY);
    values.put(Imps.Provider.SIGNUP_URL, signUpUrl);
    Uri result = cr.insert(Imps.Provider.CONTENT_URI, values);
    return ContentUris.parseId(result);
}

From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java

public static void updateAvatarBlob(ContentResolver resolver, Uri updateUri, byte[] data, String username) {
    ContentValues values = new ContentValues(3);
    values.put(Imps.Avatars.DATA, data);

    StringBuilder buf = new StringBuilder(Imps.Avatars.CONTACT);
    buf.append("=?");

    String[] selectionArgs = new String[] { username };

    resolver.update(updateUri, values, buf.toString(), selectionArgs);

}

From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java

public static boolean hasAvatarContact(ContentResolver resolver, Uri updateUri, String username) {
    ContentValues values = new ContentValues(3);
    values.put(Imps.Avatars.CONTACT, username);

    StringBuilder buf = new StringBuilder(Imps.Avatars.CONTACT);
    buf.append("=?");

    String[] selectionArgs = new String[] { username };

    return resolver.update(updateUri, values, buf.toString(), selectionArgs) > 0;

}

From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java

public static void insertAvatarBlob(ContentResolver resolver, Uri updateUri, long providerId, long accountId,
        byte[] data, String hash, String contact) {

    ContentValues values = new ContentValues(3);
    values.put(Imps.Avatars.DATA, data);
    values.put(Imps.Avatars.CONTACT, contact);
    values.put(Imps.Avatars.PROVIDER, providerId);
    values.put(Imps.Avatars.ACCOUNT, accountId);
    values.put(Imps.Avatars.HASH, hash);
    resolver.insert(updateUri, values);/*from  w ww .  java  2  s  .  c om*/

}