Search in sources :

Example 1 with SQLiteDatabase

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;
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) BitmapFactory(android.graphics.BitmapFactory) Cursor(android.database.Cursor)

Example 2 with SQLiteDatabase

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);
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with SQLiteDatabase

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) });
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) File(java.io.File)

Example 4 with SQLiteDatabase

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();
}
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 5 with SQLiteDatabase

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;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1553 Cursor (android.database.Cursor)499 ContentValues (android.content.ContentValues)321 ArrayList (java.util.ArrayList)105 File (java.io.File)65 Test (org.junit.Test)57 SQLiteException (android.database.sqlite.SQLiteException)45 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)44 Uri (android.net.Uri)44 ServiceStatus (com.vodafone360.people.service.ServiceStatus)42 IOException (java.io.IOException)41 SQLException (android.database.SQLException)36 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)36 RemoteException (android.os.RemoteException)36 Pair (android.util.Pair)31 MediumTest (android.test.suitebuilder.annotation.MediumTest)30 Account (android.accounts.Account)29 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)22 HashMap (java.util.HashMap)21