Search in sources :

Example 1 with Call

use of retrofit2.Call in project Parse-SDK-Android by ParsePlatform.

the class ParseOkHttpClient method executeInternal.

@Override
/* package */
ParseHttpResponse executeInternal(ParseHttpRequest parseRequest) throws IOException {
    Request okHttpRequest = getRequest(parseRequest);
    Call okHttpCall = okHttpClient.newCall(okHttpRequest);
    Response okHttpResponse = okHttpCall.execute();
    return getResponse(okHttpResponse);
}
Also used : Response(okhttp3.Response) ParseHttpResponse(com.parse.http.ParseHttpResponse) Call(okhttp3.Call) Request(okhttp3.Request) ParseHttpRequest(com.parse.http.ParseHttpRequest)

Example 2 with Call

use of retrofit2.Call in project lottie-android by airbnb.

the class AnimationFragment method loadUrl.

private void loadUrl(String url) {
    Request request;
    try {
        request = new Request.Builder().url(url).build();
    } catch (IllegalArgumentException e) {
        onLoadError();
        return;
    }
    if (client == null) {
        client = new OkHttpClient();
    }
    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
            onLoadError();
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            if (!response.isSuccessful()) {
                onLoadError();
            }
            try {
                JSONObject json = new JSONObject(response.body().string());
                LottieComposition.Factory.fromJson(getResources(), json, new OnCompositionLoadedListener() {

                    @Override
                    public void onCompositionLoaded(LottieComposition composition) {
                        setComposition(composition, "Network Animation");
                    }
                });
            } catch (JSONException e) {
                onLoadError();
            }
        }
    });
}
Also used : Call(okhttp3.Call) OnCompositionLoadedListener(com.airbnb.lottie.OnCompositionLoadedListener) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) JSONException(org.json.JSONException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) LottieComposition(com.airbnb.lottie.LottieComposition)

Example 3 with Call

use of retrofit2.Call in project okhttp-OkGo by jeasonlzy.

the class FormUploadActivity method formUpload.

@OnClick(R.id.formUpload)
public void formUpload(View view) {
    ArrayList<File> files = new ArrayList<>();
    if (imageItems != null && imageItems.size() > 0) {
        for (int i = 0; i < imageItems.size(); i++) {
            files.add(new File(imageItems.get(i).path));
        }
    }
    //拼接参数
    //
    OkGo.post(Urls.URL_FORM_UPLOAD).tag(//
    this).headers("header1", //
    "headerValue1").headers("header2", //
    "headerValue2").params("param1", //
    "paramValue1").params("param2", //
    "paramValue2").addFileParams("file", // 这种方式为同一个key,上传多个文件
    files).execute(new JsonCallback<LzyResponse<ServerModel>>() {

        @Override
        public void onBefore(BaseRequest request) {
            super.onBefore(request);
            btnFormUpload.setText("正在上传中...");
        }

        @Override
        public void onSuccess(LzyResponse<ServerModel> responseData, Call call, Response response) {
            handleResponse(responseData.data, call, response);
            btnFormUpload.setText("上传完成");
        }

        @Override
        public void onError(Call call, Response response, Exception e) {
            super.onError(call, response, e);
            handleError(call, response);
            btnFormUpload.setText("上传出错");
        }

        @Override
        public void upProgress(long currentSize, long totalSize, float progress, long networkSpeed) {
            System.out.println("upProgress -- " + totalSize + "  " + currentSize + "  " + progress + "  " + networkSpeed);
            String downloadLength = Formatter.formatFileSize(getApplicationContext(), currentSize);
            String totalLength = Formatter.formatFileSize(getApplicationContext(), totalSize);
            tvDownloadSize.setText(downloadLength + "/" + totalLength);
            String netSpeed = Formatter.formatFileSize(getApplicationContext(), networkSpeed);
            tvNetSpeed.setText(netSpeed + "/S");
            tvProgress.setText((Math.round(progress * 10000) * 1.0f / 100) + "%");
            pbProgress.setMax(100);
            pbProgress.setProgress((int) (progress * 100));
        }
    });
}
Also used : Call(okhttp3.Call) LzyResponse(com.lzy.demo.model.LzyResponse) ArrayList(java.util.ArrayList) Response(okhttp3.Response) LzyResponse(com.lzy.demo.model.LzyResponse) ServerModel(com.lzy.demo.model.ServerModel) BaseRequest(com.lzy.okgo.request.BaseRequest) File(java.io.File) OnClick(butterknife.OnClick)

