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:br.ufc.mdcc.mpos.persistence.ProfileNetworkDao.java

/**
 * Adiciona os resultados obtidos no PingTask
 * /*from  ww w. j  av a 2s  .  c  om*/
 * @param network - Objeto com os resultados do PingTask
 */
public void add(Network network) {
    openDatabase();

    ContentValues cv = new ContentValues();

    cv.put(F_DATE, dateFormat.format(network.getDate()));
    cv.put(F_LOSS, network.getLossPacket());
    cv.put(F_JITTER, network.getJitter());
    cv.put(F_UDP, Network.arrayToString(network.getResultPingUdp()));
    cv.put(F_TCP, Network.arrayToString(network.getResultPingTcp()));
    cv.put(F_DOWN, network.getBandwidthDownload());
    cv.put(F_UP, network.getBandwidthUpload());
    cv.put(F_NET_TYPE, network.getNetworkType());
    cv.put(F_ENDPOINT_TYPE, network.getEndpointType());

    database.insert(TABLE_NAME, null, cv);

    closeDatabase();
}

From source file:br.ufc.mdcc.benchimage2.dao.ResultDao.java

public void add(ResultImage results) {
    openDatabase();/*from   w ww  .j  av a2  s. c  o m*/

    ContentValues cv = new ContentValues();

    cv.put(F_PHOTO_NAME, results.getConfig().getImage());
    cv.put(F_FILTER_NAME, results.getConfig().getFilter());
    cv.put(F_LOCAL, results.getConfig().getLocal());
    cv.put(F_SIZE, results.getConfig().getSize());

    cv.put(F_EXECUTION_CPU_TIME, results.getRpcProfile().getExecutionCpuTime());
    cv.put(F_UPLOAD_TIME, results.getRpcProfile().getUploadTime());
    cv.put(F_DOWNLOAD_TIME, results.getRpcProfile().getDonwloadTime());
    cv.put(F_TOTAL_TIME, results.getTotalTime());
    cv.put(F_DOWN_SIZE, results.getRpcProfile().getDownloadSize());
    cv.put(F_UP_SIZE, results.getRpcProfile().getUploadSize());

    cv.put(F_DATE, dateFormat.format(results.getDate()));

    database.insert(TABLE_NAME, null, cv);

    closeDatabase();
}

From source file:com.inferiorhumanorgans.WayToGo.Agency.BART.Station.StationTask.java

public void addLocationToStation(final String aStationTag, final int aLatitude, final int aLongitude) {
    Log.d(LOG_NAME, "Trying to update " + aStationTag);
    ContentValues theStation = theStations.get(aStationTag);
    theStation.put("lat", aLatitude);
    theStation.put("lng", aLongitude);
}

From source file:com.mobileaffairs.seminar.videolib.VideoLibSyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {//from w w w .ja  v a 2  s  .  c  om

    String videosJson = readVideosFromRemoteService();
    try {
        JSONArray jsonArray = new JSONArray(videosJson);
        Log.i("SyncAdapter", "Number of entries " + jsonArray.length());
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Cursor cs = provider.getLocalContentProvider().query(
                    Uri.parse(VideoLibContentProvider.CONTENT_URI + "/" + jsonObject.getString("id")), null,
                    null, null, null);
            long count = cs.getCount();
            cs.close();
            if (count == 0) {
                ContentValues values = new ContentValues();
                values.put("_id", jsonObject.getString("id"));
                values.put("title", jsonObject.getString("title"));
                values.put("duration", jsonObject.getString("duration"));
                values.put("videoUrl", jsonObject.getString("url"));
                byte[] imageBytes = readImage(jsonObject.getString("thumbnail_small"));
                if (imageBytes != null && imageBytes.length > 0) {
                    values.put("thumbnail", imageBytes);
                }
                provider.getLocalContentProvider().insert(VideoLibContentProvider.CONTENT_URI, values);
            }
            syncResult.fullSyncRequested = true;
        }
    } catch (Exception e) {
        e.printStackTrace();

    }
}

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  w w. ja v a2  s .  c o 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:com.google.samples.apps.iosched.feedback.FeedbackHelper.java

/**
 * Saves the session feedback using the appropriate content provider, and dismisses the
 * feedback notification.// ww  w  . j  a  v a  2s .c  o m
 */
public void saveSessionFeedback(SessionFeedbackData data) {
    if (null == data.comments) {
        data.comments = "";
    }

    String answers = data.sessionId + ", " + data.sessionRating + ", " + data.sessionRelevantAnswer + ", "
            + data.contentAnswer + ", " + data.speakerAnswer + ", " + data.comments;
    LOGD(TAG, answers);

    ContentValues values = new ContentValues();
    values.put(ScheduleContract.Feedback.SESSION_ID, data.sessionId);
    values.put(ScheduleContract.Feedback.UPDATED, System.currentTimeMillis());
    values.put(ScheduleContract.Feedback.SESSION_RATING, data.sessionRating);
    values.put(ScheduleContract.Feedback.ANSWER_RELEVANCE, data.sessionRelevantAnswer);
    values.put(ScheduleContract.Feedback.ANSWER_CONTENT, data.contentAnswer);
    values.put(ScheduleContract.Feedback.ANSWER_SPEAKER, data.speakerAnswer);
    values.put(ScheduleContract.Feedback.COMMENTS, data.comments);

    Uri uri = mContext.getContentResolver().insert(ScheduleContract.Feedback.buildFeedbackUri(data.sessionId),
            values);
    LOGD(TAG, null == uri ? "No feedback was saved" : uri.toString());
    dismissFeedbackNotification(data.sessionId);
}

