diff options
| author | Taran Singh <tarandeep@google.com> | 2019-10-10 14:45:17 +0200 |
|---|---|---|
| committer | Taran Singh <tarandeep@google.com> | 2019-10-14 12:40:09 +0000 |
| commit | d7fc5864f44a7cff1e4b9851d5675a2c2b9541f6 (patch) | |
| tree | d32d3e3b0784c985289d63f213033f8a5f99e54d /core/java/android | |
| parent | f1e0887eb83483eff1ef9fee8de72266387d45b8 (diff) | |
Ime target window should control when to hide IME (2/2)
This followup CL implements hideInsets() introduced in 1/2.
Bug: 142461756
Bug: 111084606
Test: Manually tested using steps below:
1. Make sure new insets flag is enabled
2. Launch any activity which has child window with NOT_FOCUSABLE,
ALT_FOCUSABLE_IM (e.g. Instagram login screen)
3. Verify IME can be shown and hidden by this window.
Change-Id: I307594014eca8a06397c739ffbc9c12eac160fdc
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/InsetsAnimationControlImpl.java | 4 | ||||
| -rw-r--r-- | core/java/android/view/InsetsController.java | 65 |
2 files changed, 35 insertions, 34 deletions
diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java index 341c2147c64a..e4deffadc966 100644 --- a/core/java/android/view/InsetsAnimationControlImpl.java +++ b/core/java/android/view/InsetsAnimationControlImpl.java @@ -229,6 +229,10 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll final InsetsSourceConsumer consumer = items.valueAt(i); final InsetsSource source = mInitialInsetsState.getSource(consumer.getType()); final InsetsSourceControl control = consumer.getControl(); + if (control == null) { + // Control may not be available for consumer yet or revoked. + continue; + } final SurfaceControl leash = consumer.getControl().getLeash(); mTmpMatrix.setTranslate(control.getSurfacePosition().x, control.getSurfacePosition().y); diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index 5a8636d85a08..5bb4f63d62c8 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -251,6 +251,10 @@ public class InsetsController implements WindowInsetsController { @Override public void hide(@InsetType int types) { + hide(types, false /* fromIme */); + } + + void hide(@InsetType int types, boolean fromIme) { int typesReady = 0; final ArraySet<Integer> internalTypes = InsetsState.toInternalType(types); for (int i = internalTypes.size() - 1; i >= 0; i--) { @@ -265,7 +269,7 @@ public class InsetsController implements WindowInsetsController { } typesReady |= InsetsState.toPublicType(consumer.getType()); } - applyAnimation(typesReady, false /* show */, false /* fromIme */); + applyAnimation(typesReady, false /* show */, fromIme /* fromIme */); } @Override @@ -331,42 +335,35 @@ public class InsetsController implements WindowInsetsController { boolean isReady = true; for (int i = internalTypes.size() - 1; i >= 0; i--) { InsetsSourceConsumer consumer = getSourceConsumer(internalTypes.valueAt(i)); - // Double check for IME that IME target window has focus. - if (consumer.getType() != TYPE_IME || consumer.hasWindowFocus()) { - boolean setVisible = !consumer.isVisible(); - if (setVisible) { - // Show request - switch(consumer.requestShow(fromIme)) { - case ShowResult.SHOW_IMMEDIATELY: - typesReady |= InsetsState.toPublicType(consumer.getType()); - break; - case ShowResult.SHOW_DELAYED: - isReady = false; - break; - case ShowResult.SHOW_FAILED: - // IME cannot be shown (since it didn't have focus), proceed - // with animation of other types. - if (mPendingTypesToShow != 0) { - // remove IME from pending because view no longer has focus. - mPendingTypesToShow &= ~InsetsState.toPublicType(TYPE_IME); - } - break; - } - } else { - // Hide request - // TODO: Move notifyHidden() to beginning of the hide animation - // (when visibility actually changes using hideDirectly()). - consumer.notifyHidden(); - typesReady |= InsetsState.toPublicType(consumer.getType()); + boolean setVisible = !consumer.isVisible(); + if (setVisible) { + // Show request + switch(consumer.requestShow(fromIme)) { + case ShowResult.SHOW_IMMEDIATELY: + typesReady |= InsetsState.toPublicType(consumer.getType()); + break; + case ShowResult.SHOW_DELAYED: + isReady = false; + break; + case ShowResult.SHOW_FAILED: + // IME cannot be shown (since it didn't have focus), proceed + // with animation of other types. + if (mPendingTypesToShow != 0) { + // remove IME from pending because view no longer has focus. + mPendingTypesToShow &= ~InsetsState.toPublicType(TYPE_IME); + } + break; } - consumers.put(consumer.getType(), consumer); } else { - // window doesnt have focus, no-op. - isReady = false; - // TODO: Let the calling app know that window has lost focus and - // show()/hide()/controlWindowInsetsAnimation requests will be ignored. - typesReady &= ~InsetsState.toPublicType(consumer.getType()); + // Hide request + // TODO: Move notifyHidden() to beginning of the hide animation + // (when visibility actually changes using hideDirectly()). + if (!fromIme) { + consumer.notifyHidden(); + } + typesReady |= InsetsState.toPublicType(consumer.getType()); } + consumers.put(consumer.getType(), consumer); } return new Pair<>(typesReady, isReady); } |
