From bb32275e34826dd67636d5712b0651d23751b6d2 Mon Sep 17 00:00:00 2001 From: d34d Date: Thu, 4 Feb 2016 16:27:02 -0800 Subject: Clear out previous theme component when changing themes When we change to a different theme or reset the current theme, we need to make sure we un-apply components that are not part of the theme being applied/reset, unless the user customized the theme. This also applies for resetting a theme. Change-Id: I295c082d10929b6f99af7ebc5d6a2dd123fcf64a TICKET: CYNGNOS-1847 OPO-430 --- src/com/cyngn/theme/chooser/ChooserActivity.java | 2 + src/com/cyngn/theme/chooser/MyThemeFragment.java | 89 ++++++++++++++---------- src/com/cyngn/theme/chooser/ThemeFragment.java | 36 ++++++++-- 3 files changed, 85 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/com/cyngn/theme/chooser/ChooserActivity.java b/src/com/cyngn/theme/chooser/ChooserActivity.java index 1a26828..7b14370 100644 --- a/src/com/cyngn/theme/chooser/ChooserActivity.java +++ b/src/com/cyngn/theme/chooser/ChooserActivity.java @@ -804,6 +804,8 @@ public class ChooserActivity extends FragmentActivity c.moveToPosition(-1); //Default to first wallpaper mCurrentWallpaperCmpntId.value = DEFAULT_COMPONENT_ID; + // clear out the previous map + mCurrentTheme.clear(); while(c.moveToNext()) { int mixkeyIdx = c.getColumnIndex(ThemesContract.MixnMatchColumns.COL_KEY); int pkgIdx = c.getColumnIndex(ThemesContract.MixnMatchColumns.COL_VALUE); diff --git a/src/com/cyngn/theme/chooser/MyThemeFragment.java b/src/com/cyngn/theme/chooser/MyThemeFragment.java index c674c2a..67a49d2 100644 --- a/src/com/cyngn/theme/chooser/MyThemeFragment.java +++ b/src/com/cyngn/theme/chooser/MyThemeFragment.java @@ -26,7 +26,6 @@ import android.os.Bundle; import android.provider.ThemesContract; import android.provider.ThemesContract.PreviewColumns; import android.provider.ThemesContract.ThemesColumns; -import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.util.Log; import android.util.MutableLong; @@ -39,6 +38,7 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; + import com.cyngn.theme.util.AudioUtils; import com.cyngn.theme.util.CursorLoaderHelper; import com.cyngn.theme.util.PreferenceUtils; @@ -93,6 +93,7 @@ public class MyThemeFragment extends ThemeFragment { mBaseThemeAuthor = getArguments().getString(ARG_BASE_THEME_AUTHOR); mShowAnimatedLockScreenSelectorAfterContentLoaded = getArguments().getBoolean(ARG_SHOW_ANIMATED_LOCK_SCREEN_ONLY); mSurfaceView = createSurfaceView(); + populateBaseThemeSupportedComponents(mBaseThemePkgName); } @Override @@ -106,9 +107,8 @@ public class MyThemeFragment extends ThemeFragment { if (PreferenceUtils.hasThemeBeenUpdated(getActivity(), mBaseThemePkgName)) { mThemeTagLayout.setUpdatedTagEnabled(true); } - setCustomizedTagIfCustomized(); mDelete.setVisibility(View.GONE); - mReset.setVisibility(View.VISIBLE); + setCustomized(isThemeCustomized()); return v; } @@ -309,33 +309,9 @@ public class MyThemeFragment extends ThemeFragment { } }; - private void setCustomizedTagIfCustomized() { - boolean isDefault = - mBaseThemePkgName.equals(Utils.getDefaultThemePackageName(getActivity())); - if (isDefault) { - // The default theme could be a mix of the system default theme and holo so lets check - // that. i.e. Hexo with holo for the components not found in Hexo - Map defaultComponents = ThemeUtils.getDefaultComponents(getActivity()); - for (String component : mCurrentTheme.keySet()) { - String componentPkgName = mCurrentTheme.get(component); - if (defaultComponents.containsKey(component)) { - if (!componentPkgName.equals(defaultComponents.get(component))) { - mThemeTagLayout.setCustomizedTagEnabled(true); - break; - } - } else { - mThemeTagLayout.setCustomizedTagEnabled(true); - break; - } - } - } else { - for (String pkgName : mCurrentTheme.values()) { - if (!pkgName.equals(mBaseThemePkgName)) { - mThemeTagLayout.setCustomizedTagEnabled(true); - break; - } - } - } + private void setCustomized(boolean customized) { + mReset.setVisibility(customized ? View.VISIBLE : View.GONE); + mThemeTagLayout.setCustomizedTagEnabled(customized); } @Override @@ -391,14 +367,23 @@ public class MyThemeFragment extends ThemeFragment { @Override protected Map getComponentsToApply() { - Map componentsToApply = new HashMap(); - // Only apply components that actually changed - for (String component : mSelectedComponentsMap.keySet()) { - String currentPkg = mCurrentTheme.get(component); - String selectedPkg = mSelectedComponentsMap.get(component); - if (currentPkg == null || mThemeResetting || !currentPkg.equals(selectedPkg) || - mCurrentWallpaperComponentId.value != mSelectedWallpaperComponentId) { - componentsToApply.put(component, selectedPkg); + Map componentsToApply = mThemeResetting + ? getEmptyComponentsMap() + : new HashMap(); + if (mThemeResetting) { + final String pkgName = getThemePackageName(); + for (String component : mBaseThemeSupportedComponents) { + componentsToApply.put(component, pkgName); + } + } else { + // Only apply components that actually changed + for (String component : mSelectedComponentsMap.keySet()) { + String currentPkg = mCurrentTheme.get(component); + String selectedPkg = mSelectedComponentsMap.get(component); + if (currentPkg == null || mThemeResetting || !currentPkg.equals(selectedPkg) || + mCurrentWallpaperComponentId.value != mSelectedWallpaperComponentId) { + componentsToApply.put(component, selectedPkg); + } } } return componentsToApply; @@ -666,4 +651,32 @@ public class MyThemeFragment extends ThemeFragment { mShadowFrame.removeView(sv); } } + + /** + * Populates mBaseThemeSupportedComponents. + * @param pkgName Package name of the base theme used + */ + private void populateBaseThemeSupportedComponents(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.moveToFirst()) { + List components = ThemeUtils.getAllComponents(); + final String baseThemePackageName = getThemePackageName(); + for (String component : components) { + int pkgIdx = c.getColumnIndex(ThemesColumns.PKG_NAME); + int modifiesCompIdx = c.getColumnIndex(component); + + String pkg = pkgIdx >= 0 ? c.getString(pkgIdx) : null; + boolean supported = (modifiesCompIdx >= 0) && (c.getInt(modifiesCompIdx) == 1); + if (supported && baseThemePackageName.equals(pkg)) { + mBaseThemeSupportedComponents.add(component); + } + } + } + c.close(); + } + } } diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java index 5f1e8ac..6812c43 100644 --- a/src/com/cyngn/theme/chooser/ThemeFragment.java +++ b/src/com/cyngn/theme/chooser/ThemeFragment.java @@ -884,9 +884,9 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb content.setPadding(leftRightPadding, 0, leftRightPadding, 0); if (applyTheme) { - final boolean changed = componentsChanged(); - mThemeTagLayout.setCustomizedTagEnabled(changed); - mReset.setVisibility(changed ? View.VISIBLE : View.GONE); + final boolean customized = isThemeCustomized(); + mThemeTagLayout.setCustomizedTagEnabled(customized); + mReset.setVisibility(customized ? View.VISIBLE : View.GONE); } //Move the theme preview so that it is near the center of page per spec @@ -2207,7 +2207,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb Map originalMap) { HashMap newMap = new HashMap(); newMap.putAll(originalMap); - Map defaultMap = ThemeUtils.getDefaultComponents(getActivity()); + Map defaultMap = getEmptyComponentsMap(); for(Map.Entry entry : defaultMap.entrySet()) { String component = entry.getKey(); String defaultPkg = entry.getValue(); @@ -2218,6 +2218,15 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb return newMap; } + protected Map getEmptyComponentsMap() { + List componentsList = ThemeUtils.getAllComponents(); + Map defaultMap = new HashMap<>(componentsList.size()); + for (String component : componentsList) { + defaultMap.put(component, ""); + } + return defaultMap; + } + /** * This is the method that will be called when applying a theme and the idea is to override * it in MyThemeFragment and pass in a different RequestType, once we have a type that indicates @@ -2731,6 +2740,25 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb return false; } + protected boolean isThemeCustomized() { + final String themePkgName = getThemePackageName(); + for (String key : mSelectedComponentsMap.keySet()) { + final String selectedPkgName = mSelectedComponentsMap.get(key); + if (!themePkgName.equals(selectedPkgName)) { + return true; + } + if (mBaseThemeSupportedComponents.size() > 0 && + !mBaseThemeSupportedComponents.contains(key)) { + return true; + } + } + // finally check if we're missing anything from mBaseThemeSupportedComponents + for (String component : mBaseThemeSupportedComponents) { + if (!mSelectedComponentsMap.containsKey(component)) return true; + } + return false; + } + public void clearChanges() { mSelectedComponentsMap.clear(); mExternalWallpaperUri = null; -- cgit v1.2.3