本文整理汇总了Java中com.lzy.okgo.OkGo类的典型用法代码示例。如果您正苦于以下问题:Java OkGo类的具体用法?Java OkGo怎么用?Java OkGo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OkGo类属于com.lzy.okgo包,在下文中一共展示了OkGo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPanoView
import com.lzy.okgo.OkGo; //导入依赖的package包/类
private void initPanoView() {
vrPano = (VrPanoramaView) findViewById(R.id.vr_pano);
loading = findViewById(R.id.pb_loading);
Intent intent = getIntent();
String url = intent.getStringExtra("url");
String mp3 = intent.getStringExtra("mp3");
initPlayer(mp3);
OkGo.get(url).cacheKey(url).execute(new BitmapCallback() {
@Override
public void onSuccess(Bitmap bitmap, Call call, Response response) {
loading.setVisibility(View.GONE);
VrPanoramaView.Options options = new VrPanoramaView.Options();
options.inputType = VrPanoramaView.Options.TYPE_MONO;
vrPano.loadImageFromBitmap(bitmap, options);
}
});
}
示例2: updateData
import com.lzy.okgo.OkGo; //导入依赖的package包/类
public List<UploadTask<?>> updateData(List<ImageItem> images) {
this.type = -1;
this.images = images;
values = new ArrayList<>();
if (images != null) {
Random random = new Random();
for (int i = 0; i < images.size(); i++) {
ImageItem imageItem = images.get(i);
//这里是演示可以传递任何数据
PostRequest<String> postRequest = OkGo.<String>post(Urls.URL_FORM_UPLOAD)//
.headers("aaa", "111")//
.params("bbb", "222")//
.params("fileKey" + i, new File(imageItem.path))//
.converter(new StringConvert());
UploadTask<String> task = OkUpload.request(imageItem.path, postRequest)//
.priority(random.nextInt(100))//
.extra1(imageItem)//
.save();
values.add(task);
}
}
notifyDataSetChanged();
return values;
}
示例3: startAll
import com.lzy.okgo.OkGo; //导入依赖的package包/类
@OnClick(R.id.startAll)
public void startAll(View view) {
for (ApkModel apk : apks) {
//这里只是演示,表示请求可以传参,怎么传都行,和okgo使用方法一样
GetRequest<File> request = OkGo.<File>get(apk.url)//
.headers("aaa", "111")//
.params("bbb", "222");
//这里第一个参数是tag,代表下载任务的唯一标识,传任意字符串都行,需要保证唯一,我这里用url作为了tag
OkDownload.request(apk.url, request)//
.priority(apk.priority)//
.extra1(apk)//
.save()//
.register(new LogDownloadListener())//
.start();
adapter.notifyDataSetChanged();
}
}
示例4: download
import com.lzy.okgo.OkGo; //导入依赖的package包/类
@OnClick(R.id.download)
public void download() {
//这里只是演示,表示请求可以传参,怎么传都行,和okgo使用方法一样
GetRequest<File> request = OkGo.<File>get(apk.url)//
.headers("aaa", "111")//
.params("bbb", "222");
//这里第一个参数是tag,代表下载任务的唯一标识,传任意字符串都行,需要保证唯一,我这里用url作为了tag
OkDownload.request(apk.url, request)//
.priority(apk.priority)//
.extra1(apk)//
.save()//
.register(new LogDownloadListener())//
.start();
adapter.notifyDataSetChanged();
}
示例5: btn2
import com.lzy.okgo.OkGo; //导入依赖的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();
}
示例6: Request
import com.lzy.okgo.OkGo; //导入依赖的package包/类
public Request(String url) {
this.url = url;
baseUrl = url;
OkGo go = OkGo.getInstance();
//默认添加 Accept-Language
String acceptLanguage = HttpHeaders.getAcceptLanguage();
if (!TextUtils.isEmpty(acceptLanguage)) headers(HttpHeaders.HEAD_KEY_ACCEPT_LANGUAGE, acceptLanguage);
//默认添加 User-Agent
String userAgent = HttpHeaders.getUserAgent();
if (!TextUtils.isEmpty(userAgent)) headers(HttpHeaders.HEAD_KEY_USER_AGENT, userAgent);
//添加公共请求参数
if (go.getCommonParams() != null) params(go.getCommonParams());
if (go.getCommonHeaders() != null) headers(go.getCommonHeaders());
//添加缓存模式
retryCount = go.getRetryCount();
cacheMode = go.getCacheMode();
cacheTime = go.getCacheTime();
}
示例7: changeProgress
import com.lzy.okgo.OkGo; //导入依赖的package包/类
public static Progress changeProgress(final Progress progress, long writeSize, long totalSize, final Action action) {
progress.totalSize = totalSize;
progress.currentSize += writeSize;
progress.tempSize += writeSize;
long currentTime = SystemClock.elapsedRealtime();
boolean isNotify = (currentTime - progress.lastRefreshTime) >= OkGo.REFRESH_TIME;
if (isNotify || progress.currentSize == totalSize) {
long diffTime = currentTime - progress.lastRefreshTime;
if (diffTime == 0) diffTime = 1;
progress.fraction = progress.currentSize * 1.0f / totalSize;
progress.speed = progress.bufferSpeed(progress.tempSize * 1000 / diffTime);
progress.lastRefreshTime = currentTime;
progress.tempSize = 0;
if (action != null) {
action.call(progress);
}
}
return progress;
}
示例8: onViewCreated
import com.lzy.okgo.OkGo; //导入依赖的package包/类
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
// super.onViewCreated(view, savedInstanceState);
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
RecyclerView.LayoutManager layoutManager = getLayoutManager();
recyclerView.setLayoutManager(layoutManager);
OkGo.get(ApiUrls.URL_Query).cacheKey(ApiUrls.URL_Query).cacheMode(CacheMode.DEFAULT).execute(new StringCallback() {
@Override
public void onSuccess(String s, Call call, Response response) {
try {
JSONObject obj = new JSONObject(s);
String content = obj.getString("content");
List<VideoItem> videoItems = JSON.parseArray(content, VideoItem.class);
recyclerView.setAdapter(new VrVideoAdapter(videoItems));
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
示例9: retrieveDrawerMenu
import com.lzy.okgo.OkGo; //导入依赖的package包/类
private void retrieveDrawerMenu() {
OkGo.get(WebUtils.getCategoriesURL())
.tag(this)
.cacheKey("cacheKey")
.cacheMode(CacheMode.DEFAULT)
.execute(new StringCallback() {
@Override
public void onSuccess(String s, Call call, Response response) {
categories = JSONParser.parseCategoryList(s);
// 获取导航栏内容后异步更新UI
if (categories != null) {
Message msg = new Message();
msg.what = UPDATE_DRAWER_MENU;
handler.sendMessage(msg);
}
}
});
}
示例10: initData
import com.lzy.okgo.OkGo; //导入依赖的package包/类
private void initData() {
OkGo.post(requestUrl)
.params("CityName", getActivity().getResources().getString(R.string.beijing))
.getCall(StringConvert.create(), RxAdapter.<String>create())
.doOnSubscribe(() -> {
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s -> {
Type type = new TypeToken<HomeTicketBean>() {
}.getType();
HomeTicketBean bean = new Gson().fromJson(s, type);
if (bean.getStatus().equals("0")) {
mProductListEntities = bean.getResult().getProductList();
if (mProductListEntities.size() > 0) {
mAdapter.setDatas(mProductListEntities);
}
}
}, throwable -> {
});
}
示例11: sendSuccessResultCallback
import com.lzy.okgo.OkGo; //导入依赖的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线程)
}
}
});
}
示例12: generateCall
import com.lzy.okgo.OkGo; //导入依赖的package包/类
/** 根据当前的请求参数,生成对应的 Call 任务 */
public okhttp3.Call generateCall(Request request) {
mRequest = request;
//如果当前这个请求没有重新设置自己的各超时时间,则仍然使用已有的okHttpClient来发起请求
if (readTimeOut <= 0 && writeTimeOut <= 0 && connectTimeout <= 0 && interceptors.size() == 0) {
return OkGo.getInstance().getOkHttpClient().newCall(request);
}
else {
//当前本次请求有设置自己的各超时时间,则为了不覆盖OkGo中的okHttpClient的通用设置而是继承通用okHttpClient的配置,而新建一个okHttpClient发起请求
OkHttpClient.Builder newClientBuilder = OkGo.getInstance().getOkHttpClient().newBuilder();
if (readTimeOut > 0) newClientBuilder.readTimeout(readTimeOut, TimeUnit.MILLISECONDS);
if (writeTimeOut > 0) newClientBuilder.writeTimeout(writeTimeOut, TimeUnit.MILLISECONDS);
if (connectTimeout > 0) newClientBuilder.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS);
if (interceptors.size() > 0) {
for (Interceptor interceptor : interceptors) {
newClientBuilder.addInterceptor(interceptor);
}
}
return newClientBuilder.build().newCall(request);
}
}
示例13: initRecommentOne
import com.lzy.okgo.OkGo; //导入依赖的package包/类
/**
* 请求首页下面展示的图片的第一个banner
*/
private void initRecommentOne() {
OkGo.post(HttpUrlPaths.HOME_RECOMMENT_ONE_BANNER)
.getCall(StringConvert.create(), RxAdapter.<String>create())
.doOnSubscribe(() -> {
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s -> {
Type type = new TypeToken<HomeBannerOne>() {
}.getType();
HomeBannerOne homeBannerOne = new Gson().fromJson(s, type);
if (homeBannerOne.getErrorStr().equals("success")
&& homeBannerOne.getErrorCode() == 0) {
Glide.with(getContext())
.load(homeBannerOne.getResults().getBanner())
.asBitmap()
.into(mRecommentImgOne);
}
}, throwable -> {
});
}
示例14: initRecommentTwo
import com.lzy.okgo.OkGo; //导入依赖的package包/类
/**
* 请求首页下面展示的图片的第一个banner
*/
private void initRecommentTwo() {
OkGo.post(HttpUrlPaths.HOME_RECOMMENT_TWO_BANNER)
.getCall(StringConvert.create(), RxAdapter.<String>create())
.doOnSubscribe(() -> {
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s -> {
Type type = new TypeToken<HomeBannerTwo>() {
}.getType();
HomeBannerTwo homeBannerTwo = new Gson().fromJson(s, type);
if (homeBannerTwo.getErrorStr().equals("success")
&& homeBannerTwo.getErrorCode() == 0) {
Glide.with(getContext())
.load(homeBannerTwo.getResults().getImage())
.asBitmap()
.into(mImageView);
mTvDesTrecomment.setText(homeBannerTwo.getResults().getTitle());
}
}, throwable -> {
});
}
示例15: initAdvisoryData
import com.lzy.okgo.OkGo; //导入依赖的package包/类
/**
* 请求推荐咨询师数据
*/
private void initAdvisoryData() {
OkGo.post(HttpUrlPaths.HOME_RECOMMENT)
.getCall(StringConvert.create(), RxAdapter.<String>create())
.doOnSubscribe(() -> {
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s -> {
Type type = new TypeToken<AdvisoryBean>() {
}.getType();
AdvisoryBean bean = new Gson().fromJson(s, type);
if (bean != null
&& bean.getErrorCode() == 0
&& bean.getErrorStr().equals("success")) {
mAdvisoryBean = bean.getResults();
if (mAdvisoryBean != null && mAdvisoryBean.size() > 0) {
initAdvisory(mAdvisoryBean);
}
}
}, throwable -> {
});
}