summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClark Scheff <clark@cyngn.com>2014-05-17 16:44:06 -0700
committerClark Scheff <clark@cyngn.com>2014-05-18 14:46:35 -0700
commit8ff5a8cd6aa1fe64a1f3ee63cade6ed8d8acc439 (patch)
tree022cf44e726f1f7b4a41c340262f1dfa236935b3 /src
parent3f39f20caad2f3579eecacc14ab93b44bcdeffed (diff)
downloadandroid_packages_providers_ThemesProvider-8ff5a8cd6aa1fe64a1f3ee63cade6ed8d8acc439.zip
android_packages_providers_ThemesProvider-8ff5a8cd6aa1fe64a1f3ee63cade6ed8d8acc439.tar.gz
android_packages_providers_ThemesProvider-8ff5a8cd6aa1fe64a1f3ee63cade6ed8d8acc439.tar.bz2
CM11 Themes: Allow defining a custom default theme [2/3]
Change-Id: I94521a09339fb760b7a56b9a3ba3d2c56e2d3ac5
Diffstat (limited to 'src')
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemePackageHelper.java9
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java52
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemesProvider.java33
3 files changed, 78 insertions, 16 deletions
diff --git a/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java b/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
index bc367e0..0ecdcaf 100644
--- a/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
+++ b/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
@@ -22,6 +22,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ThemeInfo;
+import android.content.pm.ThemeUtils;
import android.content.res.AssetManager;
import android.content.res.ThemeManager;
import android.database.Cursor;
@@ -90,6 +91,8 @@ public class ThemePackageHelper {
values.put(ThemesColumns.DATE_CREATED, System.currentTimeMillis());
values.put(ThemesColumns.PRESENT_AS_THEME, isPresentableTheme);
values.put(ThemesColumns.IS_LEGACY_THEME, pi.isLegacyThemeApk);
+ values.put(ThemesColumns.IS_DEFAULT_THEME,
+ ThemeUtils.getDefaultThemePackageName(context).equals(pi.packageName) ? 1 : 0);
values.put(ThemesColumns.LAST_UPDATE_TIME, pi.lastUpdateTime);
// Insert theme capabilities
@@ -112,6 +115,8 @@ public class ThemePackageHelper {
values.put(ThemesColumns.DATE_CREATED, System.currentTimeMillis());
values.put(ThemesColumns.PRESENT_AS_THEME, 1);
values.put(ThemesColumns.IS_LEGACY_THEME, pi.isLegacyThemeApk);
+ values.put(ThemesColumns.IS_DEFAULT_THEME,
+ ThemeUtils.getDefaultThemePackageName(context).equals(pi.packageName) ? 1 : 0);
values.put(ThemesColumns.LAST_UPDATE_TIME, pi.lastUpdateTime);
// Insert theme capabilities
@@ -172,6 +177,8 @@ public class ThemePackageHelper {
values.put(ThemesColumns.DATE_CREATED, System.currentTimeMillis());
values.put(ThemesColumns.PRESENT_AS_THEME, isPresentableTheme);
values.put(ThemesColumns.IS_LEGACY_THEME, pi.isLegacyThemeApk);
+ values.put(ThemesColumns.IS_DEFAULT_THEME,
+ ThemeUtils.getDefaultThemePackageName(context).equals(pi.packageName) ? 1 : 0);
values.put(ThemesColumns.LAST_UPDATE_TIME, pi.lastUpdateTime);
String where = ThemesColumns.PKG_NAME + "=?";
@@ -189,6 +196,8 @@ public class ThemePackageHelper {
values.put(ThemesColumns.DATE_CREATED, System.currentTimeMillis());
values.put(ThemesColumns.PRESENT_AS_THEME, 1);
values.put(ThemesColumns.IS_LEGACY_THEME, pi.isLegacyThemeApk);
+ values.put(ThemesColumns.IS_DEFAULT_THEME,
+ ThemeUtils.getDefaultThemePackageName(context).equals(pi.packageName) ? 1 : 0);
values.put(ThemesColumns.LAST_UPDATE_TIME, pi.lastUpdateTime);
String where = ThemesColumns.PKG_NAME + "=?";
diff --git a/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java b/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java
index 95e4905..6a0f54a 100644
--- a/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java
+++ b/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java
@@ -17,6 +17,8 @@ package org.cyanogenmod.themes.provider;
import android.content.ContentValues;
import android.content.Context;
+import android.content.pm.ThemeUtils;
+import android.content.res.CustomTheme;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
@@ -28,12 +30,15 @@ import android.util.Log;
public class ThemesOpenHelper extends SQLiteOpenHelper {
private static final String TAG = ThemesOpenHelper.class.getName();
- private static final int DATABASE_VERSION = 4;
+ private static final int DATABASE_VERSION = 5;
private static final String DATABASE_NAME = "themes.db";
- private static final String DEFAULT_PKG_NAME = "default";
+ private static final String DEFAULT_PKG_NAME = CustomTheme.HOLO_DEFAULT;
+
+ private Context mContext;
public ThemesOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
+ mContext = context;
}
@Override
@@ -41,7 +46,7 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
db.execSQL(ThemesTable.THEMES_TABLE_CREATE);
db.execSQL(MixnMatchTable.MIXNMATCH_TABLE_CREATE);
- ThemesTable.insertDefaults(db);
+ ThemesTable.insertHoloDefaults(db, mContext);
MixnMatchTable.insertDefaults(db);
}
@@ -61,6 +66,10 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
upgradeToVersion4(db);
oldVersion = 4;
}
+ if (oldVersion == 4) {
+ upgradeToVersion5(db);
+ oldVersion = 5;
+ }
if (oldVersion != DATABASE_VERSION) {
Log.e(TAG, "Recreating db because unknown database version: " + oldVersion);
dropTables(db);
@@ -91,11 +100,36 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
private void upgradeToVersion4(SQLiteDatabase db) {
String isLegacyIconPackColumn = String.format("ALTER TABLE %s" +
- " ADD COLUMN %s INTEGER DEFAULT 0",
+ " ADD COLUMN %s INTEGER DEFAULT 0",
ThemesTable.TABLE_NAME, ThemesColumns.IS_LEGACY_ICONPACK);
db.execSQL(isLegacyIconPackColumn);
}
+ private void upgradeToVersion5(SQLiteDatabase db) {
+ String addIsDefault = String.format("ALTER TABLE %s ADD COLUMN %s TEXT",
+ ThemesTable.TABLE_NAME, ThemesColumns.IS_DEFAULT_THEME);
+ db.execSQL(addIsDefault);
+
+ // change default package name to holo
+ String changeDefaultToHolo = String.format("UPDATE %s SET %s='%s' WHERE" +
+ " %s='%s'", ThemesTable.TABLE_NAME, ThemesColumns.PKG_NAME,
+ DEFAULT_PKG_NAME, ThemesColumns.PKG_NAME, "default");
+ db.execSQL(changeDefaultToHolo);
+
+ if (isHoloDefault(mContext)) {
+ // flag holo as default if
+ String makeHoloDefault = String.format("UPDATE %s SET %s=%d WHERE" +
+ " %s='%s'", ThemesTable.TABLE_NAME, ThemesColumns.IS_DEFAULT_THEME, 1,
+ ThemesColumns.PKG_NAME, DEFAULT_PKG_NAME);
+ db.execSQL(makeHoloDefault);
+ }
+
+ // change any existing mixnmatch values set to "default" to "holo"
+ db.execSQL(String.format("UPDATE %s SET %s='%s' WHERE %s='%s'",
+ MixnMatchTable.TABLE_NAME, MixnMatchColumns.COL_VALUE, DEFAULT_PKG_NAME,
+ MixnMatchColumns.COL_VALUE, "default"));
+ }
+
private void dropTables(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + ThemesTable.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + MixnMatchTable.TABLE_NAME);
@@ -132,11 +166,13 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
ThemesColumns.MODIFIES_OVERLAYS + " INTEGER DEFAULT 0, " +
ThemesColumns.PRESENT_AS_THEME + " INTEGER DEFAULT 0, " +
ThemesColumns.IS_LEGACY_THEME + " INTEGER DEFAULT 0," +
+ ThemesColumns.IS_DEFAULT_THEME + " INTEGER DEFAULT 0," +
ThemesColumns.IS_LEGACY_ICONPACK + " INTEGER DEFAULT 0," +
ThemesColumns.LAST_UPDATE_TIME + " INTEGER DEFAULT 0" +
")";
- public static void insertDefaults(SQLiteDatabase db) {
+ public static void insertHoloDefaults(SQLiteDatabase db, Context context) {
+ int isDefault = isHoloDefault(context) ? 1 : 0;
ContentValues values = new ContentValues();
values.put(ThemesColumns.TITLE, "Holo (Default)");
values.put(ThemesColumns.PKG_NAME, DEFAULT_PKG_NAME);
@@ -158,6 +194,7 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
values.put(ThemesColumns.MODIFIES_RINGTONES, 1);
values.put(ThemesColumns.PRESENT_AS_THEME, 1);
values.put(ThemesColumns.IS_LEGACY_THEME, 0);
+ values.put(ThemesColumns.IS_DEFAULT_THEME, isDefault);
values.put(ThemesColumns.IS_LEGACY_ICONPACK, 0);
values.put(ThemesColumns.MODIFIES_OVERLAYS, 1);
db.insert(TABLE_NAME, null, values);
@@ -181,6 +218,11 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
}
}
}
+
+ private static boolean isHoloDefault(Context context) {
+ // == is okay since we are checking if what is returned is the same constant string value
+ return CustomTheme.HOLO_DEFAULT == ThemeUtils.getDefaultThemePackageName(context);
+ }
}
diff --git a/src/org/cyanogenmod/themes/provider/ThemesProvider.java b/src/org/cyanogenmod/themes/provider/ThemesProvider.java
index 03c8d44..4154b3e 100644
--- a/src/org/cyanogenmod/themes/provider/ThemesProvider.java
+++ b/src/org/cyanogenmod/themes/provider/ThemesProvider.java
@@ -25,6 +25,7 @@ import android.content.SharedPreferences.Editor;
import android.content.UriMatcher;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ThemeUtils;
import android.content.res.ThemeManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
@@ -47,6 +48,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import static android.content.res.CustomTheme.HOLO_DEFAULT;
+
public class ThemesProvider extends ContentProvider {
private static final String TAG = ThemesProvider.class.getSimpleName();
private static final boolean DEBUG = false;
@@ -76,7 +79,8 @@ public class ThemesProvider extends ContentProvider {
public static String getActiveTheme(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- return prefs.getString("SelectedThemePkgName", "default");
+ return prefs.getString("SelectedThemePkgName",
+ ThemeUtils.getDefaultThemePackageName(context));
}
@Override
@@ -295,16 +299,22 @@ public class ThemesProvider extends ContentProvider {
*/
Cursor current = mDb.query(ThemesTable.TABLE_NAME, null, null, null, null, null, null);
List<String> deleteList = new LinkedList<String>();
- List<PackageInfo> updateList = new LinkedList<PackageInfo>();
+ List<String> updateList = new LinkedList<String>();
+ String defaultThemePkg = ThemeUtils.getDefaultThemePackageName(getContext());
while (current.moveToNext()) {
int updateTimeIdx = current.getColumnIndex(
ThemesContract.ThemesColumns.LAST_UPDATE_TIME);
int pkgNameIdx = current.getColumnIndex(ThemesContract.ThemesColumns.PKG_NAME);
+ int isDefaultIdx = current.getColumnIndex(ThemesColumns.IS_DEFAULT_THEME);
long updateTime = current.getLong(updateTimeIdx);
String pkgName = current.getString(pkgNameIdx);
+ boolean isDefault = current.getInt(isDefaultIdx) == 1;
- // Ignore default theme
- if (pkgName.equals("default")) {
+ // Ignore holo theme
+ if (pkgName.equals(HOLO_DEFAULT)) {
+ if (defaultThemePkg.equals(HOLO_DEFAULT) != isDefault) {
+ updateList.add(HOLO_DEFAULT);
+ }
continue;
}
@@ -319,8 +329,9 @@ public class ThemesProvider extends ContentProvider {
// updated in the db
long pmUpdateTime = (info.lastUpdateTime == 0) ? info.firstInstallTime
: info.lastUpdateTime;
- if (pmUpdateTime != updateTime) {
- updateList.add(info);
+ if (pmUpdateTime != updateTime ||
+ (defaultThemePkg.equals(info.packageName) != isDefault)) {
+ updateList.add(info.packageName);
}
// The remaining packages in pmThemes
@@ -347,7 +358,7 @@ public class ThemesProvider extends ContentProvider {
}
ThemeManager mService = (ThemeManager) getContext().getSystemService(
Context.THEME_SERVICE);
- mService.requestThemeChange("default", moveToDefault);
+ mService.requestThemeChange(HOLO_DEFAULT, moveToDefault);
// Update the database after we revert to default
deleteThemes(deleteList);
@@ -375,12 +386,12 @@ public class ThemesProvider extends ContentProvider {
}
}
- private void updateThemes(List<PackageInfo> themesToUpdate) {
- for (PackageInfo themeInfo : themesToUpdate) {
+ private void updateThemes(List<String> themesToUpdate) {
+ for (String pkgName : themesToUpdate) {
try {
- ThemePackageHelper.updatePackage(getContext(), themeInfo.packageName);
+ ThemePackageHelper.updatePackage(getContext(), pkgName);
} catch (NameNotFoundException e) {
- Log.e(TAG, "Unable to update theme " + themeInfo.packageName, e);
+ Log.e(TAG, "Unable to update theme " + pkgName, e);
}
}
}