diff 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
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/service/TerminalBridge.java	Wed Jul 09 09:37:00 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalBridge.java	Wed Jul 09 14:27:51 2014 -0700
@@ -1129,47 +1129,38 @@
      * Show arrows dialog
      */
     public boolean showArrowsDialog() {
-        final String pickerString = "←→↑↓TIDE";
+        final String []pickerStrings = {"←", "→", "↑", "↓", "tab", "ins", "del", "ret";
+        final HashMap<String,Integer> keymap = new HashMap<String,Integer>();
+        keymap.put("←",   vt320.KEY_LEFT);
+        keymap.put("→",   vt320.KEY_RIGHT);
+        keymap.put("↑",   vt320.KEY_UP);
+        keymap.put("↓",   vt320.KEY_DOWN);
+        keymap.put("tab", vt320.KEY_TAB);
+        keymap.put("ins", vt320.KEY_INSERT);
+        keymap.put("del", vt320.KEY_DELETE);
+        keymap.put("ret", vt320.KEY_ENTER);
+
         CharSequence str = "";
         Editable content = Editable.Factory.getInstance().newEditable(str);
 
-        if (parent == null)
-            return false;
+        if (parent == null) return false;
 
-        CharacterPickerDialog cpd = new CharacterPickerDialog(parent.getContext(),
-        parent, content, pickerString, true) {
-            private void buttonPressed(CharSequence result) {
-                if (result.equals("←"))
-                    buffer.keyPressed(vt320.KEY_LEFT, ' ', 0);
-                else if (result.equals("→"))
-                    buffer.keyPressed(vt320.KEY_RIGHT, ' ', 0);
-                else if (result.equals("↑"))
-                    buffer.keyPressed(vt320.KEY_UP, ' ', 0);
-                else if (result.equals("↓"))
-                    buffer.keyPressed(vt320.KEY_DOWN, ' ', 0);
-                else if (result.equals("T"))
-                    buffer.keyPressed(vt320.KEY_TAB, ' ', 0);
-                else if (result.equals("I"))
-                    buffer.keyPressed(vt320.KEY_INSERT, ' ', 0);
-                else if (result.equals("D"))
-                    buffer.keyPressed(vt320.KEY_DELETE, ' ', 0);
-                else if (result.equals("E"))
-                    buffer.keyPressed(vt320.KEY_ENTER, ' ', 0);
+        StringPickerDialog cpd = new StringPickerDialog(parent.getContext(),
+                                                        parent, content,
+                                                        pickerStrings, true) {
+            private void buttonPressed(String s) {
+                if (keymap.containsKey(s)) buffer.keyPressed(keymap.get(s), ' ', 0);
             }
             @Override
             public void onItemClick(AdapterView p, View v, int pos, long id) {
-                final String result = String.valueOf(pickerString.charAt(pos));
-                buttonPressed(result);
+                buttonPressed(pickerStrings[pos]);
             }
             @Override
             public void onClick(View v) {
                 if (v instanceof Button) {
-                    final CharSequence result = ((Button) v).getText();
-
-                    if (result.equals(""))
-                        dismiss();
-                    else
-                        buttonPressed(result);
+                    final String s = ((Button) v).getText().toString();
+                    if (s.equals("")) dismiss();
+                    else buttonPressed(s);
                 }
             }
             @Override
@@ -1262,7 +1253,7 @@
      * Function keys dialog
      */
     public boolean showFKeysDialog() {
-        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"};
+        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"};
         final HashMap<String,Integer> keymap = new HashMap<String,Integer>();
         keymap.put("F1", vt320.KEY_F1);
         keymap.put("F2", vt320.KEY_F2);
@@ -1292,31 +1283,25 @@
         CharSequence str = "";
         Editable content = Editable.Factory.getInstance().newEditable(str);
 
-        if (parent == null)
-            return false;
+        if (parent == null) return false;
 
         StringPickerDialog cpd = new StringPickerDialog(parent.getContext(),
-        parent, content, pickerString, true) {
-            private void buttonPressed(CharSequence result) {
-                String s = result.toString();
+                                                        parent, content,
+                                                        pickerStrings, true) {
+            private void buttonPressed(String s) {
                 if (keymap.containsKey(s)) buffer.keyPressed(keymap.get(s), ' ', 0);
                 dismiss();
             }
             @Override
             public void onItemClick(AdapterView p, View v, int pos, long id) {
-                final String result = pickerString[pos];
-                buttonPressed(result);
+                buttonPressed(pickerStrings[pos]);
             }
             @Override
             public void onClick(View v) {
                 if (v instanceof Button) {
-                    Button b = (Button)v;
-                    final CharSequence result = b.getText();
-
-                    if (result.equals(""))
-                        dismiss();
-                    else
-                        buttonPressed(result);
+                    final String s = ((Button) v).getText().toString();
+                    if (s.equals("")) dismiss();
+                    else buttonPressed(s);
                 }
             }
             @Override