Add support for thumbnails to WallpaperInfo.
Clean up the Gallery to show thumbnails appropriately; still using FPO artwork
for wallpapers without thumbnails.
This change introduces a new "thumbnail" attribute to the API (used
in wallpaper metadata to point to the thumbnail drawable resource).
diff --git a/api/current.xml b/api/current.xml
index 68a1c76..581d2c4 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -8259,6 +8259,17 @@
visibility="public"
>
</field>
+<field name="thumbnail"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843429"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="tileMode"
type="int"
transient="false"
diff --git a/core/java/android/app/WallpaperInfo.java b/core/java/android/app/WallpaperInfo.java
index 5e44bc7..587e8f9 100644
--- a/core/java/android/app/WallpaperInfo.java
+++ b/core/java/android/app/WallpaperInfo.java
@@ -40,6 +40,11 @@
final String mSettingsActivityName;
/**
+ * Resource identifier for this wallpaper's thumbnail image.
+ */
+ final int mThumbnailResource;
+
+ /**
* Constructor.
*
* @param context The Context in which we are parsing the wallpaper.
@@ -53,6 +58,7 @@
PackageManager pm = context.getPackageManager();
String settingsActivityComponent = null;
+ int thumbnailRes = -1;
XmlResourceParser parser = null;
try {
@@ -79,16 +85,23 @@
com.android.internal.R.styleable.Wallpaper);
settingsActivityComponent = sa.getString(
com.android.internal.R.styleable.Wallpaper_settingsActivity);
+
+ thumbnailRes = sa.getResourceId(
+ com.android.internal.R.styleable.Wallpaper_thumbnail,
+ -1);
+
sa.recycle();
} finally {
if (parser != null) parser.close();
}
mSettingsActivityName = settingsActivityComponent;
+ mThumbnailResource = thumbnailRes;
}
WallpaperInfo(Parcel source) {
mSettingsActivityName = source.readString();
+ mThumbnailResource = source.readInt();
mService = ResolveInfo.CREATOR.createFromParcel(source);
}
@@ -144,6 +157,20 @@
}
/**
+ * Load the thumbnail image for this wallpaper.
+ *
+ * @param pm Supply a PackageManager used to load the wallpaper's
+ * resources.
+ */
+ public Drawable loadThumbnail(PackageManager pm) {
+ if (mThumbnailResource < 0) return null;
+
+ return pm.getDrawable(mService.serviceInfo.packageName,
+ mThumbnailResource,
+ null);
+ }
+
+ /**
* Return the class name of an activity that provides a settings UI for
* the wallpaper. You can launch this activity be starting it with
* an {@link android.content.Intent} whose action is MAIN and with an
@@ -178,6 +205,7 @@
*/
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mSettingsActivityName);
+ dest.writeInt(mThumbnailResource);
mService.writeToParcel(dest, flags);
}
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index a0d046f..193fdb2 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -3451,6 +3451,9 @@
<!-- Component name of an activity that allows the user to modify
the current settings for this wallpaper. -->
<attr name="settingsActivity" />
+
+ <!-- Reference to a the wallpaper's thumbnail bitmap. -->
+ <attr name="thumbnail" format="reference" />
</declare-styleable>
<!-- =============================== -->
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index b08a58a..4d23ef4 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1169,6 +1169,7 @@
<public type="attr" name="summaryColumn" />
<public type="attr" name="detailColumn" />
<public type="attr" name="detailSocialSummary" />
+ <public type="attr" name="thumbnail" />
<public type="style" name="Theme.Wallpaper" />
<public type="style" name="Theme.Wallpaper.NoTitleBar" />