org.kymjs.kjframe.http.HttpCallBack Java Examples

The following examples show how to use org.kymjs.kjframe.http.HttpCallBack. 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: HttpActivity.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 附带有Http请求头的get请求
 */
private void getWithHeader() {
    KJHttp kjh = new KJHttp();
    HttpParams params = new HttpParams();
    params.put("uid", 863548);
    params.put("teamid", 12375);
    params.put("pageIndex", 0);
    params.put("pageSize", 20);
    params.put("type", "all");
    params.putHeaders("cookie", "cookie不能告诉你");
    kjh.get("http://team.oschina.net/action/api/team_active_list", params,
            new HttpCallBack() {
                @Override
                public void onSuccess(String t) {
                    super.onSuccess(t);
                    toast(t);
                }
            });
}
 
Example #2
Source File: HttpActivity.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
private void post() {
    KJHttp kjh = new KJHttp();
    HttpParams params = new HttpParams();
    // params.put("uid", 863548);
    // params.put("msg", "没有网,[发怒]");
    // params.putHeaders("cookie", "cookie不能告诉你");
    // kjh.post("http://www.oschina.net/action/api/tweet_pub", params,
    params.put("username", "[email protected]");
    params.put("pwd", "123456");
    kjh.post("http://www.oschina.net/action/api/login_validate", params,
            new HttpCallBack() {
                @Override
                public void onSuccess(Map<String, String> headers, byte[] t) {
                    super.onSuccess(headers, t);
                    // 获取cookie
                    KJLoger.debug("===" + headers.get("Set-Cookie"));
                    Log.i("kymjs", new String(t));
                }
            });
}
 
Example #3
Source File: HttpActivity.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 附带有文件的post请求
 */
private void postWithFile() {
    KJHttp kjh = new KJHttp();
    HttpParams params = new HttpParams();
    params.put("uid", 863548);
    params.put("msg", "在有图片的时 [发呆]");
    params.put("img", new File("/storage/emulated/0/qrcode.jpg"));
    params.putHeaders("Cookie", "cookie不能告诉你");
    kjh.post("http://www.oschina.net/action/api/tweet_pub", params,
            new HttpCallBack() {
                @Override
                public void onSuccess(String t) {
                    super.onSuccess(t);
                    toast(t);
                }
            });
}
 
Example #4
Source File: HttpActivity.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 使用JSON提交参数而不是Form表单
 */
private void jsonRequest() {
    KJHttp kjh = new KJHttp();
    HttpParams params = new HttpParams();
    params.putHeaders("Cookie", "cookie不能告诉你");
    params.putJsonParams("{\"uid\":863548,\"stickys\":[{\"id\":29058,\"iid\":0,\"content\":\"你好\",\"color\":\"green\",\"createtime\":\"2015-04-16 16:26:17\",\"updatetime\":\"2015-04-16 16:26:17\"}]}");
    kjh.jsonPost(
            "http://www.oschina.net/action/api/team_stickynote_batch_update",
            params, new HttpCallBack() {
                @Override
                public void onSuccess(String t) {
                    super.onSuccess(t);
                    toast(t);
                }
            });
}
 
Example #5
Source File: HttpActivity.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 下载。有一个陷阱需要你注意:下载方法中的KJHttp对象必须和暂停方法中的KJHttp对象为同一个对象
 */
private void download() {
    kjh.download(
            FileUtils.getSDCardPath() + "/1.apk",
            "http://music.baidu.com/cms/mobile/static/apk/Baidumusic_yinyuehexzfc.apk",
            new HttpCallBack() {
                @Override
                public void onLoading(long count, long current) {
                    super.onLoading(count, current);
                    KJLoger.debug(count + "====" + current);
                }

                @Override
                public void onSuccess(byte[] t) {
                    super.onSuccess(t);
                    toast("完成");
                }

                @Override
                public void onFailure(int errorNo, String strMsg) {
                    super.onFailure(errorNo, strMsg);
                    KJLoger.debug(errorNo + "====" + strMsg);
                }
            });
}
 
