summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAndy Mast <andy@cyngn.com>2015-05-20 17:27:42 -0700
committerClark Scheff <clark@cyngn.com>2015-10-27 18:19:23 -0700
commitc07ca25126b4f9650f86af043a44fa90c37025fd (patch)
tree3dc976e0dc679743b82866e3d7471b6d9e0ecd1a /core
parent58f5b46439cc714a25400c42110423d4f73aa9c0 (diff)
downloadframeworks_base-c07ca25126b4f9650f86af043a44fa90c37025fd.zip
frameworks_base-c07ca25126b4f9650f86af043a44fa90c37025fd.tar.gz
frameworks_base-c07ca25126b4f9650f86af043a44fa90c37025fd.tar.bz2
[1/2] Themes: Multiwallpaper support
1. Add wallpaper component id to ThemeChangeRequest 2. Query themes provider for the wallpaper path given a pkgName and wallpaper id. Previously the path was only assumed from the pkgName. 3. Update the mix'n'match table to reflect the component id Change-Id: Ia38da1c36b3c2f7f038d0a34054aff2257a294dc
Diffstat (limited to 'core')
-rw-r--r--core/java/android/content/res/ThemeChangeRequest.java22
-rw-r--r--core/java/android/provider/ThemesContract.java7
-rw-r--r--core/java/com/android/internal/util/cm/ImageUtils.java45
3 files changed, 67 insertions, 7 deletions
diff --git a/core/java/android/content/res/ThemeChangeRequest.java b/core/java/android/content/res/ThemeChangeRequest.java
index 6c55cd2..08b0217 100644
--- a/core/java/android/content/res/ThemeChangeRequest.java
+++ b/core/java/android/content/res/ThemeChangeRequest.java
@@ -27,9 +27,12 @@ import static android.provider.ThemesContract.ThemesColumns.*;
/** @hide */
public final class ThemeChangeRequest implements Parcelable {
+ public static final int DEFAULT_WALLPAPER_ID = -1;
+
private final Map<String, String> mThemeComponents = new HashMap<String, String>();
private final Map<String, String> mPerAppOverlays = new HashMap<String, String>();
private RequestType mRequestType;
+ private long mWallpaperId = -1;
public String getOverlayThemePackageName() {
return getThemePackageNameForComponent(MODIFIES_OVERLAYS);
@@ -79,6 +82,10 @@ public final class ThemeChangeRequest implements Parcelable {
return Collections.unmodifiableMap(mThemeComponents);
}
+ public long getWallpaperId() {
+ return mWallpaperId;
+ }
+
/**
* Get the mapping for per app themes
* @return A mapping of apps and the theme to apply for each one. or null if none set.
@@ -100,7 +107,7 @@ public final class ThemeChangeRequest implements Parcelable {
}
private ThemeChangeRequest(Map<String, String> components, Map<String, String> perAppThemes,
- RequestType requestType) {
+ RequestType requestType, long wallpaperId) {
if (components != null) {
mThemeComponents.putAll(components);
}
@@ -108,6 +115,7 @@ public final class ThemeChangeRequest implements Parcelable {
mPerAppOverlays.putAll(perAppThemes);
}
mRequestType = requestType;
+ mWallpaperId = wallpaperId;
}
private ThemeChangeRequest(Parcel source) {
@@ -121,6 +129,7 @@ public final class ThemeChangeRequest implements Parcelable {
mPerAppOverlays.put(source.readString(), source.readString());
}
mRequestType = RequestType.values()[source.readInt()];
+ mWallpaperId = source.readLong();
}
@Override
@@ -141,6 +150,7 @@ public final class ThemeChangeRequest implements Parcelable {
dest.writeString(mPerAppOverlays.get(appPkgName));
}
dest.writeInt(mRequestType.ordinal());
+ dest.writeLong(mWallpaperId);
}
public static final Parcelable.Creator<ThemeChangeRequest> CREATOR =
@@ -168,6 +178,7 @@ public final class ThemeChangeRequest implements Parcelable {
Map<String, String> mThemeComponents = new HashMap<String, String>();
Map<String, String> mPerAppOverlays = new HashMap<String, String>();
RequestType mRequestType = RequestType.USER_REQUEST;
+ long mWallpaperId;
public Builder() {}
@@ -199,6 +210,12 @@ public final class ThemeChangeRequest implements Parcelable {
return setComponent(MODIFIES_LAUNCHER, pkgName);
}
+ // Used in the case that more than one wallpaper exists for a given pkg name
+ public Builder setWallpaperId(long id) {
+ mWallpaperId = id;
+ return this;
+ }
+
public Builder setLockWallpaper(String pkgName) {
return setComponent(MODIFIES_LOCKSCREEN, pkgName);
}
@@ -242,7 +259,8 @@ public final class ThemeChangeRequest implements Parcelable {
}
public ThemeChangeRequest build() {
- return new ThemeChangeRequest(mThemeComponents, mPerAppOverlays, mRequestType);
+ return new ThemeChangeRequest(mThemeComponents, mPerAppOverlays,
+ mRequestType, mWallpaperId);
}
}
}
diff --git a/core/java/android/provider/ThemesContract.java b/core/java/android/provider/ThemesContract.java
index c67ba4c..e3307a2 100644
--- a/core/java/android/provider/ThemesContract.java
+++ b/core/java/android/provider/ThemesContract.java
@@ -295,6 +295,13 @@ public class ThemesContract {
*/
public static final String COL_UPDATE_TIME = "update_time";
+ /*
+ * The unique ID for the component within a theme.
+ * Always 0 unless multiples of a component exist.
+ * <P>Type: INTEGER (long)</P>
+ */
+ public static final String COL_COMPONENT_ID = "component_id";
+
/**
* Valid keys
*/
diff --git a/core/java/com/android/internal/util/cm/ImageUtils.java b/core/java/com/android/internal/util/cm/ImageUtils.java
index d780384..73189a3 100644
--- a/core/java/com/android/internal/util/cm/ImageUtils.java
+++ b/core/java/com/android/internal/util/cm/ImageUtils.java
@@ -180,7 +180,8 @@ public class ImageUtils {
*
* @return a new InputStream of the cropped image/*"
*/
- public static InputStream getCroppedWallpaperStream(String pkgName, Context context) {
+ public static InputStream getCroppedWallpaperStream(String pkgName, long wallpaperId,
+ Context context) {
if (TextUtils.isEmpty(pkgName)) {
throw new IllegalArgumentException("'pkgName' cannot be null or empty!");
}
@@ -191,7 +192,7 @@ public class ImageUtils {
InputStream cropped = null;
InputStream stream = null;
try {
- stream = getOriginalWallpaperStream(pkgName, context);
+ stream = getOriginalWallpaperStream(pkgName, wallpaperId, context);
if (stream == null) {
return null;
}
@@ -203,7 +204,7 @@ public class ImageUtils {
WallpaperManager wm = WallpaperManager.getInstance(context);
int outWidth = wm.getDesiredMinimumWidth();
int outHeight = wm.getDesiredMinimumHeight();
- stream = getOriginalWallpaperStream(pkgName, context);
+ stream = getOriginalWallpaperStream(pkgName, wallpaperId, context);
if (stream == null) {
return null;
}
@@ -240,7 +241,9 @@ public class ImageUtils {
return inputStream;
}
- private static InputStream getOriginalWallpaperStream(String pkgName, Context context) {
+ private static InputStream getOriginalWallpaperStream(String pkgName, long componentId,
+ Context context) {
+ String wpPath;
if (TextUtils.isEmpty(pkgName) || context == null) {
return null;
}
@@ -277,7 +280,8 @@ public class ImageUtils {
Context themeCtx = context.createPackageContext(pkgName,
Context.CONTEXT_IGNORE_SECURITY);
AssetManager assetManager = themeCtx.getAssets();
- String wpPath = ThemeUtils.getWallpaperPath(assetManager);
+ wpPath = queryWpPathFromComponentId(context, pkgName, componentId);
+ if (wpPath == null) wpPath = ThemeUtils.getWallpaperPath(assetManager);
if (wpPath == null) {
Log.e(TAG, "Not setting wp because wallpaper file was not found.");
} else {
@@ -293,5 +297,36 @@ public class ImageUtils {
return inputStream;
}
+
+ private static String queryWpPathFromComponentId(Context context, String pkgName,
+ long componentId) {
+ String wpPath = null;
+ String[] projection = new String[] { ThemesContract.PreviewColumns.COL_VALUE };
+ String selection = ThemesColumns.PKG_NAME + "=? AND " +
+ ThemesContract.PreviewColumns.COMPONENT_ID + "=? AND " +
+ ThemesContract.PreviewColumns.COL_KEY + "=?";
+ String[] selectionArgs = new String[] {
+ pkgName,
+ Long.toString(componentId),
+ ThemesContract.PreviewColumns.WALLPAPER_FULL
+ };
+
+ Cursor c = context.getContentResolver()
+ .query(ThemesContract.PreviewColumns.COMPONENTS_URI,
+ projection, selection, selectionArgs, null);
+ if (c != null) {
+ try {
+ if (c.moveToFirst()) {
+ int valIdx = c.getColumnIndex(ThemesContract.PreviewColumns.COL_VALUE);
+ wpPath = c.getString(valIdx);
+ }
+ } catch(Exception e) {
+ Log.e(TAG, "Could not get wallpaper path", e);
+ } finally {
+ c.close();
+ }
+ }
+ return wpPath;
+ }
}