From e1c095f3941f4461834c5f9226f59726f43a8943 Mon Sep 17 00:00:00 2001 From: Christophe BOUCAUT Date: Tue, 18 Nov 2014 17:03:11 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Passage=20d'un=20param=C3=A8tre=20fixe=20?= =?UTF-8?q?=C3=A0=20l'activit=C3=A9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/android/CameraLauncher.java | 6 ++++++ .../src/org/geneanet/customcamera/CameraView.java | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index 4fc292c..8c30599 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -7,10 +7,16 @@ import org.json.JSONArray; import org.json.JSONException; import android.content.Intent; +import android.os.Bundle; public class CameraLauncher extends CordovaPlugin { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { Intent intent = new Intent(this.cordova.getActivity(), CameraView.class); + + Bundle imgBase64 = new Bundle(); + imgBase64.putString("imgBase64", "mon base 64"); + intent.putExtras(imgBase64); + cordova.getActivity().startActivity(intent); return true; diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraView.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraView.java index 0bc86d6..2d231f5 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraView.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraView.java @@ -32,7 +32,8 @@ public class CameraView extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { - + Bundle currentBundle = this.getIntent().getExtras(); + String imgBase64 = currentBundle.getString("imgBase64"); System.out.println("ON RENTRE DANS L'APPLICATION"); From 3b0e0dab881dbd33bfb10bd2131e0d353c318772 Mon Sep 17 00:00:00 2001 From: Christophe BOUCAUT Date: Wed, 19 Nov 2014 11:33:05 +0100 Subject: [PATCH 2/3] Ajout d'interactions entre js & java. --- src/android/CameraLauncher.java | 20 +++++++++++++------ .../org/geneanet/customcamera/CameraView.java | 14 ++++++++++++- www/customCamera.js | 13 ++++-------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index 8c30599..6bc6450 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -3,6 +3,7 @@ package org.geneanet.customcamera; import XXX_NAME_CURRENT_PACKAGE_XXX.CameraView; import org.apache.cordova.CordovaPlugin; import org.apache.cordova.CallbackContext; +import org.apache.cordova.PluginResult; import org.json.JSONArray; import org.json.JSONException; @@ -11,14 +12,21 @@ import android.os.Bundle; public class CameraLauncher extends CordovaPlugin { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - Intent intent = new Intent(this.cordova.getActivity(), CameraView.class); + if (action.equals("startCamera")) { + Intent intent = new Intent(this.cordova.getActivity(), CameraView.class); - Bundle imgBase64 = new Bundle(); - imgBase64.putString("imgBase64", "mon base 64"); - intent.putExtras(imgBase64); + Bundle imgBackgroundBase64 = new Bundle(); + imgBackgroundBase64.putString("imgBackgroundBase64", args.getString(0)); + intent.putExtras(imgBackgroundBase64); - cordova.getActivity().startActivity(intent); + cordova.getActivity().startActivity(intent); - return true; + PluginResult r = new PluginResult(PluginResult.Status.OK, "base64retour"); + callbackContext.sendPluginResult(r); + + return true; + } + + return false; } } diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraView.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraView.java index 2d231f5..4321859 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraView.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraView.java @@ -6,6 +6,7 @@ import java.util.List; import java.lang.Math; import android.app.Activity; +import android.app.AlertDialog; import android.hardware.Camera; import android.os.Bundle; import android.view.Display; @@ -33,7 +34,18 @@ public class CameraView extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { Bundle currentBundle = this.getIntent().getExtras(); - String imgBase64 = currentBundle.getString("imgBase64"); + if (currentBundle != null) { + String imgBackgroundBase64 = currentBundle.getString("imgBackgroundBase64"); + new AlertDialog.Builder(this) + .setTitle("Delete entry") + .setMessage(imgBackgroundBase64) + .show(); + } else { + new AlertDialog.Builder(this) + .setTitle("que neni") + .setMessage("que neni") + .show(); + } System.out.println("ON RENTRE DANS L'APPLICATION"); diff --git a/www/customCamera.js b/www/customCamera.js index 40cd64e..9aed4ad 100644 --- a/www/customCamera.js +++ b/www/customCamera.js @@ -1,8 +1,8 @@ +'use strict'; /** * Permet de faire l'interface entre phonegap et l'application customcamera en java. */ -'use strict'; var exec = require('cordova/exec'); @@ -10,12 +10,7 @@ var exec = require('cordova/exec'); var customCameraExport = function() { }; -// add method. -customCameraExport.prototype.getPicture = function() { - alert("Oh yeah !"); -}; - -customCameraExport.prototype.startCamera = function() { +customCameraExport.prototype.startCamera = function(imgBackgroundBase64) { exec( function(result) { console.log("success"); @@ -26,8 +21,8 @@ customCameraExport.prototype.startCamera = function() { console.log(result); }, "CustomCamera", - "testAction", - [] + "startCamera", + [imgBackgroundBase64] ); }; From 13d6f216e494bd136ec2383bd7c4c5ce615bffce Mon Sep 17 00:00:00 2001 From: Christophe BOUCAUT Date: Wed, 19 Nov 2014 12:33:30 +0100 Subject: [PATCH 3/3] =?UTF-8?q?On=20passe=20les=20m=C3=A9thodes=20de=20cal?= =?UTF-8?q?lback=20lors=20de=20l'appel=20de=20la=20cam=C3=A9ra=20en=20js.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/customCamera.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/www/customCamera.js b/www/customCamera.js index 9aed4ad..4e9311f 100644 --- a/www/customCamera.js +++ b/www/customCamera.js @@ -10,16 +10,10 @@ var exec = require('cordova/exec'); var customCameraExport = function() { }; -customCameraExport.prototype.startCamera = function(imgBackgroundBase64) { +customCameraExport.prototype.startCamera = function(imgBackgroundBase64, successFct, failFct) { exec( - function(result) { - console.log("success"); - console.log(result); - }, - function(result) { - console.log("fail"); - console.log(result); - }, + successFct, + failFct, "CustomCamera", "startCamera", [imgBackgroundBase64]