/** * Use this to monitor key events being delivered to the application. * We get first crack at them, and can either resume them or let them * continue to the app. */ @Override public boolean onKeyUp(int keyCode, KeyEvent event) { // Log.v("SpartacusRex","SOFT : onKeyUp "+keyCode +" "+event.getMetaState()); // If we want to do transformations on text being entered with a hard // keyboard, we need to process the up events to update the meta key // state we are tracking. if (PROCESS_HARD_KEYS) { if (mPredictionOn) { mMetaState = MetaKeyKeyListener.handleKeyUp(mMetaState, keyCode, event); } } return super.onKeyUp(keyCode, event); }
@Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { if (mTemporaryDetach) { // If we are temporarily in the detach state, then do nothing. super.onFocusChanged(focused, direction, previouslyFocusedRect); return; } if (mEditor != null) mEditor.onFocusChanged(focused, direction); if (focused) { if (mText instanceof Spannable) { Spannable sp = (Spannable) mText; MetaKeyKeyListener.resetMetaState(sp); } } startStopMarquee(focused); if (mTransformation != null) { mTransformation.onFocusChanged(this, mText, focused, direction, previouslyFocusedRect); } super.onFocusChanged(focused, direction, previouslyFocusedRect); }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (!m_started) return false; m_metaState = MetaKeyKeyListener.handleKeyDown(m_metaState, keyCode, event); int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(m_metaState)); int lc=c; m_metaState = MetaKeyKeyListener.adjustMetaAfterKeypress(m_metaState); if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) { c = c & KeyCharacterMap.COMBINING_ACCENT_MASK; int composed = KeyEvent.getDeadChar(m_lastChar, c); c = composed; } m_lastChar = lc; // if (keyCode != KeyEvent.KEYCODE_BACK) QtApplication.keyDown(keyCode, c, event.getMetaState()); return true; }
private boolean up(TextView widget, Spannable buffer) { boolean cap = (MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_SHIFT_ON) == 1) || (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0); boolean alt = MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_ALT_ON) == 1; Layout layout = widget.getLayout(); if (cap) { if (alt) { // Selection.extendSelection(buffer, 0); widget.movePage(true,true); return true; } else { return Selection.extendUp(buffer, layout); } } else { if (alt) { // Selection.setSelection(buffer, 0); widget.movePage(true,false); return true; } else { return Selection.moveUp(buffer, layout); } } }
private boolean down(TextView widget, Spannable buffer) { boolean cap = (MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_SHIFT_ON) == 1) || (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0); boolean alt = MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_ALT_ON) == 1; Layout layout = widget.getLayout(); if (cap) { if (alt) { // Selection.extendSelection(buffer, buffer.length()); widget.movePage(false,true); return true; } else { return Selection.extendDown(buffer, layout); } } else { if (alt) { // Selection.setSelection(buffer, buffer.length()); widget.movePage(false,false); return true; } else { return Selection.moveDown(buffer, layout); } } }
private boolean left(TextView widget, Spannable buffer) { boolean cap = (MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_SHIFT_ON) == 1) || (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0); boolean alt = MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_ALT_ON) == 1; Layout layout = widget.getLayout(); if (cap) { if (alt) { return Selection.extendToLeftEdge(buffer, layout); } else { return Selection.extendLeft(buffer, layout); } } else { if (alt) { return Selection.moveToLeftEdge(buffer, layout); } else { return Selection.moveLeft(buffer, layout); } } }
private boolean right(TextView widget, Spannable buffer) { boolean cap = (MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_SHIFT_ON) == 1) || (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0); boolean alt = MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_ALT_ON) == 1; Layout layout = widget.getLayout(); if (cap) { if (alt) { return Selection.extendToRightEdge(buffer, layout); } else { return Selection.extendRight(buffer, layout); } } else { if (alt) { return Selection.moveToRightEdge(buffer, layout); } else { return Selection.moveRight(buffer, layout); } } }
private boolean movehome(TextView widget, Spannable buffer, KeyEvent event) { boolean cap = (MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_SHIFT_ON) == 1) || (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0); Layout layout = widget.getLayout(); boolean ctrl = (event.getMetaState() & mShortcutCtrlKey)!=0; if ( ctrl ){ if (cap) { Selection.extendSelection(buffer, 0); return true; } else { Selection.setSelection(buffer, 0); return true; } }else{ if (cap) { return Selection.extendToLeftEdge(buffer, layout); } else { return Selection.moveToLeftEdge(buffer, layout); } } }
private boolean moveend(TextView widget, Spannable buffer, KeyEvent event) { boolean cap = (MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_SHIFT_ON) == 1) || (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0); Layout layout = widget.getLayout(); boolean ctrl = (event.getMetaState() & mShortcutCtrlKey)!=0; if ( ctrl ){ if (cap) { Selection.extendSelection(buffer, buffer.length()); return true; } else { Selection.setSelection(buffer, buffer.length()); return true; } }else{ if (cap) { return Selection.extendToRightEdge(buffer, layout); } else { return Selection.moveToRightEdge(buffer, layout); } } }
/** * This translates incoming hard key events in to edit operations on an * InputConnection. It is only needed when using the * PROCESS_HARD_KEYS option. */ private boolean translateKeyDown(int keyCode, KeyEvent event) { mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState, keyCode, event); int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(mMetaState)); mMetaState = MetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState); InputConnection ic = getCurrentInputConnection(); if (c == 0 || ic == null) { return false; } boolean dead = false; if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) { dead = true; c = c & KeyCharacterMap.COMBINING_ACCENT_MASK; } if (mComposing.length() > 0) { char accent = mComposing.charAt(mComposing.length() -1 ); int composed = KeyEvent.getDeadChar(accent, c); if (composed != 0) { c = composed; mComposing.setLength(mComposing.length()-1); } } onKey(c, null); return true; }
/** * This translates incoming hard key events in to edit operations on an * InputConnection. It is only needed when using the * PROCESS_HARD_KEYS option. */ private boolean translateKeyDown(int keyCode, KeyEvent event) { // Log.v("SpartacusRex","SOFT : translateKeyDown "+keyCode); mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState, keyCode, event); int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(mMetaState)); mMetaState = MetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState); InputConnection ic = getCurrentInputConnection(); if (c == 0 || ic == null) { return false; } boolean dead = false; if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) { dead = true; c = c & KeyCharacterMap.COMBINING_ACCENT_MASK; } if (mComposing.length() > 0) { char accent = mComposing.charAt(mComposing.length() - 1); int composed = KeyEvent.getDeadChar(accent, c); if (composed != 0) { c = composed; mComposing.setLength(mComposing.length() - 1); } } onKey(c, null); return true; }
/** * Use this to monitor key events being delivered to the application. * We get first crack at them, and can either resume them or let them * continue to the app. */ @Override public boolean onKeyUp(int keyCode, KeyEvent event) { // If we want to do transformations on text being entered with a hard // keyboard, we need to process the up events to update the meta key // state we are tracking. if (PROCESS_HARD_KEYS) { if (mPredictionOn) { mMetaState = MetaKeyKeyListener.handleKeyUp(mMetaState, keyCode, event); } } return super.onKeyUp(keyCode, event); }
public void afterTextChanged(Editable buffer) { if (DEBUG_EXTRACT) Log.v(LOG_TAG, "afterTextChanged: " + buffer); TextView.this.sendAfterTextChanged(buffer); if (MetaKeyKeyListener.getMetaState(buffer, MetaKeyKeyListener.META_SELECTING) != 0) { MetaKeyKeyListener.stopSelecting(TextView.this, buffer); } }
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (!m_started) return false; m_metaState = MetaKeyKeyListener.handleKeyUp(m_metaState, keyCode, event); QtApplication.keyUp(keyCode, event.getUnicodeChar(), event.getMetaState()); return true; }
public void afterTextChanged(Editable buffer) { if (DEBUG_EXTRACT) Log.v(TAG, "afterTextChanged: " + buffer); TextView.this.sendAfterTextChanged(buffer); if (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0) { MetaKeyKeyListener.stopSelecting(TextView.this, buffer); } }
public boolean doFunction(TextView widget, Spannable buffer, int function) { boolean cap = (MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_SHIFT_ON) == 1) || (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0); Log.d("=========================>","cap="+cap); switch( function ) { case TextView.FUNCTION_CURSOR_LEFT: return moveLeft(widget, buffer, cap); case TextView.FUNCTION_CURSOR_RIGHT: return moveRight(widget, buffer, cap); case TextView.FUNCTION_CURSOR_UP: return moveUp(widget, buffer, cap); case TextView.FUNCTION_CURSOR_DOWN: return moveDown(widget, buffer, cap); case TextView.FUNCTION_PAGE_UP: return movePageUp(widget, buffer, cap); case TextView.FUNCTION_PAGE_DOWN: return movePageDown(widget, buffer, cap); case TextView.FUNCTION_HOME: return moveHome(widget, buffer, cap); case TextView.FUNCTION_END: return moveEnd(widget, buffer, cap); case TextView.FUNCTION_TOP: return moveTop(widget, buffer, cap); case TextView.FUNCTION_BOTTOM: return moveBottom(widget, buffer, cap); } return false; }
private boolean volup(TextView widget, Spannable buffer) { boolean cap = (MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_SHIFT_ON) == 1) || (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0); if (cap) { widget.movePage(true,true); return true; } else { widget.movePage(true,false); return true; } }
private boolean voldown(TextView widget, Spannable buffer) { boolean cap = (MetaKeyKeyListener.getMetaState(buffer, KeyEvent.META_SHIFT_ON) == 1) || (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0); if (cap) { widget.movePage(false,true); return true; } else { widget.movePage(false,false); return true; } }
public boolean onKeyDown(TextView widget, Spannable buffer, int keyCode, KeyEvent event) { if (executeDown(widget, buffer, keyCode,event)) { MetaKeyKeyListener.adjustMetaAfterKeypress(buffer); resetLockedMeta(buffer); return true; } return false; }
public static MovementMethod getInstance() { if (sInstance == null) sInstance = new ArrowKeyMovementMethod(); try{ Class<?> c = MetaKeyKeyListener.class; sMethod = c.getDeclaredMethod("resetLockedMeta", new Class[]{ Spannable.class }); sMethod.setAccessible(true); }catch(Exception e){ } return sInstance; }
/** * This translates incoming hard key events in to edit operations on an * InputConnection. It is only needed when using the * PROCESS_HARD_KEYS option. */ private boolean translateKeyDown(int keyCode, KeyEvent event) { // Log.v("SpartacusRex","SOFT : translateKeyDown "+keyCode); mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState, keyCode, event); int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(mMetaState)); mMetaState = MetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState); InputConnection ic = getCurrentInputConnection(); if (c == 0 || ic == null) { return false; } boolean dead = false; if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) { dead = true; c = c & KeyCharacterMap.COMBINING_ACCENT_MASK; } if (mComposing.length() > 0) { char accent = mComposing.charAt(mComposing.length() -1 ); int composed = KeyEvent.getDeadChar(accent, c); if (composed != 0) { c = composed; mComposing.setLength(mComposing.length()-1); } } onKey(c, null); return true; }
private boolean translateKeyDown(int keyCode, KeyEvent event) { MetaState = MetaKeyKeyListener.handleKeyDown(MetaState, keyCode, event); int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(MetaState)); MetaState = MetaKeyKeyListener.adjustMetaAfterKeypress(MetaState); InputConnection ic = getCurrentInputConnection(); if (c == 0 || ic == null) { return false; } dead = false; if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) { dead = true; c = c & KeyCharacterMap.COMBINING_ACCENT_MASK; } if (Composing.length() > 0) { char accent = Composing.charAt(Composing.length() -1 ); int composed = KeyEvent.getDeadChar(accent, c); if (composed != 0) { c = composed; Composing.setLength(Composing.length()-1); } } onKey(c, null); return true; }
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (PROCESS_HARD_KEYS) { if (PredictionOn) { MetaState = MetaKeyKeyListener.handleKeyUp(MetaState, keyCode, event); } } return super.onKeyUp(keyCode, event); }
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { // Log.d(TAG, String.format("onKeyUp (%x)", keyCode)); mMetaState = MetaKeyKeyListener.handleKeyUp(mMetaState, keyCode, event); return super.onKeyUp(keyCode, event); }
private int getUnicodeChar(int keyCode, KeyEvent event) { mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState, keyCode, event); int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(mMetaState)); mMetaState = MetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState); return c; }
private boolean executeDown(TextView widget, Spannable buffer, int keyCode , KeyEvent event) { boolean handled = false; if ( keyCode == KEYCODE_PAGE_UP ){ handled |= volup(widget, buffer); }else if ( keyCode == KEYCODE_PAGE_DOWN){ handled |= voldown(widget, buffer); }else if ( keyCode == KEYCODE_MOVE_HOME){ handled |= movehome(widget, buffer ,event); }else if ( keyCode == KEYCODE_MOVE_END){ handled |= moveend(widget, buffer , event); }else{ switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: handled |= up(widget, buffer); break; case KeyEvent.KEYCODE_DPAD_DOWN: handled |= down(widget, buffer); break; case KeyEvent.KEYCODE_DPAD_LEFT: handled |= left(widget, buffer); break; case KeyEvent.KEYCODE_DPAD_RIGHT: handled |= right(widget, buffer); break; case KeyEvent.KEYCODE_DPAD_CENTER: if (JotaTextKeyListener.getMetaStateSelecting(buffer) != 0) { if (widget.showContextMenu()) { handled = true; } } break; case KeyEvent.KEYCODE_VOLUME_UP: if ( sUseVolumeKey ){ handled |= volup(widget, buffer); } break; case KeyEvent.KEYCODE_VOLUME_DOWN: if ( sUseVolumeKey ){ handled |= voldown(widget, buffer); } break; } } if (handled) { MetaKeyKeyListener.adjustMetaAfterKeypress(buffer); resetLockedMeta(buffer); } return handled; }
public static final int getMetaStateSelecting(CharSequence text) { return MetaKeyKeyListener.getMetaState(text, META_SELECTING); }
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { Log.i(TAG, "onKeyUp (keyCode='" + keyCode + "', event.keyCode='" + event.getKeyCode() + "', metaState='" + event.getMetaState() + "')"); metaState = MetaKeyKeyListener.handleKeyUp(metaState, keyCode, event); return super.onKeyUp(keyCode, event); }
private int getUnicodeChar(int keyCode, KeyEvent event) { metaState = MetaKeyKeyListener.handleKeyDown(metaState, keyCode, event); int c = event.getUnicodeChar(event.getMetaState()); metaState = MetaKeyKeyListener.adjustMetaAfterKeypress(metaState); return c; }