框架的使用

来源:互联网 发布:unity3d麻将游戏源码 编辑:程序博客网 时间:2024/06/03 20:36

Gson框架:(javabean 对象)TestEntity entity =gson.fromJson( jsonString ,TestEntity.class );
如果json 没有key值的时候:
Type listType = new TypeToken

@SuppressWarnings("unused")public void getJson(Context cxt, String url) {    HttpUtils http = new HttpUtils();    http.configCurrentHttpCacheExpiry(1000 * 10);// 设置超时时间    http.send(HttpMethod.POST, url, null, new RequestCallBack<String>() {// 接口回调                public void onSuccess(ResponseInfo<String> info) {                    System.out.println("返回的json字符串:" + info.result);                }                public void onFailure(HttpException arg0, String arg1) {                    System.out.println("请求数据失败!!");                    // Toast.makeText(cxt, "请求数据失败!!", 0).show();                }            });}

断点续传:

HttpUtils http = new HttpUtils();HttpHandler handler = http.download("http://apache.dataguru.cn/httpcomponents/httpclient/source/httpcomponents-client-4.2.5-src.zip",    "/sdcard/httpcomponents-client-4.2.5-src.zip",    true, // 如果目标文件存在,接着未完成的部分继续下载。服务器不支持RANGE时将从新下载。    true, // 如果从请求返回信息中获取到文件名,下载完成后自动重命名。    new RequestCallBack<File>() {        @Override        public void onStart() {            testTextView.setText("conn...");        }        @Override        public void onLoading(long total, long current, boolean isUploading) {            testTextView.setText(current + "/" + total);        }        @Override        public void onSuccess(ResponseInfo<File> responseInfo) {            testTextView.setText("downloaded:" + responseInfo.result.getPath());        }        @Override        public void onFailure(HttpException error, String msg) {            testTextView.setText(msg);        }});...//调用cancel()方法停止下载handler.cancel();

加载图片:

BitmapUtils bitmapUtils = new BitmapUtils(this);// 加载网络图片bitmapUtils.display(testImageView, "http://bbs.lidroid.com/static/image/common/logo.png");// 加载本地图片(路径以/开头, 绝对路径)bitmapUtils.display(testImageView, "/sdcard/test.jpg");// 加载assets中的图片(路径以assets开头)bitmapUtils.display(testImageView, "assets/img/wallpaper.jpg");// 使用ListView等容器展示图片时可通过PauseOnScrollListener控制滑动和快速滑动过程中时候暂停加载图片listView.setOnScrollListener(new PauseOnScrollListener(bitmapUtils, false, true));listView.setOnScrollListener(new PauseOnScrollListener(bitmapUtils, false, true, customListener));
0 0
原创粉丝点击