Example #6
Source File: WeChatFragment.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
private void refresh() {
    kjh.get(EVERYDAY_HOST, new HttpCallBack() {
        @Override
        public void onSuccess(String t) {
            super.onSuccess(t);
            KJLoger.debug(TAG + "网络请求:" + t);
            if (t != null && !t.equals(cache)) {
                List<EverydayMessage> datas = Parser.getEveryDayMsg(t);
                if (adapter == null) {
                    adapter = new WeChatAdapter(outsideAty, datas);
                    mListView.setAdapter(adapter);
                } else {
                    adapter.refresh(datas);
                }
            }
        }
    });
}
 
Example #7
Source File: ImageDisplayer.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 创建一个网络请求
 */
protected Request<Bitmap> makeImageRequest(final String requestUrl,
                                           int maxWidth, int maxHeight) {
    return new ImageRequest(requestUrl, maxWidth, maxHeight,
            new HttpCallBack() {
                @Override
                public void onSuccess(Bitmap t) {
                    super.onSuccess(t);
                    onGetImageSuccess(requestUrl, t);
                }

                @Override
                public void onFailure(int errorNo, String strMsg) {
                    super.onFailure(errorNo, strMsg);
                    onGetImageError(requestUrl, new KJHttpException(strMsg));
                }
            });
}
 
Example #8
Source File: KJHttp.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 发起post请求
 *
 * @param url      地址
 * @param params   参数集
 * @param callback 请求中的回调方法
 * @param useCache 是否缓存本条请求
 */
public Request<byte[]> post(String url, HttpParams params,
                            boolean useCache, HttpCallBack callback) {
    Request<byte[]> request = new FormRequest(HttpMethod.POST, url, params,
            callback);
    request.setShouldCache(useCache);
    doRequest(request);
    return request;
}
 
Example #9
Source File: Core.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 发起get请求
 *
 * @param url      地址
 * @param params   参数集
 * @param callback 请求中的回调方法
 * @param useCache 是否缓存本条请求
 */
public static Request<byte[]> get(String url, HttpParams params, boolean useCache,
                                  HttpCallBack callback) {
    if (params != null) {
        url += params.getUrlParams();
    } else {
        params = new HttpParams();
    }
    Request<byte[]> request = new FormRequest(Request.HttpMethod.GET, url, params,
            callback);
    request.setShouldCache(useCache);
    getKJHttp().doRequest(request);
    return request;
}
 
Example #10
Source File: Core.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 发起post请求
 *
 * @param url      地址
 * @param params   参数集
 * @param callback 请求中的回调方法
 * @param useCache 是否缓存本条请求
 */
public static Request<byte[]> post(String url, HttpParams params,
                                   boolean useCache, HttpCallBack callback) {
    Request<byte[]> request = new FormRequest(HttpMethod.POST, url, params,
            callback);
    request.setShouldCache(useCache);
    getKJHttp().doRequest(request);
    return request;
}
 
Example #11
Source File: Core.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 使用JSON传参的post请求
 *
 * @param url      地址
 * @param params   参数集
 * @param callback 请求中的回调方法
 * @param useCache 是否缓存本条请求
 */
public Request<byte[]> jsonPost(String url, HttpParams params,
                                boolean useCache, HttpCallBack callback) {
    Request<byte[]> request = new JsonRequest(HttpMethod.POST, url, params,
            callback);
    request.setShouldCache(useCache);
    getKJHttp().doRequest(request);
    return request;
}
 
Example #12
Source File: Core.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 使用JSON传参的get请求
 *
 * @param url      地址
 * @param params   参数集
 * @param callback 请求中的回调方法
 * @param useCache 是否缓存本条请求
 */
public Request<byte[]> jsonGet(String url, HttpParams params,
                               boolean useCache, HttpCallBack callback) {
    Request<byte[]> request = new JsonRequest(HttpMethod.GET, url, params,
            callback);
    request.setShouldCache(useCache);
    getKJHttp().doRequest(request);
    return request;
}
 
Example #13
Source File: Core.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 下载
 *
 * @param storeFilePath 文件保存路径。注,必须是一个file路径不能是folder
 * @param url           下载地址
 * @param callback      请求中的回调方法
 */
public static DownloadTaskQueue download(String storeFilePath, String url,
                                         HttpCallBack callback) {
    FileRequest request = new FileRequest(storeFilePath, url, callback);
    HttpConfig config = getKJHttp().getConfig();
    request.setConfig(config);
    config.mController.add(request);
    return config.mController;
}
 
