org.kymjs.kjframe.http.HttpConfig Java Examples
The following examples show how to use
org.kymjs.kjframe.http.HttpConfig.
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: KJHttp.java From KJFrameForAndroid with Apache License 2.0 | 6 votes |
/** * 将一个请求标记为已完成 */ public void finish(Request<?> request) { synchronized (mCurrentRequests) { mCurrentRequests.remove(request); } if (request.shouldCache()) { synchronized (mWaitingRequests) { String cacheKey = request.getCacheKey(); Queue<Request<?>> waitingRequests = mWaitingRequests.remove(cacheKey); if (waitingRequests != null) { if (HttpConfig.DEBUG) { KJLoger.debug("Releasing %d waiting requests for cacheKey=%s.", waitingRequests.size(), cacheKey); } mCacheQueue.addAll(waitingRequests); } } } }
Example #2
Source File: OSCBlogListFragment.java From KJFrameForAndroid with Apache License 2.0 | 6 votes |
@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 #3
Source File: OSCBlogDetailFragment.java From KJFrameForAndroid with Apache License 2.0 | 6 votes |
@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 #4
Source File: Core.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
/** * 下载 * * @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 #5
Source File: KJHttp.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
/** * 启动队列调度 */ private void start() { stop();// 首先关闭之前的运行,不管是否存在 mCacheDispatcher = new CacheDispatcher(mCacheQueue, mNetworkQueue, mConfig); mCacheDispatcher.start(); // 构建线程池 for (int i = 0; i < mTaskThreads.length; i++) { NetworkDispatcher tasker = new NetworkDispatcher(mNetworkQueue, mConfig.mNetwork, HttpConfig.mCache, mConfig.mDelivery); mTaskThreads[i] = tasker; tasker.start(); } }
Example #6
Source File: KJHttp.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
/** * 获取缓存数据 * * @param url 哪条url的缓存 * @return 缓存的二进制数组 */ public byte[] getCache(String url) { Cache cache = HttpConfig.mCache; cache.initialize(); Cache.Entry entry = cache.get(url); if (entry != null) { return entry.data; } else { return new byte[0]; } }
Example #7
Source File: ImageRequest.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
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 #8
Source File: KJBitmap.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
/** * 获取缓存数据 * * @param url 哪条url的缓存 * @return 缓存数据的二进制数组 */ public byte[] getCache(String url) { Cache cache = HttpConfig.mCache; cache.initialize(); Cache.Entry entry = cache.get(url); if (entry != null) { return entry.data; } else { return new byte[0]; } }
Example #9
Source File: MainActivity.java From Contacts with Apache License 2.0 | 5 votes |
@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 #10
Source File: BlogAuthorFragment.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
@Override protected void initData() { super.initData(); HttpConfig config = new HttpConfig(); config.cacheTime = 30; config.useDelayCache = true; kjh = new KJHttp(config); }
Example #11
Source File: WeChatFragment.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
@Override protected void initData() { super.initData(); HttpConfig config = new HttpConfig(); config.cacheTime = 300; config.useDelayCache = true; kjh = new KJHttp(config); }
Example #12
Source File: TweetFragment.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
@Override protected void initData() { super.initData(); HttpConfig config = new HttpConfig(); config.cacheTime = 0; config.useDelayCache = false; kjh = new KJHttp(config); }
Example #13
Source File: TweetFragment.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
/** * 发布动弹 */ 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: AboutFragment.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
@Override protected void initData() { super.initData(); HttpConfig config = new HttpConfig(); config.cacheTime = 0; kjh = new KJHttp(config); }
Example #15
Source File: ActiveFragment.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
@Override protected void initData() { super.initData(); HttpConfig config = new HttpConfig(); config.useDelayCache = false; kjh = new KJHttp(config); }
Example #16
Source File: BlogFragment.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
@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 #17
Source File: KJBitmap.java From KJFrameForAndroid with Apache License 2.0 | 4 votes |
public KJBitmap(HttpConfig httpConfig, BitmapConfig bitmapConfig) { this(new KJHttp(httpConfig), bitmapConfig); }
Example #18
Source File: KJBitmap.java From KJFrameForAndroid with Apache License 2.0 | 4 votes |
/** * 清空缓存 */ public void cleanCache() { BitmapConfig.mMemoryCache.clean(); HttpConfig.mCache.clean(); }
Example #19
Source File: AppContext.java From KJFrameForAndroid with Apache License 2.0 | 4 votes |
@Override public void onCreate() { super.onCreate(); HttpConfig.CACHEPATH = AppConfig.httpCachePath; CrashHandler.create(this); }
Example #20
Source File: Login.java From KJFrameForAndroid with Apache License 2.0 | 4 votes |
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 #21
Source File: KJHttp.java From KJFrameForAndroid with Apache License 2.0 | 4 votes |
public Builder config(HttpConfig httpConfig) { this.httpConfig = httpConfig; return this; }
Example #22
Source File: KJHttp.java From KJFrameForAndroid with Apache License 2.0 | 4 votes |
/** * 清空缓存 */ public void cleanCache() { HttpConfig.mCache.clean(); }
Example #23
Source File: KJHttp.java From KJFrameForAndroid with Apache License 2.0 | 4 votes |
public HttpConfig getConfig() { return mConfig; }
Example #24
Source File: KJHttp.java From KJFrameForAndroid with Apache License 2.0 | 4 votes |
public void setConfig(HttpConfig config) { this.mConfig = config; }
Example #25
Source File: CommonService.java From KJFrameForAndroid with Apache License 2.0 | 4 votes |
public CommonService() { super("CommonService"); HttpConfig config = new HttpConfig(); config.cacheTime = 0; kjh = new KJHttp(config); }
Example #26
Source File: KJHttp.java From KJFrameForAndroid with Apache License 2.0 | 4 votes |
/** * 向请求队列加入一个请求 * Note:此处工作模式是这样的:KJHttp可以看做是一个队列类,而本方法不断的向这个队列添加request;另一方面, * TaskThread不停的从这个队列中取request并执行。类似的设计可以参考Handle...Looper...MessageQueue的关系 */ public <T> Request<T> add(Request<T> request) { if (request.getCallback() != null) { request.getCallback().onPreStart(); } // 标记该请求属于该队列,并将它添加到该组当前的请求。 request.setRequestQueue(this); synchronized (mCurrentRequests) { mCurrentRequests.add(request); } // 设置进程优先序列 request.setSequence(mSequenceGenerator.incrementAndGet()); // 如果请求不可缓存,跳过缓存队列,直接进入网络。 if (!request.shouldCache()) { mNetworkQueue.add(request); return request; } // 如果已经在mWaitingRequests中有本请求,则替换 synchronized (mWaitingRequests) { String cacheKey = request.getCacheKey(); if (mWaitingRequests.containsKey(cacheKey)) { // There is already a request in flight. Queue up. Queue<Request<?>> stagedRequests = mWaitingRequests .get(cacheKey); if (stagedRequests == null) { stagedRequests = new LinkedList<Request<?>>(); } stagedRequests.add(request); mWaitingRequests.put(cacheKey, stagedRequests); if (HttpConfig.DEBUG) { KJLoger.debug("Request for cacheKey=%s is in flight, putting on hold.", cacheKey); } } else { mWaitingRequests.put(cacheKey, null); mCacheQueue.add(request); } return request; } }
Example #27
Source File: GifRequest.java From KJGallery with Apache License 2.0 | 4 votes |
public GifRequest(String url, HttpCallBack callback) { super(HttpMethod.GET, url, callback); mHeaders.put("cookie", HttpConfig.sCookie); }
Example #28
Source File: KJBitmap.java From KJFrameForAndroid with Apache License 2.0 | 2 votes |
/** * 移除一个缓存 * * @param url 哪条url的缓存 */ public void removeCache(String url) { BitmapConfig.mMemoryCache.remove(url); HttpConfig.mCache.remove(url); }
Example #29
Source File: KJHttp.java From KJFrameForAndroid with Apache License 2.0 | 2 votes |
/** * 移除一个缓存 * * @param url 哪条url的缓存 */ public void removeCache(String url) { HttpConfig.mCache.remove(url); }