mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-22 01:34:22 +00:00
add file to create keyboardTextsTable (looks like it works), some formatting
and slight adjustment to korean handling in latinIme
This commit is contained in:
parent
a7a3465e9b
commit
4cdabe2680
6 changed files with 237 additions and 218 deletions
|
@ -8,17 +8,17 @@ import org.dslul.openboard.inputmethod.event.HangulCombiner.HangulJamo
|
|||
object HangulEventDecoder {
|
||||
|
||||
@JvmStatic
|
||||
fun decodeHardwareKeyEvent(subtype: RichInputMethodSubtype, event: KeyEvent, defaultEvent: Event): Event {
|
||||
val layout = LAYOUTS[subtype.keyboardLayoutSetName] ?: return defaultEvent
|
||||
val codePoint = layout[event.keyCode]?.let { if(event.isShiftPressed) it.second else it.first } ?: return defaultEvent
|
||||
fun decodeHardwareKeyEvent(subtype: RichInputMethodSubtype, event: KeyEvent, defaultEvent: () -> Event): Event {
|
||||
val layout = LAYOUTS[subtype.keyboardLayoutSetName] ?: return defaultEvent()
|
||||
val codePoint = layout[event.keyCode]?.let { if (event.isShiftPressed) it.second else it.first } ?: return defaultEvent()
|
||||
val hardwareEvent = Event.createHardwareKeypressEvent(codePoint, event.keyCode, null, event.repeatCount != 0)
|
||||
return decodeSoftwareKeyEvent(hardwareEvent)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun decodeSoftwareKeyEvent(event: Event): Event {
|
||||
if(event.isCombining) return event
|
||||
return if(HangulJamo.of(event.mCodePoint) is HangulJamo.NonHangul) event
|
||||
if (event.isCombining) return event
|
||||
return if (HangulJamo.of(event.mCodePoint) is HangulJamo.NonHangul) event
|
||||
else Event.createCombiningEvent(event)
|
||||
}
|
||||
|
||||
|
|
|
@ -26,42 +26,41 @@ import org.dslul.openboard.inputmethod.latin.common.Constants
|
|||
* can be dead keys, they can be meta keys like shift or ctrl... This does not deal with
|
||||
* 10-key like keyboards; a different decoder is used for this.
|
||||
*/
|
||||
class HardwareKeyboardEventDecoder // TODO: get the layout for this hardware keyboard
|
||||
(val mDeviceId: Int) : HardwareEventDecoder {
|
||||
override fun decodeHardwareKey(keyEvent: KeyEvent): Event { // KeyEvent#getUnicodeChar() does not exactly returns a unicode char, but rather a value
|
||||
// that includes both the unicode char in the lower 21 bits and flags in the upper bits,
|
||||
// hence the name "codePointAndFlags". {@see KeyEvent#getUnicodeChar()} for more info.
|
||||
// TODO: get the layout for this hardware keyboard
|
||||
class HardwareKeyboardEventDecoder(val mDeviceId: Int) : HardwareEventDecoder {
|
||||
override fun decodeHardwareKey(keyEvent: KeyEvent): Event {
|
||||
// KeyEvent#getUnicodeChar() does not exactly returns a unicode char, but rather a value
|
||||
// that includes both the unicode char in the lower 21 bits and flags in the upper bits,
|
||||
// hence the name "codePointAndFlags". {@see KeyEvent#getUnicodeChar()} for more info.
|
||||
val codePointAndFlags = keyEvent.unicodeChar
|
||||
// The keyCode is the abstraction used by the KeyEvent to represent different keys that
|
||||
// do not necessarily map to a unicode character. This represents a physical key, like
|
||||
// the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock.
|
||||
// do not necessarily map to a unicode character. This represents a physical key, like
|
||||
// the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock.
|
||||
val keyCode = keyEvent.keyCode
|
||||
val isKeyRepeat = 0 != keyEvent.repeatCount
|
||||
if (KeyEvent.KEYCODE_DEL == keyCode) {
|
||||
return Event.Companion.createHardwareKeypressEvent(Event.Companion.NOT_A_CODE_POINT, Constants.CODE_DELETE,
|
||||
null /* next */, isKeyRepeat)
|
||||
return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT, Constants.CODE_DELETE, null /* next */, isKeyRepeat)
|
||||
}
|
||||
if (keyEvent.isPrintingKey || KeyEvent.KEYCODE_SPACE == keyCode || KeyEvent.KEYCODE_ENTER == keyCode) {
|
||||
if (0 != codePointAndFlags and KeyCharacterMap.COMBINING_ACCENT) { // A dead key.
|
||||
return Event.Companion.createDeadEvent(
|
||||
codePointAndFlags and KeyCharacterMap.COMBINING_ACCENT_MASK, keyCode,
|
||||
null /* next */)
|
||||
return Event.createDeadEvent(
|
||||
codePointAndFlags and KeyCharacterMap.COMBINING_ACCENT_MASK, keyCode, null /* next */)
|
||||
}
|
||||
return if (KeyEvent.KEYCODE_ENTER == keyCode) { // The Enter key. If the Shift key is not being pressed, this should send a
|
||||
// CODE_ENTER to trigger the action if any, or a carriage return otherwise. If the
|
||||
// Shift key is being pressed, this should send a CODE_SHIFT_ENTER and let
|
||||
// Latin IME decide what to do with it.
|
||||
return if (KeyEvent.KEYCODE_ENTER == keyCode) {
|
||||
// The Enter key. If the Shift key is not being pressed, this should send a
|
||||
// CODE_ENTER to trigger the action if any, or a carriage return otherwise. If the
|
||||
// Shift key is being pressed, this should send a CODE_SHIFT_ENTER and let
|
||||
// Latin IME decide what to do with it.
|
||||
if (keyEvent.isShiftPressed) {
|
||||
Event.Companion.createHardwareKeypressEvent(Event.Companion.NOT_A_CODE_POINT,
|
||||
Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT,
|
||||
Constants.CODE_SHIFT_ENTER, null /* next */, isKeyRepeat)
|
||||
} else Event.Companion.createHardwareKeypressEvent(Constants.CODE_ENTER, keyCode,
|
||||
} else Event.createHardwareKeypressEvent(Constants.CODE_ENTER, keyCode,
|
||||
null /* next */, isKeyRepeat)
|
||||
} else Event.Companion.createHardwareKeypressEvent(codePointAndFlags, keyCode, null /* next */,
|
||||
isKeyRepeat)
|
||||
} else Event.createHardwareKeypressEvent(codePointAndFlags, keyCode, null /* next */, isKeyRepeat)
|
||||
// If not Enter, then this is just a regular keypress event for a normal character
|
||||
// that can be committed right away, taking into account the current state.
|
||||
// that can be committed right away, taking into account the current state.
|
||||
}
|
||||
return Event.Companion.createNotHandledEvent()
|
||||
return Event.createNotHandledEvent()
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -39,9 +39,14 @@ public class KoreanDictionary extends Dictionary {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<SuggestedWords.SuggestedWordInfo> getSuggestions(ComposedData composedData, NgramContext ngramContext, long proximityInfoHandle, SettingsValuesForSuggestion settingsValuesForSuggestion, int sessionId, float weightForLocale, float[] inOutWeightOfLangModelVsSpatialModel) {
|
||||
composedData = new ComposedData(composedData.mInputPointers, composedData.mIsBatchMode, processInput(composedData.mTypedWord));
|
||||
ArrayList<SuggestedWords.SuggestedWordInfo> suggestions = mDictionary.getSuggestions(composedData, ngramContext, proximityInfoHandle, settingsValuesForSuggestion, sessionId, weightForLocale, inOutWeightOfLangModelVsSpatialModel);
|
||||
public ArrayList<SuggestedWords.SuggestedWordInfo> getSuggestions(ComposedData composedData,
|
||||
NgramContext ngramContext, long proximityInfoHandle, SettingsValuesForSuggestion settingsValuesForSuggestion,
|
||||
int sessionId, float weightForLocale, float[] inOutWeightOfLangModelVsSpatialModel) {
|
||||
composedData = new ComposedData(composedData.mInputPointers,
|
||||
composedData.mIsBatchMode, processInput(composedData.mTypedWord));
|
||||
ArrayList<SuggestedWords.SuggestedWordInfo> suggestions = mDictionary.getSuggestions(composedData,
|
||||
ngramContext, proximityInfoHandle, settingsValuesForSuggestion, sessionId,
|
||||
weightForLocale, inOutWeightOfLangModelVsSpatialModel);
|
||||
ArrayList<SuggestedWords.SuggestedWordInfo> result = new ArrayList<>();
|
||||
for (SuggestedWords.SuggestedWordInfo info : suggestions) {
|
||||
result.add(new SuggestedWords.SuggestedWordInfo(processOutput(info.mWord), info.mPrevWordsContext,
|
||||
|
|
|
@ -1886,13 +1886,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
if (!ProductionFlags.IS_HARDWARE_KEYBOARD_SUPPORTED) {
|
||||
return super.onKeyDown(keyCode, keyEvent);
|
||||
}
|
||||
final Event event = getHardwareKeyEventDecoder(
|
||||
keyEvent.getDeviceId()).decodeHardwareKey(keyEvent);
|
||||
final Event event;
|
||||
if (mRichImm.getCurrentSubtypeLocale().getLanguage().equals("ko")) {
|
||||
event = HangulEventDecoder.decodeHardwareKeyEvent(mRichImm.getCurrentSubtype(), keyEvent,
|
||||
() -> getHardwareKeyEventDecoder(keyEvent.getDeviceId()).decodeHardwareKey(keyEvent));
|
||||
} else {
|
||||
event = getHardwareKeyEventDecoder(keyEvent.getDeviceId()).decodeHardwareKey(keyEvent);
|
||||
}
|
||||
// If the event is not handled by LatinIME, we just pass it to the parent implementation.
|
||||
// If it's handled, we return true because we did handle it.
|
||||
if (event.isHandled()) {
|
||||
Event hangulDecodedEvent = HangulEventDecoder.decodeHardwareKeyEvent(mKeyboardSwitcher.getKeyboard().mId.mSubtype, keyEvent, event);
|
||||
mInputLogic.onCodeInput(mSettings.getCurrent(), hangulDecodedEvent,
|
||||
mInputLogic.onCodeInput(mSettings.getCurrent(), event,
|
||||
mKeyboardSwitcher.getKeyboardShiftMode(),
|
||||
// TODO: this is not necessarily correct for a hardware keyboard right now
|
||||
mKeyboardSwitcher.getCurrentKeyboardScriptId(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue