diff --git a/app/LAYOUT.md b/app/LAYOUT.md index 643f642..fdc5631 100644 --- a/app/LAYOUT.md +++ b/app/LAYOUT.md @@ -6,8 +6,14 @@ features a voice input key, a language change key, an emoji key, a menu, and ext This choice of symbols is strange, because all of those keys can be easily accessed using your right hand on the Alt key, and the left hand on any of those symbols (they are available on the left half of the keyboard). What is obstructed by the right hand though is the numbers. This is what the -symbol bar should contain. +symbol bar should contain, and it should look like this: -Additionally, it should contain some symbols that are unavailable on the physical keyboard. That is -the symbols "$", "%", "&", "=". However, as those are not used as often as numbers, they should be -hidden away in a collapsed menu along with more, less frequently used symbols. \ No newline at end of file +(1) (2) (3) (4) (5) (6) (7) (8) (9) (0) + +When pressing the shift key, the number bar should change into a symbol bar. This will contain all +the symbols not found on the physical keyboard. It'll look like this (likely the most needed symbols +are in the middle): + +(^) (\) (|) (=) (%) (&) ($) (<) (>) (MORE) + +When pressing more, additional less-used symbols will be shown. \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index b5bb99b..c23f4fd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,6 @@ android { targetSdk 34 versionCode 1 versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { @@ -28,3 +26,4 @@ android { } } + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0b3cc2f..9d33da9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ diff --git a/app/src/main/java/cfpi_fpsi/eu/titanboard/TitanboardIME.java b/app/src/main/java/cfpi_fpsi/eu/titanboard/TitanboardIME.java index e1a8458..48fc514 100644 --- a/app/src/main/java/cfpi_fpsi/eu/titanboard/TitanboardIME.java +++ b/app/src/main/java/cfpi_fpsi/eu/titanboard/TitanboardIME.java @@ -1,10 +1,10 @@ package cfpi_fpsi.eu.titanboard; import android.inputmethodservice.InputMethodService; -import android.util.Log; +import android.inputmethodservice.Keyboard; +import android.inputmethodservice.KeyboardView; import android.view.KeyEvent; import android.view.View; -import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import org.xmlpull.v1.XmlPullParser; @@ -13,71 +13,68 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.HashMap; -public class TitanboardIME extends InputMethodService { - private HashMap keymap; +public class TitanboardIME extends InputMethodService implements KeyboardView.OnKeyboardActionListener { + private HashMap mKeymap; + + private boolean mShiftOn = false; + private boolean mAltOn = false; + + private KeyboardView mInputView; + private Keyboard mKeyboard; @Override public void onCreate() { super.onCreate(); - keymap = new HashMap<>(); - // We load the keymap from the XML file into a variable - XmlPullParser parser = getResources().getXml(getResources() - .getIdentifier("keymap_titan", "xml", getPackageName())); - int code = 0; - int value = 0; - int alt = 0; + mKeymap = new HashMap<>(); + XmlPullParser parser = getResources().getXml(R.xml.keymap_titan); + int code = 0, value = 0, valueAlt = 0; + try { while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { - switch (parser.getEventType()) { - case XmlPullParser.START_TAG: - if (parser.getName().equals("key")) { - for (int i = 0; i < parser.getAttributeCount(); ++i) { - switch (parser.getAttributeName(i)) { - case "code": - code = Integer.parseInt(parser.getAttributeValue(i)); - Log.d("STATE", "KeyCode: " + code); - break; - case "value": - value = Integer.parseInt(String.valueOf(parser.getAttributeValue(i).codePointAt(0))); - break; - case "alt": - alt = Integer.parseInt(String.valueOf(parser.getAttributeValue(i).codePointAt(0))); - break; - } - } + int type = parser.getEventType(); + if (type == XmlPullParser.START_TAG && parser.getName().equals("key")) { + for (int i = 0; i < parser.getAttributeCount(); ++i) { + String attr = parser.getAttributeName(i); + if (attr.equals("code")) { + code = Integer.parseInt(parser.getAttributeValue(i)); + } else if (attr.equals("value")) { + value = Integer.parseInt(String.valueOf(parser.getAttributeValue(i).codePointAt(0))); + } else if (attr.equals("valueAlt")) { + valueAlt = Integer.parseInt(String.valueOf(parser.getAttributeValue(i).codePointAt(0))); } - break; - case XmlPullParser.END_TAG: - if (parser.getName().equals("key")) { - Log.d("STATE", "Adding KeyCode " + code + " which corresponds to: " + value + " and " + alt); - keymap.put(code, new int[] { value, alt }); - } - break; - default: - break; + } + } else if (type == XmlPullParser.END_TAG && parser.getName().equals("key")) { + mKeymap.put(code, new int[]{value, valueAlt}); } parser.next(); } - } catch (XmlPullParserException e) { - throw new RuntimeException(e); - } catch (IOException e) { + } catch (XmlPullParserException | IOException e) { throw new RuntimeException(e); } } @Override - public View onCreateInputView() { - return getLayoutInflater().inflate(R.layout.input, null); + public void onInitializeInterface() { + mInputView = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard_symbol, null); + mKeyboard = new Keyboard(this, R.xml.keylayout_symbol); + mInputView.setKeyboard(mKeyboard); + mInputView.setOnKeyboardActionListener(this); + } + + @Override + public boolean onEvaluateFullscreenMode() { + // This is to override the default behaviour, which seems to do more than detect landscape + // mode. + return false; } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { InputConnection conn = getCurrentInputConnection(); - EditorInfo info = getCurrentInputEditorInfo(); - if (conn == null || info == null) { + if (conn == null) { return false; } @@ -94,20 +91,37 @@ public class TitanboardIME extends InputMethodService { return false; // If it's the backspace key, we remove one character. case KeyEvent.KEYCODE_DEL: - conn.deleteSurroundingText(1, 0); - return true; - // We suppress the alt keys so the system cannot use them. + CharSequence selection = conn.getSelectedText(0); + if (selection != null) { + // This IME won't handle it, and in turn the whole selection gets deleted. + return false; + } else { + conn.deleteSurroundingText(1, 0); + return true; + } case KeyEvent.KEYCODE_ALT_LEFT: case KeyEvent.KEYCODE_ALT_RIGHT: + mAltOn = !mAltOn; + mShiftOn = false; + return true; + case KeyEvent.KEYCODE_SHIFT_LEFT: + case KeyEvent.KEYCODE_SHIFT_RIGHT: + mShiftOn = !mShiftOn; + mAltOn = false; + return true; + case KeyEvent.KEYCODE_SPACE: + conn.commitText(" ", 1); return true; default: // And we send the character to the app. - int[] key = keymap.get(keyCode); + int[] key = mKeymap.get(keyCode); if (key != null) { - if (event.isAltPressed()) { + if (mAltOn) { conn.commitText(new String(Character.toChars(key[1])), 1); - } else if (event.isShiftPressed()) { + mAltOn = false; + } else if (mShiftOn) { conn.commitText(new String(Character.toChars(key[0])).toUpperCase(), 1); + mShiftOn = false; } else { conn.commitText(new String(Character.toChars(key[0])), 1); } @@ -117,4 +131,53 @@ public class TitanboardIME extends InputMethodService { } } } + + @Override + public View onCreateInputView() { + return mInputView; + } + + @Override + public void onPress(int primaryCode) { + + } + + @Override + public void onRelease(int primaryCode) { + + } + + @Override + public void onKey(int primaryCode, int[] keyCodes) { + InputConnection conn = getCurrentInputConnection(); + + if (conn != null) { + conn.commitText(String.valueOf((char) primaryCode), 1); + } + } + + @Override + public void onText(CharSequence text) { + + } + + @Override + public void swipeLeft() { + + } + + @Override + public void swipeRight() { + + } + + @Override + public void swipeDown() { + + } + + @Override + public void swipeUp() { + + } } diff --git a/app/src/main/res/layout/input.xml b/app/src/main/res/layout/input.xml deleted file mode 100644 index 0e34f4c..0000000 --- a/app/src/main/res/layout/input.xml +++ /dev/null @@ -1,155 +0,0 @@ - - - - - -