public bool onKey(android.view.View v, int keyCode, android.view.KeyEvent @event) { // guard against possible race conditions if (this._enclosing.mSearchable == null) { return false; } // If a suggestion is selected, handle enter, search key, and action keys // as presses on the selected suggestion if (this._enclosing.mQueryTextView.isPopupShowing() && this._enclosing.mQueryTextView .getListSelection() != android.widget.AdapterView.INVALID_POSITION) { return this._enclosing.onSuggestionsKey(v, keyCode, @event); } // If there is text in the query box, handle enter, and action keys // The search key is handled by the dialog's onKeyDown(). if (!this._enclosing.mQueryTextView.isEmpty() && @event.hasNoModifiers()) { if (@event.getAction() == android.view.KeyEvent.ACTION_UP) { if (keyCode == android.view.KeyEvent.KEYCODE_ENTER) { v.cancelLongPress(); // Launch as a regular search. this._enclosing.launchQuerySearch(android.view.KeyEvent.KEYCODE_UNKNOWN, null, (( android.text.Editable)this._enclosing.mQueryTextView.getText()).ToString()); return true; } } if (@event.getAction() == android.view.KeyEvent.ACTION_DOWN) { android.app.SearchableInfo.ActionKeyInfo actionKey = this._enclosing.mSearchable. findActionKey(keyCode); if ((actionKey != null) && (actionKey.getQueryActionMsg() != null)) { this._enclosing.launchQuerySearch(keyCode, actionKey.getQueryActionMsg(), ((android.text.Editable )this._enclosing.mQueryTextView.getText()).ToString()); return true; } } } return false; }
public override bool onTouchEvent(android.widget.TextView widget, android.text.Spannable buffer, android.view.MotionEvent @event) { int initialScrollX = -1; int initialScrollY = -1; int action = @event.getAction(); if (action == android.view.MotionEvent.ACTION_UP) { initialScrollX = android.text.method.Touch.getInitialScrollX(widget, buffer); initialScrollY = android.text.method.Touch.getInitialScrollY(widget, buffer); } bool handled = android.text.method.Touch.onTouchEvent(widget, buffer, @event); if (widget.isFocused() && !widget.didTouchFocusSelect()) { if (action == android.view.MotionEvent.ACTION_DOWN) { if (isSelecting(buffer)) { int offset = widget.getOffsetForPosition(@event.getX(), @event.getY()); buffer.setSpan(LAST_TAP_DOWN, offset, offset, android.text.SpannedClass.SPAN_POINT_POINT ); // Disallow intercepting of the touch events, so that // users can scroll and select at the same time. // without this, users would get booted out of select // mode once the view detected it needed to scroll. widget.getParent().requestDisallowInterceptTouchEvent(true); } } else { if (action == android.view.MotionEvent.ACTION_MOVE) { if (isSelecting(buffer) && handled) { // Before selecting, make sure we've moved out of the "slop". // handled will be true, if we're in select mode AND we're // OUT of the slop // Turn long press off while we're selecting. User needs to // re-tap on the selection to enable long press widget.cancelLongPress(); // Update selection as we're moving the selection area. // Get the current touch position int offset = widget.getOffsetForPosition(@event.getX(), @event.getY()); android.text.Selection.extendSelection(buffer, offset); return true; } } else { if (action == android.view.MotionEvent.ACTION_UP) { // If we have scrolled, then the up shouldn't move the cursor, // but we do need to make sure the cursor is still visible at // the current scroll offset to avoid the scroll jumping later // to show it. if ((initialScrollY >= 0 && initialScrollY != widget.getScrollY()) || (initialScrollX >= 0 && initialScrollX != widget.getScrollX())) { widget.moveCursorToVisibleOffset(); return true; } int offset = widget.getOffsetForPosition(@event.getX(), @event.getY()); if (isSelecting(buffer)) { buffer.removeSpan(LAST_TAP_DOWN); android.text.Selection.extendSelection(buffer, offset); } else { if (!widget.shouldIgnoreActionUpEvent()) { android.text.Selection.setSelection(buffer, offset); } } android.text.method.MetaKeyKeyListener.adjustMetaAfterKeypress(buffer); android.text.method.MetaKeyKeyListener.resetLockedMeta(buffer); return true; } } } } return handled; }