Ink API הוא מודולרי, כך שאפשר להשתמש רק במה שצריך.
תנועות
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 by theInProgressStrokescomposable.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.
גיאומטריה
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, 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.
יצירת תוכן
מודול הכתיבה Compose מאפשר לכם לתעד קלט מגע של משתמשים ולהציג אותו כמשיכות מכחול במסך בזמן אמת עם השהיה נמוכה. האפקט הזה מושג באמצעות רכיב ה-Composable InProgressStrokes, שמעבד אירועי תנועה ומציג את הקווים בזמן שהם מצוירים.
אחרי שמסיימים לצייר צורה, הקומפוננטה הקומפוזבילית שולחת הודעה לאפליקציית הלקוח באמצעות קריאה חוזרת (callback) של InProgressStrokesFinishedListener. כך האפליקציה יכולה לאחזר את הקווים המוגמרים לצורך עיבוד או אחסון.
ב-Compose, InProgressStrokes מקבלת את הקריאה החוזרת הזו בפרמטר onStrokesFinished. מעבירים את הקווים המוגמרים לרכיב אחר שאפשר להוסיף כדי להציג אותם במסך באמצעות מודול העיבוד.
רינדור
מודול העיבוד מפשט את ציור המשיכות של הדיו ב-Android Canvas.
הוא מספק CanvasStrokeRenderer לכתיבה וViewStrokeRenderer לפריסות מבוססות-תצוגה. המעבדים האלה מבצעים אופטימיזציה של ביצועי העיבוד ועוזרים לספק תוכן ויזואלי באיכות גבוהה, כולל החלקת קצוות.
כדי לעבד את הקווים, קוראים ל-method create() כדי לקבל מופע CanvasStrokeRenderer, ואז קוראים ל-method draw() כדי לעבד קווים שהושלמו (Stroke) או קווים בתהליך (InProgressStroke) על Canvas.
אפשר לשנות את הצורה של הקנבס כשמציירים קו. לדוגמה, הזזה, שינוי גודל וסיבוב. כדי שהקו יופיע בצורה נכונה, צריך להעביר גם את טרנספורמציית canvas אל CanvasStrokeRenderer.draw.
כדי להימנע ממעקב נפרד של טרנספורמציית canvas, משתמשים במקום זאת ב-ViewStrokeRenderer.
אחסון
The storage module provides utilities for
efficiently serializing and deserializing stroke data, primarily focusing
on StrokeInputBatch.
The module uses protocol buffers and optimized delta compression techniques, resulting in significant storage savings compared to naive methods.
The storage module simplifies saving, loading, and sharing strokes.