org.kymjs.kjframe.KJHttp Java Examples

The following examples show how to use org.kymjs.kjframe.KJHttp. 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: OSCBlogDetailFragment.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void initData() {
    super.initData();
    kjdb = KJDB.create(outsideAty);
    Bundle outData = aty.getBundleData();
    if (outData != null) {
        if (outData.getString(DATA_URL_KEY) != null) {
            blogUrl = outData.getString(DATA_URL_KEY);
        } else {
            OSCBLOG_ID = outData.getInt("oscblog_id", 295001);
            blogUrl = OSCBLOG_HOST + OSCBLOG_ID;
        }
    }
    HttpConfig config = new HttpConfig();
    config.cacheTime = 300;
    kjh = new KJHttp(config);
    cacheData = kjh.getStringCache(blogUrl);
}
 
Example #2
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 #3
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 #4
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 #5
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 #6
Source File: OSCBlogListFragment.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void initData() {
    super.initData();
    HttpConfig config = new HttpConfig();
    int hour = StringUtils.toInt(StringUtils.getDataTime("HH"), 0);
    if (hour > 7 && hour < 10) { // 如果是在早上7点到10点,就缓存的时间短一点
        config.cacheTime = 10;
    } else {
        config.cacheTime = 300;
    }
    config.useDelayCache = true;
    kjh = new KJHttp(config);

    Bundle bundle = aty.getBundleData();
    String name = null;
    if (bundle != null) {
        BLOGLIST_ID = bundle.getInt(BLOGLIST_KEY, 1428332);
        name = bundle.getString(BlogAuthorFragment.AUTHOR_NAME_KEY);
    }
    if (StringUtils.isEmpty(name)) {
        titleBarName = getString(R.string.osc_joke);
    } else {
        titleBarName = name + "的博客";
    }
}
 
Example #7
Source File: MainActivity.java    From Contacts with Apache License 2.0 5 votes vote down vote up
@Override
public void initData() {
    super.initData();
    HttpConfig config = new HttpConfig();
    HttpConfig.sCookie = "oscid=V" +
            "%2BbmxZFR8UfmpvrBHAcVRKALrd72iPWknXaWDa5Is3veK7WsxTSWY80kRXB1LoH%2F4VJ" +
            "%2F9s7K3Kd9CwCC1CAV%2BnJ7T3ka0blF8vZojozhUdOYkq6D6Laldg%3D%3D; Domain=.oschina" +
            ".net; Path=/; ";
    config.cacheTime = 0;
    kjh = new KJHttp();
}
 
Example #8
Source File: BlogAuthorFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void initData() {
    super.initData();
    HttpConfig config = new HttpConfig();
    config.cacheTime = 30;
    config.useDelayCache = true;
    kjh = new KJHttp(config);
}
 
Example #9
Source File: BlogFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void initData() {
    super.initData();
    HttpConfig config = new HttpConfig();
    int hour = StringUtils.toInt(StringUtils.getDataTime("HH"), 0);
    if (hour > 12 && hour < 22) {
        config.cacheTime = 10;
    } else {
        config.cacheTime = 300;
    }
    config.useDelayCache = true;
    kjh = new KJHttp(config);
}
 
Example #10
Source File: WeChatFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void initData() {
    super.initData();
    HttpConfig config = new HttpConfig();
    config.cacheTime = 300;
    config.useDelayCache = true;
    kjh = new KJHttp(config);
}
 
Example #11
Source File: ActiveFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void initData() {
    super.initData();
    HttpConfig config = new HttpConfig();
    config.useDelayCache = false;
    kjh = new KJHttp(config);
}
 
Example #12
Source File: AboutFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void initData() {
    super.initData();
    HttpConfig config = new HttpConfig();
    config.cacheTime = 0;
    kjh = new KJHttp(config);
}
 
Example #13
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 #14
Source File: TweetFragment.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void initData() {
    super.initData();
    HttpConfig config = new HttpConfig();
    config.cacheTime = 0;
    config.useDelayCache = false;
    kjh = new KJHttp(config);
}
 
