本文整理汇总了Java中com.lzy.okgo.model.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于com.lzy.okgo.model包,在下文中一共展示了Response类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: btn2
import com.lzy.okgo.model.Response; //导入依赖的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();
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:TestActivity.java
示例2: onNext
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@Override
public void onNext(Response<R> response) {
if (response.isSuccessful()) {
subscriber.onNext(response.body());
} else {
subscriberTerminated = true;
Throwable t = new HttpException(response);
try {
subscriber.onError(t);
} catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException e) {
RxJavaHooks.getOnError().call(e);
} catch (Throwable inner) {
Exceptions.throwIfFatal(inner);
RxJavaHooks.getOnError().call(new CompositeException(t, inner));
}
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:BodyOnSubscribe.java
示例3: onAnalysisResponse
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@Override
public boolean onAnalysisResponse(final Call call, final okhttp3.Response response) {
if (response.code() != 304) return false;
if (cacheEntity == null) {
final Response<T> error = Response.error(true, call, response, CacheException.NON_AND_304(request.getCacheKey()));
runOnUiThread(new Runnable() {
@Override
public void run() {
mCallback.onError(error);
mCallback.onFinish();
}
});
} else {
final Response<T> success = Response.success(true, cacheEntity.getData(), call, response);
runOnUiThread(new Runnable() {
@Override
public void run() {
mCallback.onCacheSuccess(success);
mCallback.onFinish();
}
});
}
return true;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:DefaultCachePolicy.java
示例4: requestSync
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@Override
public Response<T> requestSync(CacheEntity<T> cacheEntity) {
try {
prepareRawCall();
} catch (Throwable throwable) {
return Response.error(false, rawCall, null, throwable);
}
Response<T> response = requestNetworkSync();
//HTTP cache protocol
if (response.isSuccessful() && response.code() == 304) {
if (cacheEntity == null) {
response = Response.error(true, rawCall, response.getRawResponse(), CacheException.NON_AND_304(request.getCacheKey()));
} else {
response = Response.success(true, cacheEntity.getData(), rawCall, response.getRawResponse());
}
}
return response;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:DefaultCachePolicy.java
示例5: requestAsync
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@Override
public void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback) {
mCallback = callback;
runOnUiThread(new Runnable() {
@Override
public void run() {
mCallback.onStart(request);
try {
prepareRawCall();
} catch (Throwable throwable) {
Response<T> error = Response.error(false, rawCall, null, throwable);
mCallback.onError(error);
return;
}
requestNetworkAsync();
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:DefaultCachePolicy.java
示例6: requestSync
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@Override
public Response<T> requestSync(CacheEntity<T> cacheEntity) {
try {
prepareRawCall();
} catch (Throwable throwable) {
return Response.error(false, rawCall, null, throwable);
}
//同步请求,不能返回两次,只返回正确的数据
Response<T> response;
if (cacheEntity != null) {
response = Response.success(true, cacheEntity.getData(), rawCall, null);
}
response = requestNetworkSync();
if (!response.isSuccessful() && cacheEntity != null) {
response = Response.success(true, cacheEntity.getData(), rawCall, response.getRawResponse());
}
return response;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:FirstCacheRequestPolicy.java
示例7: requestAsync
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@Override
public void requestAsync(final CacheEntity<T> cacheEntity, Callback<T> callback) {
mCallback = callback;
runOnUiThread(new Runnable() {
@Override
public void run() {
mCallback.onStart(request);
try {
prepareRawCall();
} catch (Throwable throwable) {
Response<T> error = Response.error(false, rawCall, null, throwable);
mCallback.onError(error);
return;
}
if (cacheEntity != null) {
Response<T> success = Response.success(true, cacheEntity.getData(), rawCall, null);
mCallback.onCacheSuccess(success);
}
requestNetworkAsync();
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:FirstCacheRequestPolicy.java
示例8: requestSync
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@Override
public Response<T> requestSync(CacheEntity<T> cacheEntity) {
try {
prepareRawCall();
} catch (Throwable throwable) {
return Response.error(false, rawCall, null, throwable);
}
Response<T> response = null;
if (cacheEntity != null) {
response = Response.success(true, cacheEntity.getData(), rawCall, null);
}
if (response == null) {
response = requestNetworkSync();
}
return response;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:NoneCacheRequestPolicy.java
示例9: requestAsync
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@Override
public void requestAsync(final CacheEntity<T> cacheEntity, Callback<T> callback) {
mCallback = callback;
runOnUiThread(new Runnable() {
@Override
public void run() {
mCallback.onStart(request);
try {
prepareRawCall();
} catch (Throwable throwable) {
Response<T> error = Response.error(false, rawCall, null, throwable);
mCallback.onError(error);
return;
}
if (cacheEntity != null) {
Response<T> success = Response.success(true, cacheEntity.getData(), rawCall, null);
mCallback.onCacheSuccess(success);
mCallback.onFinish();
return;
}
requestNetworkAsync();
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:NoneCacheRequestPolicy.java
示例10: onError
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@Override
public void onError(final Response<T> error) {
if (cacheEntity != null) {
final Response<T> cacheSuccess = Response.success(true, cacheEntity.getData(), error.getRawCall(), error.getRawResponse());
runOnUiThread(new Runnable() {
@Override
public void run() {
mCallback.onCacheSuccess(cacheSuccess);
mCallback.onFinish();
}
});
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
mCallback.onError(error);
mCallback.onFinish();
}
});
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RequestFailedCachePolicy.java
示例11: sendSuccessResultCallback
import com.lzy.okgo.model.Response; //导入依赖的package包/类
/** 成功回调,发送到主线程 */
private void sendSuccessResultCallback(final boolean isFromCache, final T t, final okhttp3.Call call, final okhttp3.Response response) {
final CacheMode cacheMode = baseRequest.getCacheMode();
OkGo.getInstance().getDelivery().post(new Runnable() {
@Override
public void run() {
if (isFromCache) {
mCallback.onCacheSuccess(t, call); //缓存成功回调 (UI线程)
if (cacheMode == CacheMode.DEFAULT || cacheMode == CacheMode.REQUEST_FAILED_READ_CACHE || cacheMode == CacheMode.IF_NONE_CACHE_REQUEST) {
mCallback.onAfter(t, null); //请求结束回调 (UI线程)
}
} else {
mCallback.onSuccess(t, call, response); //请求成功回调 (UI线程)
mCallback.onAfter(t, null); //请求结束回调 (UI线程)
}
}
});
}
开发者ID:feer921,项目名称:BaseProject,代码行数:20,代码来源:CacheCall.java
示例12: subscribeActual
import com.lzy.okgo.model.Response; //导入依赖的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));
}
}
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:CallExecuteObservable.java
示例13: onNext
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@Override
public void onNext(Response<R> response) {
if (response.isSuccessful()) {
observer.onNext(response.body());
} else {
terminated = true;
Throwable t = new HttpException(response);
try {
observer.onError(t);
} catch (Throwable inner) {
Exceptions.throwIfFatal(inner);
RxJavaPlugins.onError(new CompositeException(t, inner));
}
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:BodyObservable.java
示例14: subscribeActual
import com.lzy.okgo.model.Response; //导入依赖的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);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:CallEnqueueObservable.java
示例15: onSuccess
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@Override
public void onSuccess(Response<T> response) {
if (call.isCanceled()) return;
try {
observer.onNext(response);
} catch (Exception e) {
if (terminated) {
RxJavaPlugins.onError(e);
} else {
onError(response);
}
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:CallEnqueueObservable.java
示例16: onError
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@Override
public void onError(Response<T> response) {
if (call.isCanceled()) return;
Throwable throwable = response.getException();
try {
terminated = true;
observer.onError(throwable);
} catch (Throwable inner) {
Exceptions.throwIfFatal(inner);
RxJavaPlugins.onError(new CompositeException(throwable, inner));
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:CallEnqueueObservable.java
示例17: analysis
import com.lzy.okgo.model.Response; //导入依赖的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;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:AnalysisParams.java
示例18: requestImage
import com.lzy.okgo.model.Response; //导入依赖的package包/类
@OnClick(R.id.requestImage)
public void requestImage(View view) {
ServerApi.getBitmap("aaa", "bbb")//
.subscribeOn(Schedulers.io())//
.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(@NonNull Disposable disposable) throws Exception {
showLoading();
}
})//
.observeOn(AndroidSchedulers.mainThread())//
.subscribe(new Observer<Response<Bitmap>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
addDisposable(d);
}
@Override
public void onNext(@NonNull Response<Bitmap> response) {
handleResponse(response);
imageView.setImageBitmap(response.body());
}
@Override
public void onError(@NonNull Throwable e) {
e.printStackTrace(); //请求失败
handleError(null);
showToast("请求失败");
}
@Override
public void onComplete() {
dismissLoading();
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:RxBitmapActivity.java
示例19: getBitmap
import com.lzy.okgo.model.Response; //导入依赖的package包/类
public static Observable<Response<Bitmap>> getBitmap(String header, String param) {
return OkGo.<Bitmap>post(Urls.URL_IMAGE)//
.headers("aaa", header)//
.params("bbb", param)//
.converter(new BitmapConvert())//
.adapt(new ObservableResponse<Bitmap>());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:ServerApi.java
示例20: getFile
import com.lzy.okgo.model.Response; //导入依赖的package包/类
public static Observable<Response<File>> getFile(String header, String param) {
return OkGo.<File>get(Urls.URL_DOWNLOAD)//
.headers("aaa", header)//
.params("bbb", param)//
.converter(new FileConvert())//
.adapt(new ObservableResponse<File>());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:ServerApi.java
注:本文中的com.lzy.okgo.model.Response类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论