summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2015-10-09 00:44:10 (GMT)
committerd34d <clark@cyngn.com>2015-11-20 03:22:56 (GMT)
commitc4a60a1aacab57d0587b8b7d5c5eedb7a691e69c (patch)
treea750dfa4b7732198fabf32cf67124ca3c69bcd30 /src
parent70ef064857296615e5ab777d91523e53e2581d3c (diff)
downloadandroid_packages_providers_ThemesProvider-c4a60a1aacab57d0587b8b7d5c5eedb7a691e69c.zip
android_packages_providers_ThemesProvider-c4a60a1aacab57d0587b8b7d5c5eedb7a691e69c.tar.gz
android_packages_providers_ThemesProvider-c4a60a1aacab57d0587b8b7d5c5eedb7a691e69c.tar.bz2
Add live lock screen previews [2/2]
Change-Id: Id0d210bae65b17a2eced021bdb2d19fa5063f678
Diffstat (limited to 'src')
-rw-r--r--src/org/cyanogenmod/themes/provider/PreviewGenerationService.java33
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java26
-rw-r--r--src/org/cyanogenmod/themes/provider/util/LiveLockScreenPreviewGenerator.java92
3 files changed, 148 insertions, 3 deletions
diff --git a/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java b/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java
index 3414144..fd33308 100644
--- a/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java
+++ b/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java
@@ -33,6 +33,8 @@ import android.util.Log;
import org.cyanogenmod.themes.provider.util.BootAnimationPreviewGenerator;
import org.cyanogenmod.themes.provider.util.IconPreviewGenerator;
import org.cyanogenmod.themes.provider.util.IconPreviewGenerator.IconItems;
+import org.cyanogenmod.themes.provider.util.LiveLockScreenPreviewGenerator;
+import org.cyanogenmod.themes.provider.util.LiveLockScreenPreviewGenerator.LiveLockScreenItems;
import org.cyanogenmod.themes.provider.util.PreviewUtils;
import org.cyanogenmod.themes.provider.util.StylePreviewGenerator;
import org.cyanogenmod.themes.provider.util.StylePreviewGenerator.StyleItems;
@@ -74,6 +76,7 @@ public class PreviewGenerationService extends IntentService {
boolean hasWallpaper = false;
boolean hasStyles = false;
boolean hasBootanimation = false;
+ boolean hasLiveLockScreen = false;
boolean isSystemTheme = ThemeConfig.SYSTEM_DEFAULT.equals(pkgName);
Cursor c = queryTheme(this, pkgName);
if (c != null) {
@@ -88,6 +91,8 @@ public class PreviewGenerationService extends IntentService {
hasStyles = c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_OVERLAYS)) == 1;
hasBootanimation =
c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_BOOT_ANIM)) == 1;
+ hasLiveLockScreen =
+ c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_LIVE_LOCK_SCREEN)) == 1;
}
c.close();
}
@@ -152,14 +157,25 @@ public class PreviewGenerationService extends IntentService {
Log.e(TAG, "Unable to create boot animation preview for " + pkgName, e);
}
}
+
+ LiveLockScreenItems liveLockScreenItems = null;
+ if (hasLiveLockScreen) {
+ try {
+ liveLockScreenItems = new LiveLockScreenPreviewGenerator(this)
+ .generateLiveLockScreenPreview(pkgName);
+ } catch (Exception e) {
+ Log.e(TAG, "Unable to create live lock screen preview for " + pkgName, e);
+ }
+ }
insertPreviewItemsIntoDb(pkgName, items, iconItems, wallpaperItems, styleItems,
- bootAnim);
+ liveLockScreenItems, bootAnim);
}
}
}
private void insertPreviewItemsIntoDb(String pkgName, SystemUiItems items, IconItems icons,
- WallpaperItems wallpaperItems, StyleItems styleItems, Bitmap bootAnim) {
+ WallpaperItems wallpaperItems, StyleItems styleItems,
+ LiveLockScreenItems liveLockScreenItems, Bitmap bootAnim) {
String[] projection = {ThemesColumns._ID};
String selection = ThemesColumns.PKG_NAME + "=?";
String[] selectionArgs = { pkgName };
@@ -318,6 +334,19 @@ public class PreviewGenerationService extends IntentService {
values = createPreviewEntryString(id, PreviewColumns.STYLE_PREVIEW, path);
themeValues.add(values);
}
+ if (liveLockScreenItems != null) {
+ path = PreviewUtils.compressAndSaveJpg(liveLockScreenItems.thumbnail, filesDir,
+ pkgName, PreviewColumns.LIVE_LOCK_SCREEN_THUMBNAIL);
+ values = createPreviewEntryString(id, PreviewColumns.LIVE_LOCK_SCREEN_THUMBNAIL,
+ path);
+ themeValues.add(values);
+
+ path = PreviewUtils.compressAndSaveJpg(liveLockScreenItems.preview, filesDir,
+ pkgName, PreviewColumns.LIVE_LOCK_SCREEN_PREVIEW);
+ values = createPreviewEntryString(id, PreviewColumns.LIVE_LOCK_SCREEN_PREVIEW,
+ path);
+ themeValues.add(values);
+ }
if (bootAnim != null) {
path = PreviewUtils.compressAndSavePng(bootAnim, filesDir, pkgName,
PreviewColumns.BOOTANIMATION_THUMBNAIL);
diff --git a/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java b/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java
index 4485362..eb5b21d 100644
--- a/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java
+++ b/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java
@@ -36,7 +36,7 @@ import android.util.Log;
public class ThemesOpenHelper extends SQLiteOpenHelper {
private static final String TAG = ThemesOpenHelper.class.getName();
- private static final int DATABASE_VERSION = 18;
+ private static final int DATABASE_VERSION = 19;
private static final String DATABASE_NAME = "themes.db";
private static final String SYSTEM_THEME_PKG_NAME = ThemeConfig.SYSTEM_DEFAULT;
private static final String OLD_SYSTEM_THEME_PKG_NAME = "holo";
@@ -128,6 +128,10 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
upgradeToVersion18(db);
oldVersion = 18;
}
+ if (oldVersion == 18) {
+ upgradeToVersion19(db);
+ oldVersion = 19;
+ }
if (oldVersion != DATABASE_VERSION) {
Log.e(TAG, "Recreating db because unknown database version: " + oldVersion);
dropTables(db);
@@ -459,6 +463,26 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
db.insert(MixnMatchTable.TABLE_NAME, null, values);
}
+ // Update any themes that have live lock screen
+ private void upgradeToVersion19(SQLiteDatabase db) {
+ // we need to update any existing themes
+ final String[] projection = { ThemesColumns.PKG_NAME };
+ final String selection = ThemesColumns.MODIFIES_LIVE_LOCK_SCREEN + "=?";
+ final String[] selectionArgs = { "1" };
+
+ final Cursor c = db.query(ThemesTable.TABLE_NAME, projection, selection, selectionArgs,
+ null, null, null);
+ if (c != null) {
+ while(c.moveToNext()) {
+ Intent intent = new Intent(mContext, PreviewGenerationService.class);
+ intent.setAction(PreviewGenerationService.ACTION_INSERT);
+ intent.putExtra(PreviewGenerationService.EXTRA_PKG_NAME, c.getString(0));
+ mContext.startService(intent);
+ }
+ c.close();
+ }
+ }
+
private void dropTables(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + ThemesTable.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + MixnMatchTable.TABLE_NAME);
diff --git a/src/org/cyanogenmod/themes/provider/util/LiveLockScreenPreviewGenerator.java b/src/org/cyanogenmod/themes/provider/util/LiveLockScreenPreviewGenerator.java
new file mode 100644
index 0000000..8d09e90
--- /dev/null
+++ b/src/org/cyanogenmod/themes/provider/util/LiveLockScreenPreviewGenerator.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2014 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.cyanogenmod.themes.provider.util;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.res.ThemeConfig;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.view.View;
+import android.widget.ImageView;
+import org.cyanogenmod.themes.provider.R;
+
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+public class LiveLockScreenPreviewGenerator {
+ private static final String LIVE_LOCK_SCREEN_PREVIEW_PATH = "live-lockscreen/preview";
+ private static final String PNG_EXT = ".png";
+ private static final String JPG_EXT = ".jpg";
+ private static final String JPEG_EXT = ".jpeg";
+
+ private Context mContext;
+
+ public LiveLockScreenPreviewGenerator(Context context) {
+ mContext = context;
+ }
+
+ public LiveLockScreenItems generateLiveLockScreenPreview(String pkgName)
+ throws IOException, PackageManager.NameNotFoundException {
+ final Context themeCtx = mContext.createPackageContext(pkgName, 0);
+ final InputStream is = getPreviewInputStream(themeCtx);
+ Bitmap bmp = null;
+ if (is != null) {
+ bmp = BitmapFactory.decodeStream(is);
+ }
+
+ LiveLockScreenItems items = null;
+ if (bmp != null) {
+ items = new LiveLockScreenItems();
+ items.preview = bmp;
+ items.thumbnail = Bitmap.createScaledBitmap(bmp, bmp.getWidth() / 4,
+ bmp.getHeight() / 4, true);
+ }
+
+ return items;
+ }
+
+ private InputStream getPreviewInputStream(Context themeContext) throws IOException {
+ InputStream is = null;
+ try {
+ is = themeContext.getAssets().open(LIVE_LOCK_SCREEN_PREVIEW_PATH + PNG_EXT);
+ } catch (FileNotFoundException e) {
+ }
+ if (is == null) {
+ try {
+ is = themeContext.getAssets().open(LIVE_LOCK_SCREEN_PREVIEW_PATH + JPG_EXT);
+ } catch (FileNotFoundException e) {
+ }
+ }
+ if (is == null) {
+ try {
+ is = themeContext.getAssets().open(LIVE_LOCK_SCREEN_PREVIEW_PATH + JPEG_EXT);
+ } catch (FileNotFoundException e) {
+ }
+ }
+ return is;
+ }
+
+ public class LiveLockScreenItems {
+ public Bitmap thumbnail;
+ public Bitmap preview;
+ }
+}