I'm trying to create a wrapper of this repository with little success. Always getting wi is null. I also tried with JavaObject with no success still same result. This is my wrapper code.
This the try with JavaObject
What am I doing wrong. Advice to make this work correctly.
B4X:
package cm.jahswant.docscanner;
import java.io.FileNotFoundException;
import java.io.InputStream;
import com.example.monscanner.ScanActivity;
import com.example.monscanner.ScanConstants;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.IOnActivityResult;
import anywheresoftware.b4a.objects.drawable.CanvasWrapper.BitmapWrapper;
@Version(0.20f)
@ShortName("DocScannerUp")
@Events(values={"onCameraResult(scannedImage As Bitmap)","onGaleryResult(scannedImage As Bitmap)"})
@BA.DependsOn(values = {"monscanner-release.aar"})
public class DocScannerWrapper{
private BA ba;
private String eventName;
private Intent intent;
private static IOnActivityResult ion;
/*
* Initialize the MonScanner *
*/
public void Initialize(BA ba, String EventName) {
_initialize(ba, null, EventName);
}
@Hide
public void _initialize(BA ba, Object activityClass, String EventName) {
this.eventName = EventName.toLowerCase(BA.cul);
this.ba = ba;
}
public void openCamera(){
intent = new Intent("com.example.monscanner.ScanActivity");
intent.putExtra(ScanConstants.OPEN_INTENT_PREFERENCE, ScanConstants.OPEN_CAMERA);
ion = new IOnActivityResult() {
@Override
public void ResultArrived(int resultCode, Intent intent) {
// TODO Auto-generated method stub
try {
if( intent != null) {
Uri imageUri = (intent.getExtras()).getParcelable(ScanActivity.SCAN_RESULT);
if( imageUri != null) {
InputStream imageStream = ba.context.getContentResolver().openInputStream(imageUri);
Bitmap scannedImage = BitmapFactory.decodeStream(imageStream);
ba.context.getContentResolver().delete(imageUri, null, null);
BitmapWrapper bm = new BitmapWrapper();
bm.setObject(scannedImage);
ba.raiseEvent(this, eventName + "_oncameraresult",scannedImage);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
};
ba.startActivityForResult(ion, intent);
}
public void openGalery(){
intent = new Intent("com.example.monscanner.ScanActivity");
intent.putExtra(ScanConstants.OPEN_INTENT_PREFERENCE, ScanConstants.OPEN_GALERIE);
ion = new IOnActivityResult() {
@Override
public void ResultArrived(int resultCode, Intent intent) {
// TODO Auto-generated method stub
try {
if( intent != null) {
Uri imageUri = (intent.getExtras()).getParcelable(ScanActivity.SCAN_RESULT);
if( imageUri != null) {
InputStream imageStream = ba.context.getContentResolver().openInputStream(imageUri);
Bitmap scannedImage = BitmapFactory.decodeStream(imageStream);
ba.context.getContentResolver().delete(imageUri, null, null);
BitmapWrapper bm = new BitmapWrapper();
bm.setObject(scannedImage);
ba.raiseEvent(this, eventName + "_ongaleryresult",scannedImage);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
};
ba.startActivityForResult(ion, intent);
}
}
This the try with JavaObject
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#AdditionalJar:monscanner-release.androidx.aar
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private ion As Object
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
ShowPicker
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ShowPicker
Dim i As Intent
i.Initialize("com.example.monscanner.ScanActivity", "")
i.PutExtra("open_intent_preference", 1)
StartActivityForResult(i)
End Sub
Sub ion_Event (MethodName As String, Args() As Object) As Object
'Args(0) = resultCode
'Args(1) = intent
Return Null
End Sub
Sub StartActivityForResult(i As Intent)
Dim jo As JavaObject = GetBA
ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub
Sub GetBA As Object
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls)
Return jo.GetField("processBA")
End Sub
What am I doing wrong. Advice to make this work correctly.