Example usage for android.content ContentValues get

List of usage examples for android.content ContentValues get

Introduction

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

Prototype

public Object get(String key) 

Source Link

Document

Gets a value.

Usage

From source file:Main.java

public static long getAsInteger(final ContentValues values, final String key, final int def) {
    if (values == null || key == null)
        return def;
    final Object value = values.get(key);
    if (value == null)
        return def;
    return Integer.valueOf(value.toString());
}

From source file:Main.java

public static boolean getAsBoolean(final ContentValues values, final String key, final boolean def) {
    if (values == null || key == null)
        return def;
    final Object value = values.get(key);
    if (value == null)
        return def;
    return Boolean.valueOf(value.toString());
}

From source file:Main.java

/**
 * Returns an array of values extracted from a {@link ContentValues}, based on the order of
 * the provided projection.//from   w ww .java2s  .  c o  m
 * @param values {@link ContentValues} object containing the values to convert into an array
 * @param projection array of column names
 *
 * @return array of values, in the correct order as defined by the projection
 */
public static Object[] getArrayFromContentValues(ContentValues values, String[] projection) {
    final Object[] result = new Object[projection.length];
    for (int i = 0; i < projection.length; i++) {
        result[i] = values.get(projection[i]);
    }
    return result;
}

From source file:Main.java

public static void bindValores(SQLiteStatement statement, ContentValues contentValues) {
    Set<String> chaves = new TreeSet<>(contentValues.keySet());
    int index = 1;

    for (String chave : chaves) {
        Object valor = contentValues.get(chave);

        if (valor == null) {
            statement.bindNull(index);//from   w  w  w . j  a v  a  2s  .c  om

        } else if (valor instanceof String) {
            statement.bindString(index, (String) valor);

        } else if (valor instanceof Double || valor instanceof Float) {
            statement.bindDouble(index, Double.valueOf(String.valueOf(valor)));

        } else if (valor instanceof Integer || valor instanceof Long) {
            statement.bindLong(index, Long.valueOf(String.valueOf(valor)));
        } else if (valor instanceof byte[]) {
            statement.bindBlob(index, (byte[]) valor);
        }
        index++;
    }
}

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

private static ContentProviderOperation insert(ContentValues buff) {
    final ContentProviderOperation.Builder builder = ContentProviderOperation
            .newInsert(PlateContentProvider.URI_REPORT);
    builder.withValue(Fields.RANKING, buff.get(Fields.RANKING));
    builder.withValue(Fields.DESCRIPTION, buff.get(Fields.DESCRIPTION));
    builder.withValue(Fields.DATE_REPORT, buff.get(Fields.DATE_REPORT));
    builder.withValue(Fields.CAR_PLATE, buff.get(Fields.CAR_PLATE));
    return builder.build();
}

From source file:org.servalproject.maps.bridge.json.FistJsonMaker.java

/**
 * take a table row as represented by a ContentValues object and return a JSON encoded string
 * @param values a ContentValues object representing a row in the database
 * @return a JSON encoded string of the data
 * @throws JSONException if the encode to JSON fails
 *///from w w w. j ava  2 s  .  com
public static String makePoiJson(ContentValues values) throws JSONException {

    // construct the JSON objects / arrays

    //add boilerplate to the container
    JSONObject mContainer = new JSONObject();
    mContainer.put("Version", "1.0");

    // build the event object
    JSONObject mEvent = new JSONObject();
    mEvent.put("imei", sImei);
    mEvent.put("messageCode", sMessageCode);
    mEvent.put("freeText", values.get(PointsOfInterestContract.Table.TITLE) + "<br/>"
            + values.get(PointsOfInterestContract.Table.DESCRIPTION));
    mEvent.put("timeStamp", values.get(PointsOfInterestContract.Table.TIMESTAMP));

    // build the addresses array
    JSONArray mAddresses = new JSONArray();

    for (String mAddress : sAddresses) {
        mAddresses.put(new JSONObject().put("address", mAddress));
    }
    ;

    mEvent.put("addresses", mAddresses);

    // build the point object
    JSONObject mPoint = new JSONObject();
    mPoint.put("latitude", values.get(PointsOfInterestContract.Table.LATITUDE));
    mPoint.put("longitude", values.get(PointsOfInterestContract.Table.LONGITUDE));
    mPoint.put("altitude", values.get(PointsOfInterestContract.Table.ALTITUDE));
    mPoint.put("gpsfix", values.get(PointsOfInterestContract.Table.ACCURACY));
    mPoint.put("course", sMissingPointValues);
    mPoint.put("speed", sMissingPointValues);

    // add the point object
    mEvent.put("point", mPoint);

    // build the status object
    JSONObject mStatus = new JSONObject();
    mStatus.put("autonomous", sMissingStatusValues);
    mStatus.put("lowBattery", sMissingStatusValues);
    mStatus.put("intervalChange", sMissingStatusValues);

    mEvent.put("status", mStatus);

    // build the events array
    JSONArray mEvents = new JSONArray();
    mEvents.put(mEvent);

    // finalise the object
    mContainer.put("Events", mEvents);

    return mContainer.toString();
}

