diff options
-rw-r--r-- | res/values/strings.xml | 7 | ||||
-rw-r--r-- | src/com/cyngn/theme/chooser/ChooserActivity.java | 3 | ||||
-rw-r--r-- | src/com/cyngn/theme/util/NotificationHelper.java | 28 | ||||
-rw-r--r-- | src/com/cyngn/theme/util/PreferenceUtils.java | 15 |
4 files changed, 49 insertions, 4 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index 9c57cae..b4d1c17 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -25,6 +25,13 @@ <string name="theme_installed_notification_title">%s installed</string> <string name="theme_installed_notification_text">Theme successfully installed.</string> + <!-- Note: These two are for "themes", meaning multiple themes --> + <string name="themes_installed_notification_title">%d themes installed</string> + <plurals name="themes_installed_notification_text"> + <item quantity="one">%1$s and %2$d other installed.</item> + <item quantity="other">%1$s and %2$d others installed.</item> + </plurals> + <string name="status_bar_clock_text" translatable="false">5:30</string> <string name="status_bar">Status bar</string> <string name="navigation_bar">Navigation bar</string> diff --git a/src/com/cyngn/theme/chooser/ChooserActivity.java b/src/com/cyngn/theme/chooser/ChooserActivity.java index 567cb85..6d08104 100644 --- a/src/com/cyngn/theme/chooser/ChooserActivity.java +++ b/src/com/cyngn/theme/chooser/ChooserActivity.java @@ -433,6 +433,9 @@ public class ChooserActivity extends FragmentActivity IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED); registerReceiver(mWallpaperChangeReceiver, filter); + + // clear out the newly installed themes count + PreferenceUtils.setNewlyInstalledThemeCount(this, 0); } @Override diff --git a/src/com/cyngn/theme/util/NotificationHelper.java b/src/com/cyngn/theme/util/NotificationHelper.java index bd022cd..2a83478 100644 --- a/src/com/cyngn/theme/util/NotificationHelper.java +++ b/src/com/cyngn/theme/util/NotificationHelper.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.res.Resources; import android.graphics.BitmapFactory; import android.text.TextUtils; @@ -29,6 +30,8 @@ import com.cyngn.theme.chooser.ChooserActivity; import com.cyngn.theme.chooser.R; public class NotificationHelper { + private static final int NOTIFICATION_ID = 0x434D5443; + public static void postThemeInstalledNotification(Context context, String pkgName) { String themeName = null; try { @@ -46,27 +49,44 @@ public class NotificationHelper { return; } + int themeCount = PreferenceUtils.getNewlyInstalledThemeCount(context) + 1; + Intent intent = new Intent(context, ChooserActivity.class); intent.setAction(Intent.ACTION_MAIN); intent.putExtra("pkgName", pkgName); PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT); + String title = null; + String content = null; + final Resources res = context.getResources(); + if (themeCount == 1) { + title = String.format(res.getString( + R.string.theme_installed_notification_title), themeName); + content = res.getString(R.string.theme_installed_notification_text); + } else { + title = String.format(res.getString(R.string.themes_installed_notification_title), + themeCount); + content = String.format(res.getQuantityString( + R.plurals.themes_installed_notification_text, themeCount -1), + themeName, themeCount - 1); + } NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notice = new Notification.Builder(context) .setAutoCancel(true) .setOngoing(false) - .setContentTitle(String.format( - context.getString(R.string.theme_installed_notification_title), themeName)) - .setContentText(context.getString(R.string.theme_installed_notification_text)) + .setContentTitle(title) + .setContentText(content) .setContentIntent(pi) .setSmallIcon(R.drawable.ic_notifiy) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_app_themes)) .setWhen(System.currentTimeMillis()) .build(); - nm.notify(pkgName.hashCode(), notice); + if (themeCount > 1) notice.number = themeCount; + nm.notify(NOTIFICATION_ID, notice); + PreferenceUtils.setNewlyInstalledThemeCount(context, themeCount); } public static void cancelNotificationForPackage(Context context, String pkgName) { diff --git a/src/com/cyngn/theme/util/PreferenceUtils.java b/src/com/cyngn/theme/util/PreferenceUtils.java index edbf017..6486a03 100644 --- a/src/com/cyngn/theme/util/PreferenceUtils.java +++ b/src/com/cyngn/theme/util/PreferenceUtils.java @@ -13,6 +13,7 @@ import java.util.Set; public class PreferenceUtils { 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 SharedPreferences getSharedPreferences(Context context) { if (context == null) return null; @@ -73,4 +74,18 @@ public class PreferenceUtils { Set<String> updatedThemes = getUpdatedThemes(context); return updatedThemes != null && updatedThemes.contains(pkgName); } + + public static int getNewlyInstalledThemeCount(Context context) { + SharedPreferences prefs = getSharedPreferences(context); + if (prefs == null) return 0; + + return prefs.getInt(PREF_NEWLY_INSTALLED_THEME_COUNT, 0); + } + + public static void setNewlyInstalledThemeCount(Context context, int count) { + SharedPreferences prefs = getSharedPreferences(context); + if (prefs != null) { + prefs.edit().putInt(PREF_NEWLY_INSTALLED_THEME_COUNT, count).apply(); + } + } } |