Example usage for android.content ContentValues ContentValues

List of usage examples for android.content ContentValues ContentValues

Introduction

In this page you can find the example usage for android.content ContentValues ContentValues.

Prototype

public ContentValues() 

Source Link

Document

Creates an empty set of values using the default initial size

Usage

From source file:com.groupe1.miage.ujf.tracestaroute.FetchTrackTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city// w ww  .  j a v  a  2 s.  com
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
long addLocation(String cityName, double lat, double lon) {
    long locationId;

    // On regarde si la location avec nom de ville, x et y existe dja
    Cursor locationCursor = mContext.getContentResolver().query(TrackContract.LocationEntry.CONTENT_URI,
            new String[] { TrackContract.LocationEntry._ID },
            TrackContract.LocationEntry.COLUMN_LOC_CITY + " = ? AND "
                    + TrackContract.LocationEntry.COLUMN_LOC_COORD_LAT + " = ? AND "
                    + TrackContract.LocationEntry.COLUMN_LOC_COORD_LONG + " = ?",
            new String[] { cityName, String.valueOf(lat), String.valueOf(lon) }, null);

    if (locationCursor.moveToFirst()) {
        int locationIdIndex = locationCursor.getColumnIndex(TrackContract.LocationEntry._ID);
        locationId = locationCursor.getLong(locationIdIndex);
    } else {
        //Cration du lieu
        ContentValues locationValues = new ContentValues();

        //Ajout des informations
        locationValues.put(TrackContract.LocationEntry.COLUMN_LOC_CITY, cityName);
        locationValues.put(TrackContract.LocationEntry.COLUMN_LOC_COORD_LAT, lat);
        locationValues.put(TrackContract.LocationEntry.COLUMN_LOC_COORD_LONG, lon);

        //Insertion dans la BD
        Uri insertedUri = mContext.getContentResolver().insert(TrackContract.LocationEntry.CONTENT_URI,
                locationValues);

        locationId = ContentUris.parseId(insertedUri);
    }

    locationCursor.close();
    return locationId;
}

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  a2s  . com*/
    }

    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:edu.stanford.mobisocial.dungbeetle.feed.objects.FeedAnchorObj.java

@Override
public void afterDbInsertion(Context context, DbObj obj) {
    Uri feedUri = obj.getContainingFeed().getUri();
    String parentFeedName = obj.getJson().optString(PARENT_FEED_NAME);
    if (parentFeedName == null) {
        Log.e(TAG, "anchor for feed, but no parent given");
        return;// w ww.j a v  a 2  s  . com
    }

    Maybe<Group> parentGroup = Group.forFeedName(context, parentFeedName);
    if (!parentGroup.isKnown()) {
        Log.e(TAG, "No parent entry found for " + parentFeedName);
        return;
    }
    Long parentId = -1l;
    try {
        parentId = parentGroup.get().id;
    } catch (NoValError e) {
    }

    String feedName = feedUri.getLastPathSegment();
    Log.d(TAG, "Updating parent_feed_id for " + feedName);
    DBHelper mHelper = DBHelper.getGlobal(context);
    ContentValues cv = new ContentValues();
    cv.put(Group.PARENT_FEED_ID, parentId);
    mHelper.getWritableDatabase().update(Group.TABLE, cv, Group.FEED_NAME + "=?", new String[] { feedName });
    mHelper.close();
}

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 ww  w.  ja  va2 s .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.example.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  w w . j a  va 2 s .c o  m*/
 * @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
    // If it exists, return the current ID
    // Otherwise, insert it using the content resolver and the base URI
    long locationId;

    Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting },
            null);

    if (locationCursor.moveToFirst()) {
        int columnIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = locationCursor.getLong(columnIndex);
    } 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 insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                values);

        // The resulting URI contains the ID for the row.  Extract the locationId from the Uri.
        locationId = ContentUris.parseId(insertedUri);
    }
    locationCursor.close();

    return locationId;
}

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//from w w w . ja  v a2 s  .com
 * @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:br.com.dgimenes.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//from  w w  w  . j  ava 2  s. co m
 * @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) {
    long locationId;

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

    if (locationCursor.moveToFirst()) {
        int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = locationCursor.getLong(locationIdIndex);
    } else {
        // Now that the content provider is set up, inserting rows of data is pretty simple.
        // First create a ContentValues object to hold the data you want to insert.
        ContentValues locationValues = new ContentValues();

        // Then add the data, along with the corresponding name of the data type,
        // so the content provider knows what kind of value is being inserted.
        locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        // Finally, insert location data into the database.
        Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                locationValues);

        // The resulting URI contains the ID for the row.  Extract the locationId from the Uri.
        locationId = ContentUris.parseId(insertedUri);
    }

    locationCursor.close();
    // Wait, that worked?  Yes!
    return locationId;
}

