diff options
| author | Jules Aguillon | 2023-01-15 19:11:08 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2023-01-15 19:11:08 +0100 |
| commit | a1999621178ad9fd1de713a9b9f485f110e4d899 (patch) | |
| tree | cbfb026aad88a8d939f5c2d4a88b7a51b0ce61fd /srcs | |
| parent | 8a3c0566e7fc80ae3dcaad655222f890486a7255 (diff) | |
| download | unexpected-keyboard-a1999621178ad9fd1de713a9b9f485f110e4d899.tar.gz unexpected-keyboard-a1999621178ad9fd1de713a9b9f485f110e4d899.zip | |
Separate option for horizontal margin in landscape mode
A separate option is needed, the +25dp offset wasn't enough.
Diffstat (limited to 'srcs')
| -rw-r--r-- | srcs/juloo.keyboard2/Config.java | 32 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/Keyboard2View.java | 10 |
2 files changed, 25 insertions, 17 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 6f5ca74..24a396d 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -34,7 +34,7 @@ final class Config public long longPressInterval; public float marginBottom; public float keyHeight; - public float horizontalMargin; + public float horizontal_margin; public float keyVerticalInterval; public float keyHorizontalInterval; public int labelBrightness; // 0 - 255 @@ -58,6 +58,7 @@ final class Config public Set<KeyValue> extra_keys_param; public final IKeyEventHandler handler; + public boolean orientation_landscape = false; private Config(SharedPreferences prefs, Resources res, IKeyEventHandler h) { @@ -85,6 +86,7 @@ final class Config public void refresh(Resources res) { DisplayMetrics dm = res.getDisplayMetrics(); + orientation_landscape = res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; // The height of the keyboard is relative to the height of the screen. // This is the height of the keyboard if it have 4 rows. int keyboardHeightPercent; @@ -93,7 +95,7 @@ final class Config float characterSizeScale = 1.f; String show_numpad_s = _prefs.getString("show_numpad", "never"); show_numpad = "always".equals(show_numpad_s); - if (res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) // Landscape mode + if (orientation_landscape) { if ("landscape".equals(show_numpad_s)) show_numpad = true; @@ -120,12 +122,12 @@ final class Config vibrateEnabled = _prefs.getBoolean("vibrate_enabled", true); longPressTimeout = _prefs.getInt("longpress_timeout", 600); longPressInterval = _prefs.getInt("longpress_interval", 65); - marginBottom = getDipPref(dm, _prefs, "margin_bottom", + marginBottom = get_dip_pref(dm, "margin_bottom", res.getDimension(R.dimen.margin_bottom)); - keyVerticalInterval = getDipPref(dm, _prefs, "key_vertical_space", + keyVerticalInterval = get_dip_pref(dm, "key_vertical_space", res.getDimension(R.dimen.key_vertical_interval)); keyHorizontalInterval = - getDipPref(dm, _prefs, "key_horizontal_space", + get_dip_pref(dm, "key_horizontal_space", res.getDimension(R.dimen.key_horizontal_interval)) * horizontalIntervalScale; // Label brightness is used as the alpha channel @@ -137,10 +139,9 @@ final class Config // Do not substract keyVerticalInterval from keyHeight because this is done // during rendered. keyHeight = dm.heightPixels * keyboardHeightPercent / 100 / 4; - horizontalMargin = - getDipPref(dm, _prefs, "horizontal_margin", - res.getDimension(R.dimen.horizontal_margin)) - + res.getDimension(R.dimen.extra_horizontal_margin); + horizontal_margin = + get_dip_pref(dm, oriented_pref("horizontal_margin"), + res.getDimension(R.dimen.horizontal_margin)); preciseRepeat = _prefs.getBoolean("precise_repeat", true); double_tap_lock_shift = _prefs.getBoolean("lock_double_tap", false); characterSize = @@ -236,16 +237,23 @@ final class Config return kw; } - private float getDipPref(DisplayMetrics dm, SharedPreferences prefs, String pref_name, float def) + private float get_dip_pref(DisplayMetrics dm, String pref_name, float def) { float value; - try { value = prefs.getInt(pref_name, -1); } - catch (Exception e) { value = prefs.getFloat(pref_name, -1f); } + try { value = _prefs.getInt(pref_name, -1); } + catch (Exception e) { value = _prefs.getFloat(pref_name, -1f); } if (value < 0f) return (def); return (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, dm)); } + /** Returns preference name from a prefix depending on orientation. */ + private String oriented_pref(String base_name) + { + String suffix = orientation_landscape ? "_landscape" : "_portrait"; + return base_name + suffix; + } + private int getThemeId(Resources res, String theme_name) { switch (theme_name) diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index c3271b9..835d595 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -195,7 +195,7 @@ public class Keyboard2View extends View private KeyboardData.Key getKeyAtPosition(float tx, float ty) { KeyboardData.Row row = getRowAtPosition(ty); - float x = _config.horizontalMargin; + float x = _config.horizontal_margin; if (row == null || tx < x) return null; for (KeyboardData.Key key : row.keys) @@ -232,7 +232,7 @@ public class Keyboard2View extends View + _keyboard.rows.size() + _config.marginTop + _config.marginBottom); setMeasuredDimension(width, height); - _keyWidth = (width - (_config.horizontalMargin * 2)) / _keyboard.keysWidth; + _keyWidth = (width - (_config.horizontal_margin * 2)) / _keyboard.keysWidth; } @Override @@ -244,9 +244,9 @@ public class Keyboard2View extends View { // Disable the back-gesture on the keyboard area Rect keyboard_area = new Rect( - left + (int)_config.horizontalMargin, + left + (int)_config.horizontal_margin, top + (int)_config.marginTop, - right - (int)_config.horizontalMargin, + right - (int)_config.horizontal_margin, bottom - (int)_config.marginBottom); setSystemGestureExclusionRects(Arrays.asList(keyboard_area)); } @@ -266,7 +266,7 @@ public class Keyboard2View extends View for (KeyboardData.Row row : _keyboard.rows) { y += row.shift * _config.keyHeight; - float x = _config.horizontalMargin + _config.keyHorizontalInterval / 2; + float x = _config.horizontal_margin + _config.keyHorizontalInterval / 2; float keyH = row.height * _config.keyHeight - _config.keyVerticalInterval; for (KeyboardData.Key k : row.keys) { |
