InProgressStrokesView


public final class InProgressStrokesView extends FrameLayout


Displays in-progress ink strokes as MotionEvent user inputs are provided to it.

For a Jetpack Compose equivalent which also provides a default input handler, see androidx.ink.authoring.compose.InProgressStrokes instead.

The visual styles of strokes are highly customizable by passing the appropriate Brush to startStroke, but if that declarative style specification is not rich enough and instead some more detailed programmatic logic is necessary, consider using InProgressShapesView instead.

Summary

Public constructors

InProgressStrokesView(
    @NonNull Context context,
    AttributeSet attrs,
    @AttrRes int defStyleAttr
)

Public methods

final void

Add a listener to be notified when strokes are finished.

final boolean
addToStroke(
    @NonNull MotionEvent event,
    int pointerId,
    MotionEvent prediction
)

Add event data for pointerId to the corresponding in-progress stroke, if present.

final void
addToStroke(
    @NonNull StrokeInputBatch inputs,
    @NonNull InProgressStrokeId strokeId,
    @NonNull StrokeInputBatch prediction
)

Add input data from a StrokeInputBatch to an existing stroke.

final void
addToStroke(
    @NonNull MotionEvent event,
    int pointerId,
    @NonNull InProgressStrokeId strokeId,
    MotionEvent prediction
)

Add input data, from a particular pointer within a MotionEvent, to an existing stroke.

final boolean
cancelStroke(@NonNull MotionEvent event, int pointerId)

Cancel the corresponding in-progress stroke with event data for pointerId, if present.

final void

Cancel the building of a stroke.

final void

Cancel all in-progress strokes.

final void

Removes all listeners that had previously been added with addFinishedStrokesListener.

final void

Eagerly initialize rather than waiting for the first stroke to be drawn.

final boolean
finishStroke(@NonNull MotionEvent event, int pointerId)

Finish the corresponding in-progress stroke with event data for pointerId, if present.

final void
finishStroke(
    @NonNull StrokeInput input,
    @NonNull InProgressStrokeId strokeId
)

Complete the building of a stroke, with the last input data coming from a StrokeInput.

final void
finishStroke(
    @NonNull MotionEvent event,
    int pointerId,
    @NonNull InProgressStrokeId strokeId
)

Complete the building of a stroke, with the last input data coming from a particular pointer of a MotionEvent.

final @NonNull Map<@NonNull InProgressStrokeId, @NonNull Stroke>

Returns all the finished strokes that are still being rendered by this view, with map iteration order in the z-order that the strokes are being rendered, from back to front.

final CountingIdlingResource

Allows a test to easily wait until all in-progress strokes are completed and handed off.

final Path

Denote an area of this InProgressStrokesView where no ink should be visible.

final @NonNull Matrix

The transform matrix to convert MotionEvent coordinates, as passed to startStroke, addToStroke, and finishStroke, into coordinates of this InProgressStrokesView for rendering.

final @NonNull TextureBitmapStore

TextureBitmapStore used to create the CanvasStrokeRenderer.

final boolean

Returns true if there are any in-progress strokes.

final void

Stop this view from rendering the strokes with the given IDs.

final void

Removes a listener that had previously been added with addFinishedStrokesListener.

final void

Allows a test to easily wait until all in-progress strokes are completed and handed off.

final void
setMaskPath(Path <set-?>)

Denote an area of this InProgressStrokesView where no ink should be visible.

final void

The transform matrix to convert MotionEvent coordinates, as passed to startStroke, addToStroke, and finishStroke, into coordinates of this InProgressStrokesView for rendering.

final void

TextureBitmapStore used to create the CanvasStrokeRenderer.

final @NonNull InProgressStrokeId
startStroke(
    @NonNull StrokeInput input,
    @NonNull Brush brush,
    @NonNull Matrix strokeToViewTransform
)

Start building a stroke with the provided input.

final @NonNull InProgressStrokeId
startStroke(
    @NonNull MotionEvent event,
    int pointerId,
    @NonNull Brush brush,
    @NonNull Matrix motionEventToWorldTransform,
    @NonNull Matrix strokeToWorldTransform
)

Start building a stroke using a particular pointer within a MotionEvent.

Protected methods

void
void

Inherited methods

From android.view.accessibility.AccessibilityEventSource
From android.graphics.drawable.Drawable.Callback
void
void
scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when)
void
From android.widget.FrameLayout
@NonNull CharSequence
boolean

This method is deprecated. Deprecated in Java

boolean
void
setForegroundGravity(int foregroundGravity)
void
setMeasureAllChildren(boolean measureAll)
From android.view.KeyEvent.Callback
boolean
onKeyDown(int keyCode, @NonNull KeyEvent event)
boolean
onKeyLongPress(int keyCode, @NonNull KeyEvent event)
boolean
onKeyMultiple(int keyCode, int repeatCount, @NonNull KeyEvent event)
boolean
onKeyUp(int keyCode, @NonNull KeyEvent event)
From android.view.View
void
void
addExtraDataToAccessibilityNodeInfo(
    @NonNull AccessibilityNodeInfo info,
    @NonNull String extraDataKey,
    @Nullable Bundle arguments
)
void
addFocusables(@NonNull ArrayList<@NonNull View> views, int direction)
void
addFocusables(
    @NonNull ArrayList<@NonNull View> views,
    int direction,
    int focusableMode
)
void
addKeyboardNavigationClusters(
    @NonNull Collection<@NonNull View> views,
    int direction
)
void
void
void
void
@NonNull ViewPropertyAnimator
void

This method is deprecated. Deprecated in Java

void
void
boolean
boolean
awakenScrollBars(int startDelay)
boolean
awakenScrollBars(int startDelay, boolean invalidate)
void
void

This method is deprecated. Deprecated in Java

void
buildDrawingCache(boolean autoScale)

This method is deprecated. Deprecated in Java

void
boolean
boolean
boolean
boolean
boolean
canScrollHorizontally(int direction)
boolean
canScrollVertically(int direction)
final void
void
final void
boolean
void
void
void
void
int
int
int
void
@NonNull WindowInsets
computeSystemWindowInsets(
    @NonNull WindowInsets in,
    @NonNull Rect outLocalInsets
)
int
int
int
@NonNull AccessibilityNodeInfo
void
void

This method is deprecated. Deprecated in Java

@NonNull WindowInsets
boolean
void
void
dispatchCreateViewTranslationRequest(
    @NonNull Map<@NonNull AutofillId, @NonNull long[]> viewIds,
    @NonNull int[] supportedFormats,
    @Nullable TranslationCapability capability,
    @NonNull List<@NonNull ViewTranslationRequest> requests
)
void
boolean
void
void
dispatchDrawableHotspotChanged(float x, float y)
void
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
boolean
dispatchNestedPreFling(float velocityX, float velocityY)
boolean
dispatchNestedPrePerformAccessibilityAction(
    int action,
    @Nullable Bundle arguments
)
boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    @Nullable int[] consumed,
    @Nullable int[] offsetInWindow
)
boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    @Nullable int[] offsetInWindow
)
void
dispatchPointerCaptureChanged(boolean hasCapture)
boolean
void
dispatchProvideAutofillStructure(
    @NonNull ViewStructure structure,
    int flags
)
void
void
void
void
dispatchScrollCaptureSearch(
    @NonNull Rect localVisibleRect,
    @NonNull Point windowOffset,
    @NonNull Consumer<@NonNull ScrollCaptureTarget> targets
)
void
dispatchSetActivated(boolean activated)
void
dispatchSetPressed(boolean pressed)
void
dispatchSetSelected(boolean selected)
void
void

