I am trying to integrate the AndroidPDFViewer by barteksc into my CodenameOne app using a native interface to add this code. I would like to create the PDFView, return it as a View in the native interface, and use it as a PeerComponent in my project. When I made the Java interface file in my regular CN1 code, my return value was PeerComponent and the native interface generator set the return value of that interface method as View.
I have used this library before while creating a native Android app in Android Studio and it works great. However, my CN1 project can't seem to find the xml layout for the PDFView, which would normally would be in an Android xml file. This is what the xml would look like, as per the GitHub page:
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Using CN1 build hints, I added the following to the .properties file:
codename1.arg.android.cusom_layout1= <?xml version="1.0" encoding="utf-8"?><com.github.barteksc.pdfviewer.PDFView android:id="@+id/pdfView" android:layout_width="match_parent" android:layout_height="match_parent"/>
In my Android native interface, I added the following code (with the appropriate imports, no errors there):
LayoutInflater li = LayoutInflater.from(com.codename1.impl.android.AndroidNativeUtil.getActivity().getApplicationContext());
View theview = li.inflate(R.layout.cusom_layout1, null, false);
PDFView pdfView = (PDFView)theview.findViewById(R.id.pdfView);
/*(PDFView)findViewById(R.id.pdfView);*/
if (param1) {
pdfView.fromBytes(param)
.pages(1)
.onError(onErrorListener)
.onTap(onTapListener)
.enableSwipe(false)
.enableDoubletap(false)
.load();
} else {
pdfView.fromBytes(param)
.onError(onErrorListener)
.onTap(onTapListener)
.enableSwipe(false)
.enableDoubletap(false)
.load();
}
return (View)pdfView;
I got this error; it looks like it can't find the layout but I don't know how to connect the layout with the format for initializing the PDFView in the Java code (according to the docs, it needs to reference the View ID).
Exception: android.view.InflateException - Binary XML file line #1: Binary XML file line #1: Error inflating class PDFView
Any ideas? Thank you!