Skip to content

Commit

Permalink
Merge pull request fixme-lausanne#77 from coredump-ch/annotations
Browse files Browse the repository at this point in the history
Add support for annotations
  • Loading branch information
rorist authored Mar 2, 2020
2 parents 4c92581 + 9cb53a2 commit df43352
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ android {
}

dependencies {
implementation "androidx.annotation:annotation:1.1.0"
}
6 changes: 6 additions & 0 deletions app/src/main/java/ch/fixme/status/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/ch/fixme/status/Net.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -87,6 +94,8 @@ public String getString() throws Throwable {
}
}

@WorkerThread
@NonNull
public Bitmap getBitmap() throws Throwable {
try {
return BitmapFactory.decodeStream(new FlushedInputStream(mInputStream));
Expand Down

0 comments on commit df43352

Please sign in to comment.