org.kymjs.kjframe.utils.KJLoger Java Examples

The following examples show how to use org.kymjs.kjframe.utils.KJLoger. 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
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 #2
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 #3
Source File: Parser.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 检测更新
 *
 * @param json
 */
public static String checkVersion(Context cxt, String json) {
    String url = "";
    try {
        JSONObject obj = new JSONObject(json);
        int serverVersion = obj.optInt("version", 0);
        int currentVersion = SystemTool.getAppVersionCode(cxt);
        KJLoger.debug("当前版本:" + currentVersion + "最新版本:" + serverVersion);
        if (serverVersion > currentVersion) {
            url = obj.optString("url");
        }
    } catch (JSONException e) {
        Log.e("kymjs", "getBlogList()解析异常");
    }
    return url;
}
 
Example #4
Source File: KJDB.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 删除所有数据表
 */
public void dropDb() {
    Cursor cursor = db.rawQuery(
            "SELECT name FROM sqlite_master WHERE type ='table'", null);
    if (cursor != null) {
        while (cursor.moveToNext()) {
            // 添加异常捕获.忽略删除所有表时出现的异常:
            // table sqlite_sequence may not be dropped
            try {
                db.execSQL("DROP TABLE " + cursor.getString(0));
            } catch (SQLException e) {
                KJLoger.debug(getClass().getName() + e.getMessage());
            }
        }
    }
    if (cursor != null) {
        cursor.close();
        cursor = null;
    }
}
 
Example #5
Source File: KJHttp.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 将一个请求标记为已完成
 */
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 #6
Source File: MainActivity.java    From Contacts with Apache License 2.0 6 votes vote down vote up
private void parser(String json) {
    try {
        JSONArray array = new JSONArray(json);
        for (int i = 0; i < array.length(); i++) {
            JSONObject object = array.optJSONObject(i);
            Contact data = new Contact();
            data.setName(object.optString("name"));
            data.setUrl(object.optString("portrait"));
            data.setId(object.optInt("id"));
            data.setPinyin(HanziToPinyin.getPinYin(data.getName()));
            datas.add(data);
        }
        mFooterView.setText(datas.size() + "位联系人");
        mAdapter = new ContactAdapter(mListView, datas);
        mListView.setAdapter(mAdapter);
    } catch (JSONException e) {
        KJLoger.debug("解析异常" + e.getMessage());
    }
}
 
Example #7
Source File: DiskCache.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Writes the contents of this CacheHeader to the specified
 * OutputStream.
 */
public boolean writeHeader(OutputStream os) {
    try {
        writeInt(os, CACHE_MAGIC);
        writeString(os, key);
        writeString(os, etag == null ? "" : etag);
        writeLong(os, serverDate);
        writeLong(os, ttl);
        writeLong(os, softTtl);
        writeStringStringMap(responseHeaders, os);
        os.flush();
        return true;
    } catch (IOException e) {
        KJLoger.debug("%s", e.toString());
        return false;
    }
}
 
Example #8
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 #9
Source File: Property.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
private static Date stringToDateTime(String strDate) {
    if (strDate != null) {
        try {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).parse
                    (strDate);
        } catch (ParseException e) {
            KJLoger.debug("时间解析异常");
        }
    }
    return null;
}
 
Example #10
Source File: Request.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 通知请求队列,本次请求已经完成
 */
public void finish(final String tag) {
    if (mRequestQueue != null) {
        mRequestQueue.finish(this);
    }
    long requestTime = SystemClock.elapsedRealtime() - mRequestBirthTime;
    if (requestTime >= SLOW_REQUEST_THRESHOLD_MS) {
        KJLoger.debug("%d ms: %s", requestTime, this.toString());
    }
}
 
Example #11
Source File: JsonRequest.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] getBody() {
    try {
        return mRequestBody == null ? null : mRequestBody
                .getBytes(PROTOCOL_CHARSET);
    } catch (UnsupportedEncodingException uee) {
        KJLoger.debug(
                "Unsupported Encoding while trying to get the bytes of %s using %s",
                mRequestBody, PROTOCOL_CHARSET);
        return null;
    }
}
 
Example #12
Source File: Network.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
     * 把HttpEntry转换为byte[]
     *
     * @throws IOException
     * @throws KJHttpException
     */
    private byte[] entityToBytes(KJHttpResponse kjHttpResponse) throws IOException,
            KJHttpException {
        PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(
                ByteArrayPool.get(), (int) kjHttpResponse.getContentLength());
        byte[] buffer = null;
        try {
            InputStream in = kjHttpResponse.getContentStream();
            if (in == null) {
                throw new KJHttpException("server error");
            }
            buffer = ByteArrayPool.get().getBuf(1024);
            int count;
            while ((count = in.read(buffer)) != -1) {
                bytes.write(buffer, 0, count);
            }
            return bytes.toByteArray();
        } finally {
            try {
//                entity.consumeContent();
                kjHttpResponse.getContentStream().close();
            } catch (IOException e) {
                KJLoger.debug("Error occured when calling consumingContent");
            }
            ByteArrayPool.get().returnBuf(buffer);
            bytes.close();
        }
    }
 
Example #13
Source File: DiskCache.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 清空磁盘缓存
 */
