Search in sources :

Example 11 with Cursor

use of android.database.Cursor in project Launcher3 by chislon.

the class SavedWallpaperImages method loadThumbnailsAndImageIdList.

public void loadThumbnailsAndImageIdList() {
    mImages = new ArrayList<SavedWallpaperTile>();
    SQLiteDatabase db = mDb.getReadableDatabase();
    Cursor result = db.query(ImageDb.TABLE_NAME, new String[] { ImageDb.COLUMN_ID, // cols to return
    ImageDb.COLUMN_IMAGE_THUMBNAIL_FILENAME }, // select query
    null, // args to select query
    null, null, null, ImageDb.COLUMN_ID + " DESC", null);
    while (result.moveToNext()) {
        String filename = result.getString(1);
        File file = new File(mContext.getFilesDir(), filename);
        Bitmap thumb = BitmapFactory.decodeFile(file.getAbsolutePath());
        if (thumb != null) {
            mImages.add(new SavedWallpaperTile(result.getInt(0), new BitmapDrawable(thumb)));
        }
    }
    result.close();
}
Also used : Bitmap(android.graphics.Bitmap) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Cursor(android.database.Cursor) File(java.io.File)

Example 12 with Cursor

use of android.database.Cursor in project cw-omnibus by commonsguy.

the class DatabaseHelper method onCreate.

@Override
public void onCreate(SQLiteDatabase db) {
    Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table' AND name='constants'", null);
    try {
        if (c.getCount() == 0) {
            db.execSQL("CREATE TABLE constants (_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, value REAL);");
            ContentValues cv = new ContentValues();
            cv.put(Provider.Constants.TITLE, "Gravity, Death Star I");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_DEATH_STAR_I);
            db.insert("constants", Provider.Constants.TITLE, cv);
            cv.put(Provider.Constants.TITLE, "Gravity, Earth");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_EARTH);
            db.insert("constants", Provider.Constants.TITLE, cv);
            cv.put(Provider.Constants.TITLE, "Gravity, Jupiter");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_JUPITER);
            db.insert("constants", Provider.Constants.TITLE, cv);
            cv.put(Provider.Constants.TITLE, "Gravity, Mars");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_MARS);
            db.insert("constants", Provider.Constants.TITLE, cv);
            cv.put(Provider.Constants.TITLE, "Gravity, Mercury");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_MERCURY);
            db.insert("constants", Provider.Constants.TITLE, cv);
            cv.put(Provider.Constants.TITLE, "Gravity, Moon");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_MOON);
            db.insert("constants", Provider.Constants.TITLE, cv);
            cv.put(Provider.Constants.TITLE, "Gravity, Neptune");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_NEPTUNE);
            db.insert("constants", Provider.Constants.TITLE, cv);
            cv.put(Provider.Constants.TITLE, "Gravity, Pluto");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_PLUTO);
            db.insert("constants", Provider.Constants.TITLE, cv);
            cv.put(Provider.Constants.TITLE, "Gravity, Saturn");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_SATURN);
            db.insert("constants", Provider.Constants.TITLE, cv);
            cv.put(Provider.Constants.TITLE, "Gravity, Sun");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_SUN);
            db.insert("constants", Provider.Constants.TITLE, cv);
            cv.put(Provider.Constants.TITLE, "Gravity, The Island");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_THE_ISLAND);
            db.insert("constants", Provider.Constants.TITLE, cv);
            cv.put(Provider.Constants.TITLE, "Gravity, Uranus");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_URANUS);
            db.insert("constants", Provider.Constants.TITLE, cv);
            cv.put(Provider.Constants.TITLE, "Gravity, Venus");
            cv.put(Provider.Constants.VALUE, SensorManager.GRAVITY_VENUS);
            db.insert("constants", Provider.Constants.TITLE, cv);
        }
    } finally {
        c.close();
    }
}
Also used : ContentValues(android.content.ContentValues) Cursor(android.database.Cursor)

Example 13 with Cursor

use of android.database.Cursor in project cw-omnibus by commonsguy.

the class Provider method query.

