1
0
Fork 0

removed some unused code and modernized the switch() expressions

This commit is contained in:
sspanak 2024-10-18 20:56:34 +03:00 committed by Dimo Karaivanov
parent 80d50fb546
commit 60aba7084d
19 changed files with 144 additions and 246 deletions

View file

@ -22,45 +22,35 @@ public class AddWordResult {
} }
public String toHumanFriendlyString(Context context) { public String toHumanFriendlyString(Context context) {
switch (statusCode) { return switch (statusCode) {
case CODE_SUCCESS: case CODE_SUCCESS
return context.getString(R.string.add_word_success, word); -> context.getString(R.string.add_word_success, word);
case CODE_WORD_EXISTS: case CODE_WORD_EXISTS
return context.getResources().getString(R.string.add_word_exist, word); -> context.getResources().getString(R.string.add_word_exist, word);
case CODE_BLANK_WORD: case CODE_BLANK_WORD
return context.getString(R.string.add_word_blank); -> context.getString(R.string.add_word_blank);
case CODE_INVALID_LANGUAGE: case CODE_INVALID_LANGUAGE
return context.getResources().getString(R.string.add_word_invalid_language); -> context.getResources().getString(R.string.add_word_invalid_language);
default: default
return context.getString(R.string.error_unexpected); -> context.getString(R.string.error_unexpected);
}
};
} }
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {
switch (statusCode) { return switch (statusCode) {
case CODE_SUCCESS: case CODE_SUCCESS -> "Success";
return "Success"; case CODE_BLANK_WORD -> "Blank word";
case CODE_INVALID_LANGUAGE -> "Invalid language";
case CODE_BLANK_WORD: case CODE_WORD_EXISTS -> "Word '" + word + "' exists";
return "Blank word"; case CODE_GENERAL_ERROR -> "General error";
default -> "Unknown error";
case CODE_INVALID_LANGUAGE: };
return "Invalid language";
case CODE_WORD_EXISTS:
return "Word '" + word + "' exists";
case CODE_GENERAL_ERROR:
return "General error";
default:
return "Unknown error";
}
} }
} }

View file

@ -145,20 +145,11 @@ public class ReadOps {
public String getSimilarWordPositions(@NonNull SQLiteDatabase db, @NonNull Language language, @NonNull String sequence, String wordFilter, int minPositions) { public String getSimilarWordPositions(@NonNull SQLiteDatabase db, @NonNull Language language, @NonNull String sequence, String wordFilter, int minPositions) {
int generations; int generations = switch (sequence.length()) {
case 2 -> wordFilter.isEmpty() ? 1 : 10;
switch (sequence.length()) { case 3, 4 -> wordFilter.isEmpty() ? 2 : 10;
case 2: default -> 10;
generations = wordFilter.isEmpty() ? 1 : 10; };
break;
case 3:
case 4:
generations = wordFilter.isEmpty() ? 2 : 10;
break;
default:
generations = 10;
break;
}
return getWordPositions(db, language, sequence, generations, minPositions, wordFilter); return getWordPositions(db, language, sequence, generations, minPositions, wordFilter);
} }

View file

@ -108,7 +108,7 @@ public class DictionaryLoader {
public static void load(Context context, Language language) { public static void load(Context context, Language language) {
DictionaryLoadingBar progressBar = DictionaryLoadingBar.getInstance(context); DictionaryLoadingBar progressBar = DictionaryLoadingBar.getInstance(context);
getInstance(context).setOnStatusChange(status -> progressBar.show(context, status)); getInstance(context).setOnStatusChange(status -> progressBar.show(context, status));
self.load(context, new ArrayList<Language>() {{ add(language); }}); self.load(context, new ArrayList<>() {{ add(language); }});
} }

View file

@ -1,7 +1,6 @@
package io.github.sspanak.tt9.hacks; package io.github.sspanak.tt9.hacks;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.inputmethod.InputConnection;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -10,20 +9,15 @@ import io.github.sspanak.tt9.ime.helpers.SuggestionOps;
import io.github.sspanak.tt9.ime.helpers.TextField; import io.github.sspanak.tt9.ime.helpers.TextField;
import io.github.sspanak.tt9.ime.helpers.TextSelection; import io.github.sspanak.tt9.ime.helpers.TextSelection;
import io.github.sspanak.tt9.ime.modes.InputMode; import io.github.sspanak.tt9.ime.modes.InputMode;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class AppHacks { public class AppHacks {
private final InputConnection inputConnection;
private final InputType inputType; private final InputType inputType;
private final SettingsStore settings;
private final TextField textField; private final TextField textField;
private final TextSelection textSelection; private final TextSelection textSelection;
public AppHacks(SettingsStore settings, InputConnection inputConnection, InputType inputType, TextField textField, TextSelection textSelection) { public AppHacks(InputType inputType, TextField textField, TextSelection textSelection) {
this.inputConnection = inputConnection;
this.inputType = inputType; this.inputType = inputType;
this.settings = settings;
this.textField = textField; this.textField = textField;
this.textSelection = textSelection; this.textSelection = textSelection;
} }

View file

@ -26,7 +26,7 @@ import io.github.sspanak.tt9.util.Text;
public abstract class TypingHandler extends KeyPadHandler { public abstract class TypingHandler extends KeyPadHandler {
// internal settings/data // internal settings/data
@NonNull protected AppHacks appHacks = new AppHacks(null,null, null, null, null); @NonNull protected AppHacks appHacks = new AppHacks(null, null, null);
@NonNull protected InputType inputType = new InputType(null, null); @NonNull protected InputType inputType = new InputType(null, null);
@NonNull protected TextField textField = new TextField(null, null); @NonNull protected TextField textField = new TextField(null, null);
@NonNull protected TextSelection textSelection = new TextSelection(this,null); @NonNull protected TextSelection textSelection = new TextSelection(this,null);
@ -87,7 +87,7 @@ public abstract class TypingHandler extends KeyPadHandler {
textSelection = new TextSelection(this, connection); textSelection = new TextSelection(this, connection);
// changing the TextField and notifying all interested classes is an atomic operation // changing the TextField and notifying all interested classes is an atomic operation
appHacks = new AppHacks(settings, connection, inputType, textField, textSelection); appHacks = new AppHacks(inputType, textField, textSelection);
suggestionOps.setTextField(textField); suggestionOps.setTextField(textField);
} }

View file

@ -54,18 +54,17 @@ public class InputField {
// See the example below: // See the example below:
// https://github.com/openboard-team/openboard/blob/c3772cd56e770975ea5570db903f93b199de8b32/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java#L756 // https://github.com/openboard-team/openboard/blob/c3772cd56e770975ea5570db903f93b199de8b32/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java#L756
int standardAction = field.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION); int standardAction = field.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
switch (standardAction) { return switch (standardAction) {
case EditorInfo.IME_ACTION_DONE: case EditorInfo.IME_ACTION_DONE,
case EditorInfo.IME_ACTION_GO: EditorInfo.IME_ACTION_GO,
case EditorInfo.IME_ACTION_NEXT: EditorInfo.IME_ACTION_NEXT,
case EditorInfo.IME_ACTION_PREVIOUS: EditorInfo.IME_ACTION_PREVIOUS,
case EditorInfo.IME_ACTION_SEARCH: EditorInfo.IME_ACTION_SEARCH,
case EditorInfo.IME_ACTION_SEND: EditorInfo.IME_ACTION_SEND,
case EditorInfo.IME_ACTION_UNSPECIFIED: EditorInfo.IME_ACTION_UNSPECIFIED
return standardAction; -> standardAction;
default: default -> IME_ACTION_ENTER;
return IME_ACTION_ENTER; };
}
} }

View file

@ -85,40 +85,19 @@ public class Key {
public static int codeToNumber(SettingsStore settings, int keyCode) { public static int codeToNumber(SettingsStore settings, int keyCode) {
switch (keyCode) { return switch (keyCode) {
case KeyEvent.KEYCODE_0: case KeyEvent.KEYCODE_0, KeyEvent.KEYCODE_NUMPAD_0 -> 0;
case KeyEvent.KEYCODE_NUMPAD_0: case KeyEvent.KEYCODE_1, KeyEvent.KEYCODE_NUMPAD_1 -> settings.getUpsideDownKeys() ? 7 : 1;
return 0; case KeyEvent.KEYCODE_2, KeyEvent.KEYCODE_NUMPAD_2 -> settings.getUpsideDownKeys() ? 8 : 2;
case KeyEvent.KEYCODE_1: case KeyEvent.KEYCODE_3, KeyEvent.KEYCODE_NUMPAD_3 -> settings.getUpsideDownKeys() ? 9 : 3;
case KeyEvent.KEYCODE_NUMPAD_1: case KeyEvent.KEYCODE_4, KeyEvent.KEYCODE_NUMPAD_4 -> 4;
return settings.getUpsideDownKeys() ? 7 : 1; case KeyEvent.KEYCODE_5, KeyEvent.KEYCODE_NUMPAD_5 -> 5;
case KeyEvent.KEYCODE_2: case KeyEvent.KEYCODE_6, KeyEvent.KEYCODE_NUMPAD_6 -> 6;
case KeyEvent.KEYCODE_NUMPAD_2: case KeyEvent.KEYCODE_7, KeyEvent.KEYCODE_NUMPAD_7 -> settings.getUpsideDownKeys() ? 1 : 7;
return settings.getUpsideDownKeys() ? 8 : 2; case KeyEvent.KEYCODE_8, KeyEvent.KEYCODE_NUMPAD_8 -> settings.getUpsideDownKeys() ? 2 : 8;
case KeyEvent.KEYCODE_3: case KeyEvent.KEYCODE_9, KeyEvent.KEYCODE_NUMPAD_9 -> settings.getUpsideDownKeys() ? 3 : 9;
case KeyEvent.KEYCODE_NUMPAD_3: default -> -1;
return settings.getUpsideDownKeys() ? 9 : 3; };
case KeyEvent.KEYCODE_4:
case KeyEvent.KEYCODE_NUMPAD_4:
return 4;
case KeyEvent.KEYCODE_5:
case KeyEvent.KEYCODE_NUMPAD_5:
return 5;
case KeyEvent.KEYCODE_6:
case KeyEvent.KEYCODE_NUMPAD_6:
return 6;
case KeyEvent.KEYCODE_7:
case KeyEvent.KEYCODE_NUMPAD_7:
return settings.getUpsideDownKeys() ? 1 : 7;
case KeyEvent.KEYCODE_8:
case KeyEvent.KEYCODE_NUMPAD_8:
return settings.getUpsideDownKeys() ? 2 : 8;
case KeyEvent.KEYCODE_9:
case KeyEvent.KEYCODE_NUMPAD_9:
return settings.getUpsideDownKeys() ? 3 : 9;
default:
return -1;
}
} }
public static int numberToCode(int number) { public static int numberToCode(int number) {

View file

@ -199,13 +199,11 @@ abstract public class StandardInputType {
return InputMode.CASE_CAPITALIZE; return InputMode.CASE_CAPITALIZE;
} }
switch (field.inputType & InputType.TYPE_MASK_FLAGS) { return switch (field.inputType & InputType.TYPE_MASK_FLAGS) {
case InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS: case InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS -> InputMode.CASE_UPPER;
return InputMode.CASE_UPPER; case InputType.TYPE_TEXT_FLAG_CAP_WORDS -> InputMode.CASE_CAPITALIZE;
case InputType.TYPE_TEXT_FLAG_CAP_WORDS: default -> InputMode.CASE_UNDEFINED;
return InputMode.CASE_CAPITALIZE; };
}
return InputMode.CASE_UNDEFINED;
} }
} }

View file

@ -36,11 +36,6 @@ public class TextField extends InputField {
} }
public boolean isEmpty() {
return getStringBeforeCursor(1).isEmpty() && getStringAfterCursor(1).isEmpty();
}
public String getStringAfterCursor(int numberOfChars) { public String getStringAfterCursor(int numberOfChars) {
CharSequence character = connection != null ? connection.getTextAfterCursor(numberOfChars, 0) : null; CharSequence character = connection != null ? connection.getTextAfterCursor(numberOfChars, 0) : null;
return character != null ? character.toString() : ""; return character != null ? character.toString() : "";

View file

@ -22,16 +22,13 @@ public class AutoTextCase {
* or Dutch words such as: "'s-Hertogenbosch". * or Dutch words such as: "'s-Hertogenbosch".
*/ */
public String adjustSuggestionTextCase(Text word, int newTextCase) { public String adjustSuggestionTextCase(Text word, int newTextCase) {
switch (newTextCase) { return switch (newTextCase) {
case InputMode.CASE_UPPER: case InputMode.CASE_UPPER -> word.toUpperCase();
return word.toUpperCase(); case InputMode.CASE_LOWER -> word.toLowerCase();
case InputMode.CASE_LOWER: case InputMode.CASE_CAPITALIZE ->
return word.toLowerCase(); word.isMixedCase() || word.isUpperCase() ? word.toString() : word.capitalize();
case InputMode.CASE_CAPITALIZE: default -> word.toString();
return word.isMixedCase() || word.isUpperCase() ? word.toString() : word.capitalize(); };
default:
return word.toString();
}
} }

View file

@ -49,23 +49,22 @@ public class VoiceInputError {
@NonNull @NonNull
private static String codeToString(Context context, int code) { private static String codeToString(Context context, int code) {
switch (code) { return switch (code) {
case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS: case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS
return context.getString(R.string.voice_input_error_no_permissions); -> context.getString(R.string.voice_input_error_no_permissions);
case SpeechRecognizer.ERROR_LANGUAGE_NOT_SUPPORTED: case SpeechRecognizer.ERROR_LANGUAGE_NOT_SUPPORTED
return context.getString(R.string.voice_input_error_language_not_supported); -> context.getString(R.string.voice_input_error_language_not_supported);
case SpeechRecognizer.ERROR_NETWORK: case SpeechRecognizer.ERROR_NETWORK
return context.getString(R.string.voice_input_error_no_network); -> context.getString(R.string.voice_input_error_no_network);
case ERROR_NOT_AVAILABLE: case ERROR_NOT_AVAILABLE
return context.getString(R.string.voice_input_error_not_available); -> context.getString(R.string.voice_input_error_not_available);
case SpeechRecognizer.ERROR_NETWORK_TIMEOUT: case SpeechRecognizer.ERROR_NETWORK_TIMEOUT,
case SpeechRecognizer.ERROR_SERVER: SpeechRecognizer.ERROR_SERVER,
case SpeechRecognizer.ERROR_SERVER_DISCONNECTED: SpeechRecognizer.ERROR_SERVER_DISCONNECTED,
case SpeechRecognizer.ERROR_TOO_MANY_REQUESTS: SpeechRecognizer.ERROR_TOO_MANY_REQUESTS
return context.getString(R.string.voice_input_error_network_failed); -> context.getString(R.string.voice_input_error_network_failed);
default: default -> context.getString(R.string.voice_input_error_generic);
return context.getString(R.string.voice_input_error_generic); };
}
} }
@ -105,31 +104,19 @@ public class VoiceInputError {
private static String codeToDebugStringCommon(int code) { private static String codeToDebugStringCommon(int code) {
switch (code) { return switch (code) {
case SpeechRecognizer.ERROR_AUDIO: case SpeechRecognizer.ERROR_AUDIO -> "Audio capture error.";
return "Audio capture error."; case SpeechRecognizer.ERROR_CLIENT -> "Speech recognition client error.";
case SpeechRecognizer.ERROR_CLIENT: case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS -> "No microphone permissions.";
return "Speech recognition client error."; case SpeechRecognizer.ERROR_NETWORK -> "No network connection.";
case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS: case SpeechRecognizer.ERROR_NETWORK_TIMEOUT -> "Network timeout.";
return "No microphone permissions."; case SpeechRecognizer.ERROR_NO_MATCH -> "No match.";
case SpeechRecognizer.ERROR_NETWORK: case SpeechRecognizer.ERROR_RECOGNIZER_BUSY -> "Voice input service is busy.";
return "No network connection."; case SpeechRecognizer.ERROR_SERVER -> "Speech recognition server error.";
case SpeechRecognizer.ERROR_NETWORK_TIMEOUT: case SpeechRecognizer.ERROR_SPEECH_TIMEOUT -> "No speech detected.";
return "Network timeout."; case ERROR_NOT_AVAILABLE -> "Voice input is not available.";
case SpeechRecognizer.ERROR_NO_MATCH: case ERROR_INVALID_LANGUAGE -> "Invalid language for voice input.";
return "No match."; default -> null;
case SpeechRecognizer.ERROR_RECOGNIZER_BUSY: };
return "Voice input service is busy.";
case SpeechRecognizer.ERROR_SERVER:
return "Speech recognition server error.";
case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
return "No speech detected.";
case ERROR_NOT_AVAILABLE:
return "Voice input is not available.";
case ERROR_INVALID_LANGUAGE:
return "Invalid language for voice input.";
default:
return null;
}
} }
} }

View file

@ -149,34 +149,21 @@ public class PreferencesActivity extends ActivityWithNavigation implements Prefe
return new MainSettingsScreen(this); return new MainSettingsScreen(this);
} }
switch (name) { return switch (name) {
case AppearanceScreen.NAME: case AppearanceScreen.NAME -> new AppearanceScreen(this);
return new AppearanceScreen(this); case DebugScreen.NAME -> new DebugScreen(this);
case DebugScreen.NAME: case DeleteWordsScreen.NAME -> new DeleteWordsScreen(this);
return new DebugScreen(this); case HotkeysScreen.NAME -> new HotkeysScreen(this);
case DeleteWordsScreen.NAME: case KeyPadScreen.NAME -> new KeyPadScreen(this);
return new DeleteWordsScreen(this); case LanguagesScreen.NAME -> new LanguagesScreen(this);
case HotkeysScreen.NAME: case LanguageSelectionScreen.NAME -> new LanguageSelectionScreen(this);
return new HotkeysScreen(this); case ModePredictiveScreen.NAME -> new ModePredictiveScreen(this);
case KeyPadScreen.NAME: case ModeAbcScreen.NAME -> new ModeAbcScreen(this);
return new KeyPadScreen(this); case PunctuationScreen.NAME -> new PunctuationScreen(this);
case LanguagesScreen.NAME: case SetupScreen.NAME -> new SetupScreen(this);
return new LanguagesScreen(this); case UsageStatsScreen.NAME -> new UsageStatsScreen(this);
case LanguageSelectionScreen.NAME: default -> new MainSettingsScreen(this);
return new LanguageSelectionScreen(this); };
case ModePredictiveScreen.NAME:
return new ModePredictiveScreen(this);
case ModeAbcScreen.NAME:
return new ModeAbcScreen(this);
case PunctuationScreen.NAME:
return new PunctuationScreen(this);
case SetupScreen.NAME:
return new SetupScreen(this);
case UsageStatsScreen.NAME:
return new UsageStatsScreen(this);
default:
return new MainSettingsScreen(this);
}
} }

View file

@ -131,14 +131,11 @@ abstract class AbstractPreferenceCharList extends ItemTextInput {
private String getCharName(char c) { private String getCharName(char c) {
switch (c) { return switch (c) {
case '\n': case '\n' -> getContext().getString(R.string.char_newline);
return getContext().getString(R.string.char_newline); case ' ' -> getContext().getString(R.string.char_space);
case ' ': default -> String.valueOf(c);
return getContext().getString(R.string.char_space); };
default:
return String.valueOf(c);
}
} }

View file

@ -31,15 +31,14 @@ public class PopupDialogActivity extends AppCompatActivity {
String popupType = i != null ? i.getStringExtra(PopupDialog.PARAMETER_DIALOG_TYPE) : ""; String popupType = i != null ? i.getStringExtra(PopupDialog.PARAMETER_DIALOG_TYPE) : "";
popupType = popupType != null ? popupType : ""; popupType = popupType != null ? popupType : "";
switch (popupType) { return switch (popupType) {
case AddWordDialog.TYPE: case AddWordDialog.TYPE -> new AddWordDialog(this, i, this::onDialogClose);
return new AddWordDialog(this, i, this::onDialogClose); case AutoUpdateMonologue.TYPE -> new AutoUpdateMonologue(this, i, this::onDialogClose);
case AutoUpdateMonologue.TYPE: default -> {
return new AutoUpdateMonologue(this, i, this::onDialogClose);
default:
Logger.w(LOG_TAG, "Unknown popup type: '" + popupType + "'. Not displaying anything."); Logger.w(LOG_TAG, "Unknown popup type: '" + popupType + "'. Not displaying anything.");
return null; yield null;
} }
};
} }
private void onDialogClose(String message) { private void onDialogClose(String message) {

View file

@ -29,14 +29,15 @@ abstract class BaseMainLayout {
/** setDarkTheme /** setDarkTheme
* Changes the main view colors according to the theme. * <p>Changes the main view colors according to the theme.</p>
* *
* We need to do this manually, instead of relying on the Context to resolve the appropriate colors, * <p>We need to do this manually, instead of relying on the Context to resolve the appropriate colors,
* because this View is part of the main service View. And service Views are always locked to the * because this View is part of the main service View. And service Views are always locked to the
* system context and theme. * system context and theme.</p>
* *
* More info: * <p>More info:
* <a href="https://stackoverflow.com/questions/72382886/system-applies-night-mode-to-views-added-in-service-type-application-overlay">...</a> * <a href="https://stackoverflow.com/questions/72382886/system-applies-night-mode-to-views-added-in-service-type-application-overlay">...</a>
* </p>
*/ */
void setDarkTheme(boolean dark) {} void setDarkTheme(boolean dark) {}
@ -105,11 +106,6 @@ abstract class BaseMainLayout {
} }
int getHeight() {
return getHeight(false);
}
abstract void showCommandPalette(); abstract void showCommandPalette();
abstract void hideCommandPalette(); abstract void hideCommandPalette();
abstract boolean isCommandPaletteShown(); abstract boolean isCommandPaletteShown();

View file

@ -46,15 +46,13 @@ class MainLayoutTray extends BaseMainLayout {
view.findViewById(R.id.main_soft_keys).setVisibility(LinearLayout.GONE); view.findViewById(R.id.main_soft_keys).setVisibility(LinearLayout.GONE);
view.findViewById(R.id.main_command_keys).setVisibility(LinearLayout.VISIBLE); view.findViewById(R.id.main_command_keys).setVisibility(LinearLayout.VISIBLE);
height = 0; getHeight(true);
getHeight();
} }
void hideCommandPalette() { void hideCommandPalette() {
view.findViewById(R.id.main_command_keys).setVisibility(LinearLayout.GONE); view.findViewById(R.id.main_command_keys).setVisibility(LinearLayout.GONE);
height = 0; getHeight(true);
getHeight();
} }
boolean isCommandPaletteShown() { boolean isCommandPaletteShown() {
@ -67,16 +65,14 @@ class MainLayoutTray extends BaseMainLayout {
view.findViewById(R.id.main_soft_keys).setVisibility(LinearLayout.GONE); view.findViewById(R.id.main_soft_keys).setVisibility(LinearLayout.GONE);
view.findViewById(R.id.text_editing_container).setVisibility(LinearLayout.VISIBLE); view.findViewById(R.id.text_editing_container).setVisibility(LinearLayout.VISIBLE);
height = 0; getHeight(true);
getHeight();
} }
@Override @Override
void hideTextEditingPalette() { void hideTextEditingPalette() {
view.findViewById(R.id.text_editing_container).setVisibility(LinearLayout.GONE); view.findViewById(R.id.text_editing_container).setVisibility(LinearLayout.GONE);
height = 0; getHeight(true);
getHeight();
} }
@Override @Override

View file

@ -22,7 +22,7 @@ import io.github.sspanak.tt9.util.Logger;
import io.github.sspanak.tt9.util.TextTools; import io.github.sspanak.tt9.util.TextTools;
public class SoftKeyNumber extends SoftKey { public class SoftKeyNumber extends SoftKey {
private final static SparseArray<Integer> NUMBERS = new SparseArray<Integer>() {{ private final static SparseArray<Integer> NUMBERS = new SparseArray<>() {{
put(R.id.soft_key_0, 0); put(R.id.soft_key_0, 0);
put(R.id.soft_key_1, 1); put(R.id.soft_key_1, 1);
put(R.id.soft_key_2, 2); put(R.id.soft_key_2, 2);
@ -35,7 +35,7 @@ public class SoftKeyNumber extends SoftKey {
put(R.id.soft_key_9, 9); put(R.id.soft_key_9, 9);
}}; }};
private final static SparseArray<Integer> UPSIDE_DOWN_NUMBERS = new SparseArray<Integer>() {{ private final static SparseArray<Integer> UPSIDE_DOWN_NUMBERS = new SparseArray<>() {{
put(1, 7); put(1, 7);
put(2, 8); put(2, 8);
put(3, 9); put(3, 9);
@ -146,14 +146,11 @@ public class SoftKeyNumber extends SoftKey {
int number = getNumber(getId()); int number = getNumber(getId());
switch (number) { return switch (number) {
case 0: case 0 -> getSpecialCharList(tt9);
return getSpecialCharList(tt9); case 1 -> tt9.isNumericModeStrict() ? null : PUNCTUATION_LABEL;
case 1: default -> getKeyCharList(tt9, number);
return tt9.isNumericModeStrict() ? null : PUNCTUATION_LABEL; };
default:
return getKeyCharList(tt9, number);
}
} }

View file

@ -28,14 +28,11 @@ public class SoftKeyPunctuation extends SoftKey {
@Override @Override
protected String getTitle() { protected String getTitle() {
String keyChar = getKeyChar(); String keyChar = getKeyChar();
switch (keyChar) { return switch (keyChar) {
case "": case "" -> "PUNC";
return "PUNC"; case "*" -> "";
case "*": default -> keyChar;
return ""; };
default:
return keyChar;
}
} }
private String getKeyChar() { private String getKeyChar() {

View file

@ -2,7 +2,6 @@ package io.github.sspanak.tt9.util;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.regex.Pattern; import java.util.regex.Pattern;