├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── nemocdz │ │ │ └── imagecompress │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── nemocdz │ │ └── imagecompress │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── README.md ├── imagecompress ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── nemocdz │ │ │ └── imagecompress │ │ │ └── ImageCompress.kt │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── nemocdz │ │ │ └── imagecompress │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── nemocdz │ │ └── imagecompress │ │ └── ExampleInstrumentedTest.java ├── .idea │ └── modules.xml ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── vcs.xml ├── modules.xml ├── runConfigurations.xml └── misc.xml ├── gradle.properties ├── LICENSE ├── .gitignore ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ImageCompress-Android -------------------------------------------------------------------------------- /imagecompress/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':imagecompress' 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ImageCompress 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nemocdz/ImageCompress-Android/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /imagecompress/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ImageCompress 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nemocdz/ImageCompress-Android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nemocdz/ImageCompress-Android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nemocdz/ImageCompress-Android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nemocdz/ImageCompress-Android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nemocdz/ImageCompress-Android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nemocdz/ImageCompress-Android/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/Nemocdz/ImageCompress-Android/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/Nemocdz/ImageCompress-Android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /imagecompress/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nemocdz/ImageCompress-Android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nemocdz/ImageCompress-Android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jan 15 15:11:58 CST 2019 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-4.10.1-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 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/nemocdz/imagecompress/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.nemocdz.imagecompress 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 | -------------------------------------------------------------------------------- /imagecompress/src/test/java/com/nemocdz/imagecompress/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.nemocdz.imagecompress; 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 | } -------------------------------------------------------------------------------- /imagecompress/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/nemocdz/imagecompress/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.nemocdz.imagecompress 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.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.getTargetContext() 22 | assertEquals("com.nemocdz.imagecompress", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /imagecompress/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 | -------------------------------------------------------------------------------- /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 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | 19 | 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /imagecompress/src/androidTest/java/com/nemocdz/imagecompress/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.nemocdz.imagecompress; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.nemocdz.imagecompress.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 DanziChen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 28 9 | defaultConfig { 10 | applicationId "com.nemocdz.imagecompress" 11 | minSdkVersion 19 12 | targetSdkVersion 28 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 28 | implementation 'com.android.support:appcompat-v7:28.0.0' 29 | testImplementation 'junit:junit:4.12' 30 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 31 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 32 | } 33 | -------------------------------------------------------------------------------- /imagecompress/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion 28 6 | 7 | 8 | 9 | defaultConfig { 10 | minSdkVersion 19 11 | targetSdkVersion 28 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation 'com.android.support:appcompat-v7:28.0.0' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 34 | api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 35 | api 'com.github.bumptech.glide:glide:4.8.0' 36 | api 'com.github.bumptech.glide:gifencoder-integration:4.8.0' 37 | } 38 | repositories { 39 | mavenCentral() 40 | } 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # IntelliJ 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/assetWizardSettings.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | .idea/caches 44 | 45 | # Keystore files 46 | # Uncomment the following line if you do not want to check your keystore files in. 47 | #*.jks 48 | 49 | # External native build folder generated in Android Studio 2.2 and later 50 | .externalNativeBuild 51 | 52 | # Google Services (e.g. APIs or Firebase) 53 | google-services.json 54 | 55 | # Freeline 56 | freeline.py 57 | freeline/ 58 | freeline_project_description.json 59 | 60 | # fastlane 61 | fastlane/report.xml 62 | fastlane/Preview.html 63 | fastlane/screenshots 64 | fastlane/test_output 65 | fastlane/readme.md 66 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | 35 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 37 | 38 | 39 | 40 | 41 | 42 | 44 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /imagecompress/src/main/java/com/nemocdz/imagecompress/ImageCompress.kt: -------------------------------------------------------------------------------- 1 | package com.nemocdz.imagecompress 2 | 3 | import android.content.Context 4 | import android.graphics.Bitmap 5 | import android.graphics.BitmapFactory 6 | import com.bumptech.glide.Glide 7 | import com.bumptech.glide.gifdecoder.GifHeaderParser 8 | import com.bumptech.glide.gifdecoder.StandardGifDecoder 9 | import com.bumptech.glide.gifencoder.AnimatedGifEncoder 10 | import com.bumptech.glide.load.resource.gif.GifBitmapProvider 11 | import java.io.* 12 | import kotlin.math.max 13 | import kotlin.math.min 14 | 15 | object ImageCompress { 16 | /** 17 | * 返回同步压缩图片 Byte 数据 [rawData] 的长边到 [limitLongWidth] 后的 Byte 数据,Gif 目标长边最大压缩到 512,超过用 512 18 | */ 19 | fun compressImageDataWithLongWidth(context: Context, rawData: ByteArray, limitLongWidth: Int): ByteArray? { 20 | val format = rawData.imageFormat() 21 | if (format == ImageFormat.UNKNOWN) { 22 | return null 23 | } 24 | 25 | val (imageWidth, imageHeight) = rawData.imageSize() 26 | val longSideWidth = max(imageWidth, imageHeight) 27 | 28 | if (longSideWidth <= limitLongWidth) { 29 | return rawData 30 | } 31 | 32 | if (format == ImageFormat.GIF) { 33 | // 压缩 Gif 分辨率太大编码时容易崩溃 34 | return compressGifDataWithLongWidth(context, rawData, max(512, longSideWidth)) 35 | } else { 36 | val image = BitmapFactory.decodeByteArray(rawData, 0, rawData.size) 37 | val ratio = limitLongWidth.toDouble() / longSideWidth.toDouble() 38 | val resizeImageFrame = Bitmap.createScaledBitmap( 39 | image, 40 | (image.width.toDouble() * ratio).toInt(), 41 | (image.height.toDouble() * ratio).toInt(), 42 | true 43 | ) 44 | image.recycle() 45 | var resultData: ByteArray? = null 46 | when (format) { 47 | ImageFormat.PNG -> { 48 | resultData = resizeImageFrame.toByteArray(Bitmap.CompressFormat.PNG) 49 | } 50 | ImageFormat.JPG -> { 51 | resultData = resizeImageFrame.toByteArray(Bitmap.CompressFormat.JPEG) 52 | } 53 | else -> { 54 | } 55 | } 56 | resizeImageFrame.recycle() 57 | return resultData 58 | } 59 | } 60 | 61 | 62 | /** 63 | * 返回同步压缩图片 Byte 数据 [rawData] 的数据大小到 [limitDataSize] 后的 Byte 数据 64 | */ 65 | fun compressImageDataWithSize(context: Context, rawData: ByteArray, limitDataSize: Int): ByteArray? { 66 | if (rawData.size <= limitDataSize) { 67 | return rawData 68 | } 69 | 70 | val format = rawData.imageFormat() 71 | if (format == ImageFormat.UNKNOWN) { 72 | return null 73 | } 74 | 75 | var resultData = rawData 76 | 77 | // 若是 JPG,先用压缩系数压缩 6 次,二分法 78 | if (format == ImageFormat.JPG) { 79 | var compression = 100 80 | var maxCompression = 100 81 | var minCompression = 0 82 | 83 | try { 84 | val outputStream = ByteArrayOutputStream() 85 | for (index in 0..6) { 86 | compression = (maxCompression + minCompression) / 2 87 | outputStream.reset() 88 | val image = BitmapFactory.decodeByteArray(rawData, 0, rawData.size) 89 | image.compress(Bitmap.CompressFormat.JPEG, compression, outputStream) 90 | image.recycle() 91 | resultData = outputStream.toByteArray() 92 | if (resultData.size < (limitDataSize.toDouble() * 0.9).toInt()) { 93 | minCompression = compression 94 | } else if (resultData.size > limitDataSize) { 95 | maxCompression = compression 96 | } else { 97 | break 98 | } 99 | } 100 | outputStream.close() 101 | } catch (e: IOException) { 102 | e.printStackTrace() 103 | } 104 | 105 | if (resultData.size <= limitDataSize) { 106 | return resultData 107 | } 108 | } 109 | 110 | // 若是 GIF,先用抽帧减少大小 111 | if (format == ImageFormat.GIF) { 112 | val sampleCount = resultData.fitSampleCount() 113 | val data = compressGifDataWithSampleCount(context, resultData, sampleCount) 114 | if (data != null) { 115 | resultData = data 116 | } else { 117 | return null 118 | } 119 | 120 | if (resultData.size <= limitDataSize) { 121 | return resultData 122 | } 123 | } 124 | 125 | 126 | val (imageWidth, imageHeight) = resultData.imageSize() 127 | var longSideWidth = max(imageWidth, imageHeight) 128 | 129 | // 图片尺寸按比率缩小,比率按字节比例逼近 130 | while (resultData.size > limitDataSize) { 131 | val ratio = Math.sqrt(limitDataSize.toDouble() / resultData.size.toDouble()) 132 | longSideWidth = (longSideWidth.toDouble() * ratio).toInt() 133 | val data = compressImageDataWithLongWidth(context, resultData, longSideWidth) 134 | if (data != null) { 135 | resultData = data 136 | } else { 137 | return null 138 | } 139 | } 140 | 141 | return resultData 142 | } 143 | 144 | 145 | /** 146 | * 返回同步压缩 gif 图片 Byte 数据 [rawData] 每一帧长边到 [limitLongWidth] 后的 Byte 数据 147 | */ 148 | private fun compressGifDataWithLongWidth(context: Context, rawData: ByteArray, limitLongWidth: Int): ByteArray? { 149 | val gifDecoder = StandardGifDecoder(GifBitmapProvider(Glide.get(context).bitmapPool)) 150 | val headerParser = GifHeaderParser() 151 | headerParser.setData(rawData) 152 | val header = headerParser.parseHeader() 153 | gifDecoder.setData(header, rawData) 154 | val frameCount = gifDecoder.frameCount 155 | 156 | // 计算帧的间隔 157 | val frameDurations = (0..(frameCount - 1)).map { gifDecoder.getDelay(it) } 158 | 159 | // 计算调整后大小 160 | val longSideWidth = max(header.width, header.height) 161 | val ratio = limitLongWidth.toFloat() / longSideWidth.toFloat() 162 | val resizeWidth = (header.width.toFloat() * ratio).toInt() 163 | val resizeHeight = (header.height.toFloat() * ratio).toInt() 164 | 165 | // 每一帧进行缩放 166 | val resizeImageFrames = (0 until frameCount).mapNotNull { 167 | gifDecoder.advance() 168 | var imageFrame = gifDecoder.nextFrame 169 | if (imageFrame != null) { 170 | imageFrame = Bitmap.createScaledBitmap(imageFrame, resizeWidth, resizeHeight, true) 171 | } 172 | imageFrame 173 | } 174 | 175 | val gifEncoder = AnimatedGifEncoder() 176 | var resultData: ByteArray? = null 177 | 178 | try { 179 | val outputStream = ByteArrayOutputStream() 180 | gifEncoder.start(outputStream) 181 | gifEncoder.setRepeat(0) 182 | 183 | // 每一帧都进行重新编码 184 | resizeImageFrames.zip(frameDurations).forEach { 185 | // 设置帧间隔 186 | gifEncoder.setDelay(it.second) 187 | gifEncoder.addFrame(it.first) 188 | it.first.recycle() 189 | } 190 | 191 | gifEncoder.finish() 192 | 193 | resultData = outputStream.toByteArray() 194 | outputStream.close() 195 | return resultData 196 | } catch (e: IOException) { 197 | e.printStackTrace() 198 | } 199 | return resultData 200 | } 201 | 202 | /** 203 | * 返回同步压缩 gif 图片 Byte 数据 [rawData] 的按 [sampleCount] 采样后的 Byte 数据 204 | */ 205 | private fun compressGifDataWithSampleCount(context: Context, rawData: ByteArray, sampleCount: Int): ByteArray? { 206 | if (sampleCount <= 1) { 207 | return rawData 208 | } 209 | val gifDecoder = StandardGifDecoder(GifBitmapProvider(Glide.get(context).bitmapPool)) 210 | val headerParser = GifHeaderParser() 211 | headerParser.setData(rawData) 212 | val header = headerParser.parseHeader() 213 | gifDecoder.setData(header, rawData) 214 | 215 | val frameCount = gifDecoder.frameCount 216 | 217 | // 计算帧的间隔 218 | val frameDurations = (0 until frameCount).map { gifDecoder.getDelay(it) } 219 | 220 | // 合并帧的时间,最长不可高于 200ms 221 | val mergeFrameDurations = (0 until frameCount).filter { it % sampleCount == 0 }.map { 222 | min( 223 | frameDurations.subList( 224 | it, 225 | min(it + sampleCount, frameCount) 226 | ).fold(0) { acc, duration -> acc + duration }, 200 227 | ) 228 | } 229 | 230 | // 抽取帧 231 | val sampleImageFrames = (0 until frameCount).mapNotNull { 232 | gifDecoder.advance() 233 | var imageFrame: Bitmap? = null 234 | if (it % sampleCount == 0) { 235 | imageFrame = gifDecoder.nextFrame 236 | } 237 | imageFrame 238 | } 239 | 240 | val gifEncoder = AnimatedGifEncoder() 241 | 242 | var resultData: ByteArray? = null 243 | 244 | try { 245 | val outputStream = ByteArrayOutputStream() 246 | gifEncoder.start(outputStream) 247 | gifEncoder.setRepeat(0) 248 | 249 | // 每一帧图片都进行重新编码 250 | sampleImageFrames.zip(mergeFrameDurations).forEach { 251 | // 设置帧间隔 252 | gifEncoder.setDelay(it.second) 253 | gifEncoder.addFrame(it.first) 254 | it.first.recycle() 255 | } 256 | gifEncoder.finish() 257 | 258 | resultData = outputStream.toByteArray() 259 | outputStream.close() 260 | } catch (e: IOException) { 261 | e.printStackTrace() 262 | } 263 | 264 | return resultData 265 | } 266 | } 267 | 268 | fun ByteArray.imageFormat(): ImageFormat { 269 | val headerData = this.slice(0..2) 270 | val hexString = 271 | headerData.fold(StringBuilder("")) { result, byte -> result.append((byte.toInt() and 0xFF).toString(16)) } 272 | .toString().toUpperCase() 273 | var imageFormat = ImageFormat.UNKNOWN 274 | when (hexString) { 275 | "FFD8FF" -> { 276 | imageFormat = ImageFormat.JPG 277 | } 278 | "89504E" -> { 279 | imageFormat = ImageFormat.PNG 280 | } 281 | "474946" -> { 282 | imageFormat = ImageFormat.GIF 283 | } 284 | } 285 | return imageFormat 286 | } 287 | 288 | 289 | fun Bitmap.toByteArray(format: Bitmap.CompressFormat): ByteArray? { 290 | var data: ByteArray? = null 291 | try { 292 | val outputStream = ByteArrayOutputStream() 293 | this.compress(format, 100, outputStream) 294 | data = outputStream.toByteArray() 295 | outputStream.close() 296 | return data 297 | } catch (e: IOException) { 298 | e.printStackTrace() 299 | } 300 | return data 301 | } 302 | 303 | private fun ByteArray.imageSize(): Pair { 304 | var imageWidth = 0 305 | var imageHeight = 0 306 | 307 | if (this.imageFormat() == ImageFormat.GIF) { 308 | val headerParser = GifHeaderParser() 309 | headerParser.setData(this) 310 | val header = headerParser.parseHeader() 311 | imageWidth = header.width 312 | imageHeight = header.height 313 | } else { 314 | try { 315 | val imageFrame = BitmapFactory.decodeByteArray(this, 0, this.size) 316 | imageWidth = imageFrame.width 317 | imageHeight = imageFrame.height 318 | imageFrame.recycle() 319 | } catch (e: Throwable) { 320 | e.printStackTrace() 321 | } 322 | } 323 | return Pair(imageWidth, imageHeight) 324 | } 325 | 326 | private fun ByteArray.fitSampleCount(): Int { 327 | val headerParser = GifHeaderParser() 328 | headerParser.setData(this) 329 | val header = headerParser.parseHeader() 330 | val frameCount = header.numFrames 331 | var sampleCount = 2 332 | when (frameCount) { 333 | in 0..7 -> { 334 | sampleCount = 2 335 | } 336 | in 8..19 -> { 337 | sampleCount = 3 338 | } 339 | in 20..29 -> { 340 | sampleCount = 4 341 | } 342 | in 30..39 -> { 343 | sampleCount = 5 344 | } 345 | else -> { 346 | sampleCount = 6 347 | } 348 | } 349 | return sampleCount 350 | } 351 | 352 | enum class ImageFormat { 353 | JPG, PNG, GIF, UNKNOWN 354 | } 355 | 356 | 357 | --------------------------------------------------------------------------------