mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
add support of configurable extra keys
This commit is contained in:
committed by
Fredrik Fornwall
parent
57a3a9b111
commit
f0eeb4781b
@@ -33,8 +33,6 @@ public final class ExtraKeysView extends GridLayout {
|
||||
|
||||
public ExtraKeysView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
reload();
|
||||
}
|
||||
|
||||
static void sendKey(View view, String keyName) {
|
||||
@@ -148,24 +146,24 @@ public final class ExtraKeysView extends GridLayout {
|
||||
popupWindow.showAsDropDown(view, 0, -2 * height);
|
||||
}
|
||||
|
||||
void reload() {
|
||||
void reload(final String[][] buttons) {
|
||||
altButton = controlButton = null;
|
||||
removeAllViews();
|
||||
|
||||
String[][] buttons = {
|
||||
{"ESC", "/", "―", "HOME", "↑", "END", "PGUP"},
|
||||
{"TAB", "CTRL", "ALT", "←", "↓", "→", "PGDN"}
|
||||
};
|
||||
|
||||
int mx = 0;
|
||||
for (int row = 0; row < rows; row++) {
|
||||
if(buttons[row].length > mx) mx = buttons[row].length;
|
||||
}
|
||||
final int rows = buttons.length;
|
||||
final int[] cols = {buttons[0].length, buttons[1].length};
|
||||
final int cols = mx;
|
||||
|
||||
setRowCount(rows);
|
||||
setColumnCount(cols[0]);
|
||||
|
||||
for (int row = 0; row < rows; row++) {
|
||||
for (int col = 0; col < cols[row]; col++) {
|
||||
final String buttonText = buttons[row][col];
|
||||
for (int col = 0; col < cols; col++) {
|
||||
final String buttonText = (buttons[row][col] == null ? " " : buttons[row][col]);
|
||||
|
||||
Button button;
|
||||
switch (buttonText) {
|
||||
case "CTRL":
|
||||
|
@@ -217,6 +217,11 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
||||
|
||||
final ViewPager viewPager = findViewById(R.id.viewpager);
|
||||
if (mSettings.isShowExtraKeys()) viewPager.setVisibility(View.VISIBLE);
|
||||
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = viewPager.getLayoutParams();
|
||||
layoutParams.height = layoutParams.height * mSettings.mExtraKeys.length;
|
||||
viewPager.setLayoutParams(layoutParams);
|
||||
|
||||
viewPager.setAdapter(new PagerAdapter() {
|
||||
@Override
|
||||
@@ -236,6 +241,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
||||
View layout;
|
||||
if (position == 0) {
|
||||
layout = mExtraKeysView = (ExtraKeysView) inflater.inflate(R.layout.extra_keys_main, collection, false);
|
||||
mExtraKeysView.reload(mSettings.mExtraKeys);
|
||||
} else {
|
||||
layout = inflater.inflate(R.layout.extra_keys_right, collection, false);
|
||||
final EditText editText = layout.findViewById(R.id.text_input);
|
||||
|
@@ -17,6 +17,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import org.json.JSONArray;
|
||||
|
||||
final class TermuxPreferences {
|
||||
|
||||
@@ -103,6 +104,8 @@ final class TermuxPreferences {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String[][] mExtraKeys;
|
||||
|
||||
public void reloadFromProperties(Context context) {
|
||||
try {
|
||||
@@ -128,6 +131,16 @@ final class TermuxPreferences {
|
||||
mBellBehaviour = BELL_VIBRATE;
|
||||
break;
|
||||
}
|
||||
|
||||
JSONArray arr = new JSONArray(props.getProperty("extrakeys", "[[\"ESC\",\"CTRL\",\"ALT\",\"TAB\",\"―\",\"/\",\"|\"]]"));
|
||||
mExtraKeys = new String[arr.length()][];
|
||||
for(int i = 0; i < arr.length(); i++) {
|
||||
JSONArray line = arr.getJSONArray(i);
|
||||
mExtraKeys[i] = new String[line.length()];
|
||||
for(int j = 0; j < line.length(); j++) {
|
||||
mExtraKeys[i][j] = line.getString(j);
|
||||
}
|
||||
}
|
||||
|
||||
mBackIsEscape = "escape".equals(props.getProperty("back-key", "back"));
|
||||
|
||||
|
Reference in New Issue
Block a user