Search in sources :

Example 1 with Callback

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();
                }
            }
        });
    }
}
Also used : Response(com.squareup.okhttp.Response) Callback(com.squareup.okhttp.Callback) Request(com.squareup.okhttp.Request) IOException(java.io.IOException)

Example 2 with Callback

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);
        }
    });
}
Also used : Response(com.squareup.okhttp.Response) OkHttpClient(com.squareup.okhttp.OkHttpClient) Callback(com.squareup.okhttp.Callback) Request(com.squareup.okhttp.Request) IOException(java.io.IOException)

Example 3 with Callback

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()));
                }
            }
        });
    });
}
Also used : Response(com.squareup.okhttp.Response) HTTPResponse(im.actor.runtime.http.HTTPResponse) Promise(im.actor.runtime.promise.Promise) HTTPError(im.actor.runtime.http.HTTPError) Callback(com.squareup.okhttp.Callback) HTTPResponse(im.actor.runtime.http.HTTPResponse) Request(com.squareup.okhttp.Request) IOException(java.io.IOException)

Example 4 with Callback

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);
                }
            });
        }
    };
}
Also used : Response(com.squareup.okhttp.Response) Callback(com.squareup.okhttp.Callback) Request(com.squareup.okhttp.Request) Handler(android.os.Handler) IOException(java.io.IOException) Cell(com.secupwn.aimsicd.utils.Cell) NonNull(android.support.annotation.NonNull)

Example 5 with Callback

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);
        }
    });
}
Also used : Response(com.squareup.okhttp.Response) Callback(com.squareup.okhttp.Callback) QAHttpCallback(cn.jeesoft.qa.libcore.http.QAHttpCallback) Request(com.squareup.okhttp.Request) IOException(java.io.IOException)

Aggregations

Callback (com.squareup.okhttp.Callback)10 Request (com.squareup.okhttp.Request)10 IOException (java.io.IOException)10 Response (com.squareup.okhttp.Response)9 OkHttpClient (com.squareup.okhttp.OkHttpClient)2 HTTPError (im.actor.runtime.http.HTTPError)2 HTTPResponse (im.actor.runtime.http.HTTPResponse)2 Promise (im.actor.runtime.promise.Promise)2 Handler (android.os.Handler)1 NonNull (android.support.annotation.NonNull)1 WebSettings (android.webkit.WebSettings)1 QAHttpCallback (cn.jeesoft.qa.libcore.http.QAHttpCallback)1 Builder (com.github.pockethub.android.Intents.Builder)1 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)1 IssueRequest (com.meisolsson.githubsdk.model.request.issue.IssueRequest)1 Cell (com.secupwn.aimsicd.utils.Cell)1 Call (com.squareup.okhttp.Call)1 RequestBody (com.squareup.okhttp.RequestBody)1