i have a javalibrarywrapper where i want to raise a event in b4a
For testing i put code to write the bitmap directly from the java-library... This works; the files are written here...
the sub in b4a do exists and seems to have the right signature
The log Raising... appears in b4as log
but the event do not raise. Why?
B4X:
final ParcelFileDescriptor pfd = openFile(dir,filename);
try {
PdfRenderer renderer = new PdfRenderer(pfd);
app.Log("renderer");
// let us just render all pages
final int pageCount = renderer.getPageCount();
app.Log("pagecound "+pageCount);
for (int i = 0; i < pageCount; i++) {
Page page = renderer.openPage(i);
app.Log("page open "+i);
int w = page.getWidth();
int h = page.getHeight();
// say we render for showing on the screen
Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
Bitmap mBitmap = Bitmap.createBitmap(w, h, conf);
Rect r = new Rect(0, 0, w, h);
page.render(mBitmap, r, null, page.RENDER_MODE_FOR_PRINT); // .RENDER_MODE_FOR_DISPLAY);
// do stuff with the bitmap
String file_path = destpath;
File dir1 = new File(file_path);
if(!dir1.exists())
dir1.mkdirs();
File file = new File(dir1, filename+"-" + i + ".png");
FileOutputStream fOut = new FileOutputStream(file);
mBitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
app.Log(filename+"-" + i + ".png written to "+file_path);
if (app.subExists(eventName + "_pagerendered")) {
app.Log("Raising.. "+eventName + "_pagerendered()");
app.raiseEvent(app.context, eventName+"_pagerendered", i, pageCount, mBitmap);
}else {
BA.Log("NOTFOUND '"+eventName + "_pagerendered");
}
app.raiseEvent(app.context, eventName+"_pagerendered", i, pageCount, mBitmap); //
// close the page
page.close();
}
renderer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
For testing i put code to write the bitmap directly from the java-library... This works; the files are written here...
the sub in b4a do exists and seems to have the right signature
B4X:
if (app.subExists(eventName + "_pagerendered")) {
app.Log("Raising.. "+eventName + "_pagerendered()");
but the event do not raise. Why?
B4X:
@Events(values={"pagerendered (page As Int, pagecount As Int, image As Bitmap)"})
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
File.Copy(File.DirAssets,"pdfformularbeispiel.pdf",File.DirRootExternal,"pdfformularbeispiel.pdf")
pdfr.Initialize("pdf",File.DirRootExternal,"pdfformularbeispiel.pdf", File.DirRootExternal&"/PDFs")
End Sub
Sub pdf_pagerendered (page As Int, pagecount As Int, image As Bitmap)
Log("b4a pagerendered ("&page&","&pagecount&")")
Dim bdw As BitmapDrawable
bdw.Initialize(image)
Activity.Background = bdw
End Sub