# 1993hzw/doodle architecture

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

- Interactive diagram: https://gitdiagram.com/1993hzw/doodle
- Repository: https://github.com/1993hzw/doodle

## Overview

##### Project Type and Purpose
- The README emphasizes two usage methods: launching a pre-built DoodleActivity or embedding a DoodleView in a custom layout. This indicates that the library is intended to be integrated into various Android projects for drawing purposes.

##### Analyzing the File Structure
- Two major directories:
- The "app" module: Contains AndroidManifest.xml, Java files such as MainActivity.java, MosaicDemo.java, and guide activities to demo features. This module shows how the doodle library can be integrated and used.
- The "doodle" module: Contains the core library files. It includes a variety of subpackages such as:
▪ Core interfaces and base classes (under “doodle/src/main/java/cn/hzw/doodle/core”) – e.g., IDoodle, IDoodleItem, IDoodlePen, IDoodleShape etc.
▪ Implementations like DoodleView (which implements IDoodle) and DoodleActivity.
▪ UI dialog components (e.g., ColorPickerDialog, ColorPickerView) and additional helper classes (e.g., for image picking).
- Notice the separation of concerns: one module for the demo app (UI integration examples) and one for the library’s functional components.

a. UI/Demo Layer (App Module):
- DoodleActivity – acts as an entry point to the doodle interface.
- Demo fragments/activities (e.g., MainActivity, MosaicDemo, ScaleGestureItemDemo) – these illustrate different use cases of the doodle library.
b. Core Doodle Component (Doodle Module):
- DoodleView:
- This is the centerpiece of the library. It implements the IDoodle interface and manages drawing, item management (adding, removing, undo/redo), and the rendering process.
- It interacts with user input, draws items on a Bitmap canvas, and offers optimization features.
- Gesture Detection:
- DoodleTouchDetector along with DoodleOnTouchGestureListener handle gestures (touches, scrolls, scales) that affect doodle operations.
- Doodle Items and Customization APIs:
- The doodle items (e.g., DoodlePath, DoodleText, DoodleBitmap) extend DoodleItemBase or implement IDoodleItem.
- Relationships where DoodleView aggregates “Doodle Items,” and these items can be “customized” by developers using the provided interfaces.
- Utility and Helper Components:
- Classes such as DrawUtil, dialog components (ColorPickerDialog and ColorPickerView), and the image picker tools.
- These support the core functionality by handling drawing computations and user interface dialogs.

c. Communication and Data Flow:
- That the UI modules (like DoodleActivity) initialize and configure a DoodleView.
- DoodleView receives user input via the gesture detectors (DoodleTouchDetector and its listeners).
- Interaction events are propagated to modify the doodle items (creation, modification, deletion) and then re-rendered on the canvas.
- Data flow also occurs for saving the state of the doodle (i.e., the “save” method of IDoodle).

