1
0
Fork 0

added a setting for changing the function key width

This commit is contained in:
sspanak 2025-02-02 21:54:07 +02:00 committed by Dimo Karaivanov
parent 110bd8175e
commit 5401f1e40c
22 changed files with 136 additions and 18 deletions

View file

@ -30,6 +30,7 @@ public class AppearanceScreen extends BaseScreenFragment {
ItemWidth keyboardWidth = new ItemWidth(findPreference(ItemWidth.NAME), activity.getSettings());
ItemNumpadShape numpadShape = new ItemNumpadShape(findPreference(ItemNumpadShape.NAME), activity.getSettings());
ItemShowArrows showArrows = new ItemShowArrows(findPreference(ItemShowArrows.NAME), activity.getSettings());
ItemNumpadFnKeyScale fnKeyWidth = new ItemNumpadFnKeyScale(findPreference(ItemNumpadFnKeyScale.NAME), activity.getSettings());
ItemDropDown[] items = {
new ItemSelectTheme(findPreference(ItemSelectTheme.NAME), activity),
@ -42,6 +43,7 @@ public class AppearanceScreen extends BaseScreenFragment {
keyboardWidth.onLayoutChange(layout);
numpadShape.onLayoutChange(layout);
showArrows.onLayoutChange(layout);
fnKeyWidth.onLayoutChange(layout);
}
),
new ItemSelectSettingsFontSize(findPreference(ItemSelectSettingsFontSize.NAME), this),
@ -49,6 +51,7 @@ public class AppearanceScreen extends BaseScreenFragment {
alignment,
keyboardWidth,
numpadShape,
fnKeyWidth
};
for (ItemDropDown item : items) {

View file

@ -0,0 +1,62 @@
package io.github.sspanak.tt9.preferences.screens.appearance;
import androidx.preference.DropDownPreference;
import java.util.LinkedHashMap;
import io.github.sspanak.tt9.preferences.items.ItemDropDown;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class ItemNumpadFnKeyScale extends ItemDropDown {
public static final String NAME = "pref_numpad_fn_key_width";
private final SettingsStore settings;
ItemNumpadFnKeyScale(DropDownPreference item, SettingsStore settings) {
super(item);
this.settings = settings;
}
@Override
public ItemDropDown populate() {
if (item == null) {
return this;
}
LinkedHashMap<String, String> options = new LinkedHashMap<>();
options.put("1", "100 ");
options.put("0.85", "115 ");
options.put("0.675", "135 ");
options.put("0.477", "150 "); // whatever...
super.populate(options);
super.setValue(getClosestOption(settings.getNumpadFnKeyScale(), options));
onLayoutChange(settings.getMainViewLayout());
return this;
}
private String getClosestOption(float value, LinkedHashMap<String, String> options) {
float minDiff = Float.MAX_VALUE;
String closest = null;
for (String key : options.keySet()) {
float fKey = Float.parseFloat(key);
float diff = Math.abs(value - fKey);
if (diff < minDiff) {
minDiff = diff;
closest = key;
}
}
return closest;
}
void onLayoutChange(int mainViewLayout) {
if (item != null) {
item.setVisible(mainViewLayout == SettingsStore.LAYOUT_NUMPAD);
item.setIconSpaceReserved(false);
}
}
}

View file

@ -24,4 +24,12 @@ class BaseSettings {
return defaultValue;
}
}
protected float getStringifiedFloat(String key, float defaultValue) {
try {
return Float.parseFloat(prefs.getString(key, String.valueOf(defaultValue)));
} catch (NumberFormatException ignored) {
return defaultValue;
}
}
}

View file

