HandwritingGesture


public abstract class HandwritingGesture
extends Object

java.lang.Object
   ↳ android.view.inputmethod.HandwritingGesture


Base class for stylus handwriting gestures.

During a stylus handwriting session, user can perform a stylus gesture operation like SelectGesture, DeleteGesture, InsertGesture on an area of text. IME is responsible for listening to stylus MotionEvents using InputMethodService#onStylusHandwritingMotionEvent and interpret if it can translate to a gesture operation.

While creating gesture operations SelectGesture and DeleteGesture, Granularity helps pick the correct granular level of text like word level GRANULARITY_WORD, or character level GRANULARITY_CHARACTER.

Summary

Constants

int GRANULARITY_CHARACTER

Operate on text per character basis.

int GRANULARITY_WORD

Operate text per word basis.

Public methods

final String getFallbackText()

The fallback text that will be committed at current cursor position if there is no applicable text beneath the area of gesture.

Inherited methods

Constants

GRANULARITY_CHARACTER

Added in API level 34
public static final int GRANULARITY_CHARACTER

Operate on text per character basis. i.e. each character is selected based on its intersection with selection rectangle.

Strategy of operating at a granular level is maintained in the UI toolkit. A character/word/line is included if its center is within the gesture rectangle. e.g. if a selection RectF with GRANULARITY_CHARACTER includes width-wise center of the character, it should be selected. Similarly, text in a line should be included in the operation if rectangle includes line height center.

Constant Value: 2 (0x00000002)

GRANULARITY_WORD

Added in API level 34
public static final int GRANULARITY_WORD

Operate text per word basis. e.g. if selection includes width-wise center of the word, whole word is selected.

Strategy of operating at a granular level is maintained in the UI toolkit. A character/word/line is included if its center is within the gesture rectangle. e.g. if a selection RectF with GRANULARITY_WORD includes width-wise center of the word, it should be selected. Similarly, text in a line should be included in the operation if rectangle includes line height center.

Refer to https://www.unicode.org/reports/tr29/#Word_Boundaries for more detail on how word breaks are decided.

Constant Value: 1 (0x00000001)

Public methods

getFallbackText

Added in API level 34
public final String getFallbackText ()

The fallback text that will be committed at current cursor position if there is no applicable text beneath the area of gesture. For example, select can fail if gesture is drawn over area that has no text beneath. example 2: join can fail if the gesture is drawn over text but there is no whitespace.

Returns
String This value may be null.