<commit_before>package com.njnu.kai.practice.image;

import com.njnu.kai.support.BaseTestListFragment;
import com.njnu.kai.support.TestFunction;

import java.io.File;

import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;

/**
 * @author hongkai.qian
 * @version 1.0.0
 * @since 17/4/12
 */
public class ImageCompressFragment extends BaseTestListFragment {

    @TestFunction("压缩图片")
    public void onTest01() {
        File file = new File("/sdcard/dcim/camera/IMG_20170412_195631.jpg");
        Luban.get(getContext())
                .load(file)                     //传人要压缩的图片
                .putGear(Luban.THIRD_GEAR)      //设定压缩档次，默认三挡
                .setCompressListener(new OnCompressListener() { //设置回调

                    @Override
                    public void onStart() {
                        appendResult("onStart");
                    }

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

                    @Override
                    public void onError(Throwable e) {
                        appendResult(e.getMessage());
                    }
                }).launch();
    }
}<commit_msg>test compress image use rxJava<commit_after>package com.njnu.kai.practice.image;

import com.njnu.kai.support.BaseTestListFragment;
import com.njnu.kai.support.TestFunction;

import java.io.File;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;
import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;

/**
 * @author hongkai.qian
 * @version 1.0.0
 * @since 17/4/12
 */
public class ImageCompressFragment extends BaseTestListFragment {

    @TestFunction("压缩图片 Use listener")
    public void onTest01() {
        File file = new File("/sdcard/dcim/camera/IMG_20170412_195631.jpg");
        Luban.get(getContext())
                .load(file)                     //传人要压缩的图片
                .putGear(Luban.THIRD_GEAR)      //设定压缩档次，默认三挡
                .setCompressListener(new OnCompressListener() { //设置回调

                    @Override
                    public void onStart() {
                        appendResult("onStart");
                    }

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

                    @Override
                    public void onError(Throwable e) {
                        appendResult(e.getMessage());
                    }
                }).launch();
    }

    @TestFunction("压缩图片 use rxJava")
    public void onTest02() {
        File file = new File("/sdcard/dcim/camera/IMG_20170412_195631.jpg");
        Luban.get(getContext())
                .load(file)
                .putGear(Luban.THIRD_GEAR)
                .asObservable()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnError(new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        appendResult(throwable.getMessage());
                    }
                })
                .onErrorResumeNext(new Func1<Throwable, Observable<? extends File>>() {
                    @Override
                    public Observable<? extends File> call(Throwable throwable) {
                        return Observable.empty();
                    }
                })
                .subscribe(new Action1<File>() {
                    @Override
                    public void call(File file) {
                        appendResult(file.getAbsolutePath());
                    }
                });
    }
}
{'fraction_non_alphanumeric': 0.0997673817523908, 'fraction_numerical': 0.01783406565003877, 'mean_word_length': 1.4728434504792332, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3874186', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1082, 'n_words': 176}