com.lzy.okgo.callback.StringCallback Java Examples

The following examples show how to use com.lzy.okgo.callback.StringCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpdateUtils.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取服务器的版本号
 *
 * @param context  上下文
 * @param callBack 为了控制线程,需要获取服务器版本号成功的回掉
 */
public static void getAPPServerVersion(final Context context, final VersionCallBack callBack) {
    //获取服务器最新版本号
    OkGo.<String>get(BaseUrl.HTTP_get_app_info)
            .tag(context)
            .execute(new StringCallback() {
                @Override
                public void onSuccess(Response<String> response) {
                    UpdateAppBean updateAppBean = (UpdateAppBean) JsonUtil.parseStringToBean(response.body(), UpdateAppBean.class);
                    if (updateAppBean.getCode() == 0) {
                        callBack.callBack(Integer.parseInt(updateAppBean.getData().getVersionCode()), updateAppBean.getData().getUploadUrl(),
                                updateAppBean.getData().getVersionName(), updateAppBean.getData().getVersionDetail());//数字110代表1.1.0
                    }
                }
            });
}
 
Example #2
Source File: VrVideoFragment.java    From GoogleVR with Apache License 2.0 6 votes vote down vote up
@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();
				}
			}
		});
	}
 
Example #3
Source File: TestActivity.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
@OnClick(R.id.btn3)
public void btn3(View view) {
    OkGo.<String>get("asdfasf")//
            .tag(this)//
            .headers(HttpHeaders.HEAD_KEY_USER_AGENT, "abcd")//
            .execute(new StringCallback() {
                @Override
                public void onSuccess(Response<String> response) {

                }
            });
}
 
Example #4
Source File: ComputerNewsFragment.java    From MyHearts with Apache License 2.0 5 votes vote down vote up
private void setHeaderView() {
    View headerView = LayoutInflater.from(getContext())
            .inflate(R.layout.news_banner_item_layout, null);
    mFlyBanner = (FlyBanner) headerView.findViewById(R.id.fly_banner);
    OkGo.get(bannerUrl)
            .tag(this)
            .cacheMode(CacheMode.DEFAULT)
            .execute(new StringCallback() {

                @Override
                public void onSuccess(String s, Call call, Response response) {
                    Type type = new TypeToken<NewsBannerBean>() {
                    }.getType();
                    NewsBannerBean bannerBean = new Gson().fromJson(s, type);
                    if (bannerBean.getCount() > 0) {
                        List<String> imgBanner = new ArrayList<>();
                        for (NewsBannerBean.DatasEntity entity : bannerBean.getDatas()) {
                            imgBanner.add(entity.getHeadPicUrl());
                        }
                        mFlyBanner.setImagesUrl(imgBanner);
                        mFlyBanner.setOnItemClickListener(position -> {
                            String id = bannerBean.getDatas().get(position).getId();
                            Intent intent = new Intent(getActivity(), NewsDetailActivity.class);
                            intent.putExtra("id", id);
                            intent.putExtra(Contants.TITLE, title);
                            startActivity(intent);
                        });
                    }
                }
            });
    mNewsAdapter.setHeaderView(headerView);

}