diff options
Diffstat (limited to 'srcs/juloo.keyboard2/Keyboard2View.java')
| -rw-r--r-- | srcs/juloo.keyboard2/Keyboard2View.java | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 06ed677..a10dce6 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -42,7 +42,9 @@ public class Keyboard2View extends View private Config _config; private float _keyWidth; - private float _bottomMargin; + private float _marginRight; + private float _marginLeft; + private float _marginBottom; private Theme _theme; @@ -232,7 +234,7 @@ public class Keyboard2View extends View private KeyboardData.Key getKeyAtPosition(float tx, float ty) { KeyboardData.Row row = getRowAtPosition(ty); - float x = _config.horizontal_margin; + float x = _marginLeft; if (row == null || tx < x) return null; for (KeyboardData.Key key : row.keys) @@ -256,28 +258,56 @@ public class Keyboard2View extends View @Override public void onMeasure(int wSpec, int hSpec) { - DisplayMetrics dm = getContext().getResources().getDisplayMetrics(); - int width = dm.widthPixels; - _bottomMargin = _config.margin_bottom; - // Compatibility with display cutouts and navigation on the right + int width; + int insets_left = 0; + int insets_right = 0; + int insets_bottom = 0; + // LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS is set in [Keyboard2#updateSoftInputWindowLayoutParams]. + // and keyboard is allowed do draw behind status/navigation bars if (VERSION.SDK_INT >= 30) { WindowMetrics metrics = ((WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE)) .getCurrentWindowMetrics(); - Insets insets = metrics.getWindowInsets().getInsetsIgnoringVisibility( - WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars() - | WindowInsets.Type.displayCutout()); - width = metrics.getBounds().width() - insets.right - insets.left; - // Starting in API 35, keyboard window has LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS + width = metrics.getBounds().width(); + WindowInsets wi = metrics.getWindowInsets(); + int insets_types = + WindowInsets.Type.statusBars() + | WindowInsets.Type.displayCutout() + | WindowInsets.Type.mandatorySystemGestures() + | WindowInsets.Type.navigationBars(); + Insets insets = wi.getInsets(insets_types); + insets_left = insets.left; + insets_right = insets.right; + // On API 35, the keyboard is allowed to draw under the + // button-navigation bar but on lower APIs, it must be discounted from + // the width. + if (VERSION.SDK_INT < 35) + { + Insets nav_insets = wi.getInsets(WindowInsets.Type.navigationBars()); + width -= nav_insets.left + nav_insets.right; + insets_left -= nav_insets.left; + insets_right -= nav_insets.right; + } + // [insets.bottom] doesn't take into account the buttons that appear in + // the gesture navigation bar when the IME is showing so ensure a minimum + // of margin is added. if (VERSION.SDK_INT >= 35) - _bottomMargin += insets.bottom; + insets_bottom = Math.max(insets.bottom, _config.bottomInsetMin); + } + else + { + DisplayMetrics dm = getContext().getResources().getDisplayMetrics(); + width = dm.widthPixels; } int height = (int)(_config.keyHeight * _keyboard.keysHeight - + _config.marginTop + _bottomMargin); + + _config.marginTop + _marginBottom); setMeasuredDimension(width, height); - _keyWidth = (width - (_config.horizontal_margin * 2)) / _keyboard.keysWidth; + _marginLeft = Math.max(_config.horizontal_margin, insets_left); + _marginRight = Math.max(_config.horizontal_margin, insets_right); + _marginBottom = _config.margin_bottom + insets_bottom; + _keyWidth = (width - _marginLeft - _marginRight) / _keyboard.keysWidth; } @Override @@ -289,10 +319,10 @@ public class Keyboard2View extends View { // Disable the back-gesture on the keyboard area Rect keyboard_area = new Rect( - left + (int)_config.horizontal_margin, + left + (int)_marginLeft, top + (int)_config.marginTop, - right - (int)_config.horizontal_margin, - bottom - (int)_bottomMargin); + right - (int)_marginRight, + bottom - (int)_marginBottom); setSystemGestureExclusionRects(Arrays.asList(keyboard_area)); } } @@ -327,7 +357,7 @@ public class Keyboard2View extends View for (KeyboardData.Row row : _keyboard.rows) { y += row.shift * _config.keyHeight; - float x = _config.horizontal_margin + key_horizontal_margin / 2; + float x = _marginLeft + key_horizontal_margin / 2; float keyH = row.height * _config.keyHeight - key_vertical_margin; for (KeyboardData.Key k : row.keys) { |