This method is deprecated. Deprecated in Java

boolean
boolean
boolean
dispatchUnhandledMove(@NonNull View focused, int direction)
void
dispatchVisibilityChanged(@NonNull View changedView, int visibility)
void
dispatchWindowFocusChanged(boolean hasFocus)
void
void
@NonNull WindowInsets
@NonNull WindowInsetsAnimation.Bounds
void

This method is deprecated. Deprecated in Java

void
void
draw(@NonNull Canvas canvas)
void
drawableHotspotChanged(float x, float y)
void
@NonNull View
final @Nullable OnBackInvokedDispatcher
final @NonNull T
<T extends View> findViewById(int id)
final @NonNull T
<T extends View> findViewWithTag(@NonNull Object tag)
void
findViewsWithText(
    @NonNull ArrayList<@NonNull View> outViews,
    @NonNull CharSequence text,
    int flags
)
boolean

This method is deprecated. Deprecated in Java

@NonNull View
focusSearch(int direction)
void
forceHasOverlappingRendering(boolean hasOverlappingRendering)
void
boolean
void
generateDisplayHash(
    @NonNull String hashAlgorithm,
    @Nullable Rect bounds,
    @NonNull Executor executor,
    @NonNull DisplayHashResultCallback callback
)
@NonNull View.AccessibilityDelegate
int
@NonNull AccessibilityNodeProvider
@Nullable CharSequence
int
int
@Nullable String
@Nullable String
float
@ViewDebug.ExportedProperty(category = "drawing")
getAlpha()
@NonNull Animation
@Nullable Matrix
@NonNull IBinder
@NonNull int[]
@NonNull Map<@NonNull Integer, @NonNull Integer>
@Nullable String[]
final @NonNull AutofillId
int
@Nullable AutofillValue
@NonNull Drawable
@Nullable BlendMode
@Nullable ColorStateList
@Nullable PorterDuff.Mode
int
@ViewDebug.ExportedProperty(category = "layout")
getBaseline()
final int
float
int
float
@NonNull Rect
final boolean
final @Nullable ContentCaptureSession
@NonNull CharSequence
@ViewDebug.ExportedProperty(category = "accessibility")
getContentDescription()
final int
final @NonNull Context
@NonNull ContextMenu.ContextMenuInfo
final boolean
@NonNull Display
final @NonNull int[]
@NonNull Bitmap

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

void
long
float
@ViewDebug.ExportedProperty(category = "drawing")
getElevation()
int
boolean
boolean
int
@ViewDebug.ExportedProperty(mapping = [@ViewDebug.IntToString(from = 0, to = "NOT_FOCUSABLE"), @ViewDebug.IntToString(from = 1, to = "FOCUSABLE"), @ViewDebug.IntToString(from = 16, to = "FOCUSABLE_AUTO")], category = "focus")
getFocusable()
@NonNull ArrayList<@NonNull View>
getFocusables(int direction)
void
@NonNull Drawable
int
@Nullable BlendMode
@Nullable ColorStateList
@Nullable PorterDuff.Mode
float
final boolean
boolean
@NonNull Handler
float
float
float
float
int
@Nullable Runnable
final boolean
final int
@ViewDebug.ExportedProperty(category = "layout")
getHeight()
void
int
int
@Nullable Drawable
@Nullable Drawable
int
int
@ViewDebug.ExportedProperty(category = "accessibility", mapping = [@ViewDebug.IntToString(from = 0, to = "auto"), @ViewDebug.IntToString(from = 1, to = "yes"), @ViewDebug.IntToString(from = 2, to = "no"), @ViewDebug.IntToString(from = 4, to = "noHideDescendants")])
getImportantForAccessibility()
int
@ViewDebug.ExportedProperty(mapping = [@ViewDebug.IntToString(from = 0, to = "auto"), @ViewDebug.IntToString(from = 1, to = "yes"), @ViewDebug.IntToString(from = 2, to = "no"), @ViewDebug.IntToString(from = 4, to = "yesExcludeDescendants"), @ViewDebug.IntToString(from = 8, to = "noExcludeDescendants")])
getImportantForAutofill()
int
@ViewDebug.ExportedProperty(mapping = [@ViewDebug.IntToString(from = 0, to = "auto"), @ViewDebug.IntToString(from = 1, to = "yes"), @ViewDebug.IntToString(from = 2, to = "no"), @ViewDebug.IntToString(from = 4, to = "yesExcludeDescendants"), @ViewDebug.IntToString(from = 8, to = "noExcludeDescendants")])
getImportantForContentCapture()
boolean
@NonNull KeyEvent.DispatcherState
int
@ViewDebug.ExportedProperty(category = "accessibility")
getLabelFor()
int
@ViewDebug.ExportedProperty(category = "drawing", mapping = [@ViewDebug.IntToString(from = 0, to = "NONE"), @ViewDebug.IntToString(from = 1, to = "SOFTWARE"), @ViewDebug.IntToString(from = 2, to = "HARDWARE")])
getLayerType()
int
@ViewDebug.ExportedProperty(category = "layout", mapping = [@ViewDebug.IntToString(from = 0, to = "RESOLVED_DIRECTION_LTR"), @ViewDebug.IntToString(from = 1, to = "RESOLVED_DIRECTION_RTL")])
getLayoutDirection()
@NonNull ViewGroup.LayoutParams
@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_")
getLayoutParams()
final int
float
int
final boolean
void
getLocationInSurface(@NonNull int[] location)
void
getLocationInWindow(@NonNull int[] outLocation)
void
getLocationOnScreen(@NonNull int[] outLocation)
@NonNull Matrix
final int
final int
@ViewDebug.ExportedProperty(category = "measurement", flagMapping = [@ViewDebug.FlagToString(mask = -16777216, equals = 16777216, name = "MEASURED_STATE_TOO_SMALL")])
getMeasuredHeightAndState()
final int
final int
final int
@ViewDebug.ExportedProperty(category = "measurement", flagMapping = [@ViewDebug.FlagToString(mask = -16777216, equals = 16777216, name = "MEASURED_STATE_TOO_SMALL")])
getMeasuredWidthAndState()
int
int
int
int
int
int
int
int
@NonNull View.OnFocusChangeListener
int
@NonNull ViewOutlineProvider
int
int
int
int
int
int
int
int
final @NonNull ViewParent
@NonNull ViewParent
final @Nullable OutcomeReceiver<@NonNull GetCredentialResponse, @NonNull GetCredentialException>
final @Nullable GetCredentialRequest
float
@ViewDebug.ExportedProperty(category = "drawing")
getPivotX()
float
@ViewDebug.ExportedProperty(category = "drawing")
getPivotY()
@NonNull PointerIcon
final @NonNull List<@NonNull Rect>
@Nullable String[]
float
@NonNull Resources
final boolean
final int
float
int
@Nullable AttachedSurfaceControl
@NonNull View
@NonNull WindowInsets
float
@ViewDebug.ExportedProperty(category = "drawing")
getRotation()
float
@ViewDebug.ExportedProperty(category = "drawing")
getRotationX()
float
@ViewDebug.ExportedProperty(category = "drawing")
getRotationY()
float
@ViewDebug.ExportedProperty(category = "drawing")
getScaleX()
float
@ViewDebug.ExportedProperty(category = "drawing")
getScaleY()
int
int
int
int
@ViewDebug.ExportedProperty(mapping = [@ViewDebug.IntToString(from = 0, to = "INSIDE_OVERLAY"), @ViewDebug.IntToString(from = 16777216, to = "INSIDE_INSET"), @ViewDebug.IntToString(from = 33554432, to = "OUTSIDE_OVERLAY"), @ViewDebug.IntToString(from = 50331648, to = "OUTSIDE_INSET")])
getScrollBarStyle()
int
int
final int
final int
int
@ViewDebug.ExportedProperty(category = "drawing")
getSolidColor()
int
final @Nullable CharSequence
@ViewDebug.ExportedProperty(category = "accessibility")
getStateDescription()
@NonNull StateListAnimator
int
int
@Nullable CharSequence
@NonNull List<@NonNull Rect>
int

