From 32ae47e349711fe8db77a0cd86a71e03e7f70547 Mon Sep 17 00:00:00 2001 From: Emil Kosz Date: Wed, 13 Nov 2024 17:01:31 +0100 Subject: [PATCH] Fix alt+backspace deleting lines of text, add Greek question mark under Alt+X in Greek layout, move Arabic diacritics to shifted symbols, fix button being displayed in all caps --- app/build.gradle | 4 +-- app/src/main/AndroidManifest.xml | 2 +- .../eur/cfpifpsi/titanboard/ClipManager.java | 12 ++++---- .../eur/cfpifpsi/titanboard/InputView.java | 24 +++++++-------- .../cfpifpsi/titanboard/MetaKeyManager.java | 16 +++++----- .../{InputMethod.java => TitanboardIME.java} | 23 +++++++++++---- app/src/main/res/layout/input.xml | 1 + app/src/main/res/xml/keymaps_titan.xml | 29 ++++++++++--------- 8 files changed, 62 insertions(+), 49 deletions(-) rename app/src/main/java/eur/cfpifpsi/titanboard/{InputMethod.java => TitanboardIME.java} (92%) diff --git a/app/build.gradle b/app/build.gradle index cdc1a22..176c533 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId 'eur.cfpifpsi.titanboard' minSdk 3 targetSdk 35 - versionCode 30 - versionName '0.3' + versionCode 31 + versionName '0.3.1' } buildTypes { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0382a50..5a3aa9d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,7 +33,7 @@ android:shell="true" tools:targetApi="q" /> mClips; private long mLastCallbackTimestamp; public ClipManager(Context context) { - mInputMethod = (InputMethod) context; - mClips = new ArrayList<>(mInputMethod.mPreferenceHolder.getClipboardSize()); + mTitanboardIME = (TitanboardIME) context; + mClips = new ArrayList<>(mTitanboardIME.mPreferenceHolder.getClipboardSize()); mClipboardManager = (ClipboardManager) - mInputMethod.getSystemService(Context.CLIPBOARD_SERVICE); + mTitanboardIME.getSystemService(Context.CLIPBOARD_SERVICE); mClipboardManager.addPrimaryClipChangedListener(this); } @@ -58,12 +58,12 @@ public class ClipManager implements ClipboardManager.OnPrimaryClipChangedListene mClips.add(0, item); } - if (mClips.size() > mInputMethod.mPreferenceHolder.getClipboardSize()) { + if (mClips.size() > mTitanboardIME.mPreferenceHolder.getClipboardSize()) { mClips.remove(mClips.size() - 1); } } - mInputMethod.mInputView.setClips(mClips); + mTitanboardIME.mInputView.setClips(mClips); } } } diff --git a/app/src/main/java/eur/cfpifpsi/titanboard/InputView.java b/app/src/main/java/eur/cfpifpsi/titanboard/InputView.java index 932cb26..c1a6097 100644 --- a/app/src/main/java/eur/cfpifpsi/titanboard/InputView.java +++ b/app/src/main/java/eur/cfpifpsi/titanboard/InputView.java @@ -43,7 +43,7 @@ import java.util.ArrayList; public final class InputView extends RelativeLayout { private final int[] buttonStateToggled = {R.attr.state_toggled}; - private final InputMethod mInputMethod; + private final TitanboardIME mTitanboardIME; private final LinearLayout.LayoutParams mSymbolLayout; private final LinearLayout.LayoutParams mClipLayout; public PopupWindow mClipboardPopup; @@ -54,7 +54,7 @@ public final class InputView extends RelativeLayout { public InputView(Context context, AttributeSet attrs) { super(context, attrs, 0); - mInputMethod = (InputMethod) context; + mTitanboardIME = (TitanboardIME) context; mSymbolLayout = new LinearLayout.LayoutParams( getResources().getDimensionPixelSize(R.dimen.symbol_width), ViewGroup.LayoutParams.MATCH_PARENT, 0); @@ -77,12 +77,12 @@ public final class InputView extends RelativeLayout { mClipboardPopup.setOnDismissListener(() -> mClipboardButton.setImageState(null, true)); mStateButton.setOnClickListener(button -> { - MetaKeyManager metaManager = mInputMethod.mMetaKeyManager; + MetaKeyManager metaManager = mTitanboardIME.mMetaKeyManager; if (metaManager.getAlt().isActive()) { metaManager.getAlt().resetState(); } else { - mInputMethod.mKeymapManager - .nextKeymap(mInputMethod.mPreferenceHolder.getSelectedKeymaps()); + mTitanboardIME.mKeymapManager + .nextKeymap(mTitanboardIME.mPreferenceHolder.getSelectedKeymaps()); } updateStateText(); }); @@ -103,10 +103,10 @@ public final class InputView extends RelativeLayout { mClipboardButton.setOnLongClickListener(button -> { // On a long click, we just send the latest clip (if any). - if (!mInputMethod.mClipManager.isEmpty() + if (!mTitanboardIME.mClipManager.isEmpty() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - mInputMethod.getCurrentInputConnection() - .commitText(mInputMethod.mClipManager.getItemAt(0).getText(), 1); + mTitanboardIME.getCurrentInputConnection() + .commitText(mTitanboardIME.mClipManager.getItemAt(0).getText(), 1); } return true; @@ -117,8 +117,8 @@ public final class InputView extends RelativeLayout { * @noinspection FeatureEnvy */ public void updateStateText() { - MetaKeyManager metaManager = mInputMethod.mMetaKeyManager; - KeymapManager keymapManager = mInputMethod.mKeymapManager; + MetaKeyManager metaManager = mTitanboardIME.mMetaKeyManager; + KeymapManager keymapManager = mTitanboardIME.mKeymapManager; mStateButton.setPaintFlags(mStateButton.getPaintFlags() & ~(Paint.UNDERLINE_TEXT_FLAG)); @@ -165,13 +165,13 @@ public final class InputView extends RelativeLayout { Button pasteButton = clipView.findViewById(R.id.paste_button); pasteButton.setText(item.getText()); - pasteButton.setOnClickListener(button -> mInputMethod.getCurrentInputConnection() + pasteButton.setOnClickListener(button -> mTitanboardIME.getCurrentInputConnection() .commitText(item.getText(), 1)); LinearLayout finalClipView = clipView; clipView.findViewById(R.id.button_delete).setOnClickListener(button -> { mClipList.removeView(finalClipView); - mInputMethod.mClipManager.removeItem(item); + mTitanboardIME.mClipManager.removeItem(item); }); } } diff --git a/app/src/main/java/eur/cfpifpsi/titanboard/MetaKeyManager.java b/app/src/main/java/eur/cfpifpsi/titanboard/MetaKeyManager.java index 5b50808..22456f2 100644 --- a/app/src/main/java/eur/cfpifpsi/titanboard/MetaKeyManager.java +++ b/app/src/main/java/eur/cfpifpsi/titanboard/MetaKeyManager.java @@ -32,25 +32,25 @@ public class MetaKeyManager { mVibrator = vibrator; } - public void updateMetaStateDown(int keyCode) { + public boolean updateMetaStateDown(int keyCode) { switch (keyCode) { case KeyEvent.KEYCODE_ALT_LEFT: case KeyEvent.KEYCODE_ALT_RIGHT: mAlt.onDown(); - break; + return true; case KeyEvent.KEYCODE_SHIFT_LEFT: case KeyEvent.KEYCODE_SHIFT_RIGHT: mShift.onDown(); - break; + return true; default: - break; + return false; } } /** * @noinspection FeatureEnvy */ - public void updateMetaStateUp(int keyCode, KeyEvent event) { + public boolean updateMetaStateUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_ALT_LEFT: case KeyEvent.KEYCODE_ALT_RIGHT: @@ -58,16 +58,16 @@ public class MetaKeyManager { if (mAlt.isLocked()) { mVibrator.vibrate(TOGGLE_VIBRATION_TIME); } - break; + return true; case KeyEvent.KEYCODE_SHIFT_LEFT: case KeyEvent.KEYCODE_SHIFT_RIGHT: mShift.onUp(event); if (mShift.isLocked()) { mVibrator.vibrate(TOGGLE_VIBRATION_TIME); } - break; + return true; default: - break; + return false; } } diff --git a/app/src/main/java/eur/cfpifpsi/titanboard/InputMethod.java b/app/src/main/java/eur/cfpifpsi/titanboard/TitanboardIME.java similarity index 92% rename from app/src/main/java/eur/cfpifpsi/titanboard/InputMethod.java rename to app/src/main/java/eur/cfpifpsi/titanboard/TitanboardIME.java index 2c47eff..25a1443 100644 --- a/app/src/main/java/eur/cfpifpsi/titanboard/InputMethod.java +++ b/app/src/main/java/eur/cfpifpsi/titanboard/TitanboardIME.java @@ -34,7 +34,7 @@ import java.util.ArrayList; // TODO: Implement device recognition and a keymap picking based on it. -public class InputMethod extends InputMethodService { +public class TitanboardIME extends InputMethodService { public MetaKeyManager mMetaKeyManager; public KeymapManager mKeymapManager; public PreferenceHolder mPreferenceHolder; @@ -88,8 +88,10 @@ public class InputMethod extends InputMethodService { */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - mMetaKeyManager.updateMetaStateDown(keyCode); - mInputView.updateStateText(); + if (mMetaKeyManager.updateMetaStateDown(keyCode)) { + mInputView.updateStateText(); + return true; + } if (keyCode == KeyEvent.KEYCODE_BACK) { if (isInputViewShown()) { @@ -99,6 +101,11 @@ public class InputMethod extends InputMethodService { return false; } + // Workaround for default Android behaviour that pisses people off. + if (keyCode == KeyEvent.KEYCODE_DEL && (event.isAltPressed() || event.isShiftPressed())) { + return true; + } + if (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_ENTER) { mMetaKeyManager.adjustMetaStateAfterKeypress(); mInputView.updateStateText(); @@ -124,7 +131,8 @@ public class InputMethod extends InputMethodService { if (mPreferenceHolder.isCycleManualOn()) { boolean isCycling = mHandler.hasMessages(0); - if (isCycling && keyCode == mLastSymbolKeyCode && symbols.size() > 1) { + if (isCycling && keyCode == mLastSymbolKeyCode + && mSymbolManualCycler.getList().size() > 1) { mSymbolManualCycler.run(); } else { mFinishCyclingRunnable.run(); @@ -155,8 +163,11 @@ public class InputMethod extends InputMethodService { mFinishCyclingRunnable.run(); } - mMetaKeyManager.updateMetaStateUp(keyCode, event); - mInputView.updateStateText(); + if (mMetaKeyManager.updateMetaStateUp(keyCode, event)) { + mInputView.updateStateText(); + return true; + } + return false; } diff --git a/app/src/main/res/layout/input.xml b/app/src/main/res/layout/input.xml index eefccda..848e9df 100644 --- a/app/src/main/res/layout/input.xml +++ b/app/src/main/res/layout/input.xml @@ -60,6 +60,7 @@ android:layout_alignParentRight="true" android:background="@drawable/button_state" android:text="@string/state_button_default" + android:textAllCaps="false" android:textColor="@color/background" android:textSize="@dimen/default_text_size" /> diff --git a/app/src/main/res/xml/keymaps_titan.xml b/app/src/main/res/xml/keymaps_titan.xml index 4e8090a..d4ed920 100644 --- a/app/src/main/res/xml/keymaps_titan.xml +++ b/app/src/main/res/xml/keymaps_titan.xml @@ -1465,6 +1465,7 @@ + @@ -1505,6 +1506,9 @@ + + + @@ -1526,10 +1530,8 @@ - + - - @@ -1554,7 +1556,8 @@ - + + @@ -1576,14 +1579,10 @@ - - - - - + @@ -1622,8 +1621,9 @@ - - + + + @@ -1639,13 +1639,14 @@ - + + + - - +