Mercurial > 510Connectbot
comparison src/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 112:77ac18bc1b2f
cleanup java formatting
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 18 Jun 2014 13:03:01 -0700 |
parents | f0ec55006f31 |
children | cb3b9b660b3d |
comparison
equal
deleted
inserted
replaced
111:6a0ad4d384ea | 112:77ac18bc1b2f |
---|---|
48 private int end_column = 500; // "" | 48 private int end_column = 500; // "" |
49 private boolean modified = false; // used to delay screen change notifications | 49 private boolean modified = false; // used to delay screen change notifications |
50 private boolean moved = false; // used to delay cursor moved notifications | 50 private boolean moved = false; // used to delay cursor moved notifications |
51 private int to_line = 0; // "" | 51 private int to_line = 0; // "" |
52 private int to_column = 0; // "" | 52 private int to_column = 0; // "" |
53 private HashMap<Integer,Integer> keymap = null; | 53 private HashMap<Integer, Integer> keymap = null; |
54 private IBinder bound = null; | 54 private IBinder bound = null; |
55 private Socket monitor_socket = null; | 55 private Socket monitor_socket = null; |
56 private InputStream monitor_in = null; | 56 private InputStream monitor_in = null; |
57 private OutputStream monitor_out = null; | 57 private OutputStream monitor_out = null; |
58 private MyReader monitor_reader = null; | 58 private MyReader monitor_reader = null; |
101 | 101 |
102 switch (cmd) { | 102 switch (cmd) { |
103 case MONITOR_CMD_SETFIELD: | 103 case MONITOR_CMD_SETFIELD: |
104 if (packet.length >= 4) | 104 if (packet.length >= 4) |
105 setField(packet[1], packet[2], packet, 3); | 105 setField(packet[1], packet[2], packet, 3); |
106 | |
106 break; | 107 break; |
107 | 108 |
108 case MONITOR_CMD_GETFIELD: | 109 case MONITOR_CMD_GETFIELD: |
109 if (packet.length == 4) | 110 if (packet.length == 4) |
110 getField(packet[1], packet[2], packet[3]); | 111 getField(packet[1], packet[2], packet[3]); |
112 | |
111 break; | 113 break; |
112 | 114 |
113 case MONITOR_CMD_SCREENWATCH: | 115 case MONITOR_CMD_SCREENWATCH: |
114 if (packet.length == 4) | 116 if (packet.length == 4) |
115 screenWatch(packet[1], packet[2], packet[3]); | 117 screenWatch(packet[1], packet[2], packet[3]); |
118 | |
116 break; | 119 break; |
117 | 120 |
118 case MONITOR_CMD_DEPRESS: | 121 case MONITOR_CMD_DEPRESS: |
119 if (packet.length == 2) | 122 if (packet.length == 2) |
120 depress(packet[1]); | 123 depress(packet[1]); |
124 | |
121 break; | 125 break; |
122 | 126 |
123 default: | 127 default: |
124 break; | 128 break; |
125 } | 129 } |
147 monitor_reader = new MyReader(monitor_in); | 151 monitor_reader = new MyReader(monitor_in); |
148 monitor_reader.start(); | 152 monitor_reader.start(); |
149 String x = " " + init; | 153 String x = " " + init; |
150 monitorWrite(MONITOR_CMD_INIT, x.toCharArray()); | 154 monitorWrite(MONITOR_CMD_INIT, x.toCharArray()); |
151 char [] c; | 155 char [] c; |
156 | |
152 while (true) { | 157 while (true) { |
153 c = pending_commands.poll(); | 158 c = pending_commands.poll(); |
159 | |
154 if (c == null) break; | 160 if (c == null) break; |
161 | |
155 monitorWrite(c[1], c); | 162 monitorWrite(c[1], c); |
156 } | 163 } |
157 } | 164 } |
158 catch (IOException e) { | 165 catch (IOException e) { |
159 Log.e(TAG, "exception in onServiceConnected()", e); | 166 Log.e(TAG, "exception in onServiceConnected()", e); |
170 this.parent = parent; | 177 this.parent = parent; |
171 this.buffer = buffer; | 178 this.buffer = buffer; |
172 this.keyListener = keyListener; | 179 this.keyListener = keyListener; |
173 this.view = view; | 180 this.view = view; |
174 this.init = init; | 181 this.init = init; |
175 | |
176 // setup the windows->android keymapping | 182 // setup the windows->android keymapping |
177 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 | 183 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 |
178 // http://developer.android.com/reference/android/view/KeyEvent.html | 184 // http://developer.android.com/reference/android/view/KeyEvent.html |
179 keymap = new HashMap<Integer,Integer>(); | 185 keymap = new HashMap<Integer, Integer>(); |
180 keymap.put(0x08, KeyEvent.KEYCODE_BACK); // vk_back | 186 keymap.put(0x08, KeyEvent.KEYCODE_BACK); // vk_back |
181 keymap.put(0x09, KeyEvent.KEYCODE_TAB); // vk_tab | 187 keymap.put(0x09, KeyEvent.KEYCODE_TAB); // vk_tab |
182 keymap.put(0x0d, KeyEvent.KEYCODE_ENTER); // vk_return | 188 keymap.put(0x0d, KeyEvent.KEYCODE_ENTER); // vk_return |
183 keymap.put(0x1b, KeyEvent.KEYCODE_ESCAPE); // vk_escape | 189 keymap.put(0x1b, KeyEvent.KEYCODE_ESCAPE); // vk_escape |
184 keymap.put(0x21, KeyEvent.KEYCODE_PAGE_UP); // vk_prior | 190 keymap.put(0x21, KeyEvent.KEYCODE_PAGE_UP); // vk_prior |
201 keymap.put(0x77, KeyEvent.KEYCODE_F8); // vk_f8 | 207 keymap.put(0x77, KeyEvent.KEYCODE_F8); // vk_f8 |
202 keymap.put(0x78, KeyEvent.KEYCODE_F9); // vk_f9 | 208 keymap.put(0x78, KeyEvent.KEYCODE_F9); // vk_f9 |
203 keymap.put(0x79, KeyEvent.KEYCODE_F10); // vk_f10 | 209 keymap.put(0x79, KeyEvent.KEYCODE_F10); // vk_f10 |
204 keymap.put(0x7a, KeyEvent.KEYCODE_F11); // vk_f11 | 210 keymap.put(0x7a, KeyEvent.KEYCODE_F11); // vk_f11 |
205 keymap.put(0x7b, KeyEvent.KEYCODE_F12); // vk_f12 | 211 keymap.put(0x7b, KeyEvent.KEYCODE_F12); // vk_f12 |
206 | |
207 // bind to the monitor service | 212 // bind to the monitor service |
208 Intent intent = new Intent("com.five_ten_sg.connectbot.monitor.MonitorService"); | 213 Intent intent = new Intent("com.five_ten_sg.connectbot.monitor.MonitorService"); |
209 parent.bindService(intent, monitor_connection, Context.BIND_AUTO_CREATE); | 214 parent.bindService(intent, monitor_connection, Context.BIND_AUTO_CREATE); |
210 Log.i(TAG, "constructor"); | 215 Log.i(TAG, "constructor"); |
211 } | 216 } |
300 char columns = (char)(buffer.width & 0x0000ffff); | 305 char columns = (char)(buffer.width & 0x0000ffff); |
301 char[] arg = new char[4 + lines * columns]; | 306 char[] arg = new char[4 + lines * columns]; |
302 arg[2] = lines; | 307 arg[2] = lines; |
303 arg[3] = columns; | 308 arg[3] = columns; |
304 int base = 4; | 309 int base = 4; |
310 | |
305 for (int i = 0; i < lines; i++) { | 311 for (int i = 0; i < lines; i++) { |
306 System.arraycopy(buffer.charArray[buffer.screenBase + i], 0, arg, base, columns); | 312 System.arraycopy(buffer.charArray[buffer.screenBase + i], 0, arg, base, columns); |
307 base += columns; | 313 base += columns; |
308 } | 314 } |
315 | |
309 monitorWrite(cmd, arg); | 316 monitorWrite(cmd, arg); |
310 } | 317 } |
311 | 318 |
312 public synchronized void activate() { | 319 public synchronized void activate() { |
313 sendScreen(MONITOR_CMD_ACTIVATE); | 320 sendScreen(MONITOR_CMD_ACTIVATE); |
341 public synchronized void testChanged() { | 348 public synchronized void testChanged() { |
342 if (modified) { | 349 if (modified) { |
343 modified = false; | 350 modified = false; |
344 sendScreen(MONITOR_CMD_SCREENCHANGE); | 351 sendScreen(MONITOR_CMD_SCREENCHANGE); |
345 } | 352 } |
353 | |
346 if (moved) { | 354 if (moved) { |
347 moved = false; | 355 moved = false; |
348 cursorMoved(); | 356 cursorMoved(); |
349 } | 357 } |
350 } | 358 } |
361 | 369 |
362 public synchronized void setField(int l, int c, char[] data, int offset) { | 370 public synchronized void setField(int l, int c, char[] data, int offset) { |
363 Log.i(TAG, "setField()"); | 371 Log.i(TAG, "setField()"); |
364 char[] da = new char[data.length - offset]; | 372 char[] da = new char[data.length - offset]; |
365 int i; | 373 int i; |
366 for (i=0; i<da.length; i++) { | 374 |
367 da[i] = data[i+offset]; | 375 for (i = 0; i < da.length; i++) { |
368 } | 376 da[i] = data[i + offset]; |
377 } | |
378 | |
369 buffer.setField(l, c, da); | 379 buffer.setField(l, c, da); |
370 } | 380 } |
371 | 381 |
372 public synchronized void getField(int l, int c, int len) { | 382 public synchronized void getField(int l, int c, int len) { |
373 Log.i(TAG, "getField()"); | 383 Log.i(TAG, "getField()"); |
388 } | 398 } |
389 | 399 |
390 public synchronized void depress(int vk_key) { | 400 public synchronized void depress(int vk_key) { |
391 Log.i(TAG, String.format("depress() %d", vk_key)); | 401 Log.i(TAG, String.format("depress() %d", vk_key)); |
392 Integer x = keymap.get(new Integer(vk_key)); | 402 Integer x = keymap.get(new Integer(vk_key)); |
403 | |
393 if (x != null) { | 404 if (x != null) { |
394 KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, x.intValue()); | 405 KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, x.intValue()); |
395 keyListener.onKey(view, event.getKeyCode(), event); | 406 keyListener.onKey(view, event.getKeyCode(), event); |
396 } | 407 } |
397 } | 408 } |