diff options
| author | d34d <clark@cyngn.com> | 2016-02-23 14:44:08 -0800 |
|---|---|---|
| committer | Clark Scheff <clark@cyngn.com> | 2016-03-04 14:01:06 -0800 |
| commit | 1bd60bda797443e029846ef340b2083638b5e554 (patch) | |
| tree | b852a5e9ac5584640ab338cd827f629445e0f414 /core/java/android | |
| parent | 8ff13dea571cefa0197d71b37d69adbe2908ad55 (diff) | |
| download | frameworks_base-1bd60bda797443e029846ef340b2083638b5e554.zip frameworks_base-1bd60bda797443e029846ef340b2083638b5e554.tar.gz frameworks_base-1bd60bda797443e029846ef340b2083638b5e554.tar.bz2 | |
Themes: Refactor themes to CMSDK [1/6]
Change-Id: I3688b37342eddcfceeabaae982085884e9bc63ee
TICKET: CYNGNOS-2126
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 10 | ||||
| -rw-r--r-- | core/java/android/app/ContextImpl.java | 2 | ||||
| -rw-r--r-- | core/java/android/app/IconPackHelper.java | 23 | ||||
| -rw-r--r-- | core/java/android/app/ResourcesManager.java | 8 | ||||
| -rw-r--r-- | core/java/android/app/SystemServiceRegistry.java | 11 | ||||
| -rw-r--r-- | core/java/android/content/Context.java | 10 | ||||
| -rw-r--r-- | core/java/android/content/Intent.java | 23 | ||||
| -rw-r--r-- | core/java/android/content/pm/ThemeUtils.java | 605 | ||||
| -rw-r--r-- | core/java/android/content/res/IThemeChangeListener.aidl | 22 | ||||
| -rw-r--r-- | core/java/android/content/res/IThemeProcessingListener.aidl | 21 | ||||
| -rw-r--r-- | core/java/android/content/res/IThemeService.aidl | 43 | ||||
| -rw-r--r-- | core/java/android/content/res/ThemeChangeRequest.aidl | 19 | ||||
| -rw-r--r-- | core/java/android/content/res/ThemeChangeRequest.java | 307 | ||||
| -rw-r--r-- | core/java/android/content/res/ThemeConfig.java | 52 | ||||
| -rw-r--r-- | core/java/android/content/res/ThemeManager.java | 316 | ||||
| -rw-r--r-- | core/java/android/provider/ThemesContract.java | 731 |
16 files changed, 38 insertions, 2165 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 7d3b572..f08390f 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -2456,16 +2456,6 @@ public final class ActivityThread { return activity; } - private void sendAppLaunchFailureBroadcast(ActivityClientRecord r) { - String pkg = null; - if (r.packageInfo != null && !TextUtils.isEmpty(r.packageInfo.getPackageName())) { - pkg = r.packageInfo.getPackageName(); - } - Intent intent = new Intent(Intent.ACTION_APP_FAILURE, - (pkg != null)? Uri.fromParts("package", pkg, null) : null); - getSystemContext().sendBroadcast(intent); - } - private Context createBaseContextForActivity(ActivityClientRecord r, final Activity activity) { int displayId = Display.DEFAULT_DISPLAY; try { diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index 479010d..d443d80 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -40,8 +40,6 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.AssetManager; import android.content.res.CompatibilityInfo; import android.content.res.Configuration; -import android.content.res.IThemeService; -import android.content.res.ThemeManager; import android.content.res.Resources; import android.database.DatabaseErrorHandler; import android.database.sqlite.SQLiteDatabase; diff --git a/core/java/android/app/IconPackHelper.java b/core/java/android/app/IconPackHelper.java index 627330f..80fb401 100644 --- a/core/java/android/app/IconPackHelper.java +++ b/core/java/android/app/IconPackHelper.java @@ -25,7 +25,6 @@ import java.util.Map; import java.util.Random; import android.content.pm.PackageInfo; -import android.content.res.IThemeService; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -44,7 +43,10 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.util.Log; import android.util.TypedValue; + import com.android.internal.util.cm.palette.Palette; + +import org.cyanogenmod.internal.themes.IIconCacheManager; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; @@ -103,6 +105,12 @@ public class IconPackHelper { private static final float DEFAULT_SCALE = 1.0f; private static final int COMPOSED_ICON_COOKIE = 128; + private static final String ICON_CACHE_SERVICE = "cmiconcache"; + + public static final String SYSTEM_THEME_PATH = "/data/system/theme"; + public static final String SYSTEM_THEME_ICON_CACHE_DIR = SYSTEM_THEME_PATH + + File.separator + "icons"; + private final Context mContext; private Map<ComponentName, String> mIconPackResourceMap; private String mLoadedIconPackName; @@ -410,15 +418,12 @@ public class IconPackHelper { String prefixPath; String iconApkPath; - String iconResPath; if (info.isLegacyIconPackApk) { - iconResPath = ""; iconApkPath = ""; prefixPath = ""; } else { prefixPath = ThemeUtils.ICONS_PATH; //path inside APK iconApkPath = ThemeUtils.getIconPackApkPath(packageName); - iconResPath = ThemeUtils.getIconPackResPath(packageName); } AssetManager assets = new AssetManager(); @@ -587,11 +592,11 @@ public class IconPackHelper { public static class IconCustomizer { private static final Random sRandom = new Random(); - private static final IThemeService sThemeService; + private static final IIconCacheManager sIconCacheManager; static { - sThemeService = IThemeService.Stub.asInterface( - ServiceManager.getService(Context.THEME_SERVICE)); + sIconCacheManager = IIconCacheManager.Stub.asInterface( + ServiceManager.getService(ICON_CACHE_SERVICE)); } public static Drawable getComposedIconDrawable(Drawable icon, Context context, @@ -802,7 +807,7 @@ public class IconPackHelper { private static boolean cacheComposedIcon(Bitmap bmp, String path) { try { - return sThemeService.cacheComposedIcon(bmp, path); + return sIconCacheManager.cacheComposedIcon(bmp, path); } catch (RemoteException e) { Log.e(TAG, "Unable to cache icon.", e); } @@ -811,7 +816,7 @@ public class IconPackHelper { } private static String getCachedIconPath(String pkgName, int resId, int density) { - return String.format("%s/%s", ThemeUtils.SYSTEM_THEME_ICON_CACHE_DIR, + return String.format("%s/%s", SYSTEM_THEME_ICON_CACHE_DIR, getCachedIconName(pkgName, resId, density)); } diff --git a/core/java/android/app/ResourcesManager.java b/core/java/android/app/ResourcesManager.java index 7492cd0..e2d0537 100644 --- a/core/java/android/app/ResourcesManager.java +++ b/core/java/android/app/ResourcesManager.java @@ -625,7 +625,8 @@ public class ResourcesManager { String targetPackagePath = piTarget.applicationInfo.sourceDir; String prefixPath = ThemeUtils.getOverlayPathToTarget(basePackageName); - String resCachePath = ThemeUtils.getTargetCacheDir(piTarget.packageName, piTheme); + String resCachePath = ThemeUtils.getTargetCacheDir(piTarget.packageName, + piTheme.packageName); String resApkPath = resCachePath + "/resources.apk"; String idmapPath = ThemeUtils.getIdmapPath(piTarget.packageName, piTheme.packageName); int cookie = assets.addOverlayPath(idmapPath, themePath, resApkPath, @@ -639,7 +640,8 @@ public class ResourcesManager { if (!piTarget.isThemeApk && !"android".equals(basePackageName) && piTheme.mOverlayTargets.contains("android")) { - String resCachePath= ThemeUtils.getTargetCacheDir(piAndroid.packageName, piTheme); + String resCachePath= ThemeUtils.getTargetCacheDir(piAndroid.packageName, + piTheme.packageName); String prefixPath = ThemeUtils.getOverlayPathToTarget(piAndroid.packageName); String targetPackagePath = piAndroid.applicationInfo.publicSourceDir; String resApkPath = resCachePath + "/resources.apk"; @@ -742,7 +744,7 @@ public class ResourcesManager { String themePath = piTheme.applicationInfo.publicSourceDir; String prefixPath = ThemeUtils.COMMON_RES_PATH; String resCachePath = - ThemeUtils.getTargetCacheDir(ThemeUtils.COMMON_RES_TARGET, piTheme); + ThemeUtils.getTargetCacheDir(ThemeUtils.COMMON_RES_TARGET, piTheme.packageName); String resApkPath = resCachePath + "/resources.apk"; int cookie = assets.addCommonOverlayPath(themePath, resApkPath, prefixPath); diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index 08f4efd..3d264c6 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -37,9 +37,7 @@ import android.content.IRestrictionsManager; import android.content.RestrictionsManager; import android.content.pm.ILauncherApps; import android.content.pm.LauncherApps; -import android.content.res.IThemeService; import android.content.res.Resources; -import android.content.res.ThemeManager; import android.hardware.ConsumerIrManager; import android.hardware.ISerialManager; import android.hardware.SensorManager; @@ -706,15 +704,6 @@ final class SystemServiceRegistry { public RadioManager createService(ContextImpl ctx) { return new RadioManager(ctx); }}); - - registerService(Context.THEME_SERVICE, ThemeManager.class, - new CachedServiceFetcher<ThemeManager>() { - public ThemeManager createService(ContextImpl ctx) { - IBinder b = ServiceManager.getService(Context.THEME_SERVICE); - IThemeService service = IThemeService.Stub.asInterface(b); - return new ThemeManager(ctx.getOuterContext(), - service); - }}); } /** diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index fc40a73..7ddda11 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -3152,16 +3152,6 @@ public abstract class Context { /** * Use with {@link #getSystemService} to retrieve a - * {@link android.content.res.ThemeManager} for accessing theme service. - * - * @see #getSystemService - * @see android.content.res.ThemeManager - * @hide - */ - public static final String THEME_SERVICE = "themes"; - - /** - * Use with {@link #getSystemService} to retrieve a * {@link android.nfc.NfcManager} for using NFC. * * @see #getSystemService diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index 2a24fe3..d063454 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -2881,21 +2881,6 @@ public class Intent implements Parcelable, Cloneable { "android.intent.action.QUICK_CLOCK"; /** - * Broadcast Action: Indicate that unrecoverable error happened during app launch. - * Could indicate that curently applied theme is malicious. - * @hide - */ - public static final String ACTION_APP_FAILURE = - "com.tmobile.intent.action.APP_FAILURE"; - - /** - * Broadcast Action: Request to reset the unrecoverable errors count to 0. - * @hide - */ - public static final String ACTION_APP_FAILURE_RESET = - "com.tmobile.intent.action.APP_FAILURE_RESET"; - - /** * Activity Action: Shows the brightness setting dialog. * @hide */ @@ -3282,14 +3267,6 @@ public class Intent implements Parcelable, Cloneable { @SdkConstant(SdkConstantType.INTENT_CATEGORY) public static final String CATEGORY_CAR_MODE = "android.intent.category.CAR_MODE"; - /** - * Used to indicate that a theme package has been installed or un-installed. - * - * @hide - */ - public static final String CATEGORY_THEME_PACKAGE_INSTALLED_STATE_CHANGE = - "com.tmobile.intent.category.THEME_PACKAGE_INSTALL_STATE_CHANGE"; - // --------------------------------------------------------------------- // --------------------------------------------------------------------- // Application launch intent categories (see addCategory()). diff --git a/core/java/android/content/pm/ThemeUtils.java b/core/java/android/content/pm/ThemeUtils.java index e41523c..07e73b5 100644 --- a/core/java/android/content/pm/ThemeUtils.java +++ b/core/java/android/content/pm/ThemeUtils.java @@ -15,112 +15,30 @@ */ package android.content.pm; -import android.content.BroadcastReceiver; -import android.content.ContentResolver; -import android.content.ContentValues; -import android.content.Context; -import android.content.ContextWrapper; -import android.content.IntentFilter; -import android.content.res.AssetManager; -import android.content.res.Configuration; import android.content.res.ThemeConfig; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.media.RingtoneManager; -import android.net.Uri; -import android.os.FileUtils; -import android.os.SystemProperties; -import android.provider.MediaStore; -import android.provider.Settings; -import android.provider.ThemesContract; -import android.provider.ThemesContract.ThemesColumns; import android.text.TextUtils; -import android.util.DisplayMetrics; -import android.util.Log; -import android.view.WindowManager; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedReader; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.InputStreamReader; -import java.nio.ByteBuffer; -import java.util.ArrayList; import java.util.jar.StrictJarFile; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.zip.CRC32; import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import java.util.zip.ZipOutputStream; - -import static android.content.res.ThemeConfig.SYSTEM_DEFAULT; /** * @hide */ public class ThemeUtils { - private static final String TAG = "ThemeUtils"; + private static final String TAG = ThemeUtils.class.getSimpleName(); /* Path inside a theme APK to the overlay folder */ public static final String OVERLAY_PATH = "assets/overlays/"; public static final String ICONS_PATH = "assets/icons/"; public static final String COMMON_RES_PATH = "assets/overlays/common/"; - public static final String FONT_XML = "fonts.xml"; public static final String RESOURCE_CACHE_DIR = "/data/resource-cache/"; - public static final String IDMAP_SUFFIX = "@idmap"; - public static final String COMMON_RES_SUFFIX = ".common"; public static final String COMMON_RES_TARGET = "common"; - public static final String ICON_HASH_FILENAME = "hash"; - - // path to external theme resources, i.e. bootanimation.zip - public static final String SYSTEM_THEME_PATH = "/data/system/theme"; - public static final String SYSTEM_THEME_FONT_PATH = SYSTEM_THEME_PATH + File.separator + "fonts"; - public static final String SYSTEM_THEME_RINGTONE_PATH = SYSTEM_THEME_PATH - + File.separator + "ringtones"; - public static final String SYSTEM_THEME_NOTIFICATION_PATH = SYSTEM_THEME_PATH - + File.separator + "notifications"; - public static final String SYSTEM_THEME_ALARM_PATH = SYSTEM_THEME_PATH - + File.separator + "alarms"; - public static final String SYSTEM_THEME_ICON_CACHE_DIR = SYSTEM_THEME_PATH - + File.separator + "icons"; - // internal path to bootanimation.zip inside theme apk - public static final String THEME_BOOTANIMATION_PATH = "assets/bootanimation/bootanimation.zip"; - - public static final String SYSTEM_MEDIA_PATH = "/system/media/audio"; - public static final String SYSTEM_ALARMS_PATH = SYSTEM_MEDIA_PATH + File.separator - + "alarms"; - public static final String SYSTEM_RINGTONES_PATH = SYSTEM_MEDIA_PATH + File.separator - + "ringtones"; - public static final String SYSTEM_NOTIFICATIONS_PATH = SYSTEM_MEDIA_PATH + File.separator - + "notifications"; - - // path to asset lockscreen and wallpapers directory - public static final String LOCKSCREEN_WALLPAPER_PATH = "lockscreen"; - public static final String WALLPAPER_PATH = "wallpapers"; - - private static final String MEDIA_CONTENT_URI = "content://media/internal/audio/media"; - - // Constants for theme change broadcast - public static final String ACTION_THEME_CHANGED = "org.cyanogenmod.intent.action.THEME_CHANGED"; - public static final String CATEGORY_THEME_COMPONENT_PREFIX = "org.cyanogenmod.intent.category."; - public static final String EXTRA_COMPONENTS = "components"; - public static final String EXTRA_REQUEST_TYPE = "request_type"; - public static final String EXTRA_UPDATE_TIME = "update_time"; - - public static final int SYSTEM_TARGET_API = 0; // Package name for any app which does not have a specific theme applied private static final String DEFAULT_PKG = "default"; - private static final String SETTINGS_DB = - "/data/data/com.android.providers.settings/databases/settings.db"; - private static final String SETTINGS_SECURE_TABLE = "secure"; private static final String MANIFEST_NAME = "META-INF/MANIFEST.MF"; /** @@ -156,18 +74,10 @@ public class ThemeUtils { /** * Get the path of the resource cache for the given target and theme - * @param targetPkgName - * @param themePkg + * @param targetPkgName Target app package name + * @param themePkgName Theme package name * @return Path to the resource cache for this target and theme */ - public static String getTargetCacheDir(String targetPkgName, PackageInfo themePkg) { - return getTargetCacheDir(targetPkgName, themePkg.packageName); - } - - public static String getTargetCacheDir(String targetPkgName, PackageParser.Package themePkg) { - return getTargetCacheDir(targetPkgName, themePkg.packageName); - } - public static String getTargetCacheDir(String targetPkgName, String themePkgName) { return getOverlayResourceCacheDir(themePkgName) + File.separator + targetPkgName; } @@ -181,18 +91,10 @@ public class ThemeUtils { return getOverlayResourceCacheDir(pkgName) + File.separator + "icons"; } - public static String getIconHashFile(String pkgName) { - return getIconPackDir(pkgName) + File.separator + ICON_HASH_FILENAME; - } - public static String getIconPackApkPath(String pkgName) { return getIconPackDir(pkgName) + "/resources.apk"; } - public static String getIconPackResPath(String pkgName) { - return getIconPackDir(pkgName) + "/resources.arsc"; - } - public static String getIdmapPath(String targetPkgName, String overlayPkgName) { return getTargetCacheDir(targetPkgName, overlayPkgName) + File.separator + "idmap"; } @@ -211,507 +113,6 @@ public class ThemeUtils { return COMMON_RES_TARGET; } - public static void createCacheDirIfNotExists() throws IOException { - File file = new File(RESOURCE_CACHE_DIR); - if (!file.exists() && !file.mkdir()) { - throw new IOException("Could not create dir: " + file.toString()); - } - FileUtils.setPermissions(file, FileUtils.S_IRWXU - | FileUtils.S_IRWXG | FileUtils.S_IROTH | FileUtils.S_IXOTH, -1, -1); - } - - public static void createResourcesDirIfNotExists(String targetPkgName, String overlayPkgName) - throws IOException { - createDirIfNotExists(getOverlayResourceCacheDir(overlayPkgName)); - File file = new File(getTargetCacheDir(targetPkgName, overlayPkgName)); - if (!file.exists() && !file.mkdir()) { - throw new IOException("Could not create dir: " + file.toString()); - } - FileUtils.setPermissions(file, FileUtils.S_IRWXU - | FileUtils.S_IRWXG | FileUtils.S_IROTH | FileUtils.S_IXOTH, -1, -1); - } - - public static void createIconDirIfNotExists(String pkgName) throws IOException { - createDirIfNotExists(getOverlayResourceCacheDir(pkgName)); - File file = new File(getIconPackDir(pkgName)); - if (!file.exists() && !file.mkdir()) { - throw new IOException("Could not create dir: " + file.toString()); - } - FileUtils.setPermissions(file, FileUtils.S_IRWXU - | FileUtils.S_IRWXG | FileUtils.S_IROTH | FileUtils.S_IXOTH, -1, -1); - } - - private static boolean dirExists(String dirPath) { - final File dir = new File(dirPath); - return dir.exists() && dir.isDirectory(); - } - - private static void createDirIfNotExists(String dirPath) { - if (!dirExists(dirPath)) { - File dir = new File(dirPath); - if (dir.mkdir()) { - FileUtils.setPermissions(dir, FileUtils.S_IRWXU | - FileUtils.S_IRWXG| FileUtils.S_IROTH | FileUtils.S_IXOTH, -1, -1); - } - } - } - - /** - * Create SYSTEM_THEME_PATH directory if it does not exist - */ - public static void createThemeDirIfNotExists() { - createDirIfNotExists(SYSTEM_THEME_PATH); - } - - /** - * Create SYSTEM_FONT_PATH directory if it does not exist - */ - public static void createFontDirIfNotExists() { - createDirIfNotExists(SYSTEM_THEME_FONT_PATH); - } - - /** - * Create SYSTEM_THEME_RINGTONE_PATH directory if it does not exist - */ - public static void createRingtoneDirIfNotExists() { - createDirIfNotExists(SYSTEM_THEME_RINGTONE_PATH); - } - - /** - * Create SYSTEM_THEME_NOTIFICATION_PATH directory if it does not exist - */ - public static void createNotificationDirIfNotExists() { - createDirIfNotExists(SYSTEM_THEME_NOTIFICATION_PATH); - } - - /** - * Create SYSTEM_THEME_ALARM_PATH directory if it does not exist - */ - public static void createAlarmDirIfNotExists() { - createDirIfNotExists(SYSTEM_THEME_ALARM_PATH); - } - - /** - * Create SYSTEM_THEME_ICON_CACHE_DIR directory if it does not exist - */ - public static void createIconCacheDirIfNotExists() { - createDirIfNotExists(SYSTEM_THEME_ICON_CACHE_DIR); - } - - public static void clearIconCache() { - FileUtils.deleteContents(new File(SYSTEM_THEME_ICON_CACHE_DIR)); - } - - public static InputStream getInputStreamFromAsset(Context ctx, String path) throws IOException { - if (ctx == null || path == null) - return null; - InputStream is = null; - String ASSET_BASE = "file:///android_asset/"; - path = path.substring(ASSET_BASE.length()); - AssetManager assets = ctx.getAssets(); - is = assets.open(path); - return is; - } - - public static void closeQuietly(InputStream stream) { - if (stream == null) - return; - try { - stream.close(); - } catch (IOException e) { - } - } - - public static void closeQuietly(OutputStream stream) { - if (stream == null) - return; - try { - stream.close(); - } catch (IOException e) { - } - } - - /** - * Scale the boot animation to better fit the device by editing the desc.txt found - * in the bootanimation.zip - * @param context Context to use for getting an instance of the WindowManager - * @param input InputStream of the original bootanimation.zip - * @param dst Path to store the newly created bootanimation.zip - * @throws IOException - */ - public static void copyAndScaleBootAnimation(Context context, InputStream input, String dst) - throws IOException { - final OutputStream os = new FileOutputStream(dst); - final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(os)); - final ZipInputStream bootAni = new ZipInputStream(new BufferedInputStream(input)); - ZipEntry ze; - - zos.setMethod(ZipOutputStream.STORED); - final byte[] bytes = new byte[4096]; - int len; - while ((ze = bootAni.getNextEntry()) != null) { - ZipEntry entry = new ZipEntry(ze.getName()); - entry.setMethod(ZipEntry.STORED); - entry.setCrc(ze.getCrc()); - entry.setSize(ze.getSize()); - entry.setCompressedSize(ze.getSize()); - if (!ze.getName().equals("desc.txt")) { - // just copy this entry straight over into the output zip - zos.putNextEntry(entry); - while ((len = bootAni.read(bytes)) > 0) { - zos.write(bytes, 0, len); - } - } else { - String line; - BufferedReader reader = new BufferedReader(new InputStreamReader(bootAni)); - final String[] info = reader.readLine().split(" "); - - int scaledWidth; - int scaledHeight; - WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); - DisplayMetrics dm = new DisplayMetrics(); - wm.getDefaultDisplay().getRealMetrics(dm); - // just in case the device is in landscape orientation we will - // swap the values since most (if not all) animations are portrait - if (dm.widthPixels > dm.heightPixels) { - scaledWidth = dm.heightPixels; - scaledHeight = dm.widthPixels; - } else { - scaledWidth = dm.widthPixels; - scaledHeight = dm.heightPixels; - } - - int width = Integer.parseInt(info[0]); - int height = Integer.parseInt(info[1]); - - if (width == height) - scaledHeight = scaledWidth; - else { - // adjust scaledHeight to retain original aspect ratio - float scale = (float)scaledWidth / (float)width; - int newHeight = (int)((float)height * scale); - if (newHeight < scaledHeight) - scaledHeight = newHeight; - } - - CRC32 crc32 = new CRC32(); - int size = 0; - ByteBuffer buffer = ByteBuffer.wrap(bytes); - line = String.format("%d %d %s\n", scaledWidth, scaledHeight, info[2]); - buffer.put(line.getBytes()); - size += line.getBytes().length; - crc32.update(line.getBytes()); - while ((line = reader.readLine()) != null) { - line = String.format("%s\n", line); - buffer.put(line.getBytes()); - size += line.getBytes().length; - crc32.update(line.getBytes()); - } - entry.setCrc(crc32.getValue()); - entry.setSize(size); - entry.setCompressedSize(size); - zos.putNextEntry(entry); - zos.write(buffer.array(), 0, size); - } - zos.closeEntry(); - } - zos.close(); - } - - public static boolean isValidAudible(String fileName) { - return (fileName != null && - (fileName.endsWith(".mp3") || fileName.endsWith(".ogg"))); - } - - public static boolean setAudible(Context context, File ringtone, int type, String name) { - final String path = ringtone.getAbsolutePath(); - final String mimeType = name.endsWith(".ogg") ? "audio/ogg" : "audio/mp3"; - ContentValues values = new ContentValues(); - values.put(MediaStore.MediaColumns.DATA, path); - values.put(MediaStore.MediaColumns.TITLE, name); - values.put(MediaStore.MediaColumns.MIME_TYPE, mimeType); - values.put(MediaStore.MediaColumns.SIZE, ringtone.length()); - values.put(MediaStore.Audio.Media.IS_RINGTONE, type == RingtoneManager.TYPE_RINGTONE); - values.put(MediaStore.Audio.Media.IS_NOTIFICATION, - type == RingtoneManager.TYPE_NOTIFICATION); - values.put(MediaStore.Audio.Media.IS_ALARM, type == RingtoneManager.TYPE_ALARM); - values.put(MediaStore.Audio.Media.IS_MUSIC, false); - - Uri uri = MediaStore.Audio.Media.getContentUriForPath(path); - Uri newUri = null; - Cursor c = context.getContentResolver().query(uri, - new String[] {MediaStore.MediaColumns._ID}, - MediaStore.MediaColumns.DATA + "='" + path + "'", - null, null); - if (c != null && c.getCount() > 0) { - c.moveToFirst(); - long id = c.getLong(0); - c.close(); - newUri = Uri.withAppendedPath(Uri.parse(MEDIA_CONTENT_URI), "" + id); - context.getContentResolver().update(uri, values, - MediaStore.MediaColumns._ID + "=" + id, null); - } - if (newUri == null) - newUri = context.getContentResolver().insert(uri, values); - try { - RingtoneManager.setActualDefaultRingtoneUri(context, type, newUri); - } catch (Exception e) { - return false; - } - return true; - } - - public static boolean setDefaultAudible(Context context, int type) { - final String audiblePath = getDefaultAudiblePath(type); - if (audiblePath != null) { - Uri uri = MediaStore.Audio.Media.getContentUriForPath(audiblePath); - Cursor c = context.getContentResolver().query(uri, - new String[] {MediaStore.MediaColumns._ID}, - MediaStore.MediaColumns.DATA + "='" + audiblePath + "'", - null, null); - if (c != null && c.getCount() > 0) { - c.moveToFirst(); - long id = c.getLong(0); - c.close(); - uri = Uri.withAppendedPath( - Uri.parse(MEDIA_CONTENT_URI), "" + id); - } - if (uri != null) - RingtoneManager.setActualDefaultRingtoneUri(context, type, uri); - } else { - return false; - } - return true; - } - - public static String getDefaultAudiblePath(int type) { - final String name; - final String path; - switch (type) { - case RingtoneManager.TYPE_ALARM: - name = SystemProperties.get("ro.config.alarm_alert", null); - path = name != null ? SYSTEM_ALARMS_PATH + File.separator + name : null; - break; - case RingtoneManager.TYPE_NOTIFICATION: - name = SystemProperties.get("ro.config.notification_sound", null); - path = name != null ? SYSTEM_NOTIFICATIONS_PATH + File.separator + name : null; - break; - case RingtoneManager.TYPE_RINGTONE: - name = SystemProperties.get("ro.config.ringtone", null); - path = name != null ? SYSTEM_RINGTONES_PATH + File.separator + name : null; - break; - default: - path = null; - break; - } - return path; - } - - public static void clearAudibles(Context context, String audiblePath) { - final File audibleDir = new File(audiblePath); - if (audibleDir.exists()) { - String[] files = audibleDir.list(); - final ContentResolver resolver = context.getContentResolver(); - for (String s : files) { - final String filePath = audiblePath + File.separator + s; - Uri uri = MediaStore.Audio.Media.getContentUriForPath(filePath); - resolver.delete(uri, MediaStore.MediaColumns.DATA + "=\"" - + filePath + "\"", null); - (new File(filePath)).delete(); - } - } - } - - public static Context createUiContext(final Context context) { - try { - Context uiContext = context.createPackageContext("com.android.systemui", - Context.CONTEXT_RESTRICTED); - return new ThemedUiContext(uiContext, context.getApplicationContext()); - } catch (PackageManager.NameNotFoundException e) { - } - - return null; - } - - public static void registerThemeChangeReceiver(final Context context, - final BroadcastReceiver receiver) { - IntentFilter filter = new IntentFilter(ACTION_THEME_CHANGED); - - context.registerReceiver(receiver, filter); - } - - public static String getLockscreenWallpaperPath(AssetManager assetManager) throws IOException { - String[] assets = assetManager.list(LOCKSCREEN_WALLPAPER_PATH); - String asset = getFirstNonEmptyAsset(assets); - if (asset == null) return null; - return LOCKSCREEN_WALLPAPER_PATH + File.separator + asset; - } - - public static String getWallpaperPath(AssetManager assetManager) throws IOException { - String[] assets = assetManager.list(WALLPAPER_PATH); - String asset = getFirstNonEmptyAsset(assets); - if (asset == null) return null; - return WALLPAPER_PATH + File.separator + asset; - } - - public static List<String> getWallpaperPathList(AssetManager assetManager) - throws IOException { - List<String> wallpaperList = new ArrayList<String>(); - String[] assets = assetManager.list(WALLPAPER_PATH); - for (String asset : assets) { - if (!TextUtils.isEmpty(asset)) { - wallpaperList.add(WALLPAPER_PATH + File.separator + asset); - } - } - return wallpaperList; - } - - // Returns the first non-empty asset name. Empty assets can occur if the APK is built - // with folders included as zip entries in the APK. Searching for files inside "folderName" via - // assetManager.list("folderName") can cause these entries to be included as empty strings. - private static String getFirstNonEmptyAsset(String[] assets) { - if (assets == null) return null; - String filename = null; - for(String asset : assets) { - if (!TextUtils.isEmpty(asset)) { - filename = asset; - break; - } - } - return filename; - } - - public static String getDefaultThemePackageName(Context context) { - final String defaultThemePkg = Settings.Secure.getString(context.getContentResolver(), - Settings.Secure.DEFAULT_THEME_PACKAGE); - if (!TextUtils.isEmpty(defaultThemePkg)) { - PackageManager pm = context.getPackageManager(); - try { - if (pm.getPackageInfo(defaultThemePkg, 0) != null) { - return defaultThemePkg; - } - } catch (PackageManager.NameNotFoundException e) { - // doesn't exist so system will be default - Log.w(TAG, "Default theme " + defaultThemePkg + " not found", e); - } - } - - return SYSTEM_DEFAULT; - } - - private static class ThemedUiContext extends ContextWrapper { - private Context mAppContext; - - public ThemedUiContext(Context context, Context appContext) { - super(context); - mAppContext = appContext; - } - - @Override - public Context getApplicationContext() { - return mAppContext; - } - - @Override - public String getPackageName() { - return mAppContext.getPackageName(); - } - } - - // Returns a mutable list of all theme components - public static List<String> getAllComponents() { - List<String> components = new ArrayList<String>(9); - components.add(ThemesColumns.MODIFIES_FONTS); - components.add(ThemesColumns.MODIFIES_LAUNCHER); - components.add(ThemesColumns.MODIFIES_ALARMS); - components.add(ThemesColumns.MODIFIES_BOOT_ANIM); - components.add(ThemesColumns.MODIFIES_ICONS); - components.add(ThemesColumns.MODIFIES_LOCKSCREEN); - components.add(ThemesColumns.MODIFIES_NOTIFICATIONS); - components.add(ThemesColumns.MODIFIES_OVERLAYS); - components.add(ThemesColumns.MODIFIES_RINGTONES); - components.add(ThemesColumns.MODIFIES_STATUS_BAR); - components.add(ThemesColumns.MODIFIES_NAVIGATION_BAR); - components.add(ThemesColumns.MODIFIES_LIVE_LOCK_SCREEN); - return components; - } - - /** - * Returns a mutable list of all the theme components supported by a given package - * NOTE: This queries the themes content provider. If there isn't a provider installed - * or if it is too early in the boot process this method will not work. - */ - public static List<String> getSupportedComponents(Context context, String pkgName) { - List<String> supportedComponents = new ArrayList<String>(); - - String selection = ThemesContract.ThemesColumns.PKG_NAME + "= ?"; - String[] selectionArgs = new String[]{ pkgName }; - Cursor c = context.getContentResolver().query(ThemesContract.ThemesColumns.CONTENT_URI, - null, selection, selectionArgs, null); - - if (c != null) { - if (c.moveToFirst()) { - List<String> allComponents = getAllComponents(); - for (String component : allComponents) { - int index = c.getColumnIndex(component); - if (c.getInt(index) == 1) { - supportedComponents.add(component); - } - } - } - c.close(); - } - return supportedComponents; - } - - /** - * Get the components from the default theme. If the default theme is not SYSTEM then any - * components that are not in the default theme will come from SYSTEM to create a complete - * component map. - * @param context - * @return - */ - public static Map<String, String> getDefaultComponents(Context context) { - String defaultThemePkg = getDefaultThemePackageName(context); - List<String> defaultComponents = null; - List<String> systemComponents = getSupportedComponents(context, SYSTEM_DEFAULT); - if (!SYSTEM_DEFAULT.equals(defaultThemePkg)) { - defaultComponents = getSupportedComponents(context, defaultThemePkg); - } - - Map<String, String> componentMap = new HashMap<String, String>(systemComponents.size()); - if (defaultComponents != null) { - for (String component : defaultComponents) { - componentMap.put(component, defaultThemePkg); - } - } - for (String component : systemComponents) { - if (!componentMap.containsKey(component)) { - componentMap.put(component, SYSTEM_DEFAULT); - } - } - - return componentMap; - } - - /** - * Takes an existing component map and adds any missing components from the default - * map of components. - * @param context - * @param componentMap An existing component map - */ - public static void completeComponentMap(Context context, - Map<String, String> componentMap) { - if (componentMap == null) return; - - Map<String, String> defaultComponents = getDefaultComponents(context); - for (String component : defaultComponents.keySet()) { - if (!componentMap.containsKey(component)) { - componentMap.put(component, defaultComponents.get(component)); - } - } - } - /** * Convenience method to determine if a theme component is a per app theme and not a standard * component. diff --git a/core/java/android/content/res/IThemeChangeListener.aidl b/core/java/android/content/res/IThemeChangeListener.aidl deleted file mode 100644 index a2e2abd..0000000 --- a/core/java/android/content/res/IThemeChangeListener.aidl +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 android.content.res; - -/** {@hide} */ -oneway interface IThemeChangeListener { - void onProgress(int progress); - void onFinish(boolean isSuccess); -} diff --git a/core/java/android/content/res/IThemeProcessingListener.aidl b/core/java/android/content/res/IThemeProcessingListener.aidl deleted file mode 100644 index 2e1c16e..0000000 --- a/core/java/android/content/res/IThemeProcessingListener.aidl +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 android.content.res; - -/** {@hide} */ -oneway interface IThemeProcessingListener { - void onFinishedProcessing(String pkgName); -} diff --git a/core/java/android/content/res/IThemeService.aidl b/core/java/android/content/res/IThemeService.aidl deleted file mode 100644 index 90cb9fb..0000000 --- a/core/java/android/content/res/IThemeService.aidl +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 android.content.res; - -import android.content.res.IThemeChangeListener; -import android.content.res.IThemeProcessingListener; -import android.content.res.ThemeChangeRequest; -import android.graphics.Bitmap; - -import java.util.Map; - -/** {@hide} */ -interface IThemeService { - void requestThemeChangeUpdates(in IThemeChangeListener listener); - void removeUpdates(in IThemeChangeListener listener); - - void requestThemeChange(in ThemeChangeRequest request, boolean removePerAppThemes); - void applyDefaultTheme(); - boolean isThemeApplying(); - int getProgress(); - - boolean cacheComposedIcon(in Bitmap icon, String path); - - boolean processThemeResources(String themePkgName); - boolean isThemeBeingProcessed(String themePkgName); - void registerThemeProcessingListener(in IThemeProcessingListener listener); - void unregisterThemeProcessingListener(in IThemeProcessingListener listener); - - void rebuildResourceCache(); -} diff --git a/core/java/android/content/res/ThemeChangeRequest.aidl b/core/java/android/content/res/ThemeChangeRequest.aidl deleted file mode 100644 index e6cf115..0000000 --- a/core/java/android/content/res/ThemeChangeRequest.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2015 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 android.content.res; - -/** @hide */ -parcelable ThemeChangeRequest; diff --git a/core/java/android/content/res/ThemeChangeRequest.java b/core/java/android/content/res/ThemeChangeRequest.java deleted file mode 100644 index 1d13bb0..0000000 --- a/core/java/android/content/res/ThemeChangeRequest.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (C) 2015 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 android.content.res; - -import android.content.pm.ThemeUtils; -import android.os.Parcel; -import android.os.Parcelable; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - - -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); - } - - public String getStatusBarThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_STATUS_BAR); - } - - public String getNavBarThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_NAVIGATION_BAR); - } - - public String getFontThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_FONTS); - } - - public String getIconsThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_ICONS); - } - - public String getBootanimationThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_BOOT_ANIM); - } - - public String getWallpaperThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_LAUNCHER); - } - - public String getLockWallpaperThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_LOCKSCREEN); - } - - public String getAlarmThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_ALARMS); - } - - public String getNotificationThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_NOTIFICATIONS); - } - - public String getRingtoneThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_RINGTONES); - } - - public String getLiveLockScreenThemePackageName() { - return getThemePackageNameForComponent(MODIFIES_LIVE_LOCK_SCREEN); - } - - public final Map<String, String> getThemeComponentsMap() { - 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. - */ - public final Map<String, String> getPerAppOverlays() { - return Collections.unmodifiableMap(mPerAppOverlays); - } - - public int getNumChangesRequested() { - return mThemeComponents.size() + mPerAppOverlays.size(); - } - - public RequestType getReqeustType() { - return mRequestType; - } - - private String getThemePackageNameForComponent(String componentName) { - return mThemeComponents.get(componentName); - } - - private ThemeChangeRequest(Map<String, String> components, Map<String, String> perAppThemes, - RequestType requestType, long wallpaperId) { - if (components != null) { - mThemeComponents.putAll(components); - } - if (perAppThemes != null) { - mPerAppOverlays.putAll(perAppThemes); - } - mRequestType = requestType; - mWallpaperId = wallpaperId; - } - - private ThemeChangeRequest(Parcel source) { - int numComponents = source.readInt(); - for (int i = 0; i < numComponents; i++) { - mThemeComponents.put(source.readString(), source.readString()); - } - - numComponents = source.readInt(); - for (int i = 0 ; i < numComponents; i++) { - mPerAppOverlays.put(source.readString(), source.readString()); - } - mRequestType = RequestType.values()[source.readInt()]; - mWallpaperId = source.readLong(); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(mThemeComponents.size()); - for (String component : mThemeComponents.keySet()) { - dest.writeString(component); - dest.writeString(mThemeComponents.get(component)); - } - dest.writeInt((mPerAppOverlays.size())); - for (String appPkgName : mPerAppOverlays.keySet()) { - dest.writeString(appPkgName); - dest.writeString(mPerAppOverlays.get(appPkgName)); - } - dest.writeInt(mRequestType.ordinal()); - dest.writeLong(mWallpaperId); - } - - public static final Parcelable.Creator<ThemeChangeRequest> CREATOR = - new Parcelable.Creator<ThemeChangeRequest>() { - @Override - public ThemeChangeRequest createFromParcel(Parcel source) { - return new ThemeChangeRequest(source); - } - - @Override - public ThemeChangeRequest[] newArray(int size) { - return new ThemeChangeRequest[size]; - } - }; - - public enum RequestType { - USER_REQUEST, - USER_REQUEST_MIXNMATCH, - THEME_UPDATED, - THEME_REMOVED, - THEME_RESET; - } - - public static class Builder { - 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() {} - - public Builder(ThemeConfig themeConfig) { - if (themeConfig != null) { - buildChangeRequestFromThemeConfig(themeConfig); - } - } - - public Builder setOverlay(String pkgName) { - return setComponent(MODIFIES_OVERLAYS, pkgName); - } - - public Builder setStatusBar(String pkgName) { - return setComponent(MODIFIES_STATUS_BAR, pkgName); - } - - public Builder setNavBar(String pkgName) { - return setComponent(MODIFIES_NAVIGATION_BAR, pkgName); - } - - public Builder setFont(String pkgName) { - return setComponent(MODIFIES_FONTS, pkgName); - } - - public Builder setIcons(String pkgName) { - return setComponent(MODIFIES_ICONS, pkgName); - } - - public Builder setBootanimation(String pkgName) { - return setComponent(MODIFIES_BOOT_ANIM, pkgName); - } - - public Builder setWallpaper(String pkgName) { - 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); - } - - public Builder setAlarm(String pkgName) { - return setComponent(MODIFIES_ALARMS, pkgName); - } - - public Builder setNotification(String pkgName) { - return setComponent(MODIFIES_NOTIFICATIONS, pkgName); - } - - public Builder setRingtone(String pkgName) { - return setComponent(MODIFIES_RINGTONES, pkgName); - } - - public Builder setLiveLockScreen(String pkgName) { - return setComponent(MODIFIES_LIVE_LOCK_SCREEN, pkgName); - } - - public Builder setComponent(String component, String pkgName) { - if (pkgName != null) { - mThemeComponents.put(component, pkgName); - } else { - mThemeComponents.remove(component); - } - return this; - } - - public Builder setAppOverlay(String appPkgName, String themePkgName) { - if (appPkgName != null) { - if (themePkgName != null) { - mPerAppOverlays.put(appPkgName, themePkgName); - } else { - mPerAppOverlays.remove(appPkgName); - } - } - - return this; - } - - public Builder setRequestType(RequestType requestType) { - mRequestType = requestType != null ? requestType : RequestType.USER_REQUEST; - return this; - } - - public ThemeChangeRequest build() { - return new ThemeChangeRequest(mThemeComponents, mPerAppOverlays, - mRequestType, mWallpaperId); - } - - private void buildChangeRequestFromThemeConfig(ThemeConfig themeConfig) { - if (themeConfig.getFontPkgName() != null) { - this.setFont(themeConfig.getFontPkgName()); - } - if (themeConfig.getIconPackPkgName() != null) { - this.setIcons(themeConfig.getIconPackPkgName()); - } - if (themeConfig.getOverlayPkgName() != null) { - this.setOverlay(themeConfig.getOverlayPkgName()); - } - if (themeConfig.getOverlayForStatusBar() != null) { - this.setStatusBar(themeConfig.getOverlayForStatusBar()); - } - if (themeConfig.getOverlayForNavBar() != null) { - this.setNavBar(themeConfig.getOverlayForNavBar()); - } - - // Check if there are any per-app overlays using this theme - final Map<String, ThemeConfig.AppTheme> themes = themeConfig.getAppThemes(); - for (String appPkgName : themes.keySet()) { - if (ThemeUtils.isPerAppThemeComponent(appPkgName)) { - this.setAppOverlay(appPkgName, themes.get(appPkgName).getOverlayPkgName()); - } - } - } - } -} diff --git a/core/java/android/content/res/ThemeConfig.java b/core/java/android/content/res/ThemeConfig.java index ac95d6b..f304801 100644 --- a/core/java/android/content/res/ThemeConfig.java +++ b/core/java/android/content/res/ThemeConfig.java @@ -1,12 +1,12 @@ /* - * Copyright (C) 2014 The CyanogenMod Project + * Copyright (C) 2016 The CyanogenMod Project * Portions copyright (C) 2014, T-Mobile USA, Inc. * * 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 + * 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, @@ -17,12 +17,13 @@ package android.content.res; import android.content.ContentResolver; -import android.content.res.ThemeChangeRequest.RequestType; import android.os.Parcel; import android.os.Parcelable; import android.os.UserHandle; import android.provider.Settings; import android.text.TextUtils; +import android.util.ArrayMap; +import android.util.ArraySet; import android.util.JsonReader; import android.util.JsonToken; import android.util.JsonWriter; @@ -34,8 +35,6 @@ import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; import java.util.Map; /** @@ -61,9 +60,7 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi private static final SystemAppTheme mSystemAppTheme = new SystemAppTheme(); // Maps pkgname to theme (ex com.angry.birds -> red theme) - protected final Map<String, AppTheme> mThemes = new HashMap<String, AppTheme>(); - - private RequestType mLastThemeChangeRequestType = RequestType.USER_REQUEST; + protected final Map<String, AppTheme> mThemes = new ArrayMap<>(); public ThemeConfig(Map<String, AppTheme> appThemes) { mThemes.putAll(appThemes); @@ -111,10 +108,6 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi return Collections.unmodifiableMap(mThemes); } - public RequestType getLastThemeChangeRequestType() { - return mLastThemeChangeRequestType; - } - private AppTheme getThemeFor(String pkgName) { AppTheme theme = mThemes.get(pkgName); if (theme == null) theme = getDefaultTheme(); @@ -136,12 +129,11 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi ThemeConfig o = (ThemeConfig) object; Map<String, AppTheme> currThemes = (mThemes == null) ? - new HashMap<String, AppTheme>() : mThemes; + new ArrayMap<String, AppTheme>() : mThemes; Map<String, AppTheme> newThemes = (o.mThemes == null) ? - new HashMap<String, AppTheme>() : o.mThemes; + new ArrayMap<String, AppTheme>() : o.mThemes; - return (currThemes.equals(newThemes) && - mLastThemeChangeRequestType == o.mLastThemeChangeRequestType); + return currThemes.equals(newThemes); } return false; } @@ -160,8 +152,6 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi public int hashCode() { int hash = 17; hash = 31 * hash + mThemes.hashCode(); - hash = 31 * hash + (mLastThemeChangeRequestType == null ? 0 : - mLastThemeChangeRequestType.ordinal()); return hash; } @@ -227,7 +217,6 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi public void writeToParcel(Parcel dest, int flags) { String json = JsonSerializer.toJson(this); dest.writeString(json); - dest.writeInt(mLastThemeChangeRequestType.ordinal()); } public static final Parcelable.Creator<ThemeConfig> CREATOR = @@ -235,7 +224,6 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi public ThemeConfig createFromParcel(Parcel source) { String json = source.readString(); ThemeConfig themeConfig = JsonSerializer.fromJson(json); - themeConfig.mLastThemeChangeRequestType = RequestType.values()[source.readInt()]; return themeConfig; } @@ -351,10 +339,9 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi public static class Builder { - private HashMap<String, String> mOverlays = new HashMap<String, String>(); - private HashMap<String, String> mIcons = new HashMap<String, String>(); - private HashMap<String, String> mFonts = new HashMap<String, String>(); - private RequestType mLastThemeChangeRequestType = RequestType.USER_REQUEST; + private Map<String, String> mOverlays = new ArrayMap<>(); + private Map<String, String> mIcons = new ArrayMap<>(); + private Map<String, String> mFonts = new ArrayMap<>(); public Builder() {} @@ -366,7 +353,6 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi mIcons.put(key, appTheme.getIconPackPkgName()); mOverlays.put(key, appTheme.getOverlayPkgName()); } - mLastThemeChangeRequestType = theme.mLastThemeChangeRequestType; } /** @@ -427,18 +413,13 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi return this; } - public Builder setLastThemeChangeRequestType(RequestType requestType) { - mLastThemeChangeRequestType = requestType; - return this; - } - public ThemeConfig build() { - HashSet<String> appPkgSet = new HashSet<String>(); + ArraySet<String> appPkgSet = new ArraySet<>(); appPkgSet.addAll(mOverlays.keySet()); appPkgSet.addAll(mIcons.keySet()); appPkgSet.addAll(mFonts.keySet()); - HashMap<String, AppTheme> appThemes = new HashMap<String, AppTheme>(); + Map<String, AppTheme> appThemes = new ArrayMap<>(); for(String appPkgName : appPkgSet) { String icon = mIcons.get(appPkgName); String overlay = mOverlays.get(appPkgName); @@ -455,7 +436,6 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi } } ThemeConfig themeConfig = new ThemeConfig(appThemes); - themeConfig.mLastThemeChangeRequestType = mLastThemeChangeRequestType; return themeConfig; } } @@ -506,7 +486,7 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi public static ThemeConfig fromJson(String json) { if (json == null) return null; - HashMap<String, AppTheme> map = new HashMap<String, AppTheme>(); + Map<String, AppTheme> map = new ArrayMap<>(); StringReader reader = null; JsonReader jsonReader = null; try { @@ -582,7 +562,7 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi public static class SystemConfig extends ThemeConfig { public SystemConfig() { - super(new HashMap<String, AppTheme>()); + super(new ArrayMap<String, AppTheme>()); } } @@ -593,7 +573,7 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi @Override public String toString() { - return "No Theme Applied (Holo)"; + return "No Theme Applied (System)"; } } } diff --git a/core/java/android/content/res/ThemeManager.java b/core/java/android/content/res/ThemeManager.java deleted file mode 100644 index fd05f1e..0000000 --- a/core/java/android/content/res/ThemeManager.java +++ /dev/null @@ -1,316 +0,0 @@ -/* - * 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 android.content.res; - -import android.content.Context; -import android.content.pm.ThemeUtils; -import android.os.Handler; -import android.os.Looper; -import android.os.RemoteException; -import android.util.Log; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * {@hide} - */ -public class ThemeManager { - private static final String TAG = ThemeManager.class.getName(); - private Context mContext; - private IThemeService mService; - private Handler mHandler; - - private Set<ThemeChangeListener> mChangeListeners = - new HashSet<ThemeChangeListener>(); - - private Set<ThemeProcessingListener> mProcessingListeners = - new HashSet<ThemeProcessingListener>(); - - public ThemeManager(Context context, IThemeService service) { - mContext = context; - mService = service; - mHandler = new Handler(Looper.getMainLooper()); - } - - private final IThemeChangeListener mThemeChangeListener = new IThemeChangeListener.Stub() { - @Override - public void onProgress(final int progress) throws RemoteException { - mHandler.post(new Runnable() { - @Override - public void run() { - synchronized (mChangeListeners) { - List<ThemeChangeListener> listenersToRemove = new ArrayList - <ThemeChangeListener>(); - for (ThemeChangeListener listener : mChangeListeners) { - try { - listener.onProgress(progress); - } catch (Throwable e) { - Log.w(TAG, "Unable to update theme change progress", e); - listenersToRemove.add(listener); - } - } - if (listenersToRemove.size() > 0) { - for (ThemeChangeListener listener : listenersToRemove) { - mChangeListeners.remove(listener); - } - } - } - } - }); - } - - @Override - public void onFinish(final boolean isSuccess) throws RemoteException { - mHandler.post(new Runnable() { - @Override - public void run() { - synchronized (mChangeListeners) { - List<ThemeChangeListener> listenersToRemove = new ArrayList - <ThemeChangeListener>(); - for (ThemeChangeListener listener : mChangeListeners) { - try { - listener.onFinish(isSuccess); - } catch (Throwable e) { - Log.w(TAG, "Unable to update theme change listener", e); - listenersToRemove.add(listener); - } - } - if (listenersToRemove.size() > 0) { - for (ThemeChangeListener listener : listenersToRemove) { - mChangeListeners.remove(listener); - } - } - } - } - }); - } - }; - - private final IThemeProcessingListener mThemeProcessingListener = - new IThemeProcessingListener.Stub() { - @Override - public void onFinishedProcessing(final String pkgName) throws RemoteException { - mHandler.post(new Runnable() { - @Override - public void run() { - synchronized (mProcessingListeners) { - List<ThemeProcessingListener> listenersToRemove = new ArrayList - <ThemeProcessingListener>(); - for (ThemeProcessingListener listener : mProcessingListeners) { - try { - listener.onFinishedProcessing(pkgName); - } catch (Throwable e) { - Log.w(TAG, "Unable to update theme change progress", e); - listenersToRemove.add(listener); - } - } - if (listenersToRemove.size() > 0) { - for (ThemeProcessingListener listener : listenersToRemove) { - mProcessingListeners.remove(listener); - } - } - } - } - }); - } - }; - - - public void addClient(ThemeChangeListener listener) { - synchronized (mChangeListeners) { - if (mChangeListeners.contains(listener)) { - throw new IllegalArgumentException("Client was already added "); - } - if (mChangeListeners.size() == 0) { - try { - mService.requestThemeChangeUpdates(mThemeChangeListener); - } catch (RemoteException e) { - Log.w(TAG, "Unable to register listener", e); - } - } - mChangeListeners.add(listener); - } - } - - public void removeClient(ThemeChangeListener listener) { - synchronized (mChangeListeners) { - mChangeListeners.remove(listener); - if (mChangeListeners.size() == 0) { - try { - mService.removeUpdates(mThemeChangeListener); - } catch (RemoteException e) { - Log.w(TAG, "Unable to remove listener", e); - } - } - } - } - - public void onClientPaused(ThemeChangeListener listener) { - removeClient(listener); - } - - public void onClientResumed(ThemeChangeListener listener) { - addClient(listener); - } - - public void onClientDestroyed(ThemeChangeListener listener) { - removeClient(listener); - } - - /** - * Register a ThemeProcessingListener to be notified when a theme is done being processed. - * @param listener ThemeChangeListener to register - */ - public void registerProcessingListener(ThemeProcessingListener listener) { - synchronized (mProcessingListeners) { - if (mProcessingListeners.contains(listener)) { - throw new IllegalArgumentException("Listener was already added "); - } - if (mProcessingListeners.size() == 0) { - try { - mService.registerThemeProcessingListener(mThemeProcessingListener); - } catch (RemoteException e) { - Log.w(TAG, "Unable to register listener", e); - } - } - mProcessingListeners.add(listener); - } - } - - /** - * Unregister a ThemeChangeListener. - * @param listener ThemeChangeListener to unregister - */ - public void unregisterProcessingListener(ThemeChangeListener listener) { - synchronized (mProcessingListeners) { - mProcessingListeners.remove(listener); - if (mProcessingListeners.size() == 0) { - try { - mService.unregisterThemeProcessingListener(mThemeProcessingListener); - } catch (RemoteException e) { - Log.w(TAG, "Unable to remove listener", e); - } - } - } - } - - /** - * Convenience method. Applies the entire theme. - */ - public void requestThemeChange(String pkgName) { - //List<String> components = ThemeUtils.getSupportedComponents(mContext, pkgName); - //requestThemeChange(pkgName, components); - } - - public void requestThemeChange(String pkgName, List<String> components) { - requestThemeChange(pkgName, components, true); - } - - public void requestThemeChange(String pkgName, List<String> components, - boolean removePerAppThemes) { - Map<String, String> componentMap = new HashMap<String, String>(components.size()); - for (String component : components) { - componentMap.put(component, pkgName); - } - requestThemeChange(componentMap, removePerAppThemes); - } - - public void requestThemeChange(Map<String, String> componentMap) { - requestThemeChange(componentMap, true); - } - - public void requestThemeChange(Map<String, String> componentMap, boolean removePerAppThemes) { - ThemeChangeRequest.Builder builder = new ThemeChangeRequest.Builder(); - for (String component : componentMap.keySet()) { - builder.setComponent(component, componentMap.get(component)); - } - - requestThemeChange(builder.build(), removePerAppThemes); - } - - public void requestThemeChange(ThemeChangeRequest request, boolean removePerAppThemes) { - try { - mService.requestThemeChange(request, removePerAppThemes); - } catch (RemoteException e) { - logThemeServiceException(e); - } - } - - public void applyDefaultTheme() { - try { - mService.applyDefaultTheme(); - } catch (RemoteException e) { - logThemeServiceException(e); - } - } - - public boolean isThemeApplying() { - try { - return mService.isThemeApplying(); - } catch (RemoteException e) { - logThemeServiceException(e); - } - - return false; - } - - public boolean isThemeBeingProcessed(String themePkgName) { - try { - return mService.isThemeBeingProcessed(themePkgName); - } catch (RemoteException e) { - logThemeServiceException(e); - } - return false; - } - - public int getProgress() { - try { - return mService.getProgress(); - } catch (RemoteException e) { - logThemeServiceException(e); - } - return -1; - } - - public boolean processThemeResources(String themePkgName) { - try { - return mService.processThemeResources(themePkgName); - } catch (RemoteException e) { - logThemeServiceException(e); - } - return false; - } - - private void logThemeServiceException(Exception e) { - Log.w(TAG, "Unable to access ThemeService", e); - } - - public interface ThemeChangeListener { - void onProgress(int progress); - void onFinish(boolean isSuccess); - } - - public interface ThemeProcessingListener { - void onFinishedProcessing(String pkgName); - } -} - diff --git a/core/java/android/provider/ThemesContract.java b/core/java/android/provider/ThemesContract.java deleted file mode 100644 index af7ab26..0000000 --- a/core/java/android/provider/ThemesContract.java +++ /dev/null @@ -1,731 +0,0 @@ -package android.provider; - -import android.net.Uri; - -/** - * @hide - */ -public class ThemesContract { - public static final String AUTHORITY = "com.cyanogenmod.themes"; - public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY); - - public static class ThemesColumns { - public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "themes"); - - /** - * The unique ID for a row. - * <P>Type: INTEGER (long)</P> - */ - public static final String _ID = "_id"; - - /** - * The user visible title. - * <P>Type: TEXT</P> - */ - public static final String TITLE = "title"; - - /** - * Unique text to identify the apk pkg. ie "com.foo.bar" - * <P>Type: TEXT</P> - */ - public static final String PKG_NAME = "pkg_name"; - - /** - * A 32 bit RRGGBB color representative of the themes color scheme - * <P>Type: INTEGER</P> - */ - public static final String PRIMARY_COLOR = "primary_color"; - - /** - * A 2nd 32 bit RRGGBB color representative of the themes color scheme - * <P>Type: INTEGER</P> - */ - public static final String SECONDARY_COLOR = "secondary_color"; - - /** - * Name of the author of the theme - * <P>Type: TEXT</P> - */ - public static final String AUTHOR = "author"; - - /** - * The time that this row was created on its originating client (msecs - * since the epoch). - * <P>Type: INTEGER</P> - */ - public static final String DATE_CREATED = "created"; - - /** - * URI to an image that shows the homescreen with the theme applied - * since the epoch). - * <P>Type: TEXT</P> - */ - public static final String HOMESCREEN_URI = "homescreen_uri"; - - /** - * URI to an image that shows the lockscreen with theme applied - * <P>Type: TEXT</P> - */ - public static final String LOCKSCREEN_URI = "lockscreen_uri"; - - /** - * URI to an image that shows the style (aka skin) with theme applied - * <P>Type: TEXT</P> - */ - public static final String STYLE_URI = "style_uri"; - - /** - * TODO: Figure structure for actual animation instead of static - * URI to an image of the boot_anim. - * <P>Type: TEXT</P> - */ - public static final String BOOT_ANIM_URI = "bootanim_uri"; - - /** - * URI to an image of the status bar for this theme. - * <P>Type: TEXT</P> - */ - public static final String STATUSBAR_URI = "status_uri"; - - /** - * URI to an image of the fonts in this theme. - * <P>Type: TEXT</P> - */ - public static final String FONT_URI = "font_uri"; - - /** - * URI to an image of the fonts in this theme. - * <P>Type: TEXT</P> - */ - public static final String ICON_URI = "icon_uri"; - - /** - * URI to an image of the fonts in this theme. - * <P>Type: TEXT</P> - */ - public static final String OVERLAYS_URI = "overlays_uri"; - - /** - * 1 if theme modifies the launcher/homescreen else 0 - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String MODIFIES_LAUNCHER = "mods_homescreen"; - - /** - * 1 if theme modifies the lockscreen else 0 - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String MODIFIES_LOCKSCREEN = "mods_lockscreen"; - - /** - * 1 if theme modifies icons else 0 - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String MODIFIES_ICONS = "mods_icons"; - - /** - * 1 if theme modifies fonts - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String MODIFIES_FONTS = "mods_fonts"; - - /** - * 1 if theme modifies boot animation - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String MODIFIES_BOOT_ANIM = "mods_bootanim"; - - /** - * 1 if theme modifies notifications - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String MODIFIES_NOTIFICATIONS = "mods_notifications"; - - /** - * 1 if theme modifies alarm sounds - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String MODIFIES_ALARMS = "mods_alarms"; - - /** - * 1 if theme modifies ringtones - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String MODIFIES_RINGTONES = "mods_ringtones"; - - /** - * 1 if theme has overlays - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String MODIFIES_OVERLAYS = "mods_overlays"; - - /** - * 1 if theme has an overlay for SystemUI/StatusBar - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String MODIFIES_STATUS_BAR = "mods_status_bar"; - - /** - * 1 if theme has an overlay for SystemUI/NavBar - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String MODIFIES_NAVIGATION_BAR = "mods_navigation_bar"; - - /** - * 1 if theme has a live lock screen - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String MODIFIES_LIVE_LOCK_SCREEN = "mods_live_lock_screen"; - - /** - * URI to the theme's wallpaper. We should support multiple wallpaper - * but for now we will just have 1. - * <P>Type: TEXT</P> - */ - public static final String WALLPAPER_URI = "wallpaper_uri"; - - /** - * 1 if this row should actually be presented as a theme to the user. - * For example if a "theme" only modifies one component (ex icons) then - * we do not present it to the user under the themes table. - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String PRESENT_AS_THEME = "present_as_theme"; - - /** - * 1 if this theme is a legacy theme. - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String IS_LEGACY_THEME = "is_legacy_theme"; - - /** - * 1 if this theme is the system default theme. - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String IS_DEFAULT_THEME = "is_default_theme"; - - /** - * 1 if this theme is a legacy iconpack. A legacy icon pack is an APK that was written - * for Trebuchet or a 3rd party launcher. - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String IS_LEGACY_ICONPACK = "is_legacy_iconpack"; - - /** - * install/update time in millisecs. When the row is inserted this column - * is populated by the PackageInfo. It is used for syncing to PM - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String LAST_UPDATE_TIME = "updateTime"; - - /** - * install time in millisecs. When the row is inserted this column - * is populated by the PackageInfo. - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String INSTALL_TIME = "install_time"; - - /** - * The target API this theme supports - * is populated by the PackageInfo. - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String TARGET_API = "target_api"; - - /** - * The install state of the theme. - * Can be one of the following: - * {@link InstallState#UNKNOWN} - * {@link InstallState#INSTALLING} - * {@link InstallState#UPDATING} - * {@link InstallState#INSTALLED} - * <P>Type: INTEGER</P> - * <P>Default: 0</P> - */ - public static final String INSTALL_STATE = "install_state"; - - public static class InstallState { - public static final int UNKNOWN = 0; - public static final int INSTALLING = 1; - public static final int UPDATING = 2; - public static final int INSTALLED = 3; - } - } - - /** - * Key-value table which assigns a component (ex wallpaper) to a theme's package - */ - public static class MixnMatchColumns { - public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "mixnmatch"); - - /** - * The unique key for a row. See the KEY_* constants - * for valid examples - * <P>Type: TEXT</P> - */ - public static final String COL_KEY = "key"; - - /** - * The package name that corresponds to a given component. - * <P>Type: String</P> - */ - public static final String COL_VALUE = "value"; - - /** - * The package name that corresponds to where this component was applied from previously - * <P>Type: String</P> - */ - public static final String COL_PREV_VALUE = "previous_value"; - - /** - * Time when this entry was last updated - * <P>Type: INTEGER</P> - */ - 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 - */ - public static final String KEY_HOMESCREEN = "mixnmatch_homescreen"; - public static final String KEY_LOCKSCREEN = "mixnmatch_lockscreen"; - public static final String KEY_ICONS = "mixnmatch_icons"; - public static final String KEY_STATUS_BAR = "mixnmatch_status_bar"; - public static final String KEY_BOOT_ANIM = "mixnmatch_boot_anim"; - public static final String KEY_FONT = "mixnmatch_font"; - public static final String KEY_ALARM = "mixnmatch_alarm"; - public static final String KEY_NOTIFICATIONS = "mixnmatch_notifications"; - public static final String KEY_RINGTONE = "mixnmatch_ringtone"; - public static final String KEY_OVERLAYS = "mixnmatch_overlays"; - public static final String KEY_NAVIGATION_BAR = "mixnmatch_navigation_bar"; - public static final String KEY_LIVE_LOCK_SCREEN = "mixnmatch_live_lock_screen"; - - public static final String[] ROWS = { KEY_HOMESCREEN, - KEY_LOCKSCREEN, - KEY_ICONS, - KEY_STATUS_BAR, - KEY_BOOT_ANIM, - KEY_FONT, - KEY_NOTIFICATIONS, - KEY_RINGTONE, - KEY_ALARM, - KEY_OVERLAYS, - KEY_NAVIGATION_BAR, - KEY_LIVE_LOCK_SCREEN - }; - - /** - * For a given key value in the MixNMatch table, return the column - * associated with it in the Themes Table. This is useful for URI based - * elements like wallpaper where the caller wishes to determine the - * wallpaper URI. - */ - public static String componentToImageColName(String component) { - if (component.equals(MixnMatchColumns.KEY_HOMESCREEN)) { - return ThemesColumns.HOMESCREEN_URI; - } else if (component.equals(MixnMatchColumns.KEY_LOCKSCREEN)) { - return ThemesColumns.LOCKSCREEN_URI; - } else if (component.equals(MixnMatchColumns.KEY_BOOT_ANIM)) { - return ThemesColumns.BOOT_ANIM_URI; - } else if (component.equals(MixnMatchColumns.KEY_FONT)) { - return ThemesColumns.FONT_URI; - } else if (component.equals(MixnMatchColumns.KEY_ICONS)) { - return ThemesColumns.ICON_URI; - } else if (component.equals(MixnMatchColumns.KEY_STATUS_BAR)) { - return ThemesColumns.STATUSBAR_URI; - } else if (component.equals(MixnMatchColumns.KEY_NOTIFICATIONS)) { - throw new IllegalArgumentException("Notifications mixnmatch component does not have a related column"); - } else if (component.equals(MixnMatchColumns.KEY_RINGTONE)) { - throw new IllegalArgumentException("Ringtone mixnmatch component does not have a related column"); - } else if (component.equals(MixnMatchColumns.KEY_OVERLAYS)) { - return ThemesColumns.OVERLAYS_URI; - } else if (component.equals(MixnMatchColumns.KEY_STATUS_BAR)) { - throw new IllegalArgumentException( - "Status bar mixnmatch component does not have a related column"); - } else if (component.equals(MixnMatchColumns.KEY_NAVIGATION_BAR)) { - throw new IllegalArgumentException( - "Navigation bar mixnmatch component does not have a related column"); - } else if (component.equals(MixnMatchColumns.KEY_LIVE_LOCK_SCREEN)) { - throw new IllegalArgumentException( - "Live lock screen mixnmatch component does not have a related column"); - } - return null; - } - - /** - * A component in the themes table (IE "mods_wallpaper") has an - * equivalent key in mixnmatch table - */ - public static String componentToMixNMatchKey(String component) { - if (component.equals(ThemesColumns.MODIFIES_LAUNCHER)) { - return MixnMatchColumns.KEY_HOMESCREEN; - } else if (component.equals(ThemesColumns.MODIFIES_ICONS)) { - return MixnMatchColumns.KEY_ICONS; - } else if (component.equals(ThemesColumns.MODIFIES_LOCKSCREEN)) { - return MixnMatchColumns.KEY_LOCKSCREEN; - } else if (component.equals(ThemesColumns.MODIFIES_FONTS)) { - return MixnMatchColumns.KEY_FONT; - } else if (component.equals(ThemesColumns.MODIFIES_BOOT_ANIM)) { - return MixnMatchColumns.KEY_BOOT_ANIM; - } else if (component.equals(ThemesColumns.MODIFIES_ALARMS)) { - return MixnMatchColumns.KEY_ALARM; - } else if (component.equals(ThemesColumns.MODIFIES_NOTIFICATIONS)) { - return MixnMatchColumns.KEY_NOTIFICATIONS; - } else if (component.equals(ThemesColumns.MODIFIES_RINGTONES)) { - return MixnMatchColumns.KEY_RINGTONE; - } else if (component.equals(ThemesColumns.MODIFIES_OVERLAYS)) { - return MixnMatchColumns.KEY_OVERLAYS; - } else if (component.equals(ThemesColumns.MODIFIES_STATUS_BAR)) { - return MixnMatchColumns.KEY_STATUS_BAR; - } else if (component.equals(ThemesColumns.MODIFIES_NAVIGATION_BAR)) { - return MixnMatchColumns.KEY_NAVIGATION_BAR; - } else if (component.equals(ThemesColumns.MODIFIES_LIVE_LOCK_SCREEN)) { - return MixnMatchColumns.KEY_LIVE_LOCK_SCREEN; - } - return null; - } - - /** - * A mixnmatch key in has an - * equivalent value in the themes table - */ - public static String mixNMatchKeyToComponent(String mixnmatchKey) { - if (mixnmatchKey.equals(MixnMatchColumns.KEY_HOMESCREEN)) { - return ThemesColumns.MODIFIES_LAUNCHER; - } else if (mixnmatchKey.equals(MixnMatchColumns.KEY_ICONS)) { - return ThemesColumns.MODIFIES_ICONS; - } else if (mixnmatchKey.equals(MixnMatchColumns.KEY_LOCKSCREEN)) { - return ThemesColumns.MODIFIES_LOCKSCREEN; - } else if (mixnmatchKey.equals(MixnMatchColumns.KEY_FONT)) { - return ThemesColumns.MODIFIES_FONTS; - } else if (mixnmatchKey.equals(MixnMatchColumns.KEY_BOOT_ANIM)) { - return ThemesColumns.MODIFIES_BOOT_ANIM; - } else if (mixnmatchKey.equals(MixnMatchColumns.KEY_ALARM)) { - return ThemesColumns.MODIFIES_ALARMS; - } else if (mixnmatchKey.equals(MixnMatchColumns.KEY_NOTIFICATIONS)) { - return ThemesColumns.MODIFIES_NOTIFICATIONS; - } else if (mixnmatchKey.equals(MixnMatchColumns.KEY_RINGTONE)) { - return ThemesColumns.MODIFIES_RINGTONES; - } else if (mixnmatchKey.equals(MixnMatchColumns.KEY_OVERLAYS)) { - return ThemesColumns.MODIFIES_OVERLAYS; - } else if (mixnmatchKey.equals(MixnMatchColumns.KEY_STATUS_BAR)) { - return ThemesColumns.MODIFIES_STATUS_BAR; - } else if (mixnmatchKey.equals(MixnMatchColumns.KEY_NAVIGATION_BAR)) { - return ThemesColumns.MODIFIES_NAVIGATION_BAR; - } else if (mixnmatchKey.equals(MixnMatchColumns.KEY_LIVE_LOCK_SCREEN)) { - return ThemesColumns.MODIFIES_LIVE_LOCK_SCREEN; - } - return null; - } - } - - /** - * Table containing cached preview files for a given theme - */ - public static class PreviewColumns { - /** - * Uri for retrieving the previews table. - * Querying the themes provider using this URI will return a cursor with a key and value - * columns, and a row for each component. - */ - public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "previews"); - - /** - * Uri for retrieving the previews for the currently applied components. - * Querying the themes provider using this URI will return a cursor with a single row - * containing all the previews for the components that are currently applied. - */ - public static final Uri APPLIED_URI = Uri.withAppendedPath(AUTHORITY_URI, - "applied_previews"); - - /** - * Uri for retrieving the default previews for the theme. - * Querying the themes provider using this URI will return a cursor with a single row - * containing all the previews for the default components of the current theme. - */ - public static final Uri COMPONENTS_URI = Uri.withAppendedPath(AUTHORITY_URI, - "components_previews"); - - /** - * The unique ID for a row. - * <P>Type: INTEGER (long)</P> - */ - public static final String _ID = "_id"; - - /** - * The unique ID for the theme these previews belong to. - * <P>Type: INTEGER (long)</P> - */ - public static final String THEME_ID = "theme_id"; - - /** - * The unique ID for the component within a theme. - * <P>Type: INTEGER (long)</P> - */ - public static final String COMPONENT_ID = "component_id"; - - /** - * The unique key for a row. See the Valid key constants section below - * for valid examples - * <P>Type: TEXT</P> - */ - public static final String COL_KEY = "key"; - - /** - * The package name that corresponds to a given component. - * <P>Type: String</P> - */ - public static final String COL_VALUE = "value"; - - /** - * Valid keys - */ - - /** - * Cached image of the themed status bar background. - * <P>Type: String (file path)</P> - */ - public static final String STATUSBAR_BACKGROUND = "statusbar_background"; - - /** - * Cached image of the themed bluetooth status icon. - * <P>Type: String (file path)</P> - */ - public static final String STATUSBAR_BLUETOOTH_ICON = "statusbar_bluetooth_icon"; - - /** - * Cached image of the themed wifi status icon. - * <P>Type: String (file path)</P> - */ - public static final String STATUSBAR_WIFI_ICON = "statusbar_wifi_icon"; - - /** - * Cached image of the themed cellular signal status icon. - * <P>Type: String (file path)</P> - */ - public static final String STATUSBAR_SIGNAL_ICON = "statusbar_signal_icon"; - - /** - * Cached image of the themed battery using portrait style. - * <P>Type: String (file path)</P> - */ - public static final String STATUSBAR_BATTERY_PORTRAIT = "statusbar_battery_portrait"; - - /** - * Cached image of the themed battery using landscape style. - * <P>Type: String (file path)</P> - */ - public static final String STATUSBAR_BATTERY_LANDSCAPE = "statusbar_battery_landscape"; - - /** - * Cached image of the themed battery using circle style. - * <P>Type: String (file path)</P> - */ - public static final String STATUSBAR_BATTERY_CIRCLE = "statusbar_battery_circle"; - - /** - * The themed color used for clock text in the status bar. - * <P>Type: INTEGER (int)</P> - */ - public static final String STATUSBAR_CLOCK_TEXT_COLOR = "statusbar_clock_text_color"; - - /** - * The themed margin value between the wifi and rssi signal icons. - * <P>Type: INTEGER (int)</P> - */ - public static final String STATUSBAR_WIFI_COMBO_MARGIN_END = "wifi_combo_margin_end"; - - /** - * Cached image of the themed navigation bar background. - * <P>Type: String (file path)</P> - */ - public static final String NAVBAR_BACKGROUND = "navbar_background"; - - /** - * Cached image of the themed back button. - * <P>Type: String (file path)</P> - */ - public static final String NAVBAR_BACK_BUTTON = "navbar_back_button"; - - /** - * Cached image of the themed home button. - * <P>Type: String (file path)</P> - */ - public static final String NAVBAR_HOME_BUTTON = "navbar_home_button"; - - /** - * Cached image of the themed recents button. - * <P>Type: String (file path)</P> - */ - public static final String NAVBAR_RECENT_BUTTON = "navbar_recent_button"; - - /** - * Cached image of the 1/3 icons - * <P>Type: String (file path)</P> - */ - public static final String ICON_PREVIEW_1 = "icon_preview_1"; - - /** - * Cached image of the 2/3 icons - * <P>Type: String (file path)</P> - */ - public static final String ICON_PREVIEW_2 = "icon_preview_2"; - - /** - * Cached image of the 3/3 icons - * <P>Type: String (file path)</P> - */ - public static final String ICON_PREVIEW_3 = "icon_preview_3"; - - /** - * Full path to the theme's wallpaper asset. - * <P>Type: String (file path)</P> - */ - public static final String WALLPAPER_FULL = "wallpaper_full"; - - /** - * Cached preview of the theme's wallpaper which is larger than the thumbnail - * but smaller than the full sized wallpaper. - * <P>Type: String (file path)</P> - */ - public static final String WALLPAPER_PREVIEW = "wallpaper_preview"; - - /** - * Cached thumbnail of the theme's wallpaper - * <P>Type: String (file path)</P> - */ - public static final String WALLPAPER_THUMBNAIL = "wallpaper_thumbnail"; - - /** - * Cached preview of the theme's lockscreen wallpaper which is larger than the thumbnail - * but smaller than the full sized lockscreen wallpaper. - * <P>Type: String (file path)</P> - */ - public static final String LOCK_WALLPAPER_PREVIEW = "lock_wallpaper_preview"; - - /** - * Cached thumbnail of the theme's lockscreen wallpaper - * <P>Type: String (file path)</P> - */ - public static final String LOCK_WALLPAPER_THUMBNAIL = "lock_wallpaper_thumbnail"; - - /** - * Cached preview of UI controls representing the theme's style - * <P>Type: String (file path)</P> - */ - public static final String STYLE_PREVIEW = "style_preview"; - - /** - * Cached thumbnail preview of UI controls representing the theme's style - * <P>Type: String (file path)</P> - */ - public static final String STYLE_THUMBNAIL = "style_thumbnail"; - - /** - * Cached thumbnail of the theme's boot animation - * <P>Type: String (file path)</P> - */ - public static final String BOOTANIMATION_THUMBNAIL = "bootanimation_thumbnail"; - - /** - * Cached preview of live lock screen - * <P>Type: String (file path)</P> - */ - public static final String LIVE_LOCK_SCREEN_PREVIEW = "live_lock_screen_preview"; - - /** - * Cached thumbnail preview of live lock screen - * <P>Type: String (file path)</P> - */ - public static final String LIVE_LOCK_SCREEN_THUMBNAIL = "live_lock_screen_thumbnail"; - - public static final String[] VALID_KEYS = { - STATUSBAR_BACKGROUND, - STATUSBAR_BLUETOOTH_ICON, - STATUSBAR_WIFI_ICON, - STATUSBAR_SIGNAL_ICON, - STATUSBAR_BATTERY_PORTRAIT, - STATUSBAR_BATTERY_LANDSCAPE, - STATUSBAR_BATTERY_CIRCLE, - STATUSBAR_CLOCK_TEXT_COLOR, - STATUSBAR_WIFI_COMBO_MARGIN_END, - NAVBAR_BACKGROUND, - NAVBAR_BACK_BUTTON, - NAVBAR_HOME_BUTTON, - NAVBAR_RECENT_BUTTON, - ICON_PREVIEW_1, - ICON_PREVIEW_2, - ICON_PREVIEW_3, - WALLPAPER_FULL, - WALLPAPER_PREVIEW, - WALLPAPER_THUMBNAIL, - LOCK_WALLPAPER_PREVIEW, - LOCK_WALLPAPER_THUMBNAIL, - STYLE_PREVIEW, - STYLE_THUMBNAIL, - BOOTANIMATION_THUMBNAIL, - LIVE_LOCK_SCREEN_PREVIEW, - LIVE_LOCK_SCREEN_THUMBNAIL, - }; - } - - public static class Intent { - /** - * Action sent from the provider when a theme has been fully installed. Fully installed - * means that the apk was installed by PackageManager and the theme resources were - * processed and cached by {@link com.android.server.ThemeService} - * Requires the {@link android.Manifest.permission#READ_THEMES} permission to receive - * this broadcast. - */ - public static final String ACTION_THEME_INSTALLED = - "themescontract.intent.action.THEME_INSTALLED"; - - /** - * Action sent from the provider when a theme has been updated. - * Requires the {@link android.Manifest.permission#READ_THEMES} permission to receive - * this broadcast. - */ - public static final String ACTION_THEME_UPDATED = - "themescontract.intent.action.THEME_UPDATED"; - - /** - * Action sent from the provider when a theme has been removed. - * Requires the {@link android.Manifest.permission#READ_THEMES} permission to receive - * this broadcast. - */ - public static final String ACTION_THEME_REMOVED = - "themescontract.intent.action.THEME_REMOVED"; - - /** - * Uri scheme used to broadcast the theme's package name when broadcasting - * {@link android.provider.ThemesContract.Intent#ACTION_THEME_INSTALLED} or - * {@link android.provider.ThemesContract.Intent#ACTION_THEME_REMOVED} - */ - public static final String URI_SCHEME_PACKAGE = "package"; - } -} |