This method is deprecated. Deprecated in Java

@NonNull Object
int
@ViewDebug.ExportedProperty(category = "text", mapping = [@ViewDebug.IntToString(from = 0, to = "INHERIT"), @ViewDebug.IntToString(from = 1, to = "GRAVITY"), @ViewDebug.IntToString(from = 2, to = "TEXT_START"), @ViewDebug.IntToString(from = 3, to = "TEXT_END"), @ViewDebug.IntToString(from = 4, to = "CENTER"), @ViewDebug.IntToString(from = 5, to = "VIEW_START"), @ViewDebug.IntToString(from = 6, to = "VIEW_END")])
getTextAlignment()
int
@ViewDebug.ExportedProperty(category = "text", mapping = [@ViewDebug.IntToString(from = 0, to = "INHERIT"), @ViewDebug.IntToString(from = 1, to = "FIRST_STRONG"), @ViewDebug.IntToString(from = 2, to = "ANY_RTL"), @ViewDebug.IntToString(from = 3, to = "LTR"), @ViewDebug.IntToString(from = 4, to = "RTL"), @ViewDebug.IntToString(from = 5, to = "LOCALE"), @ViewDebug.IntToString(from = 6, to = "FIRST_STRONG_LTR"), @ViewDebug.IntToString(from = 7, to = "FIRST_STRONG_RTL")])
getTextDirection()
@Nullable CharSequence
final int
float
int
@NonNull TouchDelegate
@NonNull ArrayList<@NonNull View>
float
@NonNull String
float
float
float
long
int
int
@Nullable Drawable
@Nullable Drawable
int
@Nullable ViewTranslationResponse
@NonNull ViewTreeObserver
int
@ViewDebug.ExportedProperty(mapping = [@ViewDebug.IntToString(from = 0, to = "VISIBLE"), @ViewDebug.IntToString(from = 4, to = "INVISIBLE"), @ViewDebug.IntToString(from = 8, to = "GONE")])
getVisibility()
final int
@ViewDebug.ExportedProperty(category = "layout")
getWidth()
int
@NonNull WindowId
@Nullable WindowInsetsController
int

This method is deprecated. Deprecated in Java

@NonNull IBinder
int
void
float
@ViewDebug.ExportedProperty(category = "drawing")
getX()
float
@ViewDebug.ExportedProperty(category = "drawing")
getY()
float
@ViewDebug.ExportedProperty(category = "drawing")
getZ()
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
void
void

This method is deprecated. Deprecated in Java

void
invalidate(int l, int t, int r, int b)

This method is deprecated. Deprecated in Java

void
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean

This method is deprecated. Deprecated in Java

boolean
boolean
final boolean
@ViewDebug.ExportedProperty(category = "focus")
isFocusable()
final boolean
boolean
@ViewDebug.ExportedProperty(category = "focus")
isFocused()
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
final boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
@ViewDebug.ExportedProperty(category = "drawing")
isOpaque()
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
void
@NonNull View
keyboardNavigationClusterSearch(
    @NonNull View currentCluster,
    int direction
)
final void
layout(int l, int t, int r, int b)
final void
measure(int widthMeasureSpec, int heightMeasureSpec)
void
offsetLeftAndRight(int offset)
void
offsetTopAndBottom(int offset)
void
void
@NonNull WindowInsets
void
boolean
boolean
void
void
@NonNull int[]
onCreateDrawableState(int extraSpace)
@NonNull InputConnection
void
onCreateViewTranslationRequest(
    @NonNull int[] supportedFormats,
    @NonNull Consumer<@NonNull ViewTranslationRequest> requestsCollector
)
void
onCreateVirtualViewTranslationRequests(
    @NonNull long[] virtualIds,
    @NonNull int[] supportedFormats,
    @NonNull Consumer<@NonNull ViewTranslationRequest> requestsCollector
)
void
onDisplayHint(int hint)
boolean
void
void
final void
boolean
void
void
void
onFocusChanged(
    boolean gainFocus,
    int direction,
    @Nullable Rect previouslyFocusedRect
)
boolean
void
onHoverChanged(boolean hovered)
boolean
void
void
boolean
onKeyPreIme(int keyCode, @NonNull KeyEvent event)
boolean
onKeyShortcut(int keyCode, @NonNull KeyEvent event)
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void
onOverScrolled(
    int scrollX,
    int scrollY,
    boolean clampedX,
    boolean clampedY
)
void
onPointerCaptureChange(boolean hasCapture)
void
void
void
onProvideAutofillVirtualStructure(
    @NonNull ViewStructure structure,
    int flags
)
void
onProvideContentCaptureStructure(
    @NonNull ViewStructure structure,
    int flags
)
void
void
@Nullable ContentInfo
@NonNull PointerIcon
onResolvePointerIcon(@NonNull MotionEvent event, int pointerIndex)
void
void
onRtlPropertiesChanged(int layoutDirection)
@Nullable Parcelable
void
onScreenStateChanged(int screenState)
void
onScrollCaptureSearch(
    @NonNull Rect localVisibleRect,
    @NonNull Point windowOffset,
    @NonNull Consumer<@NonNull ScrollCaptureTarget> targets
)
void
onScrollChanged(int l, int t, int oldl, int oldt)
boolean
onSetAlpha(int alpha)
void
onSizeChanged(int w, int h, int oldw, int oldh)
void
boolean
boolean
void
void
void
onVisibilityAggregated(boolean isVisible)
void
onVisibilityChanged(@NonNull View changedView, int visibility)
void
onWindowFocusChanged(boolean hasWindowFocus)
void

