OSDN Git Service

Propagate StartInputReason to attachNewInputLocked
[android-x86/frameworks-base.git] / core / java / com / android / internal / view / InputMethodClient.java
1 /*
2  * Copyright (C) 2015 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 com.android.internal.view;
18
19 import android.annotation.IntDef;
20
21 import java.lang.annotation.Retention;
22
23 import static java.lang.annotation.RetentionPolicy.SOURCE;
24
25 public final class InputMethodClient {
26     public static final int START_INPUT_REASON_UNSPECIFIED = 0;
27     public static final int START_INPUT_REASON_WINDOW_FOCUS_GAIN = 1;
28     public static final int START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY = 2;
29     public static final int START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API = 3;
30     public static final int START_INPUT_REASON_CHECK_FOCUS = 4;
31     public static final int START_INPUT_REASON_BOUND_TO_IMMS = 5;
32     public static final int START_INPUT_REASON_UNBOUND_FROM_IMMS = 6;
33     public static final int START_INPUT_REASON_ACTIVATED_BY_IMMS = 7;
34     public static final int START_INPUT_REASON_DEACTIVATED_BY_IMMS = 8;
35     public static final int START_INPUT_REASON_SESSION_CREATED_BY_IME = 9;
36
37     @Retention(SOURCE)
38     @IntDef({START_INPUT_REASON_UNSPECIFIED, START_INPUT_REASON_WINDOW_FOCUS_GAIN,
39             START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY,
40             START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API, START_INPUT_REASON_CHECK_FOCUS,
41             START_INPUT_REASON_BOUND_TO_IMMS, START_INPUT_REASON_ACTIVATED_BY_IMMS,
42             START_INPUT_REASON_DEACTIVATED_BY_IMMS, START_INPUT_REASON_SESSION_CREATED_BY_IME})
43     public @interface StartInputReason {}
44
45     public static String getStartInputReason(@StartInputReason final int reason) {
46         switch (reason) {
47             case START_INPUT_REASON_UNSPECIFIED:
48                 return "UNSPECIFIED";
49             case START_INPUT_REASON_WINDOW_FOCUS_GAIN:
50                 return "WINDOW_FOCUS_GAIN";
51             case START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY:
52                 return "WINDOW_FOCUS_GAIN_REPORT_ONLY";
53             case START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API:
54                 return "APP_CALLED_RESTART_INPUT_API";
55             case START_INPUT_REASON_CHECK_FOCUS:
56                 return "CHECK_FOCUS";
57             case START_INPUT_REASON_BOUND_TO_IMMS:
58                 return "BOUND_TO_IMMS";
59             case START_INPUT_REASON_UNBOUND_FROM_IMMS:
60                 return "UNBOUND_FROM_IMMS";
61             case START_INPUT_REASON_ACTIVATED_BY_IMMS:
62                 return "ACTIVATED_BY_IMMS";
63             case START_INPUT_REASON_DEACTIVATED_BY_IMMS:
64                 return "DEACTIVATED_BY_IMMS";
65             case START_INPUT_REASON_SESSION_CREATED_BY_IME:
66                 return "SESSION_CREATED_BY_IME";
67             default:
68                 return "Unknown=" + reason;
69         }
70     }
71
72     public static final int UNBIND_REASON_UNSPECIFIED = 0;
73     public static final int UNBIND_REASON_SWITCH_CLIENT = 1;
74     public static final int UNBIND_REASON_SWITCH_IME = 2;
75     public static final int UNBIND_REASON_DISCONNECT_IME = 3;
76     public static final int UNBIND_REASON_NO_IME = 4;
77     public static final int UNBIND_REASON_SWITCH_IME_FAILED = 5;
78     public static final int UNBIND_REASON_RESET_IME = 6;
79
80     @Retention(SOURCE)
81     @IntDef({UNBIND_REASON_UNSPECIFIED, UNBIND_REASON_SWITCH_CLIENT, UNBIND_REASON_SWITCH_IME,
82             UNBIND_REASON_DISCONNECT_IME, UNBIND_REASON_NO_IME, UNBIND_REASON_SWITCH_IME_FAILED,
83             UNBIND_REASON_RESET_IME})
84     public @interface UnbindReason {}
85
86     public static String getUnbindReason(@UnbindReason final int reason) {
87         switch (reason) {
88             case UNBIND_REASON_UNSPECIFIED:
89                 return "UNSPECIFIED";
90             case UNBIND_REASON_SWITCH_CLIENT:
91                 return "SWITCH_CLIENT";
92             case UNBIND_REASON_SWITCH_IME:
93                 return "SWITCH_IME";
94             case UNBIND_REASON_DISCONNECT_IME:
95                 return "DISCONNECT_IME";
96             case UNBIND_REASON_NO_IME:
97                 return "NO_IME";
98             case UNBIND_REASON_SWITCH_IME_FAILED:
99                 return "SWITCH_IME_FAILED";
100             case UNBIND_REASON_RESET_IME:
101                 return "RESET_IME";
102             default:
103                 return "Unknown=" + reason;
104         }
105     }
106 }