How nandodev1997/neoprinter-sdk-android works
1. Repository type and runtime
- This is an Android library module (NeoPrinterSDK) written in Kotlin, designed to be consumed by other Android apps.
- It targets ESC/POS thermal printing and exposes both Kotlin DSL and Java-friendly callback/builder APIs.
2. Top-level architecture
- The library is organized around a single orchestration layer, PrinterManager, which coordinates:
- permission checks,
- printer discovery/selection,
- connection creation,
- print execution,
- and network diagnostics.
- Around that core are smaller, focused components for transport, UI, and print command building.
3. Connection/transport layer
- The repo clearly supports two printer transport paths:
- Bluetooth via BluetoothPrinter.kt
- TCP/IP network via NetworkPrinter.kt
- These are the concrete device-connection boundaries, separating transport details from the higher-level printing API.
4. Printer abstraction and catalog
- PrinterDevice.kt likely represents a printer identity/configuration model used across the SDK.
- PrinterCatalog.kt suggests a saved or known-printer registry that the picker and manager use to present available devices.
- This creates a clean split between device metadata and live connection objects.
5. Main orchestration service
- PrinterManager.kt is the central façade.
- From the README, it appears to provide methods such as:
- opening the picker and connecting,
- running ping/network checks,
- and likely mediating access to the builder-based print API.
- For an architecture diagram, this is the main hub that connects UI, permissions, catalog, and transport.
6. Print command construction
- PrintBuilder.kt is the print-engine layer.
- It exposes a fluent/DSL-style API for composing ESC/POS commands: text formatting, layout rows, dividers, QR/barcodes, bitmap output, paper feed, cut, and drawer pulse.
- This is the key boundary between application content generation and printer-specific command encoding.
7. User-facing selection flow
- PrinterPickerDialog.kt provides the UI for discovering or choosing printers.
- The README indicates pickAndConnect(...) opens this dialog, then returns a connection on success.
- This makes the selection flow: user action → picker dialog → chosen device → connection setup.
8. Permission boundary
- PrinterPermissionHelper.kt encapsulates runtime permission handling, especially important for:
- Bluetooth permissions on Android 12+,
- location-related access for discovery,
- and internet access for network printers.
- This isolates Android permission complexity from the rest of the SDK.
9. Progress / feedback UI
- PrintingProgressDialog.kt indicates a small UI component for showing print-related progress or connection status.
- This suggests the SDK includes user feedback during potentially long operations like connecting, discovering, or sending print jobs.
10. Error model
- PrinterException.kt is the library’s dedicated failure boundary.
- It likely normalizes transport, permission, discovery, and print-command errors into a consistent exception type for consumers.
11. Support for Kotlin and Java consumers
- The README shows both Kotlin DSL usage and Java callback-based usage.
- That implies the public API is designed to be language-interoperable, with the core fluent API wrapped in Java-compatible entry points where needed.
12. Resources and Android packaging
- The res/ folder contains icons, colors, styles, and strings used by the picker/progress UI.
- Drawable assets differentiate Bluetooth vs network printers visually, reinforcing the two transport types in the UI.
- Gradle/Kotlin build files and jitpack.yml show this is intended for publishing as a reusable dependency.
13. Data flow summary
- Typical flow is:
- app requests permission via PrinterPermissionHelper,
- PrinterManager opens PrinterPickerDialog,
- user selects a PrinterDevice from the PrinterCatalog,
- a BluetoothPrinter or NetworkPrinter connection is created,
- PrintBuilder generates ESC/POS commands,
- commands are sent to the printer,
- success/failure is returned to the caller.
14. Architectural boundaries to draw
- For a diagram, the main boundaries are:
- Host app vs NeoPrinter SDK
- Permission/UI layer vs core orchestration
- Print composition vs transport execution
- Bluetooth vs TCP/IP network as parallel adapter paths
- Reusable models/catalog vs runtime connections
Main entry points: PrinterManager.kt Printer Manager · PrinterPickerDialog.kt Picker Dialog · PrintBuilder.kt Print Builder · PrintingProgressDialog.kt Progress Dialog
Components 16
SDK Core
Public orchestration, models, and print composition
- Printer Manager · Main entry point coordinating permissions, picker, transport, and print flow
NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterManager.kt - Permissions · Handles runtime permission checks for Bluetooth, discovery, and network access
NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterPermissionHelper.kt - Printer Catalog · Saved or known printers available for selection
NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterCatalog.kt - Printer Device · Printer identity and configuration data
NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterDevice.kt - Print Builder · Fluent ESC/POS command builder for text, layout, images, codes, feed, cut, and drawer pulse
NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrintBuilder.kt - Printer Error · Unified exception boundary for permission, discovery, transport, and print failures
NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterException.kt
Transports
Printer connection adapters
- Bluetooth Printer · Bluetooth connection and send path
NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/BluetoothPrinter.kt - Network Printer · TCP/IP connection and diagnostics path
NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/NetworkPrinter.kt
Android UI
Picker and progress screens
- Picker Dialog · UI for discovering and choosing a printer
NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrinterPickerDialog.kt - Progress Dialog · Feedback UI for connect and print operations
NeoPrinterSDK/src/main/java/com/nandodev1997/neoprintersdk/PrintingProgressDialog.kt
Resources
Icons, strings, colors, and styles
- Strings · UI text and labels used by the dialogs
NeoPrinterSDK/src/main/res/values/strings.xml - Colors · Theme and status colors
NeoPrinterSDK/src/main/res/values/colors.xml - Styles · Dialog and UI styling definitions
NeoPrinterSDK/src/main/res/values/styles.xml - BT Icon · Bluetooth printer icon
NeoPrinterSDK/src/main/res/drawable/ic_printer_bt.xml - Net Icon · Network printer icon
NeoPrinterSDK/src/main/res/drawable/ic_printer_network.xml
Other components
- Host App · Android app embedding the SDK
Connections 21
- Host App → Printer Manager: uses · App calls the SDK façade
- Printer Manager → Permissions: checks · Validates runtime access before discovery or connection
- Printer Manager → Picker Dialog: opens · Starts printer selection flow
- Printer Manager → Printer Catalog: reads · Uses saved or known printers for selection
- Picker Dialog → Printer Device: selects · Returns the chosen printer identity
- Printer Catalog → Printer Device: contains · Registry of printer metadata
- Printer Manager → Bluetooth Printer: connects · Creates Bluetooth printer sessions
- Printer Manager → Network Printer: connects · Creates TCP/IP printer sessions
- Printer Manager → Print Builder: executes · Sends built ESC/POS jobs to the active transport
- Print Builder → Bluetooth Printer: encodes for · Produces commands for Bluetooth delivery
- Print Builder → Network Printer: encodes for · Produces commands for network delivery
- Picker Dialog → Strings: labels · Uses resource text in the picker UI
- Picker Dialog → Styles: styles · Uses dialog styling
- Progress Dialog → Strings: labels · Uses resource text in the progress UI
- Progress Dialog → Colors: themes · Uses status and theme colors
- Picker Dialog → BT Icon: shows · Visualizes Bluetooth printers
- Picker Dialog → Net Icon: shows · Visualizes network printers
- Printer Manager → Progress Dialog: shows · Displays feedback during connect and print operations
- Printer Manager → Printer Error: throws · Normalizes failures into a shared error type
- Bluetooth Printer → Printer Error: reports · Surfaces transport errors
- Network Printer → Printer Error: reports · Surfaces transport and diagnostic errors