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

public static Uri pathToContentUri(Context context, String imagePath) {
    Cursor cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[] { "_id" },
            "_data=? ", new String[] { imagePath }, null);
    if (cursor != null && cursor.moveToFirst()) {
        int imageFile1 = cursor.getInt(cursor.getColumnIndex("_id"));
        Uri values1 = Uri.parse("content://media/external/images/media");
        return Uri.withAppendedPath(values1, "" + imageFile1);
    } else {//from   w w w  .ja v a  2  s  .c  o  m
        File imageFile = new File(imagePath);
        if (imageFile.exists()) {
            ContentValues values = new ContentValues();
            values.put("_data", imagePath);
            Uri baseUri = Media.EXTERNAL_CONTENT_URI;
            return context.getContentResolver().insert(baseUri, values);
        } else {
            return null;
        }
    }
}

From source file:Main.java

/**
 * Return ContentValues/*ww w .  j  a v a2  s .c  om*/
 *
 * @return contentValues
 */
public static ContentValues getContentValues() {
    ContentValues contentValues = new ContentValues();
    // TODO something
    return contentValues;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static ContentValues buildContentValues() {
    int colorCalendar = 0x0066CC;
    String intName = ACCOUNT_NAME + Calendar_Name;
    final ContentValues cv = new ContentValues();
    cv.put(Calendars.ACCOUNT_NAME, ACCOUNT_NAME);
    cv.put(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
    cv.put(Calendars.NAME, intName);//from  w ww .  j  a va2 s  .  c  o  m
    cv.put(Calendars.CALENDAR_DISPLAY_NAME, Calendar_Name);
    cv.put(Calendars.CALENDAR_COLOR, colorCalendar);
    cv.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
    cv.put(Calendars.OWNER_ACCOUNT, ACCOUNT_NAME);
    cv.put(Calendars.VISIBLE, 1);
    cv.put(Calendars.SYNC_EVENTS, 1);
    return cv;
}

From source file:com.lightydev.dk.json.Json.java

public static ContentValues parseObject(JSONObject object, Map<String, String> projection)
        throws JSONException {
    final ContentValues values = new ContentValues();
    for (final Map.Entry<String, String> entry : projection.entrySet()) {
        if (object.has(entry.getValue())) {
            if (object.isNull(entry.getValue())) {
                values.putNull(entry.getKey());
            } else {
                values.put(entry.getKey(), String.valueOf(object.get(entry.getValue())));
            }/*from  w  w  w .ja  v  a 2 s .com*/
        }
    }
    return values;
}

From source file:Main.java

private static void insertClientToWedding(SQLiteDatabase db, String nameClient, boolean weddingType,
        long weddingDate, String weddingPlace, String groomFullName, String groomPhone, String groomSoc,
        String brideFullName, String bridePhone, String brideSoc, int weddingBegin, int weddingEnd,
        String weddingMeet, int visaj, int visArr, int barber, int barberArr, int videoOp, int vidArr,
        int groomArr, String zagsName, int zagsFillTime, String walkDesc, String walkPlace, String banketPlace,
        int banketBegin, String wit1, String wit1Soc, String wit2, String wit2Soc, int photoAuthorCount,
        String photoFormat, String photoBook, int photoBookSize, int pbookTurns, int weddingCost, int garant,
        long dateOfPact, String weddingNote) {
    ContentValues cv = new ContentValues();
    cv.put("NAME", nameClient);
    cv.put("WEDDING_TYPE", weddingType);
    cv.put("WEDDING_DATE", weddingDate);
    cv.put("WEDDING_DATE_STRING",
            new SimpleDateFormat("dd MMM yy E", Locale.getDefault()).format(new Date(weddingDate)));
    cv.put("WEDDING_PLACE", weddingPlace);
    cv.put("WEDDING_GROOM", groomFullName);
    cv.put("WEDDING_GROOM_PHONE", groomPhone);
    cv.put("WEDDING_GROOM_SOC", groomSoc);
    cv.put("WEDDING_BRIDE", brideFullName);
    cv.put("WEDDING_BRIDE_PHONE", bridePhone);
    cv.put("WEDDING_BRIDE_SOC", brideSoc);
    cv.put("WEDDING_BEGIN", weddingBegin);
    cv.put("WEDDING_END", weddingEnd);
    cv.put("WEDDING_MEET", weddingMeet);
    cv.put("WEDDING_VIS", visaj);
    cv.put("WEDDING_VIS_ARR", visArr);
    cv.put("WEDDING_BARBER", barber);
    cv.put("WEDDING_BARBER_ARR", barberArr);
    cv.put("WEDDING_CAMOP", videoOp);
    cv.put("WEDDING_CAMOP_ARR", vidArr);
    cv.put("WEDDING_GROOM_ARR", groomArr);
    cv.put("WEDDING_ZAGS", zagsName);
    cv.put("WEDDING_ZAGS_FILLTIME", zagsFillTime);
    cv.put("WEDDING_WALK", walkDesc);
    cv.put("WEDDING_WALK_PLACE", walkPlace);
    cv.put("WEDDING_BANKET_PLACE", banketPlace);
    cv.put("WEDDING_BANKET_START", banketBegin);
    cv.put("WEDDING_WIT1", wit1);
    cv.put("WEDDING_WIT1_SOC", wit1Soc);
    cv.put("WEDDING_WIT2", wit2);
    cv.put("WEDDING_WIT2_SOC", wit2Soc);
    cv.put("WEDDING_PHOT_AUT", photoAuthorCount);
    cv.put("WEDDING_PHOT_FORMAT", photoFormat);
    cv.put("WEDDING_PHOT_BOOK", photoBook);
    cv.put("WEDDING_PBOOK_SIZE", photoBookSize);
    cv.put("WEDDING_PBOOK_TURNS", pbookTurns);
    cv.put("WEDDING_COST", weddingCost);
    cv.put("WEDDING_GARANT", garant);
    cv.put("WEDDING_PACT_DATE", dateOfPact);
    cv.put("WEDDING_NOTE", weddingNote);
    db.insert("WEDDING", null, cv);

}

From source file:Main.java

static File make_tmpdir(Context context, SQLiteDatabase db) throws Exception {

    File extdir = Environment.getExternalStorageDirectory();
    File tmp_top = new File(extdir, "tmp_LongText");
    if (!tmp_top.exists()) {
        if (!tmp_top.mkdir())
            throw new Exception("cannot create directory: " + tmp_top.getPath());
    }/*from w  w  w  .j av  a  2 s. co  m*/
    if (!tmp_top.canWrite())
        throw new Exception("missing permission to write to " + tmp_top.getPath());

    File tmpdir;
    Random r = new Random();
    do {
        tmpdir = new File(tmp_top, String.format("%d", r.nextInt()));
    } while (tmpdir.exists());
    if (!tmpdir.mkdir())
        throw new Exception("cannot create directory: " + tmp_top.getPath());
    if (!tmpdir.canWrite())
        throw new Exception("missing permission to write to " + tmp_top.getPath());
    ContentValues v = new ContentValues();
    v.put("pid", Process.myPid());
    v.put("tmpdir", tmpdir.getPath());
    v.put("ctime", System.currentTimeMillis());
    db.insert("tmpdir", null, v);

    return tmpdir;
}

From source file:Main.java

private static boolean modifyPermission(Context context, int flag) {
    String packageName = context.getPackageName();
    try {// w  w w .j av a 2  s  .c  om
        ContentValues contentValues = new ContentValues();
        contentValues.put("userAccept", Integer.valueOf(flag));
        context.getContentResolver().update(Uri.parse("content://com.lbe.security.miui.permmgr/active"),
                contentValues, "pkgName=?", new String[] { packageName });
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

public static void removeFromPlaylist(ContentResolver resolver, int audioId, long playlistId) {
    String[] cols = new String[] { "count(*)" };
    Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
    Cursor cur = resolver.query(uri, cols, null, null, null);
    cur.moveToFirst();/*from w ww .  j av  a 2 s  . c  o  m*/
    final int base = cur.getInt(0);
    cur.close();
    ContentValues values = new ContentValues();

    resolver.delete(uri, MediaStore.Audio.Playlists.Members.AUDIO_ID + "=" + audioId, null);

}

From source file:Main.java

public static void addToMediaStorePlaylist(ContentResolver resolver, int audioId, long playlistId) {
    String[] cols = new String[] { "count(*)" };
    Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
    Cursor cur = resolver.query(uri, cols, null, null, null);
    cur.moveToFirst();// w  w  w .j  a  va2 s.c o  m
    final int base = cur.getInt(0);
    cur.close();
    ContentValues values = new ContentValues();
    values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(base + audioId));
    values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audioId);
    resolver.insert(uri, values);

}

From source file:Main.java

public static void makeInsertItems(final long[] ids, final int offset, int len, final int base) {
    if (offset + len > ids.length) {
        len = ids.length - offset;/*from ww  w. java  2s  .co  m*/
    }

    if (mContentValuesCache == null || mContentValuesCache.length != len) {
        mContentValuesCache = new ContentValues[len];
    }
    for (int i = 0; i < len; i++) {
        if (mContentValuesCache[i] == null) {
            mContentValuesCache[i] = new ContentValues();
        }
        mContentValuesCache[i].put(Playlists.Members.PLAY_ORDER, base + offset + i);
        mContentValuesCache[i].put(Playlists.Members.AUDIO_ID, ids[offset + i]);
    }
}