// Path: takephoto_library/src/main/java/org/devio/takephoto/model/TException.java
// public class TException extends Exception {
//     String detailMessage;
// 
//     public TException(TExceptionType exceptionType) {
//         super(exceptionType.getStringValue());
//         this.detailMessage = exceptionType.getStringValue();
//     }
// 
//     public String getDetailMessage() {
//         return detailMessage;
//     }
// }
// 
// Path: takephoto_library/src/main/java/org/devio/takephoto/model/TExceptionType.java
// public enum TExceptionType {
//     TYPE_NOT_IMAGE("选择的文件不是图片"), TYPE_WRITE_FAIL("保存选择的的文件失败"), TYPE_URI_NULL("所选照片的Uri 为null"), TYPE_URI_PARSE_FAIL("从Uri中获取文件路径失败"),
//     TYPE_NO_MATCH_PICK_INTENT("没有匹配到选择图片的Intent"), TYPE_NO_MATCH_CROP_INTENT("没有匹配到裁切图片的Intent"), TYPE_NO_CAMERA("没有相机"),
//     TYPE_NO_FIND("选择的文件没有找到");
// 
//     String stringValue;
// 
//     TExceptionType(String stringValue) {
//         this.stringValue = stringValue;
//     }
// 
//     public String getStringValue() {
//         return stringValue;
//     }
// }


import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Log;
import org.devio.takephoto.model.TException;
import org.devio.takephoto.model.TExceptionType;
import java.io.File;
import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
            } else if (TextUtils.equals(uri.getAuthority(), TConstant.getFileProviderName(activity))) {
                picturePath = parseOwnUri(activity, uri);
            }
            cursor.close();
        } else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
            picturePath = uri.getPath();
        }
        return TextUtils.isEmpty(picturePath) ? null : new File(picturePath);
    }

    /**
     * 通过从文件中得到的URI获取文件的路径
     *
     * @param uri
     * @param activity
     * @return Author JPH
     * Date 2016/6/6 0006 20:01
     */
    public static String getFilePathWithDocumentsUri(Uri uri, Activity activity) throws TException {
        if (uri == null) {
            Log.e(TAG, "uri is null,activity may have been recovered?");
            return null;
        }
        if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()) && uri.getPath().contains("document")) {
            File tempFile = TImageFiles.getTempFile(activity, uri);
            try {
                TImageFiles.inputStreamToFile(activity.getContentResolver().openInputStream(uri), tempFile);
                return tempFile.getPath();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
// Path: takephoto_library/src/main/java/org/devio/takephoto/model/TException.java
// public class TException extends Exception {
//     String detailMessage;
// 
//     public TException(TExceptionType exceptionType) {
//         super(exceptionType.getStringValue());
//         this.detailMessage = exceptionType.getStringValue();
//     }
// 
//     public String getDetailMessage() {
//         return detailMessage;
//     }
// }
// 
// Path: takephoto_library/src/main/java/org/devio/takephoto/model/TExceptionType.java
// public enum TExceptionType {
//     TYPE_NOT_IMAGE("选择的文件不是图片"), TYPE_WRITE_FAIL("保存选择的的文件失败"), TYPE_URI_NULL("所选照片的Uri 为null"), TYPE_URI_PARSE_FAIL("从Uri中获取文件路径失败"),
//     TYPE_NO_MATCH_PICK_INTENT("没有匹配到选择图片的Intent"), TYPE_NO_MATCH_CROP_INTENT("没有匹配到裁切图片的Intent"), TYPE_NO_CAMERA("没有相机"),
//     TYPE_NO_FIND("选择的文件没有找到");
// 
//     String stringValue;
// 
//     TExceptionType(String stringValue) {
//         this.stringValue = stringValue;
//     }
// 
//     public String getStringValue() {
//         return stringValue;
//     }
// }


// Path: takephoto_library/src/main/java/org/devio/takephoto/uitl/TUriParse.java
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Log;
import org.devio.takephoto.model.TException;
import org.devio.takephoto.model.TExceptionType;
import java.io.File;
import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

            } else if (TextUtils.equals(uri.getAuthority(), TConstant.getFileProviderName(activity))) {
                picturePath = parseOwnUri(activity, uri);
            }
            cursor.close();
        } else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
            picturePath = uri.getPath();
        }
        return TextUtils.isEmpty(picturePath) ? null : new File(picturePath);
    }

    /**
     * 通过从文件中得到的URI获取文件的路径
     *
     * @param uri
     * @param activity
     * @return Author JPH
     * Date 2016/6/6 0006 20:01
     */
    public static String getFilePathWithDocumentsUri(Uri uri, Activity activity) throws TException {
        if (uri == null) {
            Log.e(TAG, "uri is null,activity may have been recovered?");
            return null;
        }
        if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()) && uri.getPath().contains("document")) {
            File tempFile = TImageFiles.getTempFile(activity, uri);
            try {
                TImageFiles.inputStreamToFile(activity.getContentResolver().openInputStream(uri), tempFile);
                return tempFile.getPath();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                throw new TException(TExceptionType.TYPE_NO_FIND);