I am developing an Android using PDFTron PDFNet SDK. I have just added the My script Geometry widget API so that I could recognise the symbols drawn or written by users. How can Integrate these tools?
Below is a code snippet for my project.
package com.myscript.atk.diagram.sample;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;
import com.myscript.atk.geometry.widget.GeometryWidgetApi;
import com.myscript.certificate.MyCertificate;
import com.pdftron.common.PDFNetException;
import com.pdftron.pdf.PDFNet;
public class Main3Activity extends AppCompatActivity implements
GeometryWidgetApi.OnConfigureListener,
GeometryWidgetApi.OnRecognitionListener
{
private static final String TAG = "GeometryDemo";
private GeometryWidgetApi widget;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try {
PDFNet.initialize(this,R.raw.pdfnet);
} catch (PDFNetException e) {
e.printStackTrace();
}
setContentView(R.layout.activity_main3);
// setContentView(R.layout.assessment_screen);
widget = (GeometryWidgetApi) findViewById(R.id.geometry_widget);
if (!widget.registerCertificate(MyCertificate.getBytes()))
{
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setMessage("Please use a valid certificate.");
dlgAlert.setTitle("Invalid certificate");
dlgAlert.setCancelable(false);
dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
//dismiss the dialog
}
});
dlgAlert.create().show();
return;
}
// Listen to widget events (see onConfigurationBegin and onRecognitionEnd APIs)
widget.setOnConfigureListener(this);
widget.setOnRecognitionListener(this);
// references assets directly from the APK to avoid extraction in application
// file system
widget.addSearchDir("zip://" + getPackageCodePath() + "!/assets/conf");
// The configuration is an asynchronous operation. Callbacks are provided to
// monitor the beginning and end of the configuration process and update the UI
// of the input method accordingly.
//
// "shape" references the shape bundle name in conf/shape.conf file in your assets.
// "standard" references the configuration name in shape.conf
widget.configure("shape", "standard");
}
@Override
protected void onDestroy()
{
widget.setOnRecognitionListener(null);
widget.setOnConfigureListener(null);
// release widget's resources
widget.release();
super.onDestroy();
}
@Override
public void onConfigurationBegin(GeometryWidgetApi widget)
{
}
@Override
public void onConfigurationEnd(GeometryWidgetApi widget, boolean success)
{
if(!success)
{
Toast.makeText(getApplicationContext(), widget.getErrorString(), Toast.LENGTH_LONG).show();
Log.e(TAG, "Unable to configure the Geometry Widget: " + widget.getErrorString());
return;
}
Toast.makeText(getApplicationContext(), "Geometry Widget Configured", Toast.LENGTH_SHORT).show();
if(BuildConfig.DEBUG)
Log.d(TAG, "Geometry Widget configured!");
}
@Override
public void onRecognitionBegin(GeometryWidgetApi widget)
{
}
@Override
public void onRecognitionEnd(GeometryWidgetApi widget)
{
Toast.makeText(getApplicationContext(), "Recognition update", Toast.LENGTH_SHORT).show();
if(BuildConfig.DEBUG)
{
Log.d(TAG, "Geometry Widget recognition");
}
}
}