Home > Net >  How to wrap List<int[]> with C Builder 11?
How to wrap List<int[]> with C Builder 11?

Time:01-15

I'm struggling to access the data returned by camera_parameters->getSupportedPreviewFpsRange() with C Builder 11.

The getSupportedPreviewFpsRange() function is described here: https://developer.android.com/reference/android/hardware/Camera.Parameters#getSupportedPreviewFpsRange()

I don't have any issue with wrapping data which is not an array returned by other functions, but I could not find a way to wrap the List<int[]> data type.

The Delphi way to handle this seems to be:

camera_parameters: JCamera_Parameters;
pointer: Pointer;
jobject: JObject;
list_fps_ranges: JList;
currentFpsRange, suitableFPSRange: TJavaArray<Integer>;

...

list_fps_ranges := camera_parameters.getSupportedPreviewFpsRange();
jobject := list_fps_ranges.get(I);
pointer := (jobject as ILocalObject).GetObjectID;

fpsRange := TJavaArray<Integer> (WrapJNIArray(pointer, TypeInfo(TJavaArray<Integer>)));

Unfortunately, I could not find a way to properly translate:

fpsRange := TJavaArray<Integer> (WrapJNIArray(pointer, TypeInfo(TJavaArray<Integer>)));

into C .

I tried with:

TJavaObjectArray__1<_di_JInteger> 

without any luck, as there is no WrapJNIArray() function.

How could it be done?

CodePudding user response:

Unfortunately, I could not find a way to properly translate:

fpsRange := TJavaArray<Integer> (WrapJNIArray(pointer, TypeInfo(TJavaArray<Integer>)));

into C .

Try something like this:

_di_JCamera_Parameters camera_parameters;
TJavaArray__1<int> *currentFpsRange;
TJavaArray__1<int> *suitableFPSRange;

... 

_di_JList list_fps_ranges = camera_parameters->getSupportedPreviewFpsRange();
_di_JObject jobject = list_fps_ranges->get(I);

void *objID = ((_di_ILocalObject)jobject)->GetObjectID();  

// alternatively:
//
// #include <Androidapi.Helpers.hpp>
// void *objID = TAndroidHelper::JObjectToID(jobject);

TJavaArray__1<int> *fpsRange = (TJavaArray__1<int>*) WrapJNIArray(objID, __typeinfo(TJavaArray__1<int>));

I tried with:

TJavaObjectArray__1<_di_JInteger>

without any luck, as there is no WrapJNIArray() function.

First, TJavaArray<Integer> translates to TJavaArray__1<int>, not to TJavaObjectArray__1<_di_JInteger>.

Second, WrapJNIArray() is a helper function declared in <Androidapi.JNIBridge.hpp>.

CodePudding user response:

The List<int[] list_fps_ranges example you posted works fine but I'm still confused about how to use WrapJNIArray properly in the case of a simple List<Integer>

I tried to replicate your solution with the getZoomRatios() function which is also part of Camera.Parameters

The getZoomRatios() function returns a List<Integer>

int n_zoomratios;
void *pointer;
_di_JList list_zoomratios;
        
list_zoomratios= jcamera_parameters->getZoomRatios(); // return List<Integer>
        
_di_JObject jobject= list_zoomratios; //fishy... 
        
pointer= TAndroidHelper::JObjectToID(jobject);
TJavaArray__1<int> *zoomratios = (TJavaArray__1<int>*) WrapJNIArray(pointer, __typeinfo(TJavaArray__1<int>));
                
            

Unfortunately I can not figure which parameters of list_zoomratio should be used by jobject.

In the fps ranges example, the list_preview_fps->get() function returns a JObject which is attributed to jobject but in the case of the list_zoomratios there is no obvious JObject parameter I could use. I tried many different ways but without any success.
What is the proper way to wrap the integer array? By the way, is there a book/document which describes these wrapping mechanisms? I could not find any information online on this subject.

Thank you for your help

  • Related