summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard MacGregor <rmacgregor@cyngn.com>2015-05-11 23:49:11 (GMT)
committerRichard MacGregor <rmacgregor@cyngn.com>2015-05-19 21:21:08 (GMT)
commitd19fe5d00c4711e4f9774f2cb752bcb2ba3c22f3 (patch)
tree4b0580ca3e92aaebd5dce86cdf0489c286083763 /src
parent4d4c54e33e1f081bb762ad18b6f411fe65036d35 (diff)
downloadandroid_packages_providers_ThemesProvider-d19fe5d00c4711e4f9774f2cb752bcb2ba3c22f3.zip
android_packages_providers_ThemesProvider-d19fe5d00c4711e4f9774f2cb752bcb2ba3c22f3.tar.gz
android_packages_providers_ThemesProvider-d19fe5d00c4711e4f9774f2cb752bcb2ba3c22f3.tar.bz2
[2/2] Recognized multiple wallpapers in theme
Generate previews for multiple wallpapers in theme assets. Add each wallpaper to the previews sql table. Make sure current ThemeChooser won't display extra wallpapers. Themes Provider will return defaults (first) wallpaper only for current ThemeChooser implementations. Later revisions of ThemeChooser will use different content URI for querying multiple wallpaper previews. Depends on: http://review.cyanogenmod.org/#/c/98012/ Change-Id: I88616148a226126509f8aca2d995d1446ccaada4
Diffstat (limited to 'src')
-rw-r--r--src/org/cyanogenmod/themes/provider/PreviewGenerationService.java87
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemesProvider.java2
-rw-r--r--src/org/cyanogenmod/themes/provider/util/ProviderUtils.java6
-rw-r--r--src/org/cyanogenmod/themes/provider/util/WallpaperPreviewGenerator.java76
4 files changed, 122 insertions, 49 deletions
diff --git a/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java b/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java
index 6d42c04..c1c0b16 100644
--- a/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java
+++ b/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java
@@ -39,6 +39,7 @@ import org.cyanogenmod.themes.provider.util.StylePreviewGenerator.StyleItems;
import org.cyanogenmod.themes.provider.util.SystemUiPreviewGenerator;
import org.cyanogenmod.themes.provider.util.SystemUiPreviewGenerator.SystemUiItems;
import org.cyanogenmod.themes.provider.util.WallpaperPreviewGenerator;
+import org.cyanogenmod.themes.provider.util.WallpaperPreviewGenerator.WallpaperItem;
import org.cyanogenmod.themes.provider.util.WallpaperPreviewGenerator.WallpaperItems;
import java.io.ByteArrayOutputStream;
@@ -267,33 +268,51 @@ public class PreviewGenerationService extends IntentService {
themeValues.add(values);
}
if (wallpaperItems != null) {
- if (wallpaperItems.wpPreview != null) {
- path = compressAndSaveJpg(wallpaperItems.wpPreview, filesDir, pkgName,
- PreviewColumns.WALLPAPER_PREVIEW);
- values = createPreviewEntryString(id,
- PreviewColumns.WALLPAPER_PREVIEW, path);
- themeValues.add(values);
- }
- if (wallpaperItems.wpThumbnail != null) {
- path = compressAndSavePng(wallpaperItems.wpThumbnail, filesDir, pkgName,
- PreviewColumns.WALLPAPER_THUMBNAIL);
- values = createPreviewEntryString(id,
- PreviewColumns.WALLPAPER_THUMBNAIL, path);
- themeValues.add(values);
- }
- if (wallpaperItems.lsPreview != null) {
- path = compressAndSaveJpg(wallpaperItems.lsPreview, filesDir, pkgName,
- PreviewColumns.LOCK_WALLPAPER_PREVIEW);
- values = createPreviewEntryString(id,
- PreviewColumns.LOCK_WALLPAPER_PREVIEW, path);
- themeValues.add(values);
+ for (int i = 0; i < wallpaperItems.wallpapers.size(); i++) {
+ String componentID = String.format("%03d", i);
+ WallpaperItem wallpaperItem = wallpaperItems.wallpapers.get(i);
+ if (wallpaperItem == null) continue;
+
+ if (wallpaperItem.assetPath != null) {
+ path = wallpaperItem.assetPath;
+ values = createPreviewEntryString(id, i,
+ PreviewColumns.WALLPAPER_FULL, path);
+ themeValues.add(values);
+ }
+
+ if (wallpaperItem.preview != null) {
+ path = compressAndSaveJpg(wallpaperItem.preview, filesDir, pkgName,
+ PreviewColumns.WALLPAPER_PREVIEW + componentID);
+ values = createPreviewEntryString(id, i,
+ PreviewColumns.WALLPAPER_PREVIEW, path);
+ themeValues.add(values);
+ }
+
+ if (wallpaperItem.thumbnail != null) {
+ path = compressAndSavePng(wallpaperItem.thumbnail, filesDir, pkgName,
+ PreviewColumns.WALLPAPER_THUMBNAIL + componentID);
+ values = createPreviewEntryString(id, i,
+ PreviewColumns.WALLPAPER_THUMBNAIL, path);
+ themeValues.add(values);
+ }
}
- if (wallpaperItems.lsThumbnail != null) {
- path = compressAndSavePng(wallpaperItems.lsThumbnail, filesDir, pkgName,
- PreviewColumns.LOCK_WALLPAPER_THUMBNAIL);
- values = createPreviewEntryString(id,
- PreviewColumns.LOCK_WALLPAPER_THUMBNAIL, path);
- themeValues.add(values);
+
+ if (wallpaperItems.lockscreen != null) {
+ if (wallpaperItems.lockscreen.preview != null) {
+ path = compressAndSaveJpg(wallpaperItems.lockscreen.preview, filesDir,
+ pkgName, PreviewColumns.LOCK_WALLPAPER_PREVIEW);
+ values = createPreviewEntryString(id,
+ PreviewColumns.LOCK_WALLPAPER_PREVIEW, path);
+ themeValues.add(values);
+ }
+
+ if (wallpaperItems.lockscreen.thumbnail != null) {
+ path = compressAndSavePng(wallpaperItems.lockscreen.thumbnail, filesDir,
+ pkgName, PreviewColumns.LOCK_WALLPAPER_THUMBNAIL);
+ values = createPreviewEntryString(id,
+ PreviewColumns.LOCK_WALLPAPER_THUMBNAIL, path);
+ themeValues.add(values);
+ }
}
}
if (styleItems != null) {
@@ -316,9 +335,11 @@ public class PreviewGenerationService extends IntentService {
}
if (!themeValues.isEmpty()) {
- selection = PreviewColumns.THEME_ID + "=? AND " + PreviewColumns.COL_KEY + "=?";
+ selection = PreviewColumns.THEME_ID + "=? AND " + PreviewColumns.COMPONENT_ID +
+ "=? AND " + PreviewColumns.COL_KEY + "=?";
for (ContentValues contentValues : themeValues) {
selectionArgs = new String[]{String.valueOf(id),
+ contentValues.getAsString(PreviewColumns.COMPONENT_ID),
contentValues.getAsString(PreviewColumns.COL_KEY)};
// Try an update first, if that returns 0 then we need to insert these values
if (resolver.update(PreviewColumns.CONTENT_URI, contentValues, selection,
@@ -331,8 +352,14 @@ public class PreviewGenerationService extends IntentService {
}
private static ContentValues createPreviewEntryInt(int id, String key, int value) {
+ return createPreviewEntryInt(id, 0, key, value);
+ }
+
+ private static ContentValues createPreviewEntryInt(int id, int componentId, String key,
+ int value) {
ContentValues values = new ContentValues();
values.put(PreviewColumns.THEME_ID, id);
+ values.put(PreviewColumns.COMPONENT_ID, componentId);
values.put(PreviewColumns.COL_KEY, key);
values.put(PreviewColumns.COL_VALUE, value);
@@ -340,8 +367,14 @@ public class PreviewGenerationService extends IntentService {
}
private static ContentValues createPreviewEntryString(int id, String key, String value) {
+ return createPreviewEntryString(id, 0, key, value);
+ }
+
+ private static ContentValues createPreviewEntryString(int id, int componentId, String key,
+ String value) {
ContentValues values = new ContentValues();
values.put(PreviewColumns.THEME_ID, id);
+ values.put(PreviewColumns.COMPONENT_ID, componentId);
values.put(PreviewColumns.COL_KEY, key);
values.put(PreviewColumns.COL_VALUE, value);
diff --git a/src/org/cyanogenmod/themes/provider/ThemesProvider.java b/src/org/cyanogenmod/themes/provider/ThemesProvider.java
index 8645bbc..1fdc69b 100644
--- a/src/org/cyanogenmod/themes/provider/ThemesProvider.java
+++ b/src/org/cyanogenmod/themes/provider/ThemesProvider.java
@@ -241,7 +241,7 @@ public class ThemesProvider extends ContentProvider {
break;
case PREVIEWS:
projection = ProviderUtils.modifyPreviewsProjection(projection);
- selection = ProviderUtils.modifyPreviewsSelection(selection, projection);
+ selection = ProviderUtils.modifyDefaultPreviewsSelection(selection, projection);
selectionArgs = ProviderUtils.modifyPreviewsSelectionArgs(selectionArgs, projection);
groupBy = PreviewColumns.THEME_ID + "," + PreviewColumns.COMPONENT_ID;
queryBuilder.setTables(THEMES_PREVIEWS_INNER_JOIN);
diff --git a/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java b/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java
index 065a1b0..ab98530 100644
--- a/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java
+++ b/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java
@@ -127,6 +127,12 @@ public class ProviderUtils {
return newProjection.toArray(new String[newProjection.size()]);
}
+ public static String modifyDefaultPreviewsSelection(String selection, String[] projection) {
+ String newSelection = modifyPreviewsSelection(selection, projection);
+ newSelection += " AND " + PreviewColumns.COMPONENT_ID + "=0";
+ return newSelection;
+ }
+
public static String modifyPreviewsSelection(String selection, String[] projection) {
String newSelection = selection;
List<String> projectionItems = getPreviewProjectionItems(projection);
diff --git a/src/org/cyanogenmod/themes/provider/util/WallpaperPreviewGenerator.java b/src/org/cyanogenmod/themes/provider/util/WallpaperPreviewGenerator.java
index 01b888a..f10a2f7 100644
--- a/src/org/cyanogenmod/themes/provider/util/WallpaperPreviewGenerator.java
+++ b/src/org/cyanogenmod/themes/provider/util/WallpaperPreviewGenerator.java
@@ -24,10 +24,13 @@ import android.content.res.Resources;
import android.content.res.ThemeConfig;
import android.graphics.Bitmap;
+import android.text.TextUtils;
import org.cyanogenmod.themes.provider.R;
import java.io.File;
import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
public class WallpaperPreviewGenerator {
private static final String WALLPAPER_ASSET_PATH = "wallpapers";
@@ -46,43 +49,74 @@ public class WallpaperPreviewGenerator {
public WallpaperItems generateWallpaperPreviews(PackageInfo themeInfo)
throws NameNotFoundException, IOException {
WallpaperItems items = new WallpaperItems();
+ WallpaperItem item = null;
+ Bitmap preview = null;
if (themeInfo == null) {
Resources res = mContext.getPackageManager().getThemedResourcesForApplication("android",
ThemeConfig.SYSTEM_DEFAULT);
- items.wpPreview = items.lsPreview = BitmapUtils.decodeResource(res,
+ item = new WallpaperItem();
+ item.preview = BitmapUtils.decodeResource(res,
com.android.internal.R.drawable.default_wallpaper, mPreviewSize, mPreviewSize);
+ item.thumbnail = Bitmap.createScaledBitmap(item.preview, mThumbnailSize, mThumbnailSize,
+ true);
+ if (item != null) {
+ items.wallpapers.add(item);
+ items.lockscreen = item;
+ }
} else {
final Context themeContext = mContext.createPackageContext(themeInfo.packageName, 0);
final AssetManager assets = themeContext.getAssets();
- String path = ThemeUtils.getWallpaperPath(assets);
- if (path != null) {
- items.wpPreview = BitmapUtils.getBitmapFromAsset(themeContext, path,
- mPreviewSize, mPreviewSize);
+ // Get all wallpapers
+ List<String> paths = ThemeUtils.getWallpaperPathList(assets);
+ for (String path : paths) {
+ if (!TextUtils.isEmpty(path)) {
+ preview = BitmapUtils.getBitmapFromAsset(themeContext, path,
+ mPreviewSize, mPreviewSize);
+ item = createWallpaperItems(path, preview);
+ if (item != null) {
+ items.wallpapers.add(item);
+ }
+ }
}
- path = ThemeUtils.getLockscreenWallpaperPath(assets);
- if (path != null) {
- items.lsPreview = BitmapUtils.getBitmapFromAsset(themeContext, path,
+ // Get the lockscreen
+ String path = ThemeUtils.getLockscreenWallpaperPath(assets);
+ if (!TextUtils.isEmpty(path)) {
+ preview = BitmapUtils.getBitmapFromAsset(themeContext, path,
mPreviewSize, mPreviewSize);
+ items.lockscreen = createWallpaperItems(path, preview);
}
}
- if (items.wpPreview != null) {
- items.wpThumbnail = Bitmap.createScaledBitmap(items.wpPreview, mThumbnailSize,
- mThumbnailSize, true);
- }
- if (items.lsPreview != null) {
- items.lsThumbnail = Bitmap.createScaledBitmap(items.lsPreview, mThumbnailSize,
- mThumbnailSize, true);
- }
return items;
}
+ private WallpaperItem createWallpaperItems(String path, Bitmap preview) {
+ if (TextUtils.isEmpty(path) || preview == null) {
+ return null;
+ }
+ WallpaperItem item = new WallpaperItem();
+ item.assetPath = path;
+ item.preview = preview;
+ item.thumbnail = Bitmap.createScaledBitmap(item.preview, mThumbnailSize, mThumbnailSize,
+ true);
+ return item;
+ }
+
+ public class WallpaperItem {
+ public String assetPath;
+ public Bitmap preview;
+ public Bitmap thumbnail;
+ }
+
public class WallpaperItems {
// Wallpaper items
- public Bitmap wpThumbnail;
- public Bitmap wpPreview;
+ public List<WallpaperItem> wallpapers;
- // Lockscreen wallpaper items
- public Bitmap lsThumbnail;
- public Bitmap lsPreview;
+ // Lockscreen wallpaper item
+ public WallpaperItem lockscreen;
+
+ public WallpaperItems() {
+ wallpapers = new LinkedList<WallpaperItem>();
+ lockscreen = null;
+ }
}
}