This method is deprecated. Deprecated in Java

void
onWindowVisibilityChanged(int visibility)
boolean
overScrollBy(
    int deltaX,
    int deltaY,
    int scrollX,
    int scrollY,
    int scrollRangeX,
    int scrollRangeY,
    int maxOverScrollX,
    int maxOverScrollY,
    boolean isTouchEvent
)
boolean
performAccessibilityAction(int action, @Nullable Bundle arguments)
boolean
boolean
boolean
performContextClick(float x, float y)
boolean
performHapticFeedback(int feedbackConstant)
boolean
performHapticFeedback(int feedbackConstant, int flags)
boolean
boolean
performLongClick(float x, float y)
@Nullable ContentInfo
void
playSoundEffect(int soundConstant)
boolean
boolean
postDelayed(@NonNull Runnable action, long delayMillis)
void
void
postInvalidate(int left, int top, int right, int bottom)
void
postInvalidateDelayed(long delayMilliseconds)
void
postInvalidateDelayed(
    long delayMilliseconds,
    int left,
    int top,
    int right,
    int bottom
)
void
void
postInvalidateOnAnimation(int left, int top, int right, int bottom)
void
void
postOnAnimationDelayed(@NonNull Runnable action, long delayMillis)
void
void
boolean
void
void
void
void
void
void

This method is deprecated. Deprecated in Java

final boolean
final boolean
requestFocus(int direction)
boolean
requestFocus(int direction, @NonNull Rect previouslyFocusedRect)
final boolean
void
void
boolean
boolean
requestRectangleOnScreen(@NonNull Rect rectangle, boolean immediate)
final void
final void
final @NonNull T
<T extends View> requireViewById(int id)
void
boolean
void
final void
saveAttributeDataForStyleable(
    @NonNull Context context,
    @NonNull int[] styleable,
    @Nullable AttributeSet attrs,
    @NonNull TypedArray t,
    int defStyleAttr,
    int defStyleRes
)
void
void
scrollBy(int x, int y)
void
scrollTo(int x, int y)
void
setAccessibilityDataSensitive(int accessibilityDataSensitive)
void
void
setAccessibilityHeading(boolean isHeading)
void
void
void
void
void
setActivated(boolean activated)
void
setAllowClickWhenDisabled(boolean clickableWhenDisabled)
void
void
void
setAlpha(float alpha)
void
void
void
setAutoHandwritingEnabled(boolean enabled)
void
setAutofillHints(@Nullable String... autofillHints)
void
void
void
setBackgroundColor(int color)
void

This method is deprecated. Deprecated in Java

void
void
void
void
final void
setBottom(int bottom)
void
setCameraDistance(float distance)
void
setClickable(boolean clickable)
void
setClipBounds(@NonNull Rect clipBounds)
void
setClipToOutline(boolean clipToOutline)
void
void
final void
void
setContextClickable(boolean contextClickable)
void
setDefaultFocusHighlightEnabled(boolean defaultFocusHighlightEnabled)
void

This method is deprecated. Deprecated in Java

void
setDrawingCacheEnabled(boolean enabled)

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
void
setElevation(float elevation)
void
setEnabled(boolean enabled)
void
setFadingEdgeLength(int length)
void
void
setFitsSystemWindows(boolean fitSystemWindows)
void
setFocusable(boolean focusable)
void
setFocusable(int focusable)
void
setFocusableInTouchMode(boolean focusableInTouchMode)
void
setFocusedByDefault(boolean isFocusedByDefault)
void
setForceDarkAllowed(boolean allow)
void
void
void
void
void
setFrameContentVelocity(float pixelsPerSecond)
void
setHandwritingBoundsOffsets(
    float offsetLeft,
    float offsetTop,
    float offsetRight,
    float offsetBottom
)
void
void
void
setHapticFeedbackEnabled(boolean hapticFeedbackEnabled)
void
setHasTransientState(boolean hasTransientState)
void
setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled)
void
setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled)
void
void
void
setHovered(boolean hovered)
void
setId(int id)
void
void
void
void
setIsCredential(boolean isCredential)
void
setIsHandwritingDelegate(boolean isHandwritingDelegate)
void
setKeepScreenOn(boolean keepScreenOn)
void
setKeyboardNavigationCluster(boolean isCluster)
void
setLabelFor(int id)
void
void
setLayerType(int layerType, @Nullable Paint paint)
void
setLayoutDirection(int layoutDirection)
void
final void
setLeft(int left)
final void
setLeftTopRightBottom(int left, int top, int right, int bottom)
void
setLongClickable(boolean longClickable)
final void
setMeasuredDimension(int measuredWidth, int measuredHeight)
void
setMinimumHeight(int minHeight)
void
setMinimumWidth(int minWidth)
void
setNestedScrollingEnabled(boolean enabled)
void
setNextClusterForwardId(int nextClusterForwardId)
void
setNextFocusDownId(int nextFocusDownId)
void
setNextFocusForwardId(int nextFocusForwardId)
void
setNextFocusLeftId(int nextFocusLeftId)
void
setNextFocusRightId(int nextFocusRightId)
void
setNextFocusUpId(int nextFocusUpId)
void
void
void
void
void
void
void
void
void
void
void
void
setOnReceiveContentListener(
    @Nullable String[] mimeTypes,
    @Nullable OnReceiveContentListener listener
)
void
void

This method is deprecated. Deprecated in Java

void
void
void
void
void
setOverScrollMode(int overScrollMode)
void
setPadding(int left, int top, int right, int bottom)
void
setPaddingRelative(int start, int top, int end, int bottom)
void
void
setPivotX(float pivotX)
void
setPivotY(float pivotY)
void
final void
setPreferKeepClear(boolean preferKeepClear)
final void
void
setPressed(boolean pressed)
void
final void
setRevealOnFocusHint(boolean revealOnFocus)
final void
setRight(int right)
void
setRotation(float rotation)
void
setRotationX(float rotationX)
void
setRotationY(float rotationY)
void
setSaveEnabled(boolean enabled)
void
setSaveFromParentEnabled(boolean enabled)
void
setScaleX(float scaleX)
void
setScaleY(float scaleY)
void
setScreenReaderFocusable(boolean screenReaderFocusable)
void
setScrollBarDefaultDelayBeforeFade(
    int scrollBarDefaultDelayBeforeFade
)
void
setScrollBarFadeDuration(int scrollBarFadeDuration)
void
setScrollBarSize(int scrollBarSize)
void
setScrollBarStyle(int style)
final void
void
void
setScrollContainer(boolean isScrollContainer)
void
setScrollIndicators(int indicators)
void
setScrollX(int value)
void
setScrollY(int value)
void
setScrollbarFadingEnabled(boolean fadeScrollbars)
void
setSelected(boolean selected)
void
setSoundEffectsEnabled(boolean soundEffectsEnabled)
void
void
void
setSupplementalDescription(
    @Nullable CharSequence supplementalDescription
)
void
void
setSystemUiVisibility(int visibility)

This method is deprecated. Deprecated in Java

