summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/inputmethodservice/InputMethodService.java8
-rw-r--r--core/java/android/view/MotionEvent.java13
-rw-r--r--core/java/android/view/inputmethod/EditorInfo.java8
3 files changed, 20 insertions, 9 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index 48b9b8869cae..3a157d30d4c4 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -107,6 +107,7 @@ import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
+import android.view.MotionEvent.ToolType;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewRootImpl;
@@ -947,7 +948,7 @@ public class InputMethodService extends AbstractInputMethodService {
* @hide
*/
@Override
- public void updateEditorToolType(int toolType) {
+ public void updateEditorToolType(@ToolType int toolType) {
onUpdateEditorToolType(toolType);
}
@@ -3079,10 +3080,13 @@ public class InputMethodService extends AbstractInputMethodService {
* {@link MotionEvent#getToolType(int)} was used to click the editor.
* e.g. when toolType is {@link MotionEvent#TOOL_TYPE_STYLUS}, IME may choose to show a
* companion widget instead of normal virtual keyboard.
+ * <p> This method is called after {@link #onStartInput(EditorInfo, boolean)} and before
+ * {@link #onStartInputView(EditorInfo, boolean)} when editor was clicked with a known tool
+ * type.</p>
* <p> Default implementation does nothing. </p>
* @param toolType what {@link MotionEvent#getToolType(int)} was used to click on editor.
*/
- public void onUpdateEditorToolType(int toolType) {
+ public void onUpdateEditorToolType(@ToolType int toolType) {
// Intentionally empty
}
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java
index 0bed342a8b27..ea0012543ba9 100644
--- a/core/java/android/view/MotionEvent.java
+++ b/core/java/android/view/MotionEvent.java
@@ -1509,6 +1509,13 @@ public final class MotionEvent extends InputEvent implements Parcelable {
*/
public static final int TOOL_TYPE_PALM = 5;
+ /** @hide */
+ @Retention(SOURCE)
+ @IntDef(prefix = { "TOOL_TYPE_" }, value = {
+ TOOL_TYPE_UNKNOWN, TOOL_TYPE_FINGER, TOOL_TYPE_STYLUS, TOOL_TYPE_MOUSE,
+ TOOL_TYPE_ERASER, TOOL_TYPE_PALM})
+ public @interface ToolType {};
+
// NOTE: If you add a new tool type here you must also add it to:
// native/include/android/input.h
@@ -2422,7 +2429,7 @@ public final class MotionEvent extends InputEvent implements Parcelable {
* @see #TOOL_TYPE_STYLUS
* @see #TOOL_TYPE_MOUSE
*/
- public final int getToolType(int pointerIndex) {
+ public @ToolType int getToolType(int pointerIndex) {
return nativeGetToolType(mNativePtr, pointerIndex);
}
@@ -3868,7 +3875,7 @@ public final class MotionEvent extends InputEvent implements Parcelable {
* @return The symbolic name of the specified tool type.
* @hide
*/
- public static String toolTypeToString(int toolType) {
+ public static String toolTypeToString(@ToolType int toolType) {
String symbolicName = TOOL_TYPE_SYMBOLIC_NAMES.get(toolType);
return symbolicName != null ? symbolicName : Integer.toString(toolType);
}
@@ -4361,7 +4368,7 @@ public final class MotionEvent extends InputEvent implements Parcelable {
*
* @see MotionEvent#getToolType(int)
*/
- public int toolType;
+ public @ToolType int toolType;
/**
* Resets the pointer properties to their initial values.
diff --git a/core/java/android/view/inputmethod/EditorInfo.java b/core/java/android/view/inputmethod/EditorInfo.java
index 5515548cdb04..36b033485575 100644
--- a/core/java/android/view/inputmethod/EditorInfo.java
+++ b/core/java/android/view/inputmethod/EditorInfo.java
@@ -42,6 +42,7 @@ import android.text.TextUtils;
import android.util.Printer;
import android.util.proto.ProtoOutputStream;
import android.view.MotionEvent;
+import android.view.MotionEvent.ToolType;
import android.view.View;
import android.view.autofill.AutofillId;
@@ -639,8 +640,7 @@ public class EditorInfo implements InputType, Parcelable {
* Initial {@link MotionEvent#ACTION_UP} tool type {@link MotionEvent#getToolType(int)} that
* was used to focus this editor.
*/
- private int mInitialToolType = MotionEvent.TOOL_TYPE_UNKNOWN;
-
+ private @ToolType int mInitialToolType = MotionEvent.TOOL_TYPE_UNKNOWN;
/**
* Editors may use this method to provide initial input text to IMEs. As the surrounding text
@@ -1022,7 +1022,7 @@ public class EditorInfo implements InputType, Parcelable {
* @see InputMethodService#onUpdateEditorToolType(int)
* @return toolType {@link MotionEvent#getToolType(int)}.
*/
- public int getInitialToolType() {
+ public @ToolType int getInitialToolType() {
return mInitialToolType;
}
@@ -1034,7 +1034,7 @@ public class EditorInfo implements InputType, Parcelable {
* @see MotionEvent#getToolType(int)
* @see InputMethodService#onUpdateEditorToolType(int)
*/
- public void setInitialToolType(int toolType) {
+ public void setInitialToolType(@ToolType int toolType) {
mInitialToolType = toolType;
}