From 9e0b9348f568aba08b08a775e2bed1285b9753ba Mon Sep 17 00:00:00 2001 From: Christophe Boucaut Date: Wed, 28 Jan 2015 11:36:07 +0100 Subject: [PATCH 1/5] =?UTF-8?q?Ajout=20d'un=20exemple=20de=20grille.=20Enc?= =?UTF-8?q?ore=20des=20soucis=20lorsque=20l'on=20tourne=20l'=C3=A9cran.=20?= =?UTF-8?q?Changer=20l'optention=20du=20width=20/=20height=20pour=20prendr?= =?UTF-8?q?e=20celui=20de=20l'=C3=A9cran=20total=20(pour=20palier=20au=20s?= =?UTF-8?q?oucis=20de=20barre=20de=20notification=20visible=20ou=20non.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/grid/.gitignore | 9 ++++++ examples/grid/config.xml | 12 ++++++++ examples/grid/www/index.html | 35 +++++++++++++++++++++++ examples/grid/www/js/index.js | 52 +++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 examples/grid/.gitignore create mode 100644 examples/grid/config.xml create mode 100644 examples/grid/www/index.html create mode 100644 examples/grid/www/js/index.js diff --git a/examples/grid/.gitignore b/examples/grid/.gitignore new file mode 100644 index 0000000..602549b --- /dev/null +++ b/examples/grid/.gitignore @@ -0,0 +1,9 @@ +platforms/* +!platforms/.gitkeep + +plugins/* +!plugins/.gitkeep + +node_modules/* + +*.DS_Store \ No newline at end of file diff --git a/examples/grid/config.xml b/examples/grid/config.xml new file mode 100644 index 0000000..693fc7c --- /dev/null +++ b/examples/grid/config.xml @@ -0,0 +1,12 @@ + + + grid + + A sample Apache Cordova application that responds to the deviceready event. + + + Apache Cordova Team + + + + diff --git a/examples/grid/www/index.html b/examples/grid/www/index.html new file mode 100644 index 0000000..7b8556c --- /dev/null +++ b/examples/grid/www/index.html @@ -0,0 +1,35 @@ + + + + + + + + + + Grid + + + + + + + + diff --git a/examples/grid/www/js/index.js b/examples/grid/www/js/index.js new file mode 100644 index 0000000..6231fa9 --- /dev/null +++ b/examples/grid/www/js/index.js @@ -0,0 +1,52 @@ +function getGrid() { + var format = "image/png"; + var width = window.innerWidth * devicePixelRatio; + var height = window.innerHeight * devicePixelRatio; + var widthInterval = width * 0.25; + var heightInterval = height * 0.25; + var x = widthInterval; + var y = heightInterval; + + var canvas = document.getElementById('my-canvas');; + canvas.width = width; + canvas.height = height; + + var ctx = canvas.getContext("2d"); + + ctx.beginPath(); + + while (x < width) { + ctx.moveTo(x, 0); + ctx.lineTo(x, height); + x += widthInterval; + } + + while (y < height) { + ctx.moveTo(0, y); + ctx.lineTo(width, y); + y += heightInterval; + } + ctx.stroke(); + + ctx.closePath(); + + var base64 = canvas.toDataURL(format); + + return base64.replace(/data:[^\/]*\/[^\,]*,/, ""); +}; + +document.getElementById("start-camera").onclick = function() { + navigator.GeneanetCustomCamera.startCamera( + { + imgBackgroundBase64: getGrid(), + opacity: false, + miniature: false + }, + function() { + window.console.log("success"); + }, + function() { + window.console.log("fail"); + } + ); +} \ No newline at end of file From c785aed2b13521848c1b35202a5ec00a301b6387 Mon Sep 17 00:00:00 2001 From: Christophe Boucaut Date: Thu, 29 Jan 2015 18:58:52 +0100 Subject: [PATCH 2/5] =?UTF-8?q?Ajout=20d'une=20option=20pour=20changer=20l?= =?UTF-8?q?'image=20en=20surimpression=20en=20fonction=20de=20l'orientatio?= =?UTF-8?q?n=20de=20l'=C3=A9cran.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/grid/www/js/index.js | 7 ++++- src/android/CameraLauncher.java | 29 ++++++++++++++----- .../geneanet/customcamera/CameraActivity.java | 10 ++++++- .../customcamera/TransferBigData.java | 19 ++++++++++++ www/customCamera.js | 2 ++ 5 files changed, 58 insertions(+), 9 deletions(-) diff --git a/examples/grid/www/js/index.js b/examples/grid/www/js/index.js index 6231fa9..c0762ca 100644 --- a/examples/grid/www/js/index.js +++ b/examples/grid/www/js/index.js @@ -1,7 +1,11 @@ -function getGrid() { +function getGrid(inverse) { var format = "image/png"; var width = window.innerWidth * devicePixelRatio; var height = window.innerHeight * devicePixelRatio; + if (inverse) { + width = window.innerHeight * devicePixelRatio; + height = window.innerWidth * devicePixelRatio; + } var widthInterval = width * 0.25; var heightInterval = height * 0.25; var x = widthInterval; @@ -39,6 +43,7 @@ document.getElementById("start-camera").onclick = function() { navigator.GeneanetCustomCamera.startCamera( { imgBackgroundBase64: getGrid(), + imgBackgroundBase64OtherOrientation: getGrid(true), opacity: false, miniature: false }, diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index fea4e1d..4b5623c 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -60,14 +60,29 @@ public class CameraLauncher extends CordovaPlugin { TransferBigData.setImgBackgroundBase64(imgBackgroundBase64); } - intent.putExtra("miniature", args.getBoolean(1)); - intent.putExtra("saveInGallery", args.getBoolean(2)); - intent.putExtra("cameraBackgroundColor", args.getString(3)); - intent.putExtra("cameraBackgroundColorPressed", args.getString(4)); - if (args.getInt(5) >= 0 && args.getInt(5) <= 100) { - intent.putExtra("quality", args.getInt(5)); + if (args.getString(1) != "null") { + byte[] imgBackgroundBase64OtherOrientation; + try { + imgBackgroundBase64OtherOrientation = Base64 + .decode(args.getString(1), Base64.NO_WRAP); + } catch (IllegalArgumentException e) { + this.callbackContext.error(generateError(CameraLauncher.RESULT_ERROR, + "Error decode base64 picture.")); + + return false; + } + TransferBigData.setImgBackgroundBase64OtherOrientation(imgBackgroundBase64OtherOrientation); } - intent.putExtra("opacity", args.getBoolean(6)); + + intent.putExtra("miniature", args.getBoolean(2)); + intent.putExtra("saveInGallery", args.getBoolean(3)); + intent.putExtra("cameraBackgroundColor", args.getString(4)); + intent.putExtra("cameraBackgroundColorPressed", args.getString(5)); + if (args.getInt(6) >= 0 && args.getInt(6) <= 100) { + intent.putExtra("quality", args.getInt(6)); + } + intent.putExtra("opacity", args.getBoolean(7)); + intent.putExtra("startOrientation", this.cordova.getActivity().getResources().getConfiguration().orientation); 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 dfd22d1..1be0e50 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -396,7 +396,15 @@ public class CameraActivity extends Activity { /** To set background in the view. */ protected void setBackground() { // Get the base64 picture for the background only if it's exist. - byte[] imgBackgroundBase64 = TransferBigData.getImgBackgroundBase64(); + byte[] imgBackgroundBase64; + if ( + TransferBigData.getImgBackgroundBase64OtherOrientation() == null || + this.getIntent().getIntExtra("startOrientation", 1) == this.getResources().getConfiguration().orientation + ) { + imgBackgroundBase64 = TransferBigData.getImgBackgroundBase64(); + } else { + imgBackgroundBase64 = TransferBigData.getImgBackgroundBase64OtherOrientation(); + } if (imgBackgroundBase64 != null) { // Get picture. Bitmap imgBackgroundBitmap = BitmapFactory.decodeByteArray( diff --git a/src/android/customCamera/src/org/geneanet/customcamera/TransferBigData.java b/src/android/customCamera/src/org/geneanet/customcamera/TransferBigData.java index f53bc4d..c3ea46a 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/TransferBigData.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/TransferBigData.java @@ -5,6 +5,7 @@ package org.geneanet.customcamera; */ public class TransferBigData { protected static byte[] imgBackgroundBase64 = null; + protected static byte[] imgBackgroundBase64OtherOrientation = null; protected static byte[] imgTaken = null; /** @@ -25,6 +26,24 @@ public class TransferBigData { TransferBigData.imgBackgroundBase64 = imgBackgroundBase64; } + /** + * Get bytes to represent background picture for OtherOrientation. + * + * @return byte[] + */ + public static byte[] getImgBackgroundBase64OtherOrientation() { + return TransferBigData.imgBackgroundBase64OtherOrientation; + } + + /** + * Set bytes to represent background picture for OtherOrientation. + * + * @param byte[] imgBackgroundBase64OtherOrientation + */ + public static void setImgBackgroundBase64OtherOrientation(byte[] imgBackgroundBase64OtherOrientation) { + TransferBigData.imgBackgroundBase64OtherOrientation = imgBackgroundBase64OtherOrientation; + } + /** * Get bytes to represent picture taken. * diff --git a/www/customCamera.js b/www/customCamera.js index d9b331a..d418b8a 100644 --- a/www/customCamera.js +++ b/www/customCamera.js @@ -17,6 +17,7 @@ CustomCameraExport.prototype.startCamera = function(options, successFct, failFct) { var defaultOptions = { imgBackgroundBase64: null, // background picture in base64. + imgBackgroundBase64OtherOrientation: null, // background picture in base64 for second orientation. If it's not defined, imgBackgroundBase64 is used. miniature: true, // active or disable the miniature function. saveInGallery: false, // save or not the picture in gallery. cameraBackgroundColor: "#e26760", // color of the camera button. @@ -47,6 +48,7 @@ "startCamera", [ options.imgBackgroundBase64, + options.imgBackgroundBase64OtherOrientation, options.miniature, options.saveInGallery, options.cameraBackgroundColor, From 81dd1caae1c6322467b522a85dd5601f61935edf Mon Sep 17 00:00:00 2001 From: Christophe BOUCAUT Date: Mon, 2 Feb 2015 10:03:22 +0100 Subject: [PATCH 3/5] Maj gitignore. --- src/android/customCamera/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/android/customCamera/.gitignore b/src/android/customCamera/.gitignore index 99008c9..a8c6fc6 100644 --- a/src/android/customCamera/.gitignore +++ b/src/android/customCamera/.gitignore @@ -2,6 +2,10 @@ .project .classpath project.properties +ant.properties +build.xml +local.properties +proguard-project.txt bin/* gen/* From f713a107abed025ec2c90153fcb3397cbf61ea23 Mon Sep 17 00:00:00 2001 From: Christophe BOUCAUT Date: Mon, 2 Feb 2015 10:05:04 +0100 Subject: [PATCH 4/5] Suppression d'un fichier inutile. --- src/android/customCamera/project.properties | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/android/customCamera/project.properties diff --git a/src/android/customCamera/project.properties b/src/android/customCamera/project.properties deleted file mode 100644 index 655eb8f..0000000 --- a/src/android/customCamera/project.properties +++ /dev/null @@ -1,14 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system edit -# "ant.properties", and override values to adapt the script to your -# project structure. -# -# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): -#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt - -# Project target. -target=Google Inc.:Google APIs:14 From a0ea67ddeff9f8c1099d36b3a690609111ed536f Mon Sep 17 00:00:00 2001 From: Christophe BOUCAUT Date: Mon, 2 Feb 2015 10:06:32 +0100 Subject: [PATCH 5/5] Mise aux normes checkstyle. --- .../src/org/geneanet/customcamera/CameraActivity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index 1be0e50..6c107d4 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -399,7 +399,8 @@ public class CameraActivity extends Activity { byte[] imgBackgroundBase64; if ( TransferBigData.getImgBackgroundBase64OtherOrientation() == null || - this.getIntent().getIntExtra("startOrientation", 1) == this.getResources().getConfiguration().orientation + this.getIntent().getIntExtra("startOrientation", 1) + == this.getResources().getConfiguration().orientation ) { imgBackgroundBase64 = TransferBigData.getImgBackgroundBase64(); } else {