Skip to content

Commit bd98e7f

Browse files
John SpurlockThe Android Automerger
John Spurlock
authored and
The Android Automerger
committed
Move the IME navigation guard view up to decor.
Although the IME windows are now allowed to extend into the nav bar, some IMEs were making assumptions about computed insets based on the height of the content view. So our navigation bar view (opaque view blocking the nav bar area to avoid the island effect when transparent) needs to live above the content view in the hierarchy, making the content view the same height as it was before. A surgical spot to put the guard view is up at the root view (PhoneWindow.DecorView). fitSystemWindows is always called since this view is not recreated, and the layout is stable: waiting until the IME is attached to the window is too late to add a guard view. This is above the screen_* layouts, so will work without having to touch all of them. And it only affects windows of TYPE_INPUT_METHOD. Bug:11237795 Change-Id: I6a93f30aec83f1cecfb854073046cbc87ab4aa66
1 parent 9f6a3c2 commit bd98e7f

File tree

4 files changed

+34
-69
lines changed

4 files changed

+34
-69
lines changed

core/java/com/android/internal/inputmethod/InputMethodRoot.java

-61
This file was deleted.

core/res/res/layout/input_method.xml

+2-7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
*/
1919
-->
2020

21-
<com.android.internal.inputmethod.InputMethodRoot xmlns:android="http://schemas.android.com/apk/res/android"
21+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2222
android:id="@+id/parentPanel"
2323
android:layout_width="match_parent"
2424
android:layout_height="wrap_content"
2525
android:orientation="vertical"
26-
android:gravity="start|bottom"
2726
>
2827

2928
<LinearLayout
@@ -54,8 +53,4 @@
5453
android:visibility="gone">
5554
</FrameLayout>
5655

57-
<View android:id="@+id/navigationGuard"
58-
android:layout_width="match_parent"
59-
android:layout_height="0dp"
60-
android:background="@+color/input_method_navigation_guard"/>
61-
</com.android.internal.inputmethod.InputMethodRoot>
56+
</LinearLayout>

core/res/res/values/symbols.xml

-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
<java-symbol type="id" name="month" />
106106
<java-symbol type="id" name="month_name" />
107107
<java-symbol type="id" name="name" />
108-
<java-symbol type="id" name="navigationGuard" />
109108
<java-symbol type="id" name="next" />
110109
<java-symbol type="id" name="next_button" />
111110
<java-symbol type="id" name="new_app_action" />

policy/src/com/android/internal/policy/impl/PhoneWindow.java

+32
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import static android.view.WindowManager.LayoutParams.*;
2424

2525
import android.view.ViewConfiguration;
26+
27+
import com.android.internal.R;
2628
import com.android.internal.view.RootViewSurfaceTaker;
2729
import com.android.internal.view.StandaloneActionMode;
2830
import com.android.internal.view.menu.ContextMenuBuilder;
@@ -1920,6 +1922,9 @@ private final class DecorView extends FrameLayout implements RootViewSurfaceTake
19201922
private PopupWindow mActionModePopup;
19211923
private Runnable mShowActionModePopup;
19221924

1925+
// View added at runtime to IME windows to cover the navigation bar
1926+
private View mNavigationGuard;
1927+
19231928
public DecorView(Context context, int featureId) {
19241929
super(context);
19251930
mFeatureId = featureId;
@@ -2479,6 +2484,33 @@ public void setWindowFrame(Drawable drawable) {
24792484
@Override
24802485
protected boolean fitSystemWindows(Rect insets) {
24812486
mFrameOffsets.set(insets);
2487+
2488+
// IMEs lay out below the nav bar, but the content view must not (for back compat)
2489+
if (getAttributes().type == WindowManager.LayoutParams.TYPE_INPUT_METHOD) {
2490+
// prevent the content view from including the nav bar height
2491+
if (mContentParent != null) {
2492+
if (mContentParent.getLayoutParams() instanceof MarginLayoutParams) {
2493+
MarginLayoutParams mlp =
2494+
(MarginLayoutParams) mContentParent.getLayoutParams();
2495+
mlp.bottomMargin = insets.bottom;
2496+
mContentParent.setLayoutParams(mlp);
2497+
}
2498+
}
2499+
// position the navigation guard view, creating it if necessary
2500+
if (mNavigationGuard == null) {
2501+
mNavigationGuard = new View(mContext);
2502+
mNavigationGuard.setBackgroundColor(mContext.getResources()
2503+
.getColor(R.color.input_method_navigation_guard));
2504+
addView(mNavigationGuard, new LayoutParams(
2505+
LayoutParams.MATCH_PARENT, insets.bottom,
2506+
Gravity.START | Gravity.BOTTOM));
2507+
} else {
2508+
LayoutParams lp = (LayoutParams) mNavigationGuard.getLayoutParams();
2509+
lp.height = insets.bottom;
2510+
mNavigationGuard.setLayoutParams(lp);
2511+
}
2512+
}
2513+
24822514
if (getForeground() != null) {
24832515
drawableChanged();
24842516
}

0 commit comments

Comments
 (0)