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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@
buildscript {
repositories {
jcenter()
maven { url "https://jitpack.io" }
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.android.tools.build:gradle:3.4.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

plugins {
id "com.jfrog.bintray" version "1.7"
}

allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}

Expand Down
26 changes: 14 additions & 12 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
compileSdkVersion 28

defaultConfig {
applicationId "me.shaohui.advancedluban"
minSdkVersion 15
targetSdkVersion 24
minSdkVersion 18
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -29,12 +29,14 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile project(':library')
compile 'com.github.lovetuzitong:MultiImageSelector:1.2'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testImplementation 'junit:junit:4.12'


implementation project(':library')
// 图片选择器
implementation 'com.github.lovetuzitong:MultiImageSelector:1.2'
}
26 changes: 13 additions & 13 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.shaohui.advancedlubanexample"
>
xmlns:tools="http://schemas.android.com/tools"
package="me.shaohui.advancedlubanexample">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
>
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:configChanges="orientation|screenSize"
android:name="me.nereo.multi_image_selector.MultiImageSelectorActivity" />
android:name="me.nereo.multi_image_selector.MultiImageSelectorActivity"
android:configChanges="orientation|screenSize" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.shaohui.advancedlubanexample;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
Expand All @@ -13,13 +14,16 @@
import java.util.ArrayList;
import java.util.List;

import io.reactivex.functions.Consumer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import me.nereo.multi_image_selector.MultiImageSelector;
import me.nereo.multi_image_selector.MultiImageSelectorActivity;
import me.shaohui.advancedluban.Luban;
import me.shaohui.advancedluban.OnCompressListener;
import me.shaohui.advancedluban.OnMultiCompressListener;


@SuppressLint("CheckResult")
public class MainActivity extends AppCompatActivity {

private static final String TAG = "LubanExample";
Expand Down Expand Up @@ -108,19 +112,23 @@ private void compressSingleRxJava(int gear) {
if (mFileList.isEmpty()) {
return;
}

printfFileInfo("压缩前", mFileList.get(0));
Luban.compress(mFileList.get(0), getFilesDir())
.putGear(gear)
.ignoreBy(500)
.asObservable()
.subscribe(new Consumer<File>() {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new io.reactivex.functions.Consumer<File>() {
@Override
public void accept(File file) throws Exception {
public void accept(File file) {
printfFileInfo("压缩后", file);
Log.i("TAG", file.getAbsolutePath());
mImageViews.get(0).setImageURI(Uri.fromFile(file));
}
}, new Consumer<Throwable>() {
}, new io.reactivex.functions.Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
public void accept(Throwable throwable) {
throwable.printStackTrace();
}
});
Expand All @@ -130,29 +138,41 @@ private void compressMultiRxJava(int gear) {
if (mFileList.isEmpty()) {
return;
}
printfFileInfo("压缩前", mFileList);
Luban.compress(this, mFileList)
.putGear(gear)
.ignoreBy(500)
.asListObservable()
.subscribe(new Consumer<List<File>>() {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new io.reactivex.functions.Consumer<List<File>>() {
@Override
public void accept(List<File> files) throws Exception {
public void accept(List<File> files) {
printfFileInfo("压缩后", files);
int size = files.size();
while (size-- > 0) {
mImageViews.get(size).setImageURI(Uri.fromFile(files.get(size)));
}
}
}, new Consumer<Throwable>() {
}, new io.reactivex.functions.Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
public void accept(Throwable throwable) {
throwable.printStackTrace();
}
});
}

/**
* 单张图片压缩
*
* @param gear
*/
private void compressSingleListener(int gear) {
if (mFileList.isEmpty()) {
return;
}
printfFileInfo("压缩前", mFileList.get(0));

Luban.compress(mFileList.get(0), getFilesDir())
.putGear(gear)
.launch(new OnCompressListener() {
Expand All @@ -164,6 +184,7 @@ public void onStart() {
@Override
public void onSuccess(File file) {
Log.i("TAG", file.getAbsolutePath());
printfFileInfo("压缩后", file);
mImageViews.get(0).setImageURI(Uri.fromFile(file));
}

Expand All @@ -178,6 +199,7 @@ private void compressMultiListener(int gear) {
if (mFileList.isEmpty()) {
return;
}
printfFileInfo("压缩前", mFileList);
Luban.compress(this, mFileList)
.putGear(gear)
.launch(new OnMultiCompressListener() {
Expand All @@ -188,6 +210,7 @@ public void onStart() {

@Override
public void onSuccess(List<File> fileList) {
printfFileInfo("压缩后", fileList);
int size = fileList.size();
while (size-- > 0) {
mImageViews.get(size).setImageURI(Uri.fromFile(fileList.get(size)));
Expand All @@ -201,17 +224,28 @@ public void onError(Throwable e) {
});
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE && data != null) {
mFileList.clear();
List<String> path = data
.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT);
List<String> path = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT);
for (String str : path) {
mFileList.add(new File(str));
}
}

super.onActivityResult(requestCode, resultCode, data);
}

private void printfFileInfo(String prefix, File file) {
Log.e(TAG, prefix + "FilePath:" + file.getAbsolutePath());
Log.e(TAG, prefix + "FileSize:" + (file.length() / 1024));
}

private void printfFileInfo(String prefix, List<File> files) {
for (int i = 0; i < files.size(); i++) {
Log.e(TAG, prefix + "FilePath:" + files.get(i).getAbsolutePath());
Log.e(TAG, prefix + "FileSize:" + (files.get(i).length() / 1024));
}
}
}
Loading