Java Code Examples for com.socks.library.KLog

The following examples show how to use com.socks.library.KLog. These examples are extracted from open source projects. 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 Project: star-zone-android   Source File: FileUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 复制单个文件
 *
 * @param oldPath String 原文件路径
 * @param newPath String 复制后路径
 * @return boolean
 */
public static boolean copyFile(String oldPath, String newPath) {
    try {
        int byteread = 0;
        File oldfile = new File(oldPath);
        if (oldfile.exists()) { // 文件存在时
            InputStream inStream = new FileInputStream(oldPath); // 读入原文件
            FileOutputStream fs = new FileOutputStream(newPath);
            byte[] buffer = new byte[IO_BUFFER_SIZE];

            while ((byteread = inStream.read(buffer)) != -1) {
                fs.write(buffer, 0, byteread);
            }
            inStream.close();
            fs.close();
        }
    } catch (Exception e) {
        KLog.e(e);
        return false;
    }
    return true;
}
 
Example 2
Source Project: star-zone-android   Source File: FileUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 写入文件
 *
 * @param strFileName 文件名
 * @param ins         流
 */
public static void writeToFile(String strFileName, InputStream ins) {
    try {
        File file = new File(strFileName);

        FileOutputStream fouts = new FileOutputStream(file);
        int len;
        int maxSize = 1024 * 1024;
        byte buf[] = new byte[maxSize];
        while ((len = ins.read(buf, 0, maxSize)) != -1) {
            fouts.write(buf, 0, len);
            fouts.flush();
        }

        fouts.close();
    } catch (IOException e) {
        KLog.e(e);
    }
}
 
Example 3
Source Project: star-zone-android   Source File: FileUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 调用系统打开文件
 */
public static boolean openFile(File file, Context context) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // 设置intent的Action属性
    intent.setAction(Intent.ACTION_VIEW);
    // 获取文件file的MIME类型
    String type = getMIMEType(file);
    // 设置intent的data和Type属性。
    intent.setDataAndType(Uri.fromFile(file), type);
    // 跳转
    try {
        ((Activity) context).startActivity(intent);
    } catch (ActivityNotFoundException e) {
        KLog.e(e);
        return false;
    }
    return true;
}
 
Example 4
Source Project: star-zone-android   Source File: CircleBaseViewHolder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onBindData(MomentInfo data, int position) {
    if (data == null) {
        KLog.e("数据是空的!!!!");
        findView(userText, R.id.item_text_field);
        userText.setText("这个动态的数据是空的。。。。OMG");
        return;
    }
    this.momentInfo = data;
    this.itemPosition = position;
    //通用数据绑定
    onBindMutualDataToViews(data);
    //点击事件
    menuButton.setOnClickListener(onMenuButtonClickListener);
    menuButton.setTag(R.id.momentinfo_data_tag_id, data);
    deleteMoments.setOnClickListener(onDeleteMomentClickListener);
    //传递到子类
    onBindDataToView(data, position, getViewType());
}
 
Example 5
Source Project: BitkyShop   Source File: CartFragment.java    License: MIT License 6 votes vote down vote up
/**
 * 更新全选复选框的状态
 */
private void updateCheckedAll() {
  Boolean isCheckedAll = true;
  if (commodityLocals == null || commodityLocals.size() == 0) {
    isCheckedAll = false;
  } else {
    for (CommodityLocal commodityLocal : commodityLocals) {
      if (!commodityLocal.getCartIsChecked()) {
        isCheckedAll = false;
        break;
      }
    }
  }
  KLog.d("isCheckedAll+" + isCheckedAll);
  checkBoxAll.setChecked(isCheckedAll);
}
 
Example 6
Source Project: star-zone-android   Source File: PhotoBrowseActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void finish() {
    final GalleryPhotoView currentPhotoView = viewBuckets.get(photoViewpager.getCurrentItem());
    if (currentPhotoView == null) {
        KLog.e(TAG, "childView is null");
        super.finish();
        return;
    }
    final Rect endRect = photoBrowseInfo.getViewLocalRects().get(photoViewpager.getCurrentItem());
    currentPhotoView.playExitAnima(endRect, blackBackground, new GalleryPhotoView.OnExitAnimaEndListener() {
        @Override
        public void onExitAnimaEnd() {
            PhotoBrowseActivity.super.finish();
            overridePendingTransition(0, 0);
        }
    });
}
 
Example 7
Source Project: star-zone-android   Source File: DefaultGlideModule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    //磁盘缓存
    builder.setDiskCache(new DiskLruCacheFactory(context.getCacheDir().getAbsolutePath(), 50 * 1024 * 1024));
    KLog.d("Glide", "glide cache file path  >>>  " + context.getCacheDir().getAbsolutePath());
    //内存缓存
    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build();
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    //设置比默认大小大1.5倍的缓存和图片池大小
    int customMemoryCacheSize = (int) (1.5 * defaultMemoryCacheSize);
    int customBitmapPoolSize = defaultBitmapPoolSize;

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));


    KLog.d("Glide", "bitmapPoolSize >>>>>   " +
            formatFileSize(context, customBitmapPoolSize) +
            " / memorySize>>>>>>>>   " +
            formatFileSize(context, customMemoryCacheSize));

    builder.setLogLevel(Log.ERROR);
}
 
Example 8
public HeaderViewWrapperAdapter(RecyclerView recyclerView,
                                @NonNull RecyclerView.Adapter mWrappedAdapter,
                                ArrayList<FixedViewInfo> mHeaderViewInfos,
                                ArrayList<FixedViewInfo> mFooterViewInfos) {
    this.recyclerView = recyclerView;
    this.mWrappedAdapter = mWrappedAdapter;
    try {
        mWrappedAdapter.registerAdapterDataObserver(mDataObserver);
    }catch (IllegalStateException e){
        //maybe observer is added
        KLog.w(e);
    }
    if (mHeaderViewInfos == null) {
        this.mHeaderViewInfos = EMPTY_INFO_LIST;
    } else {
        this.mHeaderViewInfos = mHeaderViewInfos;
    }
    if (mFooterViewInfos == null) {
        this.mFooterViewInfos = EMPTY_INFO_LIST;
    } else {
        this.mFooterViewInfos = mFooterViewInfos;
    }
}
 
Example 9
Source Project: OkHttpPlus   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
public void downloadFile(View view) {

        String desFileDir = Environment.getExternalStorageDirectory().getAbsolutePath();
        OkHttpProxy.download(URL_DOWMLOAD, new DownloadListener(desFileDir, "json.jar") {

            @Override
            public void onUIProgress(Progress progress) {
                //当下载资源长度不可知时,progress.getTotalBytes()为-1,此时不能显示下载进度
                int pro = (int) (progress.getCurrentBytes() / progress.getTotalBytes() * 100);
                if (pro > 0) {
                    pb.setProgress(pro);
                }
                KLog.d("pro = " + pro + " getCurrentBytes = " + progress.getCurrentBytes() + " getTotalBytes = " + progress.getTotalBytes());
            }

            @Override
            public void onSuccess(File file) {
                tv_response.setText(file.getAbsolutePath());
            }

            @Override
            public void onFailure(Exception e) {
                tv_response.setText(e.getMessage());
            }
        });
    }
 
Example 10
Source Project: BitkyShop   Source File: SearchActivity.java    License: MIT License 6 votes vote down vote up
private void searchCommodity() {
  ((InputMethodManager) context.getSystemService(
      Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(searchEdittext.getWindowToken(),
      InputMethodManager.HIDE_NOT_ALWAYS);
  String msg = searchEdittext.getText().toString().trim();
  if (msg.equals("")) {
    toastUtil.show("请输入要搜索的商品");
    return;
  }
  BmobQuery<Commodity> bmobQuery = new BmobQuery<>();
  bmobQuery.addWhereEqualTo("categorySub", msg);
  KLog.d(msg);
  bmobQuery.findObjects(new FindListener<Commodity>() {
    @Override public void done(List<Commodity> list, BmobException e) {
      if (e != null) {
        KLog.d(e.getMessage());
      }
      if (list != null) {
        KLog.d(list.size());
      }
    }
  });
}
 
Example 11
Source Project: ZZShow   Source File: NewsFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
        mParam1 = getArguments().getString(ARG_PARAM1);
        mParam2 = getArguments().getString(ARG_PARAM2);
    }
    mSubscription = RxBus.getInstance().toObservable(ChannelChangeEvent.class)
            .subscribe(new Action1<ChannelChangeEvent>() {
                @Override
                public void call(ChannelChangeEvent channelChangeEvent) {
                    KLog.d("NewsChannelPresenterImpl","GET ---------------");
                    if(channelChangeEvent.isChannelChanged()) {
                        mPresenter.loadNewsChannels();
                        if(channelChangeEvent.getChannelName() != null) {
                            mCurrentViewPagerName = channelChangeEvent.getChannelName();
                        }
                    }else{
                        if(channelChangeEvent.getChannelName() != null) {
                            mCurrentViewPagerName = channelChangeEvent.getChannelName();
                            mViewPager.setCurrentItem(getCurrentViewPagerPosition());
                        }
                    }
                }
            });
}
 
Example 12
Source Project: ZZShow   Source File: SplashActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void startLogoOuterAndAppName() {
    final ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
    valueAnimator.setDuration(1000);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float fraction = animation.getAnimatedFraction();
            KLog.d("fraction: " + fraction);
            if (fraction >= 0.8 && !isShowingRubberEffect) {
                isShowingRubberEffect = true;
                startLogoOuter();
                startShowAppName();
                finishActivity();
            } else if (fraction >= 0.95) {
                valueAnimator.cancel();
                startLogoInner2();
            }

        }
    });
    valueAnimator.start();
}
 
Example 13
Source Project: ZZShow   Source File: DBManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 修改
 * @param channelTable 对象
 */
public int update (NewsChannelTable channelTable){
    db.beginTransaction();
    int index = -1;
    try {
        ContentValues values = new ContentValues();
        values.put("news_channel_name", channelTable.getNewsChannelName());
        values.put("news_channel_id", channelTable.getNewsChannelId());
        values.put("news_channel_type", channelTable.getNewsChannelType());
        values.put("news_channel_select", channelTable.isNewsChannelSelect() ? 1:0);
        values.put("news_channel_index", channelTable.getNewsChannelIndex());
        values.put("news_channel_fixed", channelTable.isNewsChannelFixed()? 1:0);
        index = db.update(DBHelper.TABLE_NEWS_CHANNEL,values,"news_channel_id = ?",new String[]{channelTable.getNewsChannelId()});
        db.setTransactionSuccessful();
    }catch (Exception e){
        KLog.e(e.getMessage());
    }finally {
        db.endTransaction();
    }
    return index;
}
 
Example 14
Source Project: KLog   Source File: XmlLog.java    License: Apache License 2.0 6 votes vote down vote up
public static void printXml(String tag, String xml, String headString) {

        if (xml != null) {
            xml = XmlLog.formatXML(xml);
            xml = headString + "\n" + xml;
        } else {
            xml = headString + KLog.NULL_TIPS;
        }

        KLogUtil.printLine(tag, true);
        String[] lines = xml.split(KLog.LINE_SEPARATOR);
        for (String line : lines) {
            if (!KLogUtil.isEmpty(line)) {
                Log.d(tag, "║ " + line);
            }
        }
        KLogUtil.printLine(tag, false);
    }
 
Example 15
Source Project: ZZShow   Source File: DBManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据条件查询记录条数
 *
 * @param selection    条件
 * @param selectionArgs  值
 * @return
 */
public long getCountByWhere(String selection,String[] selectionArgs){
    db.beginTransaction();
    long count = 0;
    Cursor cursor = null;
    try {
        cursor = db.rawQuery("select count(news_channel_id) from " + DBHelper.TABLE_NEWS_CHANNEL + " where " + selection,selectionArgs);
        cursor.moveToFirst();
        count = cursor.getLong(0);
        db.setTransactionSuccessful();
    }catch (Exception e){
        KLog.e(e.getMessage());
    }finally {
        if(cursor != null) cursor.close();
        db.endTransaction();
    }
    return count;
}
 
Example 16
Source Project: KLog   Source File: JsonLog.java    License: Apache License 2.0 6 votes vote down vote up
public static void printJson(String tag, String msg, String headString) {

        String message;

        try {
            if (msg.startsWith("{")) {
                JSONObject jsonObject = new JSONObject(msg);
                message = jsonObject.toString(KLog.JSON_INDENT);
            } else if (msg.startsWith("[")) {
                JSONArray jsonArray = new JSONArray(msg);
                message = jsonArray.toString(KLog.JSON_INDENT);
            } else {
                message = msg;
            }
        } catch (JSONException e) {
            message = msg;
        }

        KLogUtil.printLine(tag, true);
        message = headString + KLog.LINE_SEPARATOR + message;
        String[] lines = message.split(KLog.LINE_SEPARATOR);
        for (String line : lines) {
            Log.d(tag, "║ " + line);
        }
        KLogUtil.printLine(tag, false);
    }
 
Example 17
Source Project: star-zone-android   Source File: BaseActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    KLog.i("当前打开 :  " + this.getClass().getSimpleName());
    if (mPermissionHelper == null) {
        mPermissionHelper = new PermissionHelper(this);
    }
    ARouter.getInstance().inject(this);
    onHandleIntent(getIntent());
}
 
Example 18
Source Project: star-zone-android   Source File: PermissionHelper.java    License: Apache License 2.0 5 votes vote down vote up
private void log(String desc, List<String> data) {
    String logText = null;
    if (!ToolUtil.isListEmpty(data)) {
        for (String datum : data) {
            logText = datum + "\n";
        }
    }
    KLog.i(TAG, desc + logText);
}
 
Example 19
Source Project: star-zone-android   Source File: CompressManager.java    License: Apache License 2.0 5 votes vote down vote up
public void start(OnCompressListener listener) {
    BaseCompressTaskHelper helper;
    if (getContext() == null) {
        KLog.e("context为空");
        return;
    }
    if (ToolUtil.isListEmpty(mOptions)) {
        KLog.e("配置为空");
        return;
    }
    new CompressTaskQueue(getContext(), mOptions, listener).start();
}
 
Example 20
Source Project: star-zone-android   Source File: CompressTaskHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
    if (data == null) {
        callError("配置为空");
        return;
    }
    CompressOption option = data;
    int[] imageSize = BitmapUtil.getImageSize(option.originalImagePath);
    if (imageSize[0] <= -1 || imageSize[1] <= -1) {
        callError(">>>>>无法获取图片大小<<<<<");
        return;
    }
    File imageFile = new File(option.originalImagePath);
    if (!imageFile.exists()) {
        callError("图片不存在。。。退出");
        return;
    }
    long fileSize = 0;
    try {
        fileSize = FileUtil.getFileSize(new File(option.originalImagePath));
        KLog.i(TAG, "文件路径  >>>  " + option.originalImagePath + "\n文件大小  >>>  " + FileUtil.fileLengthFormat(fileSize));
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (fileSize <= 0 && option.compressType != CompressManager.SCALE) {
        callError("获取图片文件大小失败。。。。");
        return;
    }

    startTask(imageSize, fileSize, option);
}
 
Example 21
Source Project: star-zone-android   Source File: CompressTaskHelper.java    License: Apache License 2.0 5 votes vote down vote up
private void startInternal(int[] imageSize, long fileSize, CompressOption option) throws Exception {
    String targetImagePath = null;
    switch (option.compressType) {
        case CompressManager.SCALE:
            targetImagePath = compressOnScale(option.originalImagePath, imageSize, option);
            break;
        case CompressManager.SIZE:
            targetImagePath = compressOnSize(option.originalImagePath, fileSize, option);
            break;
        case CompressManager.BOTH:
            String savePath = option.saveCompressImagePath;
            option.setSaveCompressImagePath(AppFileHelper.getAppTempPath().concat(EncryUtil.MD5(savePath) + option.suffix));
            String scaleTargetPath = compressOnScale(option.originalImagePath, imageSize, option);
            if (StringUtil.noEmpty(scaleTargetPath)) {
                option.setSaveCompressImagePath(savePath);
                targetImagePath = compressOnSize(scaleTargetPath, fileSize, option);
            }
            break;
    }
    if (StringUtil.noEmpty(targetImagePath)) {
        KLog.i(TAG, "压缩成功,图片地址  >>  " + targetImagePath);
        callCompress(1, 1);
        result.add(targetImagePath);
        callSuccess(result);
    } else {
        callError("压缩失败");
    }
}
 
Example 22
Source Project: JianDanRxJava   Source File: JokeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void getCommentCounts(final ArrayList<Joke> jokes) {

        StringBuilder sb = new StringBuilder();
        for (Joke joke : jokes) {
            sb.append("comment-" + joke.getComment_ID() + ",");
        }

        String url = sb.toString();
        if (url.endsWith(",")) {
            url = url.substring(0, url.length() - 1);
        }

        JDApi.getCommentNumber(url)
                .observeOn(Schedulers.io())
                .doOnNext(commentNumbers -> {
                    if (page == 1) {
                        mJokes.clear();
                        JokeCache.getInstance(mActivity).clearAllCache();
                    }
                    JokeCache.getInstance(mActivity).addResultCache(GsonHelper.toString(jokes), page);
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(commentNumbers -> {
                    for (int i = 0; i < jokes.size(); i++) {
                        jokes.get(i).setComment_counts(commentNumbers.get(i).comments + "");
                    }
                    mJokes.addAll(jokes);
                    notifyDataSetChanged();
                    mLoadFinisCallBack.loadFinish(null);
                    mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                }, e -> {
                    mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET);
                    mLoadFinisCallBack.loadFinish(null);
                    KLog.e(e);
                });
    }
 
Example 23
Source Project: star-zone-android   Source File: ThreadPoolManager.java    License: Apache License 2.0 5 votes vote down vote up
public static void execute(Runnable runnable) {
    try {
        threadPool.execute(runnable);
    } catch (Exception e) {
        e.printStackTrace();
        KLog.e(e.toString());
    }
}
 
Example 24
Source Project: star-zone-android   Source File: ThreadPoolManager.java    License: Apache License 2.0 5 votes vote down vote up
public static void executeOnUploadPool(Runnable runnable) {
    try {
        uploadThreadPool.execute(runnable);
    } catch (Exception e) {
        e.printStackTrace();
        KLog.e(e.toString());
    }
}
 
Example 25
Source Project: star-zone-android   Source File: TimeUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 时间戳转格式化日期
 *
 * @param timestamp 单位毫秒
 * @param format    日期格式
 * @return
 */
private static String transferLongToDate(long timestamp, String format) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Date date = new Date(timestamp);
        return sdf.format(date);
    } catch (Exception e) {
        KLog.e(e);
        return "null";
    }
}
 
Example 26
Source Project: star-zone-android   Source File: FileUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 写入文件
 *
 * @param strFileName 文件名
 * @param bytes       bytes
 */
public static boolean writeToFile(String strFileName, byte[] bytes) {
    try {
        File file = new File(strFileName);

        FileOutputStream fouts = new FileOutputStream(file);
        fouts.write(bytes, 0, bytes.length);
        fouts.flush();
        fouts.close();
        return true;
    } catch (IOException e) {
        KLog.e(e);
    }
    return false;
}
 
Example 27
Source Project: star-zone-android   Source File: FileUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String Read(String fileName) {
    String res = "";
    try {
        FileInputStream fin = new FileInputStream(fileName);
        int length = fin.available();
        byte[] buffer = new byte[length];
        fin.read(buffer);
        res = EncodingUtils.getString(buffer, "UTF-8");
        fin.close();
    } catch (Exception e) {
        KLog.e(e);
    }
    return res;
}
 
Example 28
Source Project: star-zone-android   Source File: FileUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 先改名,在删除(为了避免EBUSY (Device or resource busy)的错误)
 */
private static void safelyDelete(File file) {
    if (file == null || !file.exists()) return;
    try {
        final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
        file.renameTo(to);
        to.delete();
    } catch (Exception e) {
        KLog.e(e);
    }
}
 
Example 29
Source Project: star-zone-android   Source File: MomentInfo.java    License: Apache License 2.0 5 votes vote down vote up
public int getMomentType() {
    if (content == null) {
        KLog.e("朋友圈是空的");
        return MomentsType.EMPTY_CONTENT;
    }
    return content.getMomentType();
}
 
Example 30
Source Project: BitkyShop   Source File: CartRecyclerAdapter.java    License: MIT License 5 votes vote down vote up
/**
 * 初始化 RecyclerView 适配器
 *
 * @param mDatas 绑定的数据
 */
public CartRecyclerAdapter(List<CommodityLocal> mDatas) {
  super(mDatas, R.layout.recycler_cartfragment_show);
  listener = new KyRecyclerViewItemOnClickListener<CommodityLocal>() {
    @Override public void Onclick(View v, int adapterPosition, CommodityLocal data) {
      KLog.d("点击:" + data.getName() + "位置:" + adapterPosition);
    }
  };
}