Provide action to dismiss IME
Make the FocusParkingView respond to ACTION_DISMISS by dismissing the
IME. The RotaryService uses this to dismiss the IME when the user
navigates to a non-editable view.
Bug: 131421840
Bug: 154777887
Test: atest CarRotaryControllerRoboTests
Change-Id: I4bf3ca56e073c7300a7ee8d549a0d9730ce3a566
diff --git a/car-ui-lib/src/com/android/car/ui/FocusParkingView.java b/car-ui-lib/src/com/android/car/ui/FocusParkingView.java
index 1b4bd13..2167d23 100644
--- a/car-ui-lib/src/com/android/car/ui/FocusParkingView.java
+++ b/car-ui-lib/src/com/android/car/ui/FocusParkingView.java
@@ -15,12 +15,14 @@
*/
package com.android.car.ui;
+import static android.view.accessibility.AccessibilityNodeInfo.ACTION_COLLAPSE;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_DISMISS;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
+import android.view.inputmethod.InputMethodManager;
import androidx.annotation.Nullable;
@@ -116,11 +118,18 @@
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
- if (action == ACTION_DISMISS) {
- // Try to move focus to the default focus.
- getRootView().restoreDefaultFocus();
- // The action failed if the FocusParkingView is still focused.
- return !isFocused();
+ switch (action) {
+ case ACTION_DISMISS:
+ // Try to move focus to the default focus.
+ getRootView().restoreDefaultFocus();
+ // The action failed if the FocusParkingView is still focused.
+ return !isFocused();
+ case ACTION_COLLAPSE:
+ // Hide the IME.
+ InputMethodManager inputMethodManager =
+ getContext().getSystemService(InputMethodManager.class);
+ return inputMethodManager.hideSoftInputFromWindow(getWindowToken(),
+ /* flags= */ 0);
}
return super.performAccessibilityAction(action, arguments);
}