Minor restructuring of TermuxPreferences

This commit is contained in:
Fredrik Fornwall
2019-01-21 00:33:03 +01:00
parent 743225ab6a
commit d8f066dec4
2 changed files with 24 additions and 28 deletions

View File

@@ -215,7 +215,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
mTerminalView.requestFocus(); mTerminalView.requestFocus();
final ViewPager viewPager = findViewById(R.id.viewpager); final ViewPager viewPager = findViewById(R.id.viewpager);
if (mSettings.isShowExtraKeys()) viewPager.setVisibility(View.VISIBLE); if (mSettings.mShowExtraKeys) viewPager.setVisibility(View.VISIBLE);
ViewGroup.LayoutParams layoutParams = viewPager.getLayoutParams(); ViewGroup.LayoutParams layoutParams = viewPager.getLayoutParams();

View File

@@ -27,9 +27,25 @@ final class TermuxPreferences {
@IntDef({BELL_VIBRATE, BELL_BEEP, BELL_IGNORE}) @IntDef({BELL_VIBRATE, BELL_BEEP, BELL_IGNORE})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface AsciiBellBehaviour { @interface AsciiBellBehaviour {
} }
final static class KeyboardShortcut {
KeyboardShortcut(int codePoint, int shortcutAction) {
this.codePoint = codePoint;
this.shortcutAction = shortcutAction;
}
final int codePoint;
final int shortcutAction;
}
static final int SHORTCUT_ACTION_CREATE_SESSION = 1;
static final int SHORTCUT_ACTION_NEXT_SESSION = 2;
static final int SHORTCUT_ACTION_PREVIOUS_SESSION = 3;
static final int SHORTCUT_ACTION_RENAME_SESSION = 4;
static final int BELL_VIBRATE = 1; static final int BELL_VIBRATE = 1;
static final int BELL_BEEP = 2; static final int BELL_BEEP = 2;
static final int BELL_IGNORE = 3; static final int BELL_IGNORE = 3;
@@ -51,6 +67,10 @@ final class TermuxPreferences {
boolean mBackIsEscape; boolean mBackIsEscape;
boolean mShowExtraKeys; boolean mShowExtraKeys;
String[][] mExtraKeys;
final List<KeyboardShortcut> shortcuts = new ArrayList<>();
/** /**
* If value is not in the range [min, max], set it to either min or max. * If value is not in the range [min, max], set it to either min or max.
*/ */
@@ -84,10 +104,6 @@ final class TermuxPreferences {
mFontSize = clamp(mFontSize, MIN_FONTSIZE, MAX_FONTSIZE); mFontSize = clamp(mFontSize, MIN_FONTSIZE, MAX_FONTSIZE);
} }
boolean isShowExtraKeys() {
return mShowExtraKeys;
}
boolean toggleShowExtraKeys(Context context) { boolean toggleShowExtraKeys(Context context) {
mShowExtraKeys = !mShowExtraKeys; mShowExtraKeys = !mShowExtraKeys;
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(SHOW_EXTRA_KEYS_KEY, mShowExtraKeys).apply(); PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(SHOW_EXTRA_KEYS_KEY, mShowExtraKeys).apply();
@@ -128,9 +144,7 @@ final class TermuxPreferences {
return null; return null;
} }
public String[][] mExtraKeys; void reloadFromProperties(Context context) {
public void reloadFromProperties(Context context) {
File propsFile = new File(TermuxService.HOME_PATH + "/.termux/termux.properties"); File propsFile = new File(TermuxService.HOME_PATH + "/.termux/termux.properties");
if (!propsFile.exists()) if (!propsFile.exists())
propsFile = new File(TermuxService.HOME_PATH + "/.config/termux/termux.properties"); propsFile = new File(TermuxService.HOME_PATH + "/.config/termux/termux.properties");
@@ -185,24 +199,6 @@ final class TermuxPreferences {
parseAction("shortcut.rename-session", SHORTCUT_ACTION_RENAME_SESSION, props); parseAction("shortcut.rename-session", SHORTCUT_ACTION_RENAME_SESSION, props);
} }
public static final int SHORTCUT_ACTION_CREATE_SESSION = 1;
public static final int SHORTCUT_ACTION_NEXT_SESSION = 2;
public static final int SHORTCUT_ACTION_PREVIOUS_SESSION = 3;
public static final int SHORTCUT_ACTION_RENAME_SESSION = 4;
public final static class KeyboardShortcut {
public KeyboardShortcut(int codePoint, int shortcutAction) {
this.codePoint = codePoint;
this.shortcutAction = shortcutAction;
}
final int codePoint;
final int shortcutAction;
}
final List<KeyboardShortcut> shortcuts = new ArrayList<>();
private void parseAction(String name, int shortcutAction, Properties props) { private void parseAction(String name, int shortcutAction, Properties props) {
String value = props.getProperty(name); String value = props.getProperty(name);
if (value == null) return; if (value == null) return;