settings code cleanup
This commit is contained in:
parent
a09e6f65e7
commit
ca6b0badc9
5 changed files with 17 additions and 37 deletions
|
|
@ -16,4 +16,12 @@ class BaseSettings {
|
|||
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefsEditor = prefs.edit();
|
||||
}
|
||||
|
||||
protected int getStringifiedInt(String key, int defaultValue) {
|
||||
try {
|
||||
return Integer.parseInt(prefs.getString(key, String.valueOf(defaultValue)));
|
||||
} catch (NumberFormatException ignored) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,19 +11,11 @@ class SettingsHacks extends BaseSettings {
|
|||
/************* debugging settings *************/
|
||||
|
||||
public int getLogLevel() {
|
||||
try {
|
||||
return Integer.parseInt(prefs.getString("pref_log_level", String.valueOf(Logger.LEVEL)));
|
||||
} catch (NumberFormatException ignored) {
|
||||
return Logger.LEVEL;
|
||||
}
|
||||
return getStringifiedInt("pref_log_level", Logger.LEVEL);
|
||||
}
|
||||
|
||||
public int getInputHandlingMode() {
|
||||
try {
|
||||
return Integer.parseInt(prefs.getString("pref_input_handling_mode", String.valueOf(ItemInputHandlingMode.NORMAL)));
|
||||
} catch (NumberFormatException ignored) {
|
||||
return ItemInputHandlingMode.NORMAL;
|
||||
}
|
||||
return getStringifiedInt("pref_input_handling_mode", ItemInputHandlingMode.NORMAL);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -49,10 +41,6 @@ class SettingsHacks extends BaseSettings {
|
|||
*/
|
||||
|
||||
public int getKeyPadDebounceTime() {
|
||||
try {
|
||||
return Integer.parseInt(prefs.getString("pref_key_pad_debounce_time", "0"));
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
return getStringifiedInt("pref_key_pad_debounce_time", 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,14 +38,12 @@ class SettingsHotkeys extends SettingsHacks {
|
|||
.apply();
|
||||
}
|
||||
|
||||
|
||||
public int getFunctionKey(String functionName) {
|
||||
try {
|
||||
return Integer.parseInt(prefs.getString(functionName, "0"));
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
return getStringifiedInt(functionName, 0);
|
||||
}
|
||||
|
||||
|
||||
public int getKeyAddWord() {
|
||||
return getFunctionKey(SectionKeymap.ITEM_ADD_WORD);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,7 @@ class SettingsTyping extends SettingsInput {
|
|||
SettingsTyping(Context context) { super(context); }
|
||||
|
||||
public int getAbcAutoAcceptTimeout() {
|
||||
int time;
|
||||
try {
|
||||
time = Integer.parseInt(prefs.getString("pref_abc_auto_accept_time", "800"));
|
||||
} catch (NumberFormatException e) {
|
||||
time = 800;
|
||||
}
|
||||
|
||||
int time = getStringifiedInt("pref_abc_auto_accept_timeout", 800);
|
||||
return time > 0 ? time + getKeyPadDebounceTime() : time;
|
||||
}
|
||||
public boolean getAutoSpace() { return prefs.getBoolean("auto_space", true); }
|
||||
|
|
|
|||
|
|
@ -29,19 +29,11 @@ public class SettingsUI extends SettingsTyping {
|
|||
}
|
||||
|
||||
public int getTheme() {
|
||||
try {
|
||||
return Integer.parseInt(prefs.getString("pref_theme", String.valueOf(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)));
|
||||
} catch (NumberFormatException e) {
|
||||
return AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
|
||||
}
|
||||
return getStringifiedInt("pref_theme", AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
|
||||
}
|
||||
|
||||
public int getMainViewLayout() {
|
||||
try {
|
||||
return Integer.parseInt(prefs.getString("pref_layout_type", String.valueOf(LAYOUT_SMALL)));
|
||||
} catch(NumberFormatException e) {
|
||||
return LAYOUT_SMALL;
|
||||
}
|
||||
return getStringifiedInt("pref_layout_type", LAYOUT_SMALL);
|
||||
}
|
||||
|
||||
public boolean isMainLayoutNumpad() { return getMainViewLayout() == LAYOUT_NUMPAD; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue