Search in sources :

Example 11 with BaseInputConnection

use of android.view.inputmethod.BaseInputConnection in project android_frameworks_base by crdroidandroid.

the class AbsListView method onCreateInputConnection.

/**
     * Return an InputConnection for editing of the filter text.
     */
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    if (isTextFilterEnabled()) {
        if (mPublicInputConnection == null) {
            mDefInputConnection = new BaseInputConnection(this, false);
            mPublicInputConnection = new InputConnectionWrapper(outAttrs);
        }
        outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_FILTER;
        outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE;
        return mPublicInputConnection;
    }
    return null;
}
Also used : BaseInputConnection(android.view.inputmethod.BaseInputConnection)

Example 12 with BaseInputConnection

use of android.view.inputmethod.BaseInputConnection in project android_frameworks_base by DirtyUnicorns.

the class AbsListView method onCreateInputConnection.

/**
     * Return an InputConnection for editing of the filter text.
     */
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    if (isTextFilterEnabled()) {
        if (mPublicInputConnection == null) {
            mDefInputConnection = new BaseInputConnection(this, false);
            mPublicInputConnection = new InputConnectionWrapper(outAttrs);
        }
        outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_FILTER;
        outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE;
        return mPublicInputConnection;
    }
    return null;
}
Also used : BaseInputConnection(android.view.inputmethod.BaseInputConnection)

Example 13 with BaseInputConnection

use of android.view.inputmethod.BaseInputConnection in project remote-desktop-clients by iiordanov.

the class RemoteCanvas method onCreateInputConnection.

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    android.util.Log.d(TAG, "onCreateInputConnection called");
    BaseInputConnection bic = new BaseInputConnection(this, false);
    outAttrs.actionLabel = null;
    outAttrs.inputType = InputType.TYPE_NULL;
    String currentIme = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
    android.util.Log.d(TAG, "currentIme: " + currentIme);
    outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN;
    return bic;
}
Also used : BaseInputConnection(android.view.inputmethod.BaseInputConnection)

Example 14 with BaseInputConnection

use of android.view.inputmethod.BaseInputConnection in project Android-Terminal-Emulator by jackpal.

