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.jll.sunshine.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city// ww  w  . j a  v  a2 s .  c om
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
long addLocation(String locationSetting, String cityName, double lat, double lon) {
    // Students: First, check if the location with this city name exists in the db

    String selection = WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + "= ?" + " AND "
            + WeatherContract.LocationEntry.COLUMN_CITY_NAME + "= ?" + " AND "
            + WeatherContract.LocationEntry.COLUMN_COORD_LAT + "= ?" + " AND "
            + WeatherContract.LocationEntry.COLUMN_COORD_LONG + "= ?";
    String[] selectionArgs = new String[] { locationSetting, cityName, String.valueOf(lat),
            String.valueOf(lon) };

    Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID }, selection, selectionArgs, null);

    long id = -1;
    if (cursor.moveToFirst()) {
        id = cursor.getLong(0);
    } else {
        ContentValues values = new ContentValues();
        values.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        values.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        values.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        values.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        Uri newRow = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, values);
        id = ContentUris.parseId(newRow);
    }

    // If it exists, return the current ID
    // Otherwise, insert it using the content resolver and the base URI
    return id;
}

From source file:idea.ruan.oksun.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city//from   w  ww  .  jav a  2s.  c om
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
long addLocation(String locationSetting, String cityName, double lat, double lon) {

    ContentResolver contentResolver = mContext.getContentResolver();

    Uri locationTableUri = WeatherContract.LocationEntry.CONTENT_URI;

    long locationId;
    Cursor c = contentResolver.query(locationTableUri, new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_CITY_NAME + " = ?", new String[] { cityName }, null);
    if (c.moveToFirst()) {

        int i = c.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = c.getLong(i);

    } else {

        ContentValues cv = new ContentValues();

        cv.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        cv.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        cv.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        cv.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        locationId = ContentUris.parseId(contentResolver.insert(locationTableUri, cv));

    }

    c.close();

    return locationId;
}

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

@Override
protected ContentValues contentValues() {
    ContentValues values = super.contentValues();

    @Cleanup("recycle")
    Parcel members = Parcel.obtain();/*w w  w  .  j  a  v a 2s .co m*/
    members.writeStringList(contact.members);
    values.put(COLUMN_PENDING_MEMBERS, members.marshall());

    return values;
}

From source file:com.fanfou.app.opensource.api.bean.User.java

@Override
public ContentValues toContentValues() {
    final User u = this;
    final ContentValues cv = new ContentValues();

    cv.put(BasicColumns.ID, u.id);
    cv.put(BasicColumns.OWNER_ID, u.ownerId);

    cv.put(UserInfo.SCREEN_NAME, u.screenName);
    cv.put(UserInfo.LOCATION, u.location);
    cv.put(UserInfo.GENDER, u.gender);/*from w  w  w . j av  a 2  s . c  o  m*/
    cv.put(UserInfo.BIRTHDAY, u.birthday);

    cv.put(UserInfo.DESCRIPTION, u.description);
    cv.put(UserInfo.PROFILE_IMAGE_URL, u.profileImageUrl);
    cv.put(UserInfo.URL, u.url);
    cv.put(UserInfo.PROTECTED, u.protect);

    cv.put(UserInfo.FOLLOWERS_COUNT, u.followersCount);
    cv.put(UserInfo.FRIENDS_COUNT, u.friendsCount);
    cv.put(UserInfo.FAVORITES_COUNT, u.favouritesCount);
    cv.put(UserInfo.STATUSES_COUNT, u.statusesCount);

    cv.put(UserInfo.FOLLOWING, u.following);
    cv.put(BasicColumns.CREATED_AT, u.createdAt.getTime());

    cv.put(BasicColumns.TYPE, u.type);

    return cv;
}

From source file:app.com.example.android.sunshine.FetchWeatherTask.java

long addLocation(String locationSetting, String cityName, double lat, double lon) {
    // Students: First, check if the location with this city name exists in the db
    // If it exists, return the current ID
    // Otherwise, insert it using the content resolver and the base URI
    long locationId;
    SQLiteDatabase db = new WeatherDbHelper(this.mContext).getWritableDatabase();
    Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " =? ", new String[] { locationSetting },
            null);//from w  w w.j av a 2 s  . co  m
    if (locationCursor.moveToFirst()) {
        int locationIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = locationCursor.getLong(locationIndex);
    } else {
        ContentValues contentValues = new ContentValues();
        contentValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        contentValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);
        Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                contentValues);
        locationId = ContentUris.parseId(insertedUri);
    }
    locationCursor.close();
    return locationId;
}

From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java

