Search in sources :

Example 1 with BitmapCallBackResult

use of com.xiaoyunchengzhu.httpapi.net.BitmapCallBackResult in project HttpApiDemo by xiaoyunchengzhu.

the class MainActivity method onClick.

@Override
public void onClick(View view) {
    switch(view.getId()) {
        case R.id.get:
            // 此处默认get方式,默认缓存无缓存。不设置就是默认。
            APIManager.createApi(new HttpApi(Test.URL_GET)).param("name", "为什么乱码").execute(new StringCallBackResult() {

                @Override
                public void success(Api api, String result) {
                    LogManger.i(result);
                    show.setText(result);
                }

                @Override
                public void failure(Api api, String error) {
                    show.setText(error);
                }
            });
            break;
        case R.id.post:
            APIManager.createApi(new HttpApi(Test.URL_POST)).param("name", "我们的世界").httpMode(HttpMode.post).execute(new StringCallBackResult() {

                @Override
                public void success(Api api, String result) {
                    show.setText(result);
                }

                @Override
                public void failure(Api api, String error) {
                    LogManger.e(error);
                    show.setText(error);
                }
            });
            break;
        case R.id.cache:
            APIManager.createApi(new HttpApi(Test.URL_CACHE)).cacheMode(CacheMode.is_cache).param("name", "cache").execute(new StringCallBackResult() {

                @Override
                public void success(Api api, String result) {
                    show.setText(result);
                    LogManger.e(result);
                }

                @Override
                public void failure(Api api, String error) {
                    LogManger.e(error);
                    show.setText(error);
                }
            });
            break;
        case R.id.nochache:
            APIManager.createApi(new HttpApi(Test.URL_NO_CACHE)).param("name", "嗯,可以了").execute(new StringCallBackResult() {

                @Override
                public void success(Api api, String result) {
                    show.setText(result);
                    LogManger.e(result);
                }

                @Override
                public void failure(Api api, String error) {
                    LogManger.e(error);
                    show.setText(error);
                }
            });
            break;
        case R.id.downloadfile:
            // 下载
            APIManager.createApi(new HttpApi(Test.URL_DOWNLOAD)).execute(new DownLoadCallBackResult(Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.zip") {

                @Override
                public void success(Api api, String result) {
                    LogManger.i("下载成功,路径:" + result);
                    show.setText(result);
                }

                @Override
                public void failure(Api api, String error) {
                    LogManger.i("下载失败,:" + error);
                    show.setText(error);
                }

                @Override
                public void onDownloadProgress(long currentSize, long totalSize, double progress) {
                    LogManger.i("下载中,进度:currentSize:" + currentSize + "--totalSize:" + totalSize + "--progress:" + (int) (progress * 100) + "%");
                    show.setText("进度:" + (int) (progress * 100) + "%");
                }
            });
            break;
        case R.id.uploadFile:
            APIManager.createApi(new HttpApi(Test.URL_FORM_UPLOAD)).param("file", new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/image1ps.jpg")).param("key1", "value1").execute(new UpLoadCallBackResult() {

                @Override
                public void success(Api api, String result) {
                    LogManger.i("上传成功,:" + result);
                    show.setText("上传成功" + result);
                }

                @Override
                public void failure(Api api, String error) {
                    LogManger.i(error);
                    show.setText("上传失败" + error);
                }

                @Override
                public void onUpLoadProgress(long currentSize, long totalSize, double progress) {
                    LogManger.i("上传中,进度:currentSize:" + currentSize + "--totalSize:" + totalSize + "--progress:" + (int) (progress * 100) + "%");
                    show.setText("进度:" + (int) (progress * 100) + "%");
                }
            });
            break;
        case R.id.https:
            break;
        case R.id.image:
            APIManager.createApi(new HttpApi(Test.URL_IMAGE)).execute(new BitmapCallBackResult() {

                @Override
                public void success(Api api, Bitmap result) {
                    show.setBackground(new BitmapDrawable(result));
                }

                @Override
                public void failure(Api api, String error) {
                    show.setText(error);
                }
            });
            break;
        case R.id.contentUploadFile:
            APIManager.createApi(new HttpApi(Test.URL_CONTENT_UPLOAD)).content(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/image1ps.jpg")).execute(new UpLoadCallBackResult() {

                @Override
                public void success(Api api, String result) {
                    LogManger.i("上传成功,:" + result);
                    show.setText("上传成功" + result);
                }

                @Override
                public void failure(Api api, String error) {
                    LogManger.i(error);
                    show.setText("上传失败" + error);
                }

                @Override
                public void onUpLoadProgress(long currentSize, long totalSize, double progress) {
                    LogManger.i("上传中,进度:currentSize:" + currentSize + "--totalSize:" + totalSize + "--progress:" + (int) (progress * 100) + "%");
                    show.setText("进度:" + (int) (progress * 100) + "%");
                }
            });
            break;
        case R.id.updateExpired:
            APIManager.createApi(new HttpApi(Test.URL_CACHE)).cacheMode(CacheMode.is_cache).param("name", "我们的世界").execute(new StringCallBackResult() {

                @Override
                public void success(Api api, String result) {
                    show.setText(result);
                    LogManger.e(result);
                }

                @Override
                public void failure(Api api, String error) {
                    LogManger.e(error);
                    show.setText(error);
                }
            }).updateExpired(10000);
            break;
    }
}
Also used : BitmapDrawable(android.graphics.drawable.BitmapDrawable) StringCallBackResult(com.xiaoyunchengzhu.httpapi.net.StringCallBackResult) Bitmap(android.graphics.Bitmap) UpLoadCallBackResult(com.xiaoyunchengzhu.httpapi.net.UpLoadCallBackResult) HttpApi(com.xiaoyunchengzhu.httpapi.http.HttpApi) HttpApi(com.xiaoyunchengzhu.httpapi.http.HttpApi) Api(com.xiaoyunchengzhu.httpapi.net.Api) BitmapCallBackResult(com.xiaoyunchengzhu.httpapi.net.BitmapCallBackResult) DownLoadCallBackResult(com.xiaoyunchengzhu.httpapi.net.DownLoadCallBackResult) File(java.io.File)

Aggregations

Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 HttpApi (com.xiaoyunchengzhu.httpapi.http.HttpApi)1 Api (com.xiaoyunchengzhu.httpapi.net.Api)1 BitmapCallBackResult (com.xiaoyunchengzhu.httpapi.net.BitmapCallBackResult)1 DownLoadCallBackResult (com.xiaoyunchengzhu.httpapi.net.DownLoadCallBackResult)1 StringCallBackResult (com.xiaoyunchengzhu.httpapi.net.StringCallBackResult)1 UpLoadCallBackResult (com.xiaoyunchengzhu.httpapi.net.UpLoadCallBackResult)1 File (java.io.File)1