Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

PdfViewer

Kordian Bruck edited this page Aug 9, 2017 · 2 revisions

Introduction

The integration of a PdfViewer allows a userfriendly way of displaying Pdf-files without leaving the TCA app. Therefore it was necessary to implement a new fragment: "PdfViewFragment". It uses the dependency: https://github.com/barteksc/AndroidPdfViewer

barteksc's AndroidPdfViewer

The dependency introduces a new view called "PDFView", which is the only UI component of the fragment. In its onResume() method, it loads the currently referenced pdf file. After it is loaded, the pdf is automatically displayed. To verify that a file is a pdf file, the method isFilePdf checks the first four bytes of the file for the String "%PDF". To change the currently assigned pdf file, it's necessary to call the fragment's setPdf(File) method. Before the assignment is done, isFilePdf is evaluated, so that there are only valid Pdfs assigned. Additionally it was necessary to call the pdfView's fitToWidth() each time a layout change occured. (addOnLayoutChangeListener) This way the pdf gets correctly resized when the user holds the phone horizontally.

Usage

This fragment is currently in use in the PlansActivity. Originally it contained a listview of all the plans. The view has been moved to a PlansViewFragment. This made it possible to swap out the PlansViewFragment (containing the list) with the PdfViewFragment. That makes it possible to click a pdf plan within the listview and instantly display it in the PdfViewFragment.