# dimuthuupe/androidpdfviewer architecture

> Architecture diagram of the GitHub repository dimuthuupe/androidpdfviewer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dimuthuupe/androidpdfviewer
- Repository: https://github.com/dimuthuupe/androidpdfviewer

## Overview

##### Project type and purpose
- This is an Android library (“android-pdf-viewer” module) for embedding PDF viewing capability into Android apps, plus a “sample” Android application module that demonstrates usage.
- The library provides a custom View (`PDFView`) that decodes PDF pages (via PdfiumAndroid native libs), handles gestures/animations, caching, link handling, and exposes a fluent Configurator API.

##### File structure
- Top-level:
- android-pdf-viewer/    ← library module
- sample/                ← demo Android app
- gradle wrapper, settings.gradle, root build.gradle
- Inside the library:
- java/com/github/barteksc/pdfviewer/ – core classes
- sub-packages: exception, link, listener (observer callbacks), model, scroll, source (DocumentSource implementations), util
- res/ – drawable scroll handles, attrs, styles
- build scripts (build.gradle, bintray.gradle)
- Inside the sample:
- PDFViewActivity – shows layout with `<com.github.barteksc.pdfviewer.PDFView>`
- sample.pdf in assets
- layouts, menus, resource qualifiers, strings, styles

##### README for additional insights
- Confirms architecture: PDFView is entry point, Configurator builder pattern, multiple DocumentSource providers, listener callbacks, scroll handle interface, link handler interface.
- Uses PdfiumAndroid native library under the hood for decoding.

##### Essential architectural elements
[Sample App UI] → [PDFView widget] → [Configurator] → [DocumentSource] → [PagesLoader] → [DecodingAsyncTask] → [PdfiumAndroid native] → [Bitmap] → [RenderingHandler] → [Canvas/UI]
- Around it, overlay:
- Gesture managers (DragPinchManager, AnimationManager) intercepting UI events
- CacheManager caching bitmaps
- Listener interfaces & LinkHandle entry points

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Sample App Module
    subgraph "Sample App" 
        direction TB
        SA1["PDFViewActivity"]:::sample
        SA2["Layout (activity_main.xml)"]:::sample
        SA3["PDF Asset (sample.pdf)"]:::sample
    end

    %% Library Module
    subgraph "AndroidPdfViewer Library"
        direction TB
        %% UI Component
        L1["PDFView"]:::library
        L2["Configurator"]:::library

        %% Source Providers
        subgraph "DocumentSource Providers"
            direction TB
            DS["DocumentSource (interface)"]:::interface
            AS["AssetSource"]:::library
            FS["FileSource"]:::library
            IS["InputStreamSource"]:::library
            US["UriSource"]:::library
            BS["ByteArraySource"]:::library
        end

        %% Decoding Pipeline
        subgraph "Decoding"
            direction TB
            PL["PagesLoader"]:::library
            DT["DecodingAsyncTask"]:::library
            PF["PdfFile"]:::library
        end

        %% Rendering
        RH["RenderingHandler"]:::library

        %% Caching
        CM["CacheManager"]:::library

        %% Event & Gesture Managers
        GM1["DragPinchManager"]:::library
        GM2["AnimationManager"]:::library

        %% Handlers & Interfaces
        subgraph "Extensibility"
            direction TB
            LH["LinkHandler (interface)"]:::interface
            DLH["DefaultLinkHandler"]:::library
            SH["ScrollHandle (interface)"]:::interface
            DSH["DefaultScrollHandle"]:::library
            LI["Listener Interfaces"]:::interface
        end

        %% Util & Exceptions
        subgraph "Utilities & Exceptions"
            direction TB
            UTIL["Utility Classes"]:::library
            EXC["Exception Classes"]:::library
        end
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        NATIVE["PdfiumAndroid (.so)"]:::external
        ANDROID["Android Canvas & View"]:::external
    end

    %% Sample App to Library
    SA1 -->|"includes PDFView in layout"| SA2
    SA1 -->|"loads asset"| SA3
    SA1 -->|"invokes"| L1
    SA1 -->|"uses layout attrs"| L2

    %% Configuration & Source Flow
    L1 -->|"fromXxx() calls"| L2
    L2 -->|"initializes"| DS
    DS --> AS
    DS --> FS
    DS --> IS
    DS --> US
    DS --> BS

    %% Decoding Flow
    DS -->|"provides DocumentSource to"| PL
    PL -->|"enqueues"| DT
    DT -->|"creates"| PF
    DT -->|"invokes native decode"| NATIVE
    NATIVE -->|"returns Bitmaps"| DT

    %% Rendering Flow
    DT -->|"delivers Bitmaps to"| RH
    RH -->|"draws to Canvas via"| ANDROID
    RH --> L1

    %% Caching
    RH --> CM
    DT --> CM

    %% Gesture & Event Flow
    ANDROID --> GM1
    ANDROID --> GM2
    GM1 --> L1
    GM2 --> L1

    %% Handlers & Listeners
    L1 --> LH
    L1 --> SH
    LH --> DLH
    SH --> DSH
    L1 --> LI
    LI --> SA1

    %% Utils & Exceptions
    L1 --> UTIL
    DT --> EXC
    PF --> EXC

    %% Click Events - Sample App
    click SA1 "https://github.com/dimuthuupe/androidpdfviewer/blob/master/sample/src/main/java/com/github/barteksc/sample/PDFViewActivity.java"
    click SA2 "https://github.com/dimuthuupe/androidpdfviewer/blob/master/sample/src/main/res/layout/activity_main.xml"
    click SA3 "https://github.com/dimuthuupe/androidpdfviewer/blob/master/sample/src/main/assets/sample.pdf"

    %% Click Events - Library
    click L1 "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/PDFView.java"
    click DS "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/source/DocumentSource.java"
    click AS "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/source/AssetSource.java"
    click FS "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/source/FileSource.java"
    click IS "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/source/InputStreamSource.java"
    click US "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/source/UriSource.java"
    click BS "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/source/ByteArraySource.java"
    click PL "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/PagesLoader.java"
    click DT "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/DecodingAsyncTask.java"
    click PF "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/PdfFile.java"
    click RH "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/RenderingHandler.java"
    click CM "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/CacheManager.java"
    click GM1 "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/DragPinchManager.java"
    click GM2 "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/AnimationManager.java"
    click LH "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/link/LinkHandler.java"
    click DLH "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/link/DefaultLinkHandler.java"
    click SH "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/scroll/ScrollHandle.java"
    click DSH "https://github.com/dimuthuupe/androidpdfviewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/scroll/DefaultScrollHandle.java"

    %% Styles
    classDef sample fill:#b2f2bb,stroke:#2f9e44,color:#000
    classDef library fill:#74c0fc,stroke:#1c7ed6,color:#000
    classDef external fill:#ffd43b,stroke:#f08c00,color:#000
    classDef interface stroke-dasharray: 5 5,fill:#ffe8cc,stroke:#d9480f,color:#000
    class SA1,SA2,SA3 sample
    class L1,L2,AS,FS,IS,US,BS,PL,DT,PF,RH,CM,GM1,GM2,DLH,DSH,UTIL,EXC library
    class DS,LH,SH,LI interface
```
