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:it.ms.theing.loquitur.functions.Storage.java

/**
 * Set a key. If the value already exists is overwritten
 * @param genre/*from   ww w .j a  va  2s  .c  om*/
 * The genre of the key
 * @param key
 * The key
 * @param value
 * The key value
 */
@JavascriptInterface
public void setKey(String genre, String key, String value) {
    ContentValues val = new ContentValues();
    val.put("genre", genre.toUpperCase());
    val.put("key", key);
    val.put("value", value);
    dataBase.insert("alias", null, val);
}

From source file:de.uhrenbastler.watchcheck.ui.LogDialog.java

/**
 * Creates the log entry in the content provider
 *//*ww  w .  ja va  2 s. co m*/
protected void makeLogEntry() {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    double ntpDiff = modeNtp ? ((double) (localTime.getTimeInMillis() - ntpTime.getTimeInMillis())) / 1000d : 0; // Really???

    ContentValues values = new ContentValues();
    values.put(Logs.COMMENT, comment.getEditableText().toString());
    values.put(Logs.DEVIATION, deviation);
    values.put(Logs.FLAG_RESET, startFlag.isChecked());
    values.put(Logs.LOCAL_TIMESTAMP, dateFormat.format(localTime.getTime()));
    values.put(Logs.MODUS, modeNtp);
    values.put(Logs.NTP_DIFF, ntpDiff);

    if (positionSpinner.getSelectedItemId() > 0)
        values.put(Logs.POSITION, POSITIONARR[(int) positionSpinner.getSelectedItemId()]);
    if (temperatureSpinner.getSelectedItemId() > 0)
        values.put(Logs.TEMPERATURE, TEMPARR[(int) temperatureSpinner.getSelectedItemId()]);
    values.put(Logs.WATCH_ID, watchId);

    Logger.debug("values=" + values);

    getContext().getContentResolver().insert(Logs.CONTENT_URI, values);

}

From source file:cn.loveapple.client.android.shiba.database.impl.BookMarkDaoImpl.java

/**
 * {@inheritDoc}//  ww w  . ja  v a  2  s . c  o  m
 */
public BookMarkEntity save(BookMarkEntity entity) {
    if (entity == null) {
        throw new IllegalArgumentException("history entity is null.");
    }
    if (StringUtils.isEmpty(entity.getUrl())) {
        throw new IllegalArgumentException("history url is null.");
    }

    ContentValues values = new ContentValues();
    values.put(COLUMN_URL, entity.getUrl());
    if (StringUtils.isNotEmpty(entity.getTitle())) {
        values.put(COLUMN_TITLE, entity.getTitle());
    }
    if (entity.getTimestamp() != null) {
        values.put(COLUMN_TIMESTAMP, entity.getTimestamp().getTime());
    }

    BookMarkEntity result = null;

    try {
        writableDb = getWritableDb();

        int colNum = writableDb.update(TABLE_NAME, values, COLUMN_URL + "=?", new String[] { entity.getUrl() });
        if (colNum < 1) {
            writableDb.insert(TABLE_NAME, null, values);
            Log.i(LOG_TAG, "update : " + ToStringBuilder.reflectionToString(values));
        }
        result = getUrlHistory(entity.getUrl(), null);
    } finally {
        //writableDb.close();
    }
    return result;
}

From source file:com.samknows.measurement.storage.TestResultDataSource.java

public void insert(String type_name, long dtime, long success, double result, String location,
        long test_batch_id) {
    ContentValues values = new ContentValues();
    values.put(SKSQLiteHelper.TR_COLUMN_DTIME, dtime);
    values.put(SKSQLiteHelper.TR_COLUMN_TYPE, type_name);
    values.put(SKSQLiteHelper.TR_COLUMN_LOCATION, location);
    values.put(SKSQLiteHelper.TR_COLUMN_SUCCESS, success);
    values.put(SKSQLiteHelper.TR_COLUMN_RESULT, result);
    values.put(SKSQLiteHelper.TR_COLUMN_BATCH_ID, test_batch_id);
    database.insert(SKSQLiteHelper.TABLE_TESTRESULT, null, values);
}

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;/*  w w w . jav  a  2s .  c o m*/
}

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

public void modifyTodoFromServer(ContentResolver contentResolver, Todo list) {
    ContentValues cv = new ContentValues();
    cv.put(TodoContentProvider.COLUMN_TITLE, list.getTitle());
    cv.put(TodoContentProvider.COLUMN_STATUS_FLAG, StatusFlag.CLEAN);

    contentResolver.update(TodoContentProvider.CONTENT_URI, cv,
            TodoContentProvider.COLUMN_SERVER_ID + "=" + list.getId(), null);

}

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

