Skip to content

Commit

Permalink
Merge pull request #68 from stantmob/bug/INS-927-bug-on-image-orienta…
Browse files Browse the repository at this point in the history
…tion-when-attaching

bug/INS-927 Bug on image orientation when attaching
  • Loading branch information
alexandremelostant authored Aug 5, 2022
2 parents 6b5e21f + b5e7efc commit 428d2ed
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 42 deletions.
2 changes: 1 addition & 1 deletion cardshowviewtakenpicturesview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies {
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'androidx.exifinterface:exifinterface:1.3.2'
implementation 'androidx.exifinterface:exifinterface:1.3.3'

// Support for java 8 features
implementation 'com.annimon:stream:1.1.3'
Expand Down
10 changes: 10 additions & 0 deletions cardshowviewtakenpicturesview/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
android:configChanges="screenSize|orientation|screenLayout|navigation"
android:theme="@style/AppThemeCamera" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.FileUtils;
import android.os.Handler;
import android.provider.MediaStore;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -543,13 +544,13 @@ private Integer getColor(Context context, Integer colorId) {

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_IMAGE_LIST_GALLERY_RESULT && resultCode == Activity.RESULT_OK) {

if (requestCode == REQUEST_IMAGE_LIST_GALLERY_RESULT && resultCode == Activity.RESULT_OK && data != null) {
if (data.getData() != null) {
if ((data != null) && (data.getData() != null)) {
Uri imageUri = data.getData();

generateImageCallback(imageUri);
if (imageUri.getLastPathSegment() != null) {
generateImageCallback(imageUri);
}
} else if (data.getClipData() != null) {
int count = data.getClipData().getItemCount();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package br.com.stant.libraries.cardshowviewtakenpicturesview.utils;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.media.MediaScannerConnection;
import android.net.Uri;
Expand All @@ -12,6 +11,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
Expand Down Expand Up @@ -85,10 +85,7 @@ public void generateCardShowTakenImageFromImageGallery(Uri data, Integer photoTy
CardShowTakenCompressedCallback cardShowTakenCompressedCallback) {
try {
final Bitmap bitmap = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), data);
String photoPath = getRealPathFromURI(mContext, data);
if (photoPath.isEmpty()) {
photoPath = getRealPathFromURI(mContext, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
}
InputStream photoPath = mContext.getContentResolver().openInputStream(data);

final Integer desiredSize = 1400;
final Bitmap scaledBitmap = rotateBitmapBasedOnExifInterface(photoPath,
Expand All @@ -101,36 +98,7 @@ public void generateCardShowTakenImageFromImageGallery(Uri data, Integer photoTy
}
}

private String getRealPathFromURI(Context context, Uri contentUri) {
final Cursor cursor = context.getContentResolver().query(contentUri, null, null,
null, null);

String photoPath = getRealPathFromCursor(cursor, "filePath");
if (photoPath.isEmpty()) {
photoPath = getRealPathFromCursor(cursor, "_data");
}

return photoPath;
}

private String getRealPathFromCursor(Cursor cursor, String columnName) {
if (cursor != null) {
if (cursor.moveToFirst()) {
int column_index = cursor.getColumnIndex(columnName);
if (column_index >= 0) {
return cursor.getString(column_index);
} else {
return "";
}
} else {
return "";
}
} else {
return "";
}
}

private Bitmap rotateBitmapBasedOnExifInterface(String photoPath, Bitmap bitmap) {
private Bitmap rotateBitmapBasedOnExifInterface(InputStream photoPath, Bitmap bitmap) {
ExifInterface ei;
try {
if (photoPath == null) {
Expand All @@ -145,7 +113,6 @@ private Bitmap rotateBitmapBasedOnExifInterface(String photoPath, Bitmap bitmap)

switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
case ExifInterface.ORIENTATION_UNDEFINED:
rotatedBitmap = rotateImage(bitmap, 270);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
Expand Down
15 changes: 15 additions & 0 deletions cardshowviewtakenpicturesview/src/main/res/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path
name="my_cache"
path="." />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
</paths>

0 comments on commit 428d2ed

Please sign in to comment.