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
81 changes: 0 additions & 81 deletions app/build.gradle

This file was deleted.

1 change: 0 additions & 1 deletion app/release/output.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import com.baixiaohu.imagecompress.dialog.ExitDialog;
import com.baixiaohu.imagecompress.permission.imp.OnPermissionsResult;
import com.baixiaohu.imagecompress.toast.Toasts;
import com.bumptech.glide.Glide;
import com.squareup.haha.perflib.Main;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import com.baixiaohu.imagecompress.dialog.PhotoDialog;
import com.baixiaohu.imagecompress.permission.imp.OnPermissionsResult;
import com.baixiaohu.imagecompress.toast.Toasts;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.engine.impl.GlideEngine;
import com.example.media.MediaSelector;
import com.example.media.bean.MediaSelectorFile;
import com.example.media.resolver.Contast;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -121,14 +121,7 @@ public void onClickCancel(View view) {
}

protected void openZhiHuAlbum() {
Matisse.from(this)
.choose(MimeType.ofImage())
.countable(true)
.maxSelectable(9)
.restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
.thumbnailScale(0.85f)
.imageEngine(new GlideEngine())
.forResult(REQUEST_CODE_CHOOSE);
MediaSelector.with(this).openMediaActivity();
}

@Override
Expand Down Expand Up @@ -163,16 +156,16 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
imageFileResult(bean);

}
} else if (requestCode == REQUEST_CODE_CHOOSE) {
List<String> pathData = Matisse.obtainPathResult(data);
if (pathData == null || pathData.size() == 0)
}
break;
case Contast.CODE_RESULT_MEDIA:
if (requestCode == Contast.CODE_REQUEST_MEDIA) {
List<MediaSelectorFile> mediaData = MediaSelector.resultMediaFile(data);
if (mediaData == null || mediaData.size() == 0)
return;
List<ImageFileBean> imageFileBeanList = new ArrayList<>();
for (String path : pathData) {
if (path == null) {
return;
}
File file = new File(path);
for (MediaSelectorFile mediaSelectorFile : mediaData) {
File file = new File(mediaSelectorFile.filePath);
if (FileUtils.isImageFile(file)) {
ImageFileBean imageFileBean = new ImageFileBean();
imageFileBean.isImage = true;
Expand All @@ -185,6 +178,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
imageFilesResult(imageFileBeanList);
}
break;

default:
break;
}
Expand Down
89 changes: 57 additions & 32 deletions compress/src/main/java/utils/CompressPicker.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ImageDecoder;
import android.graphics.Matrix;
import android.graphics.drawable.AnimatedImageDrawable;
import android.media.ExifInterface;
import android.os.Build;
import android.support.annotation.NonNull;


Expand Down Expand Up @@ -41,43 +45,64 @@ public class CompressPicker {
* @param imageConfig bean
* @return 返回Bitmap
*/
public static Bitmap compressBitmap(ImageConfig imageConfig) {
public static Bitmap compressBitmap(final ImageConfig imageConfig) {
Bitmap bitmap = null;
if (null != imageConfig) {
CompressPicker.mImageConfig = imageConfig;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = imageConfig.config;
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imageConfig.imagePath, options);
options.inSampleSize = (int) ((options.outWidth * 1.0f) / (imageConfig.compressWidth * 1.0f) + (options.outHeight * 1.0f) / (imageConfig.compressHeight * 1.0f)) / 2;
options.inJustDecodeBounds = false;
options.inScaled = false;
options.inMutable = true;
bitmap = BitmapFactory.decodeFile(imageConfig.imagePath, options);
ExifInterface exif;
try {
exif = new ExifInterface(imageConfig.imagePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
Matrix matrix = new Matrix();
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
matrix.postRotate(90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
matrix.postRotate(180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
matrix.postRotate(270);
break;
default:
break;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ImageDecoder.Source source = ImageDecoder.createSource(new File(imageConfig.imagePath));
try {
bitmap = ImageDecoder.decodeBitmap(source, new ImageDecoder.OnHeaderDecodedListener() {
@Override
public void onHeaderDecoded(ImageDecoder decoder, ImageDecoder.ImageInfo info, ImageDecoder.Source source) {
decoder.setTargetSize(imageConfig.compressWidth, imageConfig.compressHeight);
decoder.setTargetSampleSize(150*1024);
decoder.setMutableRequired(true);
decoder.close();
}
});
} catch (IOException e) {
e.printStackTrace();
}
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
} catch (IOException e) {
e.printStackTrace();
return bitmap;
} else {
CompressPicker.mImageConfig = imageConfig;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = imageConfig.config;
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imageConfig.imagePath, options);
options.inSampleSize = (int) ((options.outWidth * 1.0f) / (imageConfig.compressWidth * 1.0f) + (options.outHeight * 1.0f) / (imageConfig.compressHeight * 1.0f)) / 2;
options.inJustDecodeBounds = false;
options.inScaled = false;
options.inMutable = true;
bitmap = BitmapFactory.decodeFile(imageConfig.imagePath, options);
}
if (bitmap != null) {
ExifInterface exif;
try {
exif = new ExifInterface(imageConfig.imagePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
Matrix matrix = new Matrix();
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
matrix.postRotate(90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
matrix.postRotate(180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
matrix.postRotate(270);
break;
default:
break;
}
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
} catch (IOException e) {
e.printStackTrace();
return bitmap;

}
}


}
return bitmap;
}
Expand Down
24 changes: 15 additions & 9 deletions config.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
ext {
android = [
compileSdkVersion: 27,
compileSdkVersion: 28,
minSdkVersion : 15,
targetSdkVersion : 27,
targetSdkVersion : 28,
versionCode : 1,
versionName : "1.0",
buildToolsVersion: "27.0.3"
buildToolsVersion: "28.0.0"
]

dependVersion = [
appcompat : "27.1.1",
appcompat : "28.0.0",
constraint : "1.0.2",
junit : "4.12",
runner : "1.0.1",
espresso : "3.0.1",
glide : "4.8.0",
design : "27.1.1",
design : "28.0.0",
PhotoView : "2.0.0",
multidex : "1.0.3",
leakcanaryAndroid : "1.6.1",
leakcanaryAndroidNoOp : "1.6.1",
leakcanarySupportFragment: "1.6.1",
supportV4 : "27.1.1",
supportV4 : "28.0.0",
rxjava : "2.0.0",
rxandroid : "2.0.0",
rxlifecycleComponents : "2.1.0",
recyclerview : "27.0.0",
recyclerview : "28.0.0",
imagezoom : "1.0.4",
picasso : "2.5.2"
picasso : "2.5.2",
projectview : "1.0.1",
eventbus : "3.1.1",
ucrop : "2.2.2"

]

Expand All @@ -50,7 +53,10 @@ ext {
rxlifecycleComponents : "com.trello.rxlifecycle2:rxlifecycle-components:${dependVersion.rxlifecycleComponents}",
recyclerview : "com.android.support:recyclerview-v7:${dependVersion.recyclerview}",
imagezoom : "it.sephiroth.android.library.imagezoom:library:${dependVersion.imagezoom}",
picasso : "com.squareup.picasso:picasso:${dependVersion.picasso}"
picasso : "com.squareup.picasso:picasso:${dependVersion.picasso}",
projectview : "com.github.Hu12037102:ProjectView:${dependVersion.projectview}",
eventbus : "org.greenrobot:eventbus:${dependVersion.eventbus}",
ucrop : "com.github.yalantis:ucrop:${dependVersion.ucrop}"
// rxlifecycleComponents:"com.trello.rxlifecycle2:rxlifecycle-android:${dependVersion.rxlifecycleComponents}"
//implementation 'com.trello.rxlifecycle2:rxlifecycle-android:2.2.2'

Expand Down
Loading