Example usage for android.view.inputmethod BaseInputConnection BaseInputConnection

List of usage examples for android.view.inputmethod BaseInputConnection BaseInputConnection

Introduction

In this page you can find the example usage for android.view.inputmethod BaseInputConnection BaseInputConnection.

Prototype

public BaseInputConnection(View targetView, boolean fullEditor) 

Source Link

Usage

From source file:org.connectbot.TerminalView.java

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_ENTER_ACTION
            | EditorInfo.IME_ACTION_NONE;
    outAttrs.inputType = EditorInfo.TYPE_NULL;
    return new BaseInputConnection(this, false) {
        @Override/*from   w w w. ja v  a2 s  . c  o m*/
        public boolean deleteSurroundingText(int leftLength, int rightLength) {
            if (rightLength == 0 && leftLength == 0) {
                return this.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            }
            for (int i = 0; i < leftLength; i++) {
                this.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            }
            // TODO: forward delete
            return true;
        }
    };
}

From source file:com.undatech.opaque.RemoteCanvas.java

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    android.util.Log.d(TAG, "onCreateInputConnection called");
    int version = android.os.Build.VERSION.SDK_INT;
    BaseInputConnection bic = null;//from   w  w w. j a v a 2s.co  m
    if (!bb && version >= Build.VERSION_CODES.JELLY_BEAN) {
        bic = new BaseInputConnection(this, false) {
            final static String junk_unit = "%%%%%%%%%%";
            final static int multiple = 1000;
            Editable e;

            @Override
            public Editable getEditable() {
                if (e == null) {
                    int numTotalChars = junk_unit.length() * multiple;
                    String junk = new String();
                    for (int i = 0; i < multiple; i++) {
                        junk += junk_unit;
                    }
                    e = Editable.Factory.getInstance().newEditable(junk);
                    Selection.setSelection(e, numTotalChars);
                    if (RemoteCanvas.this.keyboard != null) {
                        RemoteCanvas.this.keyboard.skippedJunkChars = false;
                    }
                }
                return e;
            }
        };
    } else {
        bic = new BaseInputConnection(this, false);
    }

    outAttrs.actionLabel = null;
    outAttrs.inputType = InputType.TYPE_NULL;
    /* TODO: If people complain about kbd not working, this is a possible workaround to
     * test and add an option for.
    // Workaround for IME's that don't support InputType.TYPE_NULL.
    if (version >= 11) {
    outAttrs.inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
    outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN;
    }*/
    return bic;
}

From source file:com.iiordanov.bVNC.RemoteCanvas.java

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    android.util.Log.d(TAG, "onCreateInputConnection called");
    int version = android.os.Build.VERSION.SDK_INT;
    BaseInputConnection bic = null;/*from  w  ww.j  a v a2s .c om*/
    if (!bb && version >= Build.VERSION_CODES.JELLY_BEAN) {
        bic = new BaseInputConnection(this, false) {
            final static String junk_unit = "%%%%%%%%%%";
            final static int multiple = 1000;
            Editable e;

            @Override
            public Editable getEditable() {
                if (e == null) {
                    int numTotalChars = junk_unit.length() * multiple;
                    String junk = new String();
                    for (int i = 0; i < multiple; i++) {
                        junk += junk_unit;
                    }
                    e = Editable.Factory.getInstance().newEditable(junk);
                    Selection.setSelection(e, numTotalChars);
                    if (RemoteCanvas.this.keyboard != null) {
                        RemoteCanvas.this.keyboard.skippedJunkChars = false;
                    }
                }
                return e;
            }
        };
    } else {
        bic = new BaseInputConnection(this, false);
    }

    outAttrs.actionLabel = null;
    outAttrs.inputType = InputType.TYPE_NULL;
    // Workaround for IME's that don't support InputType.TYPE_NULL.
    if (version >= 21) {
        outAttrs.inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
        outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN;
    }
    return bic;
}

