diff options
author | Clark Scheff <clark@cyngn.com> | 2014-11-19 15:16:54 -0800 |
---|---|---|
committer | Andy Mast <andy@cyngn.com> | 2014-11-20 16:39:32 +0000 |
commit | 93300f31e0445fbe021bdd7e65489d02abae2170 (patch) | |
tree | b1d28cd9d37f233aa9d3da1b406fe1b65df3e028 | |
parent | d1bf0f57a3f7cae08c8f0a6a181d8f837dede439 (diff) | |
download | packages_apps_ThemeChooser-93300f31e0445fbe021bdd7e65489d02abae2170.tar.gz packages_apps_ThemeChooser-93300f31e0445fbe021bdd7e65489d02abae2170.tar.bz2 packages_apps_ThemeChooser-93300f31e0445fbe021bdd7e65489d02abae2170.zip |
Allow applying theme components to current theme
When a third party app requests a theme to be applied and the theme
is not a complete pack the various components of that pack will be
applied to the currently applied theme. Themes that are flagged as
PRESENT_AS_THEME will be applied as a whole.
Change-Id: If49afc47ff87d8ced3f5218cc7ac26736eae96eb
-rw-r--r-- | src/com/cyngn/theme/chooser/ChooserActivity.java | 32 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/MyThemeFragment.java | 70 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/ThemeFragment.java | 122 |
3 files changed, 159 insertions, 65 deletions
diff --git a/src/com/cyngn/theme/chooser/ChooserActivity.java b/src/com/cyngn/theme/chooser/ChooserActivity.java index 7cc11c0..bfffd69 100644 --- a/src/com/cyngn/theme/chooser/ChooserActivity.java +++ b/src/com/cyngn/theme/chooser/ChooserActivity.java @@ -121,7 +121,7 @@ public class ChooserActivity extends FragmentActivity private boolean mThemeChanging = false; private boolean mAnimateContentIn = false; private long mAnimateContentInDelay; - private boolean mApplyOnThemeLoaded; + private String mThemeToApply; private boolean mAlwaysHideShopThemes; ImageView mCustomBackground; @@ -265,7 +265,7 @@ public class ChooserActivity extends FragmentActivity String action = intent.getAction(); if ((Intent.ACTION_MAIN.equals(action) || ACTION_APPLY_THEME.equals(action)) && intent.hasExtra(EXTRA_PKGNAME)) { - mSelectedTheme = intent.getStringExtra(EXTRA_PKGNAME); + mSelectedTheme = getSelectedTheme(intent.getStringExtra(EXTRA_PKGNAME)); if (mPager != null) { startLoader(LOADER_ID_INSTALLED_THEMES); if (mExpanded) { @@ -291,11 +291,31 @@ public class ChooserActivity extends FragmentActivity getPackageManager() .checkPermission(PERMISSION_WRITE_THEME, getCallingPackage())) { - mApplyOnThemeLoaded = true; + mThemeToApply = intent.getStringExtra(EXTRA_PKGNAME); } } } + private String getSelectedTheme(String requestedTheme) { + String[] projection = { ThemesColumns.PRESENT_AS_THEME }; + String selection = ThemesColumns.PKG_NAME + "=?"; + String[] selectionArgs = { requestedTheme }; + + String selectedTheme = PreferenceUtils.getAppliedBaseTheme(this); + + Cursor cursor = getContentResolver().query(ThemesColumns.CONTENT_URI, + projection, selection, selectionArgs, null); + if (cursor != null) { + if (cursor.getCount() > 0 && cursor.moveToFirst()) { + if (cursor.getInt(0) == 1) { + selectedTheme = requestedTheme; + } + } + cursor.close(); + } + return selectedTheme; + } + private void setAnimatingStateAndScheduleFinish() { mIsAnimating = true; mContainer.setIsAnimating(true); @@ -765,10 +785,10 @@ public class ChooserActivity extends FragmentActivity if (selectedThemeIndex >= 0) { mPager.setCurrentItem(selectedThemeIndex, false); - if (mApplyOnThemeLoaded) { + if (mThemeToApply != null) { ThemeFragment f = getCurrentFragment(); - f.applyThemeWhenPopulated(); - mApplyOnThemeLoaded = false; + f.applyThemeWhenPopulated(mThemeToApply); + mThemeToApply = null; } } if (mAnimateContentIn) animateContentIn(); diff --git a/src/com/cyngn/theme/chooser/MyThemeFragment.java b/src/com/cyngn/theme/chooser/MyThemeFragment.java index 54cedb7..e7c319a 100644 --- a/src/com/cyngn/theme/chooser/MyThemeFragment.java +++ b/src/com/cyngn/theme/chooser/MyThemeFragment.java @@ -174,7 +174,6 @@ public class MyThemeFragment extends ThemeFragment { @Override public void setCurrentTheme(Map<String, String> currentTheme) { super.setCurrentTheme(currentTheme); - mSelectedComponentsMap.clear(); for (String key : currentTheme.keySet()) { mSelectedComponentsMap.put(key, currentTheme.get(key)); } @@ -194,6 +193,64 @@ public class MyThemeFragment extends ThemeFragment { return false; } + @Override + protected void applyThemeWhenPopulated(String pkgName) { + super.applyThemeWhenPopulated(pkgName); + populateComponentsToApply(pkgName); + } + + private void populateComponentsToApply(String pkgName) { + String selection = ThemesColumns.PKG_NAME + "=?"; + String[] selectionArgs = { pkgName }; + Cursor c = getActivity().getContentResolver().query(ThemesColumns.CONTENT_URI, + null, selection, selectionArgs, null); + if (c != null) { + if (c.getCount() > 0 && c.moveToFirst()) { + mSelectedComponentsMap.clear(); + if (c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_ALARMS)) == 1) { + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_ALARMS, pkgName); + } + if (c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_BOOT_ANIM)) == 1) { + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_BOOT_ANIM, pkgName); + } + if (c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_FONTS)) == 1) { + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_FONTS, pkgName); + } + if (c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_ICONS)) == 1) { + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_ICONS, pkgName); + } + if (c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_LAUNCHER)) == 1) { + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_LAUNCHER, pkgName); + } + if (c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_LOCKSCREEN)) == 1) { + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_LOCKSCREEN, pkgName); + } + if (c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_NAVIGATION_BAR)) == 1) { + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_NAVIGATION_BAR, pkgName); + } + if (c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_NOTIFICATIONS)) == 1) { + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_NOTIFICATIONS, pkgName); + } + if (c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_OVERLAYS)) == 1) { + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_OVERLAYS, pkgName); + } + if (c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_RINGTONES)) == 1) { + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_RINGTONES, pkgName); + } + if (c.getInt(c.getColumnIndex(ThemesColumns.MODIFIES_STATUS_BAR)) == 1) { + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_STATUS_BAR, pkgName); + } + } + c.close(); + } + } + + private void loadComponentsToApply() { + for (String component : mSelectedComponentsMap.keySet()) { + loadComponentFromPackage(mSelectedComponentsMap.get(component), component); + } + } + private BroadcastReceiver mWallpaperChangeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -294,10 +351,21 @@ public class MyThemeFragment extends ThemeFragment { // theme components have been properly set. if (mThemeResetting && loader.getId() == LOADER_ID_ALL) { applyTheme(); + } else if (loader.getId() == LOADER_ID_ALL && mApplyThemeOnPopulated) { + loadComponentsToApply(); + applyTheme(); } } @Override + protected Map<String, String> fillMissingComponentsWithDefault( + Map<String, String> originalMap) { + if (mApplyThemeOnPopulated) return originalMap; + + return super.fillMissingComponentsWithDefault(originalMap); + } + + @Override protected void populateSupportedComponents(Cursor c) { } diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java index 40b48f7..4db4dbf 100644 --- a/src/com/cyngn/theme/chooser/ThemeFragment.java +++ b/src/com/cyngn/theme/chooser/ThemeFragment.java @@ -268,7 +268,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb protected boolean mExpanded; protected boolean mProcessingResources; - private boolean mApplyThemeOnPopulated; + protected boolean mApplyThemeOnPopulated; protected enum CustomizeResetAction { Customize, @@ -1466,7 +1466,6 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb } if (mApplyThemeOnPopulated) { - mApplyThemeOnPopulated = false; applyTheme(); } } @@ -1987,63 +1986,66 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb } }; - private OnItemClickedListener mOnComponentItemClicked = new OnItemClickedListener() { - @Override - public void onItemClicked(String pkgName) { - Bundle args = new Bundle(); - args.putString(ARG_PACKAGE_NAME, pkgName); - int loaderId = -1; - String component = mSelector.getComponentType(); - if (MODIFIES_STATUS_BAR.equals(component)) { - loaderId = LOADER_ID_STATUS_BAR; - } else if (MODIFIES_FONTS.equals(component)) { - loaderId = LOADER_ID_FONT; - } else if (MODIFIES_ICONS.equals(component)) { - loaderId = LOADER_ID_ICONS; - } else if (MODIFIES_NAVIGATION_BAR.equals(component)) { - loaderId = LOADER_ID_NAVIGATION_BAR; - } else if (MODIFIES_LAUNCHER.equals(component)) { - if (pkgName != null) { - if (TextUtils.isEmpty(pkgName)) { - mWallpaperCard.setWallpaper(null); - mSelectedComponentsMap.put(ThemesColumns.MODIFIES_LAUNCHER, WALLPAPER_NONE); - setCardTitle(mWallpaperCard, WALLPAPER_NONE, - getString(R.string.wallpaper_label)); - } else if (ComponentSelector.EXTERNAL_WALLPAPER.equals(pkgName)) { - getChooserActivity().pickExternalWallpaper(); - setCardTitle(mWallpaperCard, WALLPAPER_NONE, - getString(R.string.wallpaper_label)); - } else { - loaderId = LOADER_ID_WALLPAPER; - } - } - } else if (MODIFIES_LOCKSCREEN.equals(component)) { - if (pkgName != null && TextUtils.isEmpty(pkgName)) { - mLockScreenCard.setWallpaper(null); - mSelectedComponentsMap.put(ThemesColumns.MODIFIES_LOCKSCREEN, WALLPAPER_NONE); - setCardTitle(mLockScreenCard, WALLPAPER_NONE, - getString(R.string.lockscreen_label)); + protected void loadComponentFromPackage(String pkgName, String component) { + Bundle args = new Bundle(); + args.putString(ARG_PACKAGE_NAME, pkgName); + int loaderId = -1; + if (MODIFIES_STATUS_BAR.equals(component)) { + loaderId = LOADER_ID_STATUS_BAR; + } else if (MODIFIES_FONTS.equals(component)) { + loaderId = LOADER_ID_FONT; + } else if (MODIFIES_ICONS.equals(component)) { + loaderId = LOADER_ID_ICONS; + } else if (MODIFIES_NAVIGATION_BAR.equals(component)) { + loaderId = LOADER_ID_NAVIGATION_BAR; + } else if (MODIFIES_LAUNCHER.equals(component)) { + if (pkgName != null) { + if (TextUtils.isEmpty(pkgName)) { + mWallpaperCard.setWallpaper(null); + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_LAUNCHER, WALLPAPER_NONE); + setCardTitle(mWallpaperCard, WALLPAPER_NONE, + getString(R.string.wallpaper_label)); } else if (ComponentSelector.EXTERNAL_WALLPAPER.equals(pkgName)) { - getChooserActivity().pickExternalLockscreen(); - setCardTitle(mLockScreenCard, WALLPAPER_NONE, - getString(R.string.lockscreen_label)); + getChooserActivity().pickExternalWallpaper(); + setCardTitle(mWallpaperCard, WALLPAPER_NONE, + getString(R.string.wallpaper_label)); } else { - loaderId = LOADER_ID_LOCKSCREEN; + loaderId = LOADER_ID_WALLPAPER; } - } else if (MODIFIES_OVERLAYS.equals(component)) { - loaderId = LOADER_ID_STYLE; - } else if (MODIFIES_BOOT_ANIM.equals(component)) { - loaderId = LOADER_ID_BOOT_ANIMATION; - } else if (MODIFIES_RINGTONES.equals(component)) { - loaderId = LOADER_ID_RINGTONE; - } else if (MODIFIES_NOTIFICATIONS.equals(component)) { - loaderId = LOADER_ID_NOTIFICATION; - } else if (MODIFIES_ALARMS.equals(component)) { - loaderId = LOADER_ID_ALARM; + } + } else if (MODIFIES_LOCKSCREEN.equals(component)) { + if (pkgName != null && TextUtils.isEmpty(pkgName)) { + mLockScreenCard.setWallpaper(null); + mSelectedComponentsMap.put(ThemesColumns.MODIFIES_LOCKSCREEN, WALLPAPER_NONE); + setCardTitle(mLockScreenCard, WALLPAPER_NONE, + getString(R.string.lockscreen_label)); + } else if (ComponentSelector.EXTERNAL_WALLPAPER.equals(pkgName)) { + getChooserActivity().pickExternalLockscreen(); + setCardTitle(mLockScreenCard, WALLPAPER_NONE, + getString(R.string.lockscreen_label)); } else { - return; + loaderId = LOADER_ID_LOCKSCREEN; } - getLoaderManager().restartLoader(loaderId, args, ThemeFragment.this); + } else if (MODIFIES_OVERLAYS.equals(component)) { + loaderId = LOADER_ID_STYLE; + } else if (MODIFIES_BOOT_ANIM.equals(component)) { + loaderId = LOADER_ID_BOOT_ANIMATION; + } else if (MODIFIES_RINGTONES.equals(component)) { + loaderId = LOADER_ID_RINGTONE; + } else if (MODIFIES_NOTIFICATIONS.equals(component)) { + loaderId = LOADER_ID_NOTIFICATION; + } else if (MODIFIES_ALARMS.equals(component)) { + loaderId = LOADER_ID_ALARM; + } else { + return; + } + getLoaderManager().restartLoader(loaderId, args, ThemeFragment.this); + } + + private OnItemClickedListener mOnComponentItemClicked = new OnItemClickedListener() { + @Override + public void onItemClicked(String pkgName) { + loadComponentFromPackage(pkgName, mSelector.getComponentType()); } }; @@ -2073,13 +2075,14 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb @Override public void run() { if (mSelectedComponentsMap != null && mSelectedComponentsMap.size() > 0) { - final HashMap<String, String> fullMap + final Map<String, String> fullMap = fillMissingComponentsWithDefault(mSelectedComponentsMap); ThemeManager tm = getThemeManager(); if (tm != null) { tm.addClient(ThemeFragment.this); tm.requestThemeChange(fullMap); } + mApplyThemeOnPopulated = false; } else { onFinish(true); } @@ -2089,7 +2092,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb } }; - private HashMap<String, String> fillMissingComponentsWithDefault( + protected Map<String, String> fillMissingComponentsWithDefault( Map<String, String> originalMap) { HashMap newMap = new HashMap<String, String>(); newMap.putAll(originalMap); @@ -2165,8 +2168,11 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb animateProgressIn(mApplyThemeRunnable); } - // Use when applyTheme() might be too early. ie mSelectedComponentsMap is not pop. yet - protected void applyThemeWhenPopulated() { + /** + * Use when applyTheme() might be too early. ie mSelectedComponentsMap is not pop. yet + * @param pkgName Only used in MyThemeFragment to apply components on top of current theme + */ + protected void applyThemeWhenPopulated(String pkgName) { mApplyThemeOnPopulated = true; } |