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

private ContentValues(Parcel in) 

Source Link

Usage

From source file:com.github.gw2app.events.Gw2StaticData.java

private void _update_event_names() {
    if (Gw2JSONDownloader.internetAvailable(mContext)) {
        String result = Gw2JSONDownloader.downloadJSON(Gw2JSONDownloader.event_names_url);

        SQLiteDatabase db = mDBHelper.getWritableDatabase();
        Cursor cursor = db.query(Gw2DB.EVENT_NAMES_TABLE, null, null, null, null, null, null);

        JSONArray jsData;//from  www  .j  a va2 s .  co m

        try {
            jsData = new JSONArray(result);
            Log.d("Gw2", "LENGTH: " + jsData.length());
            Log.d("Gw2", "POCESSING STARTS");
            for (int i = 0; i < jsData.length(); i++) {
                JSONObject obj = jsData.getJSONObject(i);
                String id = obj.getString("id");
                String name = obj.getString("name");
                //Log.d("Gw2", name);

                ContentValues row = new ContentValues(3);
                row.put("_id", id);
                row.put("name", name);
                row.put("lang", "en");

                if (db != null) {
                    db.insert(Gw2DB.EVENT_NAMES_TABLE, null, row);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else {
        //TODO: throw exception.
    }
}

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:at.bitfire.ical4android.AndroidTask.java

public Task getTask() throws FileNotFoundException, CalendarStorageException {
    if (task != null)
        return task;

    try {/*  w w  w. jav a 2 s  .c  om*/
        task = new Task();
        @Cleanup
        final Cursor cursor = taskList.provider.client.query(taskSyncURI(), null, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            ContentValues values = new ContentValues(cursor.getColumnCount());
            DatabaseUtils.cursorRowToContentValues(cursor, values);
            populateTask(values);
        } else
            throw new FileNotFoundException("Couldn't load details of task #" + id);
        return task;
    } catch (RemoteException e) {
        throw new CalendarStorageException("Couldn't read locally stored event", e);
    } catch (ParseException e) {
        throw new CalendarStorageException("Couldn't parse locally stored event", e);
    }
}

From source file:com.QuarkLabs.BTCeClient.UpdateWidgetsTask.java

@Override
protected JSONObject doInBackground(Void... params) {
    Set<String> set = new HashSet<>();
    JSONObject response = null;/*from  w ww .  j av a 2s  .  com*/
    for (int x : mMap.keySet()) {
        set.add(mMap.get(x));
    }
    try {
        response = App.getPairInfo(set.toArray(new String[set.size()]));
        response = response == null ? new JSONObject() : response;
        Context context = mContext.get();
        if (context == null) {
            return null;
        }
        DBWorker dbWorker = DBWorker.getInstance(context);
        String[] columns = { "pair", "last" };
        Cursor cursor = dbWorker.pullWidgetData(columns);
        Map<String, Double> values = new HashMap<>();
        if (cursor.moveToFirst()) {
            while (!cursor.isAfterLast()) {
                values.put(cursor.getString(cursor.getColumnIndex(columns[0])),
                        cursor.getDouble(cursor.getColumnIndex(columns[1])));
                cursor.moveToNext();
            }
        }
        cursor.close();
        for (@SuppressWarnings("unchecked")
        Iterator<String> x = response.keys(); x.hasNext();) {
            String pair = x.next();
            String pairInDB = pair.replace("_", "/").toUpperCase(Locale.US);
            ContentValues cv = new ContentValues(4);
            double last = response.getJSONObject(pair).getDouble("last");
            double sell = response.getJSONObject(pair).getDouble("sell");
            double buy = response.getJSONObject(pair).getDouble("buy");
            cv.put("last", last);
            cv.put("buy", buy);
            cv.put("sell", sell);
            if (values.containsKey(pairInDB)) {
                if (last >= values.get(pairInDB)) {
                    response.getJSONObject(pair).put("color", "green");
                } else {
                    response.getJSONObject(pair).put("color", "red");
                }
            } else {
                response.getJSONObject(pair).put("color", "green");
            }

            int result = dbWorker.updateWidgetData(cv, pair.replace("_", "/").toUpperCase(Locale.US));
            if (result == 0) {
                cv.put("pair", pair.replace("_", "/").toUpperCase(Locale.US));
                dbWorker.insertToWidgetData(cv);
            }
        }

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

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:com.granita.contacticloudsync.syncadapter.CalendarSyncManager.java

@Override
protected void queryCapabilities() throws DavException, IOException, HttpException, CalendarStorageException {
    davCollection.propfind(0, DisplayName.NAME, CalendarColor.NAME, GetCTag.NAME);

    // update name and color
    log.info("Setting calendar name and color (if available)");
    ContentValues values = new ContentValues(2);

    DisplayName pDisplayName = (DisplayName) davCollection.properties.get(DisplayName.NAME);
    if (pDisplayName != null && !TextUtils.isEmpty(pDisplayName.displayName))
        values.put(Calendars.CALENDAR_DISPLAY_NAME, pDisplayName.displayName);

    CalendarColor pColor = (CalendarColor) davCollection.properties.get(CalendarColor.NAME);
    if (pColor != null && pColor.color != null)
        values.put(Calendars.CALENDAR_COLOR, pColor.color);

    if (values.size() > 0)
        localCalendar().update(values);//from  w  w  w  .  ja va 2 s. co  m
}

From source file:com.granita.contacticloudsync.syncadapter.TasksSyncManager.java

@Override
protected void queryCapabilities() throws DavException, IOException, HttpException, CalendarStorageException {
    davCollection.propfind(0, DisplayName.NAME, CalendarColor.NAME, GetCTag.NAME);

    // update name and color
    log.info("Setting task list name and color (if available)");
    ContentValues values = new ContentValues(2);

    DisplayName pDisplayName = (DisplayName) davCollection.properties.get(DisplayName.NAME);
    if (pDisplayName != null && !TextUtils.isEmpty(pDisplayName.displayName))
        values.put(TaskLists.LIST_NAME, pDisplayName.displayName);

    CalendarColor pColor = (CalendarColor) davCollection.properties.get(CalendarColor.NAME);
    if (pColor != null && pColor.color != null)
        values.put(TaskLists.LIST_COLOR, pColor.color);

    if (values.size() > 0)
        localTaskList().update(values);/*from  w  w  w. jav a 2  s . co  m*/
}

From source file:net.niyonkuru.koodroid.html.SubscribersHandler.java

@Override
public ArrayList<ContentProviderOperation> parse(Document doc, ContentResolver resolver)
        throws HandlerException {
    final ArrayList<ContentProviderOperation> batch = new ArrayList<ContentProviderOperation>();

    Element subscriberLi = doc.select("div#banSelector li:has(div)").first();
    while (subscriberLi != null) {
        String text = subscriberLi.text();

        /* this assumes the name and phone number are separated by a space */
        int separator = text.lastIndexOf(' ') + 1;

        String subscriberId = text.substring(separator).replaceAll("\\D", "");
        if (subscriberId.length() != 10)
            throw new HandlerException(getString(R.string.parser_error_unexpected_input));

        final ContentProviderOperation.Builder builder;

        final Uri subscriberUri = Subscribers.buildSubscriberUri(subscriberId);
        if (subscriberExists(subscriberUri, resolver)) {
            builder = ContentProviderOperation.newUpdate(subscriberUri);
            builder.withValue(Subscribers.UPDATED, System.currentTimeMillis());
        } else {/*  w ww .j  a  va 2  s  . co m*/
            builder = ContentProviderOperation.newInsert(Subscribers.CONTENT_URI);
        }
        builder.withValue(Subscribers.SUBSCRIBER_ID, subscriberId);

        String fullName = "";
        String[] names = text.substring(0, separator).split("\\s");
        for (String name : names) {
            fullName += ParserUtils.capitalize(name) + " ";
        }
        builder.withValue(Subscribers.SUBSCRIBER_FULL_NAME, fullName.trim());

        if (subscriberLi.hasAttr("onClick")) {
            String switchUrl = subscriberLi.attr("onClick");

            /* extract only the url */
            switchUrl = switchUrl.substring(switchUrl.indexOf('/'), switchUrl.lastIndexOf('\''));
            builder.withValue(Subscribers.SUBSCRIBER_SWITCHER, switchUrl);
        } else { /* this is the default subscriber as it doesn't have a switcher url */
            ContentValues cv = new ContentValues(1);
            cv.put(Settings.SUBSCRIBER, subscriberId);

            resolver.insert(Settings.CONTENT_URI, cv);
        }
        builder.withValue(Subscribers.SUBSCRIBER_EMAIL, mParent);

        batch.add(builder.build());

        subscriberLi = subscriberLi.nextElementSibling();
    }
    if (batch.size() == 0)
        throw new HandlerException(getString(R.string.parser_error_unexpected_input));

    JSONObject metadata = new JSONObject();
    try {
        metadata.put("subscribers", batch.size());
        metadata.put("language", getString(R.string.locale));
    } catch (JSONException ignored) {
    }
    Crittercism.setMetadata(metadata);
    Crittercism.setUsername(mParent);

    return batch;
}

From source file:at.bitfire.ical4android.AndroidTaskList.java

public static AndroidTaskList findByID(Account account, TaskProvider provider, AndroidTaskListFactory factory,
        long id) throws FileNotFoundException, CalendarStorageException {
    try {//from ww w  . ja  va  2s.  com
        @Cleanup
        Cursor cursor = provider.client.query(
                syncAdapterURI(ContentUris.withAppendedId(provider.taskListsUri(), id), account), null, null,
                null, null);
        if (cursor != null && cursor.moveToNext()) {
            AndroidTaskList taskList = factory.newInstance(account, provider, id);

            ContentValues values = new ContentValues(cursor.getColumnCount());
            DatabaseUtils.cursorRowToContentValues(cursor, values);
            taskList.populate(values);
            return taskList;
        } else
            throw new FileNotFoundException();
    } catch (RemoteException e) {
        throw new CalendarStorageException("Couldn't query task list by ID", e);
    }
}

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

@Override
public void updateFileNameAndUID(String uid) throws ContactsStorageException {
    String newFileName = uid + ".vcf";

    ContentValues values = new ContentValues(2);
    values.put(COLUMN_FILENAME, newFileName);
    values.put(COLUMN_UID, uid);/*from  ww w  .j av  a  2 s . c o m*/
    update(values);

    fileName = newFileName;
}