Merge "Support WIC.show(IME) from Activity#onCreate" into rvc-dev am: 104919428d am: 6fcb222882

Change-Id: Ia2627b93bc5d97345702613114db9b28821b4c87
This commit is contained in:
Taran Singh
2020-04-17 19:49:32 +00:00
committed by Automerger Merge Worker
2 changed files with 29 additions and 16 deletions

View File

@@ -49,7 +49,7 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
* Tracks whether we have an outstanding request from the IME to show, but weren't able to * Tracks whether we have an outstanding request from the IME to show, but weren't able to
* execute it because we didn't have control yet. * execute it because we didn't have control yet.
*/ */
private boolean mImeRequestedShow; private boolean mIsRequestedVisibleAwaitingControl;
public ImeInsetsSourceConsumer( public ImeInsetsSourceConsumer(
InsetsState state, Supplier<Transaction> transactionSupplier, InsetsState state, Supplier<Transaction> transactionSupplier,
@@ -88,15 +88,7 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
public void onWindowFocusLost() { public void onWindowFocusLost() {
super.onWindowFocusLost(); super.onWindowFocusLost();
getImm().unregisterImeConsumer(this); getImm().unregisterImeConsumer(this);
mImeRequestedShow = false; mIsRequestedVisibleAwaitingControl = false;
}
@Override
public void show(boolean fromIme) {
super.show(fromIme);
if (fromIme) {
mImeRequestedShow = true;
}
} }
@Override @Override
@@ -119,11 +111,14 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
// TODO: ResultReceiver for IME. // TODO: ResultReceiver for IME.
// TODO: Set mShowOnNextImeRender to automatically show IME and guard it with a flag. // TODO: Set mShowOnNextImeRender to automatically show IME and guard it with a flag.
if (getControl() == null) {
// If control is null, schedule to show IME when control is available.
mIsRequestedVisibleAwaitingControl = true;
}
// If we had a request before to show from IME (tracked with mImeRequestedShow), reaching // If we had a request before to show from IME (tracked with mImeRequestedShow), reaching
// this code here means that we now got control, so we can start the animation immediately. // this code here means that we now got control, so we can start the animation immediately.
// If client window is trying to control IME and IME is already visible, it is immediate. // If client window is trying to control IME and IME is already visible, it is immediate.
if (fromIme || mImeRequestedShow || mState.getSource(getType()).isVisible()) { if (fromIme || mState.getSource(getType()).isVisible()) {
mImeRequestedShow = false;
return ShowResult.SHOW_IMMEDIATELY; return ShowResult.SHOW_IMMEDIATELY;
} }
@@ -148,11 +143,19 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
public void setControl(@Nullable InsetsSourceControl control, int[] showTypes, public void setControl(@Nullable InsetsSourceControl control, int[] showTypes,
int[] hideTypes) { int[] hideTypes) {
super.setControl(control, showTypes, hideTypes); super.setControl(control, showTypes, hideTypes);
if (control == null) { if (control == getControl()) {
return;
}
if (control == null && !mIsRequestedVisibleAwaitingControl) {
hide(); hide();
} }
} }
@Override
protected boolean isRequestedVisibleAwaitingControl() {
return mIsRequestedVisibleAwaitingControl;
}
private boolean isDummyOrEmptyEditor(EditorInfo info) { private boolean isDummyOrEmptyEditor(EditorInfo info) {
// TODO(b/123044812): Handle dummy input gracefully in IME Insets API // TODO(b/123044812): Handle dummy input gracefully in IME Insets API
return info == null || (info.fieldId <= 0 && info.inputType <= 0); return info == null || (info.fieldId <= 0 && info.inputType <= 0);

View File

@@ -107,8 +107,8 @@ public class InsetsSourceConsumer {
} else { } else {
// We are gaining control, and need to run an animation since previous state // We are gaining control, and need to run an animation since previous state
// didn't match // didn't match
if (mRequestedVisible != mState.getSource(mType).isVisible()) { if (isRequestedVisibleAwaitingControl() != mState.getSource(mType).isVisible()) {
if (mRequestedVisible) { if (isRequestedVisibleAwaitingControl()) {
showTypes[0] |= toPublicType(getType()); showTypes[0] |= toPublicType(getType());
} else { } else {
hideTypes[0] |= toPublicType(getType()); hideTypes[0] |= toPublicType(getType());
@@ -138,6 +138,16 @@ public class InsetsSourceConsumer {
return mSourceControl; return mSourceControl;
} }
/**
* Determines if the consumer will be shown after control is available.
* Note: for system bars this method is same as {@link #isRequestedVisible()}.
*
* @return {@code true} if consumer has a pending show.
*/
protected boolean isRequestedVisibleAwaitingControl() {
return isRequestedVisible();
}
int getType() { int getType() {
return mType; return mType;
} }
@@ -263,7 +273,7 @@ public class InsetsSourceConsumer {
* Sets requested visibility from the client, regardless of whether we are able to control it at * Sets requested visibility from the client, regardless of whether we are able to control it at
* the moment. * the moment.
*/ */
private void setRequestedVisible(boolean requestedVisible) { protected void setRequestedVisible(boolean requestedVisible) {
mRequestedVisible = requestedVisible; mRequestedVisible = requestedVisible;
if (applyLocalVisibilityOverride()) { if (applyLocalVisibilityOverride()) {
mController.notifyVisibilityChanged(); mController.notifyVisibilityChanged();