From ce9b91f02d07a44f1c35887005a6fe89b9984fd9 Mon Sep 17 00:00:00 2001 From: Jack Palevich Date: Sun, 9 Jan 2011 10:31:17 -0800 Subject: [PATCH] Add '|' and arrow keys to "Special Chars" Add 'Camera' button as a possible Control key Make 'Volume Down' the default control key. --- AndroidManifest.xml | 3 +- res/values/arrays.xml | 2 + res/values/styles.xml | 4 +- src/jackpal/androidterm/Term.java | 94 ++++++++++++++++++++----------- 4 files changed, 67 insertions(+), 36 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 8c271a7..0a12c80 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,7 +1,6 @@ - + android:versionName="1.0.21" android:versionCode="22"> Right Alt key Vol Up key Vol Down key + Camera key @@ -114,6 +115,7 @@ 3 4 5 + 6 diff --git a/res/values/styles.xml b/res/values/styles.xml index 0e59f4a..213c38d 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -4,9 +4,9 @@ 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. diff --git a/src/jackpal/androidterm/Term.java b/src/jackpal/androidterm/Term.java index 8294ed3..36be5ec 100644 --- a/src/jackpal/androidterm/Term.java +++ b/src/jackpal/androidterm/Term.java @@ -134,7 +134,7 @@ public class Term extends Activity { private int mCursorBlink = 0; private int mFontSize = 9; private int mColorId = 2; - private int mControlKeyId = 0; + private int mControlKeyId = 5; // Default to Volume Down private int mUseCookedIME = 0; private static final String STATUSBAR_KEY = "statusbar"; @@ -163,10 +163,11 @@ public class Term extends Activity { KeyEvent.KEYCODE_ALT_LEFT, KeyEvent.KEYCODE_ALT_RIGHT, KeyEvent.KEYCODE_VOLUME_UP, - KeyEvent.KEYCODE_VOLUME_DOWN + KeyEvent.KEYCODE_VOLUME_DOWN, + KeyEvent.KEYCODE_CAMERA }; private static final String[] CONTROL_KEY_NAME = { - "Ball", "@", "Left-Alt", "Right-Alt", "Vol-Up", "Vol-Dn" + "Ball", "@", "Left-Alt", "Right-Alt", "Vol-Up", "Vol-Dn", "Camera" }; private int mControlKeyCode; @@ -563,14 +564,19 @@ public class Term extends Activity { String controlKey = CONTROL_KEY_NAME[mControlKeyId]; new AlertDialog.Builder(this). setTitle("Press " + controlKey + " and Key"). - setMessage(controlKey + " Space ==> Control-@ (NUL)\n" - + controlKey + " A..Z ==> Control-A..Z\n" - + controlKey + " 1 ==> Control-[ (ESC)\n" - + controlKey + " 5 ==> Control-_\n" - + controlKey + " . ==> Control-\\\n" - + controlKey + " 0 ==> Control-]\n" - + controlKey + " 6 ==> Control-^"). - show(); + setMessage(controlKey + " Space : Control-@ (NUL)\n" + + controlKey + " A..Z : Control-A..Z\n" + + controlKey + " 1 : Control-[ (ESC)\n" + + controlKey + " 2 : Control-_\n" + + controlKey + " 3 : Control-^\n" + + controlKey + " 4 : Control-]\n" + + controlKey + " 5 : | (pipe)\n" + + controlKey + " 6 : Left arrow\n" + + controlKey + " 7 : Down arrow\n" + + controlKey + " 8 : Up arrow\n" + + controlKey + " 9 : Right arrow\n" + + controlKey + " . : Control-\\" + ).show(); } private void doToggleSoftKeyboard() { @@ -2873,8 +2879,10 @@ class EmulatorView extends View implements GestureDetector.OnGestureListener { } private void mapAndSend(int c) throws IOException { - mTermOut.write( - mKeyListener.mapControlChar(c)); + int result = mKeyListener.mapControlChar(c); + if (result < TermKeyListener.KEYCODE_OFFSET) { + mTermOut.write(result); + } } public boolean beginBatchEdit() { @@ -4187,6 +4195,8 @@ class TermKeyListener { private boolean mCapsLock; + static public final int KEYCODE_OFFSET = 1000; + /** * Construct a term key listener. * @@ -4215,12 +4225,22 @@ class TermKeyListener { result = 27; } else if ((result == '\\') || (result == '.')) { result = 28; - } else if ((result == ']') || (result == '0')) { + } else if ((result == ']') || (result == '4')) { result = 29; - } else if ((result == '^') || (result == '6')) { + } else if ((result == '^') || (result == '3')) { result = 30; // control-^ - } else if ((result == '_') || (result == '5')) { + } else if ((result == '_') || (result == '2')) { result = 31; + } else if ((result == '5')) { + result = '|'; + } else if ((result == '6')) { + result = KEYCODE_OFFSET + KeyEvent.KEYCODE_DPAD_LEFT; + } else if ((result == '7')) { + result = KEYCODE_OFFSET + KeyEvent.KEYCODE_DPAD_DOWN; + } else if ((result == '8')) { + result = KEYCODE_OFFSET + KeyEvent.KEYCODE_DPAD_UP; + } else if ((result == '9')) { + result = KEYCODE_OFFSET + KeyEvent.KEYCODE_DPAD_RIGHT; } } @@ -4229,6 +4249,7 @@ class TermKeyListener { mCapKey.adjustAfterKeypress(); mControlKey.adjustAfterKeypress(); } + return result; } @@ -4239,21 +4260,8 @@ class TermKeyListener { * */ public void keyDown(int keyCode, KeyEvent event, OutputStream out, boolean appMode) throws IOException { - if (keyCode >= 0 && keyCode < mKeyCodes.length) { - String code = null; - if (appMode) { - code = mAppKeyCodes[keyCode]; - } - if (code == null) { - code = mKeyCodes[keyCode]; - } - if (code != null) { - int length = code.length(); - for (int i = 0; i < length; i++) { - out.write(code.charAt(i)); - } - return; - } + if (handleKeyCode(keyCode, out, appMode)) { + return; } int result = -1; switch (keyCode) { @@ -4288,11 +4296,33 @@ class TermKeyListener { result = mapControlChar(result); - if (result >= 0) { + if (result >= KEYCODE_OFFSET) { + handleKeyCode(result - KEYCODE_OFFSET, out, appMode); + } else if (result >= 0) { out.write(result); } } + private boolean handleKeyCode(int keyCode, OutputStream out, boolean appMode) throws IOException { + if (keyCode >= 0 && keyCode < mKeyCodes.length) { + String code = null; + if (appMode) { + code = mAppKeyCodes[keyCode]; + } + if (code == null) { + code = mKeyCodes[keyCode]; + } + if (code != null) { + int length = code.length(); + for (int i = 0; i < length; i++) { + out.write(code.charAt(i)); + } + return true; + } + } + return false; + } + /** * Handle a keyUp event. *