void
void
setTextAlignment(int textAlignment)
void
setTextDirection(int textDirection)
void
final void
setTop(int top)
void
void
setTransitionAlpha(float alpha)
final void
setTransitionName(@NonNull String transitionName)
void
setTransitionVisibility(int visibility)
void
setTranslationX(float translationX)
void
setTranslationY(float translationY)
void
setTranslationZ(float translationZ)
void
setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled)
void
setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled)
void
void
void
void
void
setVisibility(int visibility)
void
setWillNotCacheDrawing(boolean willNotCacheDrawing)

This method is deprecated. Deprecated in Java

void
setWillNotDraw(boolean willNotDraw)
void
void
setX(float x)
void
setY(float y)
void
setZ(float z)
boolean
boolean
showContextMenu(float x, float y)
@NonNull ActionMode
@NonNull ActionMode
void
final boolean
startDrag(
    @NonNull ClipData data,
    @NonNull View.DragShadowBuilder shadowBuilder,
    @NonNull Object myLocalState,
    int flags
)

This method is deprecated. Deprecated in Java

final boolean
startDragAndDrop(
    @NonNull ClipData data,
    @NonNull View.DragShadowBuilder shadowBuilder,
    @NonNull Object myLocalState,
    int flags
)
boolean
void
void
void
void
final void
boolean
boolean

This method is deprecated. Deprecated in Java

boolean
@ViewDebug.ExportedProperty(category = "drawing")
willNotDraw()
From android.view.ViewGroup
boolean
void
void
addView(@NonNull View child, int index)
void
addView(
    @NonNull View child,
    int index,
    @NonNull ViewGroup.LayoutParams params
)
void
addView(@NonNull View child, int width, int height)
boolean
addViewInLayout(
    @NonNull View child,
    int index,
    @NonNull ViewGroup.LayoutParams params
)
boolean
addViewInLayout(
    @NonNull View child,
    int index,
    @NonNull ViewGroup.LayoutParams params,
    boolean preventRequestLayout
)
void
attachLayoutAnimationParameters(
    @NonNull View child,
    @NonNull ViewGroup.LayoutParams params,
    int index,
    int count
)
void
attachViewToParent(
    @NonNull View child,
    int index,
    @NonNull ViewGroup.LayoutParams params
)
boolean
boolean
void
void
void
debug(int depth)
void
void
void
void
detachViewsFromParent(int start, int count)
void
void
boolean
drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime)
void
@NonNull FrameLayout.LayoutParams
@NonNull FrameLayout.LayoutParams
@NonNull ViewGroup.LayoutParams
@NonNull View
getChildAt(int index)
int
final int
getChildDrawingOrder(int drawingPosition)
int
getChildDrawingOrder(int childCount, int drawingPosition)
boolean
boolean
boolean
int
@ViewDebug.ExportedProperty(category = "focus", mapping = [@ViewDebug.IntToString(from = 131072, to = "FOCUS_BEFORE_DESCENDANTS"), @ViewDebug.IntToString(from = 262144, to = "FOCUS_AFTER_DESCENDANTS"), @ViewDebug.IntToString(from = 393216, to = "FOCUS_BLOCK_DESCENDANTS")])
getDescendantFocusability()
@NonNull View
@NonNull LayoutAnimationController
@NonNull Animation.AnimationListener
int
@ViewDebug.ExportedProperty(category = "layout", mapping = [@ViewDebug.IntToString(from = 0, to = "RESOLVED_DIRECTION_LTR"), @ViewDebug.IntToString(from = 1, to = "RESOLVED_DIRECTION_RTL")])
getLayoutDirection()
int
@NonNull LayoutTransition
int
@NonNull ViewGroupOverlay
final @NonNull ViewParent
@NonNull ViewParent
int
@ViewDebug.ExportedProperty(category = "drawing", mapping = [@ViewDebug.IntToString(from = 0, to = "NONE"), @ViewDebug.IntToString(from = 1, to = "ANIMATION"), @ViewDebug.IntToString(from = 2, to = "SCROLLING"), @ViewDebug.IntToString(from = 3, to = "ALL")])
getPersistentDrawingCache()

This method is deprecated. Deprecated in Java

int
@ViewDebug.ExportedProperty(category = "text", mapping = [@ViewDebug.IntToString(from = 0, to = "INHERIT"), @ViewDebug.IntToString(from = 1, to = "GRAVITY"), @ViewDebug.IntToString(from = 2, to = "TEXT_START"), @ViewDebug.IntToString(from = 3, to = "TEXT_END"), @ViewDebug.IntToString(from = 4, to = "CENTER"), @ViewDebug.IntToString(from = 5, to = "VIEW_START"), @ViewDebug.IntToString(from = 6, to = "VIEW_END")])
getTextAlignment()
int
@ViewDebug.ExportedProperty(category = "text", mapping = [@ViewDebug.IntToString(from = 0, to = "INHERIT"), @ViewDebug.IntToString(from = 1, to = "FIRST_STRONG"), @ViewDebug.IntToString(from = 2, to = "ANY_RTL"), @ViewDebug.IntToString(from = 3, to = "LTR"), @ViewDebug.IntToString(from = 4, to = "RTL"), @ViewDebug.IntToString(from = 5, to = "LOCALE"), @ViewDebug.IntToString(from = 6, to = "FIRST_STRONG_LTR"), @ViewDebug.IntToString(from = 7, to = "FIRST_STRONG_RTL")])
getTextDirection()
boolean
int
boolean

This method is deprecated. Deprecated in Java

boolean

This method is deprecated. Deprecated in Java

boolean
boolean

This method is deprecated. Deprecated in Java

boolean
boolean
boolean
boolean
boolean
boolean
boolean
void
measureChild(
    @NonNull View child,
    int parentWidthMeasureSpec,
    int parentHeightMeasureSpec
)
void
measureChildWithMargins(
    @NonNull View child,
    int parentWidthMeasureSpec,
    int widthUsed,
    int parentHeightMeasureSpec,
    int heightUsed
)
void
measureChildren(int widthMeasureSpec, int heightMeasureSpec)
final void
offsetDescendantRectToMyCoords(
    @NonNull View descendant,
    @NonNull Rect rect
)
final void
offsetRectIntoDescendantCoords(
    @NonNull View descendant,
    @NonNull Rect rect
)
boolean
boolean
boolean
onRequestFocusInDescendants(
    int direction,
    @NonNull Rect previouslyFocusedRect
)
boolean
void
void
void
propagateRequestedFrameRate(float frameRate, boolean forceOverride)
void
void
void
removeDetachedView(@NonNull View child, boolean animate)
void
removeViewAt(int index)
void
void
removeViews(int start, int count)
void
removeViewsInLayout(int start, int count)
void
void
setAddStatesFromChildren(boolean addsStates)
void

This method is deprecated. Deprecated in Java

void
setAnimationCacheEnabled(boolean enabled)

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
void

This method is deprecated. Deprecated in Java

void
setClipChildren(boolean clipChildren)
void
setClipToPadding(boolean clipToPadding)
void
setDescendantFocusability(int focusability)
void
void
void
setLayoutMode(int layoutMode)
void
void
void
void
setPersistentDrawingCache(int drawingCacheToKeep)

This method is deprecated. Deprecated in Java

void
setRequestedFrameRate(float frameRate)
void
void
setTouchscreenBlocksFocus(boolean touchscreenBlocksFocus)
void
setTransitionGroup(boolean isTransitionGroup)
boolean
void
void
void
suppressLayout(boolean suppress)
From android.view.ViewManager
void
void
void
From android.view.ViewParent
void
void
void
childHasTransientStateChanged(
    @NonNull View child,
    boolean childHasTransientState
)
void
@Nullable OnBackInvokedDispatcher
findOnBackInvokedDispatcherForChild(
    @NonNull View child,
    @NonNull View requester
)
@NonNull View
focusSearch(@NonNull View focused, int direction)
void
boolean
getChildVisibleRect(
    @NonNull View child,
    @NonNull Rect r,
    @NonNull Point offset
)
final void

This method is deprecated. Deprecated in Java

@NonNull ViewParent
invalidateChildInParent(@NonNull int[] location, @NonNull Rect dirty)

This method is deprecated. Deprecated in Java

void
notifySubtreeAccessibilityStateChanged(
    @NonNull View child,
    @NonNull View source,
    int changeType
)
void
boolean
onNestedFling(
    @NonNull View target,
    float velocityX,
    float velocityY,
    boolean consumed
)
boolean
onNestedPreFling(@NonNull View target, float velocityX, float velocityY)
boolean
onNestedPrePerformAccessibilityAction(
    @NonNull View target,
    int action,
    Bundle args
)
void
onNestedPreScroll(
    @NonNull View target,
    int dx,
    int dy,
    @NonNull int[] consumed
)
void
onNestedScroll(
    @NonNull View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed
)
void
onNestedScrollAccepted(@NonNull View child, @NonNull View target, int axes)
boolean
onStartNestedScroll(
    @NonNull View child,
    @NonNull View target,
    int nestedScrollAxes
)
void
void
void
boolean
requestChildRectangleOnScreen(
    @NonNull View child,
    @NonNull Rect rectangle,
    boolean immediate
)
void
requestDisallowInterceptTouchEvent(boolean disallowIntercept)
boolean
void
boolean
boolean
showContextMenuForChild(@NonNull View originalView, float x, float y)
@NonNull ActionMode
startActionModeForChild(
    @NonNull View originalView,
    @NonNull ActionMode.Callback callback
)
@NonNull ActionMode
startActionModeForChild(
    @NonNull View originalView,
    @NonNull ActionMode.Callback callback,
    int type
)

Public constructors

InProgressStrokesView

Added in 1.0.0
public InProgressStrokesView(
    @NonNull Context context,
    AttributeSet attrs,
    @AttrRes int defStyleAttr
)

Public methods

addFinishedStrokesListener

Added in 1.0.0
public final void addFinishedStrokesListener(
    @NonNull InProgressStrokesFinishedListener listener
)

Add a listener to be notified when strokes are finished. These strokes will continue to be rendered within this view until removeFinishedStrokes is called. All of the strokes that have been delivered to listeners but have not yet been removed with removeFinishedStrokes are available through getFinishedStrokes.

addToStroke

Added in 1.0.0
public final boolean addToStroke(
    @NonNull MotionEvent event,
    int pointerId,
    MotionEvent prediction
)

Add event data for pointerId to the corresponding in-progress stroke, if present. The stroke must have been started with an overload of startStroke that accepts a MotionEvent.

Parameters
@NonNull MotionEvent event

the next MotionEvent as part of a Stroke's input data, typically an ACTION_MOVE.

int pointerId

the index of the relevant pointer in the event. If pointerId does not correspond to an in-progress stroke, this call is ignored.

MotionEvent prediction

optional predicted MotionEvent containing predicted inputs between event and the time of the next frame, as generated by androidx.input.motionprediction.MotionEventPredictor.predict.

Returns
boolean

Whether the pointer corresponds to an in-progress stroke.

addToStroke

Added in 1.0.0
public final void addToStroke(
    @NonNull StrokeInputBatch inputs,
    @NonNull InProgressStrokeId strokeId,
    @NonNull StrokeInputBatch prediction
)

Add input data from a StrokeInputBatch to an existing stroke. The stroke must have been started with an overload of startStroke that accepts a StrokeInput.

Parameters
@NonNull StrokeInputBatch inputs

The next StrokeInputBatch to be added to the stroke.

@NonNull InProgressStrokeId strokeId

The InProgressStrokeId of the stroke to be built upon.

@NonNull StrokeInputBatch prediction

Predicted StrokeInputBatch containing predicted inputs between inputs and the time of the next frame. This can technically be empty, but it is strongly recommended for it to be non-empty to achieve the best performance.

addToStroke

Added in 1.0.0
public final void addToStroke(
    @NonNull MotionEvent event,
    int pointerId,
    @NonNull InProgressStrokeId strokeId,
    MotionEvent prediction
)

Add input data, from a particular pointer within a MotionEvent, to an existing stroke. The stroke must have been started with an overload of startStroke that accepts a MotionEvent.

Parameters
@NonNull MotionEvent event

The next MotionEvent as part of a stroke's input data, typically one with MotionEvent.getActionMasked of MotionEvent.ACTION_MOVE.

int pointerId

The identifier of the pointer within event to be used for inking, as determined by MotionEvent.getPointerId and used as an input to MotionEvent.findPointerIndex. Note that this is the ID of the pointer, not its index.

@NonNull InProgressStrokeId strokeId

The InProgressStrokeId of the stroke to be built upon.

MotionEvent prediction

Predicted MotionEvent containing predicted inputs between event and the time of the next frame. This value typically comes from androidx.input.motionprediction.MotionEventPredictor.predict. It is technically optional, but it is strongly recommended to achieve the best performance.

cancelStroke

Added in 1.0.0
public final boolean cancelStroke(@NonNull MotionEvent event, int pointerId)

Cancel the corresponding in-progress stroke with event data for pointerId, if present. The stroke must have been started with an overload of startStroke that accepts a MotionEvent.

Parameters
@NonNull MotionEvent event

The MotionEvent that led to this cancellation, typically an ACTION_CANCEL.

int pointerId

the id of the relevant pointer in the event.

Returns
boolean

Whether the pointer corresponded to an in-progress stroke.

cancelStroke

Added in 1.0.0
public final void cancelStroke(@NonNull InProgressStrokeId strokeId, MotionEvent event)

Cancel the building of a stroke. It will no longer be visible within this InProgressStrokesView, and no completed Stroke object will come through InProgressStrokesFinishedListener.