the class EmulatorView method onCreateInputConnection.

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    outAttrs.inputType = mUseCookedIme ? EditorInfo.TYPE_CLASS_TEXT : EditorInfo.TYPE_NULL;
    return new BaseInputConnection(this, true) {

        /**
         * Used to handle composing text requests
         */
        private int mCursor;

        private int mComposingTextStart;

        private int mComposingTextEnd;

        private int mSelectedTextStart;

        private int mSelectedTextEnd;

        private void sendText(CharSequence text) {
            int n = text.length();
            char c;
            try {
                for (int i = 0; i < n; i++) {
                    c = text.charAt(i);
                    if (Character.isHighSurrogate(c)) {
                        int codePoint;
                        if (++i < n) {
                            codePoint = Character.toCodePoint(c, text.charAt(i));
                        } else {
                            // Unicode Replacement Glyph, aka white question mark in black diamond.
                            codePoint = '\ufffd';
                        }
                        mapAndSend(codePoint);
                    } else {
                        mapAndSend(c);
                    }
                }
            } catch (IOException e) {
                Log.e(TAG, "error writing ", e);
            }
        }

        private void mapAndSend(int c) throws IOException {
            int result = mKeyListener.mapControlChar(c);
            if (result < TermKeyListener.KEYCODE_OFFSET) {
                mTermSession.write(result);
            } else {
                mKeyListener.handleKeyCode(result - TermKeyListener.KEYCODE_OFFSET, null, getKeypadApplicationMode());
            }
            clearSpecialKeyStatus();
        }

        public boolean beginBatchEdit() {
            if (LOG_IME) {
                Log.w(TAG, "beginBatchEdit");
            }
            setImeBuffer("");
            mCursor = 0;
            mComposingTextStart = 0;
            mComposingTextEnd = 0;
            return true;
        }

        public boolean clearMetaKeyStates(int arg0) {
            if (LOG_IME) {
                Log.w(TAG, "clearMetaKeyStates " + arg0);
            }
            return false;
        }

        public boolean commitCompletion(CompletionInfo arg0) {
            if (LOG_IME) {
                Log.w(TAG, "commitCompletion " + arg0);
            }
            return false;
        }

        public boolean endBatchEdit() {
            if (LOG_IME) {
                Log.w(TAG, "endBatchEdit");
            }
            return true;
        }

        public boolean finishComposingText() {
            if (LOG_IME) {
                Log.w(TAG, "finishComposingText");
            }
            sendText(mImeBuffer);
            setImeBuffer("");
            mComposingTextStart = 0;
            mComposingTextEnd = 0;
            mCursor = 0;
            return true;
        }

        public int getCursorCapsMode(int reqModes) {
            if (LOG_IME) {
                Log.w(TAG, "getCursorCapsMode(" + reqModes + ")");
            }
            int mode = 0;
            if ((reqModes & TextUtils.CAP_MODE_CHARACTERS) != 0) {
                mode |= TextUtils.CAP_MODE_CHARACTERS;
            }
            return mode;
        }

        public ExtractedText getExtractedText(ExtractedTextRequest arg0, int arg1) {
            if (LOG_IME) {
                Log.w(TAG, "getExtractedText" + arg0 + "," + arg1);
            }
            return null;
        }

        public CharSequence getTextAfterCursor(int n, int flags) {
            if (LOG_IME) {
                Log.w(TAG, "getTextAfterCursor(" + n + "," + flags + ")");
            }
            int len = Math.min(n, mImeBuffer.length() - mCursor);
            if (len <= 0 || mCursor < 0 || mCursor >= mImeBuffer.length()) {
                return "";
            }
            return mImeBuffer.substring(mCursor, mCursor + len);
        }

        public CharSequence getTextBeforeCursor(int n, int flags) {
            if (LOG_IME) {
                Log.w(TAG, "getTextBeforeCursor(" + n + "," + flags + ")");
            }
            int len = Math.min(n, mCursor);
            if (len <= 0 || mCursor < 0 || mCursor >= mImeBuffer.length()) {
                return "";
            }
            return mImeBuffer.substring(mCursor - len, mCursor);
        }

        public boolean performContextMenuAction(int arg0) {
            if (LOG_IME) {
                Log.w(TAG, "performContextMenuAction" + arg0);
            }
            return true;
        }

        public boolean performPrivateCommand(String arg0, Bundle arg1) {
            if (LOG_IME) {
                Log.w(TAG, "performPrivateCommand" + arg0 + "," + arg1);
            }
            return true;
        }

        public boolean reportFullscreenMode(boolean arg0) {
            if (LOG_IME) {
                Log.w(TAG, "reportFullscreenMode" + arg0);
            }
            return true;
        }

        public boolean commitCorrection(CorrectionInfo correctionInfo) {
            if (LOG_IME) {
                Log.w(TAG, "commitCorrection");
            }
            return true;
        }

        public boolean commitText(CharSequence text, int newCursorPosition) {
            if (LOG_IME) {
                Log.w(TAG, "commitText(\"" + text + "\", " + newCursorPosition + ")");
            }
            clearComposingText();
            sendText(text);
            setImeBuffer("");
            mCursor = 0;
            return true;
        }

        private void clearComposingText() {
            int len = mImeBuffer.length();
            if (mComposingTextStart > len || mComposingTextEnd > len) {
                mComposingTextEnd = mComposingTextStart = 0;
                return;
            }
            setImeBuffer(mImeBuffer.substring(0, mComposingTextStart) + mImeBuffer.substring(mComposingTextEnd));
            if (mCursor < mComposingTextStart) {
            // do nothing
            } else if (mCursor < mComposingTextEnd) {
                mCursor = mComposingTextStart;
            } else {
                mCursor -= mComposingTextEnd - mComposingTextStart;
            }
            mComposingTextEnd = mComposingTextStart = 0;
        }

        public boolean deleteSurroundingText(int leftLength, int rightLength) {
            if (LOG_IME) {
                Log.w(TAG, "deleteSurroundingText(" + leftLength + "," + rightLength + ")");
            }
            if (leftLength > 0) {
                for (int i = 0; i < leftLength; i++) {
                    sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
                }
            } else if ((leftLength == 0) && (rightLength == 0)) {
                // Delete key held down / repeating
                sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            }
            // TODO: handle forward deletes.
            return true;
        }

        public boolean performEditorAction(int actionCode) {
            if (LOG_IME) {
                Log.w(TAG, "performEditorAction(" + actionCode + ")");
            }
            if (actionCode == EditorInfo.IME_ACTION_UNSPECIFIED) {
                // The "return" key has been pressed on the IME.
                sendText("\r");
            }
            return true;
        }

        public boolean sendKeyEvent(KeyEvent event) {
            if (LOG_IME) {
                Log.w(TAG, "sendKeyEvent(" + event + ")");
            }
            // Some keys are sent here rather than to commitText.
            // In particular, del and the digit keys are sent here.
            // (And I have reports that the HTC Magic also sends Return here.)
            // As a bit of defensive programming, handle every key.
            dispatchKeyEvent(event);
            return true;
        }

        public boolean setComposingText(CharSequence text, int newCursorPosition) {
            if (LOG_IME) {
                Log.w(TAG, "setComposingText(\"" + text + "\", " + newCursorPosition + ")");
            }
            int len = mImeBuffer.length();
            if (mComposingTextStart > len || mComposingTextEnd > len) {
                return false;
            }
            setImeBuffer(mImeBuffer.substring(0, mComposingTextStart) + text + mImeBuffer.substring(mComposingTextEnd));
            mComposingTextEnd = mComposingTextStart + text.length();
            mCursor = newCursorPosition > 0 ? mComposingTextEnd + newCursorPosition - 1 : mComposingTextStart - newCursorPosition;
            return true;
        }

        public boolean setSelection(int start, int end) {
            if (LOG_IME) {
                Log.w(TAG, "setSelection" + start + "," + end);
            }
            int length = mImeBuffer.length();
            if (start == end && start > 0 && start < length) {
                mSelectedTextStart = mSelectedTextEnd = 0;
                mCursor = start;
            } else if (start < end && start > 0 && end < length) {
                mSelectedTextStart = start;
                mSelectedTextEnd = end;
                mCursor = start;
            }
            return true;
        }

        public boolean setComposingRegion(int start, int end) {
            if (LOG_IME) {
                Log.w(TAG, "setComposingRegion " + start + "," + end);
            }
            if (start < end && start > 0 && end < mImeBuffer.length()) {
                clearComposingText();
                mComposingTextStart = start;
                mComposingTextEnd = end;
            }
            return true;
        }

        public CharSequence getSelectedText(int flags) {
            if (LOG_IME) {
                Log.w(TAG, "getSelectedText " + flags);
            }
            int len = mImeBuffer.length();
            if (mSelectedTextEnd >= len || mSelectedTextStart > mSelectedTextEnd) {
                return "";
            }
            return mImeBuffer.substring(mSelectedTextStart, mSelectedTextEnd + 1);
        }
    };
}
Also used : BaseInputConnection(android.view.inputmethod.BaseInputConnection) CompletionInfo(android.view.inputmethod.CompletionInfo) KeyEvent(android.view.KeyEvent) Bundle(android.os.Bundle) ExtractedTextRequest(android.view.inputmethod.ExtractedTextRequest) IOException(java.io.IOException) CorrectionInfo(android.view.inputmethod.CorrectionInfo) Paint(android.graphics.Paint)

