1
0
Fork 0

it is now possible to hide an entire Fn column

This commit is contained in:
sspanak 2025-05-05 12:42:26 +03:00 committed by Dimo Karaivanov
parent 58f9be779a
commit ea42b41a05
17 changed files with 133 additions and 73 deletions

View file

@ -46,7 +46,7 @@ public class FnKeyOrderValidator {
private boolean validateLength(String text, int side) {
if (text == null || text.length() != 4) {
if (text == null || text.length() > 4) {
error = R.string.fn_key_order_error_wrong_key_count;
errorSide = side;
return false;
@ -57,7 +57,7 @@ public class FnKeyOrderValidator {
private boolean validateDigits(String text, int side) {
if (text == null || !text.matches("^[1-8]+$")) {
if (text == null || !text.matches("^[1-8]*$")) {
error = R.string.fn_key_order_error_unsupported_key_code;
errorSide = side;
return false;

View file

@ -3,6 +3,8 @@ package io.github.sspanak.tt9.preferences.settings;
import android.content.Context;
import android.util.TypedValue;
import androidx.annotation.NonNull;
import java.util.HashMap;
import io.github.sspanak.tt9.R;
@ -35,11 +37,11 @@ public class SettingsVirtualNumpad extends SettingsUI {
return !prefs.getBoolean("pref_arrow_keys_visible", true);
}
public String getLfnKeyOrder() {
@NonNull public String getLfnKeyOrder() {
return prefs.getString("pref_lfn_key_order", DEFAULT_LFN_KEY_ORDER);
}
public String getRfnKeyOrder() {
@NonNull public String getRfnKeyOrder() {
return prefs.getString("pref_rfn_key_order", DEFAULT_RFN_KEY_ORDER);
}

View file

@ -11,6 +11,7 @@ import android.view.WindowInsets;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.view.WindowInsetsCompat;
@ -39,6 +40,24 @@ abstract class BaseMainLayout {
}
protected void addKey(int keyId, @Nullable ViewGroup container) {
View source = container != null ? container : view;
if (source == null) {
return;
}
SoftKey key = source.findViewById(keyId);
if (key != null) {
keys.add(key);
}
}
protected void addKey(int keyId) {
addKey(keyId, null);
}
/**
* getKeys
* Returns a list of all the usable Soft Keys. Useful for attaching click handlers and changing

View file

@ -116,9 +116,8 @@ class MainLayoutNumpad extends BaseMainLayout {
* This prevents Android from auto-closing the keyboard in some apps that have a lot of content.
* Returns the adjusted height of a single key.
*/
private int calculateKeyHeight() {
int keyHeight = tt9.getSettings().getNumpadKeyHeight();
boolean isLandscape = DeviceInfo.isLandscapeOrientation(tt9.getApplicationContext());
private int[] calculateKeyHeight() {
final boolean isLandscape = DeviceInfo.isLandscapeOrientation(tt9.getApplicationContext());
int bottomPadding = 0;
if (DeviceInfo.AT_LEAST_ANDROID_15) {
@ -126,21 +125,42 @@ class MainLayoutNumpad extends BaseMainLayout {
bottomPadding = bottomPadding < 0 ? DeviceInfo.getNavigationBarHeight(tt9.getApplicationContext(), tt9.getSettings(), isLandscape) : bottomPadding;
}
int screenHeight = DeviceInfo.getScreenHeight(tt9.getApplicationContext()) - bottomPadding;
double maxScreenHeight = isLandscape ? screenHeight * 0.6 : screenHeight * 0.75;
int maxKeyHeight = (int) Math.round(maxScreenHeight / 5);
final int screenHeight = DeviceInfo.getScreenHeight(tt9.getApplicationContext()) - bottomPadding;
final double maxScreenHeight = isLandscape ? screenHeight * 0.6 : screenHeight * 0.75;
final int maxKeyHeight = (int) Math.round(maxScreenHeight / 5);
return Math.min(keyHeight, maxKeyHeight);
final int defaultHeight = Math.min(tt9.getSettings().getNumpadKeyHeight(), maxKeyHeight);
// in case some of the Fn keys are hidden, we need to stretch the rest
final int lfnCount = tt9.getSettings().getLfnKeyOrder().length();
final int lfnHeight = lfnCount > 0 ? defaultHeight * 4 / lfnCount : defaultHeight;
final int rfnCount = tt9.getSettings().getRfnKeyOrder().length();
final int rfnHeight = rfnCount > 0 ? defaultHeight * 4 / rfnCount : defaultHeight;
return new int[] {defaultHeight, lfnHeight, rfnHeight};
}
private void setKeyHeight(int height) {
if (view == null || height <= 0) {
private void setKeyHeight(int defaultHeight, int leftHeight, int rightHeight) {
if (view == null || defaultHeight <= 0) {
return;
}
final View leftColumn = view.findViewById(R.id.numpad_column_fn_left);
final View rightColumn = view.findViewById(R.id.numpad_column_fn_right);
for (SoftKey key : getKeys()) {
key.setHeight(height);
final View wrapper = (View) key.getParent();
final View container = wrapper != null ? (View) wrapper.getParent() : null;
if (container != null && container.equals(leftColumn)) {
key.setHeight(leftHeight);
} else if (container != null && container.equals(rightColumn)) {
key.setHeight(rightHeight);
} else {
key.setHeight(defaultHeight);
}
}
}
@ -180,7 +200,7 @@ class MainLayoutNumpad extends BaseMainLayout {
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(calculateKeyHeight())
+ getKeyColumnHeight(calculateKeyHeight()[0])
+ Math.round(resources.getDimension(R.dimen.numpad_keys_spacing_bottom));
}
@ -219,58 +239,53 @@ class MainLayoutNumpad extends BaseMainLayout {
}
// status bar
ViewGroup statusBar = view.findViewById(R.id.status_bar_container);
keys.add(statusBar.findViewById(R.id.soft_key_left_arrow));
keys.add(statusBar.findViewById(R.id.soft_key_right_arrow));
keys.addAll(getKeysFromContainer(view.findViewById(R.id.status_bar_container)));
// left Fn
keys.add(view.findViewById(R.id.soft_key_settings));
keys.add(view.findViewById(R.id.soft_key_add_word));
keys.add(view.findViewById(R.id.soft_key_shift));
keys.add(view.findViewById(R.id.soft_key_lf4));
addKey(R.id.soft_key_settings);
addKey(R.id.soft_key_add_word);
addKey(R.id.soft_key_shift);
addKey(R.id.soft_key_lf4);
// right Fn
keys.add(view.findViewById(R.id.soft_key_numpad_backspace));
keys.add(view.findViewById(R.id.soft_key_filter));
keys.add(view.findViewById(R.id.soft_key_rf3));
keys.add(view.findViewById(R.id.soft_key_numpad_ok));
addKey(R.id.soft_key_numpad_backspace);
addKey(R.id.soft_key_filter);
addKey(R.id.soft_key_rf3);
addKey(R.id.soft_key_numpad_ok);
// digits panel
ViewGroup table = view.findViewById(R.id.main_soft_keys);
keys.add(table.findViewById(R.id.soft_key_0));
keys.add(table.findViewById(R.id.soft_key_1));
keys.add(table.findViewById(R.id.soft_key_2));
keys.add(table.findViewById(R.id.soft_key_3));
keys.add(table.findViewById(R.id.soft_key_4));
keys.add(table.findViewById(R.id.soft_key_5));
keys.add(table.findViewById(R.id.soft_key_6));
keys.add(table.findViewById(R.id.soft_key_7));
keys.add(table.findViewById(R.id.soft_key_8));
keys.add(table.findViewById(R.id.soft_key_9));
keys.add(table.findViewById(R.id.soft_key_punctuation_1));
keys.add(table.findViewById(R.id.soft_key_punctuation_2));
addKey(R.id.soft_key_0, table);
addKey(R.id.soft_key_1, table);
addKey(R.id.soft_key_2, table);
addKey(R.id.soft_key_3, table);
addKey(R.id.soft_key_4, table);
addKey(R.id.soft_key_5, table);
addKey(R.id.soft_key_6, table);
addKey(R.id.soft_key_7, table);
addKey(R.id.soft_key_8, table);
addKey(R.id.soft_key_9, table);
addKey(R.id.soft_key_punctuation_1, table);
addKey(R.id.soft_key_punctuation_2, table);
// text editing panel
keys.add(table.findViewById(R.id.soft_key_100));
keys.add(table.findViewById(R.id.soft_key_101));
keys.add(table.findViewById(R.id.soft_key_102));
keys.add(table.findViewById(R.id.soft_key_103));
keys.add(table.findViewById(R.id.soft_key_104));
keys.add(table.findViewById(R.id.soft_key_105));
keys.add(table.findViewById(R.id.soft_key_106));
keys.add(table.findViewById(R.id.soft_key_107));
keys.add(table.findViewById(R.id.soft_key_108));
keys.add(table.findViewById(R.id.soft_key_109));
keys.add(table.findViewById(R.id.soft_key_punctuation_101));
keys.add(table.findViewById(R.id.soft_key_punctuation_102));
addKey(R.id.soft_key_100, table);
addKey(R.id.soft_key_101, table);
addKey(R.id.soft_key_102, table);
addKey(R.id.soft_key_103, table);
addKey(R.id.soft_key_104, table);
addKey(R.id.soft_key_105, table);
addKey(R.id.soft_key_106, table);
addKey(R.id.soft_key_107, table);
addKey(R.id.soft_key_108, table);
addKey(R.id.soft_key_109, table);
addKey(R.id.soft_key_punctuation_101, table);
addKey(R.id.soft_key_punctuation_102, table);
// Long space panel
keys.add(table.findViewById(R.id.soft_key_200));
keys.add(table.findViewById(R.id.soft_key_punctuation_201));
keys.add(table.findViewById(R.id.soft_key_punctuation_202));
keys.addAll(getKeysFromContainer(view.findViewById(R.id.status_bar_container)));
addKey(R.id.soft_key_200, table);
addKey(R.id.soft_key_punctuation_201, table);
addKey(R.id.soft_key_punctuation_202, table);
return keys;
}
@ -302,6 +317,7 @@ class MainLayoutNumpad extends BaseMainLayout {
keyWrappers.put(entry.getValue(), view.findViewById(entry.getValue()));
}
hideUnusedFnKeys(keyWrappers, lfnOrder, rfnOrder);
reorderFnColumn(left, lfnOrder, keyWrappers);
reorderFnColumn(right, rfnOrder, keyWrappers);
@ -310,7 +326,29 @@ class MainLayoutNumpad extends BaseMainLayout {
}
private void reorderFnColumn(ViewGroup column, String order, Map<Integer, View> keyWrappers) {
private void hideUnusedFnKeys(@NonNull Map<Integer, View> keyWrappers, @NonNull String leftOrder, @NonNull String rightOrder) {
for (Map.Entry<Integer, View> entry : keyWrappers.entrySet()) {
Integer keyId = entry.getKey();
View key = entry.getValue();
if (key != null && leftOrder.indexOf(keyId) < 0 && rightOrder.indexOf(keyId) < 0) {
key.setVisibility(View.GONE);
}
}
View leftColumn = view.findViewById(R.id.numpad_column_fn_left);
if (leftColumn != null) {
leftColumn.setVisibility(leftOrder.isEmpty() ? View.GONE : View.VISIBLE);
}
View rightColumn = view.findViewById(R.id.numpad_column_fn_right);
if (rightColumn != null) {
rightColumn.setVisibility(rightOrder.isEmpty() ? View.GONE : View.VISIBLE);
}
}
private void reorderFnColumn(@NonNull ViewGroup column, @NonNull String order, @NonNull Map<Integer, View> keyWrappers) {
for (char keyId : order.toCharArray()) {
Integer viewId = SettingsVirtualNumpad.KEY_ORDER_MAP.get(keyId);
if (viewId == null) {
@ -325,18 +363,19 @@ class MainLayoutNumpad extends BaseMainLayout {
((ViewGroup) key.getParent()).removeView(key);
column.addView(key);
key.setVisibility(View.VISIBLE);
}
}
@Override
void render() {
int defaultKeyHeight = calculateKeyHeight();
final int[] keyHeights = calculateKeyHeight();
getView();
reorderFnKeys();
enableClickHandlers();
setKeyHeight(defaultKeyHeight);
setKeyHeight(keyHeights[0], keyHeights[1], keyHeights[2]);
preventEdgeToEdge();
setWidth(tt9.getSettings().getWidthPercent(), tt9.getSettings().getAlignment());
setKeyColumnWidth(tt9.getSettings().getNumpadFnKeyScale());
@ -345,7 +384,7 @@ class MainLayoutNumpad extends BaseMainLayout {
boolean hasLettersOnAllKeys = tt9.getLanguage() != null && tt9.getLanguage().hasLettersOnAllKeys();
showLongSpace(
tt9.getSettings().isNumpadShapeLongSpace() && !tt9.isInputModeNumeric() && !hasLettersOnAllKeys,
defaultKeyHeight
keyHeights[0]
);
for (SoftKey key : getKeys()) {

View file

@ -221,7 +221,7 @@
<string name="function_undo">Отмяна (Undo)</string>
<string name="pref_hack_precalculate_navbar_height">Преизчисли долното отстояние</string>
<string name="fn_key_order_column_2">Колона 2</string>
<string name="fn_key_order_error_wrong_key_count">Трябва да има точно по 4 клавиша в колона.</string>
<string name="fn_key_order_error_wrong_key_count">Колоната може да съдържа най-много 4 клавиша.</string>
<string name="fn_key_order_error_unsupported_key_code">Разрешени са само кодове на клавиши от 1 до 8.</string>
<string name="fn_key_order_error_key_on_both_sides">Един клавиш не може да бъде поставен и в двете колони.</string>
<string name="fn_key_order_column_1">Колона 1</string>

View file

@ -223,7 +223,7 @@
<string name="function_undo">Rückgängig machen</string>
<string name="pref_hack_precalculate_navbar_height">Unteren Abstand neu berechnen</string>
<string name="fn_key_order_column_2">Spalte 2</string>
<string name="fn_key_order_error_wrong_key_count">Es müssen genau 4 Tasten pro Spalte sein.</string>
<string name="fn_key_order_error_wrong_key_count">Die Spalte darf höchstens 4 Tasten enthalten.</string>
<string name="fn_key_order_error_unsupported_key_code">Nur Tastencodes 18 sind erlaubt.</string>
<string name="fn_key_order_error_key_on_both_sides">Eine Taste kann nicht in beiden Spalten platziert werden.</string>
<string name="fn_key_order_column_1">Spalte 1</string>

View file

@ -221,7 +221,7 @@
<string name="function_undo">Deshacer</string>
<string name="pref_hack_precalculate_navbar_height">Recalcular el relleno inferior</string>
<string name="fn_key_order_column_2">Columna 2</string>
<string name="fn_key_order_error_wrong_key_count">Debe haber exactamente 4 teclas por columna.</string>
<string name="fn_key_order_error_wrong_key_count">La columna puede contener como máximo 4 teclas.</string>
<string name="fn_key_order_error_unsupported_key_code">Solo se permiten los códigos de tecla del 1 al 8.</string>
<string name="fn_key_order_error_key_on_both_sides">Una tecla no puede colocarse en ambas columnas.</string>
<string name="fn_key_order_column_1">Columna 1</string>

View file

@ -221,7 +221,7 @@
<string name="function_undo">Annuler (Undo)</string>
<string name="pref_hack_precalculate_navbar_height">Recalculer le remplissage inférieur</string>
<string name="fn_key_order_column_2">Colonne 2</string>
<string name="fn_key_order_error_wrong_key_count">Il doit y avoir exactement 4 touches par colonne.</string>
<string name="fn_key_order_error_wrong_key_count">La colonne peut contenir au maximum 4 touches.</string>
<string name="fn_key_order_error_unsupported_key_code">Seuls les codes de touche 1 à 8 sont autorisés.</string>
<string name="fn_key_order_error_key_on_both_sides">Une touche ne peut pas être placée dans les deux colonnes.</string>
<string name="fn_key_order_column_1">Colonne 1</string>

View file

@ -224,7 +224,7 @@
<string name="function_undo">Annulla (Undo)</string>
<string name="pref_hack_precalculate_navbar_height">Ricalcola il margine inferiore</string>
<string name="fn_key_order_column_2">Colonna 2</string>
<string name="fn_key_order_error_wrong_key_count">Devono esserci esattamente 4 tasti per colonna.</string>
<string name="fn_key_order_error_wrong_key_count">La colonna può contenere al massimo 4 tasti.</string>
<string name="fn_key_order_error_unsupported_key_code">Sono consentiti solo i codici dei tasti da 1 a 8.</string>
<string name="fn_key_order_error_key_on_both_sides">Un tasto non può essere inserito in entrambe le colonne.</string>
<string name="fn_key_order_column_1">Colonna 1</string>

View file

@ -228,7 +228,7 @@
<string name="function_undo">ביטול (Undo)</string>
<string name="pref_hack_precalculate_navbar_height">חשב מחדש ריווח תחתון</string>
<string name="fn_key_order_column_2">עמודה 2</string>
<string name="fn_key_order_error_wrong_key_count">חייבים להיות בדיוק 4 מקשים בכל עמודה.</string>
<string name="fn_key_order_error_wrong_key_count">העמודה יכולה להכיל לכל היותר 4 מקשים.</string>
<string name="fn_key_order_error_unsupported_key_code">רק קודי מקשים 18 מותרים.</string>
<string name="fn_key_order_error_key_on_both_sides">לא ניתן למקם מקש אחד בשתי העמודות.</string>
<string name="fn_key_order_column_1">עמודה 1</string>

View file

@ -230,7 +230,7 @@
<string name="function_undo">Atšaukti (Undo)</string>
<string name="pref_hack_precalculate_navbar_height">Perskaičiuoti apatinį paraštę</string>
<string name="fn_key_order_column_2">Stulpelis 2</string>
<string name="fn_key_order_error_wrong_key_count">Kiekvienoje stulpelyje turi būti tiksliai 4 klavišai.</string>
<string name="fn_key_order_error_wrong_key_count">Stulpelyje gali būti daugiausiai 4 klavišai.</string>
<string name="fn_key_order_error_unsupported_key_code">Leidžiami tik klavišų kodai nuo 1 iki 8.</string>
<string name="fn_key_order_error_key_on_both_sides">Vieno klavišo negalima dėti į abu stulpelius.</string>
<string name="fn_key_order_column_1">Stulpelis 1</string>

View file

@ -222,7 +222,7 @@
<string name="function_undo">Ongedaan maken</string>
<string name="pref_hack_precalculate_navbar_height">Onderrand opnieuw berekenen</string>
<string name="fn_key_order_column_2">Kolom 2</string>
<string name="fn_key_order_error_wrong_key_count">Er moeten precies 4 toetsen per kolom zijn.</string>
<string name="fn_key_order_error_wrong_key_count">De kolom mag maximaal 4 toetsen bevatten.</string>
<string name="fn_key_order_error_unsupported_key_code">Alleen toetscodes 18 zijn toegestaan.</string>
<string name="fn_key_order_error_key_on_both_sides">Eén toets kan niet in beide kolommen staan.</string>
<string name="fn_key_order_column_1">Kolom 1</string>

View file

@ -228,7 +228,7 @@
<string name="function_undo">Desfazer</string>
<string name="pref_hack_precalculate_navbar_height">Recalcular o espaçamento inferior</string>
<string name="fn_key_order_column_2">Coluna 2</string>
<string name="fn_key_order_error_wrong_key_count">Deve haver exatamente 4 teclas por coluna.</string>
<string name="fn_key_order_error_wrong_key_count">A coluna pode conter no máximo 4 teclas.</string>
<string name="fn_key_order_error_unsupported_key_code">Apenas os códigos de tecla de 1 a 8 são permitidos.</string>
<string name="fn_key_order_error_key_on_both_sides">Uma tecla não pode estar nas duas colunas.</string>
<string name="fn_key_order_column_1">Coluna 1</string>

View file

@ -221,7 +221,7 @@
<string name="function_undo">Отменить (Undo)</string>
<string name="pref_hack_precalculate_navbar_height">Пересчитать нижний отступ</string>
<string name="fn_key_order_column_2">Столбец 2</string>
<string name="fn_key_order_error_wrong_key_count">В каждой колонке должно быть ровно 4 клавиши.</string>
<string name="fn_key_order_error_wrong_key_count">В столбце может быть не более 4 клавиш.</string>
<string name="fn_key_order_error_unsupported_key_code">Разрешены только коды клавиш от 1 до 8.</string>
<string name="fn_key_order_error_key_on_both_sides">Одна клавиша не может находиться в обеих колонках.</string>
<string name="fn_key_order_column_1">Столбец 1</string>

View file

@ -226,7 +226,7 @@
<string name="function_undo">Geri al (Undo)</string>
<string name="pref_hack_precalculate_navbar_height">Alt boşluğu yeniden hesapla</string>
<string name="fn_key_order_column_2">Sütun 2</string>
<string name="fn_key_order_error_wrong_key_count">Her sütunda tam olarak 4 tuş olmalıdır.</string>
<string name="fn_key_order_error_wrong_key_count">Sütun en fazla 4 tuş içerebilir.</string>
<string name="fn_key_order_error_unsupported_key_code">Yalnızca 18 arası tuş kodlarına izin verilir.</string>
<string name="fn_key_order_error_key_on_both_sides">Bir tuş her iki sütuna da yerleştirilemez.</string>
<string name="fn_key_order_column_1">Sütun 1</string>

View file

@ -232,7 +232,7 @@
<string name="function_undo">Скасувати (Undo)</string>
<string name="pref_hack_precalculate_navbar_height">Перерахувати нижній відступ</string>
<string name="fn_key_order_column_2">Стовпець 2</string>
<string name="fn_key_order_error_wrong_key_count">У кожному стовпці має бути рівно 4 клавіші.</string>
<string name="fn_key_order_error_wrong_key_count">У стовпці може бути щонайбільше 4 клавіші.</string>
<string name="fn_key_order_error_unsupported_key_code">Дозволено лише коди клавіш від 1 до 8.</string>
<string name="fn_key_order_error_key_on_both_sides">Одна клавіша не може бути в обох стовпцях.</string>
<string name="fn_key_order_column_1">Стовпець 1</string>

View file

@ -164,7 +164,7 @@
<string name="fn_key_order_column_1">Column 1</string>
<string name="fn_key_order_column_2">Column 2</string>
<string name="fn_key_order_error_wrong_key_count">There must be exactly 4 keys per column.</string>
<string name="fn_key_order_error_wrong_key_count">The column can contain at most 4 keys.</string>
<string name="fn_key_order_error_unsupported_key_code">Only key codes 18 are allowed.</string>
<string name="fn_key_order_error_key_on_both_sides">One key cannot be placed in both columns.</string>
<string name="fn_key_order_error_duplicate_key">No duplicate keys allowed.</string>