Search in sources :

Example 6 with InputConnection

use of android.view.inputmethod.InputConnection in project Signal-Android by WhisperSystems.

the class ComposeText method onCreateInputConnection.

@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
    InputConnection inputConnection = super.onCreateInputConnection(editorInfo);
    if (TextSecurePreferences.isEnterSendsEnabled(getContext())) {
        editorInfo.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
    }
    if (Build.VERSION.SDK_INT < 21)
        return inputConnection;
    if (mediaListener == null)
        return inputConnection;
    if (inputConnection == null)
        return null;
    EditorInfoCompat.setContentMimeTypes(editorInfo, new String[] { "image/jpeg", "image/png", "image/gif" });
    return InputConnectionCompat.createWrapper(inputConnection, editorInfo, new CommitContentListener(mediaListener));
}
Also used : InputConnection(android.view.inputmethod.InputConnection)

Example 7 with InputConnection

use of android.view.inputmethod.InputConnection in project cornerstone by Onskreen.

the class ViewRootImpl method handleMessage.

@Override
public void handleMessage(Message msg) {
    switch(msg.what) {
        case View.AttachInfo.INVALIDATE_MSG:
            ((View) msg.obj).invalidate();
            break;
        case View.AttachInfo.INVALIDATE_RECT_MSG:
            final View.AttachInfo.InvalidateInfo info = (View.AttachInfo.InvalidateInfo) msg.obj;
            info.target.invalidate(info.left, info.top, info.right, info.bottom);
            info.release();
            break;
        case DO_TRAVERSAL:
            if (mProfile) {
                Debug.startMethodTracing("ViewAncestor");
            }
            final long traversalStartTime;
            if (ViewDebug.DEBUG_LATENCY) {
                traversalStartTime = System.nanoTime();
                mLastDrawDurationNanos = 0;
            }
            performTraversals();
            if (ViewDebug.DEBUG_LATENCY) {
                long now = System.nanoTime();
                Log.d(TAG, "Latency: Spent " + ((now - traversalStartTime) * 0.000001f) + "ms in performTraversals(), with " + (mLastDrawDurationNanos * 0.000001f) + "ms of that time in draw()");
                mLastTraversalFinishedTimeNanos = now;
            }
            if (mProfile) {
                Debug.stopMethodTracing();
                mProfile = false;
            }
            break;
        case FINISHED_EVENT:
            handleFinishedEvent(msg.arg1, msg.arg2 != 0);
            break;
        case DISPATCH_KEY:
            deliverKeyEvent((KeyEvent) msg.obj, msg.arg1 != 0);
            break;
        case DISPATCH_POINTER:
            deliverPointerEvent((MotionEvent) msg.obj, msg.arg1 != 0);
            break;
        case DISPATCH_TRACKBALL:
            deliverTrackballEvent((MotionEvent) msg.obj, msg.arg1 != 0);
            break;
        case DISPATCH_GENERIC_MOTION:
            deliverGenericMotionEvent((MotionEvent) msg.obj, msg.arg1 != 0);
            break;
        case PROCESS_INPUT_EVENTS:
            processInputEvents(false);
            break;
        case DISPATCH_APP_VISIBILITY:
            handleAppVisibility(msg.arg1 != 0);
            break;
        case DISPATCH_GET_NEW_SURFACE:
            handleGetNewSurface();
            break;
        case RESIZED:
            ResizedInfo ri = (ResizedInfo) msg.obj;
            if (mWinFrame.width() == msg.arg1 && mWinFrame.height() == msg.arg2 && mPendingContentInsets.equals(ri.coveredInsets) && mPendingVisibleInsets.equals(ri.visibleInsets) && ((ResizedInfo) msg.obj).newConfig == null) {
                break;
            }
        // fall through...
        case RESIZED_REPORT:
            if (mAdded) {
                Configuration config = ((ResizedInfo) msg.obj).newConfig;
                if (config != null) {
                    updateConfiguration(config, false);
                }
                mWinFrame.left = 0;
                mWinFrame.right = msg.arg1;
                mWinFrame.top = 0;
                mWinFrame.bottom = msg.arg2;
                mPendingContentInsets.set(((ResizedInfo) msg.obj).coveredInsets);
                mPendingVisibleInsets.set(((ResizedInfo) msg.obj).visibleInsets);
                if (msg.what == RESIZED_REPORT) {
                    mReportNextDraw = true;
                }
                if (mView != null) {
                    forceLayout(mView);
                }
                requestLayout();
            }
            break;
        case WINDOW_FOCUS_CHANGED:
            {
                if (mAdded) {
                    boolean hasWindowFocus = msg.arg1 != 0;
                    mAttachInfo.mHasWindowFocus = hasWindowFocus;
                    profileRendering(hasWindowFocus);
                    if (hasWindowFocus) {
                        boolean inTouchMode = msg.arg2 != 0;
                        ensureTouchModeLocally(inTouchMode);
                        if (mAttachInfo.mHardwareRenderer != null && mSurface != null && mSurface.isValid()) {
                            mFullRedrawNeeded = true;
                            try {
                                mAttachInfo.mHardwareRenderer.initializeIfNeeded(mWidth, mHeight, mAttachInfo, mHolder);
                            } catch (Surface.OutOfResourcesException e) {
                                Log.e(TAG, "OutOfResourcesException locking surface", e);
                                try {
                                    if (!sWindowSession.outOfMemory(mWindow)) {
                                        Slog.w(TAG, "No processes killed for memory; killing self");
                                        Process.killProcess(Process.myPid());
                                    }
                                } catch (RemoteException ex) {
                                }
                                // Retry in a bit.
                                sendMessageDelayed(obtainMessage(msg.what, msg.arg1, msg.arg2), 500);
                                return;
                            }
                        }
                    }
                    mLastWasImTarget = WindowManager.LayoutParams.mayUseInputMethod(mWindowAttributes.flags);
                    InputMethodManager imm = InputMethodManager.peekInstance();
                    if (mView != null) {
                        if (hasWindowFocus && imm != null && mLastWasImTarget) {
                            imm.startGettingWindowFocus(mView);
                        }
                        mAttachInfo.mKeyDispatchState.reset();
                        mView.dispatchWindowFocusChanged(hasWindowFocus);
                    }
                    // so all of the view state is set up correctly.
                    if (hasWindowFocus) {
                        if (imm != null && mLastWasImTarget) {
                            imm.onWindowFocus(mView, mView.findFocus(), mWindowAttributes.softInputMode, !mHasHadWindowFocus, mWindowAttributes.flags);
                        }
                        // Clear the forward bit.  We can just do this directly, since
                        // the window manager doesn't care about it.
                        mWindowAttributes.softInputMode &= ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
                        ((WindowManager.LayoutParams) mView.getLayoutParams()).softInputMode &= ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
                        mHasHadWindowFocus = true;
                    }
                    if (hasWindowFocus && mView != null) {
                        sendAccessibilityEvents();
                    }
                }
            }
            break;
        case DIE:
            doDie();
            break;
        case DISPATCH_KEY_FROM_IME:
            {
                if (LOCAL_LOGV)
                    Log.v(TAG, "Dispatching key " + msg.obj + " from IME to " + mView);
                KeyEvent event = (KeyEvent) msg.obj;
                if ((event.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) != 0) {
                    // The IME is trying to say this event is from the
                    // system!  Bad bad bad!
                    //noinspection UnusedAssignment
                    event = KeyEvent.changeFlags(event, event.getFlags() & ~KeyEvent.FLAG_FROM_SYSTEM);
                }
                deliverKeyEventPostIme((KeyEvent) msg.obj, false);
            }
            break;
        case FINISH_INPUT_CONNECTION:
            {
                InputMethodManager imm = InputMethodManager.peekInstance();
                if (imm != null) {
                    imm.reportFinishInputConnection((InputConnection) msg.obj);
                }
            }
            break;
        case CHECK_FOCUS:
            {
                InputMethodManager imm = InputMethodManager.peekInstance();
                if (imm != null) {
                    imm.checkFocus();
                }
            }
            break;
        case CLOSE_SYSTEM_DIALOGS:
            {
                if (mView != null) {
                    mView.onCloseSystemDialogs((String) msg.obj);
                }
            }
            break;
        case DISPATCH_DRAG_EVENT:
        case DISPATCH_DRAG_LOCATION_EVENT:
            {
                DragEvent event = (DragEvent) msg.obj;
                // only present when this app called startDrag()
                event.mLocalState = mLocalDragState;
                handleDragEvent(event);
            }
            break;
        case DISPATCH_SYSTEM_UI_VISIBILITY:
            {
                handleDispatchSystemUiVisibilityChanged((SystemUiVisibilityInfo) msg.obj);
            }
            break;
        case UPDATE_CONFIGURATION:
            {
                Configuration config = (Configuration) msg.obj;
                if (config.isOtherSeqNewer(mLastConfiguration)) {
                    config = mLastConfiguration;
                }
                updateConfiguration(config, false);
            }
            break;
        case DO_FIND_ACCESSIBLITY_NODE_INFO_BY_ACCESSIBILITY_ID:
            {
                if (mView != null) {
                    getAccessibilityInteractionController().findAccessibilityNodeInfoByAccessibilityIdUiThread(msg);
                }
            }
            break;
        case DO_PERFORM_ACCESSIBILITY_ACTION:
            {
                if (mView != null) {
                    getAccessibilityInteractionController().perfromAccessibilityActionUiThread(msg);
                }
            }
            break;
        case DO_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_ID:
            {
                if (mView != null) {
                    getAccessibilityInteractionController().findAccessibilityNodeInfoByViewIdUiThread(msg);
                }
            }
            break;
        case DO_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_TEXT:
            {
                if (mView != null) {
                    getAccessibilityInteractionController().findAccessibilityNodeInfosByViewTextUiThread(msg);
                }
            }
            break;
    }
}
Also used : Configuration(android.content.res.Configuration) InputMethodManager(android.view.inputmethod.InputMethodManager) InputConnection(android.view.inputmethod.InputConnection) RemoteException(android.os.RemoteException)