@Override
public synchronized void clean() {
    File[] files = mRootDirectory.listFiles();
    if (files != null) {
        for (File file : files) {
            file.delete();
        }
    }
    mEntries.clear();
    mTotalSize = 0;
    KJLoger.debug("disk Cache cleared.");
}
 
Example #14
Source File: DiskCache.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 获取一个cache
 *
 * @return 如果不存在返回null
 */
@Override
public synchronized Entry get(String key) {
    CacheHeader entry = mEntries.get(key);
    if (entry == null) {
        return null;
    }

    File file = getFileForKey(key);
    CountingInputStream cis = null;
    try {
        cis = new CountingInputStream(new FileInputStream(file));
        CacheHeader.readHeader(cis); // eat header
        byte[] data = streamToBytes(cis,
                (int) (file.length() - cis.bytesRead));
        return entry.toCacheEntry(data);
    } catch (IOException e) {
        KJLoger.debug("%s: %s", file.getAbsolutePath(), e.toString());
        remove(key);
        return null;
    } finally {
        if (cis != null) {
            try {
                cis.close();
            } catch (IOException ioe) {
                return null;
            }
        }
    }
}
 
Example #15
Source File: DiskCache.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void remove(String key) {
    boolean deleted = getFileForKey(key).delete();
    removeEntry(key);
    if (!deleted) {
        KJLoger.debug(
                "Could not delete cache entry for key=%s, filename=%s",
                key, getFilenameForKey(key));
    }
}
 
Example #16
Source File: FormRequest.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] getBody() {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        mParams.writeTo(bos);
    } catch (IOException e) {
        KJLoger.debug("FormRequest75--->IOException writing to ByteArrayOutputStream");
    }
    return bos.toByteArray();
}
 
Example #17
Source File: SupportActivity.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/***************************************************************************
 * print Activity callback methods
 ***************************************************************************/
@Override
protected void onCreate(Bundle savedInstanceState) {
    aty = this;
    KJActivityStack.create().addActivity(this);
    KJLoger.state(this.getClass().getName(), "---------onCreat ");
    super.onCreate(savedInstanceState);

    setRootView(); // 必须放在annotate之前调用
    AnnotateUtil.initBindView(this);
    initializer();
    registerBroadcast();
}
 
Example #18
Source File: SupportActivity.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    unRegisterBroadcast();
    activityState = DESTROY;
    KJLoger.state(this.getClass().getName(), "---------onDestroy ");
    super.onDestroy();
    KJActivityStack.create().finishActivity(this);
    currentKJFragment = null;
    currentSupportFragment = null;
    callback = null;
    threadHandle = null;
    aty = null;
}
 
Example #19
Source File: KJActivity.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/***************************************************************************
 * print Activity callback methods
 ***************************************************************************/
@Override
protected void onCreate(Bundle savedInstanceState) {
    aty = this;
    KJActivityStack.create().addActivity(this);
    KJLoger.state(this.getClass().getName(), "---------onCreat ");

    setRootView(); // 必须放在annotate之前调用
    AnnotateUtil.initBindView(this);
    initializer();
    registerBroadcast();
    super.onCreate(savedInstanceState);
}
 
Example #20
Source File: KJActivity.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    unRegisterBroadcast();
    activityState = DESTROY;
    KJLoger.state(this.getClass().getName(), "---------onDestroy ");
    super.onDestroy();
    KJActivityStack.create().finishActivity(this);
    currentKJFragment = null;
    currentSupportFragment = null;
    callback = null;
    threadHandle = null;
    aty = null;
}
 
Example #21
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();
        }
    });
}
 
Example #22
Source File: GifRequest.java    From KJGallery with Apache License 2.0 5 votes vote down vote up
@Override
public Response<byte[]> parseNetworkResponse(NetworkResponse response) {
    synchronized (sDecodeLock) {
        try {
            return doParse(response);
        } catch (OutOfMemoryError e) {
            KJLoger.debug("Caught OOM for %d byte image, url=%s",
                    response.data.length, getUrl());
            return Response.error(new KJHttpException(e));
        }
    }
}
 
Example #23
Source File: ImageRequest.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
    synchronized (sDecodeLock) {
        try {
            return doParse(response);
        } catch (OutOfMemoryError e) {
            KJLoger.debug("Caught OOM for %d byte image, url=%s",
                    response.data.length, getUrl());
            return Response.error(new KJHttpException(e));
        }
    }
}
 
Example #24
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 #25
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 #26
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 #27
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 #28
Source File: KJDB.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 把List<KeyValue>数据存储到ContentValues
 * 
 * @param list
 * @param cv
 */
private void insertContentValues(List<KeyValue> list, ContentValues cv) {
    if (list != null && cv != null) {
        for (KeyValue kv : list) {
            cv.put(kv.getKey(), kv.getValue().toString());
        }
    } else {
        KJLoger.debug(getClass().getName()
                + "insertContentValues: List<KeyValue> is empty or ContentValues is empty!");
    }

}
 
Example #29
Source File: KJDB.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
private void exeSqlInfo(SqlInfo sqlInfo) {
    if (sqlInfo != null) {
        debugSql(sqlInfo.getSql());
        db.execSQL(sqlInfo.getSql(), sqlInfo.getBindArgsAsArray());
    } else {
        KJLoger.debug(getClass().getName() + "sava error:sqlInfo is null");
    }
}
 
Example #30
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();
        }
    });
}