import android.view.View;
import java.io.File;
-import java.sql.Time;
import cz.cvut.fel.dce.qrscanner.mupdf.MuPDFCore;
/**
- * Created by Michal Horn on 16.2.15.
+ * View for viewing PDF page.
+ *
+ * This view is designed to be used in two ways.
+ * 1) To view the PDF page itself on the device, which is supported by an interface for scrolling, zooming, switching pages and loading pages.
+ * 2) To load the PDF page to a bitmap, which can be accessed in the program by calling getPageBitmap() method.
*/
public class PdfPageView extends View {
/**
Log.i(TAG, "Pages: " + mPage.toString());
}
+ /**
+ * Get actual page. The actual page can be selected by setPage() method.
+ * @return actual page.
+ */
public int getActualPage() {
return mPage.getValue();
}
+ /**
+ * Get total number of pages in the document
+ * @return total number of pages
+ */
public int getLastPage() {
return mPage.getMaximum();
}
return mPage.setValue(page);
}
+ /**
+ * Load PDF and convert selected page to a bitmap.
+ *
+ * The page of the PDF document can be selected by setPage() method.
+ * This method can take significant time to finish. Consider calling it in separated thread.
+ */
public void loadPage() {
long startTime = System.currentTimeMillis();
try {
mYPosition = new IntervalValue<>(360.0f/2, -mSceneHeight+360.0f/2, mSceneHeight+360.0f/2);
mZoom = new IntervalValue<>(1.0f, 0.2f, 2.0f);
} catch (Exception e) {
- Log.e(TAG, "Error in setting page dimensions.");
+ Log.e(TAG, "Error in setting page dimensions: " + e.getMessage());
e.printStackTrace();
}
long endTime = System.currentTimeMillis();
}
}
+ /**
+ * Get PDF page bitmap
+ * @return Bitmap of the PDF page or null, if it has not been yet loaded.
+ */
public Bitmap getPageBitmap() {
return mPdfBitmap;
}
-
-
/**
* Set a listener of the events
* @param listener listener of the events
mListener = listener;
}
+ /**
+ * Clear listener.
+ */
public void clearListener() {
mListener = null;
}
if (!mPageLoaded) return;
float ratio = mZoom.getValue();
ratio += deltaRatio;
- if (mZoom.setValue(ratio) == true && mListener != null) {
+ if (mZoom.setValue(ratio) && mListener != null) {
mListener.onViewChanged(this);
}
}