From source file:com.example.mihai.inforoute.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/*from w  w 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) {
    long locationId;

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

    if (locationCursor.moveToFirst()) {
        int locationIdIndex = locationCursor.getColumnIndex(RouteContract.LocationEntry._ID);
        locationId = locationCursor.getLong(locationIdIndex);
    } else {
        // Now that the content provider is set up, inserting rows of data is pretty simple.
        // First create a ContentValues object to hold the data you want to insert.
        ContentValues locationValues = new ContentValues();

        // Then add the data, along with the corresponding name of the data type,
        // so the content provider knows what kind of value is being inserted.
        locationValues.put(RouteContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(RouteContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        locationValues.put(RouteContract.LocationEntry.COLUMN_COORD_LAT, lat);
        locationValues.put(RouteContract.LocationEntry.COLUMN_COORD_LONG, lon);

        // Finally, insert location data into the database.
        Uri insertedUri = mContext.getContentResolver().insert(RouteContract.LocationEntry.CONTENT_URI,
                locationValues);

        // The resulting URI contains the ID for the row.  Extract the locationId from the Uri.
        locationId = ContentUris.parseId(insertedUri);
    }

    locationCursor.close();
    return locationId;
}

From source file:com.prashantpal.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//from   ww  w .  ja  va  2  s.  c  o m
 * @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
    // If it exists, return the current ID
    long locationId;
    ContentResolver resolver = mContext.getContentResolver();
    Cursor cursor = resolver.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);
        locationId = cursor.getLong(locationIdIndex);
    } else {
        ContentValues contentValues = new ContentValues();
        contentValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);
        contentValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        Uri uri = resolver.insert(WeatherContract.LocationEntry.CONTENT_URI, contentValues);
        locationId = ContentUris.parseId(uri);
    }
    cursor.close();
    // Otherwise, insert it using the content resolver and the base URI
    return locationId;
}

From source file:totalcross.android.ConnectionManager4A.java

public static void setDefaultConfiguration(int type, String cfg) {
    if (cfg == null)
        cfg = "";

    switch (type) {
    case GPRS: {// w ww. j  a va2s.c o m
        int id = -1;
        ContentResolver contentResolver = Launcher4A.loader.getContentResolver();
        Cursor cursor = contentResolver.query(CONTENT_URI, new String[] { "_id" },
                "apn = ? and user = ? and password = ?", new String[] { "tim.br", "tim", "tim" }, null);
        if (cursor == null || cursor.getCount() <= 0) {
            TelephonyManager tel = (TelephonyManager) Launcher4A.loader
                    .getSystemService(Context.TELEPHONY_SERVICE);
            String networkOperator = tel.getNetworkOperator();

            if (networkOperator != null && networkOperator.length() > 0) {
                int mcc = Integer.parseInt(networkOperator.substring(0, 3));
                int mnc = Integer.parseInt(networkOperator.substring(3));
                ContentValues values = new ContentValues();
                values.put("apn", "tim.br");
                values.put("user", "tim");
                values.put("password", "tim");
                values.put("mcc", mcc);
                values.put("mnc", mnc);
                values.put("numeric", mcc + "" + mnc);
                contentResolver.insert(CONTENT_URI, values);
                cursor = contentResolver.query(CONTENT_URI, new String[] { "_id" },
                        "apn = ? and user = ? and password = ?", new String[] { "tim.br", "tim", "tim" }, null);
            }
        }
        if (cursor == null)
            return;
        if (cursor.moveToFirst())
            id = cursor.getInt(0);
        cursor.close();

        if (id > -1) {
            ContentValues values = new ContentValues();
            //See /etc/apns-conf.xml. The TelephonyProvider uses this file to provide
            //content://telephony/carriers/preferapn URI mapping
            values.put("apn_id", id);
            contentResolver.update(PREFERRED_APN_URI, values, null, null);
            cursor = contentResolver.query(PREFERRED_APN_URI, new String[] { "name", "apn" }, "_id=" + id, null,
                    null);
            if (cursor != null)
                cursor.close();
        }
    }
        break;
    case WIFI:
        connWIFI = connWIFIPrefix + cfg;
        break;
    //default:
    //   throw new IllegalArgumentException("Invalid value for argument 'type'");
    }
}