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();
}
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();
}
}
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);
}
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);
}
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();
}
}
Aggregations