##### Architectural Patterns and Design Principles
- The project follows a modular design with clear separation between the demo application and the doodle library.
- It employs interface-based design (e.g., IDoodle, IDoodleItem, IDoodlePen) to support extensibility—allowing developers to swap or extend implementations easily.
- The use of a DoodleView as a central component supports the MVC or MVP-like separation where the view handles input and rendering based on a model (the state of all doodle items).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Demo Application (App Module)"
        MA["MainActivity"]:::demo
        MD["MosaicDemo"]:::demo
        SG["ScaleGestureItemDemo"]:::demo
        DGA["DoodleGuideActivity"]:::demo
    end

    subgraph "Doodle Library (Core Library)"
        subgraph "Core Doodle Engine"
            DA["DoodleActivity"]:::core
            DV["DoodleView"]:::core
        end
        subgraph "Input Handling"
            DTD["DoodleTouchDetector"]:::input
            DOT["DoodleOnTouchGestureListener"]:::input
        end
        subgraph "Doodle Items & Customization"
            DP["DoodlePath"]:::custom
            DT["DoodleText"]:::custom
            DB["DoodleBitmap"]:::custom
            DPen["DoodlePen"]:::custom
            DShape["DoodleShape"]:::custom
            CI["Core Interfaces"]:::custom
        end
        subgraph "Utilities & Helpers"
            DU["DrawUtil"]:::util
            CPD["ColorPickerDialog"]:::util
            CPV["ColorPickerView"]:::util
            IP["ImagePicker Tools"]:::util
        end
    end

    %% Demo Application launches Doodle Activity
    MA -->|"launches"| DA
    MD -->|"launches"| DA
    SG -->|"launches"| DA
    DGA -->|"launches"| DA

    %% DoodleActivity configures DoodleView
    DA -->|"configures"| DV

    %% Input handling directs user input to DoodleView
    DTD -->|"userInput"| DV
    DOT -->|"gestureEvents"| DV

    %% DoodleView interacts with doodle items & customization
    DV -->|"draws"| DP
    DV -->|"draws"| DT
    DV -->|"draws"| DB
    DV -->|"customizes"| DPen
    DV -->|"customizes"| DShape
    DV -->|"implements"| CI

    %% DoodleView utilizes utilities & helpers
    DV -->|"utilizes"| DU
    DV -->|"opens"| CPD
    DV -->|"opens"| CPV
    DV -->|"uses"| IP

    classDef demo fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef input fill:#FFFF99,stroke:#333,stroke-width:2px;
    classDef custom fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef util fill:#FFA500,stroke:#333,stroke-width:2px;

    %% Click Events for Demo Application Nodes
    click MA "https://github.com/1993hzw/doodle/blob/master/app/src/main/java/cn/hzw/doodledemo/MainActivity.java"
    click MD "https://github.com/1993hzw/doodle/blob/master/app/src/main/java/cn/hzw/doodledemo/MosaicDemo.java"
    click SG "https://github.com/1993hzw/doodle/blob/master/app/src/main/java/cn/hzw/doodledemo/ScaleGestureItemDemo.java"
    click DGA "https://github.com/1993hzw/doodle/blob/master/app/src/main/java/cn/hzw/doodledemo/guide/DoodleGuideActivity.java"

    %% Click Events for Doodle Library Components
    click DV "https://github.com/1993hzw/doodle/blob/master/doodle/src/main/java/cn/hzw/doodle/DoodleView.java"
    click DTD "https://github.com/1993hzw/doodle/blob/master/doodle/src/main/java/cn/hzw/doodle/DoodleTouchDetector.java"
    click DOT "https://github.com/1993hzw/doodle/blob/master/doodle/src/main/java/cn/hzw/doodle/DoodleOnTouchGestureListener.java"
    click DP "https://github.com/1993hzw/doodle/blob/master/doodle/src/main/java/cn/hzw/doodle/DoodlePath.java"
    click DT "https://github.com/1993hzw/doodle/blob/master/doodle/src/main/java/cn/hzw/doodle/DoodleText.java"
    click DB "https://github.com/1993hzw/doodle/blob/master/doodle/src/main/java/cn/hzw/doodle/DoodleBitmap.java"
    click DPen "https://github.com/1993hzw/doodle/blob/master/doodle/src/main/java/cn/hzw/doodle/DoodlePen.java"
    click DShape "https://github.com/1993hzw/doodle/blob/master/doodle/src/main/java/cn/hzw/doodle/DoodleShape.java"
    click CI "https://github.com/1993hzw/doodle/tree/master/doodle/src/main/java/cn/hzw/doodle/core/"
    click DU "https://github.com/1993hzw/doodle/blob/master/doodle/src/main/java/cn/hzw/doodle/util/DrawUtil.java"
    click CPD "https://github.com/1993hzw/doodle/blob/master/doodle/src/main/java/cn/hzw/doodle/dialog/ColorPickerDialog.java"
    click CPV "https://github.com/1993hzw/doodle/blob/master/doodle/src/main/java/cn/hzw/doodle/dialog/ColorPickerView.java"
    click IP "https://github.com/1993hzw/doodle/tree/master/doodle/src/main/java/cn/hzw/doodle/imagepicker/"
```
