aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/connectbot/ConsoleActivity.java33
-rw-r--r--src/org/connectbot/StrictModeSetup.java23
-rw-r--r--src/org/connectbot/service/TerminalKeyListener.java69
3 files changed, 107 insertions, 18 deletions
diff --git a/src/org/connectbot/ConsoleActivity.java b/src/org/connectbot/ConsoleActivity.java
index 58eaed2..31ba444 100644
--- a/src/org/connectbot/ConsoleActivity.java
+++ b/src/org/connectbot/ConsoleActivity.java
@@ -98,6 +98,10 @@ public class ConsoleActivity extends Activity {
private SharedPreferences prefs = null;
+ // determines whether or not menuitem accelerators are bound
+ // otherwise they collide with an external keyboard's CTRL-char
+ private boolean hardKeyboard = false;
+
protected Uri requested;
protected ClipboardManager clipboard;
@@ -255,9 +259,20 @@ public class ConsoleActivity extends Activity {
booleanPromptGroup.setVisibility(View.GONE);
}
+ // more like configureLaxMode -- enable network IO on UI thread
+ private void configureStrictMode() {
+ try {
+ Class.forName("android.os.StrictMode");
+ StrictModeSetup.run();
+ } catch (ClassNotFoundException e) {
+ }
+ }
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ configureStrictMode();
+ hardKeyboard = getResources().getConfiguration().keyboard ==
+ Configuration.KEYBOARD_QWERTY;
this.setContentView(R.layout.act_console);
@@ -620,7 +635,8 @@ public class ConsoleActivity extends Activity {
menu.setQwertyMode(true);
disconnect = menu.add(R.string.list_host_disconnect);
- disconnect.setAlphabeticShortcut('w');
+ if (hardKeyboard)
+ disconnect.setAlphabeticShortcut('w');
if (!sessionOpen && disconnected)
disconnect.setTitle(R.string.console_menu_close);
disconnect.setEnabled(activeTerminal);
@@ -637,7 +653,8 @@ public class ConsoleActivity extends Activity {
});
copy = menu.add(R.string.console_menu_copy);
- copy.setAlphabeticShortcut('c');
+ if (hardKeyboard)
+ copy.setAlphabeticShortcut('c');
copy.setIcon(android.R.drawable.ic_menu_set_as);
copy.setEnabled(activeTerminal);
copy.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@@ -661,7 +678,8 @@ public class ConsoleActivity extends Activity {
});
paste = menu.add(R.string.console_menu_paste);
- paste.setAlphabeticShortcut('v');
+ if (hardKeyboard)
+ paste.setAlphabeticShortcut('v');
paste.setIcon(android.R.drawable.ic_menu_edit);
paste.setEnabled(clipboard.hasText() && sessionOpen);
paste.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@@ -679,7 +697,8 @@ public class ConsoleActivity extends Activity {
});
portForward = menu.add(R.string.console_menu_portforwards);
- portForward.setAlphabeticShortcut('f');
+ if (hardKeyboard)
+ portForward.setAlphabeticShortcut('f');
portForward.setIcon(android.R.drawable.ic_menu_manage);
portForward.setEnabled(sessionOpen && canForwardPorts);
portForward.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@@ -695,7 +714,8 @@ public class ConsoleActivity extends Activity {
});
urlscan = menu.add(R.string.console_menu_urlscan);
- urlscan.setAlphabeticShortcut('u');
+ if (hardKeyboard)
+ urlscan.setAlphabeticShortcut('u');
urlscan.setIcon(android.R.drawable.ic_menu_search);
urlscan.setEnabled(activeTerminal);
urlscan.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@@ -720,7 +740,8 @@ public class ConsoleActivity extends Activity {
});
resize = menu.add(R.string.console_menu_resize);
- resize.setAlphabeticShortcut('s');
+ if (hardKeyboard)
+ resize.setAlphabeticShortcut('s');
resize.setIcon(android.R.drawable.ic_menu_crop);
resize.setEnabled(sessionOpen);
resize.setOnMenuItemClickListener(new OnMenuItemClickListener() {
diff --git a/src/org/connectbot/StrictModeSetup.java b/src/org/connectbot/StrictModeSetup.java
new file mode 100644
index 0000000..3a2000e
--- /dev/null
+++ b/src/org/connectbot/StrictModeSetup.java
@@ -0,0 +1,23 @@
+/*
+ * ConnectBot: simple, powerful, open-source SSH client for Android
+ * Copyright 2007 Kenny Root, Jeffrey Sharkey
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.connectbot;
+import android.os.StrictMode;
+public class StrictModeSetup {
+ public static void run() {
+ StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.LAX);
+ }
+}
diff --git a/src/org/connectbot/service/TerminalKeyListener.java b/src/org/connectbot/service/TerminalKeyListener.java
index fc326d6..4f0855c 100644
--- a/src/org/connectbot/service/TerminalKeyListener.java
+++ b/src/org/connectbot/service/TerminalKeyListener.java
@@ -56,6 +56,10 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
public final static int META_ALT_MASK = META_ALT_ON | META_ALT_LOCK;
public final static int META_SHIFT_MASK = META_SHIFT_ON | META_SHIFT_LOCK;
+ // backport constants from api level 11
+ public final static int KEYCODE_ESCAPE = 111;
+ public final static int HC_META_CTRL_ON = 4096;
+
// All the transient key codes
public final static int META_TRANSIENT = META_CTRL_ON | META_ALT_ON
| META_SHIFT_ON;
@@ -171,6 +175,7 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
}
int curMetaState = event.getMetaState();
+ final int orgMetaState = curMetaState;
if ((metaState & META_SHIFT_MASK) != 0) {
curMetaState |= KeyEvent.META_SHIFT_ON;
@@ -181,6 +186,11 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
}
int key = event.getUnicodeChar(curMetaState);
+ // no hard keyboard? ALT-k should pass through to below
+ if ((orgMetaState & KeyEvent.META_ALT_ON) != 0 &&
+ (!hardKeyboard || hardKeyboardHidden)) {
+ key = 0;
+ }
if ((key & KeyCharacterMap.COMBINING_ACCENT) != 0) {
mDeadKey = key & KeyCharacterMap.COMBINING_ACCENT_MASK;
@@ -216,18 +226,7 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
&& sendFunctionKey(keyCode))
return true;
- // Support CTRL-a through CTRL-z
- if (key >= 0x61 && key <= 0x7A)
- key -= 0x60;
- // Support CTRL-A through CTRL-_
- else if (key >= 0x41 && key <= 0x5F)
- key -= 0x40;
- // CTRL-space sends NULL
- else if (key == 0x20)
- key = 0x00;
- // CTRL-? sends DEL
- else if (key == 0x3F)
- key = 0x7F;
+ key = keyAsControl(key);
}
// handle pressing f-keys
@@ -246,6 +245,30 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
return true;
}
+ // send ctrl and meta-keys as appropriate
+ if (!hardKeyboard || hardKeyboardHidden) {
+ int k = event.getUnicodeChar(0);
+ int k0 = k;
+ boolean sendCtrl = false;
+ boolean sendMeta = false;
+ if (k != 0) {
+ if ((orgMetaState & HC_META_CTRL_ON) != 0) {
+ k = keyAsControl(k);
+ if (k != k0)
+ sendCtrl = true;
+ // send F1-F10 via CTRL-1 through CTRL-0
+ if (!sendCtrl && sendFunctionKey(keyCode))
+ return true;
+ } else if ((orgMetaState & KeyEvent.META_ALT_ON) != 0) {
+ sendMeta = true;
+ sendEscape();
+ }
+ if (sendMeta || sendCtrl) {
+ bridge.transport.write(k);
+ return true;
+ }
+ }
+ }
// try handling keymode shortcuts
if (hardKeyboard && !hardKeyboardHidden &&
event.getRepeatCount() == 0) {
@@ -295,6 +318,12 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
// look for special chars
switch(keyCode) {
+ case KEYCODE_ESCAPE:
+ sendEscape();
+ return true;
+ case KeyEvent.KEYCODE_TAB:
+ bridge.transport.write(0x09);
+ return true;
case KeyEvent.KEYCODE_CAMERA:
// check to see which shortcut the camera button triggers
@@ -421,6 +450,22 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
return false;
}
+ public int keyAsControl(int key) {
+ // Support CTRL-a through CTRL-z
+ if (key >= 0x61 && key <= 0x7A)
+ key -= 0x60;
+ // Support CTRL-A through CTRL-_
+ else if (key >= 0x41 && key <= 0x5F)
+ key -= 0x40;
+ // CTRL-space sends NULL
+ else if (key == 0x20)
+ key = 0x00;
+ // CTRL-? sends DEL
+ else if (key == 0x3F)
+ key = 0x7F;
+ return key;
+ }
+
public void sendEscape() {
((vt320)buffer).keyTyped(vt320.KEY_ESCAPE, ' ', 0);
}