Skip to content

Commit

Permalink
Graphical console keyboard refactoring: Step 3
Browse files Browse the repository at this point in the history
  • Loading branch information
green-green-avk committed Jan 31, 2022
1 parent 07a4ca6 commit 4f8d4d8
Show file tree
Hide file tree
Showing 10 changed files with 674 additions and 67 deletions.
4 changes: 4 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
*;
}

-keep class green_green_avk.anotherterm.wlterm.protocol.** {
*;
}

#-dontshrink
#-dontoptimize
#-dontobfuscate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void setSink(@Nullable final Sink sink) {
public final IConsoleOutput consoleOutput = new IConsoleOutput() {
@Override
public boolean getKeyAutorepeat() {
return false;
return true; // Text input mode only
}

@Override
Expand Down
163 changes: 148 additions & 15 deletions app/src/main/java/green_green_avk/anotherterm/ui/ExtKeyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import android.util.TypedValue;
import android.util.Xml;
import android.view.InflateException;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -81,22 +80,156 @@ public class ExtKeyboard {
public static final int ALT = 2;
public static final int CTRL = 4;

private static final int[] ascii2Codes = new int[128];

static {
final KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
for (int i = KeyEvent.KEYCODE_0; i <= KeyEvent.KEYCODE_9; i++) {
ascii2Codes[kcm.get(i, 0)] = i;
ascii2Codes[kcm.get(i, KeyEvent.META_SHIFT_ON)] = i;
}
for (int i = KeyEvent.KEYCODE_A; i <= KeyEvent.KEYCODE_Z; i++) {
ascii2Codes[kcm.get(i, 0)] = i;
ascii2Codes[kcm.get(i, KeyEvent.META_SHIFT_ON)] = i;
}
}
private static final int[] ascii2KeyCode = {
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,

KEYCODE_NONE,
KeyEvent.KEYCODE_TAB,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,

KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,

KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,
KEYCODE_NONE,

KeyEvent.KEYCODE_SPACE,
KeyEvent.KEYCODE_1,
KeyEvent.KEYCODE_APOSTROPHE,
KeyEvent.KEYCODE_3,
KeyEvent.KEYCODE_4,
KeyEvent.KEYCODE_5,
KeyEvent.KEYCODE_7,
KeyEvent.KEYCODE_APOSTROPHE,

KeyEvent.KEYCODE_9,
KeyEvent.KEYCODE_0,
KeyEvent.KEYCODE_8,
KeyEvent.KEYCODE_EQUALS,
KeyEvent.KEYCODE_COMMA,
KeyEvent.KEYCODE_MINUS,
KeyEvent.KEYCODE_PERIOD,
KeyEvent.KEYCODE_SLASH,

KeyEvent.KEYCODE_0,
KeyEvent.KEYCODE_1,
KeyEvent.KEYCODE_2,
KeyEvent.KEYCODE_3,
KeyEvent.KEYCODE_4,
KeyEvent.KEYCODE_5,
KeyEvent.KEYCODE_6,
KeyEvent.KEYCODE_7,

KeyEvent.KEYCODE_8,
KeyEvent.KEYCODE_9,
KeyEvent.KEYCODE_SEMICOLON,
KeyEvent.KEYCODE_SEMICOLON,
KeyEvent.KEYCODE_COMMA,
KeyEvent.KEYCODE_EQUALS,
KeyEvent.KEYCODE_PERIOD,
KeyEvent.KEYCODE_SLASH,

KeyEvent.KEYCODE_2,
KeyEvent.KEYCODE_A,
KeyEvent.KEYCODE_B,
KeyEvent.KEYCODE_C,
KeyEvent.KEYCODE_D,
KeyEvent.KEYCODE_E,
KeyEvent.KEYCODE_F,
KeyEvent.KEYCODE_G,

KeyEvent.KEYCODE_H,
KeyEvent.KEYCODE_I,
KeyEvent.KEYCODE_J,
KeyEvent.KEYCODE_K,
KeyEvent.KEYCODE_L,
KeyEvent.KEYCODE_M,
KeyEvent.KEYCODE_N,
KeyEvent.KEYCODE_O,

KeyEvent.KEYCODE_P,
KeyEvent.KEYCODE_Q,
KeyEvent.KEYCODE_R,
KeyEvent.KEYCODE_S,
KeyEvent.KEYCODE_T,
KeyEvent.KEYCODE_U,
KeyEvent.KEYCODE_V,
KeyEvent.KEYCODE_W,

KeyEvent.KEYCODE_X,
KeyEvent.KEYCODE_Y,
KeyEvent.KEYCODE_Z,
KeyEvent.KEYCODE_LEFT_BRACKET,
KeyEvent.KEYCODE_BACKSLASH,
KeyEvent.KEYCODE_RIGHT_BRACKET,
KeyEvent.KEYCODE_6,
KeyEvent.KEYCODE_MINUS,

KeyEvent.KEYCODE_GRAVE,
KeyEvent.KEYCODE_A,
KeyEvent.KEYCODE_B,
KeyEvent.KEYCODE_C,
KeyEvent.KEYCODE_D,
KeyEvent.KEYCODE_E,
KeyEvent.KEYCODE_F,
KeyEvent.KEYCODE_G,

KeyEvent.KEYCODE_H,
KeyEvent.KEYCODE_I,
KeyEvent.KEYCODE_J,
KeyEvent.KEYCODE_K,
KeyEvent.KEYCODE_L,
KeyEvent.KEYCODE_M,
KeyEvent.KEYCODE_N,
KeyEvent.KEYCODE_O,

KeyEvent.KEYCODE_P,
KeyEvent.KEYCODE_Q,
KeyEvent.KEYCODE_R,
KeyEvent.KEYCODE_S,
KeyEvent.KEYCODE_T,
KeyEvent.KEYCODE_U,
KeyEvent.KEYCODE_V,
KeyEvent.KEYCODE_W,

KeyEvent.KEYCODE_X,
KeyEvent.KEYCODE_Y,
KeyEvent.KEYCODE_Z,
KeyEvent.KEYCODE_LEFT_BRACKET,
KeyEvent.KEYCODE_BACKSLASH,
KeyEvent.KEYCODE_RIGHT_BRACKET,
KeyEvent.KEYCODE_GRAVE,
KEYCODE_NONE
};

public static int getKeyCodeByAscii(final char c) {
return ascii2Codes[c];
if (c >= ascii2KeyCode.length)
return KEYCODE_NONE;
return ascii2KeyCode[c];
}

// /**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.arch.core.util.Function;
import androidx.core.util.Pools;

import java.util.HashSet;
Expand Down Expand Up @@ -122,6 +123,10 @@ public boolean getAutoRepeat() {
protected int mPopupShadowColor;
protected float mPopupShadowRadius;

public static final Function<ExtKeyboard.Key, ExtKeyboard.Key> popupFunctionsSuppress =
key -> null;
protected Function<ExtKeyboard.Key, ExtKeyboard.Key> popupFunctions = null;

protected int mLabelTextSize;
protected int mKeyTextSize;
protected int mKeyTextColor;
Expand Down Expand Up @@ -356,6 +361,16 @@ public void setLedsByCode(final int code, final boolean on) {
else leds.remove(code);
}

/**
* Override current keys popup
*
* @param v <code>null</code> - don't override; function returning <code>null</code> - suppress
*/
public void setPopupFunctions(@Nullable final Function<ExtKeyboard.Key, ExtKeyboard.Key> v) {
cancelKeys();
popupFunctions = v;
}

/**
* Requests a redraw of the entire keyboard. Calling {@link #invalidate} is not sufficient
* because the keyboard renders the keys to an off-screen buffer and an invalidate() only
Expand Down Expand Up @@ -843,7 +858,10 @@ public View(final Context context) {
@Override
protected void onDraw(final Canvas canvas) {
super.onDraw(canvas);
if (keyState.key == null || keyState.key.functions.size() < 2) return;
if (keyState.key == null || keyState.key.functions.size() < 2)
return;
if (popupFunctions != null)
return;
canvas.save();
if (mPopupBackground != null) {
mPopupBackground.setBounds(0, 0, getWidth(), getHeight());
Expand Down Expand Up @@ -923,7 +941,7 @@ public void invalidate() {
protected ExtKeyboard.KeyFcn _getAltKeyFcn() {
if (ptrD < mPopupKeySize * mPopupKeySize)
return getModifiersAltKeyFcn(keyState.key);
final ExtKeyboard.KeyFcn fcn =
final ExtKeyboard.KeyFcn fcn = popupFunctions != null ? null :
keyState.key.getCircularKeyFcn((int) (ptrA / ptrStep));
if (fcn == null)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ public class GraphicsConsoleKeyboardView extends ExtKeyboardView implements
protected int mode = MODE_VISIBLE;
protected int prevMode = mode;
protected int currMode = mode;
protected boolean textMode = false; // For teh text input!1
protected boolean textMode; // ANSI-keyboard like input

protected void initTextMode(final boolean v) {
textMode = v;
setPopupFunctions(v ? null : popupFunctionsSuppress);
}

{
initTextMode(false);
}

protected int keyHeightDp = 0;
@NonNull
Expand All @@ -75,7 +84,7 @@ public void save(@NonNull final GraphicsConsoleKeyboardView v) {

public void apply(@NonNull final GraphicsConsoleKeyboardView v) {
if (mode == MODE_UNKNOWN) return;
v.textMode = textMode;
v.initTextMode(textMode);
v.setMode(mode);
}
}
Expand Down Expand Up @@ -295,7 +304,7 @@ public boolean isTextMode() {

public void setTextMode(final boolean v) {
if (textMode != v) {
textMode = v;
initTextMode(v);
//reapplyMode();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import green_green_avk.anotherterm.BuildConfig;
import green_green_avk.anotherterm.ConsoleService;
import green_green_avk.anotherterm.GraphicsCompositor;
import green_green_avk.anotherterm.wlterm.protocol.wl_own_helper;
import green_green_avk.ptyprocess.PtyProcess;
import green_green_avk.wayland.os.WlEventHandler;
import green_green_avk.wayland.os.WlMmap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package green_green_avk.anotherterm.wlterm;
package green_green_avk.anotherterm.wlterm.protocol;

import green_green_avk.anotherterm.wlterm.WlOwnCustomException;
import green_green_avk.wayland.protocol_core.WlInterface;

/**
Expand Down
Loading

0 comments on commit 4f8d4d8

Please sign in to comment.