モジュール

Ink API はモジュール化されているため、必要なものだけを使用できます。

ストローク

strokes モジュールは Ink API の基盤として機能します。このモジュールの主なデータ型は次のとおりです。

  • StrokeInputBatch: ポインタ入力の一連の動作を表します。位置、タイムスタンプ、必要に応じて圧力、傾き、向きを含みます。
  • InProgressStroke: 現在描画中のストロークを表します。InProgressStroke は、低レイテンシで部分的なストロークをレンダリングし、入力が完了したら最終的な Stroke を構築するために使用されます。その後、オブジェクトを再利用できます。 `InProgressStrokeInProgressStrokesView によって使用されます。
  • Stroke: ジオメトリが固定された確定済みのストロークの不変表現。各 Stroke には、ImmutableStrokeInputBatch(入力ポイント)、Brush(スタイル)、PartitionedMesh(幾何学模様)があります。アプリケーション内でストロークを保存、操作、レンダリングできます。

ジオメトリ

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.

ブラシ

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, and BrushFamily. BrushFamily is analogous to a font family, it defines a stroke's style. For example, a BrushFamily can 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-use BrushFamily instances.

オーサリング

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 モジュールは、Android の Canvas にインク ストロークを描画するのに役立ちます。Compose 用の CanvasStrokeRenderer と、ビューベースのレイアウト用の ViewStrokeRenderer が用意されています。これらのレンダラは、高パフォーマンスのレンダリング用に設計されており、アンチエイリアシングなどの高品質なビジュアルの提供に役立ちます。

ストロークをレンダリングするには、create() メソッドを呼び出して CanvasStrokeRenderer インスタンスを取得します。次に、draw() メソッドを呼び出して、完了したストローク(Stroke)または進行中のストローク(InProgressStroke)を Canvas にレンダリングします。

ストロークを描画するときに、キャンバスを変換できます。たとえば、パン、ズーム、回転などがあります。ストロークを正しくレンダリングするには、canvas 変換を CanvasStrokeRenderer.draw に渡す必要もあります。

canvas 変換を個別にトラッキングしないようにするには、代わりに ViewStrokeRenderer を使用します。

ストレージ

ストレージ モジュールは、ストローク データを効率的にシリアル化および逆シリアル化するためのユーティリティを提供します。主に StrokeInputBatch に重点を置いています。

このモジュールは、プロトコル バッファと最適化されたデルタ圧縮技術を使用しているため、単純な方法と比較してストレージを大幅に節約できます。

ストレージ モジュールを使用すると、ストロークの保存、読み込み、共有が簡単になります。