Skip to content

Commit

Permalink
add exif support library fix rotation
Browse files Browse the repository at this point in the history
remove Deprecated method
  • Loading branch information
Qixingchen committed Sep 29, 2017
1 parent 7727d5c commit b51f3e9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 92 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})

compile 'com.github.Qixingchen:RV-Utils:V1.1.4'
compile 'com.github.Qixingchen:RV-Utils:V1.1.5'

compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.bumptech.glide:glide:4.1.1'
testCompile 'junit:junit:4.12'
}
7 changes: 6 additions & 1 deletion app/src/main/java/moe/xing/getimage_app/ImageAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import java.io.File;

Expand All @@ -15,6 +16,8 @@

/**
* Created by Qi Xingchen on 16-11-30.
* <p>
* 图片列表
*/

class ImageAdapter extends BaseRecyclerViewAdapter<File, ImageAdapter.ViewHolder> {
Expand All @@ -31,7 +34,9 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
Glide.with(holder.itemView.getContext()).load(datas.get(position)).centerCrop().into(holder.mBinding.image);
Glide.with(holder.itemView.getContext()).load(datas.get(position))
.apply(new RequestOptions().centerCrop())
.into(holder.mBinding.image);
}

class ViewHolder extends RecyclerView.ViewHolder {
Expand Down
16 changes: 6 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: "com.vanniktech.android.junit.jacoco"
//apply plugin: "com.vanniktech.android.junit.jacoco"

buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha8'
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.1'
classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.6.0'
// classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.1'
// classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.9.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -22,9 +20,7 @@ allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
maven {
url "https://maven.google.com"
}
google()
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
27 changes: 14 additions & 13 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.github.kt3k.coveralls'
apply plugin: 'jacoco'
//apply plugin: 'com.github.kt3k.coveralls'
//apply plugin: 'jacoco'

android {
compileSdkVersion rootProject.ext.sdk_version
Expand All @@ -19,9 +19,9 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
// debug {
// testCoverageEnabled true
// }
lintOptions {
abortOnError false
}
Expand All @@ -37,6 +37,7 @@ dependencies {

compile "com.github.Qixingchen:Rx-Utils:V1.2.6"
compile "com.android.support:appcompat-v7:$supportLibraryVersion"
compile "com.android.support:exifinterface:$supportLibraryVersion"
//corp
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
//luban 压缩
Expand Down Expand Up @@ -72,11 +73,11 @@ artifacts {
archives javadocJar
}

coveralls {
jacocoReportPath = "${buildDir}/reports/jacoco/debug/jacoco.xml"
}

tasks.coveralls {
dependsOn 'assembleDebugUnitTest'
onlyIf { System.env.'CI' }
}
//coveralls {
// jacocoReportPath = "${buildDir}/reports/jacoco/debug/jacoco.xml"
//}
//
//tasks.coveralls {
// dependsOn 'assembleDebugUnitTest'
// onlyIf { System.env.'CI' }
//}
56 changes: 36 additions & 20 deletions lib/src/main/java/moe/xing/getimage/GetImageActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.media.ExifInterface;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
Expand Down Expand Up @@ -51,8 +52,6 @@ public class GetImageActivity extends Activity {
private static final int TAKE_PHOTO = 20;
private static final int CORP_PHOTO = 30;
private static final String SUBSCRIBER_ID = "SubscriberID";
// @Deprecated
// private static final String SELECT_MODE = "select_mode";
private static final String MAX_ARRAY_SIZE = "MAX_ARRAY_SIZE";
private static final String IS_SINGLE = "IS_SINGLE";
private static final String IS_TAKE_PHOTO = "IS_TAKE_PHOTO";
Expand All @@ -65,21 +64,6 @@ public class GetImageActivity extends Activity {
@Nullable
private File takenFile = null;

// /**
// * 获取启动 intent
// *
// * @param subscriberID subscriberID
// * @param selectMode 选择模式(单选/多选)
// */
// public static Intent getStartIntent(Context context, int subscriberID,
// @RxGetImage.SelectMode int selectMode,
// int maxSize) {
// Intent intent = new Intent(context, GetImageActivity.class);
// intent.putExtra(SUBSCRIBER_ID, subscriberID);
// intent.putExtra(SELECT_MODE, selectMode);
// intent.putExtra(MAX_ARRAY_SIZE, maxSize);
// return intent;
// }

/**
* 获取启动 intent
Expand Down Expand Up @@ -283,13 +267,20 @@ public void call(Throwable throwable) {
}
}).flatMap(new Func1<File, Observable<File>>() {
@Override
public Observable<File> call(File file) {
public Observable<File> call(final File file) {
if (getIntent().getBooleanExtra(NEED_COMPRESS, true)) {
return Luban.compress(GetImageActivity.this, file)
.setMaxSize(getIntent().getIntExtra(MAX_SIZE_IN_KIB, 150))
.setMaxWidth(getIntent().getIntExtra(MAX_WIDTH_IN_PX, 1920))
.setMaxHeight(getIntent().getIntExtra(MAX_HEIGHT_IN_PX, 1920))
.putGear(Luban.CUSTOM_GEAR).asObservable();
.putGear(Luban.CUSTOM_GEAR).asObservable()
.map(new Func1<File, File>() {
@Override
public File call(File out) {
copyExif(file, out);
return out;
}
});
} else {
return Observable.just(file);
}
Expand Down Expand Up @@ -384,7 +375,7 @@ private File takenPhotoFile() throws IOException {
return image;
}

private void sendSingleAnsAndFinish(@NonNull File image) {
private void sendSingleAnsAndFinish(@NonNull final File image) {
if (getIntent().getBooleanExtra(NEED_COMPRESS, true)) {
Luban.compress(this, image)
.setMaxSize(getIntent().getIntExtra(MAX_SIZE_IN_KIB, 150))
Expand All @@ -406,6 +397,7 @@ public void onError(Throwable e) {

@Override
public void onNext(File file) {
copyExif(image, file);
RxGetImage.getInstance().onAns(file, getSubscriberID());
}
});
Expand All @@ -415,4 +407,28 @@ public void onNext(File file) {
finish();
}
}

/**
* 复写 exif 信息
*
* @param origin 原始文件
* @param after 新增文件
*/
private void copyExif(@NonNull File origin, @NonNull File after) {

try {
ExifInterface originExif = new ExifInterface(origin.getAbsolutePath());
ExifInterface afterExif = new ExifInterface(after.getAbsolutePath());
afterExif.setAttribute(ExifInterface.TAG_ORIENTATION,
String.valueOf(originExif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL)));
double[] latLong = originExif.getLatLong();
if (latLong != null && latLong.length >= 2) {
afterExif.setLatLong(latLong[0], latLong[1]);
}
afterExif.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
}
}
46 changes: 1 addition & 45 deletions lib/src/main/java/moe/xing/getimage/RxGetImage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package moe.xing.getimage;

import android.content.Intent;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.SparseArray;
Expand All @@ -21,11 +20,6 @@
@SuppressWarnings("WeakerAccess")
public class RxGetImage {

public static final int MODE_SINGLE = 1;
public static final int MODE_SINGLE_AND_CORP = 2;
public static final int MODE_MULTIPLE = 3;
public static final int MODE_TAKE_PHOTO = 4;
public static final int MODE_TAKE_PHOTO_AND_CORP = 5;
private static RxGetImage sSingleton;
private SparseArray<Subscriber<? super File>> mSubscribers = new SparseArray<>();

Expand All @@ -51,40 +45,6 @@ public static Builder newBuilder() {
return new Builder();
}

/**
* 获取图片
*
* @return Observable<File>
*/
@NonNull
@Deprecated
public Observable<File> getImage(final boolean needCorp) {
return new Builder().isSingle(true).needCorp(needCorp).build();
}

/**
* 获取多张图片
*
* @param maxSize 最大数量
* @return Observable<File>
*/
@NonNull
@Deprecated
public Observable<File> getMultipleImage(final int maxSize) {
return new Builder().isTakePhoto(false).isSingle(false).maxArraySize(maxSize).build();
}

/**
* 拍摄图片
*
* @return Observable<File>
*/
@NonNull
@Deprecated
public Observable<File> takeImage(final boolean needCorp) {
return new Builder().isTakePhoto(true).needCorp(needCorp).build();
}

/**
* 设置返回的图片
*
Expand Down Expand Up @@ -141,11 +101,7 @@ public void call(Subscriber<? super File> subscriber) {
});
}

@IntDef({MODE_SINGLE, MODE_MULTIPLE, MODE_SINGLE_AND_CORP, MODE_TAKE_PHOTO, MODE_TAKE_PHOTO_AND_CORP})
@Deprecated
public @interface SelectMode {
}

@SuppressWarnings("SameParameterValue")
public static final class Builder {
private boolean needCorp;
private boolean needCompress;
Expand Down

0 comments on commit b51f3e9

Please sign in to comment.