Example 8 with InputConnection

use of android.view.inputmethod.InputConnection in project Jota-Text-Editor-old by jiro-aqua.

the class TextView method onCreateInputConnection.

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    if (onCheckIsTextEditor()) {
        if (mInputMethodState == null) {
            mInputMethodState = new InputMethodState();
        }
        outAttrs.inputType = mInputType;
        if (mInputContentType != null) {
            outAttrs.imeOptions = mInputContentType.imeOptions;
            outAttrs.privateImeOptions = mInputContentType.privateImeOptions;
            outAttrs.actionLabel = mInputContentType.imeActionLabel;
            outAttrs.actionId = mInputContentType.imeActionId;
            outAttrs.extras = mInputContentType.extras;
        } else {
            outAttrs.imeOptions = EditorInfo.IME_NULL;
        }
        if ((outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION) == EditorInfo.IME_ACTION_UNSPECIFIED) {
            if (focusSearch(FOCUS_DOWN) != null) {
                // An action has not been set, but the enter key will move to
                // the next focus, so set the action to that.
                outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
            } else {
                // An action has not been set, and there is no focus to move
                // to, so let's just supply a "done" action.
                outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE;
            }
            if (!shouldAdvanceFocusOnEnter()) {
                outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION;
            }
        }
        if ((outAttrs.inputType & (InputType.TYPE_MASK_CLASS | InputType.TYPE_TEXT_FLAG_MULTI_LINE)) == (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE)) {
            // Multi-line text editors should always show an enter key.
            outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION;
        }
        outAttrs.hintText = mHint;
        if (mText instanceof Editable) {
            InputConnection ic = new EditableInputConnection(this);
            outAttrs.initialSelStart = getSelectionStart();
            outAttrs.initialSelEnd = getSelectionEnd();
            outAttrs.initialCapsMode = ic.getCursorCapsMode(mInputType);
            // patch by matthias.gruenewald@googlemail.com
            if (!mDontUseSoftkeyWithHardkey || getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
                InputMethodManager imm = InputMethodManager.peekInstance();
                if (imm != null) {
                    imm.showSoftInput(this, 0);
                }
            }
            return ic;
        }
    }
    return null;
}
Also used : BaseInputConnection(android.view.inputmethod.BaseInputConnection) InputConnection(android.view.inputmethod.InputConnection) Editable(android.text.Editable) InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 9 with InputConnection

