├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ ├── adapter_image.xml │ │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── donkingliang │ │ │ └── imageselectdemo │ │ │ ├── adapter │ │ │ └── ImageAdapter.java │ │ │ └── MainActivity.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── donkingliang │ │ │ └── imageselectdemo │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── donkingliang │ │ └── imageselectdemo │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── imageselector ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-xhdpi │ │ │ │ ├── ic_gif.png │ │ │ │ ├── icon_back.png │ │ │ │ ├── text_indicator.png │ │ │ │ ├── ic_photo_camera.png │ │ │ │ ├── icon_image_select.png │ │ │ │ └── icon_image_un_select.png │ │ │ ├── drawable │ │ │ │ ├── btn_green_shape.xml │ │ │ │ ├── btn_back_selector.xml │ │ │ │ ├── btn_foreground_selector.xml │ │ │ │ └── folder_bg.xml │ │ │ ├── xml │ │ │ │ └── image_selector_file_paths.xml │ │ │ ├── layout │ │ │ │ ├── adapter_camera.xml │ │ │ │ ├── adapter_images_item.xml │ │ │ │ ├── adapter_folder.xml │ │ │ │ ├── activity_clip_image.xml │ │ │ │ ├── activity_preview.xml │ │ │ │ └── activity_image_select.xml │ │ │ ├── values │ │ │ │ └── strings.xml │ │ │ └── values-en │ │ │ │ └── strings.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── donkingliang │ │ │ │ └── imageselector │ │ │ │ ├── provider │ │ │ │ └── ImageSelectorProvider.java │ │ │ │ ├── utils │ │ │ │ ├── StringUtils.java │ │ │ │ ├── VersionUtils.java │ │ │ │ ├── MD5Utils.java │ │ │ │ ├── DateUtils.java │ │ │ │ ├── ImageSelector.java │ │ │ │ ├── UriUtils.java │ │ │ │ └── ImageUtil.java │ │ │ │ ├── view │ │ │ │ ├── SquareImageView.java │ │ │ │ ├── MyViewPager.java │ │ │ │ └── ClipImageView.java │ │ │ │ ├── entry │ │ │ │ ├── Folder.java │ │ │ │ ├── RequestConfig.java │ │ │ │ └── Image.java │ │ │ │ ├── adapter │ │ │ │ ├── FolderAdapter.java │ │ │ │ ├── ImagePagerAdapter.java │ │ │ │ └── ImageAdapter.java │ │ │ │ ├── ClipImageActivity.java │ │ │ │ ├── model │ │ │ │ └── ImageModel.java │ │ │ │ ├── PreviewActivity.java │ │ │ │ └── ImageSelectorActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── donkingliang │ │ │ └── imageselector │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── donkingliang │ │ └── imageselector │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── 效果图 ├── 相册.jpg ├── 预览.jpg └── 文件夹.jpg ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── README1.4.0.md ├── gradlew ├── README.md └── LICENSE /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /imageselector/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':imageselector' 2 | -------------------------------------------------------------------------------- /效果图/相册.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/效果图/相册.jpg -------------------------------------------------------------------------------- /效果图/预览.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/效果图/预览.jpg -------------------------------------------------------------------------------- /效果图/文件夹.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/效果图/文件夹.jpg -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ImageSelectDemo 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /imageselector/src/main/res/drawable-xhdpi/ic_gif.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/imageselector/src/main/res/drawable-xhdpi/ic_gif.png -------------------------------------------------------------------------------- /imageselector/src/main/res/drawable-xhdpi/icon_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/imageselector/src/main/res/drawable-xhdpi/icon_back.png -------------------------------------------------------------------------------- /imageselector/src/main/res/drawable-xhdpi/text_indicator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/imageselector/src/main/res/drawable-xhdpi/text_indicator.png -------------------------------------------------------------------------------- /imageselector/src/main/res/drawable-xhdpi/ic_photo_camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/imageselector/src/main/res/drawable-xhdpi/ic_photo_camera.png -------------------------------------------------------------------------------- /imageselector/src/main/res/drawable-xhdpi/icon_image_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/imageselector/src/main/res/drawable-xhdpi/icon_image_select.png -------------------------------------------------------------------------------- /imageselector/src/main/res/drawable-xhdpi/icon_image_un_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donkingliang/ImageSelector/HEAD/imageselector/src/main/res/drawable-xhdpi/icon_image_un_select.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /imageselector/src/main/res/drawable/btn_green_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /imageselector/src/main/res/xml/image_selector_file_paths.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /imageselector/src/main/java/com/donkingliang/imageselector/provider/ImageSelectorProvider.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselector.provider; 2 | 3 | import androidx.core.content.FileProvider; 4 | 5 | /** 6 | * @Author teach liang 7 | * @Description 8 | * @Date 2019/9/12 9 | */ 10 | public class ImageSelectorProvider extends FileProvider { 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /imageselector/src/main/java/com/donkingliang/imageselector/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselector.utils; 2 | 3 | public class StringUtils { 4 | 5 | public static boolean isNotEmptyString(final String str) { 6 | return str != null && str.length() > 0; 7 | } 8 | 9 | public static boolean isEmptyString(final String str) { 10 | return str == null || str.length() <= 0; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /app/src/test/java/com/donkingliang/imageselectdemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselectdemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /imageselector/src/test/java/com/donkingliang/imageselector/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselector; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/donkingliang/imageselectdemo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselectdemo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /imageselector/src/androidTest/java/com/donkingliang/imageselector/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselector; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /captures 3 | 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | 8 | 9 | 10 | # Generated files 11 | bin/ 12 | gen/ 13 | 14 | # Gradle files 15 | .gradle/ 16 | /build 17 | /*/build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | # Eclipse project files 29 | .classpath 30 | .project 31 | .settings/ 32 | 33 | # Intellij project files 34 | *.iml 35 | *.ipr 36 | *.iws 37 | .idea/ 38 | 39 | # System files 40 | .DS_Store -------------------------------------------------------------------------------- /app/src/main/res/layout/adapter_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | -------------------------------------------------------------------------------- /imageselector/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /imageselector/src/main/res/layout/adapter_camera.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 17 | -------------------------------------------------------------------------------- /imageselector/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 | -------------------------------------------------------------------------------- /imageselector/src/main/res/drawable/btn_back_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /imageselector/src/main/res/drawable/btn_foreground_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /imageselector/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 图片 3 | 确定 4 | 预览 5 | 选择 6 | %d张 7 | 全部图片 8 | 今天 9 | 本周 10 | 本月 11 | 确定 12 | 取消 13 | 提示 14 | 该相册需要赋予访问存储和拍照的权限,请到“设置”>“应用”>“权限”中配置权限。 15 | 16 | -------------------------------------------------------------------------------- /imageselector/src/main/res/drawable/folder_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | 20 | 21 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /imageselector/src/main/java/com/donkingliang/imageselector/view/SquareImageView.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselector.view; 2 | 3 | import android.content.Context; 4 | import androidx.appcompat.widget.AppCompatImageView; 5 | import android.util.AttributeSet; 6 | 7 | /** 8 | * 正方形的ImageView 9 | */ 10 | public class SquareImageView extends AppCompatImageView { 11 | 12 | public SquareImageView(Context context) { 13 | super(context); 14 | } 15 | 16 | public SquareImageView(Context context, AttributeSet attrs) { 17 | super(context, attrs); 18 | } 19 | 20 | public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) { 21 | super(context, attrs, defStyleAttr); 22 | } 23 | 24 | @Override 25 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 26 | super.onMeasure(widthMeasureSpec, widthMeasureSpec); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /imageselector/src/main/res/values-en/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Photos 3 | Send 4 | Preview 5 | Select 6 | %d 7 | All Photos 8 | This today 9 | This week 10 | This month 11 | Confirm 12 | Cancel 13 | Hint 14 | This album needs to be granted access to storage and photos, please go to Settings > App > Permissions to configure permissions. 15 | 16 | -------------------------------------------------------------------------------- /imageselector/src/main/java/com/donkingliang/imageselector/view/MyViewPager.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselector.view; 2 | 3 | import android.content.Context; 4 | import androidx.viewpager.widget.ViewPager; 5 | import android.util.AttributeSet; 6 | import android.view.MotionEvent; 7 | 8 | /** 9 | * 继承ViewPager并在onInterceptTouchEvent捕捉异常。 10 | * 因为ViewPager嵌套PhotoView使用,有时候会发生IllegalArgumentException异常。 11 | */ 12 | public class MyViewPager extends ViewPager { 13 | 14 | public MyViewPager(Context context) { 15 | super(context); 16 | } 17 | 18 | public MyViewPager(Context context, AttributeSet attrs) { 19 | super(context, attrs); 20 | } 21 | 22 | @Override 23 | public boolean onInterceptTouchEvent(MotionEvent ev) { 24 | try { 25 | return super.onInterceptTouchEvent(ev); 26 | } catch (IllegalArgumentException e) { 27 | return false; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 30 5 | defaultConfig { 6 | applicationId "com.donkingliang.imageselectdemo" 7 | minSdkVersion 14 8 | targetSdkVersion 30 9 | versionCode 1 10 | versionName "1.0" 11 | } 12 | buildTypes { 13 | release { 14 | minifyEnabled false 15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 16 | } 17 | } 18 | } 19 | 20 | dependencies { 21 | implementation fileTree(dir: 'libs', include: ['*.jar']) 22 | testImplementation 'junit:junit:4.12' 23 | implementation 'androidx.appcompat:appcompat:1.2.0' 24 | implementation 'androidx.recyclerview:recyclerview:1.1.0' 25 | implementation 'com.github.bumptech.glide:glide:4.12.0' 26 | annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' 27 | implementation project(':imageselector') 28 | } 29 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | android.enableJetifier=true 20 | android.useAndroidX=true -------------------------------------------------------------------------------- /imageselector/src/main/java/com/donkingliang/imageselector/utils/VersionUtils.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselector.utils; 2 | 3 | import android.os.Build; 4 | 5 | /** 6 | * @Author teach-梁任彦 7 | * @Description 8 | * @Date 2019-09-11 9 | */ 10 | public class VersionUtils { 11 | 12 | /** 13 | * 判断是否是Android L版本 14 | * 15 | * @return 16 | */ 17 | public static boolean isAndroidL() { 18 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; 19 | } 20 | 21 | /** 22 | * 判断是否是Android N版本 23 | * 24 | * @return 25 | */ 26 | public static boolean isAndroidN() { 27 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N; 28 | } 29 | 30 | /** 31 | * 判断是否是Android P版本 32 | * 33 | * @return 34 | */ 35 | public static boolean isAndroidP() { 36 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.P; 37 | } 38 | 39 | /** 40 | * 判断是否是Android Q版本 41 | * 42 | * @return 43 | */ 44 | public static boolean isAndroidQ() { 45 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /imageselector/src/main/java/com/donkingliang/imageselector/utils/MD5Utils.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselector.utils; 2 | 3 | import java.security.MessageDigest; 4 | 5 | /** 6 | * @Author teach liang 7 | * @Description MD5工具类 8 | * @Date 2019/1/2 9 | */ 10 | public class MD5Utils { 11 | 12 | private static final String HEX_DIGITS[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}; 13 | 14 | public static String md5(String s) { 15 | try { 16 | MessageDigest md = MessageDigest.getInstance("MD5"); 17 | byte[] bytes = md.digest(s.getBytes("utf-8")); 18 | return toHex(bytes); 19 | } catch (Exception e) { 20 | e.printStackTrace(); 21 | } 22 | return null; 23 | } 24 | 25 | private static String toHex(byte[] bytes) { 26 | StringBuilder ret = new StringBuilder(bytes.length * 2); 27 | for (int i = 0; i < bytes.length; i++) { 28 | ret.append(HEX_DIGITS[(bytes[i] >> 4) & 0x0f]); 29 | ret.append(HEX_DIGITS[bytes[i] & 0x0f]); 30 | } 31 | return ret.toString(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /imageselector/src/main/res/layout/adapter_images_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 22 | 23 | 33 | 34 | 42 | -------------------------------------------------------------------------------- /imageselector/src/main/java/com/donkingliang/imageselector/entry/Folder.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselector.entry; 2 | 3 | 4 | import com.donkingliang.imageselector.utils.StringUtils; 5 | 6 | import java.util.ArrayList; 7 | 8 | /** 9 | * 图片文件夹实体类 10 | */ 11 | public class Folder { 12 | 13 | private boolean useCamera; // 是否可以调用相机拍照。只有“全部”文件夹才可以拍照 14 | private String name; 15 | private ArrayList images; 16 | 17 | public Folder(String name) { 18 | this.name = name; 19 | } 20 | 21 | public Folder(String name, ArrayList images) { 22 | this.name = name; 23 | this.images = images; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public ArrayList getImages() { 35 | return images; 36 | } 37 | 38 | public void setImages(ArrayList images) { 39 | this.images = images; 40 | } 41 | 42 | public boolean isUseCamera() { 43 | return useCamera; 44 | } 45 | 46 | public void setUseCamera(boolean useCamera) { 47 | this.useCamera = useCamera; 48 | } 49 | 50 | public void addImage(Image image) { 51 | if (image != null && StringUtils.isNotEmptyString(image.getPath())) { 52 | if (images == null) { 53 | images = new ArrayList<>(); 54 | } 55 | images.add(image); 56 | } 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "Folder{" + 62 | "name='" + name + '\'' + 63 | ", images=" + images + 64 | '}'; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 30 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /imageselector/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | group='com.github.donkingliang' // 指定group,com.github.<用户名> 4 | 5 | android { 6 | compileSdkVersion 30 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 30 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | testImplementation 'junit:junit:4.12' 24 | implementation 'androidx.appcompat:appcompat:1.2.0' 25 | implementation 'androidx.recyclerview:recyclerview:1.1.0' 26 | implementation 'com.github.bumptech.glide:glide:4.12.0' 27 | annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' 28 | implementation 'com.github.chrisbanes:PhotoView:2.3.0' 29 | } 30 | 31 | //--------------------------------------------- 32 | 33 | // 指定编码 34 | tasks.withType(JavaCompile) { 35 | options.encoding = "UTF-8" 36 | } 37 | 38 | // 打包源码 39 | task sourcesJar(type: Jar) { 40 | from android.sourceSets.main.java.srcDirs 41 | classifier = 'sources' 42 | } 43 | 44 | task javadoc(type: Javadoc) { 45 | failOnError false 46 | source = android.sourceSets.main.java.sourceFiles 47 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 48 | classpath += configurations.compile 49 | } 50 | 51 | // 制作文档(Javadoc) 52 | task javadocJar(type: Jar, dependsOn: javadoc) { 53 | classifier = 'javadoc' 54 | from javadoc.destinationDir 55 | } 56 | 57 | artifacts { 58 | archives sourcesJar 59 | archives javadocJar 60 | } -------------------------------------------------------------------------------- /imageselector/src/main/java/com/donkingliang/imageselector/utils/DateUtils.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselector.utils; 2 | 3 | import android.content.Context; 4 | 5 | import com.donkingliang.imageselector.R; 6 | 7 | import java.text.SimpleDateFormat; 8 | import java.util.Calendar; 9 | import java.util.Date; 10 | 11 | public class DateUtils { 12 | 13 | public static String getImageTime(Context context,long time) { 14 | Calendar calendar = Calendar.getInstance(); 15 | calendar.setTime(new Date()); 16 | Calendar imageTime = Calendar.getInstance(); 17 | imageTime.setTimeInMillis(time); 18 | if (sameDay(calendar, imageTime)) { 19 | return context.getString(R.string.selector_this_today); 20 | } else if (sameWeek(calendar, imageTime)) { 21 | return context.getString(R.string.selector_this_week); 22 | } else if (sameMonth(calendar, imageTime)) { 23 | return context.getString(R.string.selector_this_month); 24 | } else { 25 | Date date = new Date(time); 26 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM"); 27 | return sdf.format(date); 28 | } 29 | } 30 | 31 | public static boolean sameDay(Calendar calendar1, Calendar calendar2) { 32 | return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) 33 | && calendar1.get(Calendar.DAY_OF_YEAR) == calendar2.get(Calendar.DAY_OF_YEAR); 34 | } 35 | 36 | public static boolean sameWeek(Calendar calendar1, Calendar calendar2) { 37 | return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) 38 | && calendar1.get(Calendar.WEEK_OF_YEAR) == calendar2.get(Calendar.WEEK_OF_YEAR); 39 | } 40 | 41 | public static boolean sameMonth(Calendar calendar1, Calendar calendar2) { 42 | return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) 43 | && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/donkingliang/imageselectdemo/adapter/ImageAdapter.java: -------------------------------------------------------------------------------- 1 | package com.donkingliang.imageselectdemo.adapter; 2 | 3 | import android.content.Context; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | 10 | import com.bumptech.glide.Glide; 11 | import com.donkingliang.imageselectdemo.R; 12 | import com.donkingliang.imageselector.utils.ImageUtil; 13 | import com.donkingliang.imageselector.utils.UriUtils; 14 | import com.donkingliang.imageselector.utils.VersionUtils; 15 | 16 | import java.util.ArrayList; 17 | 18 | public class ImageAdapter extends RecyclerView.Adapter { 19 | 20 | private Context mContext; 21 | private ArrayList mImages; 22 | private LayoutInflater mInflater; 23 | private boolean isAndroidQ = VersionUtils.isAndroidQ(); 24 | 25 | public ImageAdapter(Context context) { 26 | mContext = context; 27 | this.mInflater = LayoutInflater.from(mContext); 28 | } 29 | 30 | public ArrayList getImages() { 31 | return mImages; 32 | } 33 | 34 | @Override 35 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 36 | View view = mInflater.inflate(R.layout.adapter_image, parent, false); 37 | return new ViewHolder(view); 38 | } 39 | 40 | @Override 41 | public void onBindViewHolder(final ViewHolder holder, final int position) { 42 | final String image = mImages.get(position); 43 | // 是否是剪切返回的图片 44 | boolean isCutImage = ImageUtil.isCutImage(mContext, image); 45 | if (isAndroidQ && !isCutImage) { 46 | Glide.with(mContext).load(UriUtils.getImageContentUri(mContext, image)).into(holder.ivImage); 47 | } else { 48 | Glide.with(mContext).load(image).into(holder.ivImage); 49 | } 50 | 51 | } 52 | 53 | @Override 54 | public int getItemCount() { 55 | return mImages == null ? 0 : mImages.size(); 56 | } 57 | 58 | public void refresh(ArrayList images) { 59 | mImages = images; 60 | notifyDataSetChanged(); 61 | } 62 | 63 | static class ViewHolder extends RecyclerView.ViewHolder { 64 | 65 | ImageView ivImage; 66 | 67 | public ViewHolder(View itemView) { 68 | super(itemView); 69 | ivImage = itemView.findViewById(R.id.iv_image); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 |