package com.qoppa; import java.util.Vector; import com.qoppa.android.pdf.Bookmark; import com.qoppa.android.pdf.PDFException; import com.qoppa.android.pdfProcess.PDFDocument; import com.qoppa.android.pdfViewer.actions.Action; import com.qoppa.android.pdfViewer.actions.GotoPageAction; import com.qoppa.notes.QPDFNotesView; import com.qoppa.viewer.listeners.DocumentListener; import android.app.Activity; import android.os.Bundle; public class GotoFirstSample extends Activity { public QPDFNotesView notes; protected void onCreate(Bundle bundle) { super.onCreate(bundle); notes = new QPDFNotesView(this); notes.setActivity(this); // listen for when a document is opened notes.addDocumentListener(new DocumentListener(){ @Override public void documentOpened() { goToFirstBookmark(); } @Override public void documentSaved(String previousPath){} @Override public void zoomChanged(float zoom){} }); setContentView(notes); } private void goToFirstBookmark() { PDFDocument doc = notes.getDocument(); if (doc != null) { try { // loop through the bookmarks Bookmark root = doc.getRootBookmark(); GotoPageAction action = findGotoPageAction(root); if (action != null) { notes.handleAction(action); } } catch (PDFException e) { e.printStackTrace(); } } } // Find the first GotoPageAction in the Bookmark's children private GotoPageAction findGotoPageAction(Bookmark parent) { if (parent == null) { return null; } // Look for a GotoPageAction in each child bookmark Vector children = parent.getChildren(); if (children != null) { // loop through the child bookmarks for (Bookmark child : children) { // look through the bookmark's actions Vector actions = child.getActions(); if (actions != null) { for (Action action : actions) { if (action instanceof GotoPageAction) { return (GotoPageAction) action; } } } // Not found in this bookmark's actions, so look though it's child bookmarks GotoPageAction action = findGotoPageAction(child); if (action != null) { return action; } } } return null; } }