diff options
author | Andy Mast <andy@cyngn.com> | 2014-11-07 11:15:13 -0800 |
---|---|---|
committer | Andy Mast <andy@cyngn.com> | 2014-11-09 22:25:07 +0000 |
commit | 8c7837887bdc25e31c66e2acc59c71e0d7832988 (patch) | |
tree | 908a61b6cef1023bf2b17a26d1634f00da948f50 /src/com | |
parent | 3eab9ffd19d1db72870f3a79eeabb085b453b99a (diff) | |
download | packages_apps_ThemeChooser-8c7837887bdc25e31c66e2acc59c71e0d7832988.tar.gz packages_apps_ThemeChooser-8c7837887bdc25e31c66e2acc59c71e0d7832988.tar.bz2 packages_apps_ThemeChooser-8c7837887bdc25e31c66e2acc59c71e0d7832988.zip |
Allow Other Apps To Apply Themes through Chooser
Change-Id: Ifc8115b9bb0320af1c51141c4516b0399583c32e
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/cyngn/theme/chooser/ChooserActivity.java | 22 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/ThemeFragment.java | 11 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/com/cyngn/theme/chooser/ChooserActivity.java b/src/com/cyngn/theme/chooser/ChooserActivity.java index 4ece3dc..cb89f31 100644 --- a/src/com/cyngn/theme/chooser/ChooserActivity.java +++ b/src/com/cyngn/theme/chooser/ChooserActivity.java @@ -79,6 +79,8 @@ public class ChooserActivity extends FragmentActivity private static final String THEME_STORE_PACKAGE = "com.cyngn.themestore"; private static final String THEME_STORE_ACTIVITY = THEME_STORE_PACKAGE + ".ui.StoreActivity"; + private static final String ACTION_APPLY_THEME = "android.intent.action.APPLY_THEME"; + private static final String PERMISSION_WRITE_THEME = "android.permission.WRITE_THEMES"; private static final String TYPE_IMAGE = "image/*"; @@ -118,6 +120,7 @@ public class ChooserActivity extends FragmentActivity private boolean mThemeChanging = false; private boolean mAnimateContentIn = false; private long mAnimateContentInDelay; + private boolean mApplyOnThemeLoaded; ImageView mCustomBackground; @@ -252,7 +255,9 @@ public class ChooserActivity extends FragmentActivity } private void handleIntent(Intent intent) { - if (Intent.ACTION_MAIN.equals(intent.getAction()) && intent.hasExtra(EXTRA_PKGNAME)) { + String action = intent.getAction(); + if ((Intent.ACTION_MAIN.equals(action) || ACTION_APPLY_THEME.equals(action)) + && intent.hasExtra(EXTRA_PKGNAME)) { mSelectedTheme = intent.getStringExtra(EXTRA_PKGNAME); if (mPager != null) { startLoader(LOADER_ID_INSTALLED_THEMES); @@ -272,6 +277,15 @@ public class ChooserActivity extends FragmentActivity }, collapseDelay); } } + + if (ACTION_APPLY_THEME.equals(action) && + getCallingPackage() != null && + PackageManager.PERMISSION_GRANTED == + getPackageManager() + .checkPermission(PERMISSION_WRITE_THEME, + getCallingPackage())) { + mApplyOnThemeLoaded = true; + } } } @@ -743,6 +757,12 @@ public class ChooserActivity extends FragmentActivity mAdapter.notifyDataSetChanged(); if (selectedThemeIndex >= 0) { mPager.setCurrentItem(selectedThemeIndex, false); + + if (mApplyOnThemeLoaded) { + ThemeFragment f = getCurrentFragment(); + f.applyThemeWhenPopulated(); + mApplyOnThemeLoaded = false; + } } if (mAnimateContentIn) animateContentIn(); break; diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java index ccf22c5..e6b4be3 100644 --- a/src/com/cyngn/theme/chooser/ThemeFragment.java +++ b/src/com/cyngn/theme/chooser/ThemeFragment.java @@ -266,6 +266,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb protected boolean mExpanded; protected boolean mProcessingResources; + private boolean mApplyThemeOnPopulated; protected enum CustomizeResetAction { Customize, @@ -1456,6 +1457,11 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb mSelectedComponentsMap.put(component, pkg); } } + + if (mApplyThemeOnPopulated) { + mApplyThemeOnPopulated = false; + applyTheme(); + } } /** @@ -2142,6 +2148,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() { + mApplyThemeOnPopulated = true; + } + private void animateProgressIn(Runnable endAction) { mProgress.setVisibility(View.VISIBLE); mProgress.setProgress(0); |