diff --git a/embedding/android/AlertNotification.java b/embedding/android/AlertNotification.java index bb52d84ac9f..16ccbf5fd55 100644 --- a/embedding/android/AlertNotification.java +++ b/embedding/android/AlertNotification.java @@ -41,6 +41,7 @@ import android.app.Notification; import android.app.NotificationManager; import android.content.Context; import android.widget.RemoteViews; +import java.text.NumberFormat; public class AlertNotification extends Notification @@ -51,6 +52,9 @@ public class AlertNotification String mTitle; boolean mProgressStyle; NotificationManager mNotificationManager; + double mPrevPercent = -1; + String mPrevAlertText = ""; + static final double UPDATE_THRESHOLD = .01; public AlertNotification(Context aContext, int aNotificationId, int aIcon, String aTitle, long aWhen) { super(aIcon, aTitle, aWhen); @@ -88,19 +92,25 @@ public class AlertNotification } String text; - if (aAlertText.length() > 0) { + double percent = 0; + if (aProgressMax > 0) + percent = ((double)aProgress / (double)aProgressMax); + + if (aAlertText.length() > 0) text = aAlertText; - } else { - int percent = 0; - if (aProgressMax > 0) - percent = (int)(100 * aProgress / aProgressMax); - text = percent + "%"; - } + else + text = NumberFormat.getPercentInstance().format(percent); + + if (mPrevAlertText.equals(text) && Math.abs(mPrevPercent - percent) < UPDATE_THRESHOLD) + return; contentView.setTextViewText(R.id.notificationText, text); contentView.setProgressBar(R.id.notificationProgressbar, (int)aProgressMax, (int)aProgress, false); // Update the notification mNotificationManager.notify(mId, this); + + mPrevPercent = percent; + mPrevAlertText = text; } }