1 /*
2  * Copyright (C) 2020 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.inputmethod;
18 
19 import static java.lang.annotation.RetentionPolicy.SOURCE;
20 
21 import android.annotation.IntDef;
22 import android.view.WindowManager;
23 import android.view.WindowManager.LayoutParams;
24 
25 import java.lang.annotation.Retention;
26 
27 /**
28  * Describes the reason why Soft input window visible / hidden.
29  */
30 @Retention(SOURCE)
31 @IntDef(value = {
32         SoftInputShowHideReason.SHOW_SOFT_INPUT,
33         SoftInputShowHideReason.ATTACH_NEW_INPUT,
34         SoftInputShowHideReason.SHOW_MY_SOFT_INPUT,
35         SoftInputShowHideReason.HIDE_SOFT_INPUT,
36         SoftInputShowHideReason.HIDE_MY_SOFT_INPUT,
37         SoftInputShowHideReason.SHOW_AUTO_EDITOR_FORWARD_NAV,
38         SoftInputShowHideReason.SHOW_STATE_VISIBLE_FORWARD_NAV,
39         SoftInputShowHideReason.SHOW_STATE_ALWAYS_VISIBLE,
40         SoftInputShowHideReason.SHOW_SETTINGS_ON_CHANGE,
41         SoftInputShowHideReason.HIDE_SWITCH_USER,
42         SoftInputShowHideReason.HIDE_INVALID_USER,
43         SoftInputShowHideReason.HIDE_UNSPECIFIED_WINDOW,
44         SoftInputShowHideReason.HIDE_STATE_HIDDEN_FORWARD_NAV,
45         SoftInputShowHideReason.HIDE_ALWAYS_HIDDEN_STATE,
46         SoftInputShowHideReason.HIDE_RESET_SHELL_COMMAND,
47         SoftInputShowHideReason.HIDE_SETTINGS_ON_CHANGE,
48         SoftInputShowHideReason.HIDE_POWER_BUTTON_GO_HOME,
49         SoftInputShowHideReason.HIDE_DOCKED_STACK_ATTACHED,
50         SoftInputShowHideReason.HIDE_RECENTS_ANIMATION,
51         SoftInputShowHideReason.HIDE_BUBBLES,
52         SoftInputShowHideReason.HIDE_SAME_WINDOW_FOCUSED_WITHOUT_EDITOR,
53         SoftInputShowHideReason.HIDE_REMOVE_CLIENT,
54         SoftInputShowHideReason.SHOW_RESTORE_IME_VISIBILITY,
55         SoftInputShowHideReason.SHOW_TOGGLE_SOFT_INPUT,
56         SoftInputShowHideReason.HIDE_TOGGLE_SOFT_INPUT,
57         SoftInputShowHideReason.SHOW_SOFT_INPUT_BY_INSETS_API,
58         SoftInputShowHideReason.HIDE_DISPLAY_IME_POLICY_HIDE})
59 public @interface SoftInputShowHideReason {
60     /** Show soft input by {@link android.view.inputmethod.InputMethodManager#showSoftInput}. */
61     int SHOW_SOFT_INPUT = 0;
62 
63     /** Show soft input when {@code InputMethodManagerService#attachNewInputLocked} called. */
64     int ATTACH_NEW_INPUT = 1;
65 
66     /** Show soft input by {@code InputMethodManagerService#showMySoftInput}. */
67     int SHOW_MY_SOFT_INPUT = 2;
68 
69     /**
70      * Hide soft input by
71      * {@link android.view.inputmethod.InputMethodManager#hideSoftInputFromWindow}.
72      */
73     int HIDE_SOFT_INPUT = 3;
74 
75     /** Hide soft input by {@code InputMethodManagerService#hideMySoftInput}. */
76     int HIDE_MY_SOFT_INPUT = 4;
77 
78     /**
79      * Show soft input when navigated forward to the window (with
80      * {@link LayoutParams#SOFT_INPUT_IS_FORWARD_NAVIGATION}} which the focused view is text
81      * editor and system will auto-show the IME when the window can resize or running on a large
82      * screen.
83      */
84     int SHOW_AUTO_EDITOR_FORWARD_NAV = 5;
85 
86     /**
87      * Show soft input when navigated forward to the window with
88      * {@link LayoutParams#SOFT_INPUT_IS_FORWARD_NAVIGATION} and
89      * {@link LayoutParams#SOFT_INPUT_STATE_VISIBLE}.
90      */
91     int SHOW_STATE_VISIBLE_FORWARD_NAV = 6;
92 
93     /**
94      * Show soft input when the window with {@link LayoutParams#SOFT_INPUT_STATE_ALWAYS_VISIBLE}.
95      */
96     int SHOW_STATE_ALWAYS_VISIBLE = 7;
97 
98     /**
99      * Show soft input during {@code InputMethodManagerService} receive changes from
100      * {@code SettingsProvider}.
101      */
102     int SHOW_SETTINGS_ON_CHANGE = 8;
103 
104     /** Hide soft input during switching user. */
105     int HIDE_SWITCH_USER = 9;
106 
107     /** Hide soft input when the user is invalid. */
108     int HIDE_INVALID_USER = 10;
109 
110     /**
111      * Hide soft input when the window with {@link LayoutParams#SOFT_INPUT_STATE_UNSPECIFIED} which
112      * the focused view is not text editor.
113      */
114     int HIDE_UNSPECIFIED_WINDOW = 11;
115 
116     /**
117      * Hide soft input when navigated forward to the window with
118      * {@link LayoutParams#SOFT_INPUT_IS_FORWARD_NAVIGATION} and
119      * {@link LayoutParams#SOFT_INPUT_STATE_HIDDEN}.
120      */
121     int HIDE_STATE_HIDDEN_FORWARD_NAV = 12;
122 
123     /**
124      * Hide soft input when the window with {@link LayoutParams#SOFT_INPUT_STATE_ALWAYS_HIDDEN}.
125      */
126     int HIDE_ALWAYS_HIDDEN_STATE = 13;
127 
128     /** Hide soft input when "adb shell ime <command>" called. */
129     int HIDE_RESET_SHELL_COMMAND = 14;
130 
131     /**
132      * Hide soft input during {@code InputMethodManagerService} receive changes from
133      * {@code SettingsProvider}.
134      */
135     int HIDE_SETTINGS_ON_CHANGE = 15;
136 
137     /**
138      * Hide soft input from {@link com.android.server.policy.PhoneWindowManager} when setting
139      * {@link com.android.internal.R.integer#config_shortPressOnPowerBehavior} in config.xml as
140      * dismiss IME.
141      */
142     int HIDE_POWER_BUTTON_GO_HOME = 16;
143 
144     /** Hide soft input when attaching docked stack. */
145     int HIDE_DOCKED_STACK_ATTACHED = 17;
146 
147     /**
148      * Hide soft input when {@link com.android.server.wm.RecentsAnimationController} starts
149      * intercept touch from app window.
150      */
151     int HIDE_RECENTS_ANIMATION = 18;
152 
153     /**
154      * Hide soft input when {@link com.android.wm.shell.bubbles.BubbleController} is expanding,
155      * switching, or collapsing Bubbles.
156      */
157     int HIDE_BUBBLES = 19;
158 
159     /**
160      * Hide soft input when focusing the same window (e.g. screen turned-off and turn-on) which no
161      * valid focused editor.
162      *
163      * Note: From Android R, the window focus change callback is processed by InputDispatcher,
164      * some focus behavior changes (e.g. There are an activity with a dialog window, after
165      * screen turned-off and turned-on, before Android R the window focus sequence would be
166      * the activity first and then the dialog focused, however, in R the focus sequence would be
167      * only the dialog focused as it's the latest window with input focus) makes we need to hide
168      * soft-input when the same window focused again to align with the same behavior prior to R.
169      */
170     int HIDE_SAME_WINDOW_FOCUSED_WITHOUT_EDITOR = 20;
171 
172     /**
173      * Hide soft input when a {@link com.android.internal.view.IInputMethodClient} is removed.
174      */
175     int HIDE_REMOVE_CLIENT = 21;
176 
177     /**
178      * Show soft input when the system invoking
179      * {@link com.android.server.wm.WindowManagerInternal#shouldRestoreImeVisibility}.
180      */
181     int SHOW_RESTORE_IME_VISIBILITY = 22;
182 
183     /**
184      * Show soft input by
185      * {@link android.view.inputmethod.InputMethodManager#toggleSoftInput(int, int)};
186      */
187     int SHOW_TOGGLE_SOFT_INPUT = 23;
188 
189     /**
190      * Hide soft input by
191      * {@link android.view.inputmethod.InputMethodManager#toggleSoftInput(int, int)};
192      */
193     int HIDE_TOGGLE_SOFT_INPUT = 24;
194 
195     /**
196      * Show soft input by
197      * {@link android.view.InsetsController#show(int)};
198      */
199     int SHOW_SOFT_INPUT_BY_INSETS_API = 25;
200 
201     /**
202      * Hide soft input if Ime policy has been set to {@link WindowManager#DISPLAY_IME_POLICY_HIDE}.
203      * See also {@code InputMethodManagerService#mImeHiddenByDisplayPolicy}.
204      */
205     int HIDE_DISPLAY_IME_POLICY_HIDE = 26;
206 }
207