summaryrefslogtreecommitdiffstats
path: root/src/org/cyanogenmod/themes/provider/util
diff options
context:
space:
mode:
authorRichard MacGregor <rmacgregor@cyngn.com>2015-05-11 16:49:11 -0700
committerRichard MacGregor <rmacgregor@cyngn.com>2015-05-19 14:21:08 -0700
commitd19fe5d00c4711e4f9774f2cb752bcb2ba3c22f3 (patch)
tree4b0580ca3e92aaebd5dce86cdf0489c286083763 /src/org/cyanogenmod/themes/provider/util
parent4d4c54e33e1f081bb762ad18b6f411fe65036d35 (diff)
downloadandroid_packages_providers_ThemesProvider-d19fe5d00c4711e4f9774f2cb752bcb2ba3c22f3.tar.gz
android_packages_providers_ThemesProvider-d19fe5d00c4711e4f9774f2cb752bcb2ba3c22f3.tar.bz2
android_packages_providers_ThemesProvider-d19fe5d00c4711e4f9774f2cb752bcb2ba3c22f3.zip
[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/org/cyanogenmod/themes/provider/util')
-rw-r--r--src/org/cyanogenmod/themes/provider/util/ProviderUtils.java6
-rw-r--r--src/org/cyanogenmod/themes/provider/util/WallpaperPreviewGenerator.java76
2 files changed, 61 insertions, 21 deletions
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;
+ }
}
}