Ink API is modularized, so you can use only what you need.
Strokes
The strokes module serves as the foundation of the Ink API. Key data types within this module are:
StrokeInputBatch: Represents a series of pointer inputs, including their position, timestamp, and optionally pressure, tilt, and orientation.InProgressStroke: Represents a stroke that is actively being drawn.InProgressStrokeis used to render partial strokes with low latency and to build the finalStrokeonce input is complete, after which the object can be reused. `InProgressStrokeis used byInProgressStrokesView.Stroke: An immutable representation of a finalized stroke with fixed geometry. EachStrokehas anImmutableStrokeInputBatch(input points), aBrush(style), and aPartitionedMesh(geometric shape). You can store, manipulate, and render strokes within your application.
Geometry
The Geometry module supports geometric operations on primitive shapes (using dedicated classes like Box and Vec), as well as arbitrary shapes (using PartitionedMesh), including intersection detection and transformation. PartitionedMesh can also hold additional data to support rendering.
Brush
The brush module defines the style of strokes. It
consists of two main parts:
Brush: Specifies the style of a stroke including base color, base size, andBrushFamily.BrushFamilyis analogous to a font family, it defines a stroke's style. For example, aBrushFamilycan represent a specific style of marker or highlighter, allowing strokes with different sizes and colors to share that style.StockBrushes: Provides factory functions for creating ready-to-useBrushFamilyinstances.
Authoring
The Authoring module lets you capture user pointer input and render it as low-latency strokes on the screen in real time. It provides an InProgressStrokesView, which processes motion events and displays the strokes as they are drawn.
Once a stroke is completed, the view notifies the client application by means
of a registered callback
(InProgressStrokesFinishedListener). The callback lets
the application retrieve the finished stroke for rendering or storage.
Rendering
The Rendering module helps you draw ink strokes onto an Android
Canvas.
It provides CanvasStrokeRenderer for Compose and
ViewStrokeRenderer for view-based layouts. These
renderers are designed for high-performance rendering and help deliver
high-quality visuals, including antialiasing.
To render strokes, call the create() method to get a
CanvasStrokeRenderer instance. Then, call the draw() method to
render either finished (Stroke) or in-progress
(InProgressStroke) strokes onto a Canvas.
You can transform the canvas when you draw a stroke. Examples include panning,
zooming, and rotating. To render the stroke correctly, you must also pass the
canvas transform to CanvasStrokeRenderer.draw.
To avoid tracking the canvas transform separately, use
ViewStrokeRenderer instead.
Storage
存储模块提供用于高效序列化和反序列化笔画数据的实用程序,主要侧重于 StrokeInputBatch。
该模块使用 Protocol Buffer 和优化的增量压缩技术,与简单的方法相比,可显著节省存储空间。
存储模块简化了笔画的保存、加载和分享。