From 9c82c9cfdcd1e6ac69ebe467932bedfc930cf9bc Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 30 Dec 2021 22:22:25 +0100 Subject: [PATCH] Improve the "precision" option Now named "swiping distance". Changed to a dropdown. --- res/values/arrays.xml | 14 ++++++++++++++ res/values/strings.xml | 9 +++++++-- res/xml/settings.xml | 2 +- srcs/juloo.keyboard2/Config.java | 23 ++++++++--------------- srcs/juloo.keyboard2/Keyboard2View.java | 4 ++-- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index d8c83f1..66d5699 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -32,4 +32,18 @@ light black + + @string/pref_swipe_dist_e_very_short + @string/pref_swipe_dist_e_short + @string/pref_swipe_dist_e_default + @string/pref_swipe_dist_e_far + @string/pref_swipe_dist_e_very_far + + + 5 + 7.5 + 15 + 25 + 35 + diff --git a/res/values/strings.xml b/res/values/strings.xml index ca31dca..59689ea 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -11,8 +11,8 @@ Show every accents Hide accents Typing - Precision - Distance of corner values (%sdp) + Swiping distance + Distance of characters in the corners of the keys (%s) Long press timeout Long press interval Vibration @@ -31,4 +31,9 @@ Dark Light Black + Very short + Short + Normal + Far + Very far diff --git a/res/xml/settings.xml b/res/xml/settings.xml index 94c96d6..c882f00 100644 --- a/res/xml/settings.xml +++ b/res/xml/settings.xml @@ -5,7 +5,7 @@ - + diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 7123043..b2a0d83 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -17,7 +17,8 @@ final class Config // From preferences public int layout; // Or '-1' for the system defaults - public float subValueDist; + private float swipe_dist_dp; + public float swipe_dist_px; public boolean vibrateEnabled; public long vibrateDuration; public long longPressTimeout; @@ -46,7 +47,6 @@ final class Config keyHorizontalInterval = res.getDimension(R.dimen.key_horizontal_interval); // default values layout = -1; - subValueDist = 10f; vibrateEnabled = true; vibrateDuration = 20; longPressTimeout = 600; @@ -73,21 +73,22 @@ final class Config SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); DisplayMetrics dm = context.getResources().getDisplayMetrics(); layout = layoutId_of_string(prefs.getString("layout", "system")); - subValueDist = getDipPrefFloat(dm, prefs, "sub_value_dist", subValueDist); + swipe_dist_dp = Float.valueOf(prefs.getString("swipe_dist", "15")); + swipe_dist_px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, swipe_dist_dp, dm); vibrateEnabled = prefs.getBoolean("vibrate_enabled", vibrateEnabled); vibrateDuration = prefs.getInt("vibrate_duration", (int)vibrateDuration); longPressTimeout = prefs.getInt("longpress_timeout", (int)longPressTimeout); longPressInterval = prefs.getInt("longpress_interval", (int)longPressInterval); - marginBottom = getDipPrefInt(dm, prefs, "margin_bottom", marginBottom); - keyHeight = getDipPrefInt(dm, prefs, "key_height", keyHeight); - horizontalMargin = getDipPrefInt(dm, prefs, "horizontal_margin", horizontalMargin); + marginBottom = getDipPref(dm, prefs, "margin_bottom", marginBottom); + keyHeight = getDipPref(dm, prefs, "key_height", keyHeight); + horizontalMargin = getDipPref(dm, prefs, "horizontal_margin", horizontalMargin); preciseRepeat = prefs.getBoolean("precise_repeat", preciseRepeat); characterSize = prefs.getFloat("character_size", characterSize); accents = Integer.valueOf(prefs.getString("accents", "1")); theme = themeId_of_string(prefs.getString("theme", "")); } - private float getDipPrefInt(DisplayMetrics dm, SharedPreferences prefs, String pref_name, float def) + private float getDipPref(DisplayMetrics dm, SharedPreferences prefs, String pref_name, float def) { int value = prefs.getInt(pref_name, -1); if (value < 0) @@ -95,14 +96,6 @@ final class Config return (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, dm)); } - private float getDipPrefFloat(DisplayMetrics dm, SharedPreferences prefs, String pref_name, float def) - { - float value = prefs.getFloat(pref_name, -1.f); - if (value < 0.f) - return (def); - return (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, dm)); - } - public static int layoutId_of_string(String name) { switch (name) diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 10ec678..603984d 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -145,7 +145,7 @@ public class Keyboard2View extends View moveY -= key.downY; float absDist = Math.abs(moveX) + Math.abs(moveY); key.ptrDist = absDist; - if (absDist < _config.subValueDist) + if (absDist < _config.swipe_dist_px) newValue = key.key.key0; else if (moveX < 0) newValue = (moveY < 0) ? key.key.key1 : key.key.key3; @@ -313,7 +313,7 @@ public class Keyboard2View extends View if (_config.preciseRepeat && (key.flags & KeyValue.FLAG_PRECISE_REPEAT) != 0) { // Modulate repeat interval depending on the distance of the pointer - float accel = Math.min(4.f, Math.max(0.3f, key.ptrDist / (_config.subValueDist * 15.f))); + float accel = Math.min(4.f, Math.max(0.3f, key.ptrDist / (_config.swipe_dist_px * 15.f))); nextInterval = (long)((float)nextInterval / accel); } _handler.sendEmptyMessageDelayed(msg.what, nextInterval);