Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In some special cases it is necessary to transfer more simple or even complex data structuresto the host application. For this purpose it is fairly enough to only work with static methods. The ARES Touch SDK provides a handful helper classes to avoid working directly with the JNI interfaces and Java environment. The utility class is called FxJavaUtils and provides a large set of classes. These are the steps to address a simple data transfer between the host app and the C++ app part and vice versa.

1.Transfer data from C++ to Java

Status
titleJAVA
Status
colourYellow
titleC++

1.1 Create a Java class and add a public static method

public static RETURNTYPE CPP_TO_JAVA( PARAMS );

The RETURNTYPE as well as the PARAMSmust be declared with Java known data types. The method name CPP_TO_JAVA does not need to contain characters like _ , may be just CPPTOJAVA.

Java Type

Description

boolean

unsigned 8 bits

byte

signed 8 bits

char

unsigned 16 bits

short

signed 16 bits

int

signed 32 bits

long

signed 64 bits

float

32 bits

double

64 bits

void

N/A

java/lang/String

String class

android/util/ArrayMap

Array map class

For more details check official Java documentation:

java.lang (Java Platform SE 7 )
java.util (Java Platform SE 7 )

Note: Whenever the code inside the Java method manipulates the UI of the host application, the code must be executed from the UI thread.

Status
titleJAVA

Code Block
public class JAVA_CLASS
{
...
public static RETURNTYPE CPP_TO_JAVA( [PARAMS ...] )
{
    CFxARESInstance.instance().runOnUiThread(new Runnable()
    {
        @Override
        public void run()
        {
            
        }
    });
}
...
}


1.1 Call a Java method from C++ (Simple Data)

Status
titleJAVA
Status
colourYellow
titleC++

The SDK ships a helper class CFxStaticInvocation that takes care about most of the JNI settings and can be used quite fast. The class CFxStaticInvocation constructor only requires the location of the Java class PATH_OF_JAVA_CLASS, the java class method name JAVA_METHOD and the Java method signature JAVA_METHOD_SIGNATURE. If every detail matches perfectly it is only necessary to call it using the void Call( bool bWithParameters = false, ... ); method of CFxStaticInvocation.

Status
colourYellow
titleC++

Code Block
CFxStaticInvocation obj( "PATH_OF_JAVA_CLASS", "JAVA_METHOD", "JAVA_METHOD_SIGNATURE" );
obj.Call( true, [PARAMS, ...] );


Specifying the Java class method signature is the only challenging part. Here is a list of the matching Java / JNI signature pairs.

Type Signature

Java Type

Z

boolean

B

byte

C

char

S

short

I

int

J

long

F

float

D

double

L fully-qualified-class ;

fully-qualified-class

[ type

type[]

( arg-types ) ret-type

method type

For more details check official Java documentation:

JNI Types and Data Structures


Sample (None executable code):

Status
titleJAVA

Code Block
public class Geometry
{
...
public static void PointAdded( final double x , final double y )
{
    CFxARESInstance.instance().runOnUiThread(new Runnable()
    {
        @Override
        public void run()
        {
            //
        }
    });
}
...
}


Status
colourYellow
titleC++

Code Block
CFxStaticInvocation invocation( "com/domain/Geometry", "PointAdded", "(DD)V" );
invocation.Call( true, 100.23, 100.67 );


For further samples look for any use of CFxStaticInvocation in the Android projects.

1.2 Call a Java method from C++ (Complex Data)

Status
titleJAVA
Status
colourYellow
titleC++

Coming soon …

1.3 Return values back from C++ to Java

Status
titleJAVA
Status
colourYellow
titleC++

Coming soon …