diff --git a/app/build.gradle b/app/build.gradle index 4d3059f..45dc106 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,4 +25,5 @@ android { } dependencies { + implementation "androidx.annotation:annotation:1.1.0" } diff --git a/app/src/main/java/ch/fixme/status/Main.java b/app/src/main/java/ch/fixme/status/Main.java index 36b3045..4581ac0 100644 --- a/app/src/main/java/ch/fixme/status/Main.java +++ b/app/src/main/java/ch/fixme/status/Main.java @@ -59,6 +59,8 @@ import java.util.Set; import java.util.regex.Pattern; +import androidx.annotation.UiThread; + public class Main extends Activity { // API: https://spaceapi.io/ @@ -92,6 +94,7 @@ public class Main extends Activity { private GetImage getImageTask; @Override + @UiThread public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); @@ -110,12 +113,14 @@ public void onCreate(Bundle savedInstanceState) { } @Override + @UiThread protected void onNewIntent(Intent intent) { Log.d(TAG, "onNewIntent()=" + intent); showHsInfo(intent); } @Override + @UiThread protected void onDestroy() { if (getApiTask != null) { getApiTask.cancel(true); @@ -205,6 +210,7 @@ protected Dialog onCreateDialog(int id) { } @Override + @UiThread public void startActivity(Intent intent) { // http://stackoverflow.com/questions/13691241/autolink-not-working-on-htc-htclinkifydispatcher try { diff --git a/app/src/main/java/ch/fixme/status/Net.java b/app/src/main/java/ch/fixme/status/Net.java index 9b1e490..628bac3 100644 --- a/app/src/main/java/ch/fixme/status/Net.java +++ b/app/src/main/java/ch/fixme/status/Net.java @@ -18,6 +18,9 @@ import java.net.HttpURLConnection; import java.net.URL; +import androidx.annotation.NonNull; +import androidx.annotation.WorkerThread; + // From CommonsWare and Android Blog // https://github.com/commonsguy/cw-android/tree/master/Internet // http://android-developers.blogspot.ch/2010/07/multithreading-for-performance.html @@ -31,11 +34,13 @@ public class Net { private HttpURLConnection mUrlConnection; private InputStream mInputStream; - public Net(String urlStr) throws Throwable { + @WorkerThread + public Net(@NonNull String urlStr) throws Throwable { this(urlStr, true); } - public Net(String urlStr, boolean useCache) throws Throwable { + @WorkerThread + public Net(@NonNull String urlStr, boolean useCache) throws Throwable { // Connect to URL URL url; int responseCode; @@ -70,6 +75,8 @@ public Net(String urlStr, boolean useCache) throws Throwable { mInputStream = mUrlConnection.getInputStream(); } + @WorkerThread + @NonNull public String getString() throws Throwable { try { BufferedReader r = new BufferedReader(new InputStreamReader(mInputStream)); @@ -87,6 +94,8 @@ public String getString() throws Throwable { } } + @WorkerThread + @NonNull public Bitmap getBitmap() throws Throwable { try { return BitmapFactory.decodeStream(new FlushedInputStream(mInputStream));