diff --git a/README.md b/README.md
index 4980d1f..a3e856f 100644
--- a/README.md
+++ b/README.md
@@ -5,10 +5,31 @@ Godot Camera Plugin (For 3.2 and and above)
A plugin for displaying native camera preview in @godotengine (currently Android only)
+## How to build:
+You can follow these steps to build a new release of the plugin.
+
+Prerequisites:
+- Android SDK (platform version 29)
+- the Godot Android library (`godot-lib.***.release.aar`) for your version of Godot from the [downloads page](https://godotengine.org/download).
+
+Plugin build steps:
+1. Clone this Git repository
+2. Put `godot-lib.***.release.aar` in `./android/godot-camera-plugin/libs`
+3. Run `gradlew build` in `./android`
+4. Output `.aar` files are located in `./android/godot-camera-plugin/build/outputs/aar`
+
## How to use:
-Make sure you are running godotengine version 3.2 or above and that your project have been setup for exporting with [custom Android template](https://docs.godotengine.org/en/latest/getting_started/workflow/export/android_custom_build.html).
+Make sure you are running godotengine version 3.2 or above and that your project have been setup for exporting with [Android custom builds](https://docs.godotengine.org/en/stable/getting_started/workflow/export/android_custom_build.html#doc-android-custom-build).
+
+Editor add-on installation:
+1. Copy `./addons` folder into the project root
+2. Open `Project Settings > Plugins` and enable the camera plugin
-Download and incude the plugin in your project, then enable it from the Plugin tab in your project settings.
+Android plugin installation:
+1. Copy `FunababCameraPlugin.gdap` to `android/plugins` in the project folder
+2. Copy `FunababCameraPlugin.***.aar` files to `android/plugins` in the project folder
+3. In the Android preset, enable `Plugins > Funabab Camera Plugin`
+4. In the Android preset, enable `Permissions > Camera`
A custom godot control (**CameraView**) is provided which serve as a dummy view for communicating with the *real native camera preview*.
diff --git a/addons/godot-camera-plugin.funabab/camera_view.gd b/addons/godot-camera-plugin.funabab/camera_view.gd
index 3f0c640..6c07010 100644
--- a/addons/godot-camera-plugin.funabab/camera_view.gd
+++ b/addons/godot-camera-plugin.funabab/camera_view.gd
@@ -3,7 +3,6 @@ extends Control
const CameraViewNativeBridge = preload("camera_view_native_bridge.gd").CameraViewNativeBridge;
const ERROR_FATAL = 1;
-const ICON_CAMERA = preload("icon_camera.png");
const COLOR_BG = Color.black;
enum ERROR {
@@ -28,9 +27,11 @@ export(int, "Auto", "HDR", "Portrait", "Landscape", "Night", "Sunset") var scene
export(int, "Auto", "Incandesent", "Flourescent", "Daylight", "Twilight", "Shade") var white_balanace := 0 setget set_white_balanace;
export(int, "None", "Mono", "Negative", "Solarize", "Sepia") var color_effect := 0 setget set_color_effect;
-var cameraViewBridge setget __set_blank__, __get_blank__;
-var is_initialized : bool = false setget __set_blank__;
-var camera_permission_granted = false setget __set_blank__, __get_blank__;
+var cameraViewBridge
+var is_initialized : bool = false
+var camera_permission_granted = false
+
+var camera_icon = load("res://addons/godot-camera-plugin.funabab/icon_camera.png");
signal picture_taken; # @parameters: error_code, image_texture, extra
signal initialized;
@@ -70,17 +71,38 @@ func take_picture(minimum_number_of_face = 0):
cameraViewBridge.take_picture(minimum_number_of_face);
pass
+func _ready():
+ get_tree().connect("on_request_permissions_result", self, "_on_permission_result");
+ pass
+
+func _on_permission_result(permission, granted):
+ print("permission '%s' result: %s" % [permission, granted]);
+ if (permission.ends_with("CAMERA")):
+ camera_permission_granted = granted;
+ if !is_initialized && camera_permission_granted:
+ _initialize_camera();
+ pass
+
+func _initialize_camera():
+ print("initialize camera");
+ var CameraViewNativeBridge = preload("camera_view_native_bridge.gd");
+ cameraViewBridge = CameraViewNativeBridge.initialize(self);
+ is_initialized = true;
+ pass
+
func _draw():
if !draw_camera_splash: return;
var rect = get_rect();
+ rect.position = Vector2.ZERO;
+
var icon_size = rect.size.x * .3;
- var size = Vector2(icon_size / ICON_CAMERA.get_width(),
- icon_size / ICON_CAMERA.get_width());
+ var size = Vector2(icon_size / camera_icon.get_width(),
+ icon_size / camera_icon.get_width());
draw_rect(rect, COLOR_BG);
- draw_set_transform((rect.size - (size * ICON_CAMERA.get_width())) / 2, 0, size);
- draw_texture(ICON_CAMERA, Vector2(0, 0),
+ draw_set_transform((rect.size - (size * camera_icon.get_width())) / 2, 0, size);
+ draw_texture(camera_icon, Vector2.ZERO,
Color.red if is_initialized else Color.white);
pass
@@ -92,24 +114,13 @@ func _notification(what):
if what == NOTIFICATION_ENTER_TREE:
if OS.get_name() == "Android":
+ print("requesting camera permission...");
camera_permission_granted = OS.request_permission("CAMERA");
- if camera_permission_granted == false:
- # Camera will proberly not start due to permission not granted
-
- # give users some time to grant permission
- yield(get_tree().create_timer(2), "timeout");
- prints("Godot: restart?");
- get_tree().reload_current_scene(); # lets reload and try again
elif what == NOTIFICATION_RESIZED:
if !is_initialized && camera_permission_granted:
-# yield(get_tree(), "idle_frame");
- var CameraViewNativeBridge = preload("camera_view_native_bridge.gd");
- cameraViewBridge = CameraViewNativeBridge.initialize(self);
- is_initialized = true;
- else:
- if cameraViewBridge != null:
- cameraViewBridge.resize_view(get_global_rect());
-
+ _initialize_camera();
+ elif cameraViewBridge != null:
+ cameraViewBridge.resize_view(get_global_rect());
update();
elif what == NOTIFICATION_VISIBILITY_CHANGED:
if cameraViewBridge != null:
@@ -136,14 +147,6 @@ func __get_parameters__()->Dictionary:
}
pass
-func __set_blank__(value):
- # do nothing...
- pass
-
-func __get_blank__():
- # do nothing...
- pass
-
func set_camera_facing(value):
camera_facing = value;
if cameraViewBridge != null:
diff --git a/addons/godot-camera-plugin.funabab/camera_view_native_bridge.gd b/addons/godot-camera-plugin.funabab/camera_view_native_bridge.gd
index 29dfa4e..c1696c9 100644
--- a/addons/godot-camera-plugin.funabab/camera_view_native_bridge.gd
+++ b/addons/godot-camera-plugin.funabab/camera_view_native_bridge.gd
@@ -111,13 +111,21 @@ static func initialize(node: Control)->CameraViewNativeBridge:
var instanse_id = node.get_instance_id();
if Engine.has_singleton(SINGLETON_NAME):
var plugin = Engine.get_singleton(SINGLETON_NAME);
- var r : Rect2= node.get_global_rect();
+ var r : Rect2 = node.get_global_rect();
+ var s : Vector2 = Vector2.ONE;
+
+ var parent = node.get_parent_control();
+ if parent:
+ var parent_r = parent.get_global_rect()
+ s = r.size / parent_r.size
+ r.size = parent_r.size
+ r.position -= r.size * 0.5
var cameraViewNativeBridge = CameraViewNativeBridge.new(plugin, node);
var result = plugin.initializeView(cameraViewNativeBridge.get_instance_id(),
node.get_camera_facing(), ParameterSerializer.serialize(node.__get_parameters__()),
int(r.position.x), int(r.position.y),
- int(r.size.x), int(r.size.y), node.visible);
+ int(r.size.x), int(r.size.y), s.x, s.y, node.visible);
if result == true:
return cameraViewNativeBridge;
diff --git a/addons/godot-camera-plugin.funabab/icon_camera.png.import b/addons/godot-camera-plugin.funabab/icon_camera.png.import
new file mode 100644
index 0000000..e0db374
--- /dev/null
+++ b/addons/godot-camera-plugin.funabab/icon_camera.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/icon_camera.png-b2668087f7e7255e71cd8888d15ae040.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://addons/godot-camera-plugin.funabab/icon_camera.png"
+dest_files=[ "res://.import/icon_camera.png-b2668087f7e7255e71cd8888d15ae040.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=true
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+stream=false
+size_limit=0
+detect_3d=true
+svg/scale=1.0
diff --git a/addons/godot-camera-plugin.funabab/icon_node.png.import b/addons/godot-camera-plugin.funabab/icon_node.png.import
new file mode 100644
index 0000000..9bab383
--- /dev/null
+++ b/addons/godot-camera-plugin.funabab/icon_node.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/icon_node.png-30f8f9efd25c6739f8122fe2bfd0aae8.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://addons/godot-camera-plugin.funabab/icon_node.png"
+dest_files=[ "res://.import/icon_node.png-30f8f9efd25c6739f8122fe2bfd0aae8.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=true
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+stream=false
+size_limit=0
+detect_3d=true
+svg/scale=1.0
diff --git a/addons/godot-camera-plugin.funabab/plugin.gd b/addons/godot-camera-plugin.funabab/plugin.gd
index f93656b..4352a19 100644
--- a/addons/godot-camera-plugin.funabab/plugin.gd
+++ b/addons/godot-camera-plugin.funabab/plugin.gd
@@ -5,7 +5,7 @@ const ANDROID_MODULE = "org/godotengine/godot/funabab/camera/FunababCameraPlugin
const CUSTOM_NODE_NAME = "CameraView";
func _enter_tree():
- add_custom_type(CUSTOM_NODE_NAME, "Control", preload("camera_view.gd"), preload("icon_node.png"));
+ add_custom_type(CUSTOM_NODE_NAME, "Control", preload("camera_view.gd"), load("res://addons/godot-camera-plugin.funabab/icon_node.png"));
pass
func _exit_tree():
diff --git a/android/.gitignore b/android/.gitignore
new file mode 100644
index 0000000..4e1167a
--- /dev/null
+++ b/android/.gitignore
@@ -0,0 +1,75 @@
+# Built application files
+*.apk
+*.aar
+*.ap_
+*.aab
+
+# Files for the ART/Dalvik VM
+*.dex
+
+# Java class files
+*.class
+
+# Generated files
+bin/
+gen/
+out/
+# Uncomment the following line in case you need and you don't have the release build type files in your app
+# release/
+
+# Gradle files
+.gradle/
+build/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Proguard folder generated by Eclipse
+proguard/
+
+# Log Files
+*.log
+
+# Android Studio Navigation editor temp files
+.navigation/
+
+# Android Studio captures folder
+captures/
+
+# IntelliJ
+*.iml
+.idea
+
+# Keystore files
+# Uncomment the following lines if you do not want to check your keystore files in.
+#*.jks
+#*.keystore
+
+# External native build folder generated in Android Studio 2.2 and later
+.externalNativeBuild
+.cxx/
+
+# Google Services (e.g. APIs or Firebase)
+# google-services.json
+
+# Freeline
+freeline.py
+freeline/
+freeline_project_description.json
+
+# fastlane
+fastlane/report.xml
+fastlane/Preview.html
+fastlane/screenshots
+fastlane/test_output
+fastlane/readme.md
+
+# Version control
+vcs.xml
+
+# lint
+lint/intermediates/
+lint/generated/
+lint/outputs/
+lint/tmp/
+# lint/reports/
diff --git a/android/FunababCameraPlugin.gdap b/android/FunababCameraPlugin.gdap
new file mode 100644
index 0000000..0df69ab
--- /dev/null
+++ b/android/FunababCameraPlugin.gdap
@@ -0,0 +1,5 @@
+[config]
+
+name="FunababCameraPlugin"
+binary_type="local"
+binary="FunababCameraPlugin.1.0.0.release.aar"
diff --git a/android/build.gradle b/android/build.gradle
new file mode 100644
index 0000000..25a626a
--- /dev/null
+++ b/android/build.gradle
@@ -0,0 +1,24 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+buildscript {
+ repositories {
+ google()
+ jcenter()
+ }
+ dependencies {
+ classpath "com.android.tools.build:gradle:4.0.0"
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ google()
+ jcenter()
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
diff --git a/android/godot-camera-plugin.funabab/AndroidManifest.conf b/android/godot-camera-plugin.funabab/AndroidManifest.conf
deleted file mode 100644
index fa2243c..0000000
--- a/android/godot-camera-plugin.funabab/AndroidManifest.conf
+++ /dev/null
@@ -1,2 +0,0 @@
-[user_permissions]
-
\ No newline at end of file
diff --git a/android/godot-camera-plugin/build.gradle b/android/godot-camera-plugin/build.gradle
new file mode 100644
index 0000000..debc8a1
--- /dev/null
+++ b/android/godot-camera-plugin/build.gradle
@@ -0,0 +1,29 @@
+plugins {
+ id 'com.android.library'
+}
+
+ext.pluginVersionCode = 1
+ext.pluginVersionName = "1.0.0"
+
+android {
+ compileSdkVersion 29
+ buildToolsVersion "29.0.3"
+
+ defaultConfig {
+ minSdkVersion 18
+ targetSdkVersion 29
+ versionCode pluginVersionCode
+ versionName pluginVersionName
+ }
+
+ libraryVariants.all { variant ->
+ variant.outputs.all { output ->
+ output.outputFileName = "FunababCameraPlugin.$pluginVersionName.${variant.name}.aar"
+ }
+ }
+}
+
+dependencies {
+ implementation "androidx.legacy:legacy-support-v4:1.0.0"
+ compileOnly fileTree(dir: 'libs', include: ['godot-lib*.aar'])
+}
diff --git a/android/godot-camera-plugin/src/main/AndroidManifest.xml b/android/godot-camera-plugin/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..ac7b9f4
--- /dev/null
+++ b/android/godot-camera-plugin/src/main/AndroidManifest.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
diff --git a/android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/CameraPreview.java b/android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/CameraPreview.java
similarity index 97%
rename from android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/CameraPreview.java
rename to android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/CameraPreview.java
index dd5f2d9..249e666 100644
--- a/android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/CameraPreview.java
+++ b/android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/CameraPreview.java
@@ -1,4 +1,4 @@
-package org.godotengine.godot.funabab.camera;
+package org.godotengine.godot.plugin.godotcameraplugin;
import android.annotation.SuppressLint;
import android.content.Context;
@@ -39,12 +39,18 @@ public abstract class CameraPreview extends FrameLayout implements TextureView.S
private boolean mPreviewFaceDetection;
private int mOriginalCameraOrientation = 0;
private float mOutputImageResolution = 1f;
+
+ private float mViewScaleX = 1f;
+ private float mViewScaleY = 1f;
@SuppressLint("ClickableViewAccessibility")
- public CameraPreview(Context context, Camera camera, Camera.CameraInfo info) {
+ public CameraPreview(Context context, Camera camera, Camera.CameraInfo info, final float scaleX, final float scaleY) {
super(context);
setClipChildren(true);
mDeviceDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
+
+ mViewScaleX = scaleX;
+ mViewScaleY = scaleY;
mRoot = new FrameLayout(context);
mRoot.setLayoutParams(new ViewGroup.LayoutParams(0, 0));
@@ -232,6 +238,9 @@ private void setCameraOutputSizes(int cameraOrientation) {
layoutParams.width = (int)(deviceScreenSize.y * ((float)layoutParams.width/layoutParams.height));
layoutParams.height = deviceScreenSize.y;
}
+
+ layoutParams.width *= mViewScaleX;
+ layoutParams.height *= mViewScaleY;
mRoot.setLayoutParams(layoutParams);
setCameraParameters();
@@ -352,7 +361,9 @@ protected final void setPreviewOrientation(int currentRotation) {
protected final void startCameraPreview() {
if (!isActive()) return;
- startCameraPreview(mTextureView.getSurfaceTexture());
+ SurfaceTexture surfaceTexture = mTextureView.getSurfaceTexture();
+ if (surfaceTexture != null)
+ startCameraPreview(surfaceTexture);
}
protected final void startCameraPreview(SurfaceTexture surfaceTexture) {
diff --git a/android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/CameraPreviewFaceDetection.java b/android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/CameraPreviewFaceDetection.java
similarity index 98%
rename from android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/CameraPreviewFaceDetection.java
rename to android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/CameraPreviewFaceDetection.java
index f866816..2a57717 100644
--- a/android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/CameraPreviewFaceDetection.java
+++ b/android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/CameraPreviewFaceDetection.java
@@ -1,4 +1,4 @@
-package org.godotengine.godot.funabab.camera;
+package org.godotengine.godot.plugin.godotcameraplugin;
import android.content.Context;
import android.graphics.Canvas;
diff --git a/android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/CameraPreviewZoomGesture.java b/android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/CameraPreviewZoomGesture.java
similarity index 97%
rename from android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/CameraPreviewZoomGesture.java
rename to android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/CameraPreviewZoomGesture.java
index 0a76563..d99e2e2 100644
--- a/android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/CameraPreviewZoomGesture.java
+++ b/android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/CameraPreviewZoomGesture.java
@@ -1,4 +1,4 @@
-package org.godotengine.godot.funabab.camera;
+package org.godotengine.godot.plugin.godotcameraplugin;
import android.content.Context;
import android.view.MotionEvent;
diff --git a/android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/FunababCameraPlugin.java b/android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/FunababCameraPlugin.java
similarity index 81%
rename from android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/FunababCameraPlugin.java
rename to android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/FunababCameraPlugin.java
index 7e408be..1f15b0e 100644
--- a/android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/FunababCameraPlugin.java
+++ b/android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/FunababCameraPlugin.java
@@ -1,10 +1,12 @@
-package org.godotengine.godot.funabab.camera;
+package org.godotengine.godot.plugin.godotcameraplugin;
import android.app.Activity;
import android.content.Context;
import org.godotengine.godot.Godot;
import org.godotengine.godot.GodotLib;
+import org.godotengine.godot.plugin.GodotPlugin;
+import org.godotengine.godot.plugin.SignalInfo;
import android.graphics.Bitmap;
import android.graphics.Rect;
@@ -12,17 +14,23 @@
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.FrameLayout;
+
+import androidx.annotation.NonNull;
+import androidx.collection.ArraySet;
import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
+import java.util.Set;
-public class FunababCameraPlugin extends Godot.SingletonBase {
+public class FunababCameraPlugin extends GodotPlugin {
- private Godot mActivity;
+ private Godot mGodot;
private Context mContext;
private Integer mInstanceId = null;
- private ViewGroup mRoot;
+ private FrameLayout mLayout = null;
public static final String TAG = FunababCameraPlugin.class.getSimpleName();
private static final int ERROR_CAMERA_NONE = 0;
@@ -32,30 +40,29 @@ public class FunababCameraPlugin extends Godot.SingletonBase {
private GodotCameraView mGodotCameraView;
- public boolean initializeView(final int instanceId, final boolean cameraFacingBack, final String parameters, final int x, final int y, final int w, final int h, final boolean visibility) {
+ public boolean initializeView(final int instanceId, final boolean cameraFacingBack, final String parameters, final int x, final int y, final int w, final int h, final float scaleX, final float scaleY, final boolean visibility) {
if (mInstanceId != null) {
Log.d(TAG, "initializeView: can only instantiate one view at a time!");
return false;
}
mInstanceId = instanceId;
- mActivity.runOnUiThread(new Runnable() {
+ mGodot.runOnUiThread(new Runnable() {
@Override
public void run() {
GodotCameraView godotCameraView;
try {
- godotCameraView = GodotCameraView.initializeView(mActivity, ParameterSerializer.unSerialize(parameters),
+ godotCameraView = GodotCameraView.initializeView(mContext, ParameterSerializer.unSerialize(parameters),
cameraFacingBack ? Camera.CameraInfo.CAMERA_FACING_BACK : Camera.CameraInfo.CAMERA_FACING_FRONT,
- new Rect(x, y, x + w, y + h), visibility);
+ new Rect(x, y, x + w, y + h), scaleX, scaleY, visibility);
} catch (Exception e) {
Log.e(TAG, "failed to create camera preview: " + e.getMessage());
return;
}
mGodotCameraView = godotCameraView;
- mRoot = (ViewGroup) mActivity.layout.getParent();
- mRoot.addView(mGodotCameraView);
+ mLayout.addView(mGodotCameraView);
GodotLib.calldeferred(instanceId, "_set_camera_features_", new Object[]{
ParameterSerializer.serialize(mGodotCameraView.getCameraFeatures())
@@ -65,12 +72,18 @@ public void run() {
return true;
}
+ @Override
+ public View onMainCreate(Activity activity) {
+ mLayout = new FrameLayout(activity);
+ return mLayout;
+ }
+
public void resizeView(int instanceId, final int x, final int y, final int w, final int h) {
if (!sanityCheck(instanceId))
return;
if (mGodotCameraView != null) {
- mActivity.runOnUiThread(new Runnable() {
+ mGodot.runOnUiThread(new Runnable() {
@Override
public void run() {
mGodotCameraView.setViewRect(new Rect(x, y, x + w, y + h));
@@ -94,7 +107,7 @@ public boolean sanityCheck(int instanceId) {
public void destroyView(int instanceId) {
if (!sanityCheck(instanceId))
return;
- mActivity.runOnUiThread(new Runnable() {
+ mGodot.runOnUiThread(new Runnable() {
@Override
public void run() {
_destroyView();
@@ -104,7 +117,7 @@ public void run() {
private void _destroyView() {
if (mGodotCameraView != null) {
- mRoot.removeView(mGodotCameraView);
+ mLayout.removeView(mGodotCameraView);
mInstanceId = null;
}
}
@@ -114,7 +127,7 @@ private void setViewVisibility(int instanceId, final boolean is_visible) {
return;
if (mGodotCameraView != null)
- mActivity.runOnUiThread(new Runnable() {
+ mGodot.runOnUiThread(new Runnable() {
@Override
public void run() {
mGodotCameraView.setVisibility(is_visible ? View.VISIBLE : View.INVISIBLE);
@@ -139,7 +152,7 @@ private void _setViewParameter(int instanceId, final String parameterKey, final
return;
if (mGodotCameraView != null)
- mActivity.runOnUiThread(new Runnable() {
+ mGodot.runOnUiThread(new Runnable() {
@Override
public void run() {
mGodotCameraView.setViewCameraParameterValue(parameterKey, parameterValue);
@@ -152,7 +165,7 @@ private void setPreviewCameraFacing(final int instanceId, final boolean isBackFa
return;
if (mGodotCameraView != null)
- mActivity.runOnUiThread(new Runnable() {
+ mGodot.runOnUiThread(new Runnable() {
@Override
public void run() {
final HashMap cameraFeatures = mGodotCameraView.setViewCameraFacing(isBackFacing);
@@ -169,7 +182,7 @@ private void takePicture(final int instanceId, final int minimumNumberOfFace) {
return;
if (mGodotCameraView != null) {
- mActivity.runOnUiThread(new Runnable() {
+ mGodot.runOnUiThread(new Runnable() {
@Override
public void run() {
mGodotCameraView.takePicture(new GodotCameraView.TakePictureCallback() {
@@ -224,7 +237,7 @@ private void refreshCameraPreview(final int instanceId) {
return;
if (mGodotCameraView != null) {
- mActivity.runOnUiThread(new Runnable() {
+ mGodot.runOnUiThread(new Runnable() {
@Override
public void run() {
mGodotCameraView.refreshPreview();
@@ -233,15 +246,23 @@ public void run() {
}
}
- static public Godot.SingletonBase initialize(Activity p_activity) {
- return new FunababCameraPlugin(p_activity);
+ public FunababCameraPlugin(Godot godot) {
+ super(godot);
+
+ mGodot = godot;
+ mContext = godot.getContext();
}
+
+ @NonNull
+ @Override
+ public String getPluginName() {
+ return "FunababCameraPlugin";
+ }
- public FunababCameraPlugin(Activity p_activity) {
- // Register class name and functions to bind.
- registerClass("FunababCameraPlugin", new String[]
- {
- "initializeView",
+ @NonNull
+ @Override
+ public List getPluginMethods() {
+ return Arrays.asList("initializeView",
"resizeView",
"destroyView",
"setViewVisibility",
@@ -250,27 +271,31 @@ public FunababCameraPlugin(Activity p_activity) {
"setViewParameterString",
"setPreviewCameraFacing",
"takePicture",
- "refreshCameraPreview"
- });
- mActivity = (Godot) p_activity;
- mContext = p_activity.getApplicationContext();
+ "refreshCameraPreview");
+ }
- }
+ @NonNull
+ @Override
+ public Set getPluginSignals() {
+ Set signals = new ArraySet<>();
+
+ return signals;
+ }
@Override
- protected void onMainPause() {
+ public void onMainPause() {
if (mGodotCameraView != null)
mGodotCameraView.onActivityPause();
}
@Override
- protected void onMainResume() {
+ public void onMainResume() {
if (mGodotCameraView != null)
mGodotCameraView.onActivityResume();
}
@Override
- protected void onMainDestroy() {
+ public void onMainDestroy() {
_destroyView();
}
-}
\ No newline at end of file
+}
diff --git a/android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/GodotCameraView.java b/android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/GodotCameraView.java
similarity index 97%
rename from android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/GodotCameraView.java
rename to android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/GodotCameraView.java
index e150167..628ac27 100644
--- a/android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/GodotCameraView.java
+++ b/android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/GodotCameraView.java
@@ -1,4 +1,4 @@
-package org.godotengine.godot.funabab.camera;
+package org.godotengine.godot.plugin.godotcameraplugin;
import android.content.Context;
import android.graphics.Color;
@@ -35,8 +35,8 @@ public class GodotCameraView extends CameraPreview {
private final HashMap mCameraViewParameters = new HashMap<>();
- public GodotCameraView(Context context, Camera camera, Camera.CameraInfo cameraInfo, Rect rect) {
- super(context, camera, cameraInfo);
+ public GodotCameraView(Context context, Camera camera, Camera.CameraInfo cameraInfo, Rect rect, final float scaleX, final float scaleY) {
+ super(context, camera, cameraInfo, scaleX, scaleY);
setX((float)rect.left);
setY((float)rect.top);
setLayoutParams(new ViewGroup.LayoutParams(rect.width(), rect.height()));
@@ -53,10 +53,10 @@ public void setViewRect(Rect rect) {
onPreviewRectChanged();
}
- public static GodotCameraView initializeView(Context context, HashMap parameters, int cameraFacing, Rect rect, boolean visible) throws Exception {
+ public static GodotCameraView initializeView(Context context, HashMap parameters, int cameraFacing, Rect rect, final float scaleX, final float scaleY, boolean visible) throws Exception {
final int cameraFacingId = getFacingCameraId(cameraFacing);
final Camera camera = Camera.open(cameraFacingId);
- final GodotCameraView godotCameraView = new GodotCameraView(context, camera, getCameraInfo(cameraFacingId), rect);
+ final GodotCameraView godotCameraView = new GodotCameraView(context, camera, getCameraInfo(cameraFacingId), rect, scaleX, scaleY);
godotCameraView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
godotCameraView.setViewCameraParameters(parameters);
return godotCameraView;
diff --git a/android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/ParameterSerializer.java b/android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/ParameterSerializer.java
similarity index 97%
rename from android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/ParameterSerializer.java
rename to android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/ParameterSerializer.java
index f9bdf68..8d92844 100644
--- a/android/godot-camera-plugin.funabab/src/org/godotengine/godot/funabab/camera/ParameterSerializer.java
+++ b/android/godot-camera-plugin/src/main/java/org/godotengine/godot/plugin/godotcameraplugin/ParameterSerializer.java
@@ -1,4 +1,4 @@
-package org.godotengine.godot.funabab.camera;
+package org.godotengine.godot.plugin.godotcameraplugin;
import android.graphics.Rect;
diff --git a/android/gradle.properties b/android/gradle.properties
new file mode 100644
index 0000000..4d15d01
--- /dev/null
+++ b/android/gradle.properties
@@ -0,0 +1,21 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx2048m
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+# AndroidX package structure to make it clearer which packages are bundled with the
+# Android operating system, and which are packaged with your app"s APK
+# https://developer.android.com/topic/libraries/support-library/androidx-rn
+android.useAndroidX=true
+# Automatically convert third-party libraries to use AndroidX
+android.enableJetifier=true
+# Kotlin code style for this project: "official" or "obsolete":
+kotlin.code.style=official
\ No newline at end of file
diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..f6b961f
Binary files /dev/null and b/android/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..fef635c
--- /dev/null
+++ b/android/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Mon Jun 15 13:39:16 CEST 2020
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
diff --git a/android/gradlew b/android/gradlew
new file mode 100644
index 0000000..cccdd3d
--- /dev/null
+++ b/android/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/android/gradlew.bat b/android/gradlew.bat
new file mode 100644
index 0000000..f955316
--- /dev/null
+++ b/android/gradlew.bat
@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/android/settings.gradle b/android/settings.gradle
new file mode 100644
index 0000000..0ca5a77
--- /dev/null
+++ b/android/settings.gradle
@@ -0,0 +1,2 @@
+include ':godot-camera-plugin'
+rootProject.name = "Godot Camera Plugin"