├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── yzs │ │ └── imageshowpicker │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── yzs │ │ │ └── imageshowpicker │ │ │ ├── HomeActivity.java │ │ │ ├── ImageBean.java │ │ │ ├── Loader.java │ │ │ ├── MainActivity.java │ │ │ ├── MyAdapter.java │ │ │ └── OnePickerActivity.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── home_ac.xml │ │ └── item.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── yzs │ └── imageshowpicker │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── imageshowpickerview ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── yzs │ │ └── imageshowpickerview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── yzs │ │ │ └── imageshowpickerview │ │ │ ├── ImageLoader.java │ │ │ ├── ImageLoaderInterface.java │ │ │ ├── ImageShowPickerAdapter.java │ │ │ ├── ImageShowPickerBean.java │ │ │ ├── ImageShowPickerListener.java │ │ │ ├── ImageShowPickerPicListener.java │ │ │ ├── ImageShowPickerView.java │ │ │ ├── MyGridLayoutManager.java │ │ │ └── SizeUtils.java │ └── res │ │ ├── drawable │ │ └── image_show_piceker_add.xml │ │ ├── mipmap-xxhdpi │ │ ├── image_show_piceker_add.png │ │ └── image_show_piceker_del.png │ │ └── values │ │ ├── attrs.xml │ │ ├── ids.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── yzs │ └── imageshowpickerview │ └── ExampleUnitTest.java ├── pic ├── imageshowpickerview.gif └── weixin_pic.jpg └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ImageShowPicker 2 | 单纯的上传图片展示控件 3 | 4 | ![image](https://github.com/yaozs/YzsLib/blob/master/app/src/main/res/mipmap-xxxhdpi/icon.png) 5 | 6 | ## 欢迎大家Star,使用 7 | 8 |  YzsLib开源交流群:331973212 9 | 10 | 朋友是否一次又一次的写着放朋友圈的选择发布框架就是这个 11 | ![image](https://github.com/yaozs/ImageShowPicker/blob/master/pic/weixin_pic.jpg) 12 | 13 | ## 现在支持的框架来了 14 | 15 | ![image](https://github.com/yaozs/ImageShowPicker/blob/master/pic/imageshowpickerview.gif) 16 | 17 | 18 | ## Attributes属性(ImageShowPicker布局文件中调用) 19 | |Attributes|forma|describe 20 | |---|---|---| 21 | |pic_size| dimension|单张图片大小(宽高一样) 22 | |max_num| integer|最大数量 23 | |add_label| reference|添加图片 24 | |del_label| reference|删除图片 25 | |is_show_del| boolean|是否显示删除按钮 26 | |is_show_anim| boolean|是否展示动画 27 | |one_line_show_num| integer|单行显示数量 28 | 29 | ## 使用步骤 30 | 31 | #### Step 1.依赖 32 | Gradle 33 | 34 | 先在 build.gradle(Project:XXXX) 的 repositories 添加: 35 | ```groovy 36 | allprojects { 37 | repositories { 38 | ... 39 | maven { url "https://jitpack.io" } 40 | } 41 | } 42 | ``` 43 | 然后在 build.gradle(Module:app) 的 dependencies 添加: 44 | 45 | ```groovy 46 | dependencies{ 47 | compile 'com.github.yaozs:ImageShowPicker:1.0.1' //最新版本 48 | } 49 | ``` 50 | ```java 51 | ImageShowPickerView pickerView = (ImageShowPickerView)findViewById(R.id.it_picker_view); 52 | final List list = getItem(position); 53 | pickerView.setImageLoaderInterface(new Loader()); 54 | pickerView.setNewData(list); 55 | //展示有动画和无动画 56 | if (position % 2 == 1) { 57 | pickerView.setShowAnim(true); 58 | } else { 59 | pickerView.setShowAnim(false); 60 | } 61 | pickerView.setPickerListener(new ImageShowPickerListener() { 62 | @Override 63 | public void addOnClickListener(int remainNum) { 64 | Toast.makeText(context, "remainNum" + remainNum, Toast.LENGTH_SHORT).show(); 65 | //在listview或recyclerview才会使用这个list.add(),其他情况都不用 66 | list.add(new ImageBean("http://pic78.huitu.com/res/20160604/1029007_20160604114552332126_1.jpg")); 67 | pickerView.addData(new ImageBean("http://pic78.huitu.com/res/20160604/1029007_20160604114552332126_1.jpg")); 68 | } 69 | 70 | @Override 71 | public void picOnClickListener(List list, int position, int remainNum) { 72 | Toast.makeText(context, list.size() + "========" + position + "remainNum" + remainNum, Toast.LENGTH_SHORT).show(); 73 | } 74 | 75 | @Override 76 | public void delOnClickListener(int position, int remainNum) { 77 | list.remove(position); 78 | Toast.makeText(context, "delOnClickListenerremainNum" + remainNum, Toast.LENGTH_SHORT).show(); 79 | } 80 | }); 81 | pickerView.show(); 82 | 83 | 84 | //获取所有数据 85 | pickerView.getDataList(); 86 | ``` 87 |       88 | ## 感谢sfshine提交的兼容代码 89 | 90 | 91 | ## 本人的其他项目 92 | [YzsLib——超好用的开发框架](https://github.com/yaozs/YzsLib) 93 | 94 | 95 | [YzsBaseActivity——简化到一定境界的BaseActivity](https://github.com/yaozs/YzsBaseActivity) 96 | 97 | 98 | 99 |       100 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.yzs.imageshowpicker" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.3.0' 28 | compile 'com.android.support.constraint:constraint-layout:1.0.1' 29 | testCompile 'junit:junit:4.12' 30 | compile project(':imageshowpickerview') 31 | compile 'com.github.bumptech.glide:glide:3.7.0' 32 | compile 'com.zhihu.android:matisse:0.4.3' 33 | compile 'com.yanzhenjie:permission:1.0.7' 34 | } 35 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/yzs/imageshowpicker/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.yzs.imageshowpicker; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.yzs.imageshowpicker", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/yzs/imageshowpicker/HomeActivity.java: -------------------------------------------------------------------------------- 1 | package com.yzs.imageshowpicker; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | 9 | /** 10 | * Author: 姚智胜 11 | * Version: V1.0版本 12 | * Description: 13 | * Date: 2017/5/8 14 | */ 15 | 16 | public class HomeActivity extends AppCompatActivity { 17 | 18 | 19 | @Override 20 | protected void onCreate(@Nullable Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.home_ac); 23 | findViewById(R.id.one_picker).setOnClickListener(new View.OnClickListener() { 24 | @Override 25 | public void onClick(View v) { 26 | Intent intent = new Intent(HomeActivity.this,OnePickerActivity.class); 27 | startActivity(intent); 28 | } 29 | }); 30 | 31 | findViewById(R.id.list_picker).setOnClickListener(new View.OnClickListener() { 32 | @Override 33 | public void onClick(View v) { 34 | Intent intent = new Intent(HomeActivity.this,MainActivity.class); 35 | startActivity(intent); 36 | } 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/yzs/imageshowpicker/ImageBean.java: -------------------------------------------------------------------------------- 1 | package com.yzs.imageshowpicker; 2 | 3 | import com.yzs.imageshowpickerview.ImageShowPickerBean; 4 | 5 | /** 6 | * Author 姚智胜 7 | * Version V1.0版本 8 | * Description: 9 | * Date: 2017/4/10 10 | */ 11 | 12 | public class ImageBean extends ImageShowPickerBean { 13 | public ImageBean(String url) { 14 | this.url = url; 15 | } 16 | 17 | public ImageBean(int resId) { 18 | this.resId = resId; 19 | } 20 | 21 | private String url; 22 | 23 | private int resId; 24 | 25 | 26 | @Override 27 | public String setImageShowPickerUrl() { 28 | return url; 29 | } 30 | 31 | @Override 32 | public int setImageShowPickerDelRes() { 33 | return resId; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/yzs/imageshowpicker/Loader.java: -------------------------------------------------------------------------------- 1 | package com.yzs.imageshowpicker; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.DrawableRes; 5 | import android.widget.ImageView; 6 | 7 | import com.bumptech.glide.Glide; 8 | import com.yzs.imageshowpickerview.ImageLoader; 9 | 10 | /** 11 | * Author 姚智胜 12 | * Version V1.0版本 13 | * Description: 14 | * Date: 2017/4/10 15 | */ 16 | 17 | public class Loader extends ImageLoader { 18 | 19 | @Override 20 | public void displayImage(Context context, String path, ImageView imageView) { 21 | Glide.with(context).load(path).into(imageView); 22 | 23 | } 24 | 25 | @Override 26 | public void displayImage(Context context, @DrawableRes Integer resId, ImageView imageView) { 27 | imageView.setImageResource(resId); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/yzs/imageshowpicker/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.yzs.imageshowpicker; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.ListView; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | List> mList = new ArrayList<>(); 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | ListView listView = (ListView) findViewById(R.id.listview); 19 | MyAdapter adapter = new MyAdapter(mList, this); 20 | listView.setAdapter(adapter); 21 | for (int i = 0; i < 10; i++) { 22 | List list = new ArrayList<>(); 23 | for (int j = 0; j < 2; j++) { 24 | 25 | list.add(new ImageBean("http://img02.tooopen.com/images/20140504/sy_60294738471.jpg")); 26 | list.add(new ImageBean("http://pic.58pic.com/58pic/16/62/63/97m58PICyWM_1024.jpg")); 27 | list.add(new ImageBean("http://pic78.huitu.com/res/20160604/1029007_20160604114552332126_1.jpg")); 28 | list.add(new ImageBean("http://img05.tooopen.com/images/20150531/tooopen_sy_127457023651.jpg")); 29 | } 30 | mList.add(list); 31 | } 32 | adapter.notifyDataSetChanged(); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/yzs/imageshowpicker/MyAdapter.java: -------------------------------------------------------------------------------- 1 | package com.yzs.imageshowpicker; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.BaseAdapter; 9 | import android.widget.Toast; 10 | 11 | import com.yzs.imageshowpickerview.ImageShowPickerBean; 12 | import com.yzs.imageshowpickerview.ImageShowPickerListener; 13 | import com.yzs.imageshowpickerview.ImageShowPickerView; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * Author: 姚智胜 19 | * Version: V1.0版本 20 | * Description: 21 | * Date: 2017/4/17 22 | */ 23 | 24 | public class MyAdapter extends BaseAdapter { 25 | private List> myLists; 26 | private Context context; 27 | 28 | public MyAdapter(List> list, Context context) { 29 | this.myLists = list; 30 | this.context = context; 31 | } 32 | 33 | @Override 34 | public int getCount() { 35 | return myLists.size(); 36 | } 37 | 38 | @Override 39 | public List getItem(int position) { 40 | return myLists.get(position); 41 | } 42 | 43 | @Override 44 | public long getItemId(int position) { 45 | return position; 46 | } 47 | 48 | @Override 49 | public View getView(int position, View convertView, final ViewGroup parent) { 50 | final MyViewHolder holder; 51 | if (convertView != null) { 52 | holder = (MyViewHolder) convertView.getTag(); 53 | } else { 54 | //当convertView 为空时 声明控件 55 | holder = new MyViewHolder(); 56 | convertView = LayoutInflater.from(context).inflate(R.layout.item, null); 57 | holder.pickerView = (ImageShowPickerView) convertView.findViewById(R.id.it_picker_view); 58 | convertView.setTag(holder); 59 | } 60 | final List list = getItem(position); 61 | Log.e("list", "======" + list.size()); 62 | holder.pickerView.setImageLoaderInterface(new Loader()); 63 | holder.pickerView.setMaxNum(9); 64 | holder.pickerView.setNewData(list); 65 | //展示有动画和无动画 66 | if (position % 2 == 1) { 67 | holder.pickerView.setShowAnim(true); 68 | } else { 69 | holder.pickerView.setShowAnim(false); 70 | } 71 | holder.pickerView.setPickerListener(new ImageShowPickerListener() { 72 | @Override 73 | public void addOnClickListener(int remainNum) { 74 | Toast.makeText(context, "remainNum" + remainNum, Toast.LENGTH_SHORT).show(); 75 | 76 | list.add(new ImageBean("http://pic78.huitu.com/res/20160604/1029007_20160604114552332126_1.jpg")); 77 | holder.pickerView.addData(new ImageBean("http://pic78.huitu.com/res/20160604/1029007_20160604114552332126_1.jpg")); 78 | 79 | } 80 | 81 | @Override 82 | public void picOnClickListener(List list, int position, int remainNum) { 83 | Toast.makeText(context, list.size() + "========" + position + "remainNum" + remainNum, Toast.LENGTH_SHORT).show(); 84 | } 85 | 86 | @Override 87 | public void delOnClickListener(int position, int remainNum) { 88 | list.remove(position); 89 | Toast.makeText(context, "delOnClickListenerremainNum" + remainNum, Toast.LENGTH_SHORT).show(); 90 | } 91 | }); 92 | holder.pickerView.show(); 93 | 94 | return convertView; 95 | } 96 | 97 | class MyViewHolder { 98 | private ImageShowPickerView pickerView; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /app/src/main/java/com/yzs/imageshowpicker/OnePickerActivity.java: -------------------------------------------------------------------------------- 1 | package com.yzs.imageshowpicker; 2 | 3 | import android.Manifest; 4 | import android.content.ContentResolver; 5 | import android.content.Context; 6 | import android.content.DialogInterface; 7 | import android.content.Intent; 8 | import android.content.pm.ActivityInfo; 9 | import android.database.Cursor; 10 | import android.net.Uri; 11 | import android.os.Bundle; 12 | import android.provider.MediaStore; 13 | import android.support.annotation.Nullable; 14 | import android.support.v7.app.AppCompatActivity; 15 | import android.util.Log; 16 | import android.widget.Toast; 17 | 18 | import com.yanzhenjie.alertdialog.AlertDialog; 19 | import com.yanzhenjie.permission.AndPermission; 20 | import com.yanzhenjie.permission.PermissionNo; 21 | import com.yanzhenjie.permission.PermissionYes; 22 | import com.yanzhenjie.permission.Rationale; 23 | import com.yanzhenjie.permission.RationaleListener; 24 | import com.yzs.imageshowpickerview.ImageShowPickerBean; 25 | import com.yzs.imageshowpickerview.ImageShowPickerListener; 26 | import com.yzs.imageshowpickerview.ImageShowPickerView; 27 | import com.zhihu.matisse.Matisse; 28 | import com.zhihu.matisse.MimeType; 29 | import com.zhihu.matisse.engine.impl.GlideEngine; 30 | 31 | import java.util.ArrayList; 32 | import java.util.List; 33 | 34 | /** 35 | * Author: 姚智胜 36 | * Version: V1.0版本 37 | * Description: 38 | * Date: 2017/4/26 39 | */ 40 | 41 | public class OnePickerActivity extends AppCompatActivity { 42 | 43 | private static final int REQUEST_CODE_CHOOSE = 233; 44 | List list; 45 | ImageShowPickerView pickerView; 46 | 47 | @Override 48 | protected void onCreate(@Nullable Bundle savedInstanceState) { 49 | super.onCreate(savedInstanceState); 50 | setContentView(R.layout.item); 51 | pickerView = (ImageShowPickerView) findViewById(R.id.it_picker_view); 52 | list = new ArrayList<>(); 53 | 54 | Log.e("list", "======" + list.size()); 55 | pickerView.setImageLoaderInterface(new Loader()); 56 | pickerView.setNewData(list); 57 | //展示有动画和无动画 58 | 59 | pickerView.setShowAnim(true); 60 | 61 | pickerView.setPickerListener(new ImageShowPickerListener() { 62 | @Override 63 | public void addOnClickListener(int remainNum) { 64 | Matisse.from(OnePickerActivity.this) 65 | .choose(MimeType.allOf()) 66 | .countable(true) 67 | .maxSelectable(remainNum + 1) 68 | .gridExpectedSize(300) 69 | .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) 70 | .thumbnailScale(0.85f) 71 | .imageEngine(new GlideEngine()) 72 | .forResult(REQUEST_CODE_CHOOSE); 73 | Toast.makeText(OnePickerActivity.this, "remainNum" + remainNum, Toast.LENGTH_SHORT).show(); 74 | 75 | // list.add(new ImageBean("http://pic78.huitu.com/res/20160604/1029007_20160604114552332126_1.jpg")); 76 | } 77 | 78 | @Override 79 | public void picOnClickListener(List list, int position, int remainNum) { 80 | Toast.makeText(OnePickerActivity.this, list.size() + "========" + position + "remainNum" + remainNum, Toast.LENGTH_SHORT).show(); 81 | } 82 | 83 | @Override 84 | public void delOnClickListener(int position, int remainNum) { 85 | Toast.makeText(OnePickerActivity.this, "delOnClickListenerremainNum" + remainNum, Toast.LENGTH_SHORT).show(); 86 | } 87 | }); 88 | pickerView.show(); 89 | 90 | // Activity: 91 | AndPermission.with(this) 92 | .requestCode(300) 93 | .permission(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE) 94 | .rationale(rationaleListener) 95 | .callback(this) 96 | .start(); 97 | 98 | 99 | } 100 | 101 | 102 | @PermissionYes(300) 103 | private void getPermissionYes(List grantedPermissions) { 104 | // Successfully. 105 | 106 | } 107 | 108 | @PermissionNo(300) 109 | private void getPermissionNo(List deniedPermissions) { 110 | // Failure. 111 | } 112 | 113 | /** 114 | * Rationale支持,这里自定义对话框。 115 | */ 116 | private RationaleListener rationaleListener = new RationaleListener() { 117 | @Override 118 | public void showRequestPermissionRationale(int i, final Rationale rationale) { 119 | // 自定义对话框。 120 | AlertDialog.newBuilder(OnePickerActivity.this) 121 | .setTitle("请求权限") 122 | .setMessage("请求权限") 123 | .setPositiveButton("确定", new DialogInterface.OnClickListener() { 124 | @Override 125 | public void onClick(DialogInterface dialog, int which) { 126 | dialog.cancel(); 127 | rationale.resume(); 128 | } 129 | }) 130 | .setNegativeButton("取消", new DialogInterface.OnClickListener() { 131 | @Override 132 | public void onClick(DialogInterface dialog, int which) { 133 | dialog.cancel(); 134 | rationale.cancel(); 135 | } 136 | }).show(); 137 | } 138 | }; 139 | 140 | List mSelected; 141 | 142 | @Override 143 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 144 | super.onActivityResult(requestCode, resultCode, data); 145 | if (requestCode == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) { 146 | // mSelected = Matisse.obtainResult(data); 147 | List uriList = Matisse.obtainResult(data); 148 | if (uriList.size() == 1) { 149 | pickerView.addData(new ImageBean(getRealFilePath(OnePickerActivity.this, uriList.get(0)))); 150 | } else { 151 | List list = new ArrayList<>(); 152 | for (Uri uri : uriList) { 153 | list.add(new ImageBean(getRealFilePath(OnePickerActivity.this, uri))); 154 | } 155 | pickerView.addData(list); 156 | } 157 | } 158 | } 159 | 160 | 161 | public String getRealFilePath(final Context context, final Uri uri) { 162 | if (null == uri) return null; 163 | final String scheme = uri.getScheme(); 164 | String data = null; 165 | if (scheme == null) 166 | data = uri.getPath(); 167 | else if (ContentResolver.SCHEME_FILE.equals(scheme)) { 168 | data = uri.getPath(); 169 | } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { 170 | Cursor cursor = context.getContentResolver().query(uri, new String[]{MediaStore.Images.ImageColumns.DATA}, null, null, null); 171 | if (null != cursor) { 172 | if (cursor.moveToFirst()) { 173 | int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); 174 | if (index > -1) { 175 | data = cursor.getString(index); 176 | } 177 | } 178 | cursor.close(); 179 | } 180 | } 181 | return data; 182 | } 183 | 184 | } 185 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/home_ac.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 |