Merge "Support WIC.show(IME) from Activity#onCreate" into rvc-dev

This commit is contained in:
Taran Singh
2020-04-17 19:28:28 +00:00
committed by Android (Google) Code Review
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
* execute it because we didn't have control yet.
*/
private boolean mImeRequestedShow;
private boolean mIsRequestedVisibleAwaitingControl;
public ImeInsetsSourceConsumer(
InsetsState state, Supplier<Transaction> transactionSupplier,
@@ -88,15 +88,7 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
public void onWindowFocusLost() {
super.onWindowFocusLost();
getImm().unregisterImeConsumer(this);
mImeRequestedShow = false;
}
@Override
public void show(boolean fromIme) {
super.show(fromIme);
if (fromIme) {
mImeRequestedShow = true;
}
mIsRequestedVisibleAwaitingControl = false;
}
@Override
@@ -119,11 +111,14 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
// TODO: ResultReceiver for IME.
// 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
// 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 (fromIme || mImeRequestedShow || mState.getSource(getType()).isVisible()) {
mImeRequestedShow = false;
if (fromIme || mState.getSource(getType()).isVisible()) {
return ShowResult.SHOW_IMMEDIATELY;
}
@@ -148,11 +143,19 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
public void setControl(@Nullable InsetsSourceControl control, int[] showTypes,
int[] hideTypes) {
super.setControl(control, showTypes, hideTypes);
if (control == null) {
if (control == getControl()) {
return;
}
if (control == null && !mIsRequestedVisibleAwaitingControl) {
hide();
}
}
@Override
protected boolean isRequestedVisibleAwaitingControl() {
return mIsRequestedVisibleAwaitingControl;
}
private boolean isDummyOrEmptyEditor(EditorInfo info) {
// TODO(b/123044812): Handle dummy input gracefully in IME Insets API
return info == null || (info.fieldId <= 0 && info.inputType <= 0);

View File

@@ -107,8 +107,8 @@ public class InsetsSourceConsumer {
} else {
// We are gaining control, and need to run an animation since previous state
// didn't match
if (mRequestedVisible != mState.getSource(mType).isVisible()) {
if (mRequestedVisible) {
if (isRequestedVisibleAwaitingControl() != mState.getSource(mType).isVisible()) {
if (isRequestedVisibleAwaitingControl()) {
showTypes[0] |= toPublicType(getType());
} else {
hideTypes[0] |= toPublicType(getType());
@@ -138,6 +138,16 @@ public class InsetsSourceConsumer {
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() {
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
* the moment.
*/
private void setRequestedVisible(boolean requestedVisible) {
protected void setRequestedVisible(boolean requestedVisible) {
mRequestedVisible = requestedVisible;
if (applyLocalVisibilityOverride()) {
mController.notifyVisibilityChanged();