Fix performance problems with notifications freezing the phone.

I am a geraffe.
This commit is contained in:
YuviPanda 2013-01-29 14:39:04 +05:30
parent da9fb88a73
commit 6039cb3fea
3 changed files with 13 additions and 14 deletions

View file

@ -19,7 +19,7 @@
<dependency>
<groupId>org.mediawiki</groupId>
<artifactId>api</artifactId>
<version>1.1</version>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>

View file

@ -33,6 +33,8 @@ public class CommonsApplication extends Application {
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
// Fire progress callbacks for every 3% of uploaded content
System.setProperty("in.yuvi.http.fluent.PROGRESS_TRIGGER_THRESHOLD", "3.0");
api = createMWApi();
}

View file

@ -56,8 +56,6 @@ public class UploadService extends IntentService {
String notificationProgressTitle;
String notificationFinishingTitle;
private int lastPercent = 0;
public NotificationUpdateProgressListener(Notification curNotification, String notificationTag, String notificationProgressTitle, String notificationFinishingTitle) {
this.curNotification = curNotification;
this.notificationTag = notificationTag;
@ -66,22 +64,21 @@ public class UploadService extends IntentService {
}
@Override
public void onProgress(long transferred, long total) {
Log.d("Commons", String.format("Uploaded %d of %d", transferred, total));
RemoteViews curView = curNotification.contentView;
if(!notificationTitleChanged) {
curView.setTextViewText(R.id.uploadNotificationTitle, notificationProgressTitle);
notificationTitleChanged = false;
startForeground(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
notificationTitleChanged = true;
notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
return;
}
int percent =(int) ((double)transferred / (double)total * 100);
if(percent > lastPercent) {
curNotification.contentView.setProgressBar(R.id.uploadNotificationProgress, 100, percent, false);
startForeground(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
lastPercent = percent;
}
if(percent == 100) {
if(transferred == total) {
// Completed!
curView.setTextViewText(R.id.uploadNotificationTitle, notificationFinishingTitle);
startForeground(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
} else {
curNotification.contentView.setProgressBar(R.id.uploadNotificationProgress, 100, (int)(((double)transferred / (double)total) * 100), false);
notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
}
}