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.danstormont.sunshine.app.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//w ww . j  av a2  s. co m
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
private long addLocation(String locationSetting, String cityName, double lat, double lon) {

    Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon);

    // First, check if the location with this city name exists in the db
    Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI,
            new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOCATION_SETTING + " = ?",
            new String[] { locationSetting }, null);

    if (cursor.moveToFirst()) {
        int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID);
        return cursor.getLong(locationIdIndex);
    } else {
        ContentValues locationValues = new ContentValues();
        locationValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(LocationEntry.COLUMN_COORD_LAT, lat);
        locationValues.put(LocationEntry.COLUMN_COORD_LONG, lon);

        Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues);

        return ContentUris.parseId(locationInsertUri);
    }
}

From source file:com.josenaves.sunshine.app.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  av  a 2 s .c o  m*/
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
private long addLocation(String locationSetting, String cityName, double lat, double lon) {

    // First, check if the location with this city name exists in the db
    Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting },
            null);

    if (cursor.moveToFirst()) {
        int locationIdIndex = cursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        return cursor.getLong(locationIdIndex);
    } else {
        ContentValues locationValues = new ContentValues();
        locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        Uri locationInsertUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                locationValues);

        return ContentUris.parseId(locationInsertUri);
    }
}

From source file:com.example.shutapp.DatabaseHandler.java

/**
 * @param chatroom/*  www. java 2  s. co m*/
 * @return 
 */
public int updateChatrooms(Chatroom chatroom) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, chatroom.getName()); // Chatroom Name
    values.put(KEY_LATITUDE, chatroom.getLatitude()); // Chatroom Latitude
    values.put(KEY_LONGITUDE, chatroom.getLongitude()); // Chatroom Longitude
    values.put(KEY_RADIUS, chatroom.getRadius()); // Chatroom Radius

    // updating row
    return db.update(TABLE_CHATROOMS, values, KEY_NAME + " = ?", new String[] { chatroom.getName() });
}

From source file:com.example.shutapp.DatabaseHandler.java

/**
 * Adds a chatroom to the database./*from   ww w.j  a  va 2s .  co  m*/
 * @param chatroom
 */
public void addChatroom(Chatroom chatroom) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, chatroom.getName()); // Chatroom Name
    values.put(KEY_LATITUDE, chatroom.getLatitude()); // Chatroom Latitude
    values.put(KEY_LONGITUDE, chatroom.getLongitude()); // Chatroom Longitude
    values.put(KEY_RADIUS, chatroom.getRadius()); // Chatroom Radius

    // Inserting Row
    db.insert(TABLE_CHATROOMS, null, values);
    db.close(); // Closing database connection
}

From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTask.java

/**
 * The parentIndex and previousIndex can be set to valid backreference
 * indices to indicate the id of the parent and previous of this note. If
 * set to null, already set values will be used which might be null.
 *///  w  w w .  j ava  2  s.  com
public ContentValues toNotesBackRefContentValues(Integer listIdIndex) {
    ContentValues values = new ContentValues();
    if (listIdIndex != null)
        values.put(NotePad.Notes.COLUMN_NAME_LIST, listIdIndex);

    return values;
}

From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java

/**
 * Expects a writeable {@link SQLiteDatabase} - used for batch commits.
 *//*from   w  ww. j ava 2 s  .  co m*/
public void insertDestination(SQLiteDatabase db, String id, long arrivalTime, long departureTime, String city,
        String region, String country, double locationLat, double locationLng, long presentsDelivered,
        long presentsAtDestination, long timezone, long altitude, String photos, String weather,
        String streetView, String gmmStreetView) {

    ContentValues cv = new ContentValues();

    cv.put(COLUMN_NAME_IDENTIFIER, id);

    cv.put(COLUMN_NAME_ARRIVAL, arrivalTime);
    cv.put(COLUMN_NAME_DEPARTURE, departureTime);

    cv.put(COLUMN_NAME_CITY, city);
    cv.put(COLUMN_NAME_REGION, region);
    cv.put(COLUMN_NAME_COUNTRY, country);

    cv.put(COLUMN_NAME_LAT, locationLat);
    cv.put(COLUMN_NAME_LNG, locationLng);

    cv.put(COLUMN_NAME_PRESENTSDELIVERED, presentsDelivered);
    cv.put(COLUMN_NAME_PRESENTS_DESTINATION, presentsAtDestination);

    cv.put(COLUMN_NAME_TIMEZONE, timezone);
    cv.put(COLUMN_NAME_ALTITUDE, altitude);
    cv.put(COLUMN_NAME_PHOTOS, photos);
    cv.put(COLUMN_NAME_WEATHER, weather);
    cv.put(COLUMN_NAME_STREETVIEW, streetView);
    cv.put(COLUMN_NAME_GMMSTREETVIEW, gmmStreetView);

    // TODO: verify whether the db parameter is needed - can we just get
    // another writeable handle on the db (even if the transaction is
    // started on a different one?)
    db.insertOrThrow(TABLE_NAME, null, cv);
}

From source file:tk.android.client.activity.Activity_client.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.button_version: {
        try {/*  w  ww . j a v  a2 s.co m*/
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(PLAY_STORE_URL)));
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
        }
        break;
    }
    case R.id.layout_support: {
        startActivity(new Intent(activity, Activity_user.class)
                .setData(Uri.parse("https://twitter.com/OrangeSphereApp")));
        break;
    }
    case R.id.layout_pro: {
        if (PropertyManager.getInstance().isProUser()) {
            Toast.makeText(activity, "You alreadry Pro User :)", Toast.LENGTH_SHORT).show();
            break;
        }
        String TAG = "EditDialog-Pro";
        final EditDialog dialog = new EditDialog();
        dialog.newInstance(activity);
        dialog.setTitle(R.string.advertisement);
        dialog.setOnFinishEditListener(new OnFinishEditListener() {

            @Override
            public void onFinishEdit(final String text) {
                int length = text.length();
                if (length > 100 || length == 0) {
                    Toast.makeText(activity, R.string.bad_string_length, Toast.LENGTH_SHORT).show();
                    return;
                }
                dialog.dismiss();
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Twitter twitter = core.getTwitter();
                            if (twitter == null) {
                                throw new Exception();
                            }
                            twitter.updateStatus(text + " " + PLAY_STORE_URL + " #OrangeSphere");
                            PropertyManager.getInstance().toBeProUser();
                            SQLiteManager manager = new SQLiteManager(activity);
                            SQLiteDatabase db = manager.getWritableDatabase();
                            ContentValues values = new ContentValues();
                            values.put("client_name", "OrangeSpherePro");
                            values.put("consumer_key", "b1NEqKgA8CGudo6yhkg");
                            values.put("consumer_secret", "awqnQwi3BXUqkyjlMZHlDIvad3bV3cVO03MxRTV4s");
                            db.insert("client_table", null, values);
                            db.close();
                            new UiHandler() {

                                @Override
                                public void run() {
                                    Toast.makeText(activity, R.string.be_pro_user, Toast.LENGTH_SHORT).show();
                                }

                            }.post();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                }).start();
            }

        });
        dialog.show(getSupportFragmentManager(), TAG);
        break;
    }
    case R.id.layout_license: {
        new LicenseDialog().show(getSupportFragmentManager(), "LicenseDialog");
        break;
    }
    }
}

From source file:com.swisscom.android.sunshine.data.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 a  2s  .  c  o m
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
private long addLocation(String locationSetting, String cityName, double lat, double lon) {

    Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon);

    // First, check if the location with this city name exists in the db
    Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI,
            new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOCATION_SETTINGS + " = ?",
            new String[] { locationSetting }, null);

    if (cursor.moveToFirst()) {
        Log.v(LOG_TAG, "Found it in the database!");
        int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID);
        return cursor.getLong(locationIdIndex);
    } else {
        Log.v(LOG_TAG, "Didn't find it in the database, inserting now!");
        ContentValues locationValues = new ContentValues();
        locationValues.put(LocationEntry.COLUMN_LOCATION_SETTINGS, locationSetting);
        locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(LocationEntry.COLUMN_LATITUDE, lat);
        locationValues.put(LocationEntry.COLUMN_LONGITUDE, lon);

        Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues);

        return ContentUris.parseId(locationInsertUri);
    }
}

