mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-11-24 16:23:14 +01:00
Fix overflow due to navigation on the right and cutouts (#641)
Take display cutouts and navigation bars when computing the keyboard width on SDK >= 30.
This commit is contained in:
parent
1a290f96f2
commit
93d58571cc
@ -3,6 +3,7 @@ package juloo.keyboard2;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Insets;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
@ -13,6 +14,9 @@ import android.util.DisplayMetrics;
|
|||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
|
import android.view.WindowInsets;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.view.WindowMetrics;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class Keyboard2View extends View
|
public class Keyboard2View extends View
|
||||||
@ -256,6 +260,17 @@ public class Keyboard2View extends View
|
|||||||
int height =
|
int height =
|
||||||
(int)(_config.keyHeight * _keyboard.keysHeight
|
(int)(_config.keyHeight * _keyboard.keysHeight
|
||||||
+ _config.marginTop + _config.margin_bottom);
|
+ _config.marginTop + _config.margin_bottom);
|
||||||
|
// Compatibility with display cutouts and navigation on the right
|
||||||
|
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;
|
||||||
|
}
|
||||||
setMeasuredDimension(width, height);
|
setMeasuredDimension(width, height);
|
||||||
_keyWidth = (width - (_config.horizontal_margin * 2)) / _keyboard.keysWidth;
|
_keyWidth = (width - (_config.horizontal_margin * 2)) / _keyboard.keysWidth;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user