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:Main.java

private static Uri createImageUri(Context context) {
    String name = "boreWbImg" + System.currentTimeMillis();
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, name);
    values.put(MediaStore.Images.Media.DISPLAY_NAME, name + ".jpeg");
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    Uri uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    return uri;/*from   w  w w.  ja v  a  2  s.  c o m*/
}

From source file:Main.java

private final static void updateMeta(Context ctx, Uri uri, String name, long ts) {
    ContentValues cv = new ContentValues();
    cv.put(MediaStore.Images.ImageColumns.DATE_TAKEN, ts);
    cv.put(MediaStore.Images.ImageColumns.IS_PRIVATE, 1);
    cv.put(MediaStore.Images.ImageColumns.TITLE, name);
    ctx.getContentResolver().update(uri, cv, null, null);
}

From source file:Main.java

public static ContentValues getContentValuesFromWeatherDataMap(HashMap<String, String> weatherDataMap) {
    if (weatherDataMap == null)
        return null;
    ContentValues contentValues = new ContentValues();
    for (Map.Entry<String, String> entry : weatherDataMap.entrySet()) {
        contentValues.put(entry.getKey(), entry.getValue());
    }//  w  w w .ja v  a  2  s  . co  m
    return contentValues;
}

From source file:Main.java

public static void insertEstablishment(SQLiteDatabase db, String name, String email, String password,
        String phone, String address, String waste) {
    ContentValues establishmentValues = new ContentValues();
    establishmentValues.put("NAME", name);
    establishmentValues.put("EMAIL", email);
    establishmentValues.put("PASSWORD", password);
    establishmentValues.put("PHONE", phone);
    establishmentValues.put("ADDRESS", address);
    establishmentValues.put("WASTE", waste);
    establishmentValues.put("ACTIVO", "ACTIVO");
    db.insert("ESTABLISHMENT", null, establishmentValues);
}

From source file:Main.java

public static void insert(SQLiteDatabase db, String title, String pubdate, String itemDetail, String link,
        String firstImgUrl, String sectionTitle) {
    ContentValues values = new ContentValues();
    values.put("title", title);
    values.put("pubdate", pubdate);
    values.put("item_detail", itemDetail);
    values.put("link", link);
    values.put("first_img_url", firstImgUrl);
    values.put("table_name", sectionTitle);
    db.insert("favorite_item", null, values);
    db.close();/*w  w w  . j a va 2s. co  m*/
}

From source file:Main.java

public static void insertContainer(SQLiteDatabase db, String nameContainer, String latlong,
        String establishmentName, String companyName, String estado, String activo, String waste) {
    ContentValues containerValues = new ContentValues();
    containerValues.put("NAME_CONTAINER", nameContainer);
    containerValues.put("LATLONG", latlong);
    containerValues.put("ESTABLISHMENT", establishmentName);
    containerValues.put("COMPANY", companyName);
    containerValues.put("ESTADO", estado);
    containerValues.put("ACTIVO", activo);
    containerValues.put("WASTE", waste);
    db.insert("CONTAINER", null, containerValues);
}

From source file:Main.java

private static void insertDepartment(SQLiteDatabase db, String name, double coordinateX, double coordinateY,
        String city, String address, String[] telephoneNumbers, String workingHours) {
    ContentValues valuesDepartment = new ContentValues();
    valuesDepartment.put("NAME", name);
    valuesDepartment.put("COORDINATE_X", coordinateX);
    valuesDepartment.put("COORDINATE_Y", coordinateY);
    valuesDepartment.put("CITY", city);
    valuesDepartment.put("ADDRESS", address);
    valuesDepartment.put("WORKING_HOURS", workingHours);
    long idInsertedDepartment = db.insert("DEPARTMENT", null, valuesDepartment);
    for (String number : telephoneNumbers) {
        ContentValues valuesNumbers = new ContentValues();
        valuesNumbers.put("DEPARTMENT_ID", idInsertedDepartment);
        valuesNumbers.put("TELEPHONE", number);
        db.insert("TELEPHONE", null, valuesNumbers);
    }//w  w w  .  j av  a  2  s  . com
}

From source file:Main.java

public static void addCallToLog(ContentResolver contentResolver, String number, long duration, int type,
        long time) {

    ContentValues values = new ContentValues();

    values.put(Calls.NUMBER, number);// ww  w  . ja v  a  2s  .c om

    values.put(Calls.DATE, time);

    values.put(Calls.DURATION, duration);

    values.put(Calls.TYPE, type);

    values.put(Calls.NEW, 1);

    values.put(Calls.CACHED_NAME, "");

    values.put(Calls.CACHED_NUMBER_TYPE, 0);

    values.put(Calls.CACHED_NUMBER_LABEL, "");

    contentResolver.insert(Calls.CONTENT_URI, values);

}

From source file:Main.java

public static void insertImage2MediaStore(Context context, String path) {
    File f = new File(path);
    if (f != null && f.exists()) {
        ContentValues values = new ContentValues();
        values.put(Media.DISPLAY_NAME, f.getName());
        values.put(Media.DESCRIPTION, f.getName());
        values.put(Media.MIME_TYPE, "image/jpeg");
        values.put(Media.DATA, path);

        Uri uri = context.getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
    }//from  w  w  w  .  j  av a  2  s  . com
}

From source file:Main.java

public static ContentValues objectToContentValues(Object object) {
    if (object == null) {
        throw new IllegalArgumentException("please check your argument");
    }/*from w w w .j  a v  a2s . co m*/
    ContentValues contentValues = new ContentValues();
    try {
        Field[] fields = object.getClass().getDeclaredFields();
        for (Field field : fields) {
            String fieldName = field.getName();
            Type type = field.getType();
            field.setAccessible(true);
            if (type.equals(String.class)) {
                contentValues.put(fieldName, field.get(object).toString());
            } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
                contentValues.put(fieldName, field.getInt(object));
            } else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
                contentValues.put(fieldName, field.getFloat(object));
            } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
                contentValues.put(fieldName, field.getLong(object));
            } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
                contentValues.put(fieldName, field.getDouble(object));
            } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
                contentValues.put(fieldName, field.getBoolean(object));
            }
        }
    } catch (IllegalAccessException | IllegalArgumentException e) {
        e.printStackTrace();
    }
    return contentValues;
}