Skip to content
This repository has been archived by the owner on Feb 18, 2019. It is now read-only.

Commit

Permalink
Backed out D3019087
Browse files Browse the repository at this point in the history
Reviewed By: zjj010104

Differential Revision: D3073724

fb-gh-sync-id: cd97477c9405f1ec048ba3dcdfd4280f77b631d2
shipit-source-id: cd97477c9405f1ec048ba3dcdfd4280f77b631d2
  • Loading branch information
chenfadafb authored and Facebook Github Bot 8 committed Mar 20, 2016
1 parent 029aa5b commit 630c142
Showing 1 changed file with 0 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,13 @@
import java.util.List;
import java.util.Map;

import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.MediaStore;
import android.text.TextUtils;

import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.GuardedAsyncTask;
import com.facebook.react.bridge.ReactApplicationContext;
Expand All @@ -46,7 +40,6 @@
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.common.ReactConstants;

/**
* Native module that provides image cropping functionality.
Expand All @@ -61,35 +54,6 @@ public class ImageEditingManager extends ReactContextBaseJavaModule {
/** Compress quality of the output file. */
private static final int COMPRESS_QUALITY = 90;

@SuppressLint("InlinedApi") private static final String[] EXIF_ATTRIBUTES = new String[] {
ExifInterface.TAG_APERTURE,
ExifInterface.TAG_DATETIME,
ExifInterface.TAG_DATETIME_DIGITIZED,
ExifInterface.TAG_EXPOSURE_TIME,
ExifInterface.TAG_FLASH,
ExifInterface.TAG_FOCAL_LENGTH,
ExifInterface.TAG_GPS_ALTITUDE,
ExifInterface.TAG_GPS_ALTITUDE_REF,
ExifInterface.TAG_GPS_DATESTAMP,
ExifInterface.TAG_GPS_LATITUDE,
ExifInterface.TAG_GPS_LATITUDE_REF,
ExifInterface.TAG_GPS_LONGITUDE,
ExifInterface.TAG_GPS_LONGITUDE_REF,
ExifInterface.TAG_GPS_PROCESSING_METHOD,
ExifInterface.TAG_GPS_TIMESTAMP,
ExifInterface.TAG_IMAGE_LENGTH,
ExifInterface.TAG_IMAGE_WIDTH,
ExifInterface.TAG_ISO,
ExifInterface.TAG_MAKE,
ExifInterface.TAG_MODEL,
ExifInterface.TAG_ORIENTATION,
ExifInterface.TAG_SUBSEC_TIME,
ExifInterface.TAG_SUBSEC_TIME_DIG,
ExifInterface.TAG_SUBSEC_TIME_ORIG,
ExifInterface.TAG_WHITE_BALANCE
};


public ImageEditingManager(ReactApplicationContext reactContext) {
super(reactContext);
new CleanTask(getReactApplicationContext()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
Expand Down Expand Up @@ -277,10 +241,6 @@ protected void doInBackgroundGuarded(Void... params) {
File tempFile = createTempFile(mContext, mimeType);
writeCompressedBitmapToFile(cropped, mimeType, tempFile);

if (mimeType.equals("image/jpeg")) {
copyExif(mContext, Uri.parse(mUri), tempFile);
}

mSuccess.invoke(Uri.fromFile(tempFile).toString());

} catch (Exception e) {
Expand Down Expand Up @@ -392,47 +352,6 @@ private Bitmap cropAndResize(

// Utils

private static void copyExif(Context context, Uri oldImage, File newFile) throws IOException {
File oldFile = getFileFromUri(context, oldImage);
if (oldFile == null) {
FLog.w(ReactConstants.TAG, "Couldn't get real path for uri: " + oldImage);
return;
}

ExifInterface oldExif = new ExifInterface(oldFile.getAbsolutePath());
ExifInterface newExif = new ExifInterface(newFile.getAbsolutePath());
for (String attribute : EXIF_ATTRIBUTES) {
String value = oldExif.getAttribute(attribute);
if (value != null) {
newExif.setAttribute(attribute, value);
}
}
newExif.saveAttributes();
}

private static @Nullable File getFileFromUri(Context context, Uri uri) {
if (uri.getScheme().equals("file")) {
return new File(uri.getPath());
} else if (uri.getScheme().equals("content")) {
Cursor cursor = context.getContentResolver()
.query(uri, new String[] { MediaStore.MediaColumns.DATA }, null, null, null);
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
String path = cursor.getString(0);
if (!TextUtils.isEmpty(path)) {
return new File(path);
}
}
} finally {
cursor.close();
}
}
}

return null;
}

private static boolean isLocalUri(String uri) {
for (String localPrefix : LOCAL_URI_PREFIXES) {
if (uri.startsWith(localPrefix)) {
Expand Down

0 comments on commit 630c142

Please sign in to comment.