From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    return new BaseInputConnection(this, false) {
        @Override/*from w  w  w .j  av a2  s .co  m*/
        public boolean sendKeyEvent(KeyEvent event) {
            return super.sendKeyEvent(event);
        }

        @Override
        public boolean deleteSurroundingText(int beforeLength, int afterLength) {
            // magic: in latest Android, deleteSurroundingText(1, 0) will be called for backspace
            if (beforeLength == 1 && afterLength == 0) {
                // backspace
                super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
                return super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
            }

            return super.deleteSurroundingText(beforeLength, afterLength);
        }
    };
}

From source file:com.example.libwidgettv.bak.AbsListView.java

/**
 * Return an InputConnection for editing of the filter text.
 *//*from w w  w. j a v a2 s . c  om*/
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    if (isTextFilterEnabled()) {
        // XXX we need to have the text filter created, so we can get an
        // InputConnection to proxy to. Unfortunately this means we pretty
        // much need to make it as soon as a list view gets focus.
        createTextFilter(false);
        if (mPublicInputConnection == null) {
            mDefInputConnection = new BaseInputConnection(this, false);
            mPublicInputConnection = new InputConnectionWrapper(mTextFilter.onCreateInputConnection(outAttrs),
                    true) {
                @Override
                public boolean reportFullscreenMode(boolean enabled) {
                    // Use our own input connection, since it is
                    // the "real" one the IME is talking with.
                    return mDefInputConnection.reportFullscreenMode(enabled);
                }

                @Override
                public boolean performEditorAction(int editorAction) {
                    // The editor is off in its own window; we need to be
                    // the one that does this.
                    if (editorAction == EditorInfo.IME_ACTION_DONE) {
                        InputMethodManager imm = (InputMethodManager) getContext()
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        if (imm != null) {
                            imm.hideSoftInputFromWindow(getWindowToken(), 0);
                        }
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean sendKeyEvent(KeyEvent event) {
                    // Use our own input connection, since the filter
                    // text view may not be shown in a window so has
                    // no ViewAncestor to dispatch events with.
                    return mDefInputConnection.sendKeyEvent(event);
                }
            };
        }
        outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_FILTER;
        outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE;
        return mPublicInputConnection;
    }
    return null;
}

From source file:com.appunite.list.AbsHorizontalListView.java

/**
 * Return an InputConnection for editing of the filter text.
 *//*from   w  w  w. j  av a2 s .c o m*/
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    if (isTextFilterEnabled()) {
        // XXX we need to have the text filter created, so we can get an
        // InputConnection to proxy to.  Unfortunately this means we pretty
        // much need to make it as soon as a list view gets focus.
        createTextFilter(false);
        if (mPublicInputConnection == null) {
            mDefInputConnection = new BaseInputConnection(this, false);
            mPublicInputConnection = new InputConnectionWrapper(mTextFilter.onCreateInputConnection(outAttrs),
                    true) {
                @Override
                public boolean reportFullscreenMode(boolean enabled) {
                    // Use our own input connection, since it is
                    // the "real" one the IME is talking with.
                    return mDefInputConnection.reportFullscreenMode(enabled);
                }

                @Override
                public boolean performEditorAction(int editorAction) {
                    // The editor is off in its own window; we need to be
                    // the one that does this.
                    if (editorAction == EditorInfo.IME_ACTION_DONE) {
                        InputMethodManager imm = (InputMethodManager) getContext()
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        if (imm != null) {
                            imm.hideSoftInputFromWindow(getWindowToken(), 0);
                        }
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean sendKeyEvent(KeyEvent event) {
                    // Use our own input connection, since the filter
                    // text view may not be shown in a window so has
                    // no ViewAncestor to dispatch events with.
                    return mDefInputConnection.sendKeyEvent(event);
                }
            };
        }
        outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_FILTER;
        outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE;
        return mPublicInputConnection;
    }
    return null;
}