Mercurial > 510Connectbot
annotate app/src/main/java/com/five_ten_sg/connectbot/service/TerminalBridge.java @ 470:2cc170e3fc9b stable-1.9.3-8
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 04 Oct 2019 16:44:44 -0700 |
parents | 105815cce146 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * ConnectBot: simple, powerful, open-source SSH client for Android | |
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey | |
4 * | |
5 * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 * you may not use this file except in compliance with the License. | |
7 * You may obtain a copy of the License at | |
8 * | |
9 * http://www.apache.org/licenses/LICENSE-2.0 | |
10 * | |
11 * Unless required by applicable law or agreed to in writing, software | |
12 * distributed under the License is distributed on an "AS IS" BASIS, | |
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 * See the License for the specific language governing permissions and | |
15 * limitations under the License. | |
16 */ | |
17 | |
18 package com.five_ten_sg.connectbot.service; | |
19 | |
20 import java.io.File; | |
21 import java.io.FileOutputStream; | |
22 import java.io.IOException; | |
23 import java.nio.charset.Charset; | |
24 import java.text.SimpleDateFormat; | |
25 import java.util.Date; | |
178 | 26 import java.util.HashMap; |
0 | 27 import java.util.LinkedHashSet; |
28 import java.util.LinkedList; | |
29 import java.util.List; | |
30 import java.util.Set; | |
31 import java.util.regex.Matcher; | |
32 import java.util.regex.Pattern; | |
33 | |
34 import com.five_ten_sg.connectbot.R; | |
35 import com.five_ten_sg.connectbot.TerminalView; | |
36 import com.five_ten_sg.connectbot.bean.HostBean; | |
37 import com.five_ten_sg.connectbot.bean.PortForwardBean; | |
38 import com.five_ten_sg.connectbot.bean.SelectionArea; | |
39 import com.five_ten_sg.connectbot.transport.AbsTransport; | |
40 import com.five_ten_sg.connectbot.transport.TransportFactory; | |
41 import com.five_ten_sg.connectbot.util.HostDatabase; | |
42 import com.five_ten_sg.connectbot.util.PreferenceConstants; | |
223
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
43 import com.five_ten_sg.connectbot.util.StringPickerDialog; |
0 | 44 import android.app.AlertDialog; |
45 import android.content.Context; | |
46 import android.graphics.Bitmap; | |
47 import android.graphics.Bitmap.Config; | |
48 import android.graphics.Canvas; | |
49 import android.graphics.Color; | |
50 import android.graphics.Paint; | |
51 import android.graphics.Paint.FontMetrics; | |
52 import android.graphics.Typeface; | |
53 import android.os.Binder; | |
54 import android.os.Environment; | |
55 import android.text.ClipboardManager; | |
56 import android.text.Editable; | |
57 import android.text.method.CharacterPickerDialog; | |
58 import android.util.Log; | |
59 import android.view.KeyEvent; | |
60 import android.view.View; | |
61 import android.widget.AdapterView; | |
62 import android.widget.Button; | |
63 import de.mud.terminal.VDUBuffer; | |
64 import de.mud.terminal.VDUDisplay; | |
65 import de.mud.terminal.vt320; | |
66 | |
67 | |
68 /** | |
69 * Provides a bridge between a MUD terminal buffer and a possible TerminalView. | |
70 * This separation allows us to keep the TerminalBridge running in a background | |
71 * service. A TerminalView shares down a bitmap that we can use for rendering | |
72 * when available. | |
73 * | |
74 * This class also provides SSH hostkey verification prompting, and password | |
75 * prompting. | |
76 */ | |
77 @SuppressWarnings("deprecation") // for ClipboardManager | |
78 public class TerminalBridge implements VDUDisplay { | |
79 public final static String TAG = "ConnectBot.TerminalBridge"; | |
80 | |
189
ab6f64d1a24a
use floating point font size, change size by scaling factor rather than linear addition
Carl Byington <carl@five-ten-sg.com>
parents:
188
diff
changeset
|
81 private final static float FONT_SIZE_FACTOR = 1.1f; |
0 | 82 |
83 public Integer[] color; | |
84 | |
85 public int defaultFg = HostDatabase.DEFAULT_FG_COLOR; | |
86 public int defaultBg = HostDatabase.DEFAULT_BG_COLOR; | |
87 | |
88 protected final TerminalManager manager; | |
95
e1c43d50f9d8
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
94
diff
changeset
|
89 public final HostBean host; |
e1c43d50f9d8
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
94
diff
changeset
|
90 public final String homeDirectory; |
0 | 91 |
92 AbsTransport transport; | |
93 | |
94 final Paint defaultPaint; | |
95 | |
96 private Relay relay; | |
97 | |
67
99d5b02ad90c
allow host override terminal type
Carl Byington <carl@five-ten-sg.com>
parents:
66
diff
changeset
|
98 private String emulation; // aka answerback string, aka terminal type |
0 | 99 |
100 public Bitmap bitmap = null; | |
101 public vt320 buffer = null; | |
102 | |
47
a3fd10a8c0de
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
45
diff
changeset
|
103 public TerminalView parent = null; |
0 | 104 private final Canvas canvas = new Canvas(); |
105 | |
106 private boolean disconnected = false; | |
107 private boolean awaitingClose = false; | |
108 | |
109 private boolean forcedSize = false; | |
110 private int columns; | |
111 private int rows; | |
112 | |
113 public TerminalMonitor monitor = null; | |
114 private TerminalKeyListener keyListener = null; | |
115 | |
116 private boolean selectingForCopy = false; | |
117 private final SelectionArea selectionArea; | |
118 | |
119 // TODO add support for the new clipboard API | |
120 private ClipboardManager clipboard; | |
121 | |
42
7ac846a07ed4
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
40
diff
changeset
|
122 public int charWidth = -1; |
7ac846a07ed4
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
40
diff
changeset
|
123 public int charHeight = -1; |
7ac846a07ed4
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
40
diff
changeset
|
124 private int charTop = -1; |
248
0181323d0d33
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
247
diff
changeset
|
125 private float fontSize = -1; |
0 | 126 |
127 private final List<FontSizeChangedListener> fontSizeChangedListeners; | |
128 | |
129 private final List<String> localOutput; | |
130 | |
131 /** | |
132 * Flag indicating if we should perform a full-screen redraw during our next | |
133 * rendering pass. | |
134 */ | |
135 private boolean fullRedraw = false; | |
136 | |
137 public PromptHelper promptHelper; | |
138 | |
139 protected BridgeDisconnectedListener disconnectListener = null; | |
140 | |
141 /** | |
142 * Create a new terminal bridge suitable for unit testing. | |
143 */ | |
144 public TerminalBridge() { | |
145 buffer = new vt320() { | |
146 @Override | |
147 public void write(byte[] b) {} | |
148 @Override | |
149 public void write(int b) {} | |
150 @Override | |
151 public void sendTelnetCommand(byte cmd) {} | |
152 @Override | |
153 public void setWindowSize(int c, int r) {} | |
154 @Override | |
155 public void debug(String s) {} | |
156 }; | |
95
e1c43d50f9d8
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
94
diff
changeset
|
157 emulation = null; |
e1c43d50f9d8
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
94
diff
changeset
|
158 manager = null; |
e1c43d50f9d8
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
94
diff
changeset
|
159 host = null; |
e1c43d50f9d8
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
94
diff
changeset
|
160 homeDirectory = null; |
e1c43d50f9d8
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
94
diff
changeset
|
161 defaultPaint = new Paint(); |
0 | 162 selectionArea = new SelectionArea(); |
95
e1c43d50f9d8
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
94
diff
changeset
|
163 localOutput = new LinkedList<String>(); |
0 | 164 fontSizeChangedListeners = new LinkedList<FontSizeChangedListener>(); |
165 transport = null; | |
166 keyListener = new TerminalKeyListener(manager, this, buffer, null); | |
167 monitor = null; | |
168 } | |
169 | |
170 /** | |
42
7ac846a07ed4
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
40
diff
changeset
|
171 * Create new terminal bridge with following parameters. |
0 | 172 */ |
94
e3b83c4f02f1
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
173 public TerminalBridge(final TerminalManager manager, final HostBean host, final String homeDirectory) throws IOException { |
e3b83c4f02f1
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
174 this.manager = manager; |
e3b83c4f02f1
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
175 this.host = host; |
e3b83c4f02f1
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
176 this.homeDirectory = homeDirectory; |
66
cb99bc2964c5
allow host override terminal type
Carl Byington <carl@five-ten-sg.com>
parents:
65
diff
changeset
|
177 emulation = host.getHostEmulation(); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
95
diff
changeset
|
178 |
65
9a6335a203b2
allow host override terminal type
Carl Byington <carl@five-ten-sg.com>
parents:
59
diff
changeset
|
179 if ((emulation == null) || (emulation.length() == 0)) emulation = manager.getEmulation(); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
95
diff
changeset
|
180 |
0 | 181 // create prompt helper to relay password and hostkey requests up to gui |
182 promptHelper = new PromptHelper(this); | |
183 // create our default paint | |
184 defaultPaint = new Paint(); | |
185 defaultPaint.setAntiAlias(true); | |
186 defaultPaint.setTypeface(Typeface.MONOSPACE); | |
187 defaultPaint.setFakeBoldText(true); // more readable? | |
188 localOutput = new LinkedList<String>(); | |
189 fontSizeChangedListeners = new LinkedList<FontSizeChangedListener>(); | |
245
23119f3c0d28
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
244
diff
changeset
|
190 setMyFontSize(); |
0 | 191 resetColors(); |
192 selectionArea = new SelectionArea(); | |
193 } | |
194 | |
195 public PromptHelper getPromptHelper() { | |
196 return promptHelper; | |
197 } | |
198 | |
199 /** | |
200 * Spawn thread to open connection and start login process. | |
201 */ | |
202 protected void startConnection() { | |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
203 transport = TransportFactory.getTransport(host.getProtocol()); |
94
e3b83c4f02f1
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
204 transport.setLinks(manager, this, homeDirectory, host, emulation); |
42
7ac846a07ed4
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
40
diff
changeset
|
205 buffer = transport.getTransportBuffer(); |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
29
diff
changeset
|
206 keyListener = transport.getTerminalKeyListener(); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
95
diff
changeset
|
207 String monitor_init = host.getMonitor(); |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
208 |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
209 if ((monitor_init != null) && (monitor_init.length() > 0)) { |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
113
diff
changeset
|
210 monitor = new TerminalMonitor(manager, buffer, parent, host, monitor_init); |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
211 } |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
212 |
0 | 213 transport.setCompression(host.getCompression()); |
214 transport.setHttpproxy(host.getHttpproxy()); | |
215 transport.setUseAuthAgent(host.getUseAuthAgent()); | |
216 | |
217 if (transport.canForwardPorts()) { | |
218 for (PortForwardBean portForward : manager.hostdb.getPortForwardsForHost(host)) | |
219 transport.addPortForward(portForward); | |
220 } | |
221 | |
222 outputLine(manager.res.getString(R.string.terminal_connecting, host.getHostname(), host.getPort(), host.getProtocol())); | |
223 Thread connectionThread = new Thread(new Runnable() { | |
224 public void run() { | |
225 transport.connect(); | |
226 } | |
227 }); | |
228 connectionThread.setName("Connection"); | |
229 connectionThread.setDaemon(true); | |
230 connectionThread.start(); | |
231 } | |
232 | |
233 /** | |
234 * Handle challenges from keyboard-interactive authentication mode. | |
235 */ | |
236 public String[] replyToChallenge(String name, String instruction, int numPrompts, String[] prompt, boolean[] echo) { | |
237 String[] responses = new String[numPrompts]; | |
238 | |
239 for (int i = 0; i < numPrompts; i++) { | |
240 // request response from user for each prompt | |
241 responses[i] = promptHelper.requestPasswordPrompt(instruction, prompt[i]); | |
242 } | |
243 | |
244 return responses; | |
245 } | |
246 | |
247 /** | |
248 * @return charset in use by bridge | |
249 */ | |
250 public Charset getCharset() { | |
42
7ac846a07ed4
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
40
diff
changeset
|
251 if (relay != null) return relay.getCharset(); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
95
diff
changeset
|
252 |
45
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
42
diff
changeset
|
253 return keyListener.getCharset(); |
0 | 254 } |
255 | |
256 /** | |
257 * Sets the encoding used by the terminal. If the connection is live, | |
258 * then the character set is changed for the next read. | |
259 * @param encoding the canonical name of the character encoding | |
260 */ | |
261 public void setCharset(String encoding) { | |
42
7ac846a07ed4
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
40
diff
changeset
|
262 if (relay != null) relay.setCharset(encoding); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
95
diff
changeset
|
263 |
0 | 264 keyListener.setCharset(encoding); |
265 } | |
266 | |
267 /** | |
268 * Convenience method for writing a line into the underlying MUD buffer. | |
269 * Should never be called once the session is established. | |
270 */ | |
271 public final void outputLine(String line) { | |
272 if (transport != null && transport.isSessionOpen()) | |
273 Log.e(TAG, "Session established, cannot use outputLine!", new IOException("outputLine call traceback")); | |
274 | |
275 synchronized (localOutput) { | |
276 final String s = line + "\r\n"; | |
277 localOutput.add(s); | |
278 buffer.putString(s); | |
279 // For accessibility | |
280 final char[] charArray = s.toCharArray(); | |
281 propagateConsoleText(charArray, charArray.length); | |
282 } | |
283 } | |
284 | |
285 /** | |
286 * Inject a specific string into this terminal. Used for post-login strings | |
287 * and pasting clipboard. | |
288 */ | |
289 public void injectString(final String string) { | |
290 if (string == null || string.length() == 0) | |
291 return; | |
292 | |
293 Thread injectStringThread = new Thread(new Runnable() { | |
294 public void run() { | |
295 try { | |
296 transport.write(string.getBytes(host.getEncoding())); | |
297 } | |
298 catch (Exception e) { | |
299 Log.e(TAG, "Couldn't inject string to remote host: ", e); | |
300 } | |
301 } | |
302 }); | |
303 injectStringThread.setName("InjectString"); | |
304 injectStringThread.start(); | |
305 } | |
306 | |
307 /** | |
308 * Internal method to request actual PTY terminal once we've finished | |
309 * authentication. If called before authenticated, it will just fail. | |
310 */ | |
311 public void onConnected() { | |
312 disconnected = false; | |
313 buffer.reset(); | |
314 buffer.setAnswerBack(emulation); | |
42
7ac846a07ed4
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
40
diff
changeset
|
315 localOutput.clear(); // We no longer need our local output. |
0 | 316 |
317 if (HostDatabase.DELKEY_BACKSPACE.equals(host.getDelKey())) | |
318 buffer.setBackspace(vt320.DELETE_IS_BACKSPACE); | |
319 else | |
320 buffer.setBackspace(vt320.DELETE_IS_DEL); | |
321 | |
322 // create thread to relay incoming connection data to buffer | |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
323 // only if needed by the transport |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
324 if (transport.needsRelay()) { |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
325 relay = new Relay(this, transport, buffer, host.getEncoding()); |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
326 Thread relayThread = new Thread(relay); |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
327 relayThread.setDaemon(true); |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
328 relayThread.setName("Relay"); |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
329 relayThread.start(); |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
330 } |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
331 |
244
32737a428805
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
231
diff
changeset
|
332 // get proper font size |
245
23119f3c0d28
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
244
diff
changeset
|
333 setMyFontSize(); |
23119f3c0d28
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
244
diff
changeset
|
334 // finally send any post-login string, if requested |
23119f3c0d28
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
244
diff
changeset
|
335 injectString(host.getPostLogin()); |
23119f3c0d28
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
244
diff
changeset
|
336 } |
23119f3c0d28
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
244
diff
changeset
|
337 |
246
dfe5f44bbea1
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
245
diff
changeset
|
338 private void setMyFontSize() { |
245
23119f3c0d28
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
244
diff
changeset
|
339 if ((parent != null) && (host.getFixedSize())) { |
23119f3c0d28
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
244
diff
changeset
|
340 resizeComputed(host.getFixedWidth(), host.getFixedHeight(), parent.getWidth(), parent.getHeight()); |
244
32737a428805
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
231
diff
changeset
|
341 } |
32737a428805
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
231
diff
changeset
|
342 else { |
32737a428805
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
231
diff
changeset
|
343 setFontSize(host.getFontSize()); |
32737a428805
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
231
diff
changeset
|
344 } |
0 | 345 } |
346 | |
347 /** | |
348 * @return whether a session is open or not | |
349 */ | |
350 public boolean isSessionOpen() { | |
351 if (transport != null) return transport.isSessionOpen(); | |
352 | |
353 return false; | |
354 } | |
355 | |
356 public void setOnDisconnectedListener(BridgeDisconnectedListener disconnectListener) { | |
357 this.disconnectListener = disconnectListener; | |
358 } | |
359 | |
360 /** | |
361 * Force disconnection of this terminal bridge. | |
362 */ | |
363 public void dispatchDisconnect(boolean immediate) { | |
364 // We don't need to do this multiple times. | |
365 synchronized (this) { | |
366 if (disconnected && !immediate) return; | |
367 | |
368 disconnected = true; | |
369 } | |
370 | |
371 // Cancel any pending prompts. | |
372 promptHelper.cancelPrompt(); | |
373 // disconnection request hangs if we havent really connected to a host yet | |
374 // temporary fix is to just spawn disconnection into a thread | |
375 Thread disconnectThread = new Thread(new Runnable() { | |
376 public void run() { | |
377 if (transport != null && transport.isConnected()) | |
378 transport.close(); | |
379 } | |
380 }); | |
381 disconnectThread.setName("Disconnect"); | |
382 disconnectThread.start(); | |
383 | |
384 if (immediate) { | |
385 awaitingClose = true; | |
386 | |
387 if (disconnectListener != null) | |
388 disconnectListener.onDisconnected(TerminalBridge.this); | |
389 } | |
390 else { | |
391 final String line = manager.res.getString(R.string.alert_disconnect_msg); | |
392 buffer.putString("\r\n" + line + "\r\n"); | |
393 | |
394 if (host.getStayConnected()) { | |
395 manager.requestReconnect(this); | |
396 return; | |
397 } | |
398 | |
399 Thread disconnectPromptThread = new Thread(new Runnable() { | |
400 public void run() { | |
401 Boolean result = promptHelper.requestBooleanPrompt(null, | |
402 manager.res.getString(R.string.prompt_host_disconnected)); | |
403 | |
404 if (result == null || result.booleanValue()) { | |
405 awaitingClose = true; | |
406 | |
407 // Tell the TerminalManager that we can be destroyed now. | |
408 if (disconnectListener != null) | |
409 disconnectListener.onDisconnected(TerminalBridge.this); | |
410 } | |
411 } | |
412 }); | |
413 disconnectPromptThread.setName("DisconnectPrompt"); | |
414 disconnectPromptThread.setDaemon(true); | |
415 disconnectPromptThread.start(); | |
416 } | |
417 | |
418 // close the monitor | |
419 if (monitor != null) monitor.Disconnect(); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
95
diff
changeset
|
420 |
0 | 421 monitor = null; |
422 } | |
423 | |
424 public void setSelectingForCopy(boolean selectingForCopy) { | |
425 this.selectingForCopy = selectingForCopy; | |
426 } | |
427 | |
428 public boolean isSelectingForCopy() { | |
429 return selectingForCopy; | |
430 } | |
431 | |
432 public SelectionArea getSelectionArea() { | |
433 return selectionArea; | |
434 } | |
435 | |
436 public synchronized void tryKeyVibrate() { | |
437 manager.tryKeyVibrate(); | |
438 } | |
439 | |
440 /** | |
441 * Request a different font size. Will make call to parentChanged() to make | |
442 * sure we resize PTY if needed. | |
443 */ | |
191
2e4ab8c33851
use floating point font size, change size by scaling factor rather than linear addition
Carl Byington <carl@five-ten-sg.com>
parents:
190
diff
changeset
|
444 final void setFontSize(float size) { |
245
23119f3c0d28
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
244
diff
changeset
|
445 if (size <= 0.0) size = 12.0f; |
307 | 446 |
191
2e4ab8c33851
use floating point font size, change size by scaling factor rather than linear addition
Carl Byington <carl@five-ten-sg.com>
parents:
190
diff
changeset
|
447 size = (float)(int)((size * 10.0f) + 0.5f) / 10.0f; |
0 | 448 defaultPaint.setTextSize(size); |
248
0181323d0d33
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
247
diff
changeset
|
449 fontSize = size; |
0 | 450 // read new metrics to get exact pixel dimensions |
451 FontMetrics fm = defaultPaint.getFontMetrics(); | |
457
105815cce146
minimum version android 5, target and compile version api 28
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
452 charTop = (int)Math.ceil(fm.top); |
0 | 453 float[] widths = new float[1]; |
454 defaultPaint.getTextWidths("X", widths); | |
457
105815cce146
minimum version android 5, target and compile version api 28
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
455 charWidth = (int)Math.ceil(widths[0]); |
105815cce146
minimum version android 5, target and compile version api 28
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
456 charHeight = (int)Math.ceil(fm.descent - fm.top); |
0 | 457 |
458 // refresh any bitmap with new font size | |
47
a3fd10a8c0de
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
45
diff
changeset
|
459 if (parent != null) parentChanged(parent); |
0 | 460 |
422
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
461 synchronized(fontSizeChangedListeners) { |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
462 for (FontSizeChangedListener ofscl : fontSizeChangedListeners) |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
463 ofscl.onFontSizeChanged(size); |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
464 } |
0 | 465 |
247
1e1bb5468ebe
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
246
diff
changeset
|
466 host.setFontSize(size); |
0 | 467 manager.hostdb.updateFontSize(host); |
468 } | |
469 | |
470 /** | |
471 * Add an {@link FontSizeChangedListener} to the list of listeners for this | |
472 * bridge. | |
473 * | |
474 * @param listener | |
475 * listener to add | |
476 */ | |
477 public void addFontSizeChangedListener(FontSizeChangedListener listener) { | |
422
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
478 synchronized(fontSizeChangedListeners) { |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
479 fontSizeChangedListeners.add(listener); |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
480 } |
0 | 481 } |
482 | |
483 /** | |
484 * Remove an {@link FontSizeChangedListener} from the list of listeners for | |
485 * this bridge. | |
486 * | |
487 * @param listener | |
488 */ | |
489 public void removeFontSizeChangedListener(FontSizeChangedListener listener) { | |
422
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
490 synchronized(fontSizeChangedListeners) { |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
491 fontSizeChangedListeners.remove(listener); |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
307
diff
changeset
|
492 } |
0 | 493 } |
494 | |
495 /** | |
496 * Something changed in our parent {@link TerminalView}, maybe it's a new | |
497 * parent, or maybe it's an updated font size. We should recalculate | |
498 * terminal size information and request a PTY resize. | |
499 */ | |
500 | |
501 public final synchronized void parentChanged(TerminalView parent) { | |
502 if (manager != null && !manager.isResizeAllowed()) { | |
503 Log.d(TAG, "Resize is not allowed now"); | |
504 return; | |
505 } | |
506 | |
507 this.parent = parent; | |
508 final int width = parent.getWidth(); | |
509 final int height = parent.getHeight(); | |
510 | |
511 // Something has gone wrong with our layout; we're 0 width or height! | |
512 if (width <= 0 || height <= 0) | |
513 return; | |
514 | |
515 clipboard = (ClipboardManager) parent.getContext().getSystemService(Context.CLIPBOARD_SERVICE); | |
516 keyListener.setClipboardManager(clipboard); | |
517 | |
518 if (!forcedSize) { | |
519 // recalculate buffer size | |
520 int newColumns, newRows; | |
521 newColumns = width / charWidth; | |
522 newRows = height / charHeight; | |
523 | |
524 // If nothing has changed in the terminal dimensions and not an intial | |
525 // draw then don't blow away scroll regions and such. | |
526 if (newColumns == columns && newRows == rows) | |
527 return; | |
528 | |
529 columns = newColumns; | |
530 rows = newRows; | |
531 } | |
532 | |
533 // reallocate new bitmap if needed | |
534 boolean newBitmap = (bitmap == null); | |
535 | |
536 if (bitmap != null) | |
537 newBitmap = (bitmap.getWidth() != width || bitmap.getHeight() != height); | |
538 | |
539 if (newBitmap) { | |
540 discardBitmap(); | |
541 bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); | |
542 canvas.setBitmap(bitmap); | |
543 } | |
544 | |
545 // clear out any old buffer information | |
546 defaultPaint.setColor(Color.BLACK); | |
547 canvas.drawPaint(defaultPaint); | |
548 | |
549 // Stroke the border of the terminal if the size is being forced; | |
550 if (forcedSize) { | |
551 int borderX = (columns * charWidth) + 1; | |
552 int borderY = (rows * charHeight) + 1; | |
553 defaultPaint.setColor(Color.GRAY); | |
554 defaultPaint.setStrokeWidth(0.0f); | |
555 | |
556 if (width >= borderX) | |
557 canvas.drawLine(borderX, 0, borderX, borderY + 1, defaultPaint); | |
558 | |
559 if (height >= borderY) | |
560 canvas.drawLine(0, borderY, borderX + 1, borderY, defaultPaint); | |
561 } | |
562 | |
563 try { | |
564 // request a terminal pty resize | |
42
7ac846a07ed4
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
40
diff
changeset
|
565 if (buffer != null) { |
7ac846a07ed4
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
40
diff
changeset
|
566 synchronized (buffer) { |
7ac846a07ed4
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
40
diff
changeset
|
567 buffer.setScreenSize(columns, rows, true); |
7ac846a07ed4
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
40
diff
changeset
|
568 } |
0 | 569 } |
570 | |
571 if (transport != null) | |
572 transport.setDimensions(columns, rows, width, height); | |
573 } | |
574 catch (Exception e) { | |
575 Log.e(TAG, "Problem while trying to resize screen or PTY", e); | |
576 } | |
577 | |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
578 // redraw local output if we don't have a session to receive our resize request |
0 | 579 if (transport == null) { |
580 synchronized (localOutput) { | |
581 buffer.reset(); | |
582 | |
583 for (String line : localOutput) | |
584 buffer.putString(line); | |
585 } | |
586 } | |
587 | |
588 // force full redraw with new buffer size | |
589 fullRedraw = true; | |
590 redraw(); | |
253
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
591 |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
592 // initial sequence from |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
593 // transport.connect() |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
594 // bridge.onConnected() |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
595 // bridge.setMyFontSize() |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
596 // bridge.resizeComputed() |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
597 // bridge.setFontSize() |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
598 // bridge.parentChanged() here is on the wrong thread |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
599 try { |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
600 parent.notifyUser(String.format("%d x %d", columns, rows)); |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
601 } |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
602 catch (Exception e) { |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
603 Log.e(TAG, "Problem while trying to notify user", e); |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
604 } |
e13878bb3ddf
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
248
diff
changeset
|
605 |
0 | 606 Log.i(TAG, String.format("parentChanged() now width=%d, height=%d", columns, rows)); |
607 } | |
608 | |
609 /** | |
610 * Somehow our parent {@link TerminalView} was destroyed. Now we don't need | |
611 * to redraw anywhere, and we can recycle our internal bitmap. | |
612 */ | |
613 | |
614 public synchronized void parentDestroyed() { | |
615 parent = null; | |
616 discardBitmap(); | |
617 } | |
618 | |
619 private void discardBitmap() { | |
620 if (bitmap != null) | |
621 bitmap.recycle(); | |
622 | |
623 bitmap = null; | |
624 } | |
625 | |
626 public void propagateConsoleText(char[] rawText, int length) { | |
627 if (parent != null) { | |
628 parent.propagateConsoleText(rawText, length); | |
629 } | |
630 } | |
631 | |
632 public void onDraw() { | |
633 int fg, bg; | |
634 | |
635 synchronized (buffer) { | |
636 boolean entireDirty = buffer.update[0] || fullRedraw; | |
637 boolean isWideCharacter = false; | |
638 | |
639 // walk through all lines in the buffer | |
640 for (int l = 0; l < buffer.height; l++) { | |
641 // check if this line is dirty and needs to be repainted | |
642 // also check for entire-buffer dirty flags | |
643 if (!entireDirty && !buffer.update[l + 1]) continue; | |
644 | |
645 // reset dirty flag for this line | |
646 buffer.update[l + 1] = false; | |
647 | |
648 // walk through all characters in this line | |
649 for (int c = 0; c < buffer.width; c++) { | |
650 int addr = 0; | |
651 int currAttr = buffer.charAttributes[buffer.windowBase + l][c]; | |
652 { | |
653 int fgcolor = defaultFg; | |
654 | |
655 // check if foreground color attribute is set | |
656 if ((currAttr & VDUBuffer.COLOR_FG) != 0) | |
657 fgcolor = ((currAttr & VDUBuffer.COLOR_FG) >> VDUBuffer.COLOR_FG_SHIFT) - 1; | |
658 | |
659 if (fgcolor < 8 && (currAttr & VDUBuffer.BOLD) != 0) | |
660 fg = color[fgcolor + 8]; | |
661 else | |
662 fg = color[fgcolor]; | |
663 } | |
664 | |
665 // check if background color attribute is set | |
666 if ((currAttr & VDUBuffer.COLOR_BG) != 0) | |
667 bg = color[((currAttr & VDUBuffer.COLOR_BG) >> VDUBuffer.COLOR_BG_SHIFT) - 1]; | |
668 else | |
669 bg = color[defaultBg]; | |
670 | |
671 // support character inversion by swapping background and foreground color | |
672 if ((currAttr & VDUBuffer.INVERT) != 0) { | |
673 int swapc = bg; | |
674 bg = fg; | |
675 fg = swapc; | |
676 } | |
677 | |
678 // set underlined attributes if requested | |
679 defaultPaint.setUnderlineText((currAttr & VDUBuffer.UNDERLINE) != 0); | |
680 isWideCharacter = (currAttr & VDUBuffer.FULLWIDTH) != 0; | |
681 | |
682 if (isWideCharacter) | |
683 addr++; | |
684 else { | |
685 // determine the amount of continuous characters with the same settings and print them all at once | |
686 while (c + addr < buffer.width | |
687 && buffer.charAttributes[buffer.windowBase + l][c + addr] == currAttr) { | |
688 addr++; | |
689 } | |
690 } | |
691 | |
692 // Save the current clip region | |
457
105815cce146
minimum version android 5, target and compile version api 28
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
693 canvas.save(); |
0 | 694 // clear this dirty area with background color |
695 defaultPaint.setColor(bg); | |
696 | |
697 if (isWideCharacter) { | |
698 canvas.clipRect(c * charWidth, | |
699 l * charHeight, | |
700 (c + 2) * charWidth, | |
701 (l + 1) * charHeight); | |
702 } | |
703 else { | |
704 canvas.clipRect(c * charWidth, | |
705 l * charHeight, | |
706 (c + addr) * charWidth, | |
707 (l + 1) * charHeight); | |
708 } | |
709 | |
710 canvas.drawPaint(defaultPaint); | |
711 // write the text string starting at 'c' for 'addr' number of characters | |
712 defaultPaint.setColor(fg); | |
713 | |
714 if ((currAttr & VDUBuffer.INVISIBLE) == 0) | |
715 canvas.drawText(buffer.charArray[buffer.windowBase + l], c, | |
716 addr, c * charWidth, (l * charHeight) - charTop, | |
717 defaultPaint); | |
718 | |
719 // Restore the previous clip region | |
720 canvas.restore(); | |
721 // advance to the next text block with different characteristics | |
722 c += addr - 1; | |
723 | |
724 if (isWideCharacter) | |
725 c++; | |
726 } | |
727 } | |
728 | |
729 // reset entire-buffer flags | |
730 buffer.update[0] = false; | |
731 } | |
732 | |
733 fullRedraw = false; | |
734 } | |
735 | |
736 public void redraw() { | |
737 if (parent != null) | |
738 parent.postInvalidate(); | |
739 } | |
740 | |
741 // We don't have a scroll bar. | |
742 public void updateScrollBar() { | |
743 } | |
744 | |
745 /** | |
746 * Resize terminal to fit [rows]x[cols] in screen of size [width]x[height] | |
747 * @param rows | |
748 * @param cols | |
749 * @param width | |
750 * @param height | |
751 */ | |
752 | |
753 public synchronized void resizeComputed(int cols, int rows, int width, int height) { | |
754 float size = 8.0f; | |
755 float step = 8.0f; | |
756 float limit = 0.125f; | |
757 int direction; | |
260
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
758 boolean fixed = true; |
0 | 759 |
260
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
760 if (!fixed) { |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
761 while ((direction = fontSizeCompare(size, cols, rows, width, height)) < 0) |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
762 size += step; |
0 | 763 |
260
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
764 if (direction == 0) { |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
765 Log.d("fontsize", String.format("Found match at %f", size)); |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
766 return; |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
767 } |
0 | 768 |
260
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
769 step /= 2.0f; |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
770 size -= step; |
0 | 771 |
260
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
772 while ((direction = fontSizeCompare(size, cols, rows, width, height)) != 0 |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
773 && step >= limit) { |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
774 step /= 2.0f; |
0 | 775 |
260
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
776 if (direction > 0) { |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
777 size -= step; |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
778 } |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
779 else { |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
780 size += step; |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
781 } |
0 | 782 } |
260
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
783 |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
784 if (direction > 0) size -= step; |
0 | 785 } |
786 | |
787 this.columns = cols; | |
788 this.rows = rows; | |
789 forcedSize = true; | |
307 | 790 |
260
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
791 if (fixed) setFontSize(host.getFontSize()); |
edf4dacea9ff
allow both fixed rows/columns and specified font size
Carl Byington <carl@five-ten-sg.com>
parents:
253
diff
changeset
|
792 else setFontSize(size); |
0 | 793 } |
794 | |
795 private int fontSizeCompare(float size, int cols, int rows, int width, int height) { | |
796 // read new metrics to get exact pixel dimensions | |
797 defaultPaint.setTextSize(size); | |
798 FontMetrics fm = defaultPaint.getFontMetrics(); | |
799 float[] widths = new float[1]; | |
800 defaultPaint.getTextWidths("X", widths); | |
801 int termWidth = (int)widths[0] * cols; | |
457
105815cce146
minimum version android 5, target and compile version api 28
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
802 int termHeight = (int)Math.ceil(fm.descent - fm.top) * rows; |
0 | 803 Log.d("fontsize", String.format("font size %f resulted in %d x %d", size, termWidth, termHeight)); |
804 | |
805 // Check to see if it fits in resolution specified. | |
806 if (termWidth > width || termHeight > height) | |
807 return 1; | |
808 | |
809 if (termWidth == width || termHeight == height) | |
810 return 0; | |
811 | |
812 return -1; | |
813 } | |
814 | |
815 /** | |
816 * @return whether underlying transport can forward ports | |
817 */ | |
818 public boolean canFowardPorts() { | |
819 return transport.canForwardPorts(); | |
820 } | |
821 | |
822 /** | |
823 * Adds the {@link PortForwardBean} to the list. | |
824 * @param portForward the port forward bean to add | |
825 * @return true on successful addition | |
826 */ | |
827 public boolean addPortForward(PortForwardBean portForward) { | |
828 return transport.addPortForward(portForward); | |
829 } | |
830 | |
831 /** | |
832 * Removes the {@link PortForwardBean} from the list. | |
833 * @param portForward the port forward bean to remove | |
834 * @return true on successful removal | |
835 */ | |
836 public boolean removePortForward(PortForwardBean portForward) { | |
837 return transport.removePortForward(portForward); | |
838 } | |
839 | |
840 /** | |
841 * @return the list of port forwards | |
842 */ | |
843 public List<PortForwardBean> getPortForwards() { | |
844 return transport.getPortForwards(); | |
845 } | |
846 | |
847 /** | |
848 * Enables a port forward member. After calling this method, the port forward should | |
849 * be operational. | |
850 * @param portForward member of our current port forwards list to enable | |
851 * @return true on successful port forward setup | |
852 */ | |
853 public boolean enablePortForward(PortForwardBean portForward) { | |
854 if (!transport.isConnected()) { | |
855 Log.i(TAG, "Attempt to enable port forward while not connected"); | |
856 return false; | |
857 } | |
858 | |
859 return transport.enablePortForward(portForward); | |
860 } | |
861 | |
862 /** | |
863 * Disables a port forward member. After calling this method, the port forward should | |
864 * be non-functioning. | |
865 * @param portForward member of our current port forwards list to enable | |
866 * @return true on successful port forward tear-down | |
867 */ | |
868 public boolean disablePortForward(PortForwardBean portForward) { | |
869 if (!transport.isConnected()) { | |
870 Log.i(TAG, "Attempt to disable port forward while not connected"); | |
871 return false; | |
872 } | |
873 | |
874 return transport.disablePortForward(portForward); | |
875 } | |
876 | |
877 /** | |
878 * @return whether underlying transport can transfer files | |
879 */ | |
880 public boolean canTransferFiles() { | |
881 return transport.canTransferFiles(); | |
882 } | |
883 | |
884 /** | |
885 * Downloads the specified remote file to the local connectbot folder. | |
886 * @return true on success, false on failure | |
887 */ | |
888 public boolean downloadFile(String remoteFile, String localFolder) { | |
889 return transport.downloadFile(remoteFile, localFolder); | |
890 } | |
891 | |
892 /** | |
893 * Uploads the specified local file to the remote host's default directory. | |
894 * @return true on success, false on failure | |
895 */ | |
896 public boolean uploadFile(String localFile, String remoteFolder, String remoteFile, String mode) { | |
897 if (mode == null) | |
898 mode = "0600"; | |
899 | |
900 return transport.uploadFile(localFile, remoteFolder, remoteFile, mode); | |
901 } | |
902 | |
903 /** | |
904 * @return whether the TerminalBridge should close | |
905 */ | |
906 public boolean isAwaitingClose() { | |
907 return awaitingClose; | |
908 } | |
909 | |
910 /** | |
911 * @return whether this connection had started and subsequently disconnected | |
912 */ | |
913 public boolean isDisconnected() { | |
914 return disconnected; | |
915 } | |
916 | |
917 /* (non-Javadoc) | |
918 * @see de.mud.terminal.VDUDisplay#setColor(byte, byte, byte, byte) | |
919 */ | |
920 public void setColor(int index, int red, int green, int blue) { | |
921 // Don't allow the system colors to be overwritten for now. May violate specs. | |
922 if (index < color.length && index >= 16) | |
923 color[index] = 0xff000000 | red << 16 | green << 8 | blue; | |
924 } | |
925 | |
926 public final void resetColors() { | |
927 int[] defaults = manager.hostdb.getDefaultColorsForScheme(HostDatabase.DEFAULT_COLOR_SCHEME); | |
928 defaultFg = defaults[0]; | |
929 defaultBg = defaults[1]; | |
930 color = manager.hostdb.getColorsForScheme(HostDatabase.DEFAULT_COLOR_SCHEME); | |
931 } | |
932 | |
933 private static Pattern urlPattern = null; | |
934 | |
935 /** | |
936 * @return | |
937 */ | |
938 public List<String> scanForURLs() { | |
939 Set<String> urls = new LinkedHashSet<String>(); | |
940 | |
941 if (urlPattern == null) { | |
942 // based on http://www.ietf.org/rfc/rfc2396.txt | |
943 String scheme = "[A-Za-z][-+.0-9A-Za-z]*"; | |
944 String unreserved = "[-._~0-9A-Za-z]"; | |
945 String pctEncoded = "%[0-9A-Fa-f]{2}"; | |
946 String subDelims = "[!$&'()*+,;:=]"; | |
947 String userinfo = "(?:" + unreserved + "|" + pctEncoded + "|" + subDelims + "|:)*"; | |
948 String h16 = "[0-9A-Fa-f]{1,4}"; | |
949 String decOctet = "(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"; | |
950 String ipv4address = decOctet + "\\." + decOctet + "\\." + decOctet + "\\." + decOctet; | |
951 String ls32 = "(?:" + h16 + ":" + h16 + "|" + ipv4address + ")"; | |
952 String ipv6address = "(?:(?:" + h16 + "){6}" + ls32 + ")"; | |
953 String ipvfuture = "v[0-9A-Fa-f]+.(?:" + unreserved + "|" + subDelims + "|:)+"; | |
954 String ipLiteral = "\\[(?:" + ipv6address + "|" + ipvfuture + ")\\]"; | |
955 String regName = "(?:" + unreserved + "|" + pctEncoded + "|" + subDelims + ")*"; | |
956 String host = "(?:" + ipLiteral + "|" + ipv4address + "|" + regName + ")"; | |
957 String port = "[0-9]*"; | |
958 String authority = "(?:" + userinfo + "@)?" + host + "(?::" + port + ")?"; | |
959 String pchar = "(?:" + unreserved + "|" + pctEncoded + "|" + subDelims + "|@)"; | |
960 String segment = pchar + "*"; | |
961 String pathAbempty = "(?:/" + segment + ")*"; | |
962 String segmentNz = pchar + "+"; | |
963 String pathAbsolute = "/(?:" + segmentNz + "(?:/" + segment + ")*)?"; | |
964 String pathRootless = segmentNz + "(?:/" + segment + ")*"; | |
965 String hierPart = "(?://" + authority + pathAbempty + "|" + pathAbsolute + "|" + pathRootless + ")"; | |
966 String query = "(?:" + pchar + "|/|\\?)*"; | |
967 String fragment = "(?:" + pchar + "|/|\\?)*"; | |
968 String uriRegex = scheme + ":" + hierPart + "(?:" + query + ")?(?:#" + fragment + ")?"; | |
969 urlPattern = Pattern.compile(uriRegex); | |
970 } | |
971 | |
972 char[] visibleBuffer = new char[buffer.height * buffer.width]; | |
973 | |
974 for (int l = 0; l < buffer.height; l++) | |
975 System.arraycopy(buffer.charArray[buffer.windowBase + l], 0, | |
976 visibleBuffer, l * buffer.width, buffer.width); | |
977 | |
978 Matcher urlMatcher = urlPattern.matcher(new String(visibleBuffer)); | |
979 | |
980 while (urlMatcher.find()) | |
981 urls.add(urlMatcher.group()); | |
982 | |
983 return (new LinkedList<String> (urls)); | |
984 } | |
985 | |
986 /** | |
987 * @return | |
988 */ | |
989 public boolean isUsingNetwork() { | |
990 return transport.usesNetwork(); | |
991 } | |
992 | |
993 /** | |
994 * @return | |
995 */ | |
996 public TerminalKeyListener getKeyHandler() { | |
997 return keyListener; | |
998 } | |
999 | |
1000 /** | |
1001 * | |
1002 */ | |
1003 public void resetScrollPosition() { | |
1004 // if we're in scrollback, scroll to bottom of window on input | |
1005 if (buffer.windowBase != buffer.screenBase) | |
1006 buffer.setWindowBase(buffer.screenBase); | |
1007 } | |
1008 | |
1009 /** | |
1010 * | |
1011 */ | |
1012 public void increaseFontSize() { | |
188
cf677a6f586d
use floating point font size, change size by scaling factor rather than linear addition
Carl Byington <carl@five-ten-sg.com>
parents:
182
diff
changeset
|
1013 setFontSize(fontSize * FONT_SIZE_FACTOR); |
0 | 1014 } |
1015 | |
1016 /** | |
1017 * | |
1018 */ | |
1019 public void decreaseFontSize() { | |
188
cf677a6f586d
use floating point font size, change size by scaling factor rather than linear addition
Carl Byington <carl@five-ten-sg.com>
parents:
182
diff
changeset
|
1020 setFontSize(fontSize / FONT_SIZE_FACTOR); |
0 | 1021 } |
1022 | |
1023 /** | |
1024 * Auto-size window back to default | |
1025 */ | |
1026 public void resetSize(TerminalView parent) { | |
1027 this.forcedSize = false; | |
245
23119f3c0d28
add host preference for fixed screen size
Carl Byington <carl@five-ten-sg.com>
parents:
244
diff
changeset
|
1028 setMyFontSize(); |
0 | 1029 } |
1030 | |
1031 /** | |
1032 * Create a screenshot of the current view | |
1033 */ | |
1034 public void captureScreen() { | |
1035 String msg; | |
1036 File dir, path; | |
1037 boolean success = true; | |
1038 Bitmap screenshot = this.bitmap; | |
1039 | |
1040 if (manager == null || parent == null || screenshot == null) | |
1041 return; | |
1042 | |
1043 SimpleDateFormat s = new SimpleDateFormat("yyyyMMdd_HHmmss"); | |
1044 String date = s.format(new Date()); | |
1045 String pref_path = manager.prefs.getString(PreferenceConstants.SCREEN_CAPTURE_FOLDER, ""); | |
1046 File default_path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); | |
1047 | |
1048 if (pref_path.equals("")) | |
1049 dir = default_path; | |
1050 else | |
1051 dir = new File(pref_path); | |
1052 | |
1053 path = new File(dir, "vx-" + date + ".png"); | |
1054 | |
1055 try { | |
1056 dir.mkdirs(); | |
1057 FileOutputStream out = new FileOutputStream(path); | |
1058 screenshot.compress(Bitmap.CompressFormat.PNG, 90, out); | |
1059 out.close(); | |
1060 } | |
1061 catch (Exception e) { | |
1062 e.printStackTrace(); | |
1063 success = false; | |
1064 } | |
1065 | |
1066 if (success) { | |
1067 msg = manager.getResources().getString(R.string.screenshot_saved_as) + " " + path; | |
1068 | |
1069 if (manager.prefs.getBoolean(PreferenceConstants.SCREEN_CAPTURE_POPUP, true)) { | |
1070 new AlertDialog.Builder(parent.getContext()) | |
1071 .setTitle(R.string.screenshot_success_title) | |
1072 .setMessage(msg) | |
1073 .setPositiveButton(R.string.button_close, null) | |
1074 .show(); | |
1075 } | |
1076 } | |
1077 else { | |
1078 msg = manager.getResources().getString(R.string.screenshot_not_saved_as) + " " + path; | |
1079 new AlertDialog.Builder(parent.getContext()) | |
1080 .setTitle(R.string.screenshot_error_title) | |
1081 .setMessage(msg) | |
1082 .setNegativeButton(R.string.button_close, null) | |
1083 .show(); | |
1084 } | |
1085 | |
1086 return; | |
1087 } | |
1088 | |
1089 /** | |
1090 * Show change font size dialog | |
1091 */ | |
1092 public boolean showFontSizeDialog() { | |
1093 final String pickerString = "+-"; | |
1094 CharSequence str = ""; | |
1095 Editable content = Editable.Factory.getInstance().newEditable(str); | |
1096 | |
1097 if (parent == null) | |
1098 return false; | |
1099 | |
1100 CharacterPickerDialog cpd = new CharacterPickerDialog(parent.getContext(), | |
1101 parent, content, pickerString, true) { | |
1102 private void changeFontSize(CharSequence result) { | |
1103 if (result.equals("+")) | |
1104 increaseFontSize(); | |
1105 else if (result.equals("-")) | |
1106 decreaseFontSize(); | |
1107 } | |
1108 @Override | |
1109 public void onItemClick(AdapterView p, View v, int pos, long id) { | |
1110 final String result = String.valueOf(pickerString.charAt(pos)); | |
1111 changeFontSize(result); | |
1112 } | |
1113 @Override | |
1114 public void onClick(View v) { | |
1115 if (v instanceof Button) { | |
1116 final CharSequence result = ((Button) v).getText(); | |
1117 | |
1118 if (result.equals("")) | |
1119 dismiss(); | |
1120 else | |
1121 changeFontSize(result); | |
1122 } | |
1123 } | |
1124 @Override | |
1125 public boolean dispatchKeyEvent(KeyEvent event) { | |
1126 if (event.getAction() == KeyEvent.ACTION_DOWN) { | |
1127 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) | |
1128 dismiss(); | |
1129 | |
1130 return keyListener.onKey(parent, event.getKeyCode(), event); | |
1131 } | |
1132 | |
1133 return true; | |
1134 } | |
1135 }; | |
1136 cpd.show(); | |
1137 return true; | |
1138 } | |
1139 | |
1140 /** | |
1141 * Show arrows dialog | |
1142 */ | |
1143 public boolean showArrowsDialog() { | |
231
502ba7668993
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
230
diff
changeset
|
1144 final String []pickerStrings = {"←", "→", "↑", "↓", "tab", "ins", "del", "ret"}; |
307 | 1145 final HashMap<String, Integer> keymap = new HashMap<String, Integer>(); |
230
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1146 keymap.put("←", vt320.KEY_LEFT); |
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1147 keymap.put("→", vt320.KEY_RIGHT); |
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1148 keymap.put("↑", vt320.KEY_UP); |
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1149 keymap.put("↓", vt320.KEY_DOWN); |
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1150 keymap.put("tab", vt320.KEY_TAB); |
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1151 keymap.put("ins", vt320.KEY_INSERT); |
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1152 keymap.put("del", vt320.KEY_DELETE); |
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1153 keymap.put("ret", vt320.KEY_ENTER); |
0 | 1154 CharSequence str = ""; |
1155 Editable content = Editable.Factory.getInstance().newEditable(str); | |
1156 | |
230
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1157 if (parent == null) return false; |
0 | 1158 |
230
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1159 StringPickerDialog cpd = new StringPickerDialog(parent.getContext(), |
307 | 1160 parent, content, |
1161 pickerStrings, true) { | |
230
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1162 private void buttonPressed(String s) { |
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1163 if (keymap.containsKey(s)) buffer.keyPressed(keymap.get(s), ' ', 0); |
0 | 1164 } |
1165 @Override | |
1166 public void onItemClick(AdapterView p, View v, int pos, long id) { | |
230
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1167 buttonPressed(pickerStrings[pos]); |
0 | 1168 } |
1169 @Override | |
1170 public void onClick(View v) { | |
1171 if (v instanceof Button) { | |
230
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1172 final String s = ((Button) v).getText().toString(); |
307 | 1173 |
230
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1174 if (s.equals("")) dismiss(); |
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1175 else buttonPressed(s); |
0 | 1176 } |
1177 } | |
1178 @Override | |
1179 public boolean dispatchKeyEvent(KeyEvent event) { | |
1180 if (event.getAction() == KeyEvent.ACTION_DOWN) { | |
1181 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) | |
1182 dismiss(); | |
1183 | |
1184 return keyListener.onKey(parent, event.getKeyCode(), event); | |
1185 } | |
1186 | |
1187 return true; | |
1188 } | |
1189 }; | |
1190 cpd.show(); | |
1191 return true; | |
1192 } | |
1193 | |
1194 | |
1195 /** | |
1196 * CTRL dialog | |
1197 */ | |
1198 private String getCtrlString() { | |
261
79e6adde6fde
ctrl picker allows a-z now
Carl Byington <carl@five-ten-sg.com>
parents:
260
diff
changeset
|
1199 final String defaultSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
0 | 1200 String set = manager.prefs.getString(PreferenceConstants.CTRL_STRING, defaultSet); |
1201 | |
1202 if (set == null || set.equals("")) { | |
1203 set = defaultSet; | |
1204 } | |
1205 | |
1206 return set; | |
1207 } | |
1208 | |
1209 public boolean showCtrlDialog() { | |
1210 CharSequence str = ""; | |
1211 Editable content = Editable.Factory.getInstance().newEditable(str); | |
1212 | |
1213 if (parent == null) | |
1214 return false; | |
1215 | |
1216 CharacterPickerDialog cpd = new CharacterPickerDialog(parent.getContext(), | |
1217 parent, content, getCtrlString(), true) { | |
1218 private void buttonPressed(CharSequence result) { | |
1219 int code = result.toString().toUpperCase().charAt(0) - 64; | |
1220 | |
1221 if (code > 0 && code < 80) { | |
1222 try { | |
1223 transport.write(code); | |
1224 } | |
1225 catch (IOException e) { | |
1226 Log.d(TAG, "Error writing CTRL+" + result.toString().toUpperCase().charAt(0)); | |
1227 } | |
1228 } | |
1229 | |
1230 dismiss(); | |
1231 } | |
1232 @Override | |
1233 public void onItemClick(AdapterView p, View v, int pos, long id) { | |
1234 final String result = String.valueOf(getCtrlString().charAt(pos)); | |
1235 buttonPressed(result); | |
1236 } | |
1237 @Override | |
1238 public void onClick(View v) { | |
1239 if (v instanceof Button) { | |
1240 final CharSequence result = ((Button) v).getText(); | |
1241 | |
1242 if (result.equals("")) | |
1243 dismiss(); | |
1244 else | |
1245 buttonPressed(result); | |
1246 } | |
1247 } | |
1248 @Override | |
1249 public boolean dispatchKeyEvent(KeyEvent event) { | |
1250 if (event.getAction() == KeyEvent.ACTION_DOWN) { | |
1251 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) | |
1252 dismiss(); | |
1253 | |
1254 return keyListener.onKey(parent, event.getKeyCode(), event); | |
1255 } | |
1256 | |
1257 return true; | |
1258 } | |
1259 }; | |
1260 cpd.show(); | |
1261 return true; | |
1262 } | |
1263 | |
1264 /** | |
1265 * Function keys dialog | |
1266 */ | |
1267 public boolean showFKeysDialog() { | |
262
db26984b69f5
update version; add cursor movement keys to the soft function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
261
diff
changeset
|
1268 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", "←", "→", "↑", "↓", "tab", "ins", "del", "ret"}; |
307 | 1269 final HashMap<String, Integer> keymap = new HashMap<String, Integer>(); |
223
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1270 keymap.put("F1", vt320.KEY_F1); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1271 keymap.put("F2", vt320.KEY_F2); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1272 keymap.put("F3", vt320.KEY_F3); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1273 keymap.put("F4", vt320.KEY_F4); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1274 keymap.put("F5", vt320.KEY_F5); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1275 keymap.put("F6", vt320.KEY_F6); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1276 keymap.put("F7", vt320.KEY_F7); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1277 keymap.put("F8", vt320.KEY_F8); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1278 keymap.put("F9", vt320.KEY_F9); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1279 keymap.put("F10", vt320.KEY_F10); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1280 keymap.put("F11", vt320.KEY_F11); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1281 keymap.put("F12", vt320.KEY_F12); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1282 keymap.put("F13", vt320.KEY_F13); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1283 keymap.put("F14", vt320.KEY_F14); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1284 keymap.put("F15", vt320.KEY_F15); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1285 keymap.put("F16", vt320.KEY_F16); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1286 keymap.put("F17", vt320.KEY_F17); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1287 keymap.put("F18", vt320.KEY_F18); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1288 keymap.put("F19", vt320.KEY_F19); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1289 keymap.put("F20", vt320.KEY_F20); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1290 keymap.put("F21", vt320.KEY_F21); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1291 keymap.put("F22", vt320.KEY_F22); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1292 keymap.put("F23", vt320.KEY_F23); |
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1293 keymap.put("F24", vt320.KEY_F24); |
262
db26984b69f5
update version; add cursor movement keys to the soft function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
261
diff
changeset
|
1294 keymap.put("←", vt320.KEY_LEFT); |
db26984b69f5
update version; add cursor movement keys to the soft function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
261
diff
changeset
|
1295 keymap.put("→", vt320.KEY_RIGHT); |
db26984b69f5
update version; add cursor movement keys to the soft function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
261
diff
changeset
|
1296 keymap.put("↑", vt320.KEY_UP); |
db26984b69f5
update version; add cursor movement keys to the soft function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
261
diff
changeset
|
1297 keymap.put("↓", vt320.KEY_DOWN); |
db26984b69f5
update version; add cursor movement keys to the soft function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
261
diff
changeset
|
1298 keymap.put("tab", vt320.KEY_TAB); |
db26984b69f5
update version; add cursor movement keys to the soft function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
261
diff
changeset
|
1299 keymap.put("ins", vt320.KEY_INSERT); |
db26984b69f5
update version; add cursor movement keys to the soft function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
261
diff
changeset
|
1300 keymap.put("del", vt320.KEY_DELETE); |
db26984b69f5
update version; add cursor movement keys to the soft function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
261
diff
changeset
|
1301 keymap.put("ret", vt320.KEY_ENTER); |
0 | 1302 CharSequence str = ""; |
1303 Editable content = Editable.Factory.getInstance().newEditable(str); | |
1304 | |
230
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1305 if (parent == null) return false; |
0 | 1306 |
223
61ed3984fc1d
proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
191
diff
changeset
|
1307 StringPickerDialog cpd = new StringPickerDialog(parent.getContext(), |
307 | 1308 parent, content, |
1309 pickerStrings, true) { | |
230
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1310 private void buttonPressed(String s) { |
176 | 1311 if (keymap.containsKey(s)) buffer.keyPressed(keymap.get(s), ' ', 0); |
307 | 1312 |
0 | 1313 dismiss(); |
1314 } | |
1315 @Override | |
1316 public void onItemClick(AdapterView p, View v, int pos, long id) { | |
230
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1317 buttonPressed(pickerStrings[pos]); |
0 | 1318 } |
1319 @Override | |
1320 public void onClick(View v) { | |
1321 if (v instanceof Button) { | |
230
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1322 final String s = ((Button) v).getText().toString(); |
307 | 1323 |
230
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1324 if (s.equals("")) dismiss(); |
bc40032ad1da
use StringPickerDialog for soft cursor keypad
Carl Byington <carl@five-ten-sg.com>
parents:
223
diff
changeset
|
1325 else buttonPressed(s); |
0 | 1326 } |
1327 } | |
1328 @Override | |
1329 public boolean dispatchKeyEvent(KeyEvent event) { | |
1330 if (event.getAction() == KeyEvent.ACTION_DOWN) { | |
1331 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) | |
1332 dismiss(); | |
1333 | |
1334 return keyListener.onKey(parent, event.getKeyCode(), event); | |
1335 } | |
1336 | |
1337 return true; | |
1338 } | |
1339 }; | |
1340 cpd.show(); | |
1341 return true; | |
1342 } | |
1343 | |
1344 private String getPickerString() { | |
1345 final String defaultSet = "~\\^()[]{}<>|/:_;,.!@#$%&*?\"'-+="; | |
1346 String set = manager.prefs.getString(PreferenceConstants.PICKER_STRING, defaultSet); | |
1347 | |
1348 if (set == null || set.equals("")) { | |
1349 set = defaultSet; | |
1350 } | |
1351 | |
1352 return set; | |
1353 } | |
1354 | |
1355 public boolean showCharPickerDialog() { | |
1356 CharSequence str = ""; | |
1357 Editable content = Editable.Factory.getInstance().newEditable(str); | |
1358 | |
1359 if (parent == null || !transport.isAuthenticated()) | |
1360 return false; | |
1361 | |
1362 CharacterPickerDialog cpd = new CharacterPickerDialog(parent.getContext(), | |
1363 parent, content, getPickerString(), true) { | |
1364 private void writeChar(CharSequence result) { | |
1365 try { | |
1366 if (transport.isAuthenticated()) | |
1367 transport.write(result.toString().getBytes(getCharset().name())); | |
1368 } | |
1369 catch (IOException e) { | |
1370 Log.e(TAG, "Problem with the CharacterPickerDialog", e); | |
1371 } | |
1372 | |
1373 if (!manager.prefs.getBoolean(PreferenceConstants.PICKER_KEEP_OPEN, false)) | |
1374 dismiss(); | |
1375 } | |
1376 @Override | |
1377 public void onItemClick(AdapterView p, View v, int pos, long id) { | |
1378 String result = String.valueOf(getPickerString().charAt(pos)); | |
1379 writeChar(result); | |
1380 } | |
1381 @Override | |
1382 public void onClick(View v) { | |
1383 if (v instanceof Button) { | |
1384 CharSequence result = ((Button) v).getText(); | |
1385 | |
1386 if (result.equals("")) | |
1387 dismiss(); | |
1388 else | |
1389 writeChar(result); | |
1390 } | |
1391 } | |
1392 @Override | |
1393 public boolean dispatchKeyEvent(KeyEvent event) { | |
1394 int keyCode = event.getKeyCode(); | |
1395 | |
1396 if (event.getAction() == KeyEvent.ACTION_DOWN) { | |
1397 // close window if SYM or BACK keys are pressed | |
1398 if (keyListener.isSymKey(keyCode) || | |
1399 keyCode == KeyEvent.KEYCODE_BACK) { | |
1400 dismiss(); | |
1401 return true; | |
1402 } | |
1403 } | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
95
diff
changeset
|
1404 |
0 | 1405 return super.dispatchKeyEvent(event); |
1406 } | |
1407 }; | |
1408 cpd.show(); | |
1409 return true; | |
1410 } | |
1411 } |