Example 15 with BaseInputConnection

use of android.view.inputmethod.BaseInputConnection in project cordova-android-chromeview by thedracle.

the class BackButtonMultiPageTest method testViaBackButtonOnView.

public void testViaBackButtonOnView() {
    testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
    sleep();
    String url = testView.getUrl();
    assertTrue(url.endsWith("sample2.html"));
    testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
    sleep();
    url = testView.getUrl();
    assertTrue(url.endsWith("sample3.html"));
    BaseInputConnection viewConnection = new BaseInputConnection(testView, true);
    KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
    KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
    viewConnection.sendKeyEvent(backDown);
    viewConnection.sendKeyEvent(backUp);
    sleep();
    url = testView.getUrl();
    assertTrue(url.endsWith("sample2.html"));
    viewConnection.sendKeyEvent(backDown);
    viewConnection.sendKeyEvent(backUp);
    sleep();
    url = testView.getUrl();
    assertTrue(url.endsWith("index.html"));
}
Also used : BaseInputConnection(android.view.inputmethod.BaseInputConnection) KeyEvent(android.view.KeyEvent)

Aggregations

BaseInputConnection (android.view.inputmethod.BaseInputConnection)15 KeyEvent (android.view.KeyEvent)7 InputConnectionWrapper (android.view.inputmethod.InputConnectionWrapper)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 Paint (android.graphics.Paint)1 Bundle (android.os.Bundle)1 CompletionInfo (android.view.inputmethod.CompletionInfo)1 CorrectionInfo (android.view.inputmethod.CorrectionInfo)1 ExtractedTextRequest (android.view.inputmethod.ExtractedTextRequest)1 IOException (java.io.IOException)1