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);
}
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();
}
}
});
}
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));
}
});
}
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);
}
});
}
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);
}
}
Aggregations