changeset 113:cb3b9b660b3d

depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
author Carl Byington <carl@five-ten-sg.com>
date Wed, 18 Jun 2014 14:24:00 -0700
parents 77ac18bc1b2f
children 5eda34fb607f
files src/com/five_ten_sg/connectbot/service/TerminalBridge.java src/com/five_ten_sg/connectbot/service/TerminalMonitor.java src/org/tn5250j/framework/tn5250/Screen5250.java
diffstat 3 files changed, 31 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/service/TerminalBridge.java	Wed Jun 18 13:03:01 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalBridge.java	Wed Jun 18 14:24:00 2014 -0700
@@ -222,7 +222,7 @@
         String monitor_init = host.getMonitor();
 
         if ((monitor_init != null) && (monitor_init.length() > 0)) {
-            monitor = new TerminalMonitor(manager, buffer, keyListener, parent, monitor_init);
+            monitor = new TerminalMonitor(manager, buffer, parent, monitor_init);
         }
 
         transport.setCompression(host.getCompression());
--- a/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Wed Jun 18 13:03:01 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Wed Jun 18 14:24:00 2014 -0700
@@ -6,7 +6,6 @@
 import android.content.ServiceConnection;
 import android.os.IBinder;
 import android.util.Log;
-import android.view.KeyEvent;
 import android.view.View;
 import de.mud.terminal.vt320;
 import java.io.IOException;
@@ -39,7 +38,6 @@
 
     private Context             parent       = null;
     private vt320               buffer       = null;
-    private TerminalKeyListener keyListener  = null;
     private View                view         = null;
     private String              init         = null;
     private int                 start_line   = 0;       // monitor part of the screen for changes
@@ -50,7 +48,7 @@
     private boolean             moved        = false;   // used to delay cursor moved notifications
     private int                 to_line      = 0;       // ""
     private int                 to_column    = 0;       // ""
-    private HashMap<Integer, Integer>  keymap = null;
+    private HashMap<Integer, Integer>  keymap = null;   // map MS VK_ keys to vt320 virtual keys
     private IBinder             bound        = null;
     private Socket              monitor_socket = null;
     private InputStream         monitor_in     = null;
@@ -173,42 +171,40 @@
     };
 
 
