diff --git a/app/src/main/java/green_green_avk/anotherterm/App.java b/app/src/main/java/green_green_avk/anotherterm/App.java
index 7f1a3937..c935a914 100644
--- a/app/src/main/java/green_green_avk/anotherterm/App.java
+++ b/app/src/main/java/green_green_avk/anotherterm/App.java
@@ -65,12 +65,12 @@ protected void onAfterChange(@NonNull final String key, @Nullable final Object v
}
public final Settings settings = new Settings();
- private static Settings sSettings = null;
+// private static Settings sSettings = null;
- @Nullable
- public static Settings getSettings() {
- return sSettings;
- }
+// @Nullable
+// public static Settings getSettings() {
+// return sSettings;
+// }
public ScratchpadManager scratchpadManager = null;
@@ -87,7 +87,7 @@ public void onCreate() {
super.onCreate();
PluginsManager.init(this);
settings.init(this, PreferenceManager.getDefaultSharedPreferences(this));
- sSettings = settings;
+// sSettings = settings;
FontsManager.init(this);
FontsManager.setFrom(settings.terminal_font_default_fromfiles);
TermKeyMapManager.init(this);
diff --git a/app/src/main/java/green_green_avk/anotherterm/HwKeyMapEditorFragment.java b/app/src/main/java/green_green_avk/anotherterm/HwKeyMapEditorFragment.java
index 0b4ff326..fe14060a 100644
--- a/app/src/main/java/green_green_avk/anotherterm/HwKeyMapEditorFragment.java
+++ b/app/src/main/java/green_green_avk/anotherterm/HwKeyMapEditorFragment.java
@@ -24,11 +24,14 @@
import green_green_avk.anotherterm.ui.HwKeyMap;
public final class HwKeyMapEditorFragment extends Fragment {
- private static final int[] devIdsDict = new int[HwKeyMapTable.DEV_IDS_NUM];
+ private static final int[] devIdsDict = new int[]{
+ R.string.label_dev_built_in,
+ R.string.label_dev_external
+ };
- static {
- devIdsDict[HwKeyMapTable.BUILT_IN] = R.string.label_built_in;
- devIdsDict[HwKeyMapTable.EXTERNAL] = R.string.label_external;
+ private int getDevIdLabel(final int devId) {
+ if (devId < 0 || devId >= devIdsDict.length) return R.string.label_dev_unknown;
+ return devIdsDict[devId];
}
private final class ToKeycode {
@@ -121,7 +124,7 @@ public View getView(final int position, final View convertView, final ViewGroup
.inflate(R.layout.hw_key_map_editor_entry, parent, false);
final HwKeyMapTable.Entry entry = keymap.getEntry(position);
v.findViewById(R.id.keycode).setText(TermKeyMap.keyCodeToString(entry.keycode));
- v.findViewById(R.id.devId).setText(devIdsDict[entry.devId]);
+ v.findViewById(R.id.devId).setText(getDevIdLabel(entry.devId));
final Spinner wToKeycode = v.findViewById(R.id.toKeycode);
final List al = KeyEvent.isModifierKey(entry.keycode) ?
toKeycodeListForModifiers : toKeycodeList;
diff --git a/app/src/main/java/green_green_avk/anotherterm/HwKeyMapManager.java b/app/src/main/java/green_green_avk/anotherterm/HwKeyMapManager.java
index ac35c9c9..192b4f6f 100644
--- a/app/src/main/java/green_green_avk/anotherterm/HwKeyMapManager.java
+++ b/app/src/main/java/green_green_avk/anotherterm/HwKeyMapManager.java
@@ -2,6 +2,7 @@
import android.content.Context;
import android.content.SharedPreferences;
+import android.os.Build;
import android.util.SparseIntArray;
import android.view.InputDevice;
import android.view.KeyCharacterMap;
@@ -66,20 +67,29 @@ public static void set(@NonNull final HwKeyMap hwKeyMap) {
else throw new IllegalArgumentException("Unable to process this HwKeyMap type");
}
+ public static boolean isVirtual(@NonNull final KeyEvent event) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
+ return event.getDevice().isVirtual();
+ return event.getDeviceId() == KeyCharacterMap.VIRTUAL_KEYBOARD;
+ }
+
+ public static boolean isExternal(@NonNull final KeyEvent event) {
+ // We can only guess before API 29.
+ return event.getDeviceId() > KeyCharacterMap.SPECIAL_FUNCTION;
+ }
+
public static boolean isBypassKey(@NonNull final KeyEvent event) {
if ((event.getSource() & InputDevice.SOURCE_ANY & (
InputDevice.SOURCE_MOUSE
| InputDevice.SOURCE_STYLUS
| InputDevice.SOURCE_TRACKBALL
)) != 0) return true; // Mouse right & middle buttons...
- if (event.getDeviceId() == KeyCharacterMap.VIRTUAL_KEYBOARD) return event.isSystem();
- if (event.getDeviceId() <= KeyCharacterMap.SPECIAL_FUNCTION)
+ if (isVirtual(event)) return event.isSystem();
+ if (!isExternal(event))
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_HOME:
- case KeyEvent.KEYCODE_VOLUME_UP: // Font size.
- case KeyEvent.KEYCODE_VOLUME_DOWN: // Font size.
case KeyEvent.KEYCODE_POWER:
- return true; // Don't prevent default behavior.
+ return true; // Just in case.
}
return false;
}
diff --git a/app/src/main/java/green_green_avk/anotherterm/HwKeyMapTable.java b/app/src/main/java/green_green_avk/anotherterm/HwKeyMapTable.java
index 3bf7f413..840cc371 100644
--- a/app/src/main/java/green_green_avk/anotherterm/HwKeyMapTable.java
+++ b/app/src/main/java/green_green_avk/anotherterm/HwKeyMapTable.java
@@ -1,7 +1,6 @@
package green_green_avk.anotherterm;
import android.util.SparseIntArray;
-import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import androidx.annotation.NonNull;
@@ -11,18 +10,17 @@
public final class HwKeyMapTable extends HwKeyMap {
public static final int BUILT_IN = 0;
public static final int EXTERNAL = 1;
- public static final int DEV_IDS_NUM = 2;
private final SparseIntArray map = new SparseIntArray();
private int key(final int keycode, final int devId) {
- return (keycode & 0xFFFF) | ((devId & 0xFFFF) << 16);
+ return (keycode & 0xFFFF) | (devId << 16);
}
@Override
public int getDevId(@NonNull final KeyEvent event) {
- if (event.getDeviceId() == KeyCharacterMap.VIRTUAL_KEYBOARD) return -1; // Of no use.
- return event.getDeviceId() <= KeyCharacterMap.SPECIAL_FUNCTION ? BUILT_IN : EXTERNAL;
+ if (HwKeyMapManager.isVirtual(event)) return -1; // Of no use.
+ return HwKeyMapManager.isExternal(event) ? EXTERNAL : BUILT_IN;
}
@Override
@@ -44,7 +42,7 @@ static final class Entry {
private Entry(final int key, final int toKeycode) {
keycode = key & 0xFFFF;
- devId = key >>> 16;
+ devId = key >> 16;
this.toKeycode = toKeycode;
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9528464a..f32133d9 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -258,8 +258,6 @@
Please, don\'t hesitate report anything you have doubts about:
it\'s an experimental feature.
- VOLUME_UP and VOLUME_DOWN buttons
- are already used for font size adjustment and thus cannot be mapped.
- \"Block\" means \"Completely turn off a key\"
- \"Bypass\" means \"Bypass as is and use to determine the final key code only,
@@ -271,10 +269,13 @@
Android own modifier flags are used by default
but in some cases they could be broken by IME.
Mapping a modifier key to itself could help in this case.
+ Note: This application own screen keyboard is not affected by and does not affect
+ Android soft input / hardware keyboard modifier keys state.
]]>
Press a key to add
- Built-in
- External
+ Unknown
+ Built-in
+ External
Block
Bypass