This is typically done for one of three reasons:

  1. A MotionEvent with MotionEvent.getActionMasked of MotionEvent.ACTION_CANCEL. This tends to be when an entire gesture has been canceled, for example when a parent android.view.View uses android.view.ViewGroup.onInterceptTouchEvent to intercept and handle the gesture itself.

  2. A MotionEvent with MotionEvent.getFlags containing MotionEvent.FLAG_CANCELED. This tends to be when the system has detected an unintentional touch, such as from the user resting their palm on the screen while writing or drawing, after some events from that unintentional pointer have already been delivered.

  3. An app's business logic reinterprets a gesture previously used for inking as something else, and the earlier inking may be seen as unintentional. For example, an app that uses single-pointer gestures for inking and dual-pointer gestures for pan/zoom/rotate will start inking when the first pointer goes down, but when the second pointer goes down it may want to cancel the stroke from the first pointer rather than leave the small ink marks on the screen.

Does nothing if a stroke with the given strokeId is not in progress.

Parameters
@NonNull InProgressStrokeId strokeId

The InProgressStrokeId of the stroke to be canceled.

MotionEvent event

The MotionEvent that led to this cancellation, if applicable.

cancelUnfinishedStrokes

Added in 1.0.0
public final void cancelUnfinishedStrokes()

Cancel all in-progress strokes.

clearFinishedStrokesListeners

Added in 1.0.0
public final void clearFinishedStrokesListeners()

Removes all listeners that had previously been added with addFinishedStrokesListener.

eagerInit

Added in 1.0.0
public final void eagerInit()

Eagerly initialize rather than waiting for the first stroke to be drawn. Since initialization can be somewhat heavyweight, doing this as soon as it's likely for the user to start drawing can prevent initialization from introducing latency to the first stroke.

finishStroke

Added in 1.0.0
public final boolean finishStroke(@NonNull MotionEvent event, int pointerId)

Finish the corresponding in-progress stroke with event data for pointerId, if present. The stroke must have been started with an overload of startStroke that accepts a MotionEvent.

Parameters
@NonNull MotionEvent event

the last MotionEvent as part of a stroke, typically an ACTION_UP.

int pointerId

the id of the relevant pointer in the event. If pointerId does not correspond to an in-progress stroke, this call is ignored.

Returns
boolean

Whether the pointer corresponded to an in-progress stroke.

finishStroke

Added in 1.0.0
public final void finishStroke(
    @NonNull StrokeInput input,
    @NonNull InProgressStrokeId strokeId
)

Complete the building of a stroke, with the last input data coming from a StrokeInput. The stroke must have been started with an overload of startStroke that accepts a StrokeInput.

Parameters
@NonNull StrokeInput input

The last StrokeInput in the stroke.

@NonNull InProgressStrokeId strokeId

The InProgressStrokeId of the stroke to be finished.

finishStroke

Added in 1.0.0
public final void finishStroke(
    @NonNull MotionEvent event,
    int pointerId,
    @NonNull InProgressStrokeId strokeId
)

Complete the building of a stroke, with the last input data coming from a particular pointer of a MotionEvent. The stroke must have been started with an overload of startStroke that accepts a MotionEvent.

When the stroke no longer needs to be rendered by this InProgressStrokesView and can instead be rendered anywhere in the android.view.View hierarchy using CanvasStrokeRenderer, the resulting Stroke object will be passed to the InProgressStrokesFinishedListener instances registered with this InProgressStrokesView using addFinishedStrokesListener.

Does nothing if a stroke with the given strokeId is not in progress.

Parameters
@NonNull MotionEvent event

The last MotionEvent as part of a stroke's input data, typically one with MotionEvent.getActionMasked of MotionEvent.ACTION_UP or MotionEvent.ACTION_POINTER_UP, but can also be other actions.

int pointerId

The identifier of the pointer within event to be used for inking, as determined by MotionEvent.getPointerId and used as an input to MotionEvent.findPointerIndex. Note that this is the ID of the pointer, not its index.

@NonNull InProgressStrokeId strokeId

The InProgressStrokeId of the stroke to be finished.

getFinishedStrokes

Added in 1.0.0
public final @NonNull Map<@NonNull InProgressStrokeId, @NonNull StrokegetFinishedStrokes()

Returns all the finished strokes that are still being rendered by this view, with map iteration order in the z-order that the strokes are being rendered, from back to front. This is the same order that strokes were started with startStroke. The IDs of these strokes should be passed to removeFinishedStrokes when they are handed off to another view.

getInProgressStrokeCounter

Added in 1.0.0
public final CountingIdlingResource getInProgressStrokeCounter()

Allows a test to easily wait until all in-progress strokes are completed and handed off. There is no reason to set this in non-test code.

getMaskPath

Added in 1.0.0
public final Path getMaskPath()

Denote an area of this InProgressStrokesView where no ink should be visible. A value of null indicates that strokes will be visible anywhere they are drawn. This is useful for UI elements that float on top of (in Z order) the drawing surface - without this, a user would be able to draw in-progress ("wet") strokes on top of those UI elements, but then when the stroke is finished, it will appear as a dry stroke underneath of the UI element. If this mask is set to the shape and position of the floating UI element, then the ink will never be rendered in that area, making it appear as if it's being drawn underneath the UI element.

This technique is most convincing when the UI element is opaque. Often there are parts of the UI element that are translucent, such as drop shadows, or anti-aliasing along the edges. The result will look a little different between wet and dry strokes for those cases, but it can be a worthwhile tradeoff compared to the alternative of drawing wet strokes on top of that UI element.

Note that this parameter does not affect the contents of the strokes at all, nor how they appear when drawn in a separate composable after InProgressStrokesFinishedListener.onStrokesFinished is called - just how the strokes appear when they are still in progress in this view.

getMotionEventToViewTransform

Added in 1.0.0
public final @NonNull Matrix getMotionEventToViewTransform()

The transform matrix to convert MotionEvent coordinates, as passed to startStroke, addToStroke, and finishStroke, into coordinates of this InProgressStrokesView for rendering. Defaults to the identity matrix, for the recommended case where InProgressStrokesView exactly overlays the android.view.View that has the touch listener from which MotionEvent instances are being forwarded.

getTextureBitmapStore

Added in 1.0.0
public final @NonNull TextureBitmapStore getTextureBitmapStore()

TextureBitmapStore used to create the CanvasStrokeRenderer.

By default, this is a no-op implementation that does not load any brush textures. The factory functions are called when the renderer is initialized, so if this will be changed to something that does load and store texture images, it must be set before the first call to startStroke or eagerInit.

hasUnfinishedStrokes

Added in 1.0.0
public final boolean hasUnfinishedStrokes()

Returns true if there are any in-progress strokes.

removeFinishedStrokes

Added in 1.0.0
@UiThread
public final void removeFinishedStrokes(@NonNull Set<@NonNull InProgressStrokeId> strokeIds)

Stop this view from rendering the strokes with the given IDs.

This should be called in the same UI thread run loop (HWUI frame) as when the strokes start being rendered elsewhere in the view hierarchy. This means they are saved in a location where they will be picked up in a view's next call to onDraw, and that view's invalidate method has been called. If these two operations are not done within the same UI thread run loop (usually side by side - see example below), then there will be brief rendering errors - either a visual gap where the stroke is not drawn during a frame, or a double draw where the stroke is drawn twice and translucent strokes appear more opaque than they should.

removeFinishedStrokesListener

Added in 1.0.0
public final void removeFinishedStrokesListener(
    @NonNull InProgressStrokesFinishedListener listener
)

