Skip to content

Commit 1c41817

Browse files
author
Marius Merkevicius
committed
Add exif support
Applying patch from unfinished MR Source: hkk595#8
1 parent e502c71 commit 1c41817

39 files changed

+454
-12
lines changed

build.gradle

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4+
ext.kotlin_version = '1.2.51'
5+
46
repositories {
57
google()
68
jcenter()
9+
maven { url 'https://maven.google.com' }
10+
maven { url "https://jitpack.io" }
711
}
812
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.0.1'
13+
classpath 'com.android.tools.build:gradle:3.1.3'
1014
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
1115

1216
// NOTE: Do not place your application dependencies here; they belong
1317
// in the individual module build.gradle files
18+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1419
}
1520
}
1621

1722
allprojects {
1823
repositories {
1924
google()
2025
jcenter()
26+
maven { url 'https://maven.google.com' }
27+
maven { url "https://jitpack.io" }
2128
}
2229
}
2330

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Nov 21 01:40:52 HKT 2017
1+
#Tue Jul 10 18:02:03 AST 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

app/.gitignore library/.gitignore

File renamed without changes.

app/build.gradle library/build.gradle

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'com.github.dcendents.android-maven'
33

4-
group='com.github.hkk595'
4+
group = 'com.github.hkk595'
55

