The uno file in CameraPanel tries to call UpdateBitmap in JavaBitmap.uno:
using Uno;
using Uno.Permissions;
using Uno.Graphics;
using Uno.Threading;
using Uno.Compiler.ExportTargetInterop;
using OpenGL;
using Android.android.app;
[TargetSpecificImplementationAttribute]
public extern(Android) class Camera
{
...
[Foreign(Language.Java)]
void CaptureAndProcess()
@{
... capture frame, process it, put into newBitmap
==> call to JavaBitmap (not working):
final Preview.JavaBitmap javaBitmap = (Preview.JavaBitmap)@{JavaBitmap:Of(_this).Handle:Get()};
javaBitmap.UpdateBitmap(newBitmap);
@}
...
JavaBitmap.uno:
using Uno;
using Uno.Compiler.ExportTargetInterop;
using Uno.Graphics;
using Fuse.Resources;
[ForeignInclude(Language.Java, "android.graphics.*")]
public class JavaBitmap
{
public JavaBitmap()
{
//Preview.PreviewPage.textureImageSource.Texture = CreateANiceTexture();
}
public UpdateBitmap(Java.Object bitmap)
{
Preview.PreviewPage.textureImageSource.Texture = CreateANiceTexture(bitmap);
}
public texture2D CreateANiceTexture(Java.Object bitmap)
{
if defined(Android)
return CreateTextureFromJavaBitmap(bitmap);
throw new Exception("no");
}
...
CameraPanel files are in /Preview/Camera.
JavaBitmap is in /Preview.
Each one of them feeds the content of Panels.
(JavaBitmap.uno is linked to:
Thanks for the reply Anders; yes (the return type is indeed missing, found that after the post) and the uno method should be called at the end of the Java method
Ok so I pass an Action and call the corresponding method from javaBitmap.uno inside the foreign code. Still, I’m struggling to link the Action<Java.Object> with the JavaBitmap.uno instance:
In UX:
<Panel >
<TextureImageSource ux:Global="textureImageSource" />
<JavaBitmap ux:Global="javaBitmap"/> => Defined in JavaBitmap.uno
<Image Source="textureImageSource" />
</Panel>
<CameraStream>
<CameraVisual Camera="cam" Facing="Front" >
<Clicked >
<Callback Handler="{singleTap}" /> => This end up calling (via JS then uno) CaptureAndProcess method, which needs to call a JavaBitmap.uno method
</Clicked>
</CameraVisual>
<Camera ux:Global="cam" />
<CameraExtended ux:Global="CameraExtended" Camera="cam" />
</CameraStream>
In the code above, I see that Camera=“cam” is passed as UX parameter to several objects, which are defined in UNO. Do you thing I could do the same with the JavaBitmap object? passing it to the Camera classes so I can call JavaBitmap from CaptureAndProcess method?
FYI, JavaBitmap.uno has a globalModule tag:
[UXGlobalModule]
public class JavaBitmap : NativeModule
{
static readonly JavaBitmap _instance;
public JavaBitmap()
{
if(_instance != null)return;
_instance = this;
Resource.SetGlobalKey(_instance, "JavaBitmap");
Hi Vegard and sorry for the late reply; when compiling, the JavaBitmap.uno class is not found (There is no identifier named ‘JavaBitmap’ accessible in this scope. Did you mean ‘JavaBitmap’? ), I guess this is due to the fact that:
I did, still I could not find an example on how to call a uno method in file A from another uno method in file B.
Getting:
MyClass.MyMethod(Uno.Action<Java.Object>)' has some invalid arguments (<method_group>)
MyMethod is called, as follows:
MyMethod(Test.Singleton.TestMe);
I built Test, trying to follow the indications in the Docs:
using Uno;
using Uno.Compiler.ExportTargetInterop;
using Uno.Threading;
using Fuse;
using Fuse.Resources;
using Fuse.Scripting;
using Uno.IO;
using Uno.UX;
[UXGlobalModule]
public class Test : NativeModule
{
static readonly Test _instance;
public static Test Singleton
{
get { return _instance; }
}
public Test()
{
if(_instance != null)return;
_instance = this;
Resource.SetGlobalKey(_instance, "Test");
AddMember(new NativeFunction("TestMe", (NativeCallback)TestMe));
}
object[] TestMe(Fuse.Scripting.Context context, object[] args)
{
return null;
}
}
Both classes (MyClass, and the one calling MyTest) are not in the same folder.
This issue has recently been resolved by Bolav via Slack, I had to post the adopted solution here:
The goal was to save a byte[], generated in Java, to be used by the same Java method on future calls.
The current solution is to store the data in the Uno class containing the Java method as JavaObject, then obtaining/updating that data from the Java method using @{JavaObjectVariable:Get() / Set()}