Search in sources :

Example 56 with InputMethodManager

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

the class View method onFocusChanged.

/**
     * Called by the view system when the focus state of this view changes.
     * When the focus change event is caused by directional navigation, direction
     * and previouslyFocusedRect provide insight into where the focus is coming from.
     * When overriding, be sure to call up through to the super class so that
     * the standard focus handling will occur.
     *
     * @param gainFocus True if the View has focus; false otherwise.
     * @param direction The direction focus has moved when requestFocus()
     *                  is called to give this view focus. Values are
     *                  {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT},
     *                  {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}.
     *                  It may not always apply, in which case use the default.
     * @param previouslyFocusedRect The rectangle, in this view's coordinate
     *        system, of the previously focused view.  If applicable, this will be
     *        passed in as finer grained information about where the focus is coming
     *        from (in addition to direction).  Will be <code>null</code> otherwise.
     */
@CallSuper
protected void onFocusChanged(boolean gainFocus, @FocusDirection int direction, @Nullable Rect previouslyFocusedRect) {
    if (gainFocus) {
        sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    } else {
        notifyViewAccessibilityStateChangedIfNeeded(AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED);
    }
    InputMethodManager imm = InputMethodManager.peekInstance();
    if (!gainFocus) {
        if (isPressed()) {
            setPressed(false);
        }
        if (imm != null && mAttachInfo != null && mAttachInfo.mHasWindowFocus) {
            imm.focusOut(this);
        }
        onFocusLost();
    } else if (imm != null && mAttachInfo != null && mAttachInfo.mHasWindowFocus) {
        imm.focusIn(this);
    }
    invalidate(true);
    ListenerInfo li = mListenerInfo;
    if (li != null && li.mOnFocusChangeListener != null) {
        li.mOnFocusChangeListener.onFocusChange(this, gainFocus);
    }
    if (mAttachInfo != null) {
        mAttachInfo.mKeyDispatchState.reset(this);
    }
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager) CallSuper(android.annotation.CallSuper)

Example 57 with InputMethodManager

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

the class View method dispatchDetachedFromWindow.

void dispatchDetachedFromWindow() {
    AttachInfo info = mAttachInfo;
    if (info != null) {
        int vis = info.mWindowVisibility;
        if (vis != GONE) {
            onWindowVisibilityChanged(GONE);
            if (isShown()) {
                // Invoking onVisibilityAggregated directly here since the subtree
                // will also receive detached from window
                onVisibilityAggregated(false);
            }
        }
    }
    onDetachedFromWindow();
    onDetachedFromWindowInternal();
    InputMethodManager imm = InputMethodManager.peekInstance();
    if (imm != null) {
        imm.onViewDetachedFromWindow(this);
    }
    ListenerInfo li = mListenerInfo;
    final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = li != null ? li.mOnAttachStateChangeListeners : null;
    if (listeners != null && listeners.size() > 0) {
        // the array from being modified while we iterate it.
        for (OnAttachStateChangeListener listener : listeners) {
            listener.onViewDetachedFromWindow(this);
        }
    }
    if ((mPrivateFlags & PFLAG_SCROLL_CONTAINER_ADDED) != 0) {
        mAttachInfo.mScrollContainers.remove(this);
        mPrivateFlags &= ~PFLAG_SCROLL_CONTAINER_ADDED;
    }
    mAttachInfo = null;
    if (mOverlay != null) {
        mOverlay.getOverlayView().dispatchDetachedFromWindow();
    }
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 58 with InputMethodManager

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

the class View method onWindowFocusChanged.

/**
     * Called when the window containing this view gains or loses focus.  Note
     * that this is separate from view focus: to receive key events, both
     * your view and its window must have focus.  If a window is displayed
     * on top of yours that takes input focus, then your own window will lose
     * focus but the view focus will remain unchanged.
     *
     * @param hasWindowFocus True if the window containing this view now has
     *        focus, false otherwise.
     */
public void onWindowFocusChanged(boolean hasWindowFocus) {
    InputMethodManager imm = InputMethodManager.peekInstance();
    if (!hasWindowFocus) {
        if (isPressed()) {
            setPressed(false);
        }
        if (imm != null && (mPrivateFlags & PFLAG_FOCUSED) != 0) {
            imm.focusOut(this);
        }
        removeLongPressCallback();
        removeTapCallback();
        onFocusLost();
    } else if (imm != null && (mPrivateFlags & PFLAG_FOCUSED) != 0) {
        imm.focusIn(this);
    }
    refreshDrawableState();
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 59 with InputMethodManager

use of android.view.inputmethod.InputMethodManager in project weiciyuan by qii.

the class WriteCommentActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm.isActive()) {
                imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
            }
            finish();
            break;
        case R.id.menu_enable_ori_comment:
            if (enableCommentOri.isChecked()) {
                enableCommentOri.setChecked(false);
            } else {
                enableCommentOri.setChecked(true);
            }
            break;
        case R.id.menu_enable_repost:
            if (enableRepost.isChecked()) {
                enableRepost.setChecked(false);
            } else {
                enableRepost.setChecked(true);
            }
            break;
        case R.id.menu_at:
            Intent intent = new Intent(WriteCommentActivity.this, AtUserActivity.class);
            intent.putExtra("token", token);
            startActivityForResult(intent, AT_USER);
            break;
        case R.id.menu_clear:
            clearContentMenu();
            break;
    }
    return true;
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager) Intent(android.content.Intent)

Example 60 with InputMethodManager

use of android.view.inputmethod.InputMethodManager in project FloatingSearchView by renaudcerrato.

the class ViewUtils method closeSoftKeyboard.

public static void closeSoftKeyboard(Activity activity) {
    View currentFocusView = activity.getCurrentFocus();
    if (currentFocusView != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(currentFocusView.getWindowToken(), 0);
    }
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View)

Aggregations

InputMethodManager (android.view.inputmethod.InputMethodManager)631 View (android.view.View)120 TextView (android.widget.TextView)67 Paint (android.graphics.Paint)43 Spannable (android.text.Spannable)34 Editable (android.text.Editable)33 EditText (android.widget.EditText)33 ImageView (android.widget.ImageView)31 Intent (android.content.Intent)29 RemoteException (android.os.RemoteException)23 KeyEvent (android.view.KeyEvent)22 TextPaint (android.text.TextPaint)21 Point (android.graphics.Point)18 InputMethodInfo (android.view.inputmethod.InputMethodInfo)18 AdapterView (android.widget.AdapterView)18 Button (android.widget.Button)16 RemoteView (android.widget.RemoteViews.RemoteView)16 Resources (android.content.res.Resources)15 ListView (android.widget.ListView)15 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)14