Q: I looked at the documentation for PDFViewCtrl.Tool and PDFViewCtrl.ToolManager but am still a little confused as to how to create a toolmanager. The sample code calls:
mPDFView.setToolManager
which takes an instantiated ToolManager from pdftron.PDF.Tools. What is the base class of ToolManager? Does it matter as long as it interfaces PDFViewCtrl.ToolManager?
A:
The sample code has the following two lines:
pdftron.PDF.Tools.ToolManager tm = new pdftron.PDF.Tools.ToolManager();
mPDFView.setToolManager™;
So, you create a tool manager instance and associate it with PDFViewCtrl by calling setToolManager().
If you take a look at the online documentation at http://www.pdftron.com/pdfnet/mobile/Javadoc/index.html (please navigate to PDFViewCtrl.ToolManager), you will find the following:
Tool manager interface that is used for creating tools. PDFViewCtrl uses this interface, together with PDFViewCtrl.Tool
interface, to interact with user-defined functional modules.
For example, in PDFViewCtrl’s PDFViewCtrl.onScroll(MotionEvent, MotionEvent, float, float)
implementation, it has code similar to the following:
boolean handled = false;
int previous_tool_mode = mTool.getMode(), next_tool_mode;
do {
handled |= mTool.onMove(e1, e2, x_dist, y_dist);
next_tool_mode = mTool.getNextToolMode();
if (previous_tool_mode != next_tool_mode) {
mTool = mToolManager.createTool(next_tm, this, mTool);
previous_tool_mode = next_tool_mode;
} else {
break;
}
} while (true);
if (handled) {
return;
}
As shown above, Tool implementation decides what the next tool is. PDFViewCtrl uses PDFViewCtrl.Tool.getNextToolMode()
to get the type of the next tool, uses createTool(int, pdftron.PDF.PDFViewCtrl, pdftron.PDF.PDFViewCtrl.Tool)
to create the next tool, and calls the tool’s corresponding function, until the next tool is the same with the current tool. With this being said, a Tool implementation should prevent forming tools in a cyclic way. Note also that if the implementation’s PDFViewCtrl.Tool.onMove(MotionEvent, MotionEvent, float, float)
returns true, the subsequent code of PDFViewCtrl.onScroll(MotionEvent, MotionEvent, float, float)
won’t be executed, preventing the view from being scrolled.