Mercurial > 510Connectbot
annotate app/src/main/java/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 528:0c031070b4ad default tip
fix vt320 delete area, incorrect parameter order
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 30 Aug 2024 12:41:52 -0600 |
parents | d6c107dedb04 |
children |
rev | line source |
---|---|
0 | 1 package com.five_ten_sg.connectbot.service; |
2 | |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
3 import android.app.ActivityManager; |
0 | 4 import android.content.ComponentName; |
5 import android.content.Context; | |
6 import android.content.Intent; | |
7 import android.content.ServiceConnection; | |
155 | 8 import android.net.Uri; |
0 | 9 import android.os.IBinder; |
10 import android.util.Log; | |
11 import android.view.View; | |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
12 import android.view.inputmethod.InputMethodManager; |
0 | 13 import de.mud.terminal.vt320; |
14 import java.io.IOException; | |
15 import java.io.InputStream; | |
16 import java.io.OutputStream; | |
17 import java.net.InetAddress; | |
18 import java.net.Socket; | |
19 import java.nio.charset.Charset; | |
252
932e34a11e9e
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
251
diff
changeset
|
20 import java.util.Arrays; |
0 | 21 import java.util.HashMap; |
15
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
22 import java.util.concurrent.ArrayBlockingQueue; |
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
23 import java.util.concurrent.BlockingQueue; |
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
24 import java.util.concurrent.ConcurrentHashMap; |
0 | 25 |
174
b010f9dc801f
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
173
diff
changeset
|
26 import com.five_ten_sg.connectbot.ConsoleActivity; |
b010f9dc801f
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
173
diff
changeset
|
27 import com.five_ten_sg.connectbot.bean.HostBean; |
b010f9dc801f
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
173
diff
changeset
|
28 |
0 | 29 public class TerminalMonitor { |
457
105815cce146
minimum version android 5, target and compile version api 28
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
30 public final static String TAG = "ConnectBot.TermMonitor"; |
0 | 31 |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
32 public static final char MONITOR_CMD_INIT = 0; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
33 public static final char MONITOR_CMD_ACTIVATE = 1; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
34 public static final char MONITOR_CMD_KEYSTATE = 2; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
35 public static final char MONITOR_CMD_CURSORMOVE = 3; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
36 public static final char MONITOR_CMD_SCREENCHANGE = 4; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
37 public static final char MONITOR_CMD_FIELDVALUE = 5; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
38 public static final char MONITOR_CMD_SETFIELD = 5; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
39 public static final char MONITOR_CMD_GETFIELD = 6; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
40 public static final char MONITOR_CMD_SCREENWATCH = 7; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
41 public static final char MONITOR_CMD_DEPRESS = 8; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
42 public static final char MONITOR_CMD_SHOWURL = 9; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
43 public static final char MONITOR_CMD_SWITCHSESSION = 10; |
205
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
44 public static final char MONITOR_CMD_CURSORREQUEST = 11; |
459
a3239022798d
compile 32 and 64 bit arch, bump version
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
45 public static final char MONITOR_CMD_SAYSTRING = 12; |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
46 public static final char MONITOR_CMD_SETFOCUS = 13; |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
47 public static final char MONITOR_CMD_KEYBOARD = 14; |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
48 public static final char MONITOR_CMD_DEPRESSUNICODE= 15; |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
49 public static final char MONITOR_CMD_FOREGROUND = 16; |
0 | 50 |
424
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
51 public static final String[] commands = { |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
52 "cmd_init", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
53 "cmd_activate", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
54 "cmd_keystate", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
55 "cmd_cursormove", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
56 "cmd_screenchange", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
57 "cmd_fieldvalue/setfield", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
58 "cmd_getfield", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
59 "cmd_screenwatch", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
60 "cmd_depress", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
61 "cmd_showurl", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
62 "cmd_switchsession", |
460
4776062555f3
compile 32 and 64 bit arch, bump version
Carl Byington <carl@five-ten-sg.com>
parents:
459
diff
changeset
|
63 "cmd_cursorrequest", |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
64 "cmd_saystring", |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
65 "cmd_setfocus", |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
66 "cmd_keyboard", |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
67 "cmd_depressunicode", |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
68 "cmd_foreground" |
424
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
69 }; |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
70 |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
71 public static final char CURSOR_REQUESTED = 0; |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
72 public static final char CURSOR_SCREEN_CHANGE = 1; |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
73 public static final char CURSOR_USER_KEY = 2; |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
74 |
0 | 75 private static final int MONITORPORT = 6000; |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
76 private static final int MONITORPORT2 = 6001; // protocol version 2 |
0 | 77 |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
78 private TerminalManager parent = null; |
0 | 79 private vt320 buffer = null; |
80 private View view = null; | |
174
b010f9dc801f
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
173
diff
changeset
|
81 private HostBean host = null; |
470
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
82 private Uri uri = null; |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
83 private int port = 0; |
470
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
84 private String target = null; |
0 | 85 private String init = null; |
506
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
86 private Watch[] watches = null; |
16
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
87 private boolean modified = false; // used to delay screen change notifications |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
88 private boolean moved = false; // used to delay cursor moved notifications |
16
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
89 private int to_line = 0; // "" |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
90 private int to_column = 0; // "" |
113
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
91 private HashMap<Integer, Integer> keymap = null; // map MS VK_ keys to vt320 virtual keys |
0 | 92 private IBinder bound = null; |
93 private Socket monitor_socket = null; | |
94 private InputStream monitor_in = null; | |
95 private OutputStream monitor_out = null; | |
96 private MyReader monitor_reader = null; | |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
97 private BlockingQueue<char[]> pending_commands = new ArrayBlockingQueue<char[]>(100); |
0 | 98 private MyServiceConnection monitor_connection = new MyServiceConnection(); |
99 | |
506
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
100 |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
101 private class Watch { |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
102 // monitor part of the screen for changes |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
103 private int start_line; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
104 private int end_line; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
105 private int start_column; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
106 private int end_column; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
107 public Watch(int l, int c, int len) { |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
108 Log.i(TAG, String.format("screenWatch(line %d, col %d, len %d)", l, c, len)); |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
109 this.start_line = l; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
110 this.end_line = l; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
111 this.start_column = c; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
112 this.end_column = c + len - 1; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
113 } |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
114 public boolean screenChanged(int llow, int lhigh, int clow, int chigh) { |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
115 return ((start_line <= lhigh) && |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
116 (llow <= end_line) && |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
117 (start_column <= chigh) && |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
118 (clow <= end_column)); |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
119 } |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
120 } |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
121 |
0 | 122 class MyReader extends Thread { |
123 private InputStream monitor_in; | |
124 private byte[] b; | |
125 private boolean is_closing = false; | |
126 | |
127 public MyReader(InputStream monitor_in) { | |
128 this.monitor_in = monitor_in; | |
129 b = new byte[100]; | |
130 Log.i(TAG, "MyReader constructor"); | |
131 } | |
132 | |
133 public void closing() { | |
134 is_closing = true; | |
135 } | |
136 | |
137 private char[] forceRead(int len) throws IOException { | |
138 int len2 = len * 2; | |
139 int off = 0; | |
140 | |
141 if (b.length < len2) b = new byte[len2]; | |
142 | |
143 while (off < len2) { | |
144 int l = monitor_in.read(b, off, len2 - off); | |
145 | |
146 if (l < 0) throw new IOException("eof"); | |
147 | |
148 off += l; | |
149 } | |
150 | |
151 return bytesToChars(b, len2); | |
152 } | |
153 | |
154 public void run() { | |
155 while (true) { | |
156 try { | |
157 char[] len = forceRead(1); | |
158 char[] packet = forceRead(len[0]); | |
159 char cmd = packet[0]; | |
508
d6c107dedb04
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
506
diff
changeset
|
160 Log.i(TAG, String.format("received %s length %d", commands[cmd], packet.length)); |
0 | 161 |
162 switch (cmd) { | |
163 case MONITOR_CMD_SETFIELD: | |
153
3ca280646f2d
allow zero length setfield
Carl Byington <carl@five-ten-sg.com>
parents:
148
diff
changeset
|
164 if (packet.length >= 3) |
0 | 165 setField(packet[1], packet[2], packet, 3); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
166 |
0 | 167 break; |
168 | |
169 case MONITOR_CMD_GETFIELD: | |
170 if (packet.length == 4) | |
171 getField(packet[1], packet[2], packet[3]); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
172 |
0 | 173 break; |
174 | |
175 case MONITOR_CMD_SCREENWATCH: | |
506
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
176 if (packet.length >= 4) { |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
177 int n = (packet.length - 1) / 3; |
508
d6c107dedb04
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
506
diff
changeset
|
178 Log.i(TAG, String.format("screen watch %d elements", n)); |
506
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
179 watches = new Watch[n]; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
180 for (int i=0; i<n; i++) { |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
181 int j = 1 + i*3; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
182 watches[i] = new Watch(packet[j], packet[j+1], packet[j+2]); |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
183 } |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
184 } |
0 | 185 break; |
186 | |
187 case MONITOR_CMD_DEPRESS: | |
188 if (packet.length == 2) | |
189 depress(packet[1]); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
190 |
0 | 191 break; |
192 | |
155 | 193 case MONITOR_CMD_SHOWURL: |
194 if (packet.length > 1) | |
195 showUrl(packet, 1); | |
196 | |
197 break; | |
198 | |
173
5f26d0ba6abd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
199 case MONITOR_CMD_SWITCHSESSION: |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
200 if (packet.length == 1) |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
201 switchSession(); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
202 |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
203 break; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
204 |
205
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
205 case MONITOR_CMD_CURSORREQUEST: |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
206 if (packet.length == 1) |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
207 cursorRequest(); |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
208 |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
209 break; |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
210 |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
211 case MONITOR_CMD_SETFOCUS: |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
212 if (packet.length == 3) |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
213 setFocus(packet[1], packet[2]); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
214 |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
215 break; |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
216 |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
217 case MONITOR_CMD_KEYBOARD: |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
218 if (packet.length == 2) |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
219 keyboard(packet[1]); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
220 |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
221 break; |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
222 |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
223 case MONITOR_CMD_DEPRESSUNICODE: |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
224 if (packet.length == 2) |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
225 depressunicode(packet[1]); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
226 |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
227 break; |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
228 |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
229 case MONITOR_CMD_FOREGROUND: |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
230 if (packet.length == 1) |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
231 foreground(); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
232 |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
233 break; |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
234 |
0 | 235 default: |
236 break; | |
237 } | |
238 } | |
239 catch (IOException e) { | |
240 if (!is_closing) Log.e(TAG, "exception in MyReader.run()", e); | |
241 | |
242 break; | |
243 } | |
244 } | |
245 } | |
246 } | |
247 | |
248 class MyServiceConnection implements ServiceConnection { | |
249 public void onServiceConnected(ComponentName className, IBinder service) { | |
250 bound = service; | |
251 Log.i(TAG, "bound to service"); | |
477
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
252 DoConnect(); |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
253 } |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
254 public void DoConnect() { |
0 | 255 try { |
470
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
256 InetAddress serverAddr = InetAddress.getByName(target); |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
257 int tries = 0; |
411
8bff0bfaec3a
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
410
diff
changeset
|
258 while (tries < 10) { |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
259 try { |
411
8bff0bfaec3a
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
410
diff
changeset
|
260 Thread.sleep(100); |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
261 monitor_socket = new Socket(serverAddr, port); |
421
660ac2d2003b
break out of infinite loop
Carl Byington <carl@five-ten-sg.com>
parents:
418
diff
changeset
|
262 break; |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
263 } |
412
057854c77217
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
411
diff
changeset
|
264 catch (Exception e) { |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
265 monitor_socket = null; |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
266 Log.e(TAG, "exception connecting to monitor socket", e); |
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
267 tries = tries + 1; |
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
268 } |
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
269 } |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
270 if (monitor_socket != null) { |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
271 Log.i(TAG, "connected to monitor socket, send init " + init); |
492
e88d48be89a8
add TCP_NODELAY to the monitor socket
Carl Byington <carl@five-ten-sg.com>
parents:
479
diff
changeset
|
272 monitor_socket.setTcpNoDelay(true); |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
273 monitor_in = monitor_socket.getInputStream(); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
274 monitor_out = monitor_socket.getOutputStream(); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
275 monitor_reader = new MyReader(monitor_in); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
276 monitor_reader.start(); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
277 String x = " " + init; |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
278 monitorWrite(MONITOR_CMD_INIT, x.toCharArray()); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
279 char [] c; |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
280 |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
281 while (true) { |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
282 c = pending_commands.poll(); |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
283 |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
284 if (c == null) break; |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
285 |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
286 monitorWrite(c[1], c); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
287 } |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
288 } |
0 | 289 } |
290 catch (IOException e) { | |
291 Log.e(TAG, "exception in onServiceConnected()", e); | |
292 } | |
293 } | |
294 public void onServiceDisconnected(ComponentName classNam) { | |
295 bound = null; | |
296 Log.i(TAG, "unbound from service"); | |
297 } | |
298 }; | |
299 | |
300 | |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
301 public TerminalMonitor(TerminalManager parent, vt320 buffer, View view, HostBean host, String url) { |
0 | 302 this.parent = parent; |
303 this.buffer = buffer; | |
304 this.view = view; | |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
305 this.host = host; |
470
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
306 this.uri = Uri.parse(url); |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
307 this.port = (uri.getScheme().equals("socket2")) ? MONITORPORT2 : MONITORPORT; |
470
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
308 this.target = uri.getHost(); |
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
309 this.init = uri.getPath(); |
0 | 310 // setup the windows->android keymapping |
19
b3d0d806cbe2
cleaner url for MS vk_ key documentation
Carl Byington <carl@five-ten-sg.com>
parents:
18
diff
changeset
|
311 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
312 keymap = new HashMap<Integer, Integer>(); |
113
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
313 keymap.put(0x08, vt320.KEY_BACK_SPACE); // vk_back |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
314 keymap.put(0x09, vt320.KEY_TAB); // vk_tab |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
315 keymap.put(0x0d, vt320.KEY_ENTER); // vk_return |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
316 keymap.put(0x1b, vt320.KEY_ESCAPE); // vk_escape |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
317 keymap.put(0x21, vt320.KEY_PAGE_UP); // vk_prior |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
318 keymap.put(0x22, vt320.KEY_PAGE_DOWN); // vk_next |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
319 keymap.put(0x23, vt320.KEY_END); // vk_end |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
320 keymap.put(0x24, vt320.KEY_HOME); // vk_home |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
321 keymap.put(0x25, vt320.KEY_LEFT); // vk_left |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
322 keymap.put(0x26, vt320.KEY_UP); // vk_up |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
323 keymap.put(0x27, vt320.KEY_RIGHT); // vk_right |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
324 keymap.put(0x28, vt320.KEY_DOWN); // vk_down |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
325 keymap.put(0x2d, vt320.KEY_INSERT); // vk_insert |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
326 keymap.put(0x2e, vt320.KEY_DELETE); // vk_delete |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
327 keymap.put(0x70, vt320.KEY_F1); // vk_f1 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
328 keymap.put(0x71, vt320.KEY_F2); // vk_f2 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
329 keymap.put(0x72, vt320.KEY_F3); // vk_f3 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
330 keymap.put(0x73, vt320.KEY_F4); // vk_f4 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
331 keymap.put(0x74, vt320.KEY_F5); // vk_f5 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
332 keymap.put(0x75, vt320.KEY_F6); // vk_f6 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
333 keymap.put(0x76, vt320.KEY_F7); // vk_f7 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
334 keymap.put(0x77, vt320.KEY_F8); // vk_f8 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
335 keymap.put(0x78, vt320.KEY_F9); // vk_f9 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
336 keymap.put(0x79, vt320.KEY_F10); // vk_f10 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
337 keymap.put(0x7a, vt320.KEY_F11); // vk_f11 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
338 keymap.put(0x7b, vt320.KEY_F12); // vk_f12 |
176 | 339 keymap.put(0x7c, vt320.KEY_F13); // vk_f13 |
340 keymap.put(0x7d, vt320.KEY_F14); // vk_f14 | |
341 keymap.put(0x7e, vt320.KEY_F15); // vk_f15 | |
342 keymap.put(0x7f, vt320.KEY_F16); // vk_f16 | |
343 keymap.put(0x80, vt320.KEY_F17); // vk_f17 | |
344 keymap.put(0x81, vt320.KEY_F18); // vk_f18 | |
345 keymap.put(0x82, vt320.KEY_F19); // vk_f19 | |
346 keymap.put(0x83, vt320.KEY_F20); // vk_f20 | |
347 keymap.put(0x84, vt320.KEY_F21); // vk_f21 | |
348 keymap.put(0x85, vt320.KEY_F22); // vk_f22 | |
349 keymap.put(0x86, vt320.KEY_F23); // vk_f23 | |
350 keymap.put(0x87, vt320.KEY_F24); // vk_f24 | |
479
3a83f40439d7
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
477
diff
changeset
|
351 if (target.equals("localhost")) { |
477
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
352 // bind to the monitor service for localhost connections |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
353 Intent intent = new Intent("com.five_ten_sg.connectbot.monitor.MonitorService"); |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
354 intent.setPackage("com.five_ten_sg.connectbot.monitor"); |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
355 parent.bindService(intent, monitor_connection, Context.BIND_AUTO_CREATE); |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
356 } |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
357 else { |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
358 // direct socket connection to external device |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
359 monitor_connection.DoConnect(); |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
360 } |
0 | 361 Log.i(TAG, "constructor"); |
362 } | |
363 | |
364 | |
365 public void Disconnect() { | |
366 if (monitor_reader != null) monitor_reader.closing(); | |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
367 |
0 | 368 try { |
369 if (monitor_out != null) monitor_out.close(); | |
370 | |
371 if (monitor_in != null) monitor_in.close(); | |
372 | |
373 if (monitor_socket != null) monitor_socket.close(); | |
374 | |
375 Log.i(TAG, "disconnected from monitor socket"); | |
376 } | |
377 catch (IOException e) { | |
378 Log.e(TAG, "exception in Disconnect() closing sockets", e); | |
379 } | |
380 | |
381 monitor_reader = null; | |
382 monitor_out = null; | |
383 monitor_in = null; | |
384 monitor_socket = null; | |
385 | |
386 if (bound != null) parent.unbindService(monitor_connection); | |
387 | |
388 monitor_connection = null; | |
389 } | |
390 | |
391 | |
392 public char[] bytesToChars(byte[] b, int len) { | |
393 char[] c = new char[len >> 1]; | |
394 int bp = 0; | |
395 | |
396 for (int i = 0; i < c.length; i++) { | |
397 byte b1 = b[bp++]; | |
398 byte b2 = b[bp++]; | |
399 c[i] = (char)(((b1 & 0x00FF) << 8) + (b2 & 0x00FF)); | |
400 } | |
401 | |
402 return c; | |
403 } | |
404 | |
405 | |
406 public byte[] charsToBytes(char[] c) { | |
407 byte[] b = new byte[c.length << 1]; | |
408 int bp = 0; | |
409 | |
410 for (int i = 0; i < c.length; i++) { | |
411 b[bp++] = (byte)((c[i] & 0xff00) >> 8); | |
412 b[bp++] = (byte)(c[i] & 0x00ff); | |
413 } | |
414 | |
415 return b; | |
416 } | |
417 | |
418 | |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
419 public synchronized void monitorWrite(char cmd, char[] c) { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
420 try { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
421 if (monitor_out != null) { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
422 c[0] = (char)(c.length - 1); // number of chars following |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
423 c[1] = cmd; |
424
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
424 Log.i(TAG, String.format("sending %s", commands[cmd])); |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
425 monitor_out.write(charsToBytes(c)); |
424
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
426 monitor_out.flush(); |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
427 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
428 else { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
429 c[1] = cmd; |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
430 pending_commands.offer(c); |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
431 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
432 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
433 catch (IOException e) { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
434 Log.i(TAG, "exception in monitorWrite(), monitor died or closed the socket", e); |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
435 |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
436 try { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
437 monitor_out.close(); |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
438 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
439 catch (IOException ee) { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
440 Log.e(TAG, "exception in monitorWrite() closing output stream", ee); |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
441 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
442 |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
443 monitor_out = null; |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
444 } |
0 | 445 }; |
446 | |
227
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents:
212
diff
changeset
|
447 public void resetWatch() { |
506
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
448 watches = null; |
227
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents:
212
diff
changeset
|
449 }; |
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents:
212
diff
changeset
|
450 |
0 | 451 public void sendScreen(char cmd) { |
452 char lines = (char)(buffer.height & 0x0000ffff); | |
453 char columns = (char)(buffer.width & 0x0000ffff); | |
454 char[] arg = new char[4 + lines * columns]; | |
455 arg[2] = lines; | |
456 arg[3] = columns; | |
457 int base = 4; | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
458 |
0 | 459 for (int i = 0; i < lines; i++) { |
460 System.arraycopy(buffer.charArray[buffer.screenBase + i], 0, arg, base, columns); | |
461 base += columns; | |
462 } | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
463 |
0 | 464 monitorWrite(cmd, arg); |
227
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents:
212
diff
changeset
|
465 resetWatch(); |
0 | 466 } |
467 | |
468 public synchronized void activate() { | |
469 sendScreen(MONITOR_CMD_ACTIVATE); | |
235
ea49747c5447
activate needs to send a cursor update
Carl Byington <carl@five-ten-sg.com>
parents:
229
diff
changeset
|
470 cursorMoved(CURSOR_SCREEN_CHANGE); |
0 | 471 } |
472 | |
148
69333ca1563c
add ptt button p2 preference
Carl Byington <carl@five-ten-sg.com>
parents:
147
diff
changeset
|
473 public synchronized void keyState(boolean down) { |
0 | 474 char[] arg = new char[3]; |
148
69333ca1563c
add ptt button p2 preference
Carl Byington <carl@five-ten-sg.com>
parents:
147
diff
changeset
|
475 arg[2] = (char)((down) ? 1 : 0); |
147
1350adb077b1
monitor key state tracking
Carl Byington <carl@five-ten-sg.com>
parents:
145
diff
changeset
|
476 monitorWrite(MONITOR_CMD_KEYSTATE, arg); |
0 | 477 } |
478 | |
479 public synchronized void cursorMove(int l, int c) { | |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
480 if ((to_line != l) || (to_column != c)) moved = true; |
307 | 481 |
17
02717d15de9b
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
482 to_line = l; |
16
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
483 to_column = c; |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
484 } |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
485 |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
486 public void cursorMoved(char why) { |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
487 char[] arg = new char[5]; |
18
49fc5fba28f3
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
17
diff
changeset
|
488 arg[2] = (char)(to_line & 0x0000ffff); |
49fc5fba28f3
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
17
diff
changeset
|
489 arg[3] = (char)(to_column & 0x0000ffff); |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
490 arg[4] = why; |
0 | 491 monitorWrite(MONITOR_CMD_CURSORMOVE, arg); |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
492 moved = false; |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
493 } |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
494 |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
495 public void testMoved() { |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
496 if (moved) cursorMoved(CURSOR_USER_KEY); |
0 | 497 } |
498 | |
499 public synchronized void testChanged() { | |
500 if (modified) { | |
501 modified = false; | |
502 sendScreen(MONITOR_CMD_SCREENCHANGE); | |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
503 cursorMoved(CURSOR_SCREEN_CHANGE); |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
504 } |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
505 else { |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
506 if (moved) cursorMoved(CURSOR_SCREEN_CHANGE); |
16
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
507 } |
0 | 508 } |
509 | |
510 public synchronized void screenChanged(int llow, int lhigh, int clow, int chigh) { | |
506
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
511 if (watches == null) { |
0 | 512 modified = true; |
506
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
513 return; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
514 } |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
515 for (Watch w : watches) { |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
516 if (w.screenChanged(llow, lhigh, clow, chigh)) { |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
517 modified = true; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
518 return; |
b8cc360e1550
allow multiple screen watch areas
Carl Byington <carl@five-ten-sg.com>
parents:
496
diff
changeset
|
519 } |
0 | 520 } |
521 } | |
522 | |
523 public synchronized void screenChanged(int l, int c) { | |
524 screenChanged(l, l, c, c); | |
525 } | |
526 | |
527 public synchronized void setField(int l, int c, char[] data, int offset) { | |
250
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
528 int len = data.length - offset; |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
529 char[] da = new char[len]; |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
530 System.arraycopy(data, offset, da, 0, len); |
422
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
531 Log.i(TAG, String.format("setField(line %d, col %d, value %s)", l, c, new String(da))); |
307 | 532 |
250
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
533 if ((l > 60000) || (c > 60000)) { |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
534 l = -1; |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
535 c = -1; |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
536 } |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
537 else { |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
538 // ignore setfield outside screen boundaries |
405
d3c5480e8441
fix broken fillRegenerationBuffer/fillScreenArray attempt to handle missing attributes; fix setfield outside screen boundaries
Carl Byington <carl@five-ten-sg.com>
parents:
404
diff
changeset
|
539 if ((l >= buffer.height) || (c + len > buffer.width)) return; |
250
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
540 } |
307 | 541 |
100 | 542 buffer.setField(l, c, da); |
0 | 543 } |
544 | |
155 | 545 public synchronized void showUrl(char [] data, int offset) { |
546 char[] da = new char[data.length - offset]; | |
307 | 547 System.arraycopy(data, offset, da, 0, data.length - offset); |
155 | 548 String url = new String(da); |
549 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | |
550 parent.startActivity(intent); | |
551 } | |
552 | |
0 | 553 public synchronized void getField(int l, int c, int len) { |
422
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
554 Log.i(TAG, String.format("getField(line %d, col %d, len %d)", l, c, len)); |
0 | 555 char[] arg2 = new char[4 + len]; |
556 arg2[2] = (char)(l & 0x0000ffff); | |
557 arg2[3] = (char)(c & 0x0000ffff); | |
558 int base = 4; | |
307 | 559 |
404
ec74f347ab5f
fix bad args to arrays.fill(); bump version number
Carl Byington <carl@five-ten-sg.com>
parents:
402
diff
changeset
|
560 if ((l >= buffer.height) || (c + len > buffer.width)) { |
ec74f347ab5f
fix bad args to arrays.fill(); bump version number
Carl Byington <carl@five-ten-sg.com>
parents:
402
diff
changeset
|
561 Arrays.fill(arg2, base, base + len, ' '); |
250
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
562 } |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
563 else { |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
564 System.arraycopy(buffer.charArray[buffer.screenBase + l], c, arg2, base, len); |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
565 } |
307 | 566 |
422
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
567 char[] da = new char[len]; |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
568 System.arraycopy(arg2, base, da, 0, len); |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
569 Log.i(TAG, String.format("getField value %s", new String(da))); |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
570 |
0 | 571 monitorWrite(MONITOR_CMD_FIELDVALUE, arg2); |
572 } | |
573 | |
574 public synchronized void depress(int vk_key) { | |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
575 Log.i(TAG, String.format("depress(%04x)", vk_key)); |
0 | 576 Integer x = keymap.get(new Integer(vk_key)); |
307 | 577 |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
578 if (x != null) buffer.keyDepressed(x); |
0 | 579 } |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
580 |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
581 public synchronized void switchSession() { |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
582 Log.i(TAG, "switchSession()"); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
583 Intent intent = new Intent(parent, ConsoleActivity.class); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
584 intent.setAction(Intent.ACTION_VIEW); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
585 intent.setData(host.getUri()); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
586 parent.startActivity(intent); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
587 } |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
588 |
205
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
589 |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
590 public synchronized void cursorRequest() { |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
591 cursorMoved(CURSOR_REQUESTED); |
205
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
592 } |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
593 |
496
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
594 public synchronized void setFocus(int l, int c) { |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
595 buffer.setField(l, c, new char[0]); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
596 } |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
597 |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
598 public synchronized void keyboard(int show) { |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
599 InputMethodManager inputMethodManager = (InputMethodManager)parent.getSystemService(Context.INPUT_METHOD_SERVICE); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
600 View view = parent.activity.getCurrentView(); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
601 if (view == null) return; |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
602 if (show != 0) { |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
603 inputMethodManager.showSoftInput(view, 0); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
604 } else { |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
605 inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
606 } |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
607 } |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
608 |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
609 public synchronized void depressunicode(int ascii) { |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
610 Log.i(TAG, String.format("depressunicode(%04x)", ascii)); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
611 buffer.keyUnicodeDepressed(ascii); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
612 } |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
613 |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
614 public synchronized void foreground() { |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
615 ActivityManager activityManager = (ActivityManager) parent.getSystemService(Context.ACTIVITY_SERVICE); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
616 activityManager.moveTaskToFront(parent.activity.getTaskId(), 0); |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
617 } |
f698820bffdf
add socket2 monitor protocol
Carl Byington <carl@five-ten-sg.com>
parents:
492
diff
changeset
|
618 |
0 | 619 } |