66
android {
7-
compileSdkVersion 26
7+
compileSdkVersion 27
88
defaultConfig {
99
minSdkVersion 16
10-
targetSdkVersion 26
10+
targetSdkVersion 27
1111
versionCode 1
1212
versionName "1.0"
1313
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -22,10 +22,15 @@ android {
2222

2323
dependencies {
2424
implementation fileTree(dir: 'libs', include: ['*.jar'])
25-
implementation 'com.android.support:appcompat-v7:26.1.0'
25+
implementation 'com.android.support:appcompat-v7:27.1.1'
2626
testImplementation 'junit:junit:4.12'
2727
androidTestImplementation 'com.android.support.test:runner:1.0.1'
2828
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
29+
implementation "com.github.jkwiecien:EasyImage:2.0.4"
2930

30-
compile 'io.reactivex.rxjava2:rxjava:2.1.6'
31+
implementation 'io.reactivex.rxjava2:rxjava:2.1.6'
32+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
3133
}
34+
35+
apply plugin: 'kotlin-android'
36+
apply plugin: 'kotlin-android-extensions'
File renamed without changes.
File renamed without changes.

app/src/main/java/me/echodev/resizer/util/ImageUtils.java library/src/main/java/me/echodev/resizer/util/ImageUtils.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import android.graphics.Bitmap;
44
import android.graphics.BitmapFactory;
5+
import android.graphics.Matrix;
6+
import android.media.ExifInterface;
57

68
import java.io.File;
79
import java.io.IOException;
@@ -12,7 +14,7 @@
1214

1315
public class ImageUtils {
1416
public static File getScaledImage(int targetLength, int quality, Bitmap.CompressFormat compressFormat,
15-
String outputDirPath, String outputFilename, File sourceImage) throws IOException {
17+
String outputDirPath, String outputFilename, File sourceImage) throws IOException {
1618
File directory = new File(outputDirPath);
1719
if (!directory.exists()) {
1820
directory.mkdirs();
@@ -28,7 +30,7 @@ public static File getScaledImage(int targetLength, int quality, Bitmap.Compress
2830
return new File(outputFilePath);
2931
}
3032

31-
public static Bitmap getScaledBitmap(int targetLength, File sourceImage) {
33+
public static Bitmap getScaledBitmap(int targetLength, File sourceImage) throws IOException {
3234
BitmapFactory.Options options = new BitmapFactory.Options();
3335
options.inJustDecodeBounds = false;
3436
Bitmap bitmap = BitmapFactory.decodeFile(sourceImage.getAbsolutePath(), options);
@@ -50,6 +52,20 @@ public static Bitmap getScaledBitmap(int targetLength, File sourceImage) {
5052
targetWidth = Math.round(targetHeight / aspectRatio);
5153
}
5254

53-
return Bitmap.createScaledBitmap(bitmap, targetWidth, targetHeight, true);
55+
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, targetWidth, targetHeight, true);
56+
57+
//check the rotation of the image and display it properly
58+
ExifInterface exif;
59+
exif = new ExifInterface(sourceImage.getAbsolutePath());
60+
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
61+
Matrix matrix = new Matrix();
62+
if (orientation == 6) {
63+
matrix.postRotate(90);
64+
} else if (orientation == 3) {
65+
matrix.postRotate(180);
66+
} else if (orientation == 8) {
67+
matrix.postRotate(270);
68+
}
69+
return Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix, true);
5470
}
5571
}
File renamed without changes.

sample/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

sample/build.gradle

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
android {
5+
compileSdkVersion 27
6+
defaultConfig {
7+
minSdkVersion 16
8+
targetSdkVersion 27
9+
versionCode 1
10+
versionName "1.0"
11+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
20+
}
21+
22+
dependencies {
23+
implementation fileTree(dir: 'libs', include: ['*.jar'])
24+
implementation project(':library')
25+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
26+
implementation 'com.android.support:appcompat-v7:27.1.1'
27+
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
28+
implementation "com.github.jkwiecien:EasyImage:2.0.4"
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+
}

sample/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cupcake.com.myapplication
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("cupcake.com.myapplication", appContext.packageName)
23+
}
24+
}

sample/src/main/AndroidManifest.xml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="cupcake.com.myapplication">
4+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
5+
6+
<application
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
<activity android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package cupcake.com.myapplication
2+
3+
import android.content.Intent
4+
import android.os.Bundle
5+
import android.support.v7.app.AppCompatActivity
6+
import android.util.Log
7+
import kotlinx.android.synthetic.main.activity_main.*
8+
import me.echodev.resizer.Resizer
9+
import pl.aprilapps.easyphotopicker.EasyImage
10+
import java.io.File
11+
12+
class MainActivity : AppCompatActivity() {
13+
14+
15+
override fun onCreate(savedInstanceState: Bundle?) {
16+
super.onCreate(savedInstanceState)
17+
setContentView(R.layout.activity_main)
18+
EasyImage.configuration(this).setAllowMultiplePickInGallery(true)
19+
EasyImage.openCamera(this, 155)
20+
}
21+
22+
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
23+
super.onActivityResult(requestCode, resultCode, data)
24+
EasyImage.handleActivityResult(requestCode, resultCode, data, this, object : EasyImage.Callbacks {
25+
override fun onImagePickerError(e: Exception, source: EasyImage.ImageSource, type: Int) {
26+
27+
}
28+
29+
override fun onImagesPicked(imageFiles: List<File>, source: EasyImage.ImageSource, type: Int) {
30+
val resizedImage = Resizer(this@MainActivity)
31+
.setTargetLength(512)
32+
.setSourceImage(imageFiles[0])
33+
.resizedBitmap
34+
35+
image.setImageBitmap(resizedImage)
36+
}
37+
38+
override fun onCanceled(source: EasyImage.ImageSource, type: Int) {
39+
if (source == EasyImage.ImageSource.CAMERA) {
40+
val photoFile = EasyImage.lastlyTakenButCanceledPhoto(this@MainActivity)
41+
if (photoFile != null) {
42+
val x = photoFile.delete()
43+
Log.i("TAG", "onCanceled: pictureDeleted =$x")
44+
}
45+
}
46+
}
47+
})
48+
}
49+
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportHeight="108"
6+
android:viewportWidth="108">
7+
<path
8+
android:fillType="evenOdd"
9+
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
10+
android:strokeColor="#00000000"
11+
android:strokeWidth="1">
12+
<aapt:attr name="android:fillColor">
13+
<gradient
14+
android:endX="78.5885"
15+
android:endY="90.9159"
16+
android:startX="48.7653"
17+
android:startY="61.0927"
18+
android:type="linear">
19+
<item
20+
android:color="#44000000"
21+
android:offset="0.0" />
22+
<item
23+
android:color="#00000000"
24+
android:offset="1.0" />
25+
</gradient>
26+
</aapt:attr>
27+
</path>
28+
<path
29+
android:fillColor="#FFFFFF"
30+
android:fillType="nonZero"
31+
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
32+
android:strokeColor="#00000000"
33+
android:strokeWidth="1" />
34+
</vector>

0 commit comments

Comments
 (0)