Skip to content

Commit bcc3eba

Browse files
committed
Merge pull request android-async-http#596 from fineswap/source-1-5-compat
Compatibility with older JDK.
2 parents 39bff98 + de17edd commit bcc3eba

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

sample/src/main/java/com/loopj/android/http/sample/IntentServiceSample.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,31 @@ public class IntentServiceSample extends SampleParentActivity {
2525
public static final String ACTION_FINISH = "SYNC_FINISH";
2626
public static final String[] ALLOWED_ACTIONS = {ACTION_START,
2727
ACTION_RETRY, ACTION_CANCEL, ACTION_SUCCESS, ACTION_FAILURE, ACTION_FINISH};
28-
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
28+
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
2929
@Override
3030
public void onReceive(Context context, Intent intent) {
31-
switch (intent.getAction()) {
32-
case ACTION_START:
33-
clearOutputs();
34-
addView(getColoredView(LIGHTBLUE, "Request started"));
35-
break;
36-
case ACTION_FINISH:
37-
addView(getColoredView(LIGHTBLUE, "Request finished"));
38-
break;
39-
case ACTION_CANCEL:
40-
addView(getColoredView(LIGHTBLUE, "Request cancelled"));
41-
break;
42-
case ACTION_RETRY:
43-
addView(getColoredView(LIGHTBLUE, "Request retried"));
44-
break;
45-
case ACTION_FAILURE:
46-
debugThrowable(LOG_TAG, (Throwable) intent.getSerializableExtra(ExampleIntentService.INTENT_THROWABLE));
47-
case ACTION_SUCCESS:
31+
String action = intent.getAction();
32+
33+
// switch() doesn't support strings in older JDK.
34+
if(ACTION_START.equals(action)) {
35+
clearOutputs();
36+
addView(getColoredView(LIGHTBLUE, "Request started"));
37+
} else if(ACTION_FINISH.equals(action)) {
38+
addView(getColoredView(LIGHTBLUE, "Request finished"));
39+
} else if(ACTION_CANCEL.equals(action)) {
40+
addView(getColoredView(LIGHTBLUE, "Request cancelled"));
41+
} else if(ACTION_RETRY.equals(action)) {
42+
addView(getColoredView(LIGHTBLUE, "Request retried"));
43+
} else if(ACTION_FAILURE.equals(action) || ACTION_SUCCESS.equals(action)) {
44+
debugThrowable(LOG_TAG, (Throwable) intent.getSerializableExtra(ExampleIntentService.INTENT_THROWABLE));
45+
if(ACTION_SUCCESS.equals(action)) {
4846
debugStatusCode(LOG_TAG, intent.getIntExtra(ExampleIntentService.INTENT_STATUS_CODE, 0));
4947
debugHeaders(LOG_TAG, IntentUtil.deserializeHeaders(intent.getStringArrayExtra(ExampleIntentService.INTENT_HEADERS)));
5048
byte[] returnedBytes = intent.getByteArrayExtra(ExampleIntentService.INTENT_DATA);
5149
if (returnedBytes != null) {
5250
debugResponse(LOG_TAG, new String(returnedBytes));
5351
}
54-
break;
52+
}
5553
}
5654
}
5755
};

sample/src/main/java/com/loopj/android/http/sample/SampleParentActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public abstract class SampleParentActivity extends Activity implements SampleInt
5050
private AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
5151
private EditText urlEditText, headersEditText, bodyEditText;
5252
private LinearLayout responseLayout;
53-
private final List<RequestHandle> requestHandles = new LinkedList<>();
53+
private final List<RequestHandle> requestHandles = new LinkedList<RequestHandle>();
5454

5555
protected static final int LIGHTGREEN = Color.parseColor("#00FF66");
5656
protected static final int LIGHTRED = Color.parseColor("#FF3300");
@@ -126,7 +126,7 @@ public void onClick(View v) {
126126
};
127127

128128
public Header[] getRequestHeaders() {
129-
List<Header> headers = new ArrayList<>();
129+
List<Header> headers = new ArrayList<Header>();
130130
String headersRaw = headersEditText.getText() == null ? null : headersEditText.getText().toString();
131131

132132
if (headersRaw != null && headersRaw.length() > 3) {

sample/src/main/java/com/loopj/android/http/sample/ThreadingTimeoutSample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public class ThreadingTimeoutSample extends SampleParentActivity {
3232

3333
private static final String LOG_TAG = "ThreadingTimeoutSample";
34-
private SparseArray<String> states = new SparseArray<>();
34+
private final SparseArray<String> states = new SparseArray<String>();
3535
private int counter = 0;
3636

3737
@Override
@@ -72,7 +72,7 @@ private synchronized void setStatus(int id, String status) {
7272
public ResponseHandlerInterface getResponseHandler() {
7373
return new AsyncHttpResponseHandler() {
7474

75-
private int id = counter++;
75+
private final int id = counter++;
7676

7777
@Override
7878
public void onStart() {

0 commit comments

Comments
 (0)