Search in sources :

Example 6 with CompletionInfo

use of android.view.inputmethod.CompletionInfo in project android_frameworks_base by ResurrectionRemix.

the class AutoCompleteTextView method buildImeCompletions.

private void buildImeCompletions() {
    final ListAdapter adapter = mAdapter;
    if (adapter != null) {
        InputMethodManager imm = InputMethodManager.peekInstance();
        if (imm != null) {
            final int count = Math.min(adapter.getCount(), 20);
            CompletionInfo[] completions = new CompletionInfo[count];
            int realCount = 0;
            for (int i = 0; i < count; i++) {
                if (adapter.isEnabled(i)) {
                    Object item = adapter.getItem(i);
                    long id = adapter.getItemId(i);
                    completions[realCount] = new CompletionInfo(id, realCount, convertSelectionToString(item));
                    realCount++;
                }
            }
            if (realCount != count) {
                CompletionInfo[] tmp = new CompletionInfo[realCount];
                System.arraycopy(completions, 0, tmp, 0, realCount);
                completions = tmp;
            }
            imm.displayCompletions(this, completions);
        }
    }
}
Also used : CompletionInfo(android.view.inputmethod.CompletionInfo) InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 7 with CompletionInfo

use of android.view.inputmethod.CompletionInfo in project HistoryEditText by zenlibs.

the class AbsHistoryEditText method buildDropDown.

/**
     * <p>
     * Builds the popup window's content and returns the height the popup should
     * have. Returns -1 when the content already exists.
     * </p>
     * 
     * @return the content's height or -1 if content already exists
     */
private int buildDropDown() {
    ViewGroup dropDownView;
    int otherHeights = 0;
    rebuildCombinedAdapter();
    if (mCombinedAdapter != null) {
        if (mImm != null) {
            final int count = Math.min(mCombinedAdapter.getCount(), 20);
            CompletionInfo[] completions = new CompletionInfo[count];
            int realCount = 0;
            for (int i = 0; i < count; i++) {
                if (mCombinedAdapter.isEnabled(i)) {
                    realCount++;
                    Object item = mCombinedAdapter.getItem(i);
                    long id = mCombinedAdapter.getItemId(i);
                    completions[i] = new CompletionInfo(id, i, convertSelectionToString(item));
                }
            }
            if (realCount != count) {
                CompletionInfo[] tmp = new CompletionInfo[realCount];
                System.arraycopy(completions, 0, tmp, 0, realCount);
                completions = tmp;
            }
            mImm.displayCompletions(this, completions);
        }
    }
    if (mDropDownList == null) {
        Context context = getContext();
        mHideSelector = new ListSelectorHider();
        /**
             * This Runnable exists for the sole purpose of checking if the view
             * layout has got completed and if so call showDropDown to display
             * the drop down. This is used to show the drop down as soon as
             * possible after user opens up the search dialog, without waiting
             * for the normal UI pipeline to do it's job which is slower than
             * this method.
             */
        mShowDropDownRunnable = new Runnable() {

            public void run() {
                // View layout should be all done before displaying the drop down.
                View view = getDropDownAnchorView();
                if (view != null && view.getWindowToken() != null) {
                    showDropDown();
                }
            }
        };
        mDropDownList = new DropDownListView(context);
        mDropDownList.setSelector(mDropDownListHighlight);
        mDropDownList.setAdapter(mCombinedAdapter);
        mDropDownList.setVerticalFadingEdgeEnabled(true);
        mDropDownList.setOnItemClickListener(mDropDownItemClickListener);
        mDropDownList.setFocusable(true);
        mDropDownList.setFocusableInTouchMode(true);
        mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (position != -1) {
                    DropDownListView dropDownList = mDropDownList;
                    if (dropDownList != null) {
                        dropDownList.mListSelectionHidden = false;
                    }
                }
            }

            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        mDropDownList.setOnScrollListener(new PopupScrollListener());
        if (mItemSelectedListener != null) {
            mDropDownList.setOnItemSelectedListener(mItemSelectedListener);
        }
        dropDownView = mDropDownList;
        View hintView = getHintView(context);
        if (hintView != null) {
            // if an hint has been specified, we accomodate more space for it and
            // add a text view in the drop down menu, at the bottom of the list
            LinearLayout hintContainer = new LinearLayout(context);
            hintContainer.setOrientation(LinearLayout.VERTICAL);
            LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f);
            hintContainer.addView(dropDownView, hintParams);
            hintContainer.addView(hintView);
            // measure the hint's height to find how much more vertical space
            // we need to add to the drop down's height
            int widthSpec = MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST);
            int heightSpec = MeasureSpec.UNSPECIFIED;
            hintView.measure(widthSpec, heightSpec);
            hintParams = (LinearLayout.LayoutParams) hintView.getLayoutParams();
            otherHeights = hintView.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
            dropDownView = hintContainer;
        }
        mPopup.setContentView(dropDownView);
    } else {
        dropDownView = (ViewGroup) mPopup.getContentView();
        final View view = dropDownView.findViewById(HINT_VIEW_ID);
        if (view != null) {
            LinearLayout.LayoutParams hintParams = (LinearLayout.LayoutParams) view.getLayoutParams();
            otherHeights = view.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
        }
    }
    // Max height available on the screen for a popup.
    boolean ignoreBottomDecorations = mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED;
    final int maxHeight = mPopup.getMaxAvailableHeightCompat(getDropDownAnchorView(), mDropDownVerticalOffset, ignoreBottomDecorations);
    // getMaxAvailableHeight() subtracts the padding, so we put it back,
    // to get the available height for the whole window
    int padding = 0;
    Drawable background = mPopup.getBackground();
    if (background != null) {
        background.getPadding(mTempRect);
        padding = mTempRect.top + mTempRect.bottom;
    }
    if (false || mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
        return maxHeight + padding;
    }
    final int listContent = mDropDownList.measureHeightOfChildrenCompat(MeasureSpec.UNSPECIFIED, 0, FroyoListView.NO_POSITION, maxHeight - otherHeights, 2);
    // the popup if it is not needed
    if (listContent > 0)
        otherHeights += padding;
    return listContent + otherHeights;
}
Also used : Context(android.content.Context) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) CompletionInfo(android.view.inputmethod.CompletionInfo) AdapterView(android.widget.AdapterView) LinearLayout(android.widget.LinearLayout)