use of android.view.inputmethod.InputConnection in project platform_frameworks_base by android.

the class InputMethodService method startExtractingText.

void startExtractingText(boolean inputChanged) {
    final ExtractEditText eet = mExtractEditText;
    if (eet != null && getCurrentInputStarted() && isFullscreenMode()) {
        mExtractedToken++;
        ExtractedTextRequest req = new ExtractedTextRequest();
        req.token = mExtractedToken;
        req.flags = InputConnection.GET_TEXT_WITH_STYLES;
        req.hintMaxLines = 10;
        req.hintMaxChars = 10000;
        InputConnection ic = getCurrentInputConnection();
        mExtractedText = ic == null ? null : ic.getExtractedText(req, InputConnection.GET_EXTRACTED_TEXT_MONITOR);
        if (mExtractedText == null || ic == null) {
            Log.e(TAG, "Unexpected null in startExtractingText : mExtractedText = " + mExtractedText + ", input connection = " + ic);
        }
        final EditorInfo ei = getCurrentInputEditorInfo();
        try {
            eet.startInternalChanges();
            onUpdateExtractingVisibility(ei);
            onUpdateExtractingViews(ei);
            int inputType = ei.inputType;
            if ((inputType & EditorInfo.TYPE_MASK_CLASS) == EditorInfo.TYPE_CLASS_TEXT) {
                if ((inputType & EditorInfo.TYPE_TEXT_FLAG_IME_MULTI_LINE) != 0) {
                    inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE;
                }
            }
            eet.setInputType(inputType);
            eet.setHint(ei.hintText);
            if (mExtractedText != null) {
                eet.setEnabled(true);
                eet.setExtractedText(mExtractedText);
            } else {
                eet.setEnabled(false);
                eet.setText("");
            }
        } finally {
            eet.finishInternalChanges();
        }
        if (inputChanged) {
            onExtractingInputChanged(ei);
        }
    }
}
Also used : InputConnection(android.view.inputmethod.InputConnection) EditorInfo(android.view.inputmethod.EditorInfo) ExtractedTextRequest(android.view.inputmethod.ExtractedTextRequest)

