summaryrefslogtreecommitdiffstats
path: root/src/com/cyngn
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2015-03-03 16:19:10 -0800
committerClark Scheff <clark@cyngn.com>2015-03-11 15:41:05 +0000
commit87b8ca5c19ec1d641a53a5ae3115c2f380a728ed (patch)
tree986678a3fd3a5d22617b9766584291519ba2fe3c /src/com/cyngn
parentb343731b5d5816bc4be98f289d7198d6210a3f2f (diff)
downloadpackages_apps_ThemeChooser-87b8ca5c19ec1d641a53a5ae3115c2f380a728ed.zip
packages_apps_ThemeChooser-87b8ca5c19ec1d641a53a5ae3115c2f380a728ed.tar.gz
packages_apps_ThemeChooser-87b8ca5c19ec1d641a53a5ae3115c2f380a728ed.tar.bz2
Use provider's broadcasts for theme installs/removals
Change-Id: I42f58ef75a45aa131c87baed0d0aeac5763e916c
Diffstat (limited to 'src/com/cyngn')
-rw-r--r--src/com/cyngn/theme/chooser/AppReceiver.java42
-rw-r--r--src/com/cyngn/theme/chooser/ChooserActivity.java5
-rw-r--r--src/com/cyngn/theme/util/PreferenceUtils.java36
3 files changed, 9 insertions, 74 deletions
diff --git a/src/com/cyngn/theme/chooser/AppReceiver.java b/src/com/cyngn/theme/chooser/AppReceiver.java
index 4edb41b..546539f 100644
--- a/src/com/cyngn/theme/chooser/AppReceiver.java
+++ b/src/com/cyngn/theme/chooser/AppReceiver.java
@@ -7,17 +7,14 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ThemeUtils;
-import android.content.res.ThemeManager;
import android.net.Uri;
+import android.provider.ThemesContract;
import android.text.TextUtils;
import com.cyngn.theme.util.NotificationHelper;
import com.cyngn.theme.util.PreferenceUtils;
-import java.util.Set;
-
public class AppReceiver extends BroadcastReceiver {
@Override
@@ -25,21 +22,10 @@ public class AppReceiver extends BroadcastReceiver {
Uri uri = intent.getData();
String pkgName = uri != null ? uri.getSchemeSpecificPart() : null;
String action = intent.getAction();
- boolean isReplacing = intent.getExtras().getBoolean(Intent.EXTRA_REPLACING, false);
- if (Intent.ACTION_PACKAGE_ADDED.equals(action) && !isReplacing) {
- try {
- if (isTheme(context, pkgName)) {
- if (!isThemeBeingProcessed(context, pkgName)) {
- NotificationHelper.postThemeInstalledNotification(context, pkgName);
- } else {
- // store this package name so we know it's being processed
- PreferenceUtils.addThemeBeingProcessed(context, pkgName);
- }
- }
- } catch (NameNotFoundException e) {
- }
- } else if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) {
+ if (ThemesContract.Intent.ACTION_THEME_INSTALLED.equals(action)) {
+ NotificationHelper.postThemeInstalledNotification(context, pkgName);
+ } else if (ThemesContract.Intent.ACTION_THEME_REMOVED.equals(action)) {
// remove updated status for this theme (if one exists)
PreferenceUtils.removeUpdatedTheme(context, pkgName);
@@ -48,27 +34,16 @@ public class AppReceiver extends BroadcastReceiver {
String appliedBaseTheme = PreferenceUtils.getAppliedBaseTheme(context);
if (!TextUtils.isEmpty(appliedBaseTheme) && appliedBaseTheme.equals(pkgName)) {
PreferenceUtils.setAppliedBaseTheme(context,
- ThemeUtils.getDefaultThemePackageName(context));
+ ThemeUtils.getDefaultThemePackageName(context));
}
NotificationHelper.cancelNotifications(context);
- } else if (Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
+ } else if (ThemesContract.Intent.ACTION_THEME_UPDATED.equals(action)) {
try {
if (isTheme(context, pkgName)) {
PreferenceUtils.addUpdatedTheme(context, pkgName);
}
} catch (NameNotFoundException e) {
}
- } else if (Intent.ACTION_THEME_RESOURCES_CACHED.equals(action)) {
- final String themePkgName = intent.getStringExtra(Intent.EXTRA_THEME_PACKAGE_NAME);
- final int result = intent.getIntExtra(Intent.EXTRA_THEME_RESULT,
- PackageManager.INSTALL_FAILED_THEME_UNKNOWN_ERROR);
- Set<String> processingThemes =
- PreferenceUtils.getInstalledThemesBeingProcessed(context);
- if (processingThemes != null &&
- processingThemes.contains(themePkgName) && result >= 0) {
- NotificationHelper.postThemeInstalledNotification(context, themePkgName);
- PreferenceUtils.removeThemeBeingProcessed(context, themePkgName);
- }
}
}
@@ -77,9 +52,4 @@ public class AppReceiver extends BroadcastReceiver {
return pi != null && pi.themeInfo != null;
}
-
- private boolean isThemeBeingProcessed(Context context, String pkgName) {
- ThemeManager tm = (ThemeManager) context.getSystemService(Context.THEME_SERVICE);
- return tm.isThemeBeingProcessed(pkgName);
- }
}
diff --git a/src/com/cyngn/theme/chooser/ChooserActivity.java b/src/com/cyngn/theme/chooser/ChooserActivity.java
index 81ec1e2..f509fa1 100644
--- a/src/com/cyngn/theme/chooser/ChooserActivity.java
+++ b/src/com/cyngn/theme/chooser/ChooserActivity.java
@@ -869,8 +869,9 @@ public class ChooserActivity extends FragmentActivity
switch (id) {
case LOADER_ID_INSTALLED_THEMES:
mAppliedBaseTheme = PreferenceUtils.getAppliedBaseTheme(this);
- selection = ThemesColumns.PRESENT_AS_THEME + "=?";
- selectionArgs = new String[] { "1" };
+ selection = ThemesColumns.PRESENT_AS_THEME + "=? AND " +
+ ThemesColumns.INSTALL_STATE + "=?";
+ selectionArgs = new String[] { "1", "" + ThemesColumns.InstallState.INSTALLED};
// sort in ascending order but make sure the "default" theme is always first
sortOrder = "(" + ThemesColumns.IS_DEFAULT_THEME + "=1) DESC, "
+ "(" + ThemesColumns.PKG_NAME + "='" + mAppliedBaseTheme + "') DESC, "
diff --git a/src/com/cyngn/theme/util/PreferenceUtils.java b/src/com/cyngn/theme/util/PreferenceUtils.java
index a963d99..b2cc552 100644
--- a/src/com/cyngn/theme/util/PreferenceUtils.java
+++ b/src/com/cyngn/theme/util/PreferenceUtils.java
@@ -82,42 +82,6 @@ public class PreferenceUtils {
}
}
- public static Set<String> getInstalledThemesBeingProcessed(Context context) {
- SharedPreferences prefs = getSharedPreferences(context);
- if (prefs == null) return null;
-
- return prefs.getStringSet(PREF_INSTALLED_THEMES_PROCESSING, null);
- }
-
- public static void addThemeBeingProcessed(Context context, String pkgName) {
- SharedPreferences prefs = getSharedPreferences(context);
- if (prefs != null) {
- Set<String> current = prefs.getStringSet(PREF_INSTALLED_THEMES_PROCESSING, null);
- if (current == null) current = new HashSet<String>(1);
- if (current.add(pkgName)) {
- prefs.edit().putStringSet(PREF_INSTALLED_THEMES_PROCESSING, current).apply();
- }
- } else {
- Log.w(TAG, "addThemeBeingProcessed: Unable to get shared preferences");
- }
- }
-
- public static void removeThemeBeingProcessed(Context context, String pkgName) {
- SharedPreferences prefs = getSharedPreferences(context);
- if (prefs != null) {
- Set<String> updatedThemes = new HashSet<String>();
- Set<String> current = prefs.getStringSet(PREF_INSTALLED_THEMES_PROCESSING, null);
- if (current != null) {
- updatedThemes.addAll(current);
- }
- if (updatedThemes.remove(pkgName)) {
- prefs.edit().putStringSet(PREF_INSTALLED_THEMES_PROCESSING, updatedThemes).apply();
- }
- } else {
- Log.w(TAG, "removeThemeBeingProcessed: Unable to get shared preferences");
- }
- }
-
public static boolean hasThemeBeenUpdated(Context context, String pkgName) {
Set<String> updatedThemes = getUpdatedThemes(context);
return updatedThemes != null && updatedThemes.contains(pkgName);