Merge branch 'transform-to-plugin'
Conflicts: src/android/customCamera/res/layout/activity_camera_view.xml src/android/customCamera/src/org/geneanet/customcamera/CameraView.java src/android/customCamera/src/org/geneanet/customcamera/MainActivity.java
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var exec = require('child_process').exec;
|
||||
exec("npm install xml2js@0.4.x");
|
||||
@@ -0,0 +1,181 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Define required.
|
||||
var fs = require("fs");
|
||||
var xml2js = require('xml2js');
|
||||
var parseString = xml2js.parseString;
|
||||
var builder = new xml2js.Builder();
|
||||
|
||||
// Define differents paths.
|
||||
var pathConfigXml = "config.xml";
|
||||
var pathAndroidCordova = "platforms/android/";
|
||||
var pathResAndroidCordova = "platforms/android/res/";
|
||||
var pathAndroidPlugin = __dirname+"/../../src/android/";
|
||||
var pathResPlugin = __dirname+"/../../res/";
|
||||
|
||||
/**
|
||||
* Generate a path based on a package name.
|
||||
*
|
||||
* @param {string} packageName Package name, eg: com.example.
|
||||
*
|
||||
* @return {string} Return path generate.
|
||||
*/
|
||||
var generatePathFrompackageName = function(packageName) {
|
||||
return packageName.split(".").join("/");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create different java classes.
|
||||
*
|
||||
* @param {string} packageName Package name of the current application.
|
||||
*/
|
||||
var createClasses = function(packageName) {
|
||||
var pathCameraView = pathAndroidPlugin+"customCamera/src/org/geneanet/customcamera/CameraView.java";
|
||||
var pathCameraLauncher = pathAndroidPlugin+"CameraLauncher.java";
|
||||
|
||||
if (fs.existsSync(pathCameraView) && fs.existsSync(pathCameraLauncher)) {
|
||||
// Rewrite package of CameraView class.
|
||||
var contentCameraView = fs.readFileSync(pathCameraView, {encoding: "utf8"});
|
||||
contentCameraView = contentCameraView.replace(/^package\s[^;]*/,"package "+packageName);
|
||||
fs.writeFileSync(pathAndroidCordova+"src/"+generatePathFrompackageName(packageName)+"/CameraView.java", contentCameraView);
|
||||
|
||||
// Rewrite import of CameraLauncher class.
|
||||
var contentCameraLauncher = fs.readFileSync(pathCameraLauncher, {encoding: "utf8"});
|
||||
contentCameraLauncher = contentCameraLauncher.replace("XXX_NAME_CURRENT_PACKAGE_XXX", packageName);
|
||||
fs.writeFileSync(
|
||||
pathAndroidCordova+"src/"+generatePathFrompackageName(contentCameraLauncher.match(/package\s([^;]*)/)[1])+"/CameraLauncher.java",
|
||||
contentCameraLauncher
|
||||
);
|
||||
} else {
|
||||
console.error("File CameraView.java or/and CameraLauncher.java not found.");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update AndroidManifest.xml of the current application.
|
||||
*
|
||||
* @param {string} packageName Package name of the current application.
|
||||
*/
|
||||
var updateAndroidManifest = function(packageName) {
|
||||
var pathAndroidManifestCordova = pathAndroidCordova+"AndroidManifest.xml";
|
||||
if (fs.existsSync(pathAndroidManifestCordova)) {
|
||||
// get content AndroidManifest.
|
||||
var contentAndroidManifest = fs.readFileSync(pathAndroidManifestCordova, {encoding: "utf8"});
|
||||
parseString(contentAndroidManifest, function (err, result) {
|
||||
contentAndroidManifest = result;
|
||||
});
|
||||
|
||||
// add activity if needed.
|
||||
var needAddActivity = true;
|
||||
var currentActivities = contentAndroidManifest["manifest"]["application"][0]["activity"];
|
||||
for (var i = currentActivities.length - 1; i >= 0; i--) {
|
||||
if (currentActivities[i]["$"]["android:name"] == "CameraView") {
|
||||
needAddActivity = false;
|
||||
}
|
||||
};
|
||||
if (needAddActivity) {
|
||||
contentAndroidManifest["manifest"]["application"][0]["activity"].push({
|
||||
$: {
|
||||
"android:name": "CameraView",
|
||||
"android:label": "CameraView",
|
||||
}
|
||||
})
|
||||
var newXmlAndroidManifest = builder.buildObject(contentAndroidManifest);
|
||||
fs.writeFileSync(
|
||||
pathAndroidManifestCordova,
|
||||
newXmlAndroidManifest
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.error("File AndroidManifest.xml for cordova not found.");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update differents config file (translate, res/layout, etc).
|
||||
*/
|
||||
var updateConfig = function() {
|
||||
var pathLayoutCordova = pathResAndroidCordova+"layout/";
|
||||
var pathLayoutPlugin = pathAndroidPlugin+"customCamera/res/layout/";
|
||||
var pathLayoutCameraView = pathLayoutPlugin+"activity_camera_view.xml";
|
||||
|
||||
// create directory layout in cordova if it doesn't exist.
|
||||
if (!fs.existsSync(pathLayoutCordova)) {
|
||||
fs.mkdirSync(pathLayoutCordova);
|
||||
}
|
||||
|
||||
// "copy" layout for camera.
|
||||
if (fs.existsSync(pathLayoutCameraView)) {
|
||||
var layoutCameraViewContent = fs.readFileSync(pathLayoutCameraView, {encoding: "utf8"});
|
||||
|
||||
fs.writeFileSync(pathLayoutCordova+"activity_camera_view.xml", layoutCameraViewContent);
|
||||
} else {
|
||||
console.error("File activity_camera_view.xml in plugin not found.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// add translations.
|
||||
var pathTranslations = pathResPlugin+"translations.json";
|
||||
if (fs.existsSync(pathTranslations)) {
|
||||
// get translations.
|
||||
var translationsForApplications = fs.readFileSync(pathTranslations, {encoding: "utf8"});
|
||||
translationsForApplications = JSON.parse(translationsForApplications);
|
||||
for (lang in translationsForApplications) {
|
||||
var pathFileTranslate = pathResAndroidCordova+"values-"+lang+"/";
|
||||
|
||||
var objToXml;
|
||||
// already exist, get data.
|
||||
if (fs.existsSync(pathFileTranslate+"strings.xml")) {
|
||||
var objToXml = fs.readFileSync(pathFileTranslate+"strings.xml", {encoding: "utf8"});
|
||||
parseString(objToXml, function (err, result) {
|
||||
objToXml = result;
|
||||
});
|
||||
} else {
|
||||
// generate minimal object.
|
||||
objToXml = {
|
||||
resources: {
|
||||
string: []
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// add message.
|
||||
for (tag in translationsForApplications[lang]) {
|
||||
objToXml["resources"]["string"].push({
|
||||
_: translationsForApplications[lang][tag],
|
||||
$: {
|
||||
name: tag
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var xmlBuild = builder.buildObject(objToXml);
|
||||
if (!fs.existsSync(pathFileTranslate)) {
|
||||
fs.mkdirSync(pathFileTranslate);
|
||||
}
|
||||
fs.writeFileSync(pathFileTranslate+"strings.xml", xmlBuild);
|
||||
}
|
||||
} else {
|
||||
console.error("File translations.json in plugin not found.");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if files required exist.
|
||||
if (fs.existsSync(pathConfigXml)) {
|
||||
// Get the name package of the current application.
|
||||
var configContent = fs.readFileSync(pathConfigXml, {encoding: "utf8"});
|
||||
parseString(configContent, function (err, result) {
|
||||
configContent = result;
|
||||
});
|
||||
var packageName = configContent["widget"]["$"]["id"];
|
||||
|
||||
createClasses(packageName);
|
||||
updateAndroidManifest(packageName);
|
||||
updateConfig();
|
||||
} else {
|
||||
console.error("File config.xml for cordova not found.");
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin
|
||||
xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="org.geneanet.customCamera"
|
||||
version="0.0.1"
|
||||
>
|
||||
<name>customCamera</name>
|
||||
<description>customCamera by Geneanet</description>
|
||||
<license>undefined</license>
|
||||
<keywords>custom,camera,geneanet</keywords>
|
||||
<js-module src="www/customCamera.js" name="customCamera">
|
||||
<clobbers target="customCamera" />
|
||||
</js-module>
|
||||
|
||||
<hook type="after_plugin_install" src="hooks/after_plugin_install/npminstall.js" />
|
||||
|
||||
<platform name="android">
|
||||
<config-file target="res/xml/config.xml" parent="/*">
|
||||
<feature name="CustomCamera">
|
||||
<param name="android-package" value="org.geneanet.customcamera.CameraLauncher"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
<config-file target="AndroidManifest.xml" parent="/*">
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
</config-file>
|
||||
|
||||
<source-file src="src/android/CameraLauncher.java" target-dir="src/org/geneanet/customcamera" />
|
||||
<source-file src="src/android/customCamera/src/org/geneanet/customcamera/CustomCamera.java" target-dir="src/org/geneanet/customcamera" />
|
||||
<source-file src="src/android/customCamera/src/org/geneanet/customcamera/CameraPreview.java" target-dir="src/org/geneanet/customcamera" />
|
||||
|
||||
<hook type="before_build" src="hooks/before_build/generateActivity.js" />
|
||||
</platform>
|
||||
</plugin>
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"fr": {
|
||||
"Miniature": "Miniature",
|
||||
"PHOTO": "Photo",
|
||||
|
||||
},
|
||||
"en": {
|
||||
"Miniature": "Miniature",
|
||||
"PHOTO": "Photo",
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.geneanet.customcamera;
|
||||
|
||||
import XXX_NAME_CURRENT_PACKAGE_XXX.CameraView;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
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);
|
||||
cordova.getActivity().startActivity(intent);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.geneanet.testcustomcamera"
|
||||
package="org.geneanet.customcamera"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 50 KiB |
@@ -11,4 +11,4 @@
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-14
|
||||
target=android-16
|
||||
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 343 KiB After Width: | Height: | Size: 343 KiB |
|
Before Width: | Height: | Size: 802 KiB After Width: | Height: | Size: 802 KiB |
|
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 7.5 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 585 KiB After Width: | Height: | Size: 585 KiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 343 KiB After Width: | Height: | Size: 343 KiB |
|
Before Width: | Height: | Size: 802 KiB After Width: | Height: | Size: 802 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 585 KiB After Width: | Height: | Size: 585 KiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 343 KiB After Width: | Height: | Size: 343 KiB |
|
Before Width: | Height: | Size: 802 KiB After Width: | Height: | Size: 802 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 585 KiB After Width: | Height: | Size: 585 KiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 343 KiB After Width: | Height: | Size: 343 KiB |
|
Before Width: | Height: | Size: 802 KiB After Width: | Height: | Size: 802 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 585 KiB After Width: | Height: | Size: 585 KiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
@@ -27,7 +27,6 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:alpha="0.2"
|
||||
android:contentDescription="@string/descImage"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/normal" />
|
||||
|
||||
@@ -36,7 +35,6 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:alpha="0"
|
||||
android:contentDescription="@string/descImage"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/colorise" />
|
||||
|
||||
@@ -45,7 +43,6 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:alpha="0"
|
||||
android:contentDescription="@string/descImage"
|
||||
android:rotation="90"
|
||||
android:src="@drawable/paysage" />
|
||||
|
||||
@@ -54,7 +51,6 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:alpha="0"
|
||||
android:contentDescription="@string/descImage"
|
||||
android:rotation="90"
|
||||
android:src="@drawable/couthenans" />
|
||||
|
||||
@@ -63,7 +59,6 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:alpha="0"
|
||||
android:contentDescription="@string/descImage"
|
||||
android:rotation="90"
|
||||
android:src="@drawable/hericourt" />
|
||||
|
||||
@@ -86,7 +81,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:contentDescription="@string/BoutonMiniature"
|
||||
android:onClick="showMiniature"
|
||||
android:text="@string/Miniature" />
|
||||
|
||||
@@ -99,7 +93,7 @@
|
||||
android:minWidth="0dp"
|
||||
android:text="@string/PHOTO" />
|
||||
|
||||
<org.geneanet.customcamera.utils.VerticalSeekBar
|
||||
<org.geneanet.customcamera.VerticalSeekBar
|
||||
android:id="@+id/switchOpacity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="300dp"
|
||||
@@ -4,7 +4,7 @@
|
||||
<string name="app_name">TestCustomCamera</string>
|
||||
<string name="hello_world">Hello world!</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="title_activity_camera_view">CameraView</string>
|
||||
<string name="title_activity_camera_view">CameraViewNative</string>
|
||||
<string name="start_custom_camera">Start Custom Camera</string>
|
||||
<string name="capture">Capture</string>
|
||||
<string name="todo">TODO</string>
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.geneanet.customcamera.utils;
|
||||
package org.geneanet.customcamera;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
package org.geneanet.customcamera;
|
||||
|
||||
import org.geneanet.customcamera.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.lang.Math;
|
||||
|
||||
import org.geneanet.customcamera.utils.CameraPreview;
|
||||
import org.geneanet.customcamera.utils.CustomCamera;
|
||||
import org.geneanet.testcustomcamera.R;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import android.hardware.Camera;
|
||||
import android.hardware.Camera.Parameters;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.view.Window;
|
||||
@@ -50,7 +44,7 @@ public class CameraView extends Activity {
|
||||
|
||||
/* Remove notification bar */
|
||||
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
|
||||
setContentView(R.layout.activity_camera_view);
|
||||
|
||||
/* Get informations about the device */
|
||||
@@ -274,4 +268,4 @@ public class CameraView extends Activity {
|
||||
// mPreview.getHolder().removeCallback(mPreview);
|
||||
System.out.println("onResume -> test ");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.geneanet.customcamera.utils;
|
||||
package org.geneanet.customcamera;
|
||||
|
||||
import android.hardware.Camera;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.geneanet.customcamera;
|
||||
|
||||
import org.geneanet.testcustomcamera.R;
|
||||
import org.geneanet.customcamera.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.geneanet.customcamera.utils;
|
||||
package org.geneanet.customcamera;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
@@ -11,8 +11,24 @@ var customCameraExport = function() {
|
||||
};
|
||||
|
||||
// add method.
|
||||
customCameraExport.prototype.jesaispasquoionverra = function() {
|
||||
|
||||
customCameraExport.prototype.getPicture = function() {
|
||||
alert("Oh yeah !");
|
||||
};
|
||||
|
||||
customCameraExport.prototype.startCamera = function() {
|
||||
exec(
|
||||
function(result) {
|
||||
console.log("success");
|
||||
console.log(result);
|
||||
},
|
||||
function(result) {
|
||||
console.log("fail");
|
||||
console.log(result);
|
||||
},
|
||||
"CustomCamera",
|
||||
"testAction",
|
||||
[]
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = new customCameraExport();
|
||||