Bug 612703 - Don't always update notification progressbars. Android only. [r=blassey, a=blocking-fennec]

This commit is contained in:
Wes Johnston 2010-12-02 13:27:26 -08:00
Родитель db36705e82
Коммит 40fb12634d
1 изменённых файлов: 17 добавлений и 7 удалений

Просмотреть файл

@ -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;
}
}