From b52694e4fdd3c8ee524b5f6f870697e40061b2a6 Mon Sep 17 00:00:00 2001 From: Clark Scheff Date: Fri, 13 Jun 2014 14:09:27 -0700 Subject: Use theme change categories and clear widget preview cache Change-Id: If10fa3fa407891b91322c7e982742eb1dfab2b93 --- .../android/launcher3/ThemeChangedReceiver.java | 40 ++++++++++------------ 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/com/android/launcher3/ThemeChangedReceiver.java b/src/com/android/launcher3/ThemeChangedReceiver.java index 134a28559..19c2e226d 100644 --- a/src/com/android/launcher3/ThemeChangedReceiver.java +++ b/src/com/android/launcher3/ThemeChangedReceiver.java @@ -19,34 +19,30 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -public class ThemeChangedReceiver extends BroadcastReceiver { - private static final String EXTRA_COMPONENTS = "components"; +import java.io.File; - public static final String MODIFIES_ICONS = "mods_icons"; - public static final String MODIFIES_FONTS = "mods_fonts"; - public static final String MODIFIES_OVERLAYS = "mods_overlays"; +import static com.android.launcher3.WidgetPreviewLoader.CacheDb.DB_NAME; +public class ThemeChangedReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { - // components is a '|' delimited string of the components that changed - // due to a theme change. - String components = intent.getStringExtra(EXTRA_COMPONENTS); - if (components != null) { - LauncherAppState.setApplicationContext(context.getApplicationContext()); - LauncherAppState app = LauncherAppState.getInstance(); - if (isInterestingThemeChange(components)) { - app.getIconCache().flush(); - app.getModel().forceReload(); - } - } + LauncherAppState app = LauncherAppState.getInstance(); + clearWidgetPreviewCache(context); + app.recreateWidgetPreviewDb(); + app.getIconCache().flush(); + app.getModel().forceReload(); } /** - * We consider this an "interesting" theme change if it modifies icons, overlays, or fonts. - * @param components - * @return + * Normally we could use context.deleteDatabase() but this db is in cache/ so we'll + * manually delete it and the journal ourselves. + * @param context */ - private boolean isInterestingThemeChange(String components) { - return components.contains(MODIFIES_ICONS) || components.contains(MODIFIES_FONTS) || - components.contains(MODIFIES_OVERLAYS); + private void clearWidgetPreviewCache(Context context) { + File[] files = context.getCacheDir().listFiles(); + if (files != null) { + for (File f : files) { + if (!f.isDirectory() && f.getName().startsWith(DB_NAME)) f.delete(); + } + } } } -- cgit v1.2.3