Icon fixes and general tweaks
This commit is contained in:
parent
28d683e16a
commit
f7e12b4f25
@ -5,11 +5,13 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v4.app.NotificationManagerCompat;
|
import android.support.v4.app.NotificationManagerCompat;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
@ -25,7 +27,6 @@ import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
|||||||
import com.nostra13.universalimageloader.core.assist.ImageSize;
|
import com.nostra13.universalimageloader.core.assist.ImageSize;
|
||||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||||
import com.nostra13.universalimageloader.utils.DiskCacheUtils;
|
import com.nostra13.universalimageloader.utils.DiskCacheUtils;
|
||||||
import com.nostra13.universalimageloader.utils.MemoryCacheUtils;
|
|
||||||
|
|
||||||
import org.fdroid.fdroid.data.App;
|
import org.fdroid.fdroid.data.App;
|
||||||
|
|
||||||
@ -169,14 +170,24 @@ class NotificationHelper {
|
|||||||
for (AppUpdateStatusManager.AppUpdateStatus entry : appUpdateStatusManager.getAll()) {
|
for (AppUpdateStatusManager.AppUpdateStatus entry : appUpdateStatusManager.getAll()) {
|
||||||
if (entry.status == AppUpdateStatusManager.Status.Installed) {
|
if (entry.status == AppUpdateStatusManager.Status.Installed) {
|
||||||
installed.add(entry);
|
installed.add(entry);
|
||||||
} else if (entry.status != AppUpdateStatusManager.Status.Unknown) {
|
} else if (!shouldIgnoreEntry(entry)) {
|
||||||
updates.add(entry);
|
updates.add(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldIgnoreEntry(AppUpdateStatusManager.AppUpdateStatus entry) {
|
||||||
|
// Ignore unknown status
|
||||||
|
if (entry.status == AppUpdateStatusManager.Status.Unknown)
|
||||||
|
return true;
|
||||||
|
// Ignore first time install downloads, assumed to be done from UI
|
||||||
|
else if (!entry.app.isInstalled() && (entry.status == AppUpdateStatusManager.Status.Downloading || entry.status == AppUpdateStatusManager.Status.ReadyToInstall))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void createNotification(AppUpdateStatusManager.AppUpdateStatus entry) {
|
private void createNotification(AppUpdateStatusManager.AppUpdateStatus entry) {
|
||||||
if (entry.status == AppUpdateStatusManager.Status.Unknown) {
|
if (shouldIgnoreEntry(entry)) {
|
||||||
notificationManager.cancel(entry.getUniqueKey(), NOTIFY_ID_UPDATES);
|
notificationManager.cancel(entry.getUniqueKey(), NOTIFY_ID_UPDATES);
|
||||||
notificationManager.cancel(entry.getUniqueKey(), NOTIFY_ID_INSTALLED);
|
notificationManager.cancel(entry.getUniqueKey(), NOTIFY_ID_INSTALLED);
|
||||||
return;
|
return;
|
||||||
@ -256,7 +267,7 @@ class NotificationHelper {
|
|||||||
case Downloading:
|
case Downloading:
|
||||||
return app.name;
|
return app.name;
|
||||||
case ReadyToInstall:
|
case ReadyToInstall:
|
||||||
return context.getString(app.isInstalled() ? R.string.notification_title_single_ready_to_install_update : R.string.notification_title_single_ready_to_install); // TODO - "Update"? Should just be "ready to install"?
|
return context.getString(R.string.notification_title_single_ready_to_install_update);
|
||||||
case Installing:
|
case Installing:
|
||||||
return app.name;
|
return app.name;
|
||||||
case Installed:
|
case Installed:
|
||||||
@ -272,7 +283,7 @@ class NotificationHelper {
|
|||||||
case UpdateAvailable:
|
case UpdateAvailable:
|
||||||
return app.name;
|
return app.name;
|
||||||
case Downloading:
|
case Downloading:
|
||||||
return context.getString(R.string.notification_content_single_downloading, app.name);
|
return context.getString(R.string.notification_content_single_downloading_update, app.name);
|
||||||
case ReadyToInstall:
|
case ReadyToInstall:
|
||||||
return app.name;
|
return app.name;
|
||||||
case Installing:
|
case Installing:
|
||||||
@ -280,19 +291,19 @@ class NotificationHelper {
|
|||||||
case Installed:
|
case Installed:
|
||||||
return context.getString(R.string.notification_content_single_installed);
|
return context.getString(R.string.notification_content_single_installed);
|
||||||
case InstallError:
|
case InstallError:
|
||||||
return context.getString(R.string.notification_content_single_install_error);
|
return app.name;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMultiItemContentString(App app, AppUpdateStatusManager.Status status) {
|
private String getMultiItemContentString(AppUpdateStatusManager.Status status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case UpdateAvailable:
|
case UpdateAvailable:
|
||||||
return context.getString(R.string.notification_title_summary_update_available);
|
return context.getString(R.string.notification_title_summary_update_available);
|
||||||
case Downloading:
|
case Downloading:
|
||||||
return context.getString(app.isInstalled() ? R.string.notification_title_summary_downloading_update : R.string.notification_title_summary_downloading);
|
return context.getString(R.string.notification_title_summary_downloading_update);
|
||||||
case ReadyToInstall:
|
case ReadyToInstall:
|
||||||
return context.getString(app.isInstalled() ? R.string.notification_title_summary_ready_to_install_update : R.string.notification_title_summary_ready_to_install);
|
return context.getString(R.string.notification_title_summary_ready_to_install_update);
|
||||||
case Installing:
|
case Installing:
|
||||||
return context.getString(R.string.notification_title_summary_installing);
|
return context.getString(R.string.notification_title_summary_installing);
|
||||||
case Installed:
|
case Installed:
|
||||||
@ -307,14 +318,17 @@ class NotificationHelper {
|
|||||||
App app = entry.app;
|
App app = entry.app;
|
||||||
AppUpdateStatusManager.Status status = entry.status;
|
AppUpdateStatusManager.Status status = entry.status;
|
||||||
|
|
||||||
|
int iconSmall = R.drawable.ic_launcher;
|
||||||
Bitmap iconLarge = getLargeIconForEntry(entry);
|
Bitmap iconLarge = getLargeIconForEntry(entry);
|
||||||
NotificationCompat.Builder builder =
|
NotificationCompat.Builder builder =
|
||||||
new NotificationCompat.Builder(context)
|
new NotificationCompat.Builder(context)
|
||||||
.setAutoCancel(false)
|
.setAutoCancel(true)
|
||||||
.setLargeIcon(iconLarge)
|
|
||||||
.setSmallIcon(R.drawable.ic_launcher)
|
|
||||||
.setContentTitle(getSingleItemTitleString(app, status))
|
.setContentTitle(getSingleItemTitleString(app, status))
|
||||||
.setContentText(getSingleItemContentString(app, status))
|
.setContentText(getSingleItemContentString(app, status))
|
||||||
|
.setSmallIcon(iconSmall)
|
||||||
|
.setLargeIcon(iconLarge)
|
||||||
|
.setLocalOnly(true)
|
||||||
|
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
|
||||||
.setGroup(GROUP_UPDATES);
|
.setGroup(GROUP_UPDATES);
|
||||||
|
|
||||||
// Handle intents
|
// Handle intents
|
||||||
@ -360,7 +374,7 @@ class NotificationHelper {
|
|||||||
App app = entry.app;
|
App app = entry.app;
|
||||||
AppUpdateStatusManager.Status status = entry.status;
|
AppUpdateStatusManager.Status status = entry.status;
|
||||||
|
|
||||||
String content = getMultiItemContentString(app, status);
|
String content = getMultiItemContentString(status);
|
||||||
SpannableStringBuilder sb = new SpannableStringBuilder(app.name);
|
SpannableStringBuilder sb = new SpannableStringBuilder(app.name);
|
||||||
sb.setSpan(new StyleSpan(Typeface.BOLD), 0, sb.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
sb.setSpan(new StyleSpan(Typeface.BOLD), 0, sb.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
sb.append(" ");
|
sb.append(" ");
|
||||||
@ -382,15 +396,14 @@ class NotificationHelper {
|
|||||||
|
|
||||||
NotificationCompat.Builder builder =
|
NotificationCompat.Builder builder =
|
||||||
new NotificationCompat.Builder(context)
|
new NotificationCompat.Builder(context)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(!useStackedNotifications())
|
||||||
.setSmallIcon(R.drawable.ic_launcher)
|
.setSmallIcon(R.drawable.ic_launcher)
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setContentText(text)
|
.setContentText(text)
|
||||||
.setContentIntent(piAction)
|
.setContentIntent(piAction)
|
||||||
|
.setLocalOnly(true)
|
||||||
|
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
|
||||||
.setStyle(inboxStyle);
|
.setStyle(inboxStyle);
|
||||||
if (BuildConfig.DEBUG) {
|
|
||||||
builder.setPriority(NotificationCompat.PRIORITY_LOW); // To make not at top of list!
|
|
||||||
}
|
|
||||||
if (useStackedNotifications()) {
|
if (useStackedNotifications()) {
|
||||||
builder.setGroup(GROUP_UPDATES)
|
builder.setGroup(GROUP_UPDATES)
|
||||||
.setGroupSummary(true);
|
.setGroupSummary(true);
|
||||||
@ -409,15 +422,16 @@ class NotificationHelper {
|
|||||||
new NotificationCompat.Builder(context)
|
new NotificationCompat.Builder(context)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setLargeIcon(iconLarge)
|
.setLargeIcon(iconLarge)
|
||||||
.setSmallIcon(R.drawable.ic_stat_notify_updates)
|
.setSmallIcon(R.drawable.ic_launcher)
|
||||||
.setContentTitle(app.name)
|
.setContentTitle(app.name)
|
||||||
.setContentText(context.getString(R.string.notification_content_single_installed))
|
.setContentText(context.getString(R.string.notification_content_single_installed))
|
||||||
|
.setLocalOnly(true)
|
||||||
|
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
|
||||||
.setGroup(GROUP_INSTALLED);
|
.setGroup(GROUP_INSTALLED);
|
||||||
|
|
||||||
PackageManager pm = context.getPackageManager();
|
if (entry.intent != null) {
|
||||||
Intent intentObject = pm.getLaunchIntentForPackage(app.packageName);
|
builder.setContentIntent(entry.intent);
|
||||||
PendingIntent piAction = PendingIntent.getActivity(context, 0, intentObject, 0);
|
}
|
||||||
builder.setContentIntent(piAction);
|
|
||||||
|
|
||||||
Intent intentDeleted = new Intent(BROADCAST_NOTIFICATIONS_INSTALLED_CLEARED);
|
Intent intentDeleted = new Intent(BROADCAST_NOTIFICATIONS_INSTALLED_CLEARED);
|
||||||
intentDeleted.putExtra(EXTRA_NOTIFICATION_KEY, entry.getUniqueKey());
|
intentDeleted.putExtra(EXTRA_NOTIFICATION_KEY, entry.getUniqueKey());
|
||||||
@ -452,11 +466,13 @@ class NotificationHelper {
|
|||||||
|
|
||||||
NotificationCompat.Builder builder =
|
NotificationCompat.Builder builder =
|
||||||
new NotificationCompat.Builder(context)
|
new NotificationCompat.Builder(context)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(!useStackedNotifications())
|
||||||
.setSmallIcon(R.drawable.ic_launcher)
|
.setSmallIcon(R.drawable.ic_launcher)
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setContentText(text)
|
.setContentText(text)
|
||||||
.setContentIntent(piAction);
|
.setContentIntent(piAction)
|
||||||
|
.setLocalOnly(true)
|
||||||
|
.setVisibility(NotificationCompat.VISIBILITY_SECRET);
|
||||||
if (useStackedNotifications()) {
|
if (useStackedNotifications()) {
|
||||||
builder.setGroup(GROUP_INSTALLED)
|
builder.setGroup(GROUP_INSTALLED)
|
||||||
.setGroupSummary(true);
|
.setGroupSummary(true);
|
||||||
@ -482,7 +498,16 @@ class NotificationHelper {
|
|||||||
private Bitmap getLargeIconForEntry(AppUpdateStatusManager.AppUpdateStatus entry) {
|
private Bitmap getLargeIconForEntry(AppUpdateStatusManager.AppUpdateStatus entry) {
|
||||||
final Point largeIconSize = getLargeIconSize();
|
final Point largeIconSize = getLargeIconSize();
|
||||||
Bitmap iconLarge = null;
|
Bitmap iconLarge = null;
|
||||||
if (DiskCacheUtils.findInCache(entry.app.iconUrl, ImageLoader.getInstance().getDiskCache()) != null) {
|
if (entry.status == AppUpdateStatusManager.Status.Downloading || entry.status == AppUpdateStatusManager.Status.Installing) {
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(largeIconSize.x, largeIconSize.y, Bitmap.Config.ARGB_8888);
|
||||||
|
Canvas canvas = new Canvas(bitmap);
|
||||||
|
Drawable downloadIcon = VectorDrawableCompat.create(context.getResources(), R.drawable.ic_notification_download, context.getTheme());
|
||||||
|
if (downloadIcon != null) {
|
||||||
|
downloadIcon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||||
|
downloadIcon.draw(canvas);
|
||||||
|
}
|
||||||
|
return bitmap;
|
||||||
|
} else if (DiskCacheUtils.findInCache(entry.app.iconUrl, ImageLoader.getInstance().getDiskCache()) != null) {
|
||||||
iconLarge = ImageLoader.getInstance().loadImageSync(entry.app.iconUrl, new ImageSize(largeIconSize.x, largeIconSize.y), displayImageOptions);
|
iconLarge = ImageLoader.getInstance().loadImageSync(entry.app.iconUrl, new ImageSize(largeIconSize.x, largeIconSize.y), displayImageOptions);
|
||||||
} else {
|
} else {
|
||||||
// Load it for later!
|
// Load it for later!
|
||||||
|
13
app/src/main/res/drawable/ic_notification_download.xml
Normal file
13
app/src/main/res/drawable/ic_notification_download.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<vector android:height="36dp" android:viewportHeight="90.0"
|
||||||
|
android:viewportWidth="90.0" android:width="36dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillAlpha="1" android:fillColor="#0066cc"
|
||||||
|
android:pathData="m45,7.73c-20.57,0 -37.27,16.7 -37.27,37.27 0,20.57 16.7,37.27 37.27,37.27 20.57,0 37.27,-16.7 37.27,-37.27 0,-20.57 -16.7,-37.27 -37.27,-37.27z"
|
||||||
|
android:strokeAlpha="1" android:strokeColor="#00000000"
|
||||||
|
android:strokeLineCap="butt" android:strokeLineJoin="miter" android:strokeWidth="2"/>
|
||||||
|
<path android:fillAlpha="1" android:fillColor="#ffffff"
|
||||||
|
android:pathData="M30.78,56.85h27.97v4.04h-27.97z"
|
||||||
|
android:strokeAlpha="1" android:strokeColor="#00000000" android:strokeWidth="2"/>
|
||||||
|
<path android:fillAlpha="1" android:fillColor="#ffffff"
|
||||||
|
android:pathData="m38.8,26.93 l0,12.18 -7.71,0 13.86,13.57 13.86,-13.57 -7.83,0 0,-12.18z"
|
||||||
|
android:strokeAlpha="1" android:strokeColor="#00000000" android:strokeWidth="2"/>
|
||||||
|
</vector>
|
@ -401,19 +401,16 @@
|
|||||||
<!-- notifications -->
|
<!-- notifications -->
|
||||||
<string name="notification_summary_more">+%1$d more…</string>
|
<string name="notification_summary_more">+%1$d more…</string>
|
||||||
<string name="notification_title_single_update_available">Update Available</string>
|
<string name="notification_title_single_update_available">Update Available</string>
|
||||||
<string name="notification_title_single_ready_to_install">Ready to install</string>
|
|
||||||
<string name="notification_title_single_ready_to_install_update">Update ready to install</string>
|
<string name="notification_title_single_ready_to_install_update">Update ready to install</string>
|
||||||
<string name="notification_title_single_install_error">Install Failed</string>
|
<string name="notification_title_single_install_error">Install Failed</string>
|
||||||
<string name="notification_content_single_downloading">Downloading update for \"%1$s\"…</string>
|
<string name="notification_content_single_downloading_update">Downloading update for \"%1$s\"…</string>
|
||||||
<string name="notification_content_single_installing">Installing \"%1$s\"…</string>
|
<string name="notification_content_single_installing">Installing \"%1$s\"…</string>
|
||||||
<string name="notification_content_single_installed">Successfully installed</string>
|
<string name="notification_content_single_installed">Successfully installed</string>
|
||||||
<string name="notification_content_single_install_error">Install Failed</string>
|
<string name="notification_content_single_install_error">Install Failed</string>
|
||||||
<string name="notification_summary_updates">%1$d Updates</string>
|
<string name="notification_summary_updates">%1$d Updates</string>
|
||||||
<string name="notification_summary_installed">%1$d Apps Installed</string>
|
<string name="notification_summary_installed">%1$d Apps Installed</string>
|
||||||
<string name="notification_title_summary_update_available">Update available</string>
|
<string name="notification_title_summary_update_available">Update available</string>
|
||||||
<string name="notification_title_summary_downloading">Downloading…</string>
|
|
||||||
<string name="notification_title_summary_downloading_update">Downloading update…</string>
|
<string name="notification_title_summary_downloading_update">Downloading update…</string>
|
||||||
<string name="notification_title_summary_ready_to_install">Ready to install</string>
|
|
||||||
<string name="notification_title_summary_ready_to_install_update">Update ready to install</string>
|
<string name="notification_title_summary_ready_to_install_update">Update ready to install</string>
|
||||||
<string name="notification_title_summary_installing">Installing</string>
|
<string name="notification_title_summary_installing">Installing</string>
|
||||||
<string name="notification_title_summary_installed">Successfully installed</string>
|
<string name="notification_title_summary_installed">Successfully installed</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user