How 1993hzw/doodle works
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).