private void _update_map_names() {
    if (Gw2JSONDownloader.internetAvailable(mContext)) {
        String result = Gw2JSONDownloader.downloadJSON(Gw2JSONDownloader.event_map_names_url);
        SQLiteDatabase db = mDBHelper.getWritableDatabase();

        try {//from   w  ww  . jav a 2 s .c  om
            JSONArray jsData;
            jsData = new JSONArray(result);

            for (int i = 0; i < jsData.length(); i++) {
                JSONObject obj = jsData.getJSONObject(i);
                Integer id = obj.getInt("id");
                String name = obj.getString("name");

                ContentValues row = new ContentValues(2);
                row.put("_id", id);
                row.put("name", name);

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

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

private void _update_world_names() {
    if (Gw2JSONDownloader.internetAvailable(mContext)) {
        String result = Gw2JSONDownloader.downloadJSON(Gw2JSONDownloader.event_world_names_url);
        SQLiteDatabase db = mDBHelper.getWritableDatabase();

        try {// w  w w .  j  av a  2s . c om
            JSONArray jsData;
            jsData = new JSONArray(result);

            for (int i = 0; i < jsData.length(); i++) {
                JSONObject obj = jsData.getJSONObject(i);
                Integer id = obj.getInt("id");
                String name = obj.getString("name");

                ContentValues row = new ContentValues(2);
                row.put("_id", id);
                row.put("name", name);

                if (db != null) {
                    db.insert(Gw2DB.WORLD_NAMES_TABLE, null, row);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else {
        //TODO: Throw Exception.
    }
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.service.CfpSyncService.java

@Override
protected void doSync(Intent intent) throws Exception {
    Log.d(TAG, "Start sync");

    final Context context = this;

    final SharedPreferences settings = Prefs.get(context);
    final int localVersion = settings.getInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_NONE);

    final long startLocal = System.currentTimeMillis();
    final boolean localParse = localVersion < VERSION_CURRENT;
    Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT);
    if (localParse) {
        // Parse values from local cache first
        mLocalExecutor.execute(R.xml.search_suggest, new SearchSuggestHandler());
        mLocalExecutor.execute(R.xml.rooms, new RoomsHandler());
        mLocalExecutor.execute(R.xml.tracks, new TracksHandler());
        mLocalExecutor.execute(R.xml.presentationtypes, new SessionTypesHandler());
        mLocalExecutor.execute(context, "cache-speakers.json", new SpeakersHandler());
        mLocalExecutor.execute(context, "cache-presentations.json", new SessionsHandler());
        mLocalExecutor.execute(context, "cache-schedule.json", new ScheduleHandler());

        // Save local parsed version
        settings.edit().putInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_CURRENT).commit();

        final ContentValues values = new ContentValues();
        values.put(Sessions.SESSION_NEW, 0);
        getContentResolver().update(Sessions.CONTENT_NEW_URI, values, null, null);
    }//from   w  w w.  ja  va2 s  .  c  o  m
    Log.d(TAG, "Local sync took " + (System.currentTimeMillis() - startLocal) + "ms");

    final CfpSyncManager syncManager = new CfpSyncManager(context);
    if (syncManager.shouldPerformRemoteSync(Intent.ACTION_SYNC.equals(intent.getAction()))) {
        Log.d(TAG, "Should perform remote sync");
        final long startRemote = System.currentTimeMillis();
        Editor prefsEditor = syncManager.hasRemoteContentChanged(mHttpClient);
        if (prefsEditor != null) {
            Log.d(TAG, "Remote content was changed");
            mRemoteExecutor.executeGet(SPEAKERS_URL, new SpeakersHandler());
            mRemoteExecutor.executeGet(PRESENTATIONS_URL, new SessionsHandler());
            mRemoteExecutor.executeGet(SCHEDULE_URL, new ScheduleHandler());
            prefsEditor.commit();
        }
        Log.d(TAG, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms");
    } else {
        Log.d(TAG, "Should not perform remote sync");
    }

    final CfpDatabase database = new CfpDatabase(this);
    database.cleanupLinkTables();

    if (!localParse) {
        final NotifierManager notifierManager = new NotifierManager(this);
        notifierManager.notifyNewSessions();
    }

    Log.d(TAG, "Sync finished");
}

From source file:com.nicolacimmino.expensestracker.tracker.data_sync.ExpenseDataSyncAdapter.java

public void fetchExpensesFromServer() {

    try {/* w  w  w.ja  va  2s. c o m*/
        ExpensesApiGetExpensesRequest request = new ExpensesApiGetExpensesRequest();

        if (!request.performRequest()) {
            Log.e(TAG, "ExpensesApiGetExpensesRequest failed");
            return;
        }
        JSONArray jsonObject = request.getExpenses();

        getContext().getContentResolver().delete(ExpensesDataContentProvider.Contract.Expense.CONTENT_URI,
                ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SYNC + "=1", null);

        for (int ix = 0; ix < jsonObject.length(); ix++) {
            Log.i(TAG, "Expense: " + jsonObject.getJSONObject(ix).get("amount"));

            ContentValues values = new ContentValues();
            values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SYNC, "1");
            values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_CURRENCY, "eur");
            values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_AMOUNT,
                    jsonObject.getJSONObject(ix).getString("amount"));
            values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_DESCRIPTION,
                    jsonObject.getJSONObject(ix).getString("notes"));
            values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SOURCE,
                    jsonObject.getJSONObject(ix).getString("source"));
            values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_DESTINATION,
                    jsonObject.getJSONObject(ix).getString("destination"));
            if (jsonObject.getJSONObject(ix).has("timestamp")) {
                values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_TIMESTAMP,
                        jsonObject.getJSONObject(ix).getString("timestamp"));
            } else {
                values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_TIMESTAMP,
                        "19750620 16:00:00");
            }

            getContext().getContentResolver().insert(ExpensesDataContentProvider.Contract.Expense.CONTENT_URI,
                    values);
        }
    } catch (JSONException e) {
        Log.e(TAG, "Invalid JSON: " + e.toString());
        return;
    } finally {
    }

}