summaryrefslogtreecommitdiff
path: root/packages/PrintSpooler/src
diff options
context:
space:
mode:
author Yohei Yukawa <yukawa@google.com> 2023-08-24 13:11:43 -0700
committer Yohei Yukawa <yukawa@google.com> 2023-08-24 13:11:43 -0700
commit2a757ef4aea5cf9674be508e87378f66874ef163 (patch)
treee61e6a26537e997c77da9678bfd3e06e513fda60 /packages/PrintSpooler/src
parent4d4fc565241c2d6297d3248b9120b2c5360d59c3 (diff)
Add @hide IMM#hideSoftInputFromView as an optimization
It seems that it is relatively a common pattern used in the Framework code when trying to hide a software keyboard. var imm = view.getSystemService(InputMethodManager.class); if (imm != null && imm.isActive(view)) { imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } The above code can be easily optimized by introducing a counterpart of InputMethodManager#showSoftInput(View view, int flags); so that the hide request can be issued when and only when the specified view has already established a connection to the IME. The optimized code would look like as follows. var imm = view.getSystemService(InputMethodManager.class); if (imm != null) { imm.hideSoftInputFromView(view, 0); } Major advantages of such an approach are: * IMM#checkFocus() can never be called. * IMM needs to take a lock only once. With above, this CL introduces IMM#hideSoftInputFromView() as @hide method so that we can start making sure that such an approach works well. Fix: 296466613 Test: atest CtsInputMethodTestCases:EditTextImeSupportTest Change-Id: I01e5a29c0f82d068751774a2c58a1bd7b7b7f91a
Diffstat (limited to 'packages/PrintSpooler/src')
-rw-r--r--packages/PrintSpooler/src/com/android/printspooler/widget/PrintContentView.java4
1 files changed, 1 insertions, 3 deletions
diff --git a/packages/PrintSpooler/src/com/android/printspooler/widget/PrintContentView.java b/packages/PrintSpooler/src/com/android/printspooler/widget/PrintContentView.java
index b0aa8f19f24b..6ecffa4752cf 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/widget/PrintContentView.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/widget/PrintContentView.java
@@ -383,9 +383,7 @@ public final class PrintContentView extends ViewGroup implements View.OnClickLis
if (focused != null && focused.isFocused()) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(
Context.INPUT_METHOD_SERVICE);
- if (imm.isActive(focused)) {
- imm.hideSoftInputFromWindow(getWindowToken(), 0);
- }
+ imm.hideSoftInputFromView(focused, 0);
focused.clearFocus();
}
}