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