mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-08-16 17:30:58 +02:00
Fix extra bottom margin when navbar buttons absent (#1024)
* Fix extra bottom margin when navbar buttons absent Fix the extra space that was appearing when the gesture-navigation bar didn't contain the "switch IME" or "close IME" buttons. This was found on OneUI 7 with the two "keyboard key" related options turned off. * Remove unneeded nav bar detection and width computation
This commit is contained in:
@ -6,9 +6,6 @@
|
|||||||
<dimen name="emoji_text_size">28dp</dimen>
|
<dimen name="emoji_text_size">28dp</dimen>
|
||||||
<dimen name="clipboard_view_height">300dp</dimen>
|
<dimen name="clipboard_view_height">300dp</dimen>
|
||||||
<dimen name="pref_button_size">28dp</dimen>
|
<dimen name="pref_button_size">28dp</dimen>
|
||||||
<!-- Margin needed to accomodate the gesture nav bar on Android 15. Found in
|
|
||||||
[core/res/res/values/dimens.xml]. -->
|
|
||||||
<dimen name="bottom_inset_min">48dp</dimen>
|
|
||||||
<!-- Will be overwritten automatically by Gradle for the debug build variant -->
|
<!-- Will be overwritten automatically by Gradle for the debug build variant -->
|
||||||
<bool name="debug_logs">false</bool>
|
<bool name="debug_logs">false</bool>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -81,7 +81,6 @@ public final class Config
|
|||||||
int current_layout_landscape;
|
int current_layout_landscape;
|
||||||
int current_layout_unfolded_portrait;
|
int current_layout_unfolded_portrait;
|
||||||
int current_layout_unfolded_landscape;
|
int current_layout_unfolded_landscape;
|
||||||
public int bottomInsetMin;
|
|
||||||
|
|
||||||
private Config(SharedPreferences prefs, Resources res, IKeyEventHandler h, Boolean foldableUnfolded)
|
private Config(SharedPreferences prefs, Resources res, IKeyEventHandler h, Boolean foldableUnfolded)
|
||||||
{
|
{
|
||||||
@ -176,8 +175,6 @@ public final class Config
|
|||||||
current_layout_unfolded_landscape = _prefs.getInt("current_layout_unfolded_landscape", 0);
|
current_layout_unfolded_landscape = _prefs.getInt("current_layout_unfolded_landscape", 0);
|
||||||
circle_sensitivity = Integer.valueOf(_prefs.getString("circle_sensitivity", "2"));
|
circle_sensitivity = Integer.valueOf(_prefs.getString("circle_sensitivity", "2"));
|
||||||
clipboard_history_enabled = _prefs.getBoolean("clipboard_history_enabled", false);
|
clipboard_history_enabled = _prefs.getBoolean("clipboard_history_enabled", false);
|
||||||
bottomInsetMin = Utils.is_navigation_bar_gestural(res) ?
|
|
||||||
(int)res.getDimension(R.dimen.bottom_inset_min) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int get_current_layout()
|
public int get_current_layout()
|
||||||
|
@ -47,6 +47,9 @@ public class Keyboard2View extends View
|
|||||||
private float _marginRight;
|
private float _marginRight;
|
||||||
private float _marginLeft;
|
private float _marginLeft;
|
||||||
private float _marginBottom;
|
private float _marginBottom;
|
||||||
|
private int _insets_left = 0;
|
||||||
|
private int _insets_right = 0;
|
||||||
|
private int _insets_bottom = 0;
|
||||||
|
|
||||||
private Theme _theme;
|
private Theme _theme;
|
||||||
private Theme.Computed _tc;
|
private Theme.Computed _tc;
|
||||||
@ -264,35 +267,11 @@ public class Keyboard2View extends View
|
|||||||
public void onMeasure(int wSpec, int hSpec)
|
public void onMeasure(int wSpec, int hSpec)
|
||||||
{
|
{
|
||||||
int width;
|
int width;
|
||||||
int insets_left = 0;
|
DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
|
||||||
int insets_right = 0;
|
width = dm.widthPixels;
|
||||||
int insets_bottom = 0;
|
_marginLeft = Math.max(_config.horizontal_margin, _insets_left);
|
||||||
// LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS is set in [Keyboard2#updateSoftInputWindowLayoutParams].
|
_marginRight = Math.max(_config.horizontal_margin, _insets_right);
|
||||||
// and keyboard is allowed do draw behind status/navigation bars
|
_marginBottom = _config.margin_bottom + _insets_bottom;
|
||||||
if (VERSION.SDK_INT >= 35)
|
|
||||||
{
|
|
||||||
WindowMetrics metrics =
|
|
||||||
((WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE))
|
|
||||||
.getCurrentWindowMetrics();
|
|
||||||
width = metrics.getBounds().width();
|
|
||||||
WindowInsets wi = metrics.getWindowInsets();
|
|
||||||
int insets_types =
|
|
||||||
WindowInsets.Type.systemBars()
|
|
||||||
| WindowInsets.Type.displayCutout()
|
|
||||||
| WindowInsets.Type.mandatorySystemGestures();
|
|
||||||
Insets insets = wi.getInsets(insets_types);
|
|
||||||
insets_left = insets.left;
|
|
||||||
insets_right = insets.right;
|
|
||||||
insets_bottom = Math.max(insets.bottom, _config.bottomInsetMin);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
|
|
||||||
width = dm.widthPixels;
|
|
||||||
}
|
|
||||||
_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;
|
_keyWidth = (width - _marginLeft - _marginRight) / _keyboard.keysWidth;
|
||||||
_tc = new Theme.Computed(_theme, _config, _keyWidth, _keyboard);
|
_tc = new Theme.Computed(_theme, _config, _keyWidth, _keyboard);
|
||||||
// Compute the size of labels based on the width or the height of keys. The
|
// Compute the size of labels based on the width or the height of keys. The
|
||||||
@ -328,6 +307,22 @@ public class Keyboard2View extends View
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WindowInsets onApplyWindowInsets(WindowInsets wi)
|
||||||
|
{
|
||||||
|
// LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS is set in [Keyboard2#updateSoftInputWindowLayoutParams] for SDK_INT >= 35.
|
||||||
|
if (VERSION.SDK_INT < 35)
|
||||||
|
return wi;
|
||||||
|
int insets_types =
|
||||||
|
WindowInsets.Type.systemBars()
|
||||||
|
| WindowInsets.Type.displayCutout();
|
||||||
|
Insets insets = wi.getInsets(insets_types);
|
||||||
|
_insets_left = insets.left;
|
||||||
|
_insets_right = insets.right;
|
||||||
|
_insets_bottom = insets.bottom;
|
||||||
|
return WindowInsets.CONSUMED;
|
||||||
|
}
|
||||||
|
|
||||||
/** Horizontal and vertical position of the 9 indexes. */
|
/** Horizontal and vertical position of the 9 indexes. */
|
||||||
static final Paint.Align[] LABEL_POSITION_H = new Paint.Align[]{
|
static final Paint.Align[] LABEL_POSITION_H = new Paint.Align[]{
|
||||||
Paint.Align.CENTER, Paint.Align.LEFT, Paint.Align.RIGHT, Paint.Align.LEFT,
|
Paint.Align.CENTER, Paint.Align.LEFT, Paint.Align.RIGHT, Paint.Align.LEFT,
|
||||||
|
@ -49,14 +49,4 @@ public final class Utils
|
|||||||
out.append(buff, 0, l);
|
out.append(buff, 0, l);
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether the thin gesture-navigation bar is used.
|
|
||||||
https://stackoverflow.com/questions/36514167/how-to-really-get-the-navigation-bar-height-in-android
|
|
||||||
*/
|
|
||||||
public static boolean is_navigation_bar_gestural(Resources res)
|
|
||||||
{
|
|
||||||
// core/java/android/view/WindowManagerPolicyConstants.java
|
|
||||||
int res_id = res.getIdentifier("config_navBarInteractionMode", "integer", "android");
|
|
||||||
return (res_id > 0 && res.getInteger(res_id) == 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user