summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2019-10-14 17:04:57 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-10-14 17:04:57 +0000
commitd6fd6f27f569d3492d803b7cf363184bb4572bbb (patch)
tree34088cda5e1cb78f14619d1b9322172aa30f4f8e /core/java/android
parent30f59237f2cf8c661f506e2eed2782c91bf4c78c (diff)
parentd7fc5864f44a7cff1e4b9851d5675a2c2b9541f6 (diff)
Merge changes from topic "b/142461756"
* changes: Ime target window should control when to hide IME (2/2) Ime target window should control when to hide IME (1/2)
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/view/IWindow.aidl8
-rw-r--r--core/java/android/view/InsetsAnimationControlImpl.java4
-rw-r--r--core/java/android/view/InsetsController.java65
-rw-r--r--core/java/android/view/ViewRootImpl.java19
4 files changed, 62 insertions, 34 deletions
diff --git a/core/java/android/view/IWindow.aidl b/core/java/android/view/IWindow.aidl
index 4b872d3ad758..8bf99ec4f251 100644
--- a/core/java/android/view/IWindow.aidl
+++ b/core/java/android/view/IWindow.aidl
@@ -81,6 +81,14 @@ oneway interface IWindow {
*/
void showInsets(int types, boolean fromIme);
+ /**
+ * Called when a set of insets source window should be hidden by policy.
+ *
+ * @param types internal inset types (WindowInsets.Type.InsetType) to hide
+ * @param fromIme true if this request originated from IME (InputMethodService).
+ */
+ void hideInsets(int types, boolean fromIme);
+
void moved(int newX, int newY);
void dispatchAppVisibility(boolean visible);
void dispatchGetNewSurface();
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);
}
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 9ddd84f1943c..20dc23492ae5 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -4570,6 +4570,7 @@ public final class ViewRootImpl implements ViewParent,
private static final int MSG_SYSTEM_GESTURE_EXCLUSION_CHANGED = 32;
private static final int MSG_LOCATION_IN_PARENT_DISPLAY_CHANGED = 33;
private static final int MSG_SHOW_INSETS = 34;
+ private static final int MSG_HIDE_INSETS = 35;
final class ViewRootHandler extends Handler {
@@ -4636,6 +4637,8 @@ public final class ViewRootImpl implements ViewParent,
return "MSG_LOCATION_IN_PARENT_DISPLAY_CHANGED";
case MSG_SHOW_INSETS:
return "MSG_SHOW_INSETS";
+ case MSG_HIDE_INSETS:
+ return "MSG_HIDE_INSETS";
}
return super.getMessageName(message);
}
@@ -4754,6 +4757,10 @@ public final class ViewRootImpl implements ViewParent,
mInsetsController.show(msg.arg1, msg.arg2 == 1);
break;
}
+ case MSG_HIDE_INSETS: {
+ mInsetsController.hide(msg.arg1, msg.arg2 == 1);
+ break;
+ }
case MSG_WINDOW_MOVED:
if (mAdded) {
final int w = mWinFrame.width();
@@ -7559,6 +7566,10 @@ public final class ViewRootImpl implements ViewParent,
mHandler.obtainMessage(MSG_SHOW_INSETS, types, fromIme ? 1 : 0).sendToTarget();
}
+ private void hideInsets(@InsetType int types, boolean fromIme) {
+ mHandler.obtainMessage(MSG_HIDE_INSETS, types, fromIme ? 1 : 0).sendToTarget();
+ }
+
public void dispatchMoved(int newX, int newY) {
if (DEBUG_LAYOUT) Log.v(mTag, "Window moved " + this + ": newX=" + newX + " newY=" + newY);
if (mTranslator != null) {
@@ -8682,6 +8693,14 @@ public final class ViewRootImpl implements ViewParent,
}
@Override
+ public void hideInsets(@InsetType int types, boolean fromIme) {
+ final ViewRootImpl viewAncestor = mViewAncestor.get();
+ if (viewAncestor != null) {
+ viewAncestor.hideInsets(types, fromIme);
+ }
+ }
+
+ @Override
public void moved(int newX, int newY) {
final ViewRootImpl viewAncestor = mViewAncestor.get();
if (viewAncestor != null) {