@Override
public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sort) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(TABLE);
    String orderBy;
    if (TextUtils.isEmpty(sort)) {
        orderBy = Constants.DEFAULT_SORT_ORDER;
    } else {
        orderBy = sort;
    }
    Cursor c = qb.query(db.getReadableDatabase(), projection, selection, selectionArgs, null, null, orderBy);
    c.setNotificationUri(getContext().getContentResolver(), url);
    return (c);
}
Also used : Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 14 with Cursor

use of android.database.Cursor in project TakePhoto by crazycodeboy.

the class TUriParse method getFileWithUri.

/**
     * 通过URI获取文件
     * @param uri
     * @param activity
     * @return
     * Author JPH
     * Date 2016/10/25
     */
public static File getFileWithUri(Uri uri, Activity activity) {
    String picturePath = null;
    String scheme = uri.getScheme();
    if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = activity.getContentResolver().query(uri, filePathColumn, null, null, //从系统表中查询指定Uri对应的照片
        null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        if (columnIndex >= 0) {
            //获取照片路径
            picturePath = cursor.getString(columnIndex);
        } else if (TextUtils.equals(uri.getAuthority(), TConstant.getFileProviderName(activity))) {
            picturePath = parseOwnUri(activity, uri);
        }
        cursor.close();
    } else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
        picturePath = uri.getPath();
    }
    return TextUtils.isEmpty(picturePath) ? null : new File(picturePath);
}
Also used : Cursor(android.database.Cursor) File(java.io.File)

Example 15 with Cursor

use of android.database.Cursor in project AndroidSyncProviderDemo by c99koder.

the class ContactsSyncAdapterService method updateContactStatus.

private static void updateContactStatus(ArrayList<ContentProviderOperation> operationList, long rawContactId, String status) {
    Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
    Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY);
    Cursor c = mContentResolver.query(entityUri, new String[] { RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1 }, null, null, null);
    try {
        while (c.moveToNext()) {
            if (!c.isNull(1)) {
                String mimeType = c.getString(2);
                if (mimeType.equals("vnd.android.cursor.item/vnd.org.c99.SyncProviderDemo.profile")) {
                    ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(ContactsContract.StatusUpdates.CONTENT_URI);
                    builder.withValue(ContactsContract.StatusUpdates.DATA_ID, c.getLong(1));
                    builder.withValue(ContactsContract.StatusUpdates.STATUS, status);
                    builder.withValue(ContactsContract.StatusUpdates.STATUS_RES_PACKAGE, "org.c99.SyncProviderDemo");
                    builder.withValue(ContactsContract.StatusUpdates.STATUS_LABEL, R.string.app_name);
                    builder.withValue(ContactsContract.StatusUpdates.STATUS_ICON, R.drawable.icon);
                    builder.withValue(ContactsContract.StatusUpdates.STATUS_TIMESTAMP, System.currentTimeMillis());
                    operationList.add(builder.build());
                    //statuses elsewhere
                    if (Integer.decode(Build.VERSION.SDK) < 11) {
                        builder = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI);
                        builder.withSelection(BaseColumns._ID + " = '" + c.getLong(1) + "'", null);
                        builder.withValue(ContactsContract.Data.DATA3, status);
                        operationList.add(builder.build());
                    }
                }
            }
        }
    } finally {
        c.close();
    }
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) Cursor(android.database.Cursor) Uri(android.net.Uri)

Aggregations

Cursor (android.database.Cursor)3795 ArrayList (java.util.ArrayList)522 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)499 Uri (android.net.Uri)455 ContentValues (android.content.ContentValues)300 ContentResolver (android.content.ContentResolver)188 RemoteException (android.os.RemoteException)182 Test (org.junit.Test)172 File (java.io.File)164 IOException (java.io.IOException)156 MatrixCursor (android.database.MatrixCursor)154 Intent (android.content.Intent)119 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 SQLException (android.database.SQLException)115 HashMap (java.util.HashMap)108 SQLiteCursor (android.database.sqlite.SQLiteCursor)88 SQLiteException (android.database.sqlite.SQLiteException)85 Query (android.app.DownloadManager.Query)76 MergeCursor (android.database.MergeCursor)75 LargeTest (android.test.suitebuilder.annotation.LargeTest)69