Example 10 with InputConnection

use of android.view.inputmethod.InputConnection in project platform_frameworks_base by android.

the class IInputMethodWrapper method executeMessage.

@Override
public void executeMessage(Message msg) {
    InputMethod inputMethod = mInputMethod.get();
    // Need a valid reference to the inputMethod for everything except a dump.
    if (inputMethod == null && msg.what != DO_DUMP) {
        Log.w(TAG, "Input method reference was null, ignoring message: " + msg.what);
        return;
    }
    switch(msg.what) {
        case DO_DUMP:
            {
                AbstractInputMethodService target = mTarget.get();
                if (target == null) {
                    return;
                }
                SomeArgs args = (SomeArgs) msg.obj;
                try {
                    target.dump((FileDescriptor) args.arg1, (PrintWriter) args.arg2, (String[]) args.arg3);
                } catch (RuntimeException e) {
                    ((PrintWriter) args.arg2).println("Exception: " + e);
                }
                synchronized (args.arg4) {
                    ((CountDownLatch) args.arg4).countDown();
                }
                args.recycle();
                return;
            }
        case DO_ATTACH_TOKEN:
            {
                inputMethod.attachToken((IBinder) msg.obj);
                return;
            }
        case DO_SET_INPUT_CONTEXT:
            {
                inputMethod.bindInput((InputBinding) msg.obj);
                return;
            }
        case DO_UNSET_INPUT_CONTEXT:
            inputMethod.unbindInput();
            return;
        case DO_START_INPUT:
            {
                SomeArgs args = (SomeArgs) msg.obj;
                int missingMethods = msg.arg1;
                IInputContext inputContext = (IInputContext) args.arg1;
                InputConnection ic = inputContext != null ? new InputConnectionWrapper(mTarget, inputContext, missingMethods) : null;
                EditorInfo info = (EditorInfo) args.arg2;
                info.makeCompatible(mTargetSdkVersion);
                inputMethod.startInput(ic, info);
                args.recycle();
                return;
            }
        case DO_RESTART_INPUT:
            {
                SomeArgs args = (SomeArgs) msg.obj;
                int missingMethods = msg.arg1;
                IInputContext inputContext = (IInputContext) args.arg1;
                InputConnection ic = inputContext != null ? new InputConnectionWrapper(mTarget, inputContext, missingMethods) : null;
                EditorInfo info = (EditorInfo) args.arg2;
                info.makeCompatible(mTargetSdkVersion);
                inputMethod.restartInput(ic, info);
                args.recycle();
                return;
            }
        case DO_CREATE_SESSION:
            {
                SomeArgs args = (SomeArgs) msg.obj;
                inputMethod.createSession(new InputMethodSessionCallbackWrapper(mContext, (InputChannel) args.arg1, (IInputSessionCallback) args.arg2));
                args.recycle();
                return;
            }
        case DO_SET_SESSION_ENABLED:
            inputMethod.setSessionEnabled((InputMethodSession) msg.obj, msg.arg1 != 0);
            return;
        case DO_REVOKE_SESSION:
            inputMethod.revokeSession((InputMethodSession) msg.obj);
            return;
        case DO_SHOW_SOFT_INPUT:
            inputMethod.showSoftInput(msg.arg1, (ResultReceiver) msg.obj);
            return;
        case DO_HIDE_SOFT_INPUT:
            inputMethod.hideSoftInput(msg.arg1, (ResultReceiver) msg.obj);
            return;
        case DO_CHANGE_INPUTMETHOD_SUBTYPE:
            inputMethod.changeInputMethodSubtype((InputMethodSubtype) msg.obj);
            return;
    }
    Log.w(TAG, "Unhandled message code: " + msg.what);
}
Also used : IInputContext(com.android.internal.view.IInputContext) InputConnectionWrapper(com.android.internal.view.InputConnectionWrapper) FileDescriptor(java.io.FileDescriptor) InputConnection(android.view.inputmethod.InputConnection) IBinder(android.os.IBinder) EditorInfo(android.view.inputmethod.EditorInfo) SomeArgs(com.android.internal.os.SomeArgs) IInputMethod(com.android.internal.view.IInputMethod) InputMethod(android.view.inputmethod.InputMethod) InputBinding(android.view.inputmethod.InputBinding) PrintWriter(java.io.PrintWriter)

Aggregations

InputConnection (android.view.inputmethod.InputConnection)81 EditorInfo (android.view.inputmethod.EditorInfo)20 InputBinding (android.view.inputmethod.InputBinding)14 InputConnectionWrapper (com.android.internal.view.InputConnectionWrapper)14 KeyEvent (android.view.KeyEvent)9 ViewGroup (android.view.ViewGroup)9 ExtractedTextRequest (android.view.inputmethod.ExtractedTextRequest)9 Editable (android.text.Editable)8 View (android.view.View)8 BaseInputConnection (android.view.inputmethod.BaseInputConnection)8 IBinder (android.os.IBinder)7 InputMethod (android.view.inputmethod.InputMethod)7 LinearLayout (android.widget.LinearLayout)7 TextView (android.widget.TextView)7 IInputContext (com.android.internal.view.IInputContext)7 IInputMethod (com.android.internal.view.IInputMethod)7 EditableInputConnection (com.android.internal.widget.EditableInputConnection)7 FileDescriptor (java.io.FileDescriptor)7 PrintWriter (java.io.PrintWriter)7 Spannable (android.text.Spannable)6