├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── android.jpg │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── 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-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── cn │ │ │ │ └── mtjsoft │ │ │ │ └── uploadmultiimagedemo │ │ │ │ ├── ImageModel.java │ │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── cn │ │ │ └── mtjsoft │ │ │ └── uploadmultiimagedemo │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── cn │ │ └── mtjsoft │ │ └── uploadmultiimagedemo │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── multiimagelibrary ├── consumer-rules.pro ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ └── attrs.xml │ │ │ ├── drawable │ │ │ │ ├── img_add.png │ │ │ │ └── img_delete.png │ │ │ └── layout │ │ │ │ └── item_def.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── cn │ │ │ └── mtjsoft │ │ │ └── multiimagelibrary │ │ │ ├── imp │ │ │ ├── ImageAddClickListener.java │ │ │ ├── ImageItemClickListener.java │ │ │ ├── ImageInfo.java │ │ │ ├── ImageDeleteClickListener.java │ │ │ └── ImageViewLoader.java │ │ │ ├── bean │ │ │ └── AddBean.java │ │ │ ├── utils │ │ │ ├── HHScreenUtils.java │ │ │ └── HHDensityUtils.java │ │ │ └── UploadMultiImageView.java │ ├── test │ │ └── java │ │ │ └── cn │ │ │ └── mtjsoft │ │ │ └── multiimagelibrary │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── cn │ │ └── mtjsoft │ │ └── multiimagelibrary │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── vcs.xml ├── misc.xml ├── runConfigurations.xml ├── gradle.xml └── jarRepositories.xml ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /multiimagelibrary/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /multiimagelibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name='UploadMultiImageView' 2 | include ':app' 3 | include ':multiimagelibrary' -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | UploadMultiImageDemo 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /multiimagelibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | GridViewPager 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/android.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/app/src/main/res/mipmap-xxhdpi/android.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /multiimagelibrary/src/main/res/drawable/img_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/multiimagelibrary/src/main/res/drawable/img_add.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /multiimagelibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /multiimagelibrary/src/main/res/drawable/img_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtjsoft/UploadMultiImageView/HEAD/multiimagelibrary/src/main/res/drawable/img_delete.png -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /multiimagelibrary/src/main/java/cn/mtjsoft/multiimagelibrary/imp/ImageAddClickListener.java: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.multiimagelibrary.imp; 2 | 3 | public interface ImageAddClickListener { 4 | void ImageAddClick(); 5 | } 6 | -------------------------------------------------------------------------------- /multiimagelibrary/src/main/java/cn/mtjsoft/multiimagelibrary/imp/ImageItemClickListener.java: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.multiimagelibrary.imp; 2 | 3 | public interface ImageItemClickListener { 4 | void ImageItemClick(int position); 5 | } 6 | -------------------------------------------------------------------------------- /multiimagelibrary/src/main/java/cn/mtjsoft/multiimagelibrary/imp/ImageInfo.java: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.multiimagelibrary.imp; 2 | 3 | public interface ImageInfo { 4 | 5 | Object getImagePath(); 6 | 7 | boolean isLastAddViewData(); 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #6200EE 4 | #3700B3 5 | #03DAC5 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jun 10 11:45:06 CST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /multiimagelibrary/src/main/java/cn/mtjsoft/multiimagelibrary/imp/ImageDeleteClickListener.java: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.multiimagelibrary.imp; 2 | 3 | import cn.mtjsoft.multiimagelibrary.UploadMultiImageView; 4 | 5 | public interface ImageDeleteClickListener { 6 | void ImageDeleteClick(UploadMultiImageView multiImageView, int position); 7 | } 8 | -------------------------------------------------------------------------------- /multiimagelibrary/src/main/java/cn/mtjsoft/multiimagelibrary/imp/ImageViewLoader.java: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.multiimagelibrary.imp; 2 | 3 | import android.content.Context; 4 | import android.widget.ImageView; 5 | 6 | /** 7 | * 图片加载器 8 | */ 9 | public interface ImageViewLoader { 10 | void displayImage(Context context, Object path, ImageView imageView); 11 | } 12 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/cn/mtjsoft/uploadmultiimagedemo/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.uploadmultiimagedemo 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /multiimagelibrary/src/test/java/cn/mtjsoft/multiimagelibrary/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.multiimagelibrary; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/cn/mtjsoft/uploadmultiimagedemo/ImageModel.java: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.uploadmultiimagedemo; 2 | 3 | import cn.mtjsoft.multiimagelibrary.imp.ImageInfo; 4 | 5 | /** 6 | * 实现 ImageInfo 7 | */ 8 | public class ImageModel implements ImageInfo { 9 | 10 | private Object path; 11 | 12 | public Object getPath() { 13 | return path; 14 | } 15 | 16 | public void setPath(Object path) { 17 | this.path = path; 18 | } 19 | 20 | /** 21 | * @return 返回图片地址 22 | */ 23 | @Override 24 | public Object getImagePath() { 25 | return path; 26 | } 27 | 28 | /** 29 | * @return 这里固定返回 false 30 | */ 31 | @Override 32 | public boolean isLastAddViewData() { 33 | return false; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /multiimagelibrary/src/main/res/layout/item_def.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 13 | 14 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /multiimagelibrary/src/main/java/cn/mtjsoft/multiimagelibrary/bean/AddBean.java: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.multiimagelibrary.bean; 2 | 3 | import cn.mtjsoft.multiimagelibrary.imp.ImageInfo; 4 | 5 | public class AddBean implements ImageInfo { 6 | private Object addPath; 7 | 8 | private boolean isAdd; 9 | 10 | public Object getAddPath() { 11 | return addPath; 12 | } 13 | 14 | public void setAddPath(Object addPath) { 15 | this.addPath = addPath; 16 | } 17 | 18 | public boolean isAdd() { 19 | return isAdd; 20 | } 21 | 22 | public void setAdd(boolean add) { 23 | isAdd = add; 24 | } 25 | 26 | @Override 27 | public Object getImagePath() { 28 | return addPath; 29 | } 30 | 31 | @Override 32 | public boolean isLastAddViewData() { 33 | return isAdd; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /multiimagelibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/cn/mtjsoft/uploadmultiimagedemo/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.uploadmultiimagedemo 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("cn.mtjsoft.uploadmultiimagedemo", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /multiimagelibrary/src/androidTest/java/cn/mtjsoft/multiimagelibrary/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.multiimagelibrary; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | 25 | assertEquals("cn.mtjsoft.multiimagelibrary.test", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 20 | 21 | 28 | 29 | -------------------------------------------------------------------------------- /multiimagelibrary/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /multiimagelibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | group='com.gitee.mtj_java' 4 | android { 5 | compileSdkVersion 29 6 | buildToolsVersion "29.0.3" 7 | 8 | defaultConfig { 9 | minSdkVersion 19 10 | targetSdkVersion 29 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 15 | consumerProguardFiles 'consumer-rules.pro' 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | 30 | implementation 'androidx.appcompat:appcompat:1.1.0' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 34 | // 35 | api "androidx.recyclerview:recyclerview:1.1.0" 36 | } 37 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /multiimagelibrary/src/main/java/cn/mtjsoft/multiimagelibrary/utils/HHScreenUtils.java: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.multiimagelibrary.utils; 2 | 3 | import android.content.Context; 4 | 5 | import java.util.HashMap; 6 | 7 | public class HHScreenUtils 8 | { 9 | private static final String tag=HHScreenUtils.class.getName(); 10 | public static final String SCREEN_HEIGHT="height"; 11 | public static final String SCREEN_WIDTH="width"; 12 | /** 13 | * 获取屏幕的宽度 14 | * @param context 上下文对象 15 | * @return 16 | */ 17 | public static int getScreenWidth(Context context) 18 | { 19 | return context.getResources().getDisplayMetrics().widthPixels; 20 | } 21 | /** 22 | * 获取屏幕的高度 23 | * @param context 上下文对象 24 | * @return 25 | */ 26 | public static int getScreenHeight(Context context) 27 | { 28 | return context.getResources().getDisplayMetrics().heightPixels; 29 | } 30 | /** 31 | * 获取屏幕的高度和宽度 32 | * @param context 上下文对象 33 | * @return 返回一个HashMap,获取宽度用SCREEN_WIDTH,获取高度用SCREEN_HEIGHT 34 | */ 35 | public static HashMap getScreenHeightAndWidth(Context context) 36 | { 37 | HashMap map=new HashMap(); 38 | map.put(SCREEN_HEIGHT, getScreenHeight(context)); 39 | map.put(SCREEN_WIDTH, getScreenWidth(context)); 40 | return map; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 29 7 | buildToolsVersion "29.0.3" 8 | 9 | defaultConfig { 10 | applicationId "cn.mtjsoft.uploadmultiimagedemo" 11 | minSdkVersion 19 12 | targetSdkVersion 29 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 31 | implementation 'androidx.appcompat:appcompat:1.1.0' 32 | implementation 'androidx.core:core-ktx:1.3.0' 33 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 34 | testImplementation 'junit:junit:4.12' 35 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 37 | // implementation project(path: ':multiimagelibrary') 38 | implementation 'com.gitee.mtj_java:UploadMultiImageView:1.1.0' 39 | } 40 | -------------------------------------------------------------------------------- /multiimagelibrary/src/main/java/cn/mtjsoft/multiimagelibrary/utils/HHDensityUtils.java: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.multiimagelibrary.utils; 2 | 3 | import android.content.Context; 4 | 5 | public class HHDensityUtils { 6 | /** 7 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素) 8 | */ 9 | public static int dip2px(Context context, float dpValue) { 10 | final float scale = context.getResources().getDisplayMetrics().density; 11 | return (int) (dpValue * scale + 0.5f); 12 | } 13 | 14 | /** 15 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp 16 | */ 17 | public static int px2dip(Context context, float pxValue) { 18 | final float scale = context.getResources().getDisplayMetrics().density; 19 | return (int) (pxValue / scale + 0.5f); 20 | } 21 | 22 | /** 23 | * 将px值转换为sp值,保证文字大小不变 24 | * 25 | * @param pxValue 26 | * @return 27 | */ 28 | public static int px2sp(Context context, float pxValue) { 29 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; 30 | return (int) (pxValue / fontScale + 0.5f); 31 | } 32 | 33 | /** 34 | * 将sp值转换为px值,保证文字大小不变 35 | * 36 | * @param spValue 37 | * @return 38 | */ 39 | public static int sp2px(Context context, float spValue) { 40 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; 41 | return (int) (spValue * fontScale + 0.5f); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/src/main/java/cn/mtjsoft/uploadmultiimagedemo/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.uploadmultiimagedemo 2 | 3 | import android.app.AlertDialog 4 | import android.content.DialogInterface 5 | import androidx.appcompat.app.AppCompatActivity 6 | import android.os.Bundle 7 | import android.widget.ImageView 8 | import android.widget.Toast 9 | import kotlinx.android.synthetic.main.activity_main.* 10 | import androidx.appcompat.app.AlertDialog as AppAlertDialog 11 | 12 | class MainActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContentView(R.layout.activity_main) 17 | 18 | val list: MutableList = ArrayList() 19 | for (i in 0..7) { 20 | val model = ImageModel() 21 | model.path = R.mipmap.android 22 | list.add(model) 23 | } 24 | 25 | uploadMultiImageView 26 | .setImageInfoList(list.toList()) 27 | // 所有属性都可以在代码中再设置 28 | // 开启拖拽排序 29 | .setDrag(true) 30 | // 设置每行3列 31 | .setColumns(3) 32 | // 显示新增按钮 33 | .setShowAdd(true) 34 | // 设置图片缩放类型 (默认 CENTER_CROP) 35 | .setScaleType(ImageView.ScaleType.CENTER_CROP) 36 | // item点击回调 37 | .setImageItemClickListener { position -> 38 | // imageview点击 39 | Toast.makeText(baseContext, "点击第了${position}个", Toast.LENGTH_SHORT).show() 40 | } 41 | // 设置删除点击监听(如果不设置,测试默认移除数据),自己处理数据删除过程 42 | .setDeleteClickListener { multiImageView, position -> 43 | AlertDialog.Builder(this) 44 | .setTitle("删除") 45 | .setMessage("确定要删除图片吗?") 46 | .setNegativeButton("确定") { dialog, which -> 47 | dialog.dismiss() 48 | multiImageView.deleteItem(position) 49 | } 50 | .show() 51 | } 52 | // 图片加载 53 | .setImageViewLoader { context, path, imageView -> 54 | // (这里自己选择图片加载框架,不做限制) 55 | imageView.setImageResource(path as Int) 56 | } 57 | // 新增按钮点击回调 58 | .setAddClickListener { 59 | // 模拟新增一条数据 60 | addNewData() 61 | } 62 | .show() 63 | } 64 | 65 | /** 66 | * 新增一条或多条数据 67 | */ 68 | private fun addNewData() { 69 | val tempList: MutableList = ArrayList() 70 | val model = ImageModel() 71 | model.path = R.mipmap.android 72 | tempList.add(model) 73 | // 新增数据 74 | uploadMultiImageView.addNewData(tempList.toList()) 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | xmlns:android 17 | 18 | ^$ 19 | 20 | 21 | 22 |
23 |
24 | 25 | 26 | 27 | xmlns:.* 28 | 29 | ^$ 30 | 31 | 32 | BY_NAME 33 | 34 |
35 |
36 | 37 | 38 | 39 | .*:id 40 | 41 | http://schemas.android.com/apk/res/android 42 | 43 | 44 | 45 |
46 |
47 | 48 | 49 | 50 | .*:name 51 | 52 | http://schemas.android.com/apk/res/android 53 | 54 | 55 | 56 |
57 |
58 | 59 | 60 | 61 | name 62 | 63 | ^$ 64 | 65 | 66 | 67 |
68 |
69 | 70 | 71 | 72 | style 73 | 74 | ^$ 75 | 76 | 77 | 78 |
79 |
80 | 81 | 82 | 83 | .* 84 | 85 | ^$ 86 | 87 | 88 | BY_NAME 89 | 90 |
91 |
92 | 93 | 94 | 95 | .* 96 | 97 | http://schemas.android.com/apk/res/android 98 | 99 | 100 | ANDROID_ATTRIBUTE_ORDER 101 | 102 |
103 |
104 | 105 | 106 | 107 | .* 108 | 109 | .* 110 | 111 | 112 | BY_NAME 113 | 114 |
115 |
116 |
117 |
118 | 119 | 121 |
122 |
-------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | @[TOC](目录) 2 | 3 | # UploadMultiImageView 多图上传组件 4 | 项目中经常会有多图上传的需求,每次都重复写,实在不是一个好办法。于是基于 **【recycleview】** 来实现一个仅仅需要 **【十几行代码】** 就可拥有拖拽排序功能的多图上传组件。 5 | 6 | 目前使用的AndroidX,不是的同学,请尽快升级吧! 7 | # 先看效果 8 | ![效果图](https://img-blog.csdnimg.cn/20200610222609657.gif#pic_center) 9 | 10 | [UploadMultiImageView源码传送门](https://gitee.com/mtj_java/UploadMultiImageView) 11 | # 使用说明 12 | ## 1、在根目录 build.gradle 添加: 13 | 14 | ```java 15 | allprojects { 16 | repositories { 17 | ... 18 | maven { url 'https://jitpack.io' } 19 | } 20 | } 21 | 22 | ``` 23 | ## 2、在module项目下的build.gradle中添加: 24 | 25 | ```java 26 | dependencies { 27 | implementation 'com.gitee.mtj_java:UploadMultiImageView:1.1.0' 28 | } 29 | ``` 30 | 31 | ## 3、在布局xml中添加组件 32 | 33 | ```java 34 | 46 | ``` 47 | # 版本及自定义属性说明 48 | 49 | V1.1.0 50 | -------------------------- 51 | 新增方法: 52 | 53 | ```java 54 | // 设置图片缩放类型 (默认 CENTER_CROP) 55 | setScaleType(ImageView.ScaleType.CENTER_CROP); 56 | // 设置删除点击监听(如果不设置,默认直接移除数据),自己处理过程 57 | setDeleteClickListener(); 58 | ``` 59 | 60 | V1.0.0 61 | -------------------------- 62 | 1.0.0 属性 | 属性说明 63 | ------------- | ------------- 64 | img_height | 图片高度(dp)默认与宽度相等 65 | item_spacing| 图片之间的间隔(dp)默认2dp 66 | column_count|列数 默认每行3列 67 | max_count|最多显示张数 默认 Integer.MAX_VALUE 68 | is_showDelete|是否显示删除按钮 默认true 69 | is_showAdd|是否显示添加按钮 默认false 70 | deleteRes|设置删除按钮 71 | deleteWH|删除按钮的宽高(dp)默认25dp 72 | deleteResMargin|删除按钮的边距(dp)默认6dp 73 | addRes|设置添加按钮 74 | is_Drag|是否开启拖拽排序 默认false 75 | 76 | # 代码实现(这里用kotlin写的) 77 | ## 1、Activity 78 | 79 | ```kotlin 80 | class MainActivity : AppCompatActivity() { 81 | 82 | override fun onCreate(savedInstanceState: Bundle?) { 83 | super.onCreate(savedInstanceState) 84 | setContentView(R.layout.activity_main) 85 | // 循环添加几条数据 86 | val list: MutableList = ArrayList() 87 | for (i in 0..7) { 88 | val model = ImageModel() 89 | model.path = R.mipmap.android 90 | list.add(model) 91 | } 92 | 93 | /** 94 | * 核心实现在这里 95 | */ 96 | uploadMultiImageView 97 | .setImageInfoList(list.toList()) 98 | // 所有属性都可以在代码中再设置 99 | // 开启拖拽排序 100 | .setDrag(true) 101 | // 设置每行3列 102 | .setColumns(3) 103 | // 显示新增按钮 104 | .setShowAdd(true) 105 | // 设置图片缩放类型 (默认 CENTER_CROP) 106 | .setScaleType(ImageView.ScaleType.CENTER_CROP) 107 | // item点击回调 108 | .setImageItemClickListener { position -> 109 | // imageview点击 110 | Toast.makeText(baseContext, "点击第了${position}个", Toast.LENGTH_SHORT).show() 111 | } 112 | // 设置删除点击监听(如果不设置,测试默认移除数据),自己处理数据删除过程 113 | .setDeleteClickListener { multiImageView, position -> 114 | AlertDialog.Builder(this) 115 | .setTitle("删除") 116 | .setMessage("确定要删除图片吗?") 117 | .setNegativeButton("确定") { dialog, which -> 118 | dialog.dismiss() 119 | multiImageView.deleteItem(position) 120 | } 121 | .show() 122 | } 123 | // 图片加载 124 | .setImageViewLoader { context, path, imageView -> 125 | // (这里自己选择图片加载框架,不做限制) 126 | imageView.setImageResource(path as Int) 127 | } 128 | // 新增按钮点击回调 129 | .setAddClickListener { 130 | // 模拟新增一条数据 131 | addNewData() 132 | } 133 | .show() 134 | } 135 | 136 | /** 137 | * 新增一条或多条数据 138 | */ 139 | private fun addNewData() { 140 | val tempList: MutableList = ArrayList() 141 | val model = ImageModel() 142 | model.path = R.mipmap.android 143 | tempList.add(model) 144 | // 调用新增数据 145 | uploadMultiImageView.addNewData(tempList.toList()) 146 | } 147 | } 148 | ``` 149 | 150 | ## 2、数据实体类 实现 ImageInfo 151 | 152 | ```java 153 | /** 154 | * 实现 ImageInfo 155 | */ 156 | public class ImageModel implements ImageInfo { 157 | 158 | private Object path; 159 | 160 | public Object getPath() { 161 | return path; 162 | } 163 | 164 | public void setPath(Object path) { 165 | this.path = path; 166 | } 167 | 168 | /** 169 | * @return 图片地址 170 | */ 171 | @Override 172 | public Object getImagePath() { 173 | return path; 174 | } 175 | 176 | /** 177 | * @return 固定返回 false 178 | */ 179 | @Override 180 | public boolean isLastAddViewData() { 181 | return false; 182 | } 183 | } 184 | ``` 185 | # 完结 186 | 怎么样?是不是十分的简洁,核心实现是不是只有仅仅十几行代码? 187 | 188 | **本人公众号,关注一波,共同交流吧。** 189 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2019012509485178.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzI4Nzc5MDgz,size_16,color_FFFFFF,t_70) 190 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /multiimagelibrary/src/main/java/cn/mtjsoft/multiimagelibrary/UploadMultiImageView.java: -------------------------------------------------------------------------------- 1 | package cn.mtjsoft.multiimagelibrary; 2 | 3 | import android.animation.AnimatorSet; 4 | import android.animation.ObjectAnimator; 5 | import android.content.Context; 6 | import android.content.res.TypedArray; 7 | import android.graphics.Rect; 8 | import android.util.AttributeSet; 9 | import android.view.Gravity; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.FrameLayout; 13 | import android.widget.ImageView; 14 | 15 | import androidx.annotation.NonNull; 16 | import androidx.annotation.Nullable; 17 | import androidx.recyclerview.widget.GridLayoutManager; 18 | import androidx.recyclerview.widget.ItemTouchHelper; 19 | import androidx.recyclerview.widget.RecyclerView; 20 | 21 | import java.util.ArrayList; 22 | import java.util.Collections; 23 | import java.util.List; 24 | 25 | import cn.mtjsoft.multiimagelibrary.bean.AddBean; 26 | import cn.mtjsoft.multiimagelibrary.imp.ImageAddClickListener; 27 | import cn.mtjsoft.multiimagelibrary.imp.ImageDeleteClickListener; 28 | import cn.mtjsoft.multiimagelibrary.imp.ImageInfo; 29 | import cn.mtjsoft.multiimagelibrary.imp.ImageItemClickListener; 30 | import cn.mtjsoft.multiimagelibrary.imp.ImageViewLoader; 31 | import cn.mtjsoft.multiimagelibrary.utils.HHDensityUtils; 32 | 33 | public class UploadMultiImageView extends RecyclerView { 34 | 35 | //数据 36 | private List imageInfoList = new ArrayList<>(); 37 | // adapter 38 | private UploadImageAdapter uploadImageAdapter; 39 | // item拖拽处理 40 | private ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemDragTouchCallback()); 41 | // 图片加载器 42 | private ImageViewLoader imageViewLoader; 43 | // 图片点击回调 44 | private ImageItemClickListener imageItemClickListener; 45 | // 新增按钮点击回调 46 | private ImageAddClickListener addClickListener; 47 | // 删除回调 48 | private ImageDeleteClickListener deleteClickListener; 49 | // 设置图片缩放类型 50 | private ImageView.ScaleType scaleType = ImageView.ScaleType.CENTER_CROP; 51 | // 间隔大小 默认2dp 52 | private int itemDecorationSize = 2; 53 | // 是否展示删除按钮 54 | private boolean isShowDelete = true; 55 | // 是否展示最后面的新增按钮(当超过最大张数时,也会隐藏) 56 | private boolean isShowAdd = false; 57 | // 设置删除按钮 58 | private int deleteRes = R.drawable.img_delete; 59 | // 设置删除按钮按钮大小 默认25dp 60 | private int deleteResWH = 25; 61 | // 设置删除按钮margin 62 | private int deleteResMargin = 6; 63 | // 设置新增按钮 64 | private int addRes = R.drawable.img_add; 65 | // 是否开启拖拽排序 66 | private boolean isDrag = false; 67 | // 最大显示张数 68 | private int maxNumber = Integer.MAX_VALUE; 69 | // 每行展示列数 70 | private int columns = 3; 71 | // 图片的高度 默认100dp 72 | private int imgHeight = 0; 73 | 74 | // itemView宽度 75 | private int itemViewWidth; 76 | 77 | public UploadMultiImageView(Context context) { 78 | this(context, null); 79 | } 80 | 81 | public UploadMultiImageView(Context context, AttributeSet attrs) { 82 | this(context, attrs, 0); 83 | } 84 | 85 | public UploadMultiImageView(Context context, AttributeSet attrs, int defStyleAttr) { 86 | super(context, attrs, defStyleAttr); 87 | handleTypedArray(context, attrs); 88 | } 89 | 90 | private void handleTypedArray(Context context, AttributeSet attrs) { 91 | if (attrs == null) { 92 | return; 93 | } 94 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.UploadMultiImageView); 95 | imgHeight = typedArray.getDimensionPixelSize(R.styleable.UploadMultiImageView_img_height, 0); 96 | itemDecorationSize = typedArray.getDimensionPixelSize(R.styleable.UploadMultiImageView_item_spacing, HHDensityUtils.dip2px(getContext(), itemDecorationSize)); 97 | columns = typedArray.getInt(R.styleable.UploadMultiImageView_column_count, columns); 98 | maxNumber = typedArray.getInt(R.styleable.UploadMultiImageView_max_count, maxNumber); 99 | isShowDelete = typedArray.getBoolean(R.styleable.UploadMultiImageView_is_showDelete, isShowDelete); 100 | isShowAdd = typedArray.getBoolean(R.styleable.UploadMultiImageView_is_showAdd, isShowAdd); 101 | deleteRes = typedArray.getResourceId(R.styleable.UploadMultiImageView_deleteRes, deleteRes); 102 | deleteResWH = typedArray.getDimensionPixelSize(R.styleable.UploadMultiImageView_deleteWH, HHDensityUtils.dip2px(getContext(), deleteResWH)); 103 | deleteResMargin = typedArray.getDimensionPixelSize(R.styleable.UploadMultiImageView_deleteResMargin, HHDensityUtils.dip2px(getContext(), deleteResMargin)); 104 | addRes = typedArray.getResourceId(R.styleable.UploadMultiImageView_addRes, addRes); 105 | isDrag = typedArray.getBoolean(R.styleable.UploadMultiImageView_is_Drag, isDrag); 106 | typedArray.recycle(); 107 | } 108 | 109 | /** 110 | * @param imgHeight 设置图片高度,默认与宽度相等 111 | * @return 112 | */ 113 | public UploadMultiImageView setImgHeight(int imgHeight) { 114 | this.imgHeight = HHDensityUtils.dip2px(getContext(), imgHeight); 115 | return this; 116 | } 117 | 118 | /** 119 | * @param columns 设置列数 120 | */ 121 | public UploadMultiImageView setColumns(int columns) { 122 | this.columns = columns; 123 | return this; 124 | } 125 | 126 | /** 127 | * @param deleteRes 设置 删除按钮 128 | */ 129 | public UploadMultiImageView setDeleteRes(int deleteRes) { 130 | this.deleteRes = deleteRes; 131 | return this; 132 | } 133 | 134 | /** 135 | * @param deleteResWH 设置删除按钮宽高 136 | * @return 137 | */ 138 | public UploadMultiImageView setDeleteResWH(int deleteResWH) { 139 | this.deleteResWH = HHDensityUtils.dip2px(getContext(), deleteResWH); 140 | return this; 141 | } 142 | 143 | /** 144 | * @param deleteResMargin 设置删除按钮 Margin 145 | * @return 146 | */ 147 | public UploadMultiImageView setDeleteResMargin(int deleteResMargin) { 148 | this.deleteResMargin = HHDensityUtils.dip2px(getContext(), deleteResMargin); 149 | return this; 150 | } 151 | 152 | /** 153 | * @param addRes 设置新增按钮 154 | */ 155 | public UploadMultiImageView setAddRes(int addRes) { 156 | this.addRes = addRes; 157 | return this; 158 | } 159 | 160 | /** 161 | * @param drag 是否开启拖拽排序 162 | */ 163 | public UploadMultiImageView setDrag(boolean drag) { 164 | isDrag = drag; 165 | return this; 166 | } 167 | 168 | /** 169 | * @param itemDecorationSize 间隔大小 170 | */ 171 | public UploadMultiImageView setItemDecorationSize(int itemDecorationSize) { 172 | this.itemDecorationSize = HHDensityUtils.dip2px(getContext(), itemDecorationSize); 173 | return this; 174 | } 175 | 176 | /** 177 | * @param showAdd 是否展示最后面的新增按钮 178 | */ 179 | public UploadMultiImageView setShowAdd(boolean showAdd) { 180 | isShowAdd = showAdd; 181 | return this; 182 | } 183 | 184 | /** 185 | * @param maxNumber 设置最大显示数量 186 | */ 187 | public UploadMultiImageView setMaxNumber(int maxNumber) { 188 | this.maxNumber = maxNumber; 189 | return this; 190 | } 191 | 192 | /** 193 | * @param showDelete 是否显示删除按钮 194 | */ 195 | public UploadMultiImageView setShowDelete(boolean showDelete) { 196 | isShowDelete = showDelete; 197 | return this; 198 | } 199 | 200 | /** 201 | * @param imageInfoList 设置数据 202 | */ 203 | public UploadMultiImageView setImageInfoList(List imageInfoList) { 204 | if (imageInfoList != null) { 205 | this.imageInfoList = imageInfoList; 206 | } 207 | return this; 208 | } 209 | 210 | /** 211 | * @param imageViewLoader 图片加载 212 | */ 213 | public UploadMultiImageView setImageViewLoader(ImageViewLoader imageViewLoader) { 214 | this.imageViewLoader = imageViewLoader; 215 | return this; 216 | } 217 | 218 | /** 219 | * @param imageItemClickListener 图片点击 220 | */ 221 | public UploadMultiImageView setImageItemClickListener(ImageItemClickListener imageItemClickListener) { 222 | this.imageItemClickListener = imageItemClickListener; 223 | return this; 224 | } 225 | 226 | /** 227 | * @param addClickListener 新增按钮点击 228 | */ 229 | public UploadMultiImageView setAddClickListener(ImageAddClickListener addClickListener) { 230 | this.addClickListener = addClickListener; 231 | return this; 232 | } 233 | 234 | /** 235 | * 删除点击回调 236 | * 237 | * @param deleteClickListener 238 | * @return 239 | */ 240 | public UploadMultiImageView setDeleteClickListener(ImageDeleteClickListener deleteClickListener) { 241 | this.deleteClickListener = deleteClickListener; 242 | return this; 243 | } 244 | 245 | /** 246 | * 设置图片缩放类型 247 | * 248 | * @param scaleType 249 | * @return 250 | */ 251 | public UploadMultiImageView setScaleType(ImageView.ScaleType scaleType) { 252 | this.scaleType = scaleType; 253 | return this; 254 | } 255 | 256 | public void show() { 257 | if (isDrag) { 258 | itemTouchHelper.attachToRecyclerView(this); 259 | } 260 | addItemDecoration(); 261 | addViewData(); 262 | this.setLayoutManager(new GridLayoutManager(getContext(), columns)); 263 | this.post(new Runnable() { 264 | @Override 265 | public void run() { 266 | itemViewWidth = (getMeasuredWidth() - (columns + 1) * itemDecorationSize) / columns; 267 | uploadImageAdapter = new UploadImageAdapter(getContext(), imageInfoList); 268 | setAdapter(uploadImageAdapter); 269 | } 270 | }); 271 | } 272 | 273 | /** 274 | * 添加新数据 275 | */ 276 | public void addNewData(List data) { 277 | if (data != null && data.size() > 0) { 278 | // 如果有新增按钮,先移除,再添加 279 | removeViewData(); 280 | imageInfoList.addAll(data); 281 | addViewData(); 282 | if (uploadImageAdapter != null) { 283 | uploadImageAdapter.notifyDataSetChanged(); 284 | } 285 | } 286 | } 287 | 288 | /** 289 | * 刷新数据 290 | */ 291 | public void notifyDataSetChanged() { 292 | if (uploadImageAdapter != null) { 293 | uploadImageAdapter.notifyDataSetChanged(); 294 | } 295 | } 296 | 297 | /** 298 | * 删除指定item 299 | * 300 | * @param position 301 | */ 302 | public void deleteItem(int position) { 303 | if (position >= 0 && position < imageInfoList.size()) { 304 | imageInfoList.remove(position); 305 | addViewData(); 306 | uploadImageAdapter.notifyDataSetChanged(); 307 | } 308 | } 309 | 310 | /** 311 | * 获取数据 312 | */ 313 | public List getImageInfoList() { 314 | if (isShowAdd && imageInfoList.size() > 0 && imageInfoList.get(imageInfoList.size() - 1).isLastAddViewData()) { 315 | // 最后一个是新增按钮,删掉 316 | List list = new ArrayList<>(imageInfoList); 317 | list.remove(imageInfoList.size() - 1); 318 | return list; 319 | } else { 320 | return imageInfoList; 321 | } 322 | } 323 | 324 | /** 325 | * 添加间隔 326 | */ 327 | private void addItemDecoration() { 328 | if (itemDecorationSize > 0) { 329 | this.addItemDecoration(new ItemDecoration() { 330 | @Override 331 | public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull State state) { 332 | super.getItemOffsets(outRect, view, parent, state); 333 | int posi = parent.getChildAdapterPosition(view); 334 | int itemPad = itemDecorationSize; 335 | boolean isLastRaw = isLastRaw(posi, columns, imageInfoList.size()); 336 | if (isFirstColum(posi, columns)) { // 第一列 337 | if (isLastRaw) { 338 | // 最后一行 339 | outRect.set(itemPad, itemPad, itemPad / 2, itemPad); 340 | } else { 341 | outRect.set(itemPad, itemPad, itemPad / 2, 0); 342 | } 343 | } else if (isLastColum(posi, columns)) { // 最后一列 344 | if (isLastRaw) { 345 | // 最后一行 346 | outRect.set(itemPad / 2, itemPad, itemPad, itemPad); 347 | } else { 348 | outRect.set(itemPad / 2, itemPad, itemPad, 0); 349 | } 350 | } else { 351 | // 中间列 352 | if (isLastRaw) { 353 | outRect.set(itemPad / 2, itemPad, itemPad / 2, itemPad); 354 | } else { 355 | outRect.set(itemPad / 2, itemPad, itemPad / 2, 0); 356 | } 357 | } 358 | } 359 | }); 360 | } 361 | } 362 | 363 | /** 364 | * 添加新增按钮 365 | */ 366 | private void addViewData() { 367 | if (isShowAdd && maxNumber > imageInfoList.size()) { 368 | if (imageInfoList.size() == 0 || !imageInfoList.get(imageInfoList.size() - 1).isLastAddViewData()) { 369 | AddBean bean = new AddBean(); 370 | bean.setAddPath(addRes); 371 | bean.setAdd(true); 372 | imageInfoList.add(bean); 373 | } 374 | } 375 | if (maxNumber > 0 && maxNumber < imageInfoList.size()) { // 超出最大显示值,直接截取 376 | imageInfoList = imageInfoList.subList(0, maxNumber); 377 | } 378 | } 379 | 380 | /** 381 | * 移除新增按钮 382 | */ 383 | private void removeViewData() { 384 | if (isShowAdd && imageInfoList.size() > 0 && imageInfoList.get(imageInfoList.size() - 1).isLastAddViewData()) { 385 | imageInfoList.remove(imageInfoList.size() - 1); 386 | } 387 | } 388 | 389 | /** 390 | * 是否是最后一列 391 | */ 392 | private boolean isLastColum(int pos, int spanCount) { 393 | return (pos + 1) % spanCount == 0; 394 | } 395 | 396 | /** 397 | * 是否是第一列 398 | */ 399 | private boolean isFirstColum(int pos, int spanCount) { 400 | return (pos + 1) % spanCount == 1; 401 | } 402 | 403 | /** 404 | * 是否是最后一行 405 | */ 406 | private boolean isLastRaw(int pos, int spanCount, int childCount) { 407 | int ys = childCount % spanCount; 408 | boolean isLastRaw; 409 | if (ys > 0) { 410 | isLastRaw = (pos >= childCount - ys); 411 | } else { 412 | isLastRaw = (pos >= childCount - spanCount); 413 | } 414 | return isLastRaw; 415 | } 416 | 417 | /** 418 | * adapter 419 | */ 420 | private class UploadImageAdapter extends RecyclerView.Adapter { 421 | 422 | private ViewGroup.LayoutParams layoutParams; 423 | 424 | private FrameLayout.LayoutParams deleteViewParams; 425 | 426 | private Context context; 427 | 428 | private List data; 429 | 430 | public UploadImageAdapter(Context context, List data) { 431 | this.context = context; 432 | this.data = data; 433 | layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, imgHeight <= 0 ? itemViewWidth : imgHeight); 434 | deleteViewParams = new FrameLayout.LayoutParams(deleteResWH, deleteResWH); 435 | deleteViewParams.topMargin = deleteResMargin; 436 | deleteViewParams.rightMargin = deleteResMargin; 437 | deleteViewParams.gravity = Gravity.END; 438 | } 439 | 440 | @NonNull 441 | @Override 442 | public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 443 | return new MyViewHolder(View.inflate(context, R.layout.item_def, null)); 444 | } 445 | 446 | 447 | @Override 448 | public int getItemCount() { 449 | return data == null ? 0 : data.size(); 450 | } 451 | 452 | @Override 453 | public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { 454 | ImageInfo imageInfo = data.get(position); 455 | holder.frameLayout.setLayoutParams(layoutParams); 456 | holder.deleteImage.setImageResource(deleteRes); 457 | holder.deleteImage.setVisibility(isShowDelete && !imageInfo.isLastAddViewData() ? VISIBLE : GONE); 458 | holder.deleteImage.setLayoutParams(deleteViewParams); 459 | holder.imageView.setScaleType(scaleType); 460 | if (imageInfo.isLastAddViewData()) { 461 | holder.imageView.setImageResource(addRes); 462 | } else { 463 | if (imageViewLoader != null) { 464 | imageViewLoader.displayImage(getContext(), imageInfo.getImagePath(), holder.imageView); 465 | } 466 | holder.deleteImage.setOnClickListener(new MyClick(position)); 467 | } 468 | holder.imageView.setOnClickListener(new MyClick(position)); 469 | } 470 | 471 | private class MyClick implements OnClickListener { 472 | private int position; 473 | 474 | public MyClick(int position) { 475 | this.position = position; 476 | } 477 | 478 | @Override 479 | public void onClick(View v) { 480 | int id = v.getId(); 481 | if (id == R.id.iv_item) { 482 | if (data.get(position).isLastAddViewData() && addClickListener != null) { 483 | addClickListener.ImageAddClick(); 484 | } else if (imageItemClickListener != null) { 485 | imageItemClickListener.ImageItemClick(position); 486 | } 487 | } else if (id == R.id.iv_delete) { 488 | if (deleteClickListener != null) { 489 | deleteClickListener.ImageDeleteClick(UploadMultiImageView.this, position); 490 | } else { 491 | deleteItem(position); 492 | } 493 | } 494 | } 495 | } 496 | 497 | private class MyViewHolder extends ViewHolder { 498 | private ImageView imageView; 499 | private ImageView deleteImage; 500 | private FrameLayout frameLayout; 501 | 502 | public MyViewHolder(@NonNull View baseViewHolder) { 503 | super(baseViewHolder); 504 | frameLayout = baseViewHolder.findViewById(R.id.fl_layout); 505 | imageView = baseViewHolder.findViewById(R.id.iv_item); 506 | deleteImage = baseViewHolder.findViewById(R.id.iv_delete); 507 | } 508 | } 509 | } 510 | 511 | /** 512 | * 拖拽排序 513 | */ 514 | private class ItemDragTouchCallback extends ItemTouchHelper.Callback { 515 | @Override 516 | public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { 517 | int dragFlags = 0; 518 | int position = viewHolder.getAdapterPosition(); 519 | if (isDrag && (!isShowAdd || !imageInfoList.get(position).isLastAddViewData())) { 520 | dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT; 521 | } 522 | return makeMovementFlags(dragFlags, 0); 523 | } 524 | 525 | /** 526 | * 针对drag状态,当前target对应的item是否允许移动 527 | * 我们一般用drag来做一些换位置的操作,就是当前对应的target对应的Item可以移动 528 | */ 529 | @Override 530 | public boolean canDropOver(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) { 531 | //得到当拖拽的viewHolder的Position 532 | int fromPosition = viewHolder.getAdapterPosition(); 533 | //拿到当前拖拽到的item的viewHolder 534 | int toPosition = target.getAdapterPosition(); 535 | // 当存在新增按钮时,当前和目标值,不能是最后一个新增按钮 536 | return !isShowAdd || (!imageInfoList.get(fromPosition).isLastAddViewData() && !imageInfoList.get(toPosition).isLastAddViewData()); 537 | } 538 | 539 | @Override 540 | public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) { 541 | //得到当拖拽的viewHolder的Position 542 | int fromPosition = viewHolder.getAdapterPosition(); 543 | //拿到当前拖拽到的item的viewHolder 544 | int toPosition = target.getAdapterPosition(); 545 | if (fromPosition < toPosition) { 546 | for (int i = fromPosition; i < toPosition; i++) { 547 | Collections.swap(imageInfoList, i, i + 1); 548 | } 549 | } else { 550 | for (int i = fromPosition; i > toPosition; i--) { 551 | Collections.swap(imageInfoList, i, i - 1); 552 | } 553 | } 554 | uploadImageAdapter.notifyItemMoved(fromPosition, toPosition); 555 | return true; 556 | } 557 | 558 | /** 559 | * 针对swipe状态,是否允许swipe(滑动)操作 560 | */ 561 | public boolean isItemViewSwipeEnabled() { 562 | return false; 563 | } 564 | 565 | @Override 566 | public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { 567 | } 568 | 569 | @Override 570 | public boolean isLongPressDragEnabled() { 571 | return true; 572 | } 573 | 574 | @Override 575 | public void onSelectedChanged(@Nullable ViewHolder viewHolder, int actionState) { 576 | if (viewHolder != null && actionState != ItemTouchHelper.ACTION_STATE_IDLE) { 577 | int position = viewHolder.getAdapterPosition(); 578 | if (isDrag && (!isShowAdd || !imageInfoList.get(position).isLastAddViewData())) { 579 | AnimatorSet animatorSet = new AnimatorSet(); 580 | ObjectAnimator animatorScaleX = 581 | ObjectAnimator.ofFloat(viewHolder.itemView, "ScaleX", 1.0f, 0.85f); 582 | ObjectAnimator animatorScaleY = 583 | ObjectAnimator.ofFloat(viewHolder.itemView, "ScaleY", 1.0f, 0.85f); 584 | animatorSet.playTogether(animatorScaleX, animatorScaleY); 585 | animatorSet.setDuration(200L); 586 | animatorSet.start(); 587 | } 588 | } 589 | super.onSelectedChanged(viewHolder, actionState); 590 | } 591 | 592 | @Override 593 | public void clearView(@NonNull RecyclerView recyclerView, @NonNull ViewHolder viewHolder) { 594 | int position = viewHolder.getAdapterPosition(); 595 | if (isDrag && (!isShowAdd || !imageInfoList.get(position).isLastAddViewData())) { 596 | AnimatorSet animatorSet = new AnimatorSet(); 597 | ObjectAnimator animatorScaleX = 598 | ObjectAnimator.ofFloat(viewHolder.itemView, "ScaleX", 0.85f, 1.0f); 599 | ObjectAnimator animatorScaleY = 600 | ObjectAnimator.ofFloat(viewHolder.itemView, "ScaleY", 0.85f, 1.0f); 601 | animatorSet.playTogether(animatorScaleX, animatorScaleY); 602 | animatorSet.setDuration(100L); 603 | animatorSet.start(); 604 | } 605 | super.clearView(recyclerView, viewHolder); 606 | } 607 | } 608 | } 609 | --------------------------------------------------------------------------------