Example 8 with CompletionInfo

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

the class AutoCompleteTextView method buildImeCompletions.

private void buildImeCompletions() {
    final ListAdapter adapter = mAdapter;
    if (adapter != null) {
        InputMethodManager imm = InputMethodManager.peekInstance();
        if (imm != null) {
            final int count = Math.min(adapter.getCount(), 20);
            CompletionInfo[] completions = new CompletionInfo[count];
            int realCount = 0;
            for (int i = 0; i < count; i++) {
                if (adapter.isEnabled(i)) {
                    Object item = adapter.getItem(i);
                    long id = adapter.getItemId(i);
                    completions[realCount] = new CompletionInfo(id, realCount, convertSelectionToString(item));
                    realCount++;
                }
            }
            if (realCount != count) {
                CompletionInfo[] tmp = new CompletionInfo[realCount];
                System.arraycopy(completions, 0, tmp, 0, realCount);
                completions = tmp;
            }
            imm.displayCompletions(this, completions);
        }
    }
}
Also used : CompletionInfo(android.view.inputmethod.CompletionInfo) InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 9 with CompletionInfo

use of android.view.inputmethod.CompletionInfo 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 = '�';
                        }
                        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 10 with CompletionInfo

use of android.view.inputmethod.CompletionInfo in project XobotOS by xamarin.

the class AutoCompleteTextView method buildImeCompletions.

private void buildImeCompletions() {
    final ListAdapter adapter = mAdapter;
    if (adapter != null) {
        InputMethodManager imm = InputMethodManager.peekInstance();
        if (imm != null) {
            final int count = Math.min(adapter.getCount(), 20);
            CompletionInfo[] completions = new CompletionInfo[count];
            int realCount = 0;
            for (int i = 0; i < count; i++) {
                if (adapter.isEnabled(i)) {
                    realCount++;
                    Object item = adapter.getItem(i);
                    long id = adapter.getItemId(i);
                    completions[i] = new CompletionInfo(id, i, convertSelectionToString(item));
                }
            }
            if (realCount != count) {
                CompletionInfo[] tmp = new CompletionInfo[realCount];
                System.arraycopy(completions, 0, tmp, 0, realCount);
                completions = tmp;
            }
            imm.displayCompletions(this, completions);
        }
    }
}
Also used : CompletionInfo(android.view.inputmethod.CompletionInfo) InputMethodManager(android.view.inputmethod.InputMethodManager)

Aggregations

CompletionInfo (android.view.inputmethod.CompletionInfo)11 InputMethodManager (android.view.inputmethod.InputMethodManager)9 SuppressLint (android.annotation.SuppressLint)2 ListAdapter (android.widget.ListAdapter)2 Context (android.content.Context)1 Paint (android.graphics.Paint)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 BaseInputConnection (android.view.inputmethod.BaseInputConnection)1 CorrectionInfo (android.view.inputmethod.CorrectionInfo)1 ExtractedTextRequest (android.view.inputmethod.ExtractedTextRequest)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 IOException (java.io.IOException)1