Skip to content

Commit

Permalink
publish v3.0.3 fix #41 适配部分手机选择照片提示非图片问题
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycodeboy committed Oct 25, 2016
1 parent c30be85 commit 2964056
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## [TakePhoto](https://github.com/crazycodeboy/TakePhoto) 简介
`TakePhoto`是一款用于在Android设备上获取照片(拍照或从相册、文件中选择)、裁剪图片、压缩图片的开源工具库,目前最新版本[3.0.2](https://github.com/crazycodeboy/TakePhoto/)
`TakePhoto`是一款用于在Android设备上获取照片(拍照或从相册、文件中选择)、裁剪图片、压缩图片的开源工具库,目前最新版本[3.0.3](https://github.com/crazycodeboy/TakePhoto/)
3.0以下版本及API说明,详见[TakePhoto2.0+](https://github.com/crazycodeboy/TakePhoto/blob/master/README.2+.md)

**V3.0**
Expand Down Expand Up @@ -35,7 +35,7 @@ GitHub地址: [https://github.com/crazycodeboy/TakePhoto](https://github.com/c
**Gradle:**

```groovy
compile 'com.jph.takephoto:takephoto_library:3.0.2'
compile 'com.jph.takephoto:takephoto_library:3.0.3'
```

**Maven:**
Expand All @@ -44,7 +44,7 @@ GitHub地址: [https://github.com/crazycodeboy/TakePhoto](https://github.com/c
<dependency>
<groupId>com.jph.takephoto</groupId>
<artifactId>takephoto_library</artifactId>
<version>3.0.2</version>
<version>3.0.3</version>
<type>pom</type>
</dependency>
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:2.2.1'
// classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
// classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
2 changes: 1 addition & 1 deletion simple/src/main/java/com/jph/simple/CustomHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private void configCompress(TakePhoto takePhoto){
int maxSize= Integer.parseInt(etSize.getText().toString());
int maxPixel= Integer.parseInt(etPx.getText().toString());
boolean showProgressBar=rgShowProgressBar.getCheckedRadioButtonId()==R.id.rbShowYes? true:false;
CompressConfig config= new CompressConfig.Builder().setMaxPixel(maxSize).setMaxPixel(maxPixel).create();
CompressConfig config= new CompressConfig.Builder().setMaxSize(maxSize).setMaxPixel(maxPixel).create();
takePhoto.onEnableCompress(config,showProgressBar);
}
private CropOptions getCropOptions(){
Expand Down
4 changes: 2 additions & 2 deletions takephoto_library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 24
versionCode 32
versionName "3.0.2"
versionCode 33
versionName "3.0.3"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jph.takephoto.uitl;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Bitmap;
Expand Down Expand Up @@ -91,7 +92,7 @@ public static void inputStreamToFile(InputStream is, File file) throws TExceptio
* @param photoUri
* @return
*/
public static File getTempFile(Context context, Uri photoUri)throws TException {
public static File getTempFile(Activity context, Uri photoUri)throws TException {
String minType=getMimeType(context, photoUri);
if (!checkMimeType(context,minType))throw new TException(TExceptionType.TYPE_NOT_IMAGE);
File filesDir=context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
Expand All @@ -115,7 +116,7 @@ public static boolean checkMimeType(Context context,String minType) {
* To find out the extension of required object in given uri
* Solution by http://stackoverflow.com/a/36514823/1171484
*/
public static String getMimeType(Context context, Uri uri) {
public static String getMimeType(Activity context, Uri uri) {
String extension;
//Check uri format to avoid null
if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
Expand All @@ -128,6 +129,12 @@ public static String getMimeType(Context context, Uri uri) {
extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());
if (TextUtils.isEmpty(extension))extension=MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri));
}
if(TextUtils.isEmpty(extension)){
extension=getMimeTypeByFileName(TUriParse.getFileWithUri(uri,context).getName());
}
return extension;
}
public static String getMimeTypeByFileName(String fileName){
return fileName.substring(fileName.lastIndexOf("."),fileName.length());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ public static String getFilePathWithUri(Uri uri, Activity activity)throws TExcep
Log.w(TAG,"uri is null,activity may have been recovered?");
throw new TException(TExceptionType.TYPE_URI_NULL);
}
File picture=getFileWithUri(uri,activity);
String picturePath=picture==null? null:picture.getPath();
if (TextUtils.isEmpty(picturePath))throw new TException(TExceptionType.TYPE_URI_PARSE_FAIL);
if (!TImageFiles.checkMimeType(activity,TImageFiles.getMimeType(activity,uri)))throw new TException(TExceptionType.TYPE_NOT_IMAGE);
return picturePath;
}
/**
* 通过URI获取文件
* @param uri
* @param activity
* @return
* Author JPH
* Date 2016/10/25
*/
public static File getFileWithUri(Uri uri, Activity activity) {
String picturePath = null;
String scheme=uri.getScheme();
if (ContentResolver.SCHEME_CONTENT.equals(scheme)){
Expand All @@ -109,9 +124,7 @@ public static String getFilePathWithUri(Uri uri, Activity activity)throws TExcep
}else if (ContentResolver.SCHEME_FILE.equals(scheme)){
picturePath=uri.getPath();
}
if (TextUtils.isEmpty(picturePath))throw new TException(TExceptionType.TYPE_URI_PARSE_FAIL);
if (!TImageFiles.checkMimeType(activity,TImageFiles.getMimeType(activity,uri)))throw new TException(TExceptionType.TYPE_NOT_IMAGE);
return picturePath;
return TextUtils.isEmpty(picturePath)? null:new File(picturePath);
}
/**
* 通过从文件中得到的URI获取文件的路径
Expand Down

0 comments on commit 2964056

Please sign in to comment.