Removes a listener that had previously been added with addFinishedStrokesListener.

setInProgressStrokeCounter

Added in 1.0.0
public final void setInProgressStrokeCounter(CountingIdlingResource <set-?>)

Allows a test to easily wait until all in-progress strokes are completed and handed off. There is no reason to set this in non-test code.

setMaskPath

Added in 1.0.0
public final void setMaskPath(Path <set-?>)

Denote an area of this InProgressStrokesView where no ink should be visible. A value of null indicates that strokes will be visible anywhere they are drawn. This is useful for UI elements that float on top of (in Z order) the drawing surface - without this, a user would be able to draw in-progress ("wet") strokes on top of those UI elements, but then when the stroke is finished, it will appear as a dry stroke underneath of the UI element. If this mask is set to the shape and position of the floating UI element, then the ink will never be rendered in that area, making it appear as if it's being drawn underneath the UI element.

This technique is most convincing when the UI element is opaque. Often there are parts of the UI element that are translucent, such as drop shadows, or anti-aliasing along the edges. The result will look a little different between wet and dry strokes for those cases, but it can be a worthwhile tradeoff compared to the alternative of drawing wet strokes on top of that UI element.

Note that this parameter does not affect the contents of the strokes at all, nor how they appear when drawn in a separate composable after InProgressStrokesFinishedListener.onStrokesFinished is called - just how the strokes appear when they are still in progress in this view.

setMotionEventToViewTransform

Added in 1.0.0
public final void setMotionEventToViewTransform(@NonNull Matrix <set-?>)

The transform matrix to convert MotionEvent coordinates, as passed to startStroke, addToStroke, and finishStroke, into coordinates of this InProgressStrokesView for rendering. Defaults to the identity matrix, for the recommended case where InProgressStrokesView exactly overlays the android.view.View that has the touch listener from which MotionEvent instances are being forwarded.

setTextureBitmapStore

Added in 1.0.0
public final void setTextureBitmapStore(@NonNull TextureBitmapStore value)

TextureBitmapStore used to create the CanvasStrokeRenderer.

By default, this is a no-op implementation that does not load any brush textures. The factory functions are called when the renderer is initialized, so if this will be changed to something that does load and store texture images, it must be set before the first call to startStroke or eagerInit.

startStroke

Added in 1.0.0
public final @NonNull InProgressStrokeId startStroke(
    @NonNull StrokeInput input,
    @NonNull Brush brush,
    @NonNull Matrix strokeToViewTransform
)

Start building a stroke with the provided input. This would typically be followed by many calls to addToStroke, and the sequence would end with a call to either finishStroke or cancelStroke.

In most circumstances, the startStroke overload that accepts a MotionEvent is more convenient. However, this overload using a StrokeInput is available for cases where the input data may not come directly from a MotionEvent, such as receiving events over a network connection. Using this function to start a stroke can only be followed by the StrokeInput variants of addToStroke and finishStroke for the same stroke.

If there is a way to request unbuffered dispatch from the source of the input data used here, equivalent to android.view.View.requestUnbufferedDispatch for unbuffered MotionEvent data, then be sure to request it for optimal performance.

Parameters
@NonNull StrokeInput input

The StrokeInput that started a stroke.

@NonNull Brush brush

Brush specification for the stroke being started. Note that if stroke coordinate units (the StrokeInput.x and StrokeInput.y fields of input) are scaled to be very different in size than screen pixels, then it is recommended to update the value of Brush.epsilon to reflect that.

@NonNull Matrix strokeToViewTransform

The Matrix that converts stroke coordinates as provided in input into the coordinate space of this InProgressStrokesView for rendering.

Returns
@NonNull InProgressStrokeId

The InProgressStrokeId of the stroke being built, later used to identify which stroke is being updated with addToStroke or ended with finishStroke or cancelStroke.

startStroke

Added in 1.0.0
public final @NonNull InProgressStrokeId startStroke(
    @NonNull MotionEvent event,
    int pointerId,
    @NonNull Brush brush,
    @NonNull Matrix motionEventToWorldTransform,
    @NonNull Matrix strokeToWorldTransform
)

Start building a stroke using a particular pointer within a MotionEvent. This would typically be followed by many calls to addToStroke, and the sequence would end with a call to either finishStroke or cancelStroke.

In most circumstances, prefer to use this function over startStroke that accepts a StrokeInput. Using this function to start a stroke must only be followed by the MotionEvent variants of addToStroke and finishStroke for the same stroke.

For optimum performance, it is strongly recommended to call android.view.View.requestUnbufferedDispatch using event and the android.view.View that generated event alongside calling this function. When requested this way, unbuffered dispatch mode will automatically end when the gesture is complete.

Parameters
@NonNull MotionEvent event

The first MotionEvent as part of a Stroke's input data, typically one with a MotionEvent.getActionMasked value of MotionEvent.ACTION_DOWN or MotionEvent.ACTION_POINTER_DOWN, but not restricted to those action types.

int pointerId

The identifier of the pointer within event to be used for inking, as determined by MotionEvent.getPointerId and used as an input to MotionEvent.findPointerIndex. Note that this is the ID of the pointer, not its index.

@NonNull Brush brush

Brush specification for the stroke being started. Note that the overall scaling factor of motionEventToWorldTransform and strokeToWorldTransform combined should be related to the value of Brush.epsilon - in general, the larger the combined motionEventToStrokeTransform scaling factor is, the smaller on screen the stroke units are, so Brush.epsilon should be a larger quantity of stroke units to maintain a similar screen size.

@NonNull Matrix motionEventToWorldTransform

The matrix that transforms event coordinates into the client app's "world" coordinates, which typically is defined by how a client app's document is panned/zoomed/rotated. This defaults to the identity matrix, in which case the world coordinate space is the same as the MotionEvent coordinates, but the caller should pass in their own value reflecting a coordinate system that is independent of the device's pixel density (e.g. scaled by 1 / android.util.DisplayMetrics.density) and any pan/zoom/rotate gestures that have been applied to the "camera" which portrays the "world" on the device screen. This matrix must be invertible.

@NonNull Matrix strokeToWorldTransform

Allows an object-specific (stroke-specific) coordinate space to be defined in relation to the caller's "world" coordinate space. This defaults to the identity matrix, which is typical for many use cases at the time of stroke construction. In typical use cases, stroke coordinates and world coordinates may start to differ from one another after stroke creation as a particular stroke is manipulated within the world, e.g. it may be moved, scaled, or rotated relative to other content within an app's document. This matrix must be invertible.

Returns
@NonNull InProgressStrokeId

The InProgressStrokeId of the stroke being built, later used to identify which stroke is being updated with addToStroke or ended with finishStroke or cancelStroke. Callers that assume strokes map one-to-one with pointers in a gesture (as is typical) can skip storing this return value and use the overrides of addToStroke, finishStroke, and cancelStroke that just take a MotionEvent and a pointerId.

Protected methods

onAttachedToWindow

protected void onAttachedToWindow()

onDetachedFromWindow

protected void onDetachedFromWindow()