update notification at most twice per second
This commit is contained in:
parent
e747f1ee37
commit
2e958ec285
@ -33,6 +33,7 @@ import android.os.Handler;
|
|||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -60,6 +61,10 @@ public class MediaScanner implements Handler.Callback {
|
|||||||
* Set by KICKSTART rpc
|
* Set by KICKSTART rpc
|
||||||
*/
|
*/
|
||||||
private boolean mIsInitialScan;
|
private boolean mIsInitialScan;
|
||||||
|
/**
|
||||||
|
* Timestamp in half-seconds since last notification
|
||||||
|
*/
|
||||||
|
private int mLastNotification;
|
||||||
/**
|
/**
|
||||||
* The id we are using for the scan notification
|
* The id we are using for the scan notification
|
||||||
*/
|
*/
|
||||||
@ -220,17 +225,21 @@ public class MediaScanner implements Handler.Callback {
|
|||||||
NotificationManager manager = (NotificationManager) mContext.getSystemService(mContext.NOTIFICATION_SERVICE);
|
NotificationManager manager = (NotificationManager) mContext.getSystemService(mContext.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
int icon = R.drawable.status_scan_0 + (stats.seen % 5);
|
int nowTime = (int)(SystemClock.uptimeMillis() / 500);
|
||||||
String title = mContext.getResources().getString(R.string.media_library_scan_running);
|
if (nowTime != mLastNotification) {
|
||||||
String content = stats.lastFile;
|
mLastNotification = nowTime;
|
||||||
|
int icon = R.drawable.status_scan_0 + (mLastNotification % 5);
|
||||||
|
String title = mContext.getResources().getString(R.string.media_library_scan_running);
|
||||||
|
String content = stats.lastFile;
|
||||||
|
|
||||||
Notification notification = new Notification.Builder(mContext)
|
Notification notification = new Notification.Builder(mContext)
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setContentText(content)
|
.setContentText(content)
|
||||||
.setSmallIcon(icon)
|
.setSmallIcon(icon)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.build();
|
.build();
|
||||||
manager.notify(NOTIFICATION_ID, notification);
|
manager.notify(NOTIFICATION_ID, notification);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
manager.cancel(NOTIFICATION_ID);
|
manager.cancel(NOTIFICATION_ID);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user