summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorRichard MacGregor <rmacgregor@cyngn.com>2015-05-18 12:24:39 -0700
committerRichard MacGregor <rmacgregor@cyngn.com>2015-05-18 21:50:49 +0000
commit364b4f3f8bb9cfe221164aa30d422fe6cf014229 (patch)
treec73c2ef2bcb200f5b9b8fdf2a46e3a4e908f413e /src/com
parentde412a4009dfe5f9d9a9434af54e1ec8f3423124 (diff)
downloadpackages_apps_ThemeChooser-364b4f3f8bb9cfe221164aa30d422fe6cf014229.tar.gz
packages_apps_ThemeChooser-364b4f3f8bb9cfe221164aa30d422fe6cf014229.tar.bz2
packages_apps_ThemeChooser-364b4f3f8bb9cfe221164aa30d422fe6cf014229.zip
Allow chooser to use files instead of blobs
This gives chooser the ability to use both older and newer versions of the themes provider. Older = blobs in previews table Newer = files paths in previews table Stable Branch depends on nothing. Master (12.1) depends on: http://review.cyanogenmod.org/#/c/98708/ http://review.cyanogenmod.org/#/c/98709/ Change-Id: I0e5d1ae85378d59d5f44deb9f6ef0a73e1a0f95b
Diffstat (limited to 'src/com')
-rw-r--r--src/com/cyngn/theme/chooser/ThemeFragment.java4
-rw-r--r--src/com/cyngn/theme/util/Utils.java30
2 files changed, 31 insertions, 3 deletions
diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java
index 585dd67..10f6a36 100644
--- a/src/com/cyngn/theme/chooser/ThemeFragment.java
+++ b/src/com/cyngn/theme/chooser/ThemeFragment.java
@@ -1271,7 +1271,6 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
PreviewColumns.ICON_PREVIEW_1,
PreviewColumns.ICON_PREVIEW_2,
PreviewColumns.ICON_PREVIEW_3,
- PreviewColumns.ICON_PREVIEW_4
};
break;
case LOADER_ID_WALLPAPER:
@@ -1638,11 +1637,10 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
if (mIconCard.isShowingEmptyView()) {
mIconCard.setEmptyViewEnabled(false);
}
- int[] iconIdx = new int[4];
+ int[] iconIdx = new int[3];
iconIdx[0] = c.getColumnIndex(PreviewColumns.ICON_PREVIEW_1);
iconIdx[1] = c.getColumnIndex(PreviewColumns.ICON_PREVIEW_2);
iconIdx[2] = c.getColumnIndex(PreviewColumns.ICON_PREVIEW_3);
- iconIdx[3] = c.getColumnIndex(PreviewColumns.ICON_PREVIEW_4);
int pkgNameIdx = c.getColumnIndex(ThemesColumns.PKG_NAME);
// Set the icons. If the provider does not have an icon preview then
diff --git a/src/com/cyngn/theme/util/Utils.java b/src/com/cyngn/theme/util/Utils.java
index 68c4211..3ae73b2 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;
@@ -33,6 +34,7 @@ import android.view.WindowManagerGlobal;
import com.cyngn.theme.chooser.ChooserActivity;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -269,11 +271,39 @@ public class Utils {
Log.w(TAG, "loadBitmapBlob(): Invalid index provided, returning null");
return null;
}
+
+ if (cursor.getType(columnIdx) == Cursor.FIELD_TYPE_STRING) {
+ return loadBitmapFile(cursor, columnIdx);
+ }
+
byte[] blob = cursor.getBlob(columnIdx);
if (blob == null) return null;
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 getBatteryIndex(int type) {
switch(type) {
case 2: