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.example.android.myargmenuplanner.data.LoadMenu.java

@Override
protected String[] doInBackground(String... params) {

    Uri mUri = MenuEntry.CONTENT_URI;

    Cursor mCursor = mContext.getContentResolver().query(mUri, null, null, null, null);

    if (mCursor.getCount() == 0) {

        int shift = 0;
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        String sDate = df.format(cal.getTime());
        int dayofweek = cal.get(Calendar.DAY_OF_WEEK);

        Log.i(LOG_TAG, "Init Date: " + date);
        Vector<ContentValues> cVVector = new Vector<ContentValues>(14 - dayofweek);

        for (int i = dayofweek; i <= 14; i++) {

            ContentValues values = new ContentValues();

            values.put(MenuEntry.COLUMN_DATE, sDate);
            values.put(MenuEntry.COLUMN_LUNCH, "Empty");
            values.put(MenuEntry.COLUMN_ID_LUNCH, 0);
            values.put(MenuEntry.COLUMN_DINNER, "Empty");
            values.put(MenuEntry.COLUMN_ID_DINNER, 0);

            cVVector.add(values);/*from  ww  w  .j av a  2 s  .  c om*/

            cal.add(Calendar.DATE, 1);
            sDate = df.format(cal.getTime());
            //            Log.i(LOG_TAG, "Day of the week: "+cal.get(Calendar.DAY_OF_WEEK));
            //            Log.i(LOG_TAG, "Date: "+date);

        }

        int inserted = 0;

        //            // add to database
        Log.i(LOG_TAG, "Creando registros en base de datos. Tabla Menu ");

        if (cVVector.size() > 0) {
            ContentValues[] cvArray = new ContentValues[cVVector.size()];
            cVVector.toArray(cvArray);

            inserted = mContext.getContentResolver().bulkInsert(MenuEntry.CONTENT_URI, cvArray);
            Log.i(LOG_TAG, "Registros nuevos creados en Tabla Menu: " + inserted);
        }

    } else { //ya tengo registros, tengo que fijarme las fechas

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        String dateNow = df.format(cal.getTime());
        int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
        String date = "";
        String week = "";
        while (mCursor.moveToNext()) {

            date = mCursor.getString(1);

            if (dateNow.equals(date)) {

            }
        }

    }

    return null;
}

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

public static void cancelFailedTransfers() {
    ContentValues values;
    final String where = Nodes.NODE_RESOURCE_STATE + "=?";
    String[] selectionArgs;/*from www .  j av  a  2 s.c o  m*/
    String clearState = null;

    // Reset uploads.
    selectionArgs = new String[] { ResourceState.STATE_POSTING_FAILED };
    sResolver.delete(Nodes.CONTENT_URI, where, selectionArgs);

    // Reset downloads.
    selectionArgs = new String[] { ResourceState.STATE_GETTING_FAILED };
    values = new ContentValues(1);
    values.put(Nodes.NODE_RESOURCE_STATE, clearState);
    sResolver.update(Nodes.CONTENT_URI, values, where, selectionArgs);
}

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;//  www  . j a  va  2  s.c o 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:net.peterkuterna.android.apps.devoxxsched.service.CfpSyncService.java

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

    Thread.sleep(5000);// ww  w  .  ja  va  2  s  .c  o m

    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());

        mLocalExecutor.execute(context, "cache-parleys-presentations.json", new ParleysPresentationsHandler());

        // 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);
    }
    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();

    final NotifierManager notifierManager = new NotifierManager(this);
    notifierManager.notifyNewSessions();

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

From source file:com.codebutler.farebot.activities.ReadingTagActivity.java

