// Path: takephoto_library/src/main/java/org/devio/takephoto/uitl/TFileUtils.java
// public class TFileUtils {
//     private static final String TAG = "TFileUtils";
//     private static String DEFAULT_DISK_CACHE_DIR = "takephoto_cache";
// 
//     public static File getPhotoCacheDir(Context context, File file) {
//         File cacheDir = context.getCacheDir();
//         if (cacheDir != null) {
//             File mCacheDir = new File(cacheDir, DEFAULT_DISK_CACHE_DIR);
//             if (!mCacheDir.mkdirs() && (!mCacheDir.exists() || !mCacheDir.isDirectory())) {
//                 return file;
//             } else {
//                 return new File(mCacheDir, file.getName());
//             }
//         }
//         if (Log.isLoggable(TAG, Log.ERROR)) {
//             Log.e(TAG, "default disk cache dir is null");
//         }
//         return file;
//     }
// 
//     public static void delete(String path) {
//         try {
//             if (path == null) {
//                 return;
//             }
//             File file = new File(path);
//             if (!file.delete()) {
//                 file.deleteOnExit();
//             }
//         } catch (Exception e) {
//             e.printStackTrace();
//         }
//     }
// }


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.os.Handler;
import org.devio.takephoto.uitl.TFileUtils;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(thumbnailFile));

            listener.onCompressSuccess(thumbnailFile.getPath());
        }
    }

    /**
     * 发送压缩结果的消息
     *
     * @param isSuccess 压缩是否成功
     * @param imagePath
     * @param message
     */
    private void sendMsg(final boolean isSuccess, final String imagePath, final String message, final CompressListener listener) {
        mhHandler.post(new Runnable() {
            @Override
            public void run() {
                if (isSuccess) {
                    listener.onCompressSuccess(imagePath);
                } else {
                    listener.onCompressFailed(imagePath, message);
                }
            }
        });
    }

    private File getThumbnailFile(File file) {
        if (file == null || !file.exists()) {
            return file;
        }
// Path: takephoto_library/src/main/java/org/devio/takephoto/uitl/TFileUtils.java
// public class TFileUtils {
//     private static final String TAG = "TFileUtils";
//     private static String DEFAULT_DISK_CACHE_DIR = "takephoto_cache";
// 
//     public static File getPhotoCacheDir(Context context, File file) {
//         File cacheDir = context.getCacheDir();
//         if (cacheDir != null) {
//             File mCacheDir = new File(cacheDir, DEFAULT_DISK_CACHE_DIR);
//             if (!mCacheDir.mkdirs() && (!mCacheDir.exists() || !mCacheDir.isDirectory())) {
//                 return file;
//             } else {
//                 return new File(mCacheDir, file.getName());
//             }
//         }
//         if (Log.isLoggable(TAG, Log.ERROR)) {
//             Log.e(TAG, "default disk cache dir is null");
//         }
//         return file;
//     }
// 
//     public static void delete(String path) {
//         try {
//             if (path == null) {
//                 return;
//             }
//             File file = new File(path);
//             if (!file.delete()) {
//                 file.deleteOnExit();
//             }
//         } catch (Exception e) {
//             e.printStackTrace();
//         }
//     }
// }


// Path: takephoto_library/src/main/java/org/devio/takephoto/compress/CompressImageUtil.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.os.Handler;
import org.devio.takephoto.uitl.TFileUtils;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(thumbnailFile));

            listener.onCompressSuccess(thumbnailFile.getPath());
        }
    }

    /**
     * 发送压缩结果的消息
     *
     * @param isSuccess 压缩是否成功
     * @param imagePath
     * @param message
     */
    private void sendMsg(final boolean isSuccess, final String imagePath, final String message, final CompressListener listener) {
        mhHandler.post(new Runnable() {
            @Override
            public void run() {
                if (isSuccess) {
                    listener.onCompressSuccess(imagePath);
                } else {
                    listener.onCompressFailed(imagePath, message);
                }
            }
        });
    }

    private File getThumbnailFile(File file) {
        if (file == null || !file.exists()) {
            return file;
        }
        return TFileUtils.getPhotoCacheDir(context, file);