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