Corrects CompactExtractEditLayout to account for systemWindowInsetBottom

Percentage-base sizes involving screen height are incorrect for watch
devices with non 1:1 display metrics. These are round screens with an
inactive bottom portion. To maintain the correct proportions the
bottom inset must be added to the height.

BUG: 36728475
Change-Id: Ibe351d1db7964b4b89ce9a588c171cd8407e2a50
This commit is contained in:
Mark Renouf
2017-03-29 16:08:21 -04:00
parent d4fdb6e3b2
commit d1a0d19794

View File

@@ -17,6 +17,7 @@
package android.inputmethodservice;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.annotation.FractionRes;
import android.util.AttributeSet;
@@ -24,6 +25,7 @@ import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.LinearLayout;
/**
@@ -109,9 +111,25 @@ public class CompactExtractEditLayout extends LinearLayout {
super.onAttachedToWindow();
if (mPerformLayoutChanges) {
Resources res = getResources();
Configuration cfg = res.getConfiguration();
DisplayMetrics dm = res.getDisplayMetrics();
int heightPixels = dm.heightPixels;
int widthPixels = dm.widthPixels;
int heightPixels = dm.heightPixels;
// Percentages must be based on the pixel height of the full (apparent) display height
// which is sometimes different from display metrics.
//
// On a round device, a display height smaller than width indicates a chin (cropped
// edge of the display) for which there is no screen buffer allocated. This is
// typically 25-35px in height.
//
// getRootWindowInsets() does not function for InputMethod windows (always null).
// Instead just set height to match width if less. This is safe because round wear
// devices are by definition 1:1 aspect ratio.
if (cfg.isScreenRound() && heightPixels < widthPixels) {
heightPixels = widthPixels;
}
applyProportionalLayout(widthPixels, heightPixels);
}
}