diff options
author | Clark Scheff <clark@cyngn.com> | 2014-11-20 11:33:33 -0800 |
---|---|---|
committer | Clark Scheff <clark@cyngn.com> | 2014-11-20 11:35:09 -0800 |
commit | 1766de5efa7775815a701a553a4791cfae415fcf (patch) | |
tree | a0332c8f7c5643700a27fe3342b2361d6631ec2d /src | |
parent | 93300f31e0445fbe021bdd7e65489d02abae2170 (diff) | |
download | packages_apps_ThemeChooser-1766de5efa7775815a701a553a4791cfae415fcf.zip packages_apps_ThemeChooser-1766de5efa7775815a701a553a4791cfae415fcf.tar.gz packages_apps_ThemeChooser-1766de5efa7775815a701a553a4791cfae415fcf.tar.bz2 |
Handle applying specified components of a theme
If a 3rd party app, such as the Theme Store, passes in a list of
components to apply for a given theme the chooser will only apply
those components to the currently applied theme.
Change-Id: Ie3b702e076b3382ad5364eabd77cb3eba8854462
REF: TSC-18
Diffstat (limited to 'src')
-rw-r--r-- | src/com/cyngn/theme/chooser/ChooserActivity.java | 13 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/MyThemeFragment.java | 22 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/ThemeFragment.java | 3 |
3 files changed, 31 insertions, 7 deletions
diff --git a/src/com/cyngn/theme/chooser/ChooserActivity.java b/src/com/cyngn/theme/chooser/ChooserActivity.java index bfffd69..461da86 100644 --- a/src/com/cyngn/theme/chooser/ChooserActivity.java +++ b/src/com/cyngn/theme/chooser/ChooserActivity.java @@ -72,6 +72,7 @@ public class ChooserActivity extends FragmentActivity public static final String DEFAULT = ThemeConfig.HOLO_DEFAULT; public static final String EXTRA_PKGNAME = "pkgName"; + public static final String EXTRA_COMPONENTS = "components"; private static final int OFFSCREEN_PAGE_LIMIT = 3; @@ -122,6 +123,7 @@ public class ChooserActivity extends FragmentActivity private boolean mAnimateContentIn = false; private long mAnimateContentInDelay; private String mThemeToApply; + private ArrayList mComponentsToApply; private boolean mAlwaysHideShopThemes; ImageView mCustomBackground; @@ -265,7 +267,14 @@ 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 = getSelectedTheme(intent.getStringExtra(EXTRA_PKGNAME)); + if (intent.hasExtra(EXTRA_COMPONENTS)) { + mComponentsToApply = intent.getStringArrayListExtra(EXTRA_COMPONENTS); + } else { + mComponentsToApply = null; + } + mSelectedTheme = mComponentsToApply != null ? + PreferenceUtils.getAppliedBaseTheme(this) : + getSelectedTheme(intent.getStringExtra(EXTRA_PKGNAME)); if (mPager != null) { startLoader(LOADER_ID_INSTALLED_THEMES); if (mExpanded) { @@ -787,7 +796,7 @@ public class ChooserActivity extends FragmentActivity if (mThemeToApply != null) { ThemeFragment f = getCurrentFragment(); - f.applyThemeWhenPopulated(mThemeToApply); + f.applyThemeWhenPopulated(mThemeToApply, mComponentsToApply); mThemeToApply = null; } } diff --git a/src/com/cyngn/theme/chooser/MyThemeFragment.java b/src/com/cyngn/theme/chooser/MyThemeFragment.java index e7c319a..a290b5d 100644 --- a/src/com/cyngn/theme/chooser/MyThemeFragment.java +++ b/src/com/cyngn/theme/chooser/MyThemeFragment.java @@ -42,6 +42,8 @@ import com.cyngn.theme.util.TypefaceHelperCache; import com.cyngn.theme.util.Utils; import java.io.IOException; +import java.util.Iterator; +import java.util.List; import java.util.Map; public class MyThemeFragment extends ThemeFragment { @@ -194,12 +196,12 @@ public class MyThemeFragment extends ThemeFragment { } @Override - protected void applyThemeWhenPopulated(String pkgName) { - super.applyThemeWhenPopulated(pkgName); - populateComponentsToApply(pkgName); + protected void applyThemeWhenPopulated(String pkgName, List<String> components) { + super.applyThemeWhenPopulated(pkgName, components); + populateComponentsToApply(pkgName, components); } - private void populateComponentsToApply(String pkgName) { + private void populateComponentsToApply(String pkgName, List<String> components) { String selection = ThemesColumns.PKG_NAME + "=?"; String[] selectionArgs = { pkgName }; Cursor c = getActivity().getContentResolver().query(ThemesColumns.CONTENT_URI, @@ -243,6 +245,18 @@ public class MyThemeFragment extends ThemeFragment { } c.close(); } + + // strip out any components that are not in the components list + if (components != null) { + Iterator<Map.Entry<String, String>> iterator = + mSelectedComponentsMap.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry<String, String> entry = iterator.next(); + if (!components.contains(entry.getKey())) { + iterator.remove(); + } + } + } } private void loadComponentsToApply() { diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java index 4db4dbf..0b346ac 100644 --- a/src/com/cyngn/theme/chooser/ThemeFragment.java +++ b/src/com/cyngn/theme/chooser/ThemeFragment.java @@ -2171,8 +2171,9 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb /** * 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 + * @param components Optional list of components to apply. */ - protected void applyThemeWhenPopulated(String pkgName) { + protected void applyThemeWhenPopulated(String pkgName, List<String> components) { mApplyThemeOnPopulated = true; } |