diff --git a/plugin.xml b/plugin.xml index 66adcbc..dccb0a6 100644 --- a/plugin.xml +++ b/plugin.xml @@ -27,6 +27,7 @@ + diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index 1e3cbb5..791948b 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -16,9 +16,7 @@ import java.io.InputStreamReader; import java.io.IOException; import android.content.Intent; -import android.os.Bundle; import android.util.Base64; -import android.util.Log; public class CameraLauncher extends CordovaPlugin { @@ -49,10 +47,7 @@ public class CameraLauncher extends CordovaPlugin { return false; } - - Bundle imgBackground = new Bundle(); - imgBackground.putByteArray("imgBackgroundBase64", imgBackgroundBase64); - intent.putExtras(imgBackground); + TransferBigData.setImgBackgroundBase64(imgBackgroundBase64); cordova.startActivityForResult((CordovaPlugin) this, intent, CameraLauncher.REQUEST_CODE); diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index 76b7bbc..825eb45 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -500,10 +500,9 @@ public class CameraActivity extends Activity { */ protected void setBackground() { // Get the base64 picture for the background only if it's exist. - Bundle currentBundle = this.getIntent().getExtras(); - if (currentBundle != null) { + byte[] imgBackgroundBase64 = TransferBigData.getImgBackgroundBase64(); + if (imgBackgroundBase64 != null) { // Get picture. - byte[] imgBackgroundBase64 = currentBundle.getByteArray("imgBackgroundBase64"); Bitmap imgBackgroundBitmap = BitmapFactory.decodeByteArray(imgBackgroundBase64, 0, imgBackgroundBase64.length); // Get sizes screen. @@ -519,30 +518,20 @@ public class CameraActivity extends Activity { // Change size ImageView. RelativeLayout.LayoutParams paramsMiniature = new RelativeLayout.LayoutParams(widthBackground, heightBackground); - if (heightBackground > displayHeightPx && widthBackground < displayWidthPx) { - // Picture's height greater than device's height AND device's width greater than picture's width. - paramsMiniature.width = (int) (displayHeightPx * widthBackground / heightBackground); - paramsMiniature.height = (int) displayHeightPx; - } else if (heightBackground < displayHeightPx && widthBackground > displayWidthPx) { - // Picture's width greater than device's width AND device's height greater than picture's height. + float ratioX = (float) displayWidthPx / (float) widthBackground; + float ratioY = (float) displayHeightPx / (float) heightBackground; + if (ratioX < ratioY && ratioX < 1) { paramsMiniature.width = (int) displayWidthPx; - paramsMiniature.height = (int) (displayWidthPx * heightBackground / widthBackground); - } else if (heightBackground > displayHeightPx && widthBackground > displayWidthPx) { - // Picture's width & Picture's height greater than device's width & device's height. - if (heightBackground > widthBackground) { - // Picture's height greater than Picture's width. - paramsMiniature.width = (int) (displayHeightPx * widthBackground / heightBackground); - paramsMiniature.height = (int) displayHeightPx; - } else { - // Picture's width greater than Picture's height. - paramsMiniature.width = (int) displayWidthPx; - paramsMiniature.height = (int) (displayWidthPx * heightBackground / widthBackground); - } + paramsMiniature.height = (int) (ratioX * heightBackground); + } else if (ratioX >= ratioY && ratioY < 1) { + paramsMiniature.width = (int) (ratioY * widthBackground); + paramsMiniature.height = (int) displayHeightPx; } // set image at the view. ImageView imageView = (ImageView) findViewById(R.id.background); imageView.setImageBitmap(imgBackgroundBitmap); + paramsMiniature.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); imageView.setLayoutParams(paramsMiniature); } diff --git a/src/android/customCamera/src/org/geneanet/customcamera/TransferBigData.java b/src/android/customCamera/src/org/geneanet/customcamera/TransferBigData.java new file mode 100644 index 0000000..d742960 --- /dev/null +++ b/src/android/customCamera/src/org/geneanet/customcamera/TransferBigData.java @@ -0,0 +1,24 @@ +package org.geneanet.customcamera; + +/** + * Use to transfer big data between activities. + */ +public class TransferBigData { + protected static byte[] imgBackgroundBase64 = null; + + /** + * Get bytes to represent background picture. + * @return byte[] + */ + public static byte[] getImgBackgroundBase64() { + return TransferBigData.imgBackgroundBase64; + } + + /** + * Set bytes to represent background picture. + * @param byte[] imgBackgroundBase64 + */ + public static void setImgBackgroundBase64(byte[] imgBackgroundBase64) { + TransferBigData.imgBackgroundBase64 = imgBackgroundBase64; + } +}