From 21df88b3e47c6ce768ae2f414c2eaf56b39da7ce Mon Sep 17 00:00:00 2001 From: Clark Scheff Date: Mon, 25 Aug 2014 11:27:55 -0700 Subject: Revert "Use theme change categories and clear widget preview cache" This reverts commit b52694e4fdd3c8ee524b5f6f870697e40061b2a6. Change-Id: I69bff363280ea69ee83dea3a8f2ef2d0d95a7be0 --- AndroidManifest.xml | 3 -- .../android/launcher3/ThemeChangedReceiver.java | 40 ++++++++++++---------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index fcf3baf8f..0dd98d68b 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -197,9 +197,6 @@ - - - diff --git a/src/com/android/launcher3/ThemeChangedReceiver.java b/src/com/android/launcher3/ThemeChangedReceiver.java index 19c2e226d..134a28559 100644 --- a/src/com/android/launcher3/ThemeChangedReceiver.java +++ b/src/com/android/launcher3/ThemeChangedReceiver.java @@ -19,30 +19,34 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import java.io.File; +public class ThemeChangedReceiver extends BroadcastReceiver { + private static final String EXTRA_COMPONENTS = "components"; -import static com.android.launcher3.WidgetPreviewLoader.CacheDb.DB_NAME; + public static final String MODIFIES_ICONS = "mods_icons"; + public static final String MODIFIES_FONTS = "mods_fonts"; + public static final String MODIFIES_OVERLAYS = "mods_overlays"; -public class ThemeChangedReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { - LauncherAppState app = LauncherAppState.getInstance(); - clearWidgetPreviewCache(context); - app.recreateWidgetPreviewDb(); - app.getIconCache().flush(); - app.getModel().forceReload(); + // 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(); + } + } } /** - * Normally we could use context.deleteDatabase() but this db is in cache/ so we'll - * manually delete it and the journal ourselves. - * @param context + * We consider this an "interesting" theme change if it modifies icons, overlays, or fonts. + * @param components + * @return */ - 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(); - } - } + private boolean isInterestingThemeChange(String components) { + return components.contains(MODIFIES_ICONS) || components.contains(MODIFIES_FONTS) || + components.contains(MODIFIES_OVERLAYS); } } -- cgit v1.2.3