Example #15
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 #16
Source File: Login.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
private void doLogin() {
    if (!inputCheck()) {
        return;
    }
    HttpConfig config = new HttpConfig();
    config.cacheTime = 0;
    KJHttp kjh = new KJHttp(config);
    HttpParams params = new HttpParams();
    params.put("username", mEtUid.getText().toString());
    params.put("pwd", mEtPwd.getText().toString());
    kjh.post("http://www.oschina.net/action/api/login_validate", params,
            new HttpCallBack() {
                @Override
                public void onFailure(int errorNo, String strMsg) {
                    super.onFailure(errorNo, strMsg);
                    ViewInject.toast("网络不好" + strMsg);
                }

                @Override
                public void onSuccess(
                        java.util.Map<String, String> headers, byte[] t) {
                    String cookie = headers.get("Set-Cookie");
                    if (t != null) {
                        String str = new String(t);
                        KJLoger.debug("登陆网络请求:" + new String(t));
                        LoginData data = Parser.xmlToBean(LoginData.class,
                                str);
                        try {
                            if (1 == data.getResult().getErrorCode()) {
                                User user = data.getUser();
                                user.setCookie(cookie);
                                user.setAccount(mEtUid.getText().toString());
                                user.setPwd(mEtPwd.getText().toString());
                                UIHelper.saveUser(aty, user);
                                finish();
                            } else {
                                mEtPwd.setText(null);
                                mEtUid.setText(null);
                            }
                            ViewInject.toast(data.getResult()
                                    .getErrorMessage());
                            // 太多判断了,写的蛋疼,还不如一个NullPointerException
                        } catch (NullPointerException e) {
                            ViewInject.toast("登陆失败");
                            mEtPwd.setText(null);
                            mEtUid.setText(null);
                        }
                    }
                }

                ;
            });
}
 
Example #17
Source File: ImageDisplayer.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
/**
 * 创建一个图片显示器
 *
 * @param bitmapConfig KJBitmap配置器
 */
public ImageDisplayer(KJHttp http, BitmapConfig bitmapConfig) {
    kjHttp = http;
    mMemoryCache = BitmapConfig.mMemoryCache;
    mResponseDelayMs = bitmapConfig.delayTime;
}
 
Example #18
Source File: DownloadTaskQueue.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
public void setRequestQueue(KJHttp requestQueue) {
    this.mRequestQueue = requestQueue;
}
 
Example #19
Source File: DownloadTaskQueue.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
KJHttp getRequestQueue() {
    return mRequestQueue;
}
 
Example #20
Source File: Request.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
public Request<?> setRequestQueue(KJHttp requestQueue) {
    mRequestQueue = requestQueue;
    return this;
}
 
Example #21
Source File: CommonService.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
public CommonService() {
    super("CommonService");
    HttpConfig config = new HttpConfig();
    config.cacheTime = 0;
    kjh = new KJHttp(config);
}
 
Example #22
Source File: HttpActivity.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
/**
 * 读取一条指定缓存,没有会返回空字符串
 */
private void readCache() {
    KJHttp kjh = new KJHttp();
    String url = "http://www.oschina.net/action/api/team_stickynote_batch_update";
    toast(new String(kjh.getCache(url)));
}
 
Example #23
Source File: HttpActivity.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
/**
 * 移除指定key的缓存(注意,get请求的时候,记得把参数附带上)
 */
private void removeCache() {
    KJHttp kjh = new KJHttp();
    String url = "http://www.oschina.net/action/api/team_stickynote_batch_update";
    kjh.removeCache(url);
}
 
Example #24
Source File: HttpActivity.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
/**
 * 清空全部缓存
 */
private void cleanCache() {
    KJHttp kjh = new KJHttp();
    kjh.cleanCache();
}
 
Example #25
Source File: SamplePagerAdapter.java    From KJGallery with Apache License 2.0 4 votes vote down vote up
public SamplePagerAdapter(Activity aty, String[] imageUrls) {
    this.aty = aty;
    this.imageUrls = imageUrls;
    kjh = new KJHttp();
}