aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2014-10-18 17:46:22 -0700
committerKenny Root <kenny@the-b.org>2014-10-18 17:46:22 -0700
commitf519fbc5df862360e0dc500eb9e100c81dd16499 (patch)
tree3896e148416066a15a929027de01595ba61461b4 /app/src/main
parent06dd2c10e044ffe770c0baee3f08eacc074ed6b0 (diff)
downloadconnectbot-f519fbc5df862360e0dc500eb9e100c81dd16499.tar.gz
connectbot-f519fbc5df862360e0dc500eb9e100c81dd16499.tar.bz2
connectbot-f519fbc5df862360e0dc500eb9e100c81dd16499.zip
Add class hiding for KeyEvent debugging
Change-Id: Id34acf00f9ec538d81b72b970ae1990c6ed36510
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/org/connectbot/service/KeyEventUtil.java57
1 files changed, 54 insertions, 3 deletions
diff --git a/app/src/main/java/org/connectbot/service/KeyEventUtil.java b/app/src/main/java/org/connectbot/service/KeyEventUtil.java
index 8ad645d..1362afa 100644
--- a/app/src/main/java/org/connectbot/service/KeyEventUtil.java
+++ b/app/src/main/java/org/connectbot/service/KeyEventUtil.java
@@ -16,6 +16,8 @@
*/
package org.connectbot.service;
+import android.annotation.TargetApi;
+import android.os.Build;
import android.view.KeyEvent;
public class KeyEventUtil {
@@ -75,10 +77,60 @@ public class KeyEventUtil {
return sb.append('"').toString();
}
+ private static class ClassCompat {
+ private static final ClassCompat INSTANCE;
+ static {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
+ INSTANCE = new HCMR2AndNewer();
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
+ INSTANCE = new HCMR1AndNewer();
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
+ INSTANCE = new GingerbreadAndNewer();
+ } else {
+ INSTANCE = new ClassCompat();
+ }
+ }
+
+ private ClassCompat() {
+ }
+
+ public static void appendExtras(StringBuilder d, int keyCode, KeyEvent event) {
+ INSTANCE.appendForApi(d, keyCode, event);
+ }
+
+ protected void appendForApi(StringBuilder d, int keyCode, KeyEvent event) {
+ }
+
+ @TargetApi(9)
+ private static class GingerbreadAndNewer extends ClassCompat {
+ @Override
+ protected void appendForApi(StringBuilder d, int keyCode, KeyEvent event) {
+ super.appendForApi(d, keyCode, event);
+ d.append(", source=").append(event.getSource());
+
+ }
+ }
+ @TargetApi(12)
+ private static class HCMR1AndNewer extends GingerbreadAndNewer {
+ protected void appendForApi(StringBuilder d, int keyCode, KeyEvent event) {
+ super.appendForApi(d, keyCode, event);
+ d.append(", keyCodeToString=").append(KeyEvent.keyCodeToString(keyCode));
+ }
+ }
+
+ @TargetApi(13)
+ private static class HCMR2AndNewer extends HCMR1AndNewer {
+ @Override
+ protected void appendForApi(StringBuilder d, int keyCode, KeyEvent event) {
+ super.appendForApi(d, keyCode, event);
+ d.append(", modifiers=").append(Integer.toHexString(event.getModifiers()));
+ }
+ }
+ }
+
public static String describeKeyEvent(int keyCode, KeyEvent event) {
StringBuilder d = new StringBuilder();
d.append("keyCode=").append(keyCode);
- d.append(", keyCodeToString=").append(KeyEvent.keyCodeToString(keyCode));
d.append(", event.toString=").append(event.toString());
d.append(", action=").append(event.getAction());
d.append(", characters=").append(printableRepresentation(event.getCharacters()));
@@ -88,11 +140,10 @@ public class KeyEventUtil {
d.append(", printingKey=").append(event.isPrintingKey());
d.append(", keyCode=").append(event.getKeyCode());
d.append(", metaState=0x").append(Integer.toHexString(event.getMetaState()));
- d.append(", modifiers=0x").append(Integer.toHexString(event.getModifiers()));
d.append(", number=").append((int) event.getNumber());
d.append(", scanCode=").append(event.getScanCode());
- d.append(", source=").append(event.getSource());
d.append(", unicodeChar=").append(event.getUnicodeChar());
+ ClassCompat.appendExtras(d, keyCode, event);
return d.toString();
}
}