Skip to content

Commit 991f429

Browse files
committed
Fix comments typo, rename param, refine obtainMessage
1 parent 12d75a8 commit 991f429

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

library/src/main/java/com/loopj/android/http/AsyncHttpClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public AsyncHttpClient(int httpPort, int httpsPort) {
169169
/**
170170
* Creates new AsyncHttpClient using given params
171171
*
172-
* @param fixNoHttpResponseException Whether to fix or not issue, by ommiting SSL verification
172+
* @param fixNoHttpResponseException Whether to fix issue or not, by omitting SSL verification
173173
* @param httpPort HTTP port to be used, must be greater than 0
174174
* @param httpsPort HTTPS port to be used, must be greater than 0
175175
*/
@@ -180,7 +180,7 @@ public AsyncHttpClient(boolean fixNoHttpResponseException, int httpPort, int htt
180180
/**
181181
* Returns default instance of SchemeRegistry
182182
*
183-
* @param fixNoHttpResponseException Whether to fix or not issue, by ommiting SSL verification
183+
* @param fixNoHttpResponseException Whether to fix issue or not, by omitting SSL verification
184184
* @param httpPort HTTP port to be used, must be greater than 0
185185
* @param httpsPort HTTPS port to be used, must be greater than 0
186186
*/

library/src/main/java/com/loopj/android/http/AsyncHttpResponseHandler.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,23 @@ public boolean getUseSynchronousMode() {
145145
}
146146

147147
@Override
148-
public void setUseSynchronousMode(boolean value) {
148+
public void setUseSynchronousMode(boolean sync) {
149149
// A looper must be prepared before setting asynchronous mode.
150-
if (!value && this.looper == null) {
151-
value = true;
150+
if (!sync && looper == null) {
151+
sync = true;
152152
Log.w(LOG_TAG, "Current thread has not called Looper.prepare(). Forcing synchronous mode.");
153153
}
154154

155155
// If using asynchronous mode.
156-
if (!value && handler == null) {
156+
if (!sync && handler == null) {
157157
// Create a handler on current thread to submit tasks
158-
handler = new ResponderHandler(this, this.looper);
159-
} else if (value && handler != null) {
158+
handler = new ResponderHandler(this, looper);
159+
} else if (sync && handler != null) {
160160
// TODO: Consider adding a flag to remove all queued messages.
161161
handler = null;
162162
}
163163

164-
useSynchronousMode = value;
164+
useSynchronousMode = sync;
165165
}
166166

167167
/**
@@ -357,6 +357,7 @@ protected void sendMessage(Message msg) {
357357
if (getUseSynchronousMode() || handler == null) {
358358
handleMessage(msg);
359359
} else if (!Thread.currentThread().isInterrupted()) { // do not send messages if request has been cancelled
360+
assert handler != null;
360361
handler.sendMessage(msg);
361362
}
362363
}
@@ -373,6 +374,7 @@ protected void postRunnable(Runnable runnable) {
373374
runnable.run();
374375
} else {
375376
// Otherwise, run on provided handler
377+
assert handler != null;
376378
handler.post(runnable);
377379
}
378380
}
@@ -386,17 +388,7 @@ protected void postRunnable(Runnable runnable) {
386388
* @return Message instance, should not be null
387389
*/
388390
protected Message obtainMessage(int responseMessageId, Object responseMessageData) {
389-
Message msg;
390-
if (handler == null) {
391-
msg = Message.obtain();
392-
if (msg != null) {
393-
msg.what = responseMessageId;
394-
msg.obj = responseMessageData;
395-
}
396-
} else {
397-
msg = Message.obtain(handler, responseMessageId, responseMessageData);
398-
}
399-
return msg;
391+
return Message.obtain(handler, responseMessageId, responseMessageData);
400392
}
401393

402394
@Override

0 commit comments

Comments
 (0)