mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +08:00
Fixing CB-210 with patch and adding fix for CB-210
This commit is contained in:
parent
f3c96ce1a0
commit
8a7af93765
@ -39,6 +39,7 @@ import android.content.ContentValues;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Bitmap.CompressFormat;
|
import android.graphics.Bitmap.CompressFormat;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
@ -272,19 +273,24 @@ public class CameraLauncher extends Plugin {
|
|||||||
// Get src and dest types from request code
|
// Get src and dest types from request code
|
||||||
int srcType = (requestCode/16) - 1;
|
int srcType = (requestCode/16) - 1;
|
||||||
int destType = (requestCode % 16) - 1;
|
int destType = (requestCode % 16) - 1;
|
||||||
|
int rotate = 0;
|
||||||
|
|
||||||
|
// Create an ExifHelper to save the exif data that is lost during compression
|
||||||
|
ExifHelper exif = new ExifHelper();
|
||||||
|
try {
|
||||||
|
if (this.encodingType == JPEG) {
|
||||||
|
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Pic.jpg");
|
||||||
|
exif.readExifData();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
// If CAMERA
|
// If CAMERA
|
||||||
if (srcType == CAMERA) {
|
if (srcType == CAMERA) {
|
||||||
// If image available
|
// If image available
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
try {
|
try {
|
||||||
// Create an ExifHelper to save the exif data that is lost during compression
|
|
||||||
ExifHelper exif = new ExifHelper();
|
|
||||||
if (this.encodingType == JPEG) {
|
|
||||||
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Pic.jpg");
|
|
||||||
exif.readExifData();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read in bitmap of captured image
|
// Read in bitmap of captured image
|
||||||
Bitmap bitmap;
|
Bitmap bitmap;
|
||||||
try {
|
try {
|
||||||
@ -375,6 +381,20 @@ public class CameraLauncher extends Plugin {
|
|||||||
if (destType == DATA_URL) {
|
if (destType == DATA_URL) {
|
||||||
try {
|
try {
|
||||||
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
||||||
|
String[] cols = { MediaStore.Images.Media.ORIENTATION };
|
||||||
|
Cursor cursor = this.ctx.getContentResolver().query(intent.getData(),
|
||||||
|
cols,
|
||||||
|
null, null, null);
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.moveToPosition(0);
|
||||||
|
rotate = cursor.getInt(0);
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
if (rotate != 0) {
|
||||||
|
Matrix matrix = new Matrix();
|
||||||
|
matrix.setRotate(rotate);
|
||||||
|
bitmap = bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
||||||
|
}
|
||||||
bitmap = scaleBitmap(bitmap);
|
bitmap = scaleBitmap(bitmap);
|
||||||
this.processPicture(bitmap);
|
this.processPicture(bitmap);
|
||||||
bitmap.recycle();
|
bitmap.recycle();
|
||||||
@ -399,6 +419,12 @@ public class CameraLauncher extends Plugin {
|
|||||||
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
|
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
|
||||||
os.close();
|
os.close();
|
||||||
|
|
||||||
|
// Restore exif data to file
|
||||||
|
if (this.encodingType == JPEG) {
|
||||||
|
exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
|
||||||
|
exif.writeExifData();
|
||||||
|
}
|
||||||
|
|
||||||
bitmap.recycle();
|
bitmap.recycle();
|
||||||
bitmap = null;
|
bitmap = null;
|
||||||
|
|
||||||
@ -497,4 +523,4 @@ public class CameraLauncher extends Plugin {
|
|||||||
public void failPicture(String err) {
|
public void failPicture(String err) {
|
||||||
this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId);
|
this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,10 @@ public class FileTransfer extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dos.writeBytes(LINE_START + BOUNDRY + LINE_END);
|
dos.writeBytes(LINE_START + BOUNDRY + LINE_END);
|
||||||
dos.writeBytes("Content-Disposition: form-data; name=\"" + fileKey + "\";" + " filename=\"" + fileName +"\"" + LINE_END);
|
dos.writeBytes("Content-Disposition: form-data; name=\"" + fileKey + "\";" + " filename=\"");
|
||||||
|
//We don't want to chagne encoding, we just want this to write for all Unicode.
|
||||||
|
dos.write(fileName.getBytes("UTF-8"));
|
||||||
|
dos.writeBytes("\"" + LINE_END);
|
||||||
dos.writeBytes("Content-Type: " + mimeType + LINE_END);
|
dos.writeBytes("Content-Type: " + mimeType + LINE_END);
|
||||||
dos.writeBytes(LINE_END);
|
dos.writeBytes(LINE_END);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user