comparison src/com/five_ten_sg/connectbot/service/TerminalBridge.java @ 230:bc40032ad1da

use StringPickerDialog for soft cursor keypad
author Carl Byington <carl@five-ten-sg.com>
date Wed, 09 Jul 2014 14:27:51 -0700
parents 61ed3984fc1d
children 502ba7668993
comparison
equal deleted inserted replaced
229:594101a0876a 230:bc40032ad1da
1127 1127
1128 /** 1128 /**
1129 * Show arrows dialog 1129 * Show arrows dialog
1130 */ 1130 */
1131 public boolean showArrowsDialog() { 1131 public boolean showArrowsDialog() {
1132 final String pickerString = "←→↑↓TIDE"; 1132 final String []pickerStrings = {"←", "→", "↑", "↓", "tab", "ins", "del", "ret";
1133 final HashMap<String,Integer> keymap = new HashMap<String,Integer>();
1134 keymap.put("←", vt320.KEY_LEFT);
1135 keymap.put("→", vt320.KEY_RIGHT);
1136 keymap.put("↑", vt320.KEY_UP);
1137 keymap.put("↓", vt320.KEY_DOWN);
1138 keymap.put("tab", vt320.KEY_TAB);
1139 keymap.put("ins", vt320.KEY_INSERT);
1140 keymap.put("del", vt320.KEY_DELETE);
1141 keymap.put("ret", vt320.KEY_ENTER);
1142
1133 CharSequence str = ""; 1143 CharSequence str = "";
1134 Editable content = Editable.Factory.getInstance().newEditable(str); 1144 Editable content = Editable.Factory.getInstance().newEditable(str);
1135 1145
1136 if (parent == null) 1146 if (parent == null) return false;
1137 return false; 1147
1138 1148 StringPickerDialog cpd = new StringPickerDialog(parent.getContext(),
1139 CharacterPickerDialog cpd = new CharacterPickerDialog(parent.getContext(), 1149 parent, content,
1140 parent, content, pickerString, true) { 1150 pickerStrings, true) {
1141 private void buttonPressed(CharSequence result) { 1151 private void buttonPressed(String s) {
1142 if (result.equals("←")) 1152 if (keymap.containsKey(s)) buffer.keyPressed(keymap.get(s), ' ', 0);
1143 buffer.keyPressed(vt320.KEY_LEFT, ' ', 0);
1144 else if (result.equals("→"))
1145 buffer.keyPressed(vt320.KEY_RIGHT, ' ', 0);
1146 else if (result.equals("↑"))
1147 buffer.keyPressed(vt320.KEY_UP, ' ', 0);
1148 else if (result.equals("↓"))
1149 buffer.keyPressed(vt320.KEY_DOWN, ' ', 0);
1150 else if (result.equals("T"))
1151 buffer.keyPressed(vt320.KEY_TAB, ' ', 0);
1152 else if (result.equals("I"))
1153 buffer.keyPressed(vt320.KEY_INSERT, ' ', 0);
1154 else if (result.equals("D"))
1155 buffer.keyPressed(vt320.KEY_DELETE, ' ', 0);
1156 else if (result.equals("E"))
1157 buffer.keyPressed(vt320.KEY_ENTER, ' ', 0);
1158 } 1153 }
1159 @Override 1154 @Override
1160 public void onItemClick(AdapterView p, View v, int pos, long id) { 1155 public void onItemClick(AdapterView p, View v, int pos, long id) {
1161 final String result = String.valueOf(pickerString.charAt(pos)); 1156 buttonPressed(pickerStrings[pos]);
1162 buttonPressed(result);
1163 } 1157 }
1164 @Override 1158 @Override
1165 public void onClick(View v) { 1159 public void onClick(View v) {
1166 if (v instanceof Button) { 1160 if (v instanceof Button) {
1167 final CharSequence result = ((Button) v).getText(); 1161 final String s = ((Button) v).getText().toString();
1168 1162 if (s.equals("")) dismiss();
1169 if (result.equals("")) 1163 else buttonPressed(s);
1170 dismiss();
1171 else
1172 buttonPressed(result);
1173 } 1164 }
1174 } 1165 }
1175 @Override 1166 @Override
1176 public boolean dispatchKeyEvent(KeyEvent event) { 1167 public boolean dispatchKeyEvent(KeyEvent event) {
1177 if (event.getAction() == KeyEvent.ACTION_DOWN) { 1168 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1260 1251
1261 /** 1252 /**
1262 * Function keys dialog 1253 * Function keys dialog
1263 */ 1254 */
1264 public boolean showFKeysDialog() { 1255 public boolean showFKeysDialog() {
1265 final String []pickerString = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23", "F24"}; 1256 final String []pickerStrings = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23", "F24"};
1266 final HashMap<String,Integer> keymap = new HashMap<String,Integer>(); 1257 final HashMap<String,Integer> keymap = new HashMap<String,Integer>();
1267 keymap.put("F1", vt320.KEY_F1); 1258 keymap.put("F1", vt320.KEY_F1);
1268 keymap.put("F2", vt320.KEY_F2); 1259 keymap.put("F2", vt320.KEY_F2);
1269 keymap.put("F3", vt320.KEY_F3); 1260 keymap.put("F3", vt320.KEY_F3);
1270 keymap.put("F4", vt320.KEY_F4); 1261 keymap.put("F4", vt320.KEY_F4);
1290 keymap.put("F24", vt320.KEY_F24); 1281 keymap.put("F24", vt320.KEY_F24);
1291 1282
1292 CharSequence str = ""; 1283 CharSequence str = "";
1293 Editable content = Editable.Factory.getInstance().newEditable(str); 1284 Editable content = Editable.Factory.getInstance().newEditable(str);
1294 1285
1295 if (parent == null) 1286 if (parent == null) return false;
1296 return false;
1297 1287
1298 StringPickerDialog cpd = new StringPickerDialog(parent.getContext(), 1288 StringPickerDialog cpd = new StringPickerDialog(parent.getContext(),
1299 parent, content, pickerString, true) { 1289 parent, content,
1300 private void buttonPressed(CharSequence result) { 1290 pickerStrings, true) {
1301 String s = result.toString(); 1291 private void buttonPressed(String s) {
1302 if (keymap.containsKey(s)) buffer.keyPressed(keymap.get(s), ' ', 0); 1292 if (keymap.containsKey(s)) buffer.keyPressed(keymap.get(s), ' ', 0);
1303 dismiss(); 1293 dismiss();
1304 } 1294 }
1305 @Override 1295 @Override
1306 public void onItemClick(AdapterView p, View v, int pos, long id) { 1296 public void onItemClick(AdapterView p, View v, int pos, long id) {
1307 final String result = pickerString[pos]; 1297 buttonPressed(pickerStrings[pos]);
1308 buttonPressed(result);
1309 } 1298 }
1310 @Override 1299 @Override
1311 public void onClick(View v) { 1300 public void onClick(View v) {
1312 if (v instanceof Button) { 1301 if (v instanceof Button) {
1313 Button b = (Button)v; 1302 final String s = ((Button) v).getText().toString();
1314 final CharSequence result = b.getText(); 1303 if (s.equals("")) dismiss();
1315 1304 else buttonPressed(s);
1316 if (result.equals(""))
1317 dismiss();
1318 else
1319 buttonPressed(result);
1320 } 1305 }
1321 } 1306 }
1322 @Override 1307 @Override
1323 public boolean dispatchKeyEvent(KeyEvent event) { 1308 public boolean dispatchKeyEvent(KeyEvent event) {
1324 if (event.getAction() == KeyEvent.ACTION_DOWN) { 1309 if (event.getAction() == KeyEvent.ACTION_DOWN) {