зеркало из https://github.com/mozilla/pjs.git
Bug 612703 - Don't always update notification progressbars. Android only. [r=blassey, a=blocking-fennec]
This commit is contained in:
Родитель
db36705e82
Коммит
40fb12634d
|
@ -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) {
|
||||
text = aAlertText;
|
||||
} else {
|
||||
int percent = 0;
|
||||
double percent = 0;
|
||||
if (aProgressMax > 0)
|
||||
percent = (int)(100 * aProgress / aProgressMax);
|
||||
text = percent + "%";
|
||||
}
|
||||
percent = ((double)aProgress / (double)aProgressMax);
|
||||
|
||||
if (aAlertText.length() > 0)
|
||||
text = aAlertText;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче