use of com.squareup.okhttp.Callback in project PocketHub by pockethub.
the class RawCommentFragment method onActivityResult.
@Override
public void onActivityResult(final int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_SELECT_PHOTO && resultCode == Activity.RESULT_OK) {
showProgressIndeterminate(R.string.loading);
ImageBinPoster.post(getActivity(), data.getData(), new Callback() {
@Override
public void onFailure(Request request, IOException e) {
dismissProgress();
showImageError();
}
@Override
public void onResponse(Response response) throws IOException {
dismissProgress();
if (response.isSuccessful()) {
insertImage(ImageBinPoster.getUrl(response.body().string()));
} else {
showImageError();
}
}
});
}
}
use of com.squareup.okhttp.Callback in project incubator-weex by apache.
the class Downloader method download.
public static void download(String url, final DownloadCallback callback) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).get().build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
callback.onError(e);
}
@Override
public void onResponse(Response response) throws IOException {
callback.handleResponse(response);
}
});
}
use of com.squareup.okhttp.Callback in project actor-platform by actorapp.
the class AndroidHttpProvider method putMethod.
@Override
public Promise<HTTPResponse> putMethod(String url, byte[] contents) {
return new Promise<>(resolver -> {
final Request request = new Request.Builder().url(url).method("PUT", RequestBody.create(MEDIA_TYPE, contents)).build();
Log.d(TAG, "Uploading part: " + request.toString());
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
Log.d(TAG, "Uploading part error: " + request.toString());
e.printStackTrace();
// TODO: Better error?
resolver.error(new HTTPError(0));
}
@Override
public void onResponse(Response response) throws IOException {
Log.d(TAG, "Upload part response: " + request.toString() + " -> " + response.toString());
if (response.code() >= 200 && response.code() < 300) {
resolver.result(new HTTPResponse(response.code(), null));
} else {
resolver.error(new HTTPError(response.code()));
}
}
});
});
}
use of com.squareup.okhttp.Callback in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class DeviceFragment method getOpenCellIdResponseCallback.
@NonNull
private Callback getOpenCellIdResponseCallback() {
return new Callback() {
@Override
public void onFailure(Request request, IOException e) {
Handler refresh = new Handler(Looper.getMainLooper());
refresh.post(new Runnable() {
public void run() {
refreshFailed();
}
});
}
@Override
public void onResponse(final Response response) throws IOException {
Handler refresh = new Handler(Looper.getMainLooper());
refresh.post(new Runnable() {
public void run() {
Cell cell = responseToCell(response);
processFinish(cell);
}
});
}
};
}
use of com.squareup.okhttp.Callback in project QuickAndroid by ImKarl.
the class OkHttp method load.
/**
* 异步请求
*
* @param method
* @param url
* @param params
* @param listener
* @param <T>
*/
public <T> void load(QAHttpMethod method, final String url, final QARequestParams params, final QAHttpCallback<T> listener) {
final Request request = createRequest(method, url, params, listener);
if (request == null) {
return;
}
if (params != null && params.isPreLoad()) {
// 缓存加载
preLoad(url, params, request, listener);
}
// 网络加载
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(final Request request, final IOException e) {
sendFailedCallback(url, e, listener);
}
@Override
public void onResponse(final Response response) {
handlerResponse(url, params, response, listener);
}
});
}
Aggregations