本文整理匯總了Java中com.lzy.okgo.adapter.Call類的典型用法代碼示例。如果您正苦於以下問題:Java Call類的具體用法?Java Call怎麽用?Java Call使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Call類屬於com.lzy.okgo.adapter包,在下文中一共展示了Call類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: btn2
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
@OnClick(R.id.btn2)
public void btn2(View view) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Call<JSONObject> adapt = OkGo.<JSONObject>get(Urls.URL_JSONOBJECT).adapt();
Response<JSONObject> response = adapt.execute();
System.out.println("body " + response.body());
Throwable exception = response.getException();
if (exception != null) exception.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
示例2: generateCall
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
/** 根據當前的請求參數,生成對應的 Call 任務 */
public okhttp3.Call generateCall(Request request) {
mRequest = request;
//如果當前這個請求沒有重新設置自己的各超時時間,則仍然使用已有的okHttpClient來發起請求
if (readTimeOut <= 0 && writeTimeOut <= 0 && connectTimeout <= 0 && interceptors.size() == 0) {
return OkGo.getInstance().getOkHttpClient().newCall(request);
}
else {
//當前本次請求有設置自己的各超時時間,則為了不覆蓋OkGo中的okHttpClient的通用設置而是繼承通用okHttpClient的配置,而新建一個okHttpClient發起請求
OkHttpClient.Builder newClientBuilder = OkGo.getInstance().getOkHttpClient().newBuilder();
if (readTimeOut > 0) newClientBuilder.readTimeout(readTimeOut, TimeUnit.MILLISECONDS);
if (writeTimeOut > 0) newClientBuilder.writeTimeout(writeTimeOut, TimeUnit.MILLISECONDS);
if (connectTimeout > 0) newClientBuilder.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS);
if (interceptors.size() > 0) {
for (Interceptor interceptor : interceptors) {
newClientBuilder.addInterceptor(interceptor);
}
}
return newClientBuilder.build().newCall(request);
}
}
示例3: subscribeActual
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
@Override
protected void subscribeActual(Observer<? super Response<T>> observer) {
// Since Call is a one-shot type, clone it for each new observer.
Call<T> call = originalCall.clone();
observer.onSubscribe(new CallDisposable(call));
boolean terminated = false;
try {
Response<T> response = call.execute();
if (!call.isCanceled()) {
observer.onNext(response);
}
if (!call.isCanceled()) {
terminated = true;
observer.onComplete();
}
} catch (Throwable t) {
Exceptions.throwIfFatal(t);
if (terminated) {
RxJavaPlugins.onError(t);
} else if (!call.isCanceled()) {
try {
observer.onError(t);
} catch (Throwable inner) {
Exceptions.throwIfFatal(inner);
RxJavaPlugins.onError(new CompositeException(t, inner));
}
}
}
}
示例4: subscribeActual
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
@Override
protected void subscribeActual(Observer<? super Response<T>> observer) {
// Since Call is a one-shot type, clone it for each new observer.
Call<T> call = originalCall.clone();
CallCallback<T> callback = new CallCallback<>(call, observer);
observer.onSubscribe(callback);
call.execute(callback);
}
示例5: analysis
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
static <T> Observable<Response<T>> analysis(Call<T> call, AdapterParam param) {
Observable<Response<T>> observable;
if (param == null) param = new AdapterParam();
if (param.isAsync) {
observable = new CallEnqueueObservable<>(call);
} else {
observable = new CallExecuteObservable<>(call);
}
return observable;
}
示例6: sync
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
@OnClick(R.id.sync)
public void sync(View view) {
new Thread(new Runnable() {
@Override
public void run() {
try {
// //同步會阻塞主線程,必須開線程
// Response response = OkGo.get(Urls.URL_JSONOBJECT)//
// .tag(this)//
// .headers("header1", "headerValue1")//
// .params("param1", "paramValue1")//
// .execute(); //不傳callback即為同步請求
Call<String> call = OkGo.<String>get(Urls.URL_JSONOBJECT)//
.tag(this)//
.headers("header1", "headerValue1")//
.params("param1", "paramValue1")//
.converter(new StringConvert())//
.adapt();
Response<String> response = call.execute();
Message message = Message.obtain();
message.obj = response.body();
handler.sendMessage(message);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
示例7: CallArbiter
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
CallArbiter(Call<T> call, Subscriber<? super Response<T>> subscriber) {
super(STATE_WAITING);
responseList = new LinkedList<>();
this.call = call;
this.subscriber = subscriber;
}
示例8: analysis
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
static <T> Observable.OnSubscribe<Response<T>> analysis(Call<T> call, AdapterParam param) {
Observable.OnSubscribe<Response<T>> onSubscribe;
if (param == null) param = new AdapterParam();
if (param.isAsync) {
onSubscribe = new CallEnqueueOnSubscribe<>(call);
} else {
onSubscribe = new CallExecuteOnSubscribe<>(call);
}
return onSubscribe;
}
示例9: getRawCall
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
/** 獲取okhttp的同步call對象 */
public okhttp3.Call getRawCall() {
//構建請求體,返回call對象
RequestBody requestBody = generateRequestBody();
if (requestBody != null) {
ProgressRequestBody<T> progressRequestBody = new ProgressRequestBody<>(requestBody, callback);
progressRequestBody.setInterceptor(uploadInterceptor);
mRequest = generateRequest(progressRequestBody);
} else {
mRequest = generateRequest(null);
}
if (client == null) client = OkGo.getInstance().getOkHttpClient();
return client.newCall(mRequest);
}
示例10: adapt
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
/** Rx支持,獲取同步call對象 */
public Call<T> adapt() {
if (call == null) {
return new CacheCall<>(this);
} else {
return call;
}
}
示例11: execute
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
/** 非阻塞方法,異步請求,但是回調在子線程中執行 */
public void execute(Callback<T> callback) {
HttpUtils.checkNotNull(callback, "callback == null");
this.callback = callback;
Call<T> call = adapt();
call.execute(callback);
}
示例12: getCall
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
/** 獲取同步call對象 */
public okhttp3.Call getCall() {
//構建請求體,返回call對象
RequestBody requestBody = generateRequestBody();
mRequest = generateRequest(wrapRequestBody(requestBody));
return generateCall(mRequest);
}
示例13: CallExecuteObservable
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
public CallExecuteObservable(Call<T> originalCall) {
this.originalCall = originalCall;
}
示例14: CallDisposable
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
CallDisposable(Call<?> call) {
this.call = call;
}
示例15: CallEnqueueObservable
import com.lzy.okgo.adapter.Call; //導入依賴的package包/類
public CallEnqueueObservable(Call<T> originalCall) {
this.originalCall = originalCall;
}