summaryrefslogtreecommitdiffstats
path: root/src/com/cyngn/theme/chooser
diff options
context:
space:
mode:
authorClark Scheff <clark@cyngn.com>2014-09-18 15:51:51 -0700
committerGerrit Code Review <gerrit@cyngn.com>2014-10-03 02:18:45 +0000
commit4658edd5edd57d75d7d2877edb4cb101a73f666b (patch)
treea0e7bc1d9ddb0e29806ea1757fe8afa6f2a0bcf6 /src/com/cyngn/theme/chooser
parentf0e9a542fe55da1d3c3509e16b71755c9c518c7c (diff)
downloadpackages_apps_ThemeChooser-4658edd5edd57d75d7d2877edb4cb101a73f666b.tar.gz
packages_apps_ThemeChooser-4658edd5edd57d75d7d2877edb4cb101a73f666b.tar.bz2
packages_apps_ThemeChooser-4658edd5edd57d75d7d2877edb4cb101a73f666b.zip
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/com/cyngn/theme/chooser')
-rw-r--r--src/com/cyngn/theme/chooser/AppReceiver.java27
-rw-r--r--src/com/cyngn/theme/chooser/ThemeFragment.java63
2 files changed, 87 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 {