Reformat DownloadService
This commit is contained in:
parent
0a8d4dd1f2
commit
a091b07cb6
1 changed files with 18 additions and 29 deletions
|
@ -29,39 +29,17 @@ import btools.util.ProgressListener;
|
||||||
public class DownloadService extends Service implements ProgressListener {
|
public class DownloadService extends Service implements ProgressListener {
|
||||||
|
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
|
public static boolean serviceState = false;
|
||||||
private ServerConfig mServerConfig;
|
private ServerConfig mServerConfig;
|
||||||
|
|
||||||
private NotificationHelper mNotificationHelper;
|
private NotificationHelper mNotificationHelper;
|
||||||
private List<String> mUrlList;
|
private List<String> mUrlList;
|
||||||
private String baseDir;
|
private String baseDir;
|
||||||
|
|
||||||
private volatile String newDownloadAction = "";
|
private volatile String newDownloadAction = "";
|
||||||
private volatile String currentDownloadOperation = "";
|
private volatile String currentDownloadOperation = "";
|
||||||
private long availableSize;
|
private long availableSize;
|
||||||
|
|
||||||
private ServiceHandler mServiceHandler;
|
private ServiceHandler mServiceHandler;
|
||||||
public static boolean serviceState = false;
|
|
||||||
private boolean bIsDownloading;
|
private boolean bIsDownloading;
|
||||||
|
|
||||||
// Handler that receives messages from the thread
|
|
||||||
private final class ServiceHandler extends Handler {
|
|
||||||
public ServiceHandler(Looper looper) {
|
|
||||||
super(looper);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
bIsDownloading = true;
|
|
||||||
downloadFiles();
|
|
||||||
|
|
||||||
stopForeground(true);
|
|
||||||
stopSelf(msg.arg1);
|
|
||||||
mNotificationHelper.stopNotification();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
if (DEBUG) Log.d("SERVICE", "onCreate");
|
if (DEBUG) Log.d("SERVICE", "onCreate");
|
||||||
|
@ -82,7 +60,6 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if (DEBUG) Log.d("SERVICE", "onStartCommand");
|
if (DEBUG) Log.d("SERVICE", "onStartCommand");
|
||||||
|
@ -105,7 +82,6 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
if (DEBUG) Log.d("SERVICE", "onDestroy");
|
if (DEBUG) Log.d("SERVICE", "onDestroy");
|
||||||
|
@ -113,13 +89,11 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void downloadFiles() {
|
public void downloadFiles() {
|
||||||
|
|
||||||
// first check lookup table and profiles
|
// first check lookup table and profiles
|
||||||
|
@ -155,7 +129,6 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
updateProgress("finished ");
|
updateProgress("finished ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void updateProgress(String progress) {
|
public void updateProgress(String progress) {
|
||||||
if (!newDownloadAction.equals(progress)) {
|
if (!newDownloadAction.equals(progress)) {
|
||||||
if (DEBUG) Log.d("BR", "up " + progress);
|
if (DEBUG) Log.d("BR", "up " + progress);
|
||||||
|
@ -466,9 +439,25 @@ public class DownloadService extends Service implements ProgressListener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isCanceled() {
|
public boolean isCanceled() {
|
||||||
return BInstallerActivity.downloadCanceled;
|
return BInstallerActivity.downloadCanceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handler that receives messages from the thread
|
||||||
|
private final class ServiceHandler extends Handler {
|
||||||
|
public ServiceHandler(Looper looper) {
|
||||||
|
super(looper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
bIsDownloading = true;
|
||||||
|
downloadFiles();
|
||||||
|
|
||||||
|
stopForeground(true);
|
||||||
|
stopSelf(msg.arg1);
|
||||||
|
mNotificationHelper.stopNotification();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue