use of android.database.sqlite.SQLiteDatabase in project Launcher3 by chislon.
the class WidgetPreviewLoader method readFromDb.
private Bitmap readFromDb(String name, Bitmap b) {
if (mCachedSelectQuery == null) {
mCachedSelectQuery = CacheDb.COLUMN_NAME + " = ? AND " + CacheDb.COLUMN_SIZE + " = ?";
}
SQLiteDatabase db = mDb.getReadableDatabase();
Cursor result = db.query(CacheDb.TABLE_NAME, // cols to return
new String[] { CacheDb.COLUMN_PREVIEW_BITMAP }, // select query
mCachedSelectQuery, // args to select query
new String[] { name, mSize }, null, null, null, null);
if (result.getCount() > 0) {
result.moveToFirst();
byte[] blob = result.getBlob(0);
result.close();
final BitmapFactory.Options opts = mCachedBitmapFactoryOptions.get();
opts.inBitmap = b;
opts.inSampleSize = 1;
try {
return BitmapFactory.decodeByteArray(blob, 0, blob.length, opts);
} catch (IllegalArgumentException e) {
removeItemFromDb(mDb, name);
return null;
}
} else {
result.close();
return null;
}
}
use of android.database.sqlite.SQLiteDatabase in project Launcher3 by chislon.
the class WidgetPreviewLoader method writeToDb.
private void writeToDb(Object o, Bitmap preview) {
String name = getObjectName(o);
SQLiteDatabase db = mDb.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(CacheDb.COLUMN_NAME, name);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
preview.compress(Bitmap.CompressFormat.PNG, 100, stream);
values.put(CacheDb.COLUMN_PREVIEW_BITMAP, stream.toByteArray());
values.put(CacheDb.COLUMN_SIZE, mSize);
db.insert(CacheDb.TABLE_NAME, null, values);
}
use of android.database.sqlite.SQLiteDatabase in project Launcher3 by chislon.
the class SavedWallpaperImages method deleteImage.
public void deleteImage(int id) {
Pair<String, String> filenames = getImageFilenames(id);
File imageFile = new File(mContext.getFilesDir(), filenames.first);
imageFile.delete();
File thumbFile = new File(mContext.getFilesDir(), filenames.second);
thumbFile.delete();
SQLiteDatabase db = mDb.getWritableDatabase();
db.delete(ImageDb.TABLE_NAME, // SELECT query
ImageDb.COLUMN_ID + " = ?", new String[] { // args to SELECT query
Integer.toString(id) });
}
use of android.database.sqlite.SQLiteDatabase 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.sqlite.SQLiteDatabase in project Launcher3 by chislon.
the class LauncherProvider method delete.
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
int count = db.delete(args.table, args.where, args.args);
if (count > 0)
sendNotify(uri);
return count;
}
Aggregations