public static long insertSysMessage(String txt, String sessionId) {

    long ownThreadId = ConversationSqlManager.querySessionIdForBySessionId(sessionId);
    ContentValues cv = new ContentValues();
    cv.put(IMessageColumn.MESSAGE_ID, UUID.randomUUID().toString());
    cv.put(IMessageColumn.MESSAGE_TYPE, 0);
    cv.put(IMessageColumn.BODY, txt);//from   ww  w.java  2s  .co m
    cv.put(IMessageColumn.sender, CCPAppManager.getUserId());
    cv.put(IMessageColumn.SEND_STATUS, 1);
    cv.put(IMessageColumn.OWN_THREAD_ID, ownThreadId);
    cv.put(IMessageColumn.USER_DATA, "yuntongxun009" + txt);
    cv.put(IMessageColumn.CREATE_DATE, System.currentTimeMillis());
    cv.put(IMessageColumn.RECEIVE_DATE, System.currentTimeMillis());

    return getInstance().sqliteDB().insertOrThrow(DatabaseHelper.TABLES_NAME_IM_MESSAGE, null, cv);
}

From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java

private void syncCheckins(ContentProviderClient provider, String cookie) {
    Cursor cursor = null;//from   w  w w .  j a  va2  s . c om
    try {
        cursor = provider.query(Table.ATTENDEE.getBaseUri(),
                new String[] { Table.Attendee.ID, Table.Attendee.CHECKIN, Table.Attendee.EVENT_ID, },
                Table.Attendee.CHECKIN_MODIFIED, null, null);
        if (0 == cursor.getCount()) {
            Log.d(TAG, "No checkin to sync.");
            return;
        }
        int syncCount = 0;
        while (cursor.moveToNext()) {
            String attendeeId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.ID));
            String eventId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.EVENT_ID));
            long checkin = cursor.getLong(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN));
            long serverCheckin = postCheckIn(attendeeId, eventId, checkin == 0, cookie);
            if (serverCheckin >= 0) {
                ContentValues values = new ContentValues();
                values.put(Table.Attendee.CHECKIN_MODIFIED, false);
                if (0 == serverCheckin) {
                    values.putNull(Table.Attendee.CHECKIN);
                } else {
                    values.put(Table.Attendee.CHECKIN, serverCheckin);
                }
                provider.update(Table.ATTENDEE.getItemUri(eventId, attendeeId), values, null, null);
                ++syncCount;
            }
        }
        Log.d(TAG, syncCount + " checkin(s) synced.");
    } catch (RemoteException e) {
        e.printStackTrace();
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.newtifry.android.database.NewtifrySource.java

@Override
protected ContentValues flatten() {
    ContentValues values = new ContentValues();
    values.put(NewtifryDatabaseAdapter.KEY_ACCOUNT_NAME, this.getAccountName());
    values.put(NewtifryDatabaseAdapter.KEY_SERVER_ENABLED, this.getServerEnabled() ? 1 : 0);
    values.put(NewtifryDatabaseAdapter.KEY_LOCAL_ENABLED, this.getLocalEnabled() ? 1 : 0);
    values.put(NewtifryDatabaseAdapter.KEY_TITLE, this.getTitle());
    values.put(NewtifryDatabaseAdapter.KEY_SOURCE_COLOR, this.getSourceColor());

    values.put(NewtifryDatabaseAdapter.KEY_SERVER_ID, this.getServerId());
    values.put(NewtifryDatabaseAdapter.KEY_CHANGE_TIMESTAMP, this.getChangeTimestamp());
    values.put(NewtifryDatabaseAdapter.KEY_SOURCE_KEY, this.getSourceKey());
    values.put(NewtifryDatabaseAdapter.KEY_USE_GLOBAL_NOTIFICATION, this.getUseGlobalNotification() ? 1 : 0);
    values.put(NewtifryDatabaseAdapter.KEY_NOTIFICATION, this.getNotification() ? 1 : 0);
    values.put(NewtifryDatabaseAdapter.KEY_VIBRATE, this.getVibrate() ? 1 : 0);
    values.put(NewtifryDatabaseAdapter.KEY_NOTIFIERPRO, this.getNotifierPro() ? 1 : 0);
    values.put(NewtifryDatabaseAdapter.KEY_RINGTONE, 0);
    values.put(NewtifryDatabaseAdapter.KEY_CUSTOM_RINGTONE, this.getRingtone());
    values.put(NewtifryDatabaseAdapter.KEY_LED_FLASH, this.getLedFlash() ? 1 : 0);
    values.put(NewtifryDatabaseAdapter.KEY_SPEAK_MESSAGE, this.getSpeakMessage() ? 1 : 0);
    return values;
}

From source file:me.kartikarora.transfersh.activities.TransferActivity.java

private void uploadFile(Uri uri) throws IOException {
    final ProgressDialog dialog = new ProgressDialog(TransferActivity.this);
    dialog.setMessage(getString(R.string.uploading_file));
    dialog.setCancelable(false);/*  w w w  . jav  a2s.c  om*/
    dialog.show();
    Cursor cursor = getContentResolver().query(uri, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
        final String name = cursor.getString(nameIndex);
        final String mimeType = getContentResolver().getType(uri);
        Log.d(this.getClass().getSimpleName(), cursor.getString(0));
        Log.d(this.getClass().getSimpleName(), name);
        Log.d(this.getClass().getSimpleName(), mimeType);
        InputStream inputStream = getContentResolver().openInputStream(uri);
        OutputStream outputStream = openFileOutput(name, MODE_PRIVATE);
        if (inputStream != null) {
            IOUtils.copy(inputStream, outputStream);
            final File file = new File(getFilesDir(), name);
            TypedFile typedFile = new TypedFile(mimeType, file);
            TransferClient.getInterface().uploadFile(typedFile, name, new ResponseCallback() {
                @Override
                public void success(Response response) {
                    BufferedReader reader;
                    StringBuilder sb = new StringBuilder();
                    try {
                        reader = new BufferedReader(new InputStreamReader(response.getBody().in()));
                        String line;
                        try {
                            while ((line = reader.readLine()) != null) {
                                sb.append(line);
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    String result = sb.toString();
                    Snackbar.make(mCoordinatorLayout, name + " " + getString(R.string.uploaded),
                            Snackbar.LENGTH_SHORT).show();

                    ContentValues values = new ContentValues();
                    values.put(FilesContract.FilesEntry.COLUMN_NAME, name);
                    values.put(FilesContract.FilesEntry.COLUMN_TYPE, mimeType);
                    values.put(FilesContract.FilesEntry.COLUMN_URL, result);
                    values.put(FilesContract.FilesEntry.COLUMN_SIZE, String.valueOf(file.getTotalSpace()));
                    getContentResolver().insert(FilesContract.BASE_CONTENT_URI, values);
                    getSupportLoaderManager().restartLoader(BuildConfig.VERSION_CODE, null,
                            TransferActivity.this);
                    FileUtils.deleteQuietly(file);
                    if (dialog.isShowing())
                        dialog.hide();
                }

                @Override
                public void failure(RetrofitError error) {
                    error.printStackTrace();
                    if (dialog.isShowing())
                        dialog.hide();
                    Snackbar.make(mCoordinatorLayout, R.string.something_went_wrong, Snackbar.LENGTH_INDEFINITE)
                            .setAction(R.string.report, new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    // TODO add feedback code
                                }
                            }).show();
                }
            });
        } else
            Snackbar.make(mCoordinatorLayout, R.string.unable_to_read, Snackbar.LENGTH_SHORT).show();
    }
}

From source file:com.wheelermarine.publicAccessSites.Updater.java

private void readDBaseFile(ZipInputStream zin, SQLiteDatabase database) throws IOException {

    // Begin parsing the DBase data.
    DBaseReader reader = new DBaseReader(zin);
    final int recordCount = reader.size();
    activity.runOnUiThread(new Runnable() {
        @Override//from   w  ww. ja  v  a2s  .co m
        public void run() {
            progress.setIndeterminate(false);
            progress.setMax(recordCount);
        }
    });
    Log.v(TAG, "DBase version: " + reader.getHeader().getSignature());
    Log.v(TAG, "Last Update: " + reader.getHeader().getLastUpdate());
    Log.v(TAG, "Record Count: " + reader.size());

    // Insert the records into the local database.
    int progress = 0;
    for (Record access : reader) {
        String lake = (String) access.getValue("LAKENAME");
        if (lake == null || lake.isEmpty())
            lake = (String) access.getValue("LAKE_NAME");
        if (lake == null || lake.isEmpty())
            lake = (String) access.getValue("ALT_NAME");
        if (lake == null || lake.isEmpty())
            lake = String.valueOf(progress);

        ContentValues values = new ContentValues();
        values.put(DatabaseHelper.PublicAccessEntry.COLUMN_NAME_NAME, (String) access.getValue("FAC_NAME"));
        values.put(DatabaseHelper.PublicAccessEntry.COLUMN_NAME_LAUNCH, (String) access.getValue("LAUNCHTYPE"));
        values.put(DatabaseHelper.PublicAccessEntry.COLUMN_NAME_RAMP, (String) access.getValue("RAMPTYPE"));
        values.put(DatabaseHelper.PublicAccessEntry.COLUMN_NAME_RAMPS, (Double) access.getValue("NUMRAMPS"));
        values.put(DatabaseHelper.PublicAccessEntry.COLUMN_NAME_DOCKS, (Double) access.getValue("NUMDOCKS"));
        values.put(DatabaseHelper.PublicAccessEntry.COLUMN_NAME_DIRECTIONS,
                (String) access.getValue("DIRECTIONS"));
        values.put(DatabaseHelper.PublicAccessEntry.COLUMN_NAME_LAKE, lake);
        values.put(DatabaseHelper.PublicAccessEntry.COLUMN_NAME_COUNTY, (String) access.getValue("COUNTYNAME"));
        values.put(DatabaseHelper.PublicAccessEntry.COLUMN_NAME_RECORD_NUMBER, progress + 1);
        database.insert(DatabaseHelper.PublicAccessEntry.TABLE_NAME, null, values);
        publishProgress(++progress);
    }
}