From d25b46108d55a2a81aa538f777bfeb8993f8a17f Mon Sep 17 00:00:00 2001 From: Richard MacGregor Date: Fri, 8 May 2015 14:25:14 -0700 Subject: Use files instead of blobs Previews columns now uses file paths instead of saving bitmap blobs in database. Depends on: http://review.cyanogenmod.org/#/c/96836/ http://review.cyanogenmod.org/#/c/97431/ http://review.cyanogenmod.org/#/c/97754/ http://gerrit.cyngn.com/#/c/11983/ Change-Id: Ie3ba8008f78b8e94dc1acf53e6b991a8311437dc --- src/com/cyngn/theme/chooser/ComponentSelector.java | 24 ++++++++++---------- src/com/cyngn/theme/chooser/MyThemeFragment.java | 4 ++-- src/com/cyngn/theme/chooser/ThemeFragment.java | 26 +++++++++++----------- src/com/cyngn/theme/util/Utils.java | 26 ++++++++++++++++++++++ 4 files changed, 53 insertions(+), 27 deletions(-) (limited to 'src/com') diff --git a/src/com/cyngn/theme/chooser/ComponentSelector.java b/src/com/cyngn/theme/chooser/ComponentSelector.java index 25d25a8..d693c7e 100644 --- a/src/com/cyngn/theme/chooser/ComponentSelector.java +++ b/src/com/cyngn/theme/chooser/ComponentSelector.java @@ -527,16 +527,16 @@ public class ComponentSelector extends LinearLayout int pkgNameIndex = cursor.getColumnIndex(ThemesContract.ThemesColumns.PKG_NAME); ((ImageView) v.findViewById(R.id.slot1)).setImageBitmap( - Utils.loadBitmapBlob(cursor, wifiIndex)); + Utils.loadBitmapFile(cursor, wifiIndex)); ((ImageView) v.findViewById(R.id.slot2)).setImageBitmap( - Utils.loadBitmapBlob(cursor, signalIndex)); + Utils.loadBitmapFile(cursor, signalIndex)); ((ImageView) v.findViewById(R.id.slot3)).setImageBitmap( - Utils.loadBitmapBlob(cursor, bluetoothIndex)); + Utils.loadBitmapFile(cursor, bluetoothIndex)); ((ImageView) v.findViewById(R.id.slot4)).setImageBitmap( - Utils.loadBitmapBlob(cursor, batteryIndex)); + Utils.loadBitmapFile(cursor, batteryIndex)); setTitle(((TextView) v.findViewById(R.id.title)), cursor); v.findViewById(R.id.container).setBackground( - new BitmapDrawable(Utils.loadBitmapBlob(cursor, backgroundIndex))); + new BitmapDrawable(Utils.loadBitmapFile(cursor, backgroundIndex))); v.setTag(cursor.getString(pkgNameIndex)); v.setOnClickListener(mItemClickListener); return v; @@ -551,10 +551,10 @@ public class ComponentSelector extends LinearLayout int pkgNameIndex = cursor.getColumnIndex(ThemesContract.ThemesColumns.PKG_NAME); ((ImageView) v.findViewById(R.id.back)).setImageBitmap( - Utils.loadBitmapBlob(cursor, backIndex)); + Utils.loadBitmapFile(cursor, backIndex)); setTitle(((TextView) v.findViewById(R.id.title)), cursor); v.findViewById(R.id.container).setBackground( - new BitmapDrawable(Utils.loadBitmapBlob(cursor, backgroundIndex))); + new BitmapDrawable(Utils.loadBitmapFile(cursor, backgroundIndex))); v.setTag(cursor.getString(pkgNameIndex)); v.setOnClickListener(mItemClickListener); return v; @@ -586,7 +586,7 @@ public class ComponentSelector extends LinearLayout int pkgNameIndex = cursor.getColumnIndex(ThemesContract.ThemesColumns.PKG_NAME); ((ImageView) v.findViewById(R.id.icon)).setImageBitmap( - Utils.loadBitmapBlob(cursor, iconIndex)); + Utils.loadBitmapFile(cursor, iconIndex)); setTitle(((TextView) v.findViewById(R.id.title)), cursor); v.setTag(cursor.getString(pkgNameIndex)); v.setOnClickListener(mItemClickListener); @@ -601,7 +601,7 @@ public class ComponentSelector extends LinearLayout int pkgNameIndex = cursor.getColumnIndex(ThemesContract.ThemesColumns.PKG_NAME); ((ImageView) v.findViewById(R.id.icon)).setImageBitmap( - Utils.loadBitmapBlob(cursor, styleIndex)); + Utils.loadBitmapFile(cursor, styleIndex)); setTitle(((TextView) v.findViewById(R.id.title)), cursor); v.setTag(cursor.getString(pkgNameIndex)); v.setOnClickListener(mItemClickListener); @@ -626,7 +626,7 @@ public class ComponentSelector extends LinearLayout cursor.moveToPosition(position - EXTRA_WALLPAPER_COMPONENTS); int pkgNameIndex = cursor.getColumnIndex(ThemesContract.ThemesColumns.PKG_NAME); iv.setImageBitmap( - Utils.loadBitmapBlob(cursor, wallpaperIndex)); + Utils.loadBitmapFile(cursor, wallpaperIndex)); setTitle(((TextView) v.findViewById(R.id.title)), cursor); v.setTag(cursor.getString(pkgNameIndex)); } @@ -642,7 +642,7 @@ public class ComponentSelector extends LinearLayout int pkgNameIndex = cursor.getColumnIndex(ThemesContract.ThemesColumns.PKG_NAME); ((ImageView) v.findViewById(R.id.preview)).setImageBitmap( - Utils.loadBitmapBlob(cursor, wallpaperIndex)); + Utils.loadBitmapFile(cursor, wallpaperIndex)); setTitle(((TextView) v.findViewById(R.id.title)), cursor); v.setTag(cursor.getString(pkgNameIndex)); v.setOnClickListener(mItemClickListener); @@ -784,4 +784,4 @@ public class ComponentSelector extends LinearLayout public void onSelectorOpened(); public void onSelectorClosed(); } -} \ No newline at end of file +} diff --git a/src/com/cyngn/theme/chooser/MyThemeFragment.java b/src/com/cyngn/theme/chooser/MyThemeFragment.java index f74d53b..c66ad53 100644 --- a/src/com/cyngn/theme/chooser/MyThemeFragment.java +++ b/src/com/cyngn/theme/chooser/MyThemeFragment.java @@ -423,7 +423,7 @@ public class MyThemeFragment extends ThemeFragment { Drawable wp = context == null ? null : wm.getDrawable(); if (wp == null) { - Bitmap bmp = Utils.loadBitmapBlob(c, wpIdx); + Bitmap bmp = Utils.loadBitmapFile(c, wpIdx); if (bmp != null) wp = new BitmapDrawable(res, bmp); } if (wp != null) { @@ -461,7 +461,7 @@ public class MyThemeFragment extends ThemeFragment { Drawable wp = context == null ? null : WallpaperManager.getInstance(context).getFastKeyguardDrawable(); if (wp == null) { - Bitmap bmp = Utils.loadBitmapBlob(c, wpIdx); + Bitmap bmp = Utils.loadBitmapFile(c, wpIdx); if (bmp != null) wp = new BitmapDrawable(res, bmp); } if (wp != null) { diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java index 09d119b..251181b 100644 --- a/src/com/cyngn/theme/chooser/ThemeFragment.java +++ b/src/com/cyngn/theme/chooser/ThemeFragment.java @@ -1638,7 +1638,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb int pkgNameIdx = c.getColumnIndex(ThemesColumns.PKG_NAME); int wpIdx = c.getColumnIndex(PreviewColumns.KEY_WALLPAPER_PREVIEW); final Resources res = getResources(); - Bitmap bitmap = Utils.loadBitmapBlob(c, wpIdx); + Bitmap bitmap = Utils.loadBitmapFile(c, wpIdx); if (bitmap != null) { mWallpaper.setImageBitmap(bitmap); mWallpaperCard.setWallpaper(new BitmapDrawable(res, bitmap)); @@ -1671,7 +1671,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb int pkgNameIdx = c.getColumnIndex(ThemesColumns.PKG_NAME); int wpIdx = c.getColumnIndex(PreviewColumns.KEY_LOCK_WALLPAPER_PREVIEW); final Resources res = getResources(); - Bitmap bitmap = Utils.loadBitmapBlob(c, wpIdx); + Bitmap bitmap = Utils.loadBitmapFile(c, wpIdx); if (bitmap != null) { mLockScreenCard.setWallpaper(new BitmapDrawable(res, bitmap)); String pkgName = c.getString(pkgNameIdx); @@ -1701,11 +1701,11 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb int clockColorIdx = c.getColumnIndex(PreviewColumns.KEY_STATUSBAR_CLOCK_TEXT_COLOR); int pkgNameIdx = c.getColumnIndex(ThemesColumns.PKG_NAME); - Bitmap background = Utils.loadBitmapBlob(c, backgroundIdx); - Bitmap bluetoothIcon = Utils.loadBitmapBlob(c, bluetoothIdx); - Bitmap wifiIcon = Utils.loadBitmapBlob(c, wifiIdx); - Bitmap signalIcon = Utils.loadBitmapBlob(c, signalIdx); - Bitmap batteryIcon = Utils.loadBitmapBlob(c, batteryIdx); + Bitmap background = Utils.loadBitmapFile(c, backgroundIdx); + Bitmap bluetoothIcon = Utils.loadBitmapFile(c, bluetoothIdx); + Bitmap wifiIcon = Utils.loadBitmapFile(c, wifiIdx); + Bitmap signalIcon = Utils.loadBitmapFile(c, signalIdx); + Bitmap batteryIcon = Utils.loadBitmapFile(c, batteryIdx); int wifiMargin = c.getInt(wifiMarginIdx); int clockTextColor = c.getInt(clockColorIdx); @@ -1778,7 +1778,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb for(int i=0; i < iconViews.size() && i < iconIdx.length; i++) { final ImageView v = iconViews.get(i); - Bitmap bitmap = Utils.loadBitmapBlob(c, iconIdx[i]); + Bitmap bitmap = Utils.loadBitmapFile(c, iconIdx[i]); Drawable oldIcon = v.getDrawable(); Drawable newIcon; if (bitmap == null) { @@ -1826,10 +1826,10 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb } int pkgNameIdx = c.getColumnIndex(ThemesColumns.PKG_NAME); - Bitmap background = Utils.loadBitmapBlob(c, backgroundIdx); - Bitmap backButton = Utils.loadBitmapBlob(c, backButtonIdx); - Bitmap homeButton = Utils.loadBitmapBlob(c, homeButtonIdx); - Bitmap recentButton = Utils.loadBitmapBlob(c, recentButtonIdx); + Bitmap background = Utils.loadBitmapFile(c, backgroundIdx); + Bitmap backButton = Utils.loadBitmapFile(c, backButtonIdx); + Bitmap homeButton = Utils.loadBitmapFile(c, homeButtonIdx); + Bitmap recentButton = Utils.loadBitmapFile(c, recentButtonIdx); Drawable overlay = null; if (animate) { @@ -1890,7 +1890,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb int pkgNameIdx = c.getColumnIndex(ThemesColumns.PKG_NAME); int styleIdx = c.getColumnIndex(PreviewColumns.KEY_STYLE_PREVIEW); - mStylePreview.setImageBitmap(Utils.loadBitmapBlob(c, styleIdx)); + mStylePreview.setImageBitmap(Utils.loadBitmapFile(c, styleIdx)); if (pkgNameIdx > -1) { String pkgName = c.getString(pkgNameIdx); if (!mPkgName.equals(pkgName) || (mPkgName.equals(pkgName) diff --git a/src/com/cyngn/theme/util/Utils.java b/src/com/cyngn/theme/util/Utils.java index 7b885a7..a2169e3 100644 --- a/src/com/cyngn/theme/util/Utils.java +++ b/src/com/cyngn/theme/util/Utils.java @@ -24,6 +24,7 @@ import android.graphics.Rect; import android.os.RemoteException; import android.provider.Settings; import android.provider.ThemesContract; +import android.text.TextUtils; import android.util.Log; import android.util.TypedValue; import android.view.IWindowManager; @@ -32,7 +33,9 @@ import android.view.WindowManager; import android.view.WindowManagerGlobal; import com.cyngn.theme.chooser.ChooserActivity; +import java.io.BufferedInputStream; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -274,6 +277,29 @@ public class Utils { return BitmapFactory.decodeByteArray(blob, 0, blob.length); } + public static Bitmap loadBitmapFile(Cursor cursor, int columnIdx) { + if (columnIdx < 0) { + Log.w(TAG, "loadBitmapFile(): Invalid index provided, returning null"); + return null; + } + String path = cursor.getString(columnIdx); + if (TextUtils.isEmpty(path)) { + return null; + } + + Bitmap image = null; + FileInputStream inputStream; + try { + inputStream = new FileInputStream(path); + image = BitmapFactory.decodeStream(inputStream); + inputStream.close(); + } catch (Exception e) { + Log.w(TAG, "Unable to open preview " + path, e); + } + + return image; + } + public static String getBatteryKey(int type) { switch(type) { case 2: -- cgit v1.2.3