本文整理汇总了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;
}