diff options
author | Clark Scheff <clark@cyngn.com> | 2014-09-18 15:51:51 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyngn.com> | 2014-10-03 02:18:45 +0000 |
commit | 4658edd5edd57d75d7d2877edb4cb101a73f666b (patch) | |
tree | a0e7bc1d9ddb0e29806ea1757fe8afa6f2a0bcf6 /src | |
parent | f0e9a542fe55da1d3c3509e16b71755c9c518c7c (diff) | |
download | packages_apps_ThemeChooser-4658edd5edd57d75d7d2877edb4cb101a73f666b.zip packages_apps_ThemeChooser-4658edd5edd57d75d7d2877edb4cb101a73f666b.tar.gz packages_apps_ThemeChooser-4658edd5edd57d75d7d2877edb4cb101a73f666b.tar.bz2 |
Add handling of themes that are being processed
When a theme is still being processed by the ThemeService we show
a "processing" overlay to let the user know their theme is not
quite ready to be applied. Once the theme is done processing the
overlay fades out and the user can apply the theme.
We also do not show the "theme installed" notification for a theme
that is being processed until it is finished processing.
Change-Id: I0486da3a5e2d0b55c2b3828613ace7e2ccf460a2
Diffstat (limited to 'src')
-rw-r--r-- | src/com/cyngn/theme/chooser/AppReceiver.java | 27 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/ThemeFragment.java | 63 | ||||
-rw-r--r-- | src/com/cyngn/theme/util/PreferenceUtils.java | 39 |
3 files changed, 126 insertions, 3 deletions
diff --git a/src/com/cyngn/theme/chooser/AppReceiver.java b/src/com/cyngn/theme/chooser/AppReceiver.java index 2ef37e1..257aa65 100644 --- a/src/com/cyngn/theme/chooser/AppReceiver.java +++ b/src/com/cyngn/theme/chooser/AppReceiver.java @@ -7,11 +7,15 @@ 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.res.ThemeManager; import android.net.Uri; import com.cyngn.theme.util.NotificationHelper; import com.cyngn.theme.util.PreferenceUtils; +import java.util.Set; + public class AppReceiver extends BroadcastReceiver { @Override @@ -24,7 +28,12 @@ public class AppReceiver extends BroadcastReceiver { if (Intent.ACTION_PACKAGE_ADDED.equals(action) && !isReplacing) { try { if (isTheme(context, pkgName)) { - NotificationHelper.postThemeInstalledNotification(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) { } @@ -43,6 +52,17 @@ public class AppReceiver extends BroadcastReceiver { } } 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); + } } } @@ -57,4 +77,9 @@ public class AppReceiver extends BroadcastReceiver { return false; } + + 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/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java index e767235..3bfcb30 100644 --- a/src/com/cyngn/theme/chooser/ThemeFragment.java +++ b/src/com/cyngn/theme/chooser/ThemeFragment.java @@ -104,7 +104,7 @@ import static android.provider.ThemesContract.ThemesColumns.MODIFIES_ICONS; import static android.provider.ThemesContract.ThemesColumns.MODIFIES_FONTS; public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor>, - ThemeManager.ThemeChangeListener { + ThemeManager.ThemeChangeListener, ThemeManager.ThemeProcessingListener { private static final String TAG = ThemeFragment.class.getSimpleName(); public static final int ANIMATE_START_DELAY = 200; @@ -253,6 +253,9 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb protected View mCustomizeButton; protected View mDismissButton; + // Processing theme layout + protected View mProcessingThemeLayout; + protected ThemeTagLayout mThemeTagLayout; protected View mClickableView; @@ -449,6 +452,8 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb mCustomizeButton = mCustomizeResetLayout.findViewById(R.id.btn_customize); mCustomizeButton.setOnClickListener(mCustomizeResetClickListener); + mProcessingThemeLayout = v.findViewById(R.id.processing_theme_layout); + if (mPkgName.equals(ThemeUtils.getDefaultThemePackageName(getActivity()))) { mThemeTagLayout.setDefaultTagEnabled(true); } @@ -475,11 +480,40 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb } @Override + public void onResume() { + super.onResume(); + ThemeManager tm = getThemeManager(); + if (tm != null) { + final String pkgName = mBaseThemePkgName != null ? mBaseThemePkgName : mPkgName; + if (tm.isThemeBeingProcessed(pkgName)) { + tm.registerProcessingListener(this); + mProcessingThemeLayout.setVisibility(View.VISIBLE); + mCustomize.setVisibility(View.INVISIBLE); + mCustomize.setAlpha(0f); + if (mDelete.getVisibility() != View.GONE) { + mDelete.setVisibility(View.INVISIBLE); + mDelete.setAlpha(0f); + } + } else { + mCustomize.setVisibility(View.VISIBLE); + mCustomize.setAlpha(1f); + if (mDelete.getVisibility() != View.GONE) { + mDelete.setVisibility(View.VISIBLE); + mDelete.setAlpha(1f); + } + } + } + } + + @Override public void onDestroy() { super.onDestroy(); freeMediaPlayers(); ThemeManager tm = getThemeManager(); - if (tm != null) tm.removeClient(this); + if (tm != null) { + tm.removeClient(this); + tm.unregisterProcessingListener(this); + } } @Override @@ -505,6 +539,28 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb } @Override + public void onFinishedProcessing(String pkgName) { + if (pkgName.equals(mPkgName) || pkgName.equals(mBaseThemePkgName)) { + if (mProcessingThemeLayout.getVisibility() == View.VISIBLE) { + mProcessingThemeLayout.animate().alpha(0).withEndAction(new Runnable() { + @Override + public void run() { + mProcessingThemeLayout.setVisibility(View.GONE); + } + }).setDuration(ANIMATE_APPLY_LAYOUT_DURATION).start(); + mCustomize.setVisibility(View.VISIBLE); + mCustomize.animate().alpha(1f).setDuration(ANIMATE_APPLY_LAYOUT_DURATION).start(); + mOverflow.setVisibility(View.VISIBLE); + mOverflow.animate().alpha(1f).setDuration(ANIMATE_APPLY_LAYOUT_DURATION).start(); + } + ThemeManager tm = getThemeManager(); + if (tm != null) { + tm.unregisterProcessingListener(this); + } + } + } + + @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); if (mThemeTagLayout == null) return; @@ -675,6 +731,9 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb } public void performClick(boolean clickedOnContent) { + // Don't do anything if the theme is being processed + if (mProcessingThemeLayout.getVisibility() == View.VISIBLE) return; + if (clickedOnContent) { showApplyThemeOverlay(); } else { diff --git a/src/com/cyngn/theme/util/PreferenceUtils.java b/src/com/cyngn/theme/util/PreferenceUtils.java index 6b3417d..5e81a9a 100644 --- a/src/com/cyngn/theme/util/PreferenceUtils.java +++ b/src/com/cyngn/theme/util/PreferenceUtils.java @@ -9,14 +9,18 @@ import android.content.pm.ThemeUtils; import android.content.res.Resources; import android.content.res.ThemeConfig; import android.text.TextUtils; +import android.util.Log; import java.util.HashSet; import java.util.Set; public class PreferenceUtils { + private static final String TAG = PreferenceUtils.class.getSimpleName(); + public static final String PREF_APPLIED_BASE_THEME = "applied_base_theme"; public static final String PREF_UPDATED_THEMES = "updated_themes"; public static final String PREF_NEWLY_INSTALLED_THEME_COUNT = "newly_installed_theme_count"; + public static final String PREF_INSTALLED_THEMES_PROCESSING = "installed_themes_processing"; public static SharedPreferences getSharedPreferences(Context context) { if (context == null) return null; @@ -77,6 +81,41 @@ 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.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); |