Example 4 with Call

use of retrofit2.Call in project okhttputils by hongyangAndroid.

the class MainActivity method getImage.

public void getImage(View view) {
    mTv.setText("");
    String url = "http://images.csdn.net/20150817/1.jpg";
    OkHttpUtils.get().url(//
    url).tag(//
    this).build().connTimeOut(20000).readTimeOut(20000).writeTimeOut(20000).execute(new BitmapCallback() {

        @Override
        public void onError(Call call, Exception e, int id) {
            mTv.setText("onError:" + e.getMessage());
        }

        @Override
        public void onResponse(Bitmap bitmap, int id) {
            Log.e("TAG", "onResponse:complete");
            mImageView.setImageBitmap(bitmap);
        }
    });
}
Also used : BitmapCallback(com.zhy.http.okhttp.callback.BitmapCallback) Call(okhttp3.Call) Bitmap(android.graphics.Bitmap)

Example 5 with Call

use of retrofit2.Call in project Pokemap by omkarmoghe.

the class GoogleManager method refreshToken.

public void refreshToken(String refreshToken, final RefreshListener listener) {
    HttpUrl url = HttpUrl.parse(OAUTH_TOKEN_ENDPOINT).newBuilder().addQueryParameter("client_id", CLIENT_ID).addQueryParameter("client_secret", SECRET).addQueryParameter("refresh_token", refreshToken).addQueryParameter("grant_type", "refresh_token").build();
    Callback<GoogleService.TokenResponse> googleCallback = new Callback<GoogleService.TokenResponse>() {

        @Override
        public void onResponse(Call<GoogleService.TokenResponse> call, Response<GoogleService.TokenResponse> response) {
            if (response != null && response.body() != null) {
                listener.refreshSuccessful(response.body().getIdToken(), response.body().getRefreshToken());
            } else {
                listener.refreshFailed("Failed on requesting the id token");
            }
        }

        @Override
        public void onFailure(Call<GoogleService.TokenResponse> call, Throwable t) {
            t.printStackTrace();
            listener.refreshFailed("Failed on requesting the id token");
        }
    };
    if (mGoogleService != null) {
        Call<GoogleService.TokenResponse> call = mGoogleService.requestToken(url.toString());
        call.enqueue(googleCallback);
    }
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) Callback(retrofit2.Callback) HttpUrl(okhttp3.HttpUrl)

Aggregations

ResponseBody (okhttp3.ResponseBody)186 Request (okhttp3.Request)169 Test (org.junit.Test)155 Call (okhttp3.Call)116 Response (retrofit2.Response)106 Response (okhttp3.Response)98 Observable (rx.Observable)94 ServiceResponse (com.microsoft.rest.ServiceResponse)92 MockResponse (okhttp3.mockwebserver.MockResponse)67 IOException (java.io.IOException)66 RequestBody (okhttp3.RequestBody)50 Callback (okhttp3.Callback)41 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)34 OkHttpClient (okhttp3.OkHttpClient)27 ToStringConverterFactory (retrofit2.helpers.ToStringConverterFactory)27 Buffer (okio.Buffer)19 Call (retrofit2.Call)18 MultipartBody (okhttp3.MultipartBody)17 HttpUrl (okhttp3.HttpUrl)15 Callback (retrofit2.Callback)14