1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.view.inputmethod;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.IntDef;
21 import android.annotation.NonNull;
22 import android.view.View;
23 
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.RetentionPolicy;
26 import java.util.concurrent.Executor;
27 
28 /**
29  * Interface to receive the result of starting a connectionless stylus handwriting session using
30  * one of {@link InputMethodManager#startConnectionlessStylusHandwriting(View, CursorAnchorInfo,
31  * Executor,ConnectionlessHandwritingCallback)}, {@link
32  * InputMethodManager#startConnectionlessStylusHandwritingForDelegation(View, CursorAnchorInfo,
33  * Executor, ConnectionlessHandwritingCallback)}, or {@link
34  * InputMethodManager#startConnectionlessStylusHandwritingForDelegation(View, CursorAnchorInfo,
35  * String, Executor, ConnectionlessHandwritingCallback)}.
36  */
37 @FlaggedApi(Flags.FLAG_CONNECTIONLESS_HANDWRITING)
38 public interface ConnectionlessHandwritingCallback {
39 
40     /** @hide */
41     @IntDef(prefix = {"CONNECTIONLESS_HANDWRITING_ERROR_"}, value = {
42             CONNECTIONLESS_HANDWRITING_ERROR_NO_TEXT_RECOGNIZED,
43             CONNECTIONLESS_HANDWRITING_ERROR_UNSUPPORTED,
44             CONNECTIONLESS_HANDWRITING_ERROR_OTHER
45     })
46     @Retention(RetentionPolicy.SOURCE)
47     @interface ConnectionlessHandwritingError {
48     }
49 
50     /**
51      * Error code indicating that the connectionless handwriting session started and completed
52      * but no text was recognized.
53      */
54     int CONNECTIONLESS_HANDWRITING_ERROR_NO_TEXT_RECOGNIZED = 0;
55 
56     /**
57      * Error code indicating that the connectionless handwriting session was not started as the
58      * current IME does not support it.
59      */
60     int CONNECTIONLESS_HANDWRITING_ERROR_UNSUPPORTED = 1;
61 
62     /**
63      * Error code for any other reason that the connectionless handwriting session did not complete
64      * successfully. Either the session could not start, or the session started but did not complete
65      * successfully.
66      */
67     int CONNECTIONLESS_HANDWRITING_ERROR_OTHER = 2;
68 
69     /**
70      * Callback when the connectionless handwriting session completed successfully and
71      * recognized text.
72      */
onResult(@onNull CharSequence text)73     void onResult(@NonNull CharSequence text);
74 
75     /** Callback when the connectionless handwriting session did not complete successfully. */
onError(@onnectionlessHandwritingError int errorCode)76     void onError(@ConnectionlessHandwritingError int errorCode);
77 }
78