Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repositories {
}

dependencies {
compile 'com.github.lovetuzitong:MultiImageSelector:1.2'
compile 'com.github.jiangm93:MultiImageSelector:1.3'
}
```

Expand Down Expand Up @@ -189,4 +189,4 @@ copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

>The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
copies or substantial portions of the Software.
10 changes: 7 additions & 3 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repositories {
}

dependencies {
compile 'com.github.lovetuzitong:MultiImageSelector:1.2'
compile 'com.github.jiangm93:MultiImageSelector:1.3'
}
```

Expand Down Expand Up @@ -60,7 +60,8 @@ MultiImageSelector.create(Context)
.count(int) // 最大选择图片数量, 默认为9. 只有在选择模式为多选时有效
.single() // 单选模式
.multi() // 多选模式, 默认模式;
.origin(ArrayList<String>) // 默认已选择图片. 只有在选择模式为多选时有效
.fileProviderName(fileProviderName);//Android 7.0文件提供者fileProviderName
       .origin(ArrayList<String>) // 默认已选择图片. 只有在选择模式为多选时有效
.start(Activity/Fragment, REQUEST_IMAGE);
```

Expand Down Expand Up @@ -141,7 +142,10 @@ class CustomerActivity extends Activity implements MultiImageSelectorFragment.Ca
-------------------

###更新日志
* 2017-4-28
   1. 新增. Android 7.0相机拍照 支持


* 2016-5-18
1. 新增. `JitPack` 支持
2. 新增. 简单的调用方式. 详细参见 `第2步`
Expand Down Expand Up @@ -190,4 +194,4 @@ copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

>The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
copies or substantial portions of the Software.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public class MultiImageSelector {
private int mMode = MultiImageSelectorActivity.MODE_MULTI;
private ArrayList<String> mOriginData;
private static MultiImageSelector sSelector;

private Context context;
private String fileProviderName;
@Deprecated
private MultiImageSelector(Context context){

this.context=context;
}

private MultiImageSelector(){}
Expand Down Expand Up @@ -73,7 +74,13 @@ public MultiImageSelector origin(ArrayList<String> images){
return sSelector;
}

public void start(Activity activity, int requestCode){
public MultiImageSelector fileProviderName(String fileProviderName){
this.fileProviderName=fileProviderName;
return sSelector;

}

public void start(Activity activity, int requestCode){
final Context context = activity;
if(hasPermission(context)) {
activity.startActivityForResult(createIntent(context), requestCode);
Expand Down Expand Up @@ -107,6 +114,9 @@ private Intent createIntent(Context context){
if(mOriginData != null){
intent.putStringArrayListExtra(MultiImageSelectorActivity.EXTRA_DEFAULT_SELECTED_LIST, mOriginData);
}
if(fileProviderName!=null){
intent.putExtra(MultiImageSelectorActivity.FILE_PROVIDER_NAME,fileProviderName);
}
intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE, mMode);
return intent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ public class MultiImageSelectorActivity extends AppCompatActivity
public static final String EXTRA_RESULT = "select_result";
/** Original data set */
public static final String EXTRA_DEFAULT_SELECTED_LIST = "default_list";
/**
* android 7.0 FileProvider
*/
public static final String FILE_PROVIDER_NAME= "file_provider_name";
// Default image size
private static final int DEFAULT_IMAGE_SIZE = 9;

private ArrayList<String> resultList = new ArrayList<>();
private Button mSubmitButton;
private int mDefaultCount = DEFAULT_IMAGE_SIZE;

private String fileProviderName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -74,7 +78,9 @@ protected void onCreate(Bundle savedInstanceState) {
if(mode == MODE_MULTI && intent.hasExtra(EXTRA_DEFAULT_SELECTED_LIST)) {
resultList = intent.getStringArrayListExtra(EXTRA_DEFAULT_SELECTED_LIST);
}

if(intent.hasExtra(FILE_PROVIDER_NAME)){
fileProviderName=intent.getStringExtra(FILE_PROVIDER_NAME);
}
mSubmitButton = (Button) findViewById(R.id.commit);
if(mode == MODE_MULTI){
updateDoneText(resultList);
Expand Down Expand Up @@ -102,6 +108,7 @@ public void onClick(View view) {
bundle.putInt(MultiImageSelectorFragment.EXTRA_SELECT_COUNT, mDefaultCount);
bundle.putInt(MultiImageSelectorFragment.EXTRA_SELECT_MODE, mode);
bundle.putBoolean(MultiImageSelectorFragment.EXTRA_SHOW_CAMERA, isShow);
bundle.putString(MultiImageSelectorFragment.FILE_PROVIDER_NAME,fileProviderName);
bundle.putStringArrayList(MultiImageSelectorFragment.EXTRA_DEFAULT_SELECTED_LIST, resultList);

getSupportFragmentManager().beginTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@
import android.graphics.Point;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.FileProvider;
import android.support.v4.content.Loader;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ListPopupWindow;
import android.text.TextUtils;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -75,7 +79,10 @@ public class MultiImageSelectorFragment extends Fragment {
public static final String EXTRA_SHOW_CAMERA = "show_camera";
/** Original data set */
public static final String EXTRA_DEFAULT_SELECTED_LIST = "default_list";

/**
* android 7.0 FileProvider
*/
public static final String FILE_PROVIDER_NAME= "file_provider_name";
// loaders
private static final int LOADER_ALL = 0;
private static final int LOADER_CATEGORY = 1;
Expand All @@ -99,7 +106,7 @@ public class MultiImageSelectorFragment extends Fragment {
private boolean hasFolderGened = false;

private File mTmpFile;

private Uri contentUri;
@Override
public void onAttach(Context context) {
super.onAttach(context);
Expand Down Expand Up @@ -303,12 +310,13 @@ public void onConfigurationChanged(Configuration newConfig) {
* Open camera
*/
private void showCameraAction() {
if(ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED){
requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN // Permission was added in API Level 16
&& ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
requestPermission(Manifest.permission.READ_EXTERNAL_STORAGE,
getString(R.string.mis_permission_rationale_write_storage),
REQUEST_STORAGE_WRITE_ACCESS_PERMISSION);
}else {
} else{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
try {
Expand All @@ -317,8 +325,33 @@ private void showCameraAction() {
e.printStackTrace();
}
if (mTmpFile != null && mTmpFile.exists()) {
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTmpFile));
startActivityForResult(intent, REQUEST_CAMERA);
// intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTmpFile));
// startActivityForResult(intent, REQUEST_CAMERA);

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M){
contentUri = Uri.fromFile(mTmpFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
startActivityForResult(intent, REQUEST_CAMERA);
}else{
/**
* 7.0 调用系统相机拍照不再允许使用Uri方式,应该替换为FileProvider
* 并且这样可以解决MIUI系统上拍照返回size为0的情况
*/
if(fileProviderName()==null){
Toast.makeText(getActivity(), R.string.mis_error_image_not_file_provider, Toast.LENGTH_SHORT).show();
return;
}else{
contentUri = FileProvider.getUriForFile(getActivity(),fileProviderName(), mTmpFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
startActivityForResult(intent, REQUEST_CAMERA);
}
}






} else {
Toast.makeText(getActivity(), R.string.mis_error_image_not_exist, Toast.LENGTH_SHORT).show();
}
Expand All @@ -329,7 +362,7 @@ private void showCameraAction() {
}

private void requestPermission(final String permission, String rationale, final int requestCode){
if(shouldShowRequestPermissionRationale(permission)){
if(ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),permission)){
new AlertDialog.Builder(getContext())
.setTitle(R.string.mis_permission_dialog_title)
.setMessage(rationale)
Expand Down Expand Up @@ -501,6 +534,11 @@ private int selectMode(){
private int selectImageCount(){
return getArguments() == null ? 9 : getArguments().getInt(EXTRA_SELECT_COUNT);
}
@Nullable
private String fileProviderName(){
return getArguments() == null ? null : getArguments().getString(FILE_PROVIDER_NAME);
}


/**
* Callback for host activity
Expand Down
2 changes: 2 additions & 0 deletions multi-image-selector/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<string name="mis_error_image_not_exist">图片错误</string>
<string name="mis_error_no_permission">无权限</string>
<string name="mis_permission_dialog_title">权限拒绝</string>
<string name="mis_error_image_not_file_provider">暂不支持 安卓7.0系统</string>
<string name="mis_permission_dialog_ok">好</string>
<string name="mis_permission_dialog_cancel">拒绝</string>
<string name="mis_permission_rationale">浏览图片需要您提供浏览存储的权限</string>
<string name="mis_permission_rationale_write_storage">保存拍照图片需要您提供写存储权限</string>
<string name="mis_permission_rationale_take_photo">拍照需要您提供启动相机权限</string>
</resources>
2 changes: 2 additions & 0 deletions multi-image-selector/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
<string name="mis_error_image_not_exist">Image error</string>
<string name="mis_error_no_permission">Has no permission</string>
<string name="mis_permission_dialog_title">Permission Deny</string>
<string name="mis_error_image_not_file_provider">Temporary support Android 7.0 system</string>
<string name="mis_permission_dialog_ok">OK</string>
<string name="mis_permission_dialog_cancel">CANCEL</string>
<string name="mis_permission_rationale">Storage read permission is needed to pick files.</string>
<string name="mis_permission_rationale_write_storage">Storage write permission is needed to save the image.</string>
<string name="mis_permission_rationale_take_photo">Camera requires you to provide the ability to start camera</string>
</resources>