From source file:com.dycody.android.idealnote.async.upgrade.UpgradeProcessor.java

/**
 * Ensures that no duplicates will be found during the creation-to-id transition
 *//*from  w  w  w .  j  a va2 s . c om*/
private void onUpgradeTo501() {
    List<Long> creations = new ArrayList<>();
    for (Note note : DbHelper.getInstance().getAllNotes(false)) {
        if (creations.contains(note.getCreation())) {

            ContentValues values = new ContentValues();
            values.put(DbHelper.KEY_CREATION, note.getCreation() + (long) (Math.random() * 999));
            DbHelper.getInstance().getDatabase().update(DbHelper.TABLE_NOTES, values,
                    DbHelper.KEY_TITLE + " = ? AND " + DbHelper.KEY_CREATION + " = ? AND "
                            + DbHelper.KEY_CONTENT + " = ?",
                    new String[] { note.getTitle(), String.valueOf(note.getCreation()), note.getContent() });
        }
        creations.add(note.getCreation());
    }
}

From source file:com.yozio.android.YozioDataStoreImpl.java

public boolean addEvent(JSONObject event) {
    synchronized (this) {
        try {/*from  ww  w  .j a  v  a 2 s .c  o m*/
            ContentValues cv = new ContentValues();
            cv.put(APP_KEY, appKey);
            cv.put(DATA, event.toString());
            dbHelper.getWritableDatabase().insert(EVENTS_TABLE, null, cv);
            if (listener != null) {
                listener.onAdd();
            }
            // Don't worry, finally will still be called.
            return true;
        } catch (SQLiteException e) {
            Log.e(LOGTAG, "addEvent", e);
        } finally {
            dbHelper.close();
        }
    }
    return false;
}

From source file:com.google.android.apps.muzei.SourceSubscriberService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null || intent.getAction() == null) {
        return;//from  w ww .j av a 2  s .c o m
    }

    String action = intent.getAction();
    if (!ACTION_PUBLISH_STATE.equals(action)) {
        return;
    }
    // Handle API call from source
    String token = intent.getStringExtra(EXTRA_TOKEN);
    ComponentName selectedSource = SourceManager.getSelectedSource(this);
    if (selectedSource == null || !TextUtils.equals(token, selectedSource.flattenToShortString())) {
        Log.w(TAG, "Dropping update from non-selected source, token=" + token + " does not match token for "
                + selectedSource);
        return;
    }

    SourceState state = null;
    if (intent.hasExtra(EXTRA_STATE)) {
        Bundle bundle = intent.getBundleExtra(EXTRA_STATE);
        if (bundle != null) {
            state = SourceState.fromBundle(bundle);
        }
    }

    if (state == null) {
        // If there is no state, there is nothing to change
        return;
    }

    ContentValues values = new ContentValues();
    values.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, selectedSource.flattenToShortString());
    values.put(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED, true);
    values.put(MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION, state.getDescription());
    values.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, state.getWantsNetworkAvailable());
    JSONArray commandsSerialized = new JSONArray();
    int numSourceActions = state.getNumUserCommands();
    boolean supportsNextArtwork = false;
    for (int i = 0; i < numSourceActions; i++) {
        UserCommand command = state.getUserCommandAt(i);
        if (command.getId() == MuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK) {
            supportsNextArtwork = true;
        } else {
            commandsSerialized.put(command.serialize());
        }
    }
    values.put(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND, supportsNextArtwork);
    values.put(MuzeiContract.Sources.COLUMN_NAME_COMMANDS, commandsSerialized.toString());
    ContentResolver contentResolver = getContentResolver();
    Cursor existingSource = contentResolver.query(MuzeiContract.Sources.CONTENT_URI,
            new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?",
            new String[] { selectedSource.flattenToShortString() }, null, null);
    if (existingSource != null && existingSource.moveToFirst()) {
        Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI,
                existingSource.getLong(0));
        contentResolver.update(sourceUri, values, null, null);
    } else {
        contentResolver.insert(MuzeiContract.Sources.CONTENT_URI, values);
    }
    if (existingSource != null) {
        existingSource.close();
    }

    Artwork artwork = state.getCurrentArtwork();
    if (artwork != null) {
        artwork.setComponentName(selectedSource);
        contentResolver.insert(MuzeiContract.Artwork.CONTENT_URI, artwork.toContentValues());

        // Download the artwork contained from the newly published SourceState
        startService(TaskQueueService.getDownloadCurrentArtworkIntent(this));
    }
}

From source file:com.openerp.addons.note.NoteDBHelper.java

public LinkedHashMap<String, String> writeNoteTags(String tagname) {

    LinkedHashMap<String, String> noteTags = new LinkedHashMap<String, String>();
    ContentValues values = new ContentValues();

    values.put("name", tagname);
    NoteDBHelper.NoteTags notetagObj = new NoteTags(mContext);
    int newId = notetagObj.createRecordOnserver(notetagObj, values);
    values.put("id", newId);
    notetagObj.create(notetagObj, values);
    noteTags.put("newID", String.valueOf(newId));
    noteTags.put("tagName", tagname);
    return noteTags;
}