Use SystemClock.sleep instead of Thread.sleep.

Gets rid of all those pointless InterruptedException catching.

(cherry picked from commit 6acaa2b)
This commit is contained in:
Johannes Mockenhaupt 2017-09-06 20:00:36 +02:00
parent c50fad81bb
commit 5c3ec9a086
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
15 changed files with 33 additions and 80 deletions

View file

@ -4,6 +4,7 @@ import android.app.Application;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
@ -167,10 +168,7 @@ public class MainApp extends Application {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
SystemClock.sleep(5000);
PumpInterface pump = MainApp.getConfigBuilder();
if (pump != null)
pump.refreshDataFromPump("Initialization");

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.NSClientInternal;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import com.j256.ormlite.dao.CloseableIterator;
@ -35,10 +36,7 @@ public class UploadQueue {
if (NSClientService.handler == null) {
Context context = MainApp.instance();
context.startService(new Intent(context, NSClientService.class));
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
SystemClock.sleep(2000);
}
}

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.Overview.Dialogs;
import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
@ -156,11 +157,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
SystemClock.sleep(5000);
BolusProgressDialog.bolusEnded = true;
Activity activity = getActivity();
if (activity != null) {

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.PumpDanaR;
import android.bluetooth.BluetoothSocket;
import android.os.SystemClock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -170,10 +171,7 @@ public class SerialIOThread extends Thread {
}
}
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
SystemClock.sleep(200);
if (!message.received) {
log.warn("Reply not received " + message.getMessageName());
if (message.getCommand() == 0xF0F1) {

View file

@ -11,6 +11,7 @@ import android.content.IntentFilter;
import android.os.Binder;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.SystemClock;
import com.squareup.otto.Subscribe;
@ -552,10 +553,6 @@ public class DanaRExecutionService extends Service {
}
private void waitMsec(long msecs) {
try {
Thread.sleep(msecs);
} catch (InterruptedException e) {
e.printStackTrace();
}
SystemClock.sleep(msecs);
}
}

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.PumpDanaRKorean;
import android.bluetooth.BluetoothSocket;
import android.os.SystemClock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -171,10 +172,7 @@ public class SerialIOThread extends Thread {
}
}
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
SystemClock.sleep(200);
if (!message.received) {
log.warn("Reply not received " + message.getMessageName());
if (message.getCommand() == 0xF0F1) {

View file

@ -11,6 +11,7 @@ import android.content.IntentFilter;
import android.os.Binder;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.SystemClock;
import com.squareup.otto.Subscribe;
@ -524,10 +525,6 @@ public class DanaRKoreanExecutionService extends Service {
}
private void waitMsec(long msecs) {
try {
Thread.sleep(msecs);
} catch (InterruptedException e) {
e.printStackTrace();
}
SystemClock.sleep(msecs);
}
}

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.PumpDanaRv2;
import android.bluetooth.BluetoothSocket;
import android.os.SystemClock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -171,10 +172,7 @@ public class SerialIOThread extends Thread {
}
}
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
SystemClock.sleep(200);
if (!message.received) {
log.warn("Reply not received " + message.getMessageName());
if (message.getCommand() == 0xF0F1) {

View file

@ -11,6 +11,7 @@ import android.content.IntentFilter;
import android.os.Binder;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.SystemClock;
import com.squareup.otto.Subscribe;
@ -554,10 +555,6 @@ public class DanaRv2ExecutionService extends Service {
}
private void waitMsec(long msecs) {
try {
Thread.sleep(msecs);
} catch (InterruptedException e) {
e.printStackTrace();
}
SystemClock.sleep(msecs);
}
}

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.PumpVirtual;
import android.content.SharedPreferences;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import org.json.JSONException;
@ -222,28 +223,19 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
Double delivering = 0d;
while (delivering < detailedBolusInfo.insulin) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
SystemClock.sleep(200);
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), delivering);
bolusingEvent.percent = Math.min((int) (delivering / detailedBolusInfo.insulin * 100), 100);
MainApp.bus().post(bolusingEvent);
delivering += 0.1d;
}
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
SystemClock.sleep(200);
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivered), detailedBolusInfo.insulin);
bolusingEvent.percent = 100;
MainApp.bus().post(bolusingEvent);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
SystemClock.sleep(1000);
if (Config.logPumpComm)
log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui());

View file

@ -2,6 +2,7 @@ package info.nightscout.utils;
import android.app.Activity;
import android.content.DialogInterface;
import android.os.SystemClock;
import android.support.v7.app.AlertDialog;
import android.support.v7.view.ContextThemeWrapper;
import android.text.Spanned;
@ -28,10 +29,7 @@ public class OKDialog {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (runnable != null) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
SystemClock.sleep(100);
activity.runOnUiThread(runnable);
}
}
@ -52,10 +50,7 @@ public class OKDialog {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (runnable != null) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
SystemClock.sleep(100);
activity.runOnUiThread(runnable);
}
}

View file

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.app.NotificationCompat;
@ -400,11 +401,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
@Override
public void run() {
try {
Thread.sleep(seconds * 1000);
} catch (InterruptedException e) {
//e.printStackTrace();
}
SystemClock.sleep(seconds * 1000);
synchronized (this) {
if(valid) {
NotificationManagerCompat notificationManager =

View file

@ -15,6 +15,7 @@ import android.graphics.Rect;
import android.graphics.Shader;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
@ -473,11 +474,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
setIsAnimated(true);
for (int i = 0; i <= 8 * 1000 / 40; i++) {
updateRainbow();
try {
Thread.sleep(40);
} catch (InterruptedException e) {
e.printStackTrace();
}
SystemClock.sleep(40);
}
mSgv.getPaint().setShader(null);
setIsAnimated(false);

View file

@ -15,6 +15,7 @@ import android.graphics.RectF;
import android.graphics.Shader;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.support.wearable.watchface.WatchFaceStyle;
@ -504,11 +505,7 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh
setIsAnimated(true);
for (int i = 0; i <= 8 * 1000 / 40; i++) {
animationStep();
try {
Thread.sleep(40);
} catch (InterruptedException e) {
log.error("Unhandled exception", e);
}
SystemClock.sleep(40);
}
setIsAnimated(false);
prepareDrawTime();

View file

@ -15,6 +15,7 @@ import android.graphics.Rect;
import android.graphics.Shader;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
@ -427,11 +428,7 @@ public class NOChart extends WatchFace implements SharedPreferences.OnSharedPref
setIsAnimated(true);
for (int i = 0; i <= 8 * 1000 / 40; i++) {
updateRainbow();
try {
Thread.sleep(40);
} catch (InterruptedException e) {
log.error("Unhandled exception", e);
}
SystemClock.sleep(40);
}
mSgv.getPaint().setShader(null);
setIsAnimated(false);