@ -2,6 +2,7 @@ package io.github.sspanak.tt9.preferences.settings;
import android.content.Context;
import android.content.res.Configuration;
import android.util.TypedValue;
import android.view.Gravity;
import androidx.appcompat.app.AppCompatDelegate;
@ -90,6 +91,21 @@ public class SettingsUI extends SettingsTyping {
return getStringifiedInt("pref_numpad_key_height", getNumpadKeyDefaultHeight());
}
public float getNumpadFnKeyDefaultScale() {
// The simpler getResource.getFloat() requires API 29, so we must get the value manually.
try {
TypedValue outValue = new TypedValue();
context.getResources().getValue(R.dimen.numpad_key_fn_layout_weight, outValue, true);
return outValue.getFloat();
} catch (Exception e) {
return 0.625f;
}
}
public float getNumpadFnKeyScale() {
return getStringifiedFloat("pref_numpad_fn_key_width", getNumpadFnKeyDefaultScale());
}
public int getNumpadShape() {
return getStringifiedInt("pref_numpad_shape", NUMPAD_SHAPE_SQUARE);
}

View file

@ -131,12 +131,34 @@ class MainLayoutNumpad extends BaseMainLayout {
}
private void setKeyColumnWidth(float layoutWeight) {
if (view == null || layoutWeight <= 0) {
return;
}
LinearLayout leftColumn = view.findViewById(R.id.numpad_column_fn_left);
LinearLayout rightColumn = view.findViewById(R.id.numpad_column_fn_right);
LinearLayout.LayoutParams leftParams = leftColumn != null ? (LinearLayout.LayoutParams) leftColumn.getLayoutParams() : null;
LinearLayout.LayoutParams rightParams = rightColumn != null ? (LinearLayout.LayoutParams) rightColumn.getLayoutParams() : null;
if (leftParams == null || rightParams == null) {
return;
}
leftParams.weight = layoutWeight;
rightParams.weight = layoutWeight;
leftColumn.setLayoutParams(leftParams);
rightColumn.setLayoutParams(rightParams);
}
int getHeight(boolean forceRecalculate) {
if (height <= 0 || forceRecalculate) {
Resources resources = tt9.getResources();
height =
+ Math.round(resources.getDimension(R.dimen.numpad_status_bar_spacing_top))
Math.round(resources.getDimension(R.dimen.numpad_status_bar_spacing_top))
+ resources.getDimensionPixelSize(R.dimen.numpad_status_bar_spacing_bottom)
+ resources.getDimensionPixelSize(R.dimen.numpad_suggestion_height)
+ getKeyColumnHeight()
@ -219,6 +241,7 @@ class MainLayoutNumpad extends BaseMainLayout {
enableClickHandlers();
setKeyHeight(calculateKeyHeight());
setWidth(tt9.getSettings().getWidthPercent(), tt9.getSettings().getAlignment());
setKeyColumnWidth(tt9.getSettings().getNumpadFnKeyScale());
for (SoftKey key : getKeys()) {
key.render();
}

View file

@ -2,13 +2,11 @@ package io.github.sspanak.tt9.ui.main.keys;
import android.content.Context;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.util.Logger;
import io.github.sspanak.tt9.util.Timer;
abstract public class BaseSwipeableKey extends BaseSoftKeyWithSideText {
@ -77,18 +75,8 @@ abstract public class BaseSwipeableKey extends BaseSoftKeyWithSideText {
return getSwipeYThreshold();
}
try {
// The simpler getResource.getFloat() requires API 29, so we must get the value manually.
TypedValue outValue = new TypedValue();
getResources().getValue(R.dimen.numpad_key_fn_layout_weight, outValue, true);
float functionKeyScale = outValue.getFloat();
float keyWidth = tt9.getWidth() / 5f * functionKeyScale;
return keyWidth * SettingsStore.SOFT_KEY_AMOUNT_OF_KEY_SIZE_FOR_SWIPE;
} catch (Exception e) {
Logger.e(LOG_TAG, "Error calculating the swipe X threshold. Using default to prevent crashing. " + e);
return getSwipeYThreshold();
}
float keyWidth = tt9.getWidth() / 5f * tt9.getSettings().getNumpadFnKeyDefaultScale();
return keyWidth * SettingsStore.SOFT_KEY_AMOUNT_OF_KEY_SIZE_FOR_SWIPE;
}

View file

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/TTheme.Numpad.Column.Fn">
style="@style/TTheme.Numpad.Column.Fn"
android:id="@+id/numpad_column_fn_left">
<RelativeLayout style="@style/TTheme.Numpad.Key.Overlay.Wrapper">
<io.github.sspanak.tt9.ui.main.keys.SoftKeySettings

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/TTheme.Numpad.Column.Fn">
style="@style/TTheme.Numpad.Column.Fn"
android:id="@+id/numpad_column_fn_right">
<io.github.sspanak.tt9.ui.main.keys.SoftKeyBackspace
style="@style/TTheme.Numpad.Key.Large"

View file

@ -144,6 +144,7 @@
<string name="dictionary_export_generating_csv_for_language">Експортиране на CSV (%1$s)…</string>
<string name="pref_layout">Екранна подредба</string>
<string name="pref_numpad_key_height">Височина</string>
<string name="pref_numpad_fn_key_width">Ширина на клавишите с букви</string>
<string name="pref_font_size">Размер на шрифта в настройките</string>
<string name="pref_font_size_default">По подразбиране</string>
<string name="key_red">Червен бутон</string>

View file

@ -132,6 +132,7 @@
<string name="dictionary_no_notifications">Wörterbuchbenachrichtigungen</string>
<string name="dictionary_no_notifications_summary">Benachrichtigen über Wörterbuchaktualisierungen und den Ladevorgang.</string>
<string name="pref_numpad_key_height">Höhe</string>
<string name="pref_numpad_fn_key_width">Breite der Buchstabentasten</string>
<string name="pref_font_size">Schriftgröße der Einstellungen</string>
<string name="pref_font_size_default">Standard</string>
<string name="function_show_command_palette">Befehlsliste anzeigen</string>

View file

@ -144,6 +144,7 @@
<string name="dictionary_export_generating_csv_for_language">Exportando CSV (%1$s)…</string>
<string name="pref_layout">Distribución del teclado en pantalla</string>
<string name="pref_numpad_key_height">Altura</string>
<string name="pref_numpad_fn_key_width">Anchura de las teclas de letras</string>
<string name="pref_font_size">Tamaño de fuente de configuración</string>
<string name="pref_font_size_default">Predeterminado</string>
<string name="key_red">Botón rojo</string>

View file

@ -142,6 +142,7 @@
<string name="dictionary_export_generating_csv_for_language">Exportation CSV en cours (%1$s)…</string>
<string name="pref_layout">Disposition à l\'écran</string>
<string name="pref_numpad_key_height">Hauteur</string>
<string name="pref_numpad_fn_key_width">Largeur des touches de lettres</string>
<string name="pref_font_size">Taille de la police des paramètres</string>
<string name="pref_font_size_default">Par défaut</string>
<string name="key_red">Bouton rouge</string>

View file

@ -133,6 +133,7 @@
<string name="dictionary_no_notifications">Notifiche del dizionario</string>
<string name="dictionary_no_notifications_summary">Ricevere notifiche sugli aggiornamenti del dizionario e sul progresso del caricamento.</string>
<string name="pref_numpad_key_height">Altezza</string>
<string name="pref_numpad_fn_key_width">Larghezza dei tasti lettera</string>
<string name="pref_font_size">Dimensione del carattere delle impostazioni</string>
<string name="pref_font_size_default">Predefinita</string>
<string name="function_show_command_palette">Mostra elenco comandi</string>

View file

@ -145,6 +145,7 @@
<string name="dictionary_no_notifications">התראות מילון</string>
<string name="dictionary_no_notifications_summary">לקבל התראות על עדכוני המילון ועל התקדמות הטעינה.</string>
<string name="pref_numpad_key_height">גובה</string>
<string name="pref_numpad_fn_key_width">רוחב מקשי האותיות</string>
<string name="pref_font_size">גודל הגופן בהגדרות</string>
<string name="pref_font_size_default">ברירת מחדל</string>
<string name="function_show_command_palette">הצג רשימת פקודות</string>

View file

@ -153,6 +153,7 @@
<string name="donate_summary">Jei jums patinka %1$s, galite pavaišinti mane alumi čia: %2$s.</string>
<string name="pref_layout">Klaviatūros išdėstymas ekrane</string>
<string name="pref_numpad_key_height">Aukštis</string>
<string name="pref_numpad_fn_key_width">Raidžių klavišų plotis</string>
<string name="pref_font_size">Nustatymų šrifto dydis</string>
<string name="pref_font_size_default">Numatytasis</string>
<string name="key_red">Raudonas mygtukas</string>

View file

@ -132,6 +132,7 @@
<string name="dictionary_no_notifications">Woordenboekmeldingen</string>
<string name="dictionary_no_notifications_summary">Ontvang meldingen over woordenboekupdates en de voortgang van het laden.</string>
<string name="pref_numpad_key_height">Hoogte</string>
<string name="pref_numpad_fn_key_width">Breedte van lettertoetsen</string>
<string name="pref_font_size">Instellingen lettergrootte</string>
<string name="pref_font_size_default">Standaard</string>
<string name="function_show_command_palette">Toon opdrachtenlijst</string>

View file

@ -145,6 +145,7 @@
<string name="dictionary_no_notifications">Notificações do dicionário</string>
<string name="dictionary_no_notifications_summary">Receber notificações sobre atualizações do dicionário e sobre o progresso do carregamento.</string>
<string name="pref_numpad_key_height">Altura</string>
<string name="pref_numpad_fn_key_width">Largura das teclas de letras</string>
<string name="pref_font_size">Tamanho da fonte das configurações</string>
<string name="pref_font_size_default">Padrão</string>
<string name="function_show_command_palette">Lista de comandos</string>

View file

@ -144,6 +144,7 @@
<string name="dictionary_export_generating_csv_for_language">Экспорт CSV (%1$s)…</string>
<string name="pref_layout">Экранная раскладка</string>
<string name="pref_numpad_key_height">Высота</string>
<string name="pref_numpad_fn_key_width">Ширина буквенных клавиш</string>
<string name="pref_font_size">Размер шрифта в настройках</string>
<string name="pref_font_size_default">По умолчанию</string>
<string name="key_red">Красная кнопка</string>

View file

@ -131,6 +131,7 @@
<string name="dictionary_no_notifications">Sözlük Bildirimleri</string>
<string name="dictionary_no_notifications_summary">Sözlük güncelleme ve yüklemeleri hakkında bildirimde bulunun.</string>
<string name="pref_numpad_key_height">Yükseklik</string>
<string name="pref_numpad_fn_key_width">Harf tuşlarının genişliği</string>
<string name="pref_font_size">Yazı tipi boyutunu ayarla</string>
<string name="pref_font_size_default">Standart</string>

View file

@ -155,6 +155,7 @@
<string name="dictionary_export_generating_csv_for_language">Експорт CSV (%1$s)…</string>
<string name="pref_layout">Екранна розкладка</string>
<string name="pref_numpad_key_height">Висота</string>
<string name="pref_numpad_fn_key_width">Ширина літерних клавіш</string>
<string name="pref_font_size">Розмір шрифту у налаштуваннях</string>
<string name="pref_font_size_default">За замовчуванням</string>
<string name="key_red">Червона кнопка</string>

View file

@ -68,6 +68,7 @@
<string name="pref_dark_theme_no">No</string>
<string name="pref_dark_theme_auto">Auto</string>
<string name="pref_double_zero_char">Character for Double 0-key Press</string>
<string name="pref_numpad_fn_key_width">Letter Keys Width</string>
<string name="pref_font_size">Settings Font Size</string>
<string name="pref_font_size_default">Default</string>
<string name="pref_font_size_large">Large</string>

View file

@ -35,6 +35,10 @@
app:key="pref_arrow_keys_visible"
app:title="@string/pref_arrow_keys_visible"
app:summary="@string/pref_arrow_keys_visible_summary" />
<DropDownPreference
app:key="pref_numpad_fn_key_width"
app:title="@string/pref_numpad_fn_key_width" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/pref_category_hacks">