From source file:com.taxicop.sync.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {//from ww  w. java 2s .  c o  m

    USER = queryUser(provider);
    Log.i(TAG, "onPerformSync: Start");
    NetworkUtilities.reset();
    FROM = queryLastId(provider);
    Log.d(TAG, "data from= " + FROM);
    ArrayList<Complaint> queries = query(provider, FROM);
    NetworkUtilities.add(USER);
    for (Complaint c : queries) {
        NetworkUtilities.add(c.RANKING, c.CAR_PLATE, c.DESCRIPTION, c.USER, c.DATE);
    }
    Log.d(TAG, "from= " + FROM + " size del query= " + queries.size());

    String response = null;
    if (NetworkUtilities.adapter.size() > 0) {
        response = ":" + NetworkUtilities.process_upload();
        Log.i(TAG, "response: " + response);
    } else
        Log.i(TAG, "no data");

    if (USER != null) {
        NetworkUtilities.reset();
        NetworkUtilities.add(USER);
        NetworkUtilities.add(FROM);
        response = null;
        if (NetworkUtilities.adapter.size() > 0) {
            response = NetworkUtilities.process_download();
            Log.d(TAG, "" + response);
        } else
            Log.e(TAG, "no data");
        try {
            if (response != null) {
                final JSONArray cars = new JSONArray(response);
                provider.delete(PlateContentProvider.URI_REPORT, null, null);
                Log.i(TAG, "" + response);
                for (int i = 0; i < cars.length(); i++) {
                    JSONObject COMPLETE = cars.getJSONObject(i);
                    JSONObject e1 = COMPLETE.getJSONObject("fields");
                    float rank = (float) e1.getDouble(Fields.RANKING);
                    String car = e1.getString(Fields.CAR_PLATE);
                    String desc = e1.getString(Fields.DESCRIPTION);
                    String date = e1.getString(Fields.DATE_REPORT);
                    ContentValues in = new ContentValues();
                    in.put(Fields.ID_KEY, i);
                    in.put(Fields.CAR_PLATE, car);
                    in.put(Fields.RANKING, rank);
                    in.put(Fields.DATE_REPORT, date);
                    in.put(Fields.DESCRIPTION, desc);
                    insert.add(in);
                }
                Log.d(TAG, "current ammount to insert= " + insert.size() + ",  FROM=" + FROM);
                ContentValues upd = new ContentValues();
                upd.put(Fields.ITH, insert.size());
                upd.put(Fields.ID_USR, USER);

                provider.update(PlateContentProvider.URI_USERS, upd, "" + Fields.ID_USR + " = '" + USER + "'",
                        null);
                //if(insert.size()>FROM)
                provider.applyBatch(insertData());
                insert.clear();
            } else {
                Log.e(TAG, "null response");
            }

        } catch (Exception e) {
            Log.e(TAG, "inserting .... fucked => message: " + e.getMessage());
        }

    }

}

From source file:github.popeen.dsub.util.SongDBHandler.java

public synchronized void setSongPlayed(DownloadFile downloadFile, boolean submission) {
    // TODO: In case of offline want to update all matches
    Pair<Integer, String> pair = getOnlineSongId(downloadFile);
    if (pair == null) {
        return;/* ww  w .  ja v  a2 s .c  o m*/
    }
    int serverKey = pair.getFirst();
    String id = pair.getSecond();

    // Open and make sure song is in db
    SQLiteDatabase db = this.getWritableDatabase();
    addSongImpl(db, serverKey, id, downloadFile.getSaveFile().getAbsolutePath());

    // Update song's last played
    ContentValues values = new ContentValues();
    values.put(submission ? SONGS_LAST_COMPLETED : SONGS_LAST_PLAYED, System.currentTimeMillis());
    db.update(TABLE_SONGS, values, SONGS_SERVER_KEY + " = ? AND " + SONGS_SERVER_ID + " = ?",
            new String[] { Integer.toString(serverKey), id });
    db.close();
}