Search in sources :

Example 1 with QASimpleHttpCallback

use of cn.jeesoft.qa.libcore.http.QASimpleHttpCallback in project QuickAndroid by ImKarl.

the class MainActivity method testHttp.

/**
     * 测试HTTP请求
     */
public void testHttp(View view) {
    String url = "http://www.baidu.com/s";
    QARequestParams params = new QARequestParams();
    params.putParam("wd", "android");
    QAHttpCallback<String> listener = new QASimpleHttpCallback<String>() {

        @Override
        public void onProgress(String url, long current, long total, QAHttpAction action) {
            super.onProgress(url, current, total, action);
            QAToast.show(MainActivity.this, "onProgress | " + action + " | " + current + "/" + total);
        }

        @Override
        public void onSuccessNet(String url, String data) {
            QALog.e(url, "onSuccessNet " + data);
        }

        @Override
        public void onSuccessCache(String url, String data) {
            QALog.e(url, "onSuccessCache " + data);
        }
    };
    QACore.getHttp().load(QAHttpMethod.GET, url, params, listener);
}
Also used : QAHttpAction(cn.jeesoft.qa.libcore.http.QAHttpAction) QARequestParams(cn.jeesoft.qa.libcore.http.QARequestParams) QASimpleHttpCallback(cn.jeesoft.qa.libcore.http.QASimpleHttpCallback)

Example 2 with QASimpleHttpCallback

use of cn.jeesoft.qa.libcore.http.QASimpleHttpCallback in project QuickAndroid by ImKarl.

the class MainActivity method testHttpFile.

/**
     * 测试HTTP请求(File)
     */
public void testHttpFile(final View view) {
    String url = "https://github.com/alafighting/QuickAndroid/archive/master.zip";
    QARequestParams params = new QARequestParams();
    params.setTargetFile(new File(QACore.file.getUsableDir(getPackageName()), "QuickAndroid-master.zip"));
    QAHttpCallback<File> listener = new QASimpleHttpCallback<File>() {

        @Override
        public void onProgress(String url, long current, long total, QAHttpAction action) {
            super.onProgress(url, current, total, action);
            QAToast.show(MainActivity.this, "onProgress | " + action + " | " + (total != -1 ? QAStringUtils.getDecimal(100D * current / total, 2) : (QAStringUtils.getDecimal(1D * current / 1024, 2) + "kb")));
        }

        @Override
        public void onSuccessNet(String url, File data) {
            QALog.e(url, "onSuccessNet", data);
        }

        @Override
        public void onSuccessCache(String url, File data) {
            QALog.e(url, "onSuccessCache", data);
        }
    };
    QACore.getHttp().load(QAHttpMethod.GET, url, params, listener);
}
Also used : QAHttpAction(cn.jeesoft.qa.libcore.http.QAHttpAction) QARequestParams(cn.jeesoft.qa.libcore.http.QARequestParams) File(java.io.File) QASimpleHttpCallback(cn.jeesoft.qa.libcore.http.QASimpleHttpCallback)

Example 3 with QASimpleHttpCallback

use of cn.jeesoft.qa.libcore.http.QASimpleHttpCallback in project QuickAndroid by ImKarl.

the class MainActivity method testHttpImage.

/**
     * 测试HTTP请求(Bitmap)
     */
public void testHttpImage(final View view) {
    String url = "http://p1.sinaimg.cn/2813897512/180/42911348395710";
    QAHttpCallback<Bitmap> listener = new QASimpleHttpCallback<Bitmap>() {

        @Override
        public void onProgress(String url, long current, long total, QAHttpAction action) {
            super.onProgress(url, current, total, action);
            QAToast.show(MainActivity.this, "onProgress | " + action + " | " + current + "/" + total);
        }

        @SuppressWarnings("deprecation")
        @Override
        public void onSuccessNet(String url, Bitmap data) {
            QALog.e(url, "onSuccessNet", data);
            // 设置按钮的背景图片
            view.setBackgroundDrawable(new BitmapDrawable(getResources(), data));
        }
    };
    QACore.getHttp().load(QAHttpMethod.GET, url, null, listener);
}
Also used : Bitmap(android.graphics.Bitmap) QAHttpAction(cn.jeesoft.qa.libcore.http.QAHttpAction) BitmapDrawable(android.graphics.drawable.BitmapDrawable) QASimpleHttpCallback(cn.jeesoft.qa.libcore.http.QASimpleHttpCallback)

Example 4 with QASimpleHttpCallback

use of cn.jeesoft.qa.libcore.http.QASimpleHttpCallback in project QuickAndroid by ImKarl.

the class MainActivity method testHttpParser.

/**
     * 测试HTTP请求(Parser)
     */
public void testHttpParser(final View view) {
    String url = "http://www.kuaidi100.com/query";
    QARequestParams params = new QARequestParams();
    params.putParam("type", "快递公司代号");
    params.putParam("postid", "快递单号");
    /**
         * 快递单信息
         */
    class Express implements QAJsonParser<Express> {

        int status;

        String message;

        @Override
        public Express parser(QAJson data) {
            QAJsonObject root = (QAJsonObject) data;
            this.status = root.getInt("status");
            this.message = root.getString("message");
            return this;
        }

        @Override
        public String toString() {
            return "Express [status=" + status + ", message=" + message + "]";
        }
    }
    QAHttpCallback<Express> listener = new QASimpleHttpCallback<Express>() {

        @Override
        public void onProgress(String url, long current, long total, QAHttpAction action) {
            super.onProgress(url, current, total, action);
            QAToast.show(MainActivity.this, "onProgress | " + action + " | " + current + "/" + total);
        }

        @Override
        public void onSuccessNet(String url, Express data) {
            QALog.e(url, "onSuccessNet", data);
        }

        @Override
        public void onSuccessCache(String url, Express data) {
            QALog.e(url, "onSuccessCache", data);
        }
    };
    QACore.getHttp().load(QAHttpMethod.GET, url, params, new Express(), listener);
}
Also used : QAJsonObject(cn.jeesoft.qa.json.QAJsonObject) QAJson(cn.jeesoft.qa.json.QAJson) QAJsonParser(cn.jeesoft.qa.libcore.http.QAJsonParser) QAHttpAction(cn.jeesoft.qa.libcore.http.QAHttpAction) QARequestParams(cn.jeesoft.qa.libcore.http.QARequestParams) QASimpleHttpCallback(cn.jeesoft.qa.libcore.http.QASimpleHttpCallback)

Aggregations

QAHttpAction (cn.jeesoft.qa.libcore.http.QAHttpAction)4 QASimpleHttpCallback (cn.jeesoft.qa.libcore.http.QASimpleHttpCallback)4 QARequestParams (cn.jeesoft.qa.libcore.http.QARequestParams)3 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 QAJson (cn.jeesoft.qa.json.QAJson)1 QAJsonObject (cn.jeesoft.qa.json.QAJsonObject)1 QAJsonParser (cn.jeesoft.qa.libcore.http.QAJsonParser)1 File (java.io.File)1