Example #14
Source File: ImageRequest.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
public ImageRequest(String url, int maxWidth, int maxHeight,
                    HttpCallBack callback) {
    super(HttpMethod.GET, url, callback);
    mHeaders.put("cookie", HttpConfig.sCookie);
    mMaxWidth = maxWidth;
    mMaxHeight = maxHeight;
}
 
Example #15
Source File: KJHttp.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 发起get请求
 *
 * @param url      地址
 * @param params   参数集
 * @param callback 请求中的回调方法
 * @param useCache 是否缓存本条请求
 */
public Request<byte[]> get(String url, HttpParams params, boolean useCache,
                           HttpCallBack callback) {
    if (params != null) {
        url += params.getUrlParams();
    }
    Request<byte[]> request = new FormRequest(HttpMethod.GET, url, params,
            callback);
    request.setShouldCache(useCache);
    doRequest(request);
    return request;
}
 
Example #16
Source File: SamplePagerAdapter.java    From KJGallery with Apache License 2.0 5 votes vote down vote up
@Override
public View instantiateItem(ViewGroup container, int position) {
    View root = View.inflate(aty, R.layout.item_pager, null);
    final PhotoView photoView = (PhotoView) root.findViewById(R.id.images);
    final GifImageView gifView = (GifImageView) root.findViewById(R.id.gifimage);
    final ProgressBar mProgressBar = (ProgressBar) root.findViewById(R.id.progress);

    GifRequest request = new GifRequest(imageUrls[position], new HttpCallBack() {
        @Override
        public void onPreStart() {
            super.onPreStart();
            mProgressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onSuccess(byte[] t) {
            super.onSuccess(t);
            //根据图片类型的不同选择不同的加载方案
            if (TYPE_GIF == getType(t)) {
                displayGif(gifView, t);
            } else {
                displayImage(photoView, t);
            }
        }

        @Override
        public void onFinish() {
            super.onFinish();
            mProgressBar.setVisibility(View.GONE);
        }
    });
    kjh.doRequest(request);

    container.addView(root, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams
            .MATCH_PARENT);
    return root;
}
 
Example #17
Source File: KJHttp.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 使用JSON传参的post请求
 *
 * @param url      地址
 * @param params   参数集
 * @param callback 请求中的回调方法
 * @param useCache 是否缓存本条请求
 */
public Request<byte[]> jsonPost(String url, HttpParams params,
                                boolean useCache, HttpCallBack callback) {
    Request<byte[]> request = new JsonRequest(HttpMethod.POST, url, params,
            callback);
    request.setShouldCache(useCache);
    doRequest(request);
    return request;
}
 
Example #18
Source File: KJHttp.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 使用JSON传参的get请求
 *
 * @param url      地址
 * @param params   参数集
 * @param callback 请求中的回调方法
 */
public Request<byte[]> jsonGet(String url, HttpParams params,
                               HttpCallBack callback) {
    Request<byte[]> request = new JsonRequest(HttpMethod.GET, url, params,
            callback);
    doRequest(request);
    return request;
}
 
Example #19
Source File: KJHttp.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 使用JSON传参的get请求
 *
 * @param url      地址
 * @param params   参数集
 * @param callback 请求中的回调方法
 * @param useCache 是否缓存本条请求
 */
public Request<byte[]> jsonGet(String url, HttpParams params,
                               boolean useCache, HttpCallBack callback) {
    Request<byte[]> request = new JsonRequest(HttpMethod.GET, url, params,
            callback);
    request.setShouldCache(useCache);
    doRequest(request);
    return request;
}
 
Example #20
Source File: KJHttp.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 下载
 *
 * @param storeFilePath 文件保存路径。注,必须是一个file路径不能是folder
 * @param url           下载地址
 * @param callback      请求中的回调方法
 */
public DownloadTaskQueue download(String storeFilePath, String url,
                                  HttpCallBack callback) {
    FileRequest request = new FileRequest(storeFilePath, url, callback);
    request.setConfig(mConfig);
    mConfig.mController.add(request);
    return mConfig.mController;
}
 
Example #21
Source File: MainActivity.java    From Contacts with Apache License 2.0 5 votes vote down vote up
private void doHttp() {
    kjh.get("http://zb.oschina.net/action/zbApi/contacts_list?uid=863548", new HttpCallBack() {
        @Override
        public void onSuccess(String t) {
            super.onSuccess(t);
            parser(t);
        }
    });
}
 
Example #22
Source File: HttpActivity.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
private void get() {
    KJHttp kjh = new KJHttp();
    HttpParams params = new HttpParams();
    params.put("pageIndex", 0);
    params.put("pageSize", 20);
    kjh.get("http://www.oschina.net/action/api/tweet_list", params,
            new HttpCallBack() {
                @Override
                public void onSuccess(String t) {
                    super.onSuccess(t);
                    toast(t);
                }
            });
}
 
Example #23
Source File: BlogAuthorFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
private void refresh() {
    kjh.get(OSCBLOG_HOST, new HttpCallBack() {
        @Override
        public void onSuccess(String t) {
            super.onSuccess(t);
            KJLoger.debug(TAG + "网络请求:" + t);
            if (t != null && !t.equals(cache)) {
                List<BlogAuthor> datas = Parser.getBlogAuthor(t);
                if (adapter == null) {
                    adapter = new BlogAuthorAdapter(mListView, datas,
                            R.layout.item_blog_author);
                    mListView.setAdapter(adapter);
                } else {
                    adapter.refresh(datas);
                }
            }
            mEmptyLayout.dismiss();
        }

        @Override
        public void onFailure(int errorNo, String strMsg) {
            super.onFailure(errorNo, strMsg);
            if (adapter != null && adapter.getCount() > 0) {
                return;
            } else {
                mEmptyLayout.setErrorType(EmptyLayout.NODATA);
            }
        }

        @Override
        public void onFinish() {
            super.onFinish();
            mRefreshLayout.onPullDownRefreshComplete();
        }
    });
}
 
Example #24
Source File: BlogFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
private void refresh() {
    kjh.get(MY_BLOG_HOST, new HttpCallBack() {
        @Override
        public void onSuccess(String t) {
            super.onSuccess(t);
            KJLoger.debug("博客列表:" + t);
            if (t != null) {
                List<Blog> datas = Parser.getBlogList(t);
                adapter = new BlogAdapter(mList, datas);
                mList.setAdapter(adapter);
            }
            mEmptyLayout.dismiss();
        }

        @Override
        public void onFailure(int errorNo, String strMsg) {
            super.onFailure(errorNo, strMsg);
            if (adapter != null && adapter.getCount() > 0) {
                return;
            } else {
                mEmptyLayout.setErrorType(EmptyLayout.NODATA);
            }
        }

        @Override
        public void onFinish() {
            super.onFinish();
            mRefreshLayout.onPullDownRefreshComplete();
            mRefreshLayout.onPullUpRefreshComplete();
        }
    });
}
 
Example #25
Source File: ActiveFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
private void refresh() {
    kjh.get(ACTIVE_HOST, new HttpCallBack() {
        @Override
        public void onSuccess(String t) {
            super.onSuccess(t);
            KJLoger.debug(TAG + "网络请求:" + t);
            if (t != null && !t.equals(cache)) {
                ActiveList dataRes = Parser.xmlToBean(ActiveList.class, t);
                if (adapter == null) {
                    adapter = new ActiveAdapter(mListView, dataRes
                            .getEvents(), R.layout.item_list_active);
                    mListView.setAdapter(adapter);
                } else {
                    adapter.refresh(dataRes.getEvents());
                }
            }
            mEmptyLayout.dismiss();
        }

        @Override
        public void onFailure(int errorNo, String strMsg) {
            super.onFailure(errorNo, strMsg);
            if (adapter != null && adapter.getCount() > 0) {
                return;
            } else {
                mEmptyLayout.setErrorType(EmptyLayout.NODATA);
            }
        }

        @Override
        public void onFinish() {
            super.onFinish();
            mRefreshLayout.onPullDownRefreshComplete();
        }
    });
}
 
Example #26
Source File: AboutFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
private void download(String url) {
    final File folder = FileUtils.getSaveFolder(AppConfig.saveFolder);
    File tempFile = new File(folder + "/kjblog.apk.tmp");
    if (tempFile.exists()) {
        tempFile.delete();
    }
    ViewInject.toast("正在为你下载新版本");
    kjh.download(folder + "/kjblog.apk", url, new HttpCallBack() {
        /**
         * 下载过程
         */
        @Override
        public void onLoading(long count, long current) {
            super.onLoading(count, current);
        }

        /**
         * 下载完成,开始安装
         */
        @Override
        public void onSuccess(byte[] t) {
            super.onSuccess(t);
            SystemTool.installApk(outsideAty, new File(folder
                    + "/kjblog.apk"));
        }
    });
}
 
Example #27
Source File: AboutFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
private void update() {
    kjh.get("http://www.kymjs.com/api/version", new HttpCallBack() {
        @Override
        public void onSuccess(String t) {
            super.onSuccess(t);
            KJLoger.debug("检测更新===" + t);
            checkVersion(t);
        }
    });
}
 
Example #28
Source File: TweetFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 发布动弹
 */
private void handleSubmit(String strSpeech, File imageFile, String audioPath) {
    HttpConfig config = new HttpConfig();
    config.cacheTime = 0;
    KJHttp kjh = new KJHttp(config);
    HttpParams params = new HttpParams();
    params.putHeaders("cookie", UIHelper.getUser(outsideAty).getCookie());
    params.put("uid", UIHelper.getUser(outsideAty).getUid());
    params.put("msg", strSpeech + "          ——————我只是一条小尾巴");

    if (imageFile != null && imageFile.exists()) {
        params.put("img", imageFile);
    }
    if (!StringUtils.isEmpty(audioPath)) {
        params.put("amr", new File(audioPath));
    }
    kjh.post("http://www.oschina.net/action/api/tweet_pub", params,
            new HttpCallBack() {
                @Override
                public void onPreStart() {
                    super.onPreStart();
                    // 设置上传动画
                }

                @Override
                public void onSuccess(String t) {
                    super.onSuccess(t);
                    KJLoger.debug("发表动弹:" + t);
                    // 隐藏上传动画
                }

                @Override
                public void onFailure(int errorNo, String strMsg) {
                    super.onFailure(errorNo, strMsg);
                    // 设置上传动画失败图标
                }
            });
}
 
Example #29
Source File: CommonService.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
private void download(String url) {
    final File folder = FileUtils.getSaveFolder(AppConfig.saveFolder);
    File tempFile = new File(folder + "/kjblog.apk.tmp");
    if (tempFile.exists()) {
        tempFile.delete();
    }
    ViewInject.toast("正在为你下载新版本");
    kjh.download(folder + "/kjblog.apk", url, new HttpCallBack() {
        /**
         * 下载过程
         */
        @Override
        public void onLoading(long count, long current) {
            super.onLoading(count, current);
        }

        /**
         * 下载完成,开始安装
         */
        @Override
        public void onSuccess(byte[] t) {
            super.onSuccess(t);
            SystemTool.installApk(CommonService.this, new File(folder
                    + "/kjblog.apk"));
        }
    });
}
 
Example #30
Source File: TweetFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
private void refresh(final int page) {
    kjh.get(OSCTWEET_HOST + page, new HttpCallBack() {
        @Override
        public void onSuccess(String t) {
            super.onSuccess(t);
            KJLoger.debug(TAG + "网络请求" + t);
            List<Tweet> datas = Parser.xmlToBean(TweetsList.class, t)
                    .getList();
            tweets.addAll(datas);
            if (adapter == null) {
                adapter = new TweetAdapter(mListView, tweets,
                        R.layout.item_list_tweet);
                mListView.setAdapter(adapter);
            } else {
                adapter.refresh(tweets);
            }
            mEmptyLayout.dismiss();
        }

        @Override
        public void onFailure(int errorNo, String strMsg) {
            super.onFailure(errorNo, strMsg);
            if (adapter != null && adapter.getCount() > 0) {
                return;
            } else {
                mEmptyLayout.setErrorType(EmptyLayout.NODATA);
            }
        }

        @Override
        public void onFinish() {
            super.onFinish();
            mRefreshLayout.onPullDownRefreshComplete();
            mRefreshLayout.onPullUpRefreshComplete();
        }
    });
}