From source file:org.droidparts.inner.PersistUtils.java

@SuppressWarnings("unchecked")
public static <T> ArrayList<String> getAddMissingColumns(SQLiteDatabase db, Class<? extends Entity> cls)
        throws Exception {
    String tableName = getTableName(cls);
    FieldSpec<ColumnAnn>[] columnSpecs = ClassSpecRegistry.getTableColumnSpecs(cls);
    ArrayList<String> presentColumns = getColumnNames(db, tableName);

    ArrayList<FieldSpec<ColumnAnn>> columns = new ArrayList<FieldSpec<ColumnAnn>>();
    for (FieldSpec<ColumnAnn> spec : columnSpecs) {
        if (!presentColumns.contains(spec.ann.name)) {
            columns.add(spec);/*from w  w w  .  j a  va  2 s.  com*/
        }
    }

    ArrayList<String> statements = new ArrayList<String>();
    for (FieldSpec<ColumnAnn> spec : columns) {
        Entity entity = ReflectionUtils.newInstance(cls);
        Converter<T> converter = (Converter<T>) ConverterRegistry.getConverter(spec.field.getType());
        Object defaultVal = ReflectionUtils.getFieldVal(entity, spec.field);
        //
        if (defaultVal != null) {
            ContentValues cv = new ContentValues();
            converter.putToContentValues((Class<T>) spec.field.getType(), spec.genericArg1, spec.genericArg2,
                    cv, DEFAULT, (T) defaultVal);
            defaultVal = cv.get(DEFAULT);
        }
        //
        String statement = getAddColumn(tableName, spec.ann.name, converter.getDBColumnType(),
                spec.ann.nullable, defaultVal);
        statements.add(statement);
    }
    return statements;
}

From source file:org.projectbuendia.client.ui.OdkActivityLauncher.java

private static boolean mapIdToUuid(Map<String, String> idToUuid, ContentValues values, String key) {
    String id = (String) values.get(key);
    String uuid = idToUuid.get(id);
    if (uuid == null) {
        return false;
    }//  w  w w.j  a  va  2s . c o  m
    values.put(key, uuid);
    return true;
}

From source file:org.catnut.util.CatnutUtils.java

/**
 * sql/*from w  w  w  . ja va2 s . c  o m*/
 */
public static String update(ContentValues values, String from, String where) {
    StringBuilder sb = new StringBuilder("UPDATE ").append(from).append(" SET");
    for (String key : values.keySet()) {
        sb.append(" ").append(key).append("=").append(reflectString(values.get(key))).append(",");
    }
    sb.deleteCharAt(sb.length() - 1); // remove the last ','
    if (where != null) {
        sb.append(" WHERE ").append(where);
    }
    return sb.toString();
}

From source file:net.eledge.android.toolkit.db.abstracts.Dao.java

public long store(E entity) {
    String idField = SQLBuilder.getIdField(clazz);
    ContentValues values = mapToContentValues(entity);
    if (values.get(idField) == null) {
        return db.insert(getTableName(), null, values);
    } else {/*  w  ww  . j  a  v  a  2  s.  c  o m*/
        long id = values.getAsLong(idField);
        StringBuilder sb = new StringBuilder("WHERE ");
        sb.append(SQLBuilder.getIdField(clazz)).append(" = ?");
        db.update(getTableName(), values, sb.toString(), new String[] { String.valueOf(id) });
        return id;
    }
}