From c596830d10c48f45025a56edd4bec11e78532237 Mon Sep 17 00:00:00 2001 From: Clark Scheff Date: Tue, 10 Jun 2014 15:01:34 -0700 Subject: Handle theme changes Change-Id: I85208f3d6b572fb7a161db79cd3b74c1102dbba2 (cherry picked from commit 50f78e36b079bbe14bcb50064d28940358d42544) --- AndroidManifest.xml | 6 ++ .../android/launcher3/ThemeChangedReceiver.java | 78 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/com/android/launcher3/ThemeChangedReceiver.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 4965c0c8e..40ee2e11c 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -219,6 +219,12 @@ + + + + + + components = intent.getStringArrayListExtra(EXTRA_COMPONENTS); + if (isInterestingThemeChange(components)) { + LauncherAppState app = LauncherAppState.getInstance(); + app.getIconCache().flush(); + clearWidgetPreviewCache(context); + app.recreateWidgetPreviewDb(); + app.getModel().forceReload(); + } + } + + /** + * We consider this an "interesting" theme change if it modifies icons, overlays, or fonts. + * @param components + * @return + */ + private boolean isInterestingThemeChange(ArrayList components) { + if (components != null) { + for (String component : components) { + if (component.equals(MODIFIES_ICONS) || + component.equals(MODIFIES_FONTS) || + component.equals(MODIFIES_OVERLAYS)) { + return true; + } + } + } + return false; + } + + /** + * 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 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