private void resolveIntent(Intent intent) {
    final TextView textView = (TextView) findViewById(R.id.textView);

    try {/*w  ww .j av a2  s  .  c  om*/
        Bundle extras = intent.getExtras();

        final Tag tag = (Tag) extras.getParcelable("android.nfc.extra.TAG");
        ;
        final String[] techs = tag.getTechList();

        new AsyncTask<Void, String, MifareCard>() {
            Exception mException;

            @Override
            protected MifareCard doInBackground(Void... params) {
                try {
                    if (ArrayUtils.contains(techs, "android.nfc.tech.NfcB"))
                        return CEPASCard.dumpTag(tag.getId(), tag);
                    else if (ArrayUtils.contains(techs, "android.nfc.tech.IsoDep"))
                        return DesfireCard.dumpTag(tag.getId(), tag);
                    else
                        throw new UnsupportedTagException(techs, Utils.getHexString(tag.getId()));
                } catch (Exception ex) {
                    mException = ex;
                    return null;
                }
            }

            @Override
            protected void onPostExecute(MifareCard card) {
                if (mException != null) {
                    if (mException instanceof UnsupportedTagException) {
                        UnsupportedTagException ex = (UnsupportedTagException) mException;
                        new AlertDialog.Builder(ReadingTagActivity.this).setTitle("Unsupported Tag")
                                .setMessage(ex.getMessage()).setCancelable(false)
                                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface arg0, int arg1) {
                                        finish();
                                    }
                                }).show();
                    } else {
                        Utils.showErrorAndFinish(ReadingTagActivity.this, mException);
                    }
                    return;
                }

                try {
                    String cardXml = Utils.xmlNodeToString(card.toXML().getOwnerDocument());

                    ContentValues values = new ContentValues();
                    values.put(CardsTableColumns.TYPE, card.getCardType().toInteger());
                    values.put(CardsTableColumns.TAG_SERIAL, Utils.getHexString(card.getTagId()));
                    values.put(CardsTableColumns.DATA, cardXml);
                    values.put(CardsTableColumns.SCANNED_AT, card.getScannedAt().getTime());

                    Uri uri = getContentResolver().insert(CardProvider.CONTENT_URI_CARD, values);
                    startActivity(new Intent(Intent.ACTION_VIEW, uri));
                    finish();
                } catch (Exception ex) {
                    Utils.showErrorAndFinish(ReadingTagActivity.this, ex);
                }
            }

            @Override
            protected void onProgressUpdate(String... values) {
                textView.setText(values[0]);
            }

        }.execute();

    } catch (Exception ex) {
        Utils.showErrorAndFinish(this, ex);
    }
}

From source file:com.przyjaznyplan.utils.CsvConverter.java

public void CreateSlides() {

    ContentValues sqlValues = new ContentValues();
    sqlValues.put(Aktywnosc.COLUMN_TITLE, new File(this.rootFolder).getName());
    sqlValues.put(Aktywnosc.COLUMN_STATUS, 0);
    sqlValues.put(Aktywnosc.COLUMN_TYPE_FLAG, "" + Activity.TypeFlag.ACTIVITY);

    Activity activity = new Activity();

    ActivityDto adto = new ActivityDto();

    adto.setContentValues(sqlValues);//from w w w . j  a  v a 2s  .c  o m

    adto.setActivity(activity);

    activityDao.create(adto);

    int i = 0;
    for (String[] values : lines) {
        CreateSlide(values, activity.getId(), ++i);
    }
}

From source file:com.android.xbrowser.DownloadTouchIcon.java

private void storeIcon(Bitmap icon) {
    // Do this first in case the download failed.
    if (mTab != null) {
        // Remove the touch icon loader from the BrowserActivity.
        mTab.mTouchIconLoader = null;//  w  w  w  .  jav  a2 s . c om
    }

    if (icon == null || mCursor == null || isCancelled()) {
        return;
    }

    if (mCursor.moveToFirst()) {
        final ByteArrayOutputStream os = new ByteArrayOutputStream();
        icon.compress(Bitmap.CompressFormat.PNG, 100, os);

        ContentValues values = new ContentValues();
        values.put(Images.TOUCH_ICON, os.toByteArray());

        do {
            values.put(Images.URL, mCursor.getString(0));
            mContentResolver.update(Images.CONTENT_URI, values, null, null);
        } while (mCursor.moveToNext());
    }
}

From source file:com.mutu.gpstracker.breadcrumbs.DownloadBreadcrumbsTrackTask.java

private ContentValues buildContentValues(String key, String value) {
    ContentValues contentValues = new ContentValues();
    contentValues.put(MetaData.KEY, key);
    contentValues.put(MetaData.VALUE, value);
    return contentValues;
}

From source file:com.ruuhkis.cookies.CookieSQLSource.java

/**
 * Updates cookie if it already exists else adds new cookie tot the table
 * @param cookie// ww  w  .  j av  a  2s. c om
 */

public void addCookie(Cookie cookie) {
    long cookieId = -1;

    Cursor cursor = db.query(CookieSQLHelper.COOKIE_TABLE_NAME, null, CookieSQLHelper.COLUMN_NAME + "=?",
            new String[] { cookie.getName() }, null, null, null);

    ContentValues cookieValues = new ContentValues();
    cookieValues.put(CookieSQLHelper.COLUMN_COMMENT, cookie.getComment());
    cookieValues.put(CookieSQLHelper.COLUMN_COMMENT_URL, cookie.getCommentURL());
    cookieValues.put(CookieSQLHelper.COLUMN_DOMAIN, cookie.getDomain());
    Date date = cookie.getExpiryDate();
    cookieValues.put(CookieSQLHelper.COLUMN_EXPIRY_DATE, date != null ? date.getTime() : -1);
    cookieValues.put(CookieSQLHelper.COLUMN_NAME, cookie.getName());
    cookieValues.put(CookieSQLHelper.COLUMN_PATH, cookie.getPath());

    cookieValues.put(CookieSQLHelper.COLUMN_PERSISTENT, cookie.isPersistent() ? 1 : 0);
    cookieValues.put(CookieSQLHelper.COLUMN_SECURE, cookie.isSecure() ? 1 : 0);
    cookieValues.put(CookieSQLHelper.COLUMN_VALUE, cookie.getValue());
    cookieValues.put(CookieSQLHelper.COLUMN_VERSION, cookie.getVersion());

    if (cursor.moveToFirst()) {
        cookieId = cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_COOKIE_ID));
        db.update(CookieSQLHelper.COOKIE_TABLE_NAME, cookieValues, CookieSQLHelper.COLUMN_ID + "=?",
                new String[] { Long.toString(cookieId) });
        db.delete(CookieSQLHelper.PORT_TABLE_NAME, CookieSQLHelper.COLUMN_COOKIE_ID + "=?",
                new String[] { Long.toString(cookieId) });
    } else {
        cookieId = db.insert(CookieSQLHelper.COOKIE_TABLE_NAME, null, cookieValues);
    }

    if (cookieId != -1) {

        int[] ports = cookie.getPorts();
        if (ports != null) {
            for (int i = 0; i < ports.length; i++) {
                ContentValues portValues = new ContentValues();
                portValues.put(CookieSQLHelper.COLUMN_COOKIE_ID, cookieId);
                portValues.put(CookieSQLHelper.COLUMN_PORT, ports[i]);
                db.insert(CookieSQLHelper.PORT_TABLE_NAME, null, portValues);
            }
        }
    } else {
        Log.e(TAG, "id = -1");
    }
    cursor.close();
}

From source file:com.adamhurwitz.android.popularmovies.service.MovieDataService.java

public void putDataIntoDb(
        //String id,
        Integer movie_id, String title, String image_url, String summary, Double vote_average,
        Double popularity, String release_date) {

    // Access database
    //CursorDbHelper mDbHelper = new CursorDbHelper(context);

    // Put Info into Database

    // Gets the data repository in write mode
    //SQLiteDatabase db = mDbHelper.getWritableDatabase();

    // Create a new map of values, where column names are the keys
    ContentValues values = new ContentValues();
    values.put(CursorContract.MovieData.COLUMN_NAME_MOVIEID, movie_id);
    values.put(CursorContract.MovieData.COLUMN_NAME_TITLE, title);
    values.put(CursorContract.MovieData.COLUMN_NAME_IMAGEURL, image_url);
    values.put(CursorContract.MovieData.COLUMN_NAME_SUMMARY, summary);
    values.put(CursorContract.MovieData.COLUMN_NAME_VOTEAVERAGE, vote_average);
    values.put(CursorContract.MovieData.COLUMN_NAME_POPULARITY, popularity);
    values.put(CursorContract.MovieData.COLUMN_NAME_RELEASEDATE, release_date);
    values.put(CursorContract.MovieData.COLUMN_NAME_FAVORITE, "1");

    // Insert the new row, returning the primary key value of the new row
    long thisRowID;

    Cursor cursor = this.getContentResolver().query(CursorContract.MovieData.CONTENT_URI, null,
            CursorContract.MovieData.COLUMN_NAME_TITLE + "= ?", new String[] { title },
            CursorContract.MovieData.COLUMN_NAME_POPULARITY + " DESC");
    if (cursor.getCount() == 0) {
        Uri uri;//from w  w  w .ja v  a  2s  .c o  m
        uri = this.getContentResolver().insert(CursorContract.MovieData.CONTENT_URI, values);
    }
}