Search in sources :

Example 1 with OnRenameListener

use of top.zibin.luban.OnRenameListener in project Luban by Curzibn.

the class MainActivity method withLs.

private <T> void withLs(final List<T> photos) {
    Luban.with(this).load(photos).ignoreBy(100).setTargetDir(getPath()).setFocusAlpha(false).filter(new CompressionPredicate() {

        @Override
        public boolean apply(String path) {
            return !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif"));
        }
    }).setRenameListener(new OnRenameListener() {

        @Override
        public String rename(String filePath) {
            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                md.update(filePath.getBytes());
                return new BigInteger(1, md.digest()).toString(32);
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
            return "";
        }
    }).setCompressListener(new OnCompressListener() {

        @Override
        public void onStart() {
        }

        @Override
        public void onSuccess(File file) {
            Log.i(TAG, file.getAbsolutePath());
            showResult(originPhotos, file);
        }

        @Override
        public void onError(Throwable e) {
        }
    }).launch();
}
Also used : OnRenameListener(top.zibin.luban.OnRenameListener) OnCompressListener(top.zibin.luban.OnCompressListener) BigInteger(java.math.BigInteger) CompressionPredicate(top.zibin.luban.CompressionPredicate) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) File(java.io.File)

Aggregations

File (java.io.File)1 BigInteger (java.math.BigInteger)1 MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CompressionPredicate (top.zibin.luban.CompressionPredicate)1 OnCompressListener (top.zibin.luban.OnCompressListener)1 OnRenameListener (top.zibin.luban.OnRenameListener)1