-    public TerminalMonitor(Context parent, vt320 buffer, TerminalKeyListener keyListener, View view, String init) {
+    public TerminalMonitor(Context parent, vt320 buffer, View view, String init) {
         this.parent      = parent;
         this.buffer      = buffer;
-        this.keyListener = keyListener;
         this.view        = view;
         this.init        = init;
         // setup the windows->android keymapping
         // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731
-        // http://developer.android.com/reference/android/view/KeyEvent.html
         keymap      = new HashMap<Integer, Integer>();
-        keymap.put(0x08, KeyEvent.KEYCODE_BACK);        // vk_back
-        keymap.put(0x09, KeyEvent.KEYCODE_TAB);         // vk_tab
-        keymap.put(0x0d, KeyEvent.KEYCODE_ENTER);       // vk_return
-        keymap.put(0x1b, KeyEvent.KEYCODE_ESCAPE);      // vk_escape
-        keymap.put(0x21, KeyEvent.KEYCODE_PAGE_UP);     // vk_prior
-        keymap.put(0x22, KeyEvent.KEYCODE_PAGE_DOWN);   // vk_next
-        keymap.put(0x23, KeyEvent.KEYCODE_MOVE_END);    // vk_end
-        keymap.put(0x24, KeyEvent.KEYCODE_MOVE_HOME);   // vk_home
-        keymap.put(0x25, KeyEvent.KEYCODE_DPAD_LEFT);   // vk_left
-        keymap.put(0x26, KeyEvent.KEYCODE_DPAD_UP);     // vk_up
-        keymap.put(0x27, KeyEvent.KEYCODE_DPAD_RIGHT);  // vk_right
-        keymap.put(0x28, KeyEvent.KEYCODE_DPAD_DOWN);   // vk_down
-        keymap.put(0x2d, KeyEvent.KEYCODE_INSERT);      // vk_insert
-        keymap.put(0x2e, KeyEvent.KEYCODE_DEL);         // vk_delete
-        keymap.put(0x70, KeyEvent.KEYCODE_F1);          // vk_f1
-        keymap.put(0x71, KeyEvent.KEYCODE_F2);          // vk_f2
-        keymap.put(0x72, KeyEvent.KEYCODE_F3);          // vk_f3
-        keymap.put(0x73, KeyEvent.KEYCODE_F4);          // vk_f4
-        keymap.put(0x74, KeyEvent.KEYCODE_F5);          // vk_f5
-        keymap.put(0x75, KeyEvent.KEYCODE_F6);          // vk_f6
-        keymap.put(0x76, KeyEvent.KEYCODE_F7);          // vk_f7
-        keymap.put(0x77, KeyEvent.KEYCODE_F8);          // vk_f8
-        keymap.put(0x78, KeyEvent.KEYCODE_F9);          // vk_f9
-        keymap.put(0x79, KeyEvent.KEYCODE_F10);         // vk_f10
-        keymap.put(0x7a, KeyEvent.KEYCODE_F11);         // vk_f11
-        keymap.put(0x7b, KeyEvent.KEYCODE_F12);         // vk_f12
+        keymap.put(0x08, vt320.KEY_BACK_SPACE);  // vk_back
+        keymap.put(0x09, vt320.KEY_TAB);         // vk_tab
+        keymap.put(0x0d, vt320.KEY_ENTER);       // vk_return
+        keymap.put(0x1b, vt320.KEY_ESCAPE);      // vk_escape
+        keymap.put(0x21, vt320.KEY_PAGE_UP);     // vk_prior
+        keymap.put(0x22, vt320.KEY_PAGE_DOWN);   // vk_next
+        keymap.put(0x23, vt320.KEY_END);         // vk_end
+        keymap.put(0x24, vt320.KEY_HOME);        // vk_home
+        keymap.put(0x25, vt320.KEY_LEFT);        // vk_left
+        keymap.put(0x26, vt320.KEY_UP);          // vk_up
+        keymap.put(0x27, vt320.KEY_RIGHT);       // vk_right
+        keymap.put(0x28, vt320.KEY_DOWN);        // vk_down
+        keymap.put(0x2d, vt320.KEY_INSERT);      // vk_insert
+        keymap.put(0x2e, vt320.KEY_DELETE);      // vk_delete
+        keymap.put(0x70, vt320.KEY_F1);          // vk_f1
+        keymap.put(0x71, vt320.KEY_F2);          // vk_f2
+        keymap.put(0x72, vt320.KEY_F3);          // vk_f3
+        keymap.put(0x73, vt320.KEY_F4);          // vk_f4
+        keymap.put(0x74, vt320.KEY_F5);          // vk_f5
+        keymap.put(0x75, vt320.KEY_F6);          // vk_f6
+        keymap.put(0x76, vt320.KEY_F7);          // vk_f7
+        keymap.put(0x77, vt320.KEY_F8);          // vk_f8
+        keymap.put(0x78, vt320.KEY_F9);          // vk_f9
+        keymap.put(0x79, vt320.KEY_F10);         // vk_f10
+        keymap.put(0x7a, vt320.KEY_F11);         // vk_f11
+        keymap.put(0x7b, vt320.KEY_F12);         // vk_f12
         // bind to the monitor service
         Intent intent = new Intent("com.five_ten_sg.connectbot.monitor.MonitorService");
         parent.bindService(intent, monitor_connection, Context.BIND_AUTO_CREATE);
@@ -400,10 +396,6 @@
     public synchronized void depress(int vk_key) {
         Log.i(TAG, String.format("depress() %d", vk_key));
         Integer x = keymap.get(new Integer(vk_key));
-
-        if (x != null) {
-            KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, x.intValue());
-            keyListener.onKey(view, event.getKeyCode(), event);
-        }
+        if (x != null) buffer.keyPressed(x, ' ', 0);
     }
 }
--- a/src/org/tn5250j/framework/tn5250/Screen5250.java	Wed Jun 18 13:03:01 2014 -0700
+++ b/src/org/tn5250j/framework/tn5250/Screen5250.java	Wed Jun 18 14:24:00 2014 -0700
@@ -985,38 +985,17 @@
                 setCursorActive(false);
 
                 while (!done) {
-                    //            while (strokenizer.hasMoreKeyStrokes() && !keyboardLocked
-                    // &&
-                    //                        !isStatusErrorCode() && !done) {
                     if (strokenizer.hasMoreKeyStrokes()) {
                         // check to see if position is in a field and if it is
-                        // then change
-                        //   current field to that field
+                        // then change current field to that field
                         isInField(lastPos, true);
                         s = strokenizer.nextKeyStroke();
 
                         if (s.length() == 1) {
-                            //                  setCursorOn();
-                            //                  if (!keysBuffered) {
-                            //                     System.out.println(" s two" + s);
-                            //                     setCursorOn();
-                            //                  }
-                            //                  try { new Thread().sleep(400);} catch
-                            // (InterruptedException ie) {}
                             simulateKeyStroke(s.charAt(0));
-                            //                     System.out.println(" s two " + s + " " +
-                            // cursorActive);
-                            //                  if (cursorActive && !keysBuffered) {
-                            //                     System.out.println(" s two" + s);
-                            //                     setCursorOn();
-                            //                  }
                         }
                         else {
                             simulateMnemonic(getMnemonicValue(s));
-                            //                  if (!cursorActive && !keysBuffered) {
-                            //                     System.out.println(" m one");
-                            //                     setCursorOn();
-                            //                  }
                         }
 
                         if (oia.isKeyBoardLocked()) {
@@ -1031,8 +1010,6 @@
                         }
                     }
                     else {
-                        //                  setCursorActive(true);
-                        //                  setCursorOn();
                         done = true;
                     }
                 }
@@ -1374,7 +1351,6 @@
                 break;
 
             case HOME:
-
                 // position to the home position set
                 if (lastPos + numCols + 1 != homePos) {
                     goto_XY(homePos - numCols - 1);