Java Code Examples for android.view.inputmethod.InputMethodManager#peekInstance()

The following examples show how to use android.view.inputmethod.InputMethodManager#peekInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimePickerClockDelegate.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void toggleRadialPickerMode() {
    if (mRadialPickerModeEnabled) {
        mRadialTimePickerView.setVisibility(View.GONE);
        mRadialTimePickerHeader.setVisibility(View.GONE);
        mTextInputPickerHeader.setVisibility(View.VISIBLE);
        mTextInputPickerView.setVisibility(View.VISIBLE);
        mRadialTimePickerModeButton.setImageResource(R.drawable.btn_clock_material);
        mRadialTimePickerModeButton.setContentDescription(
                mRadialTimePickerModeEnabledDescription);
        mRadialPickerModeEnabled = false;
    } else {
        mRadialTimePickerView.setVisibility(View.VISIBLE);
        mRadialTimePickerHeader.setVisibility(View.VISIBLE);
        mTextInputPickerHeader.setVisibility(View.GONE);
        mTextInputPickerView.setVisibility(View.GONE);
        mRadialTimePickerModeButton.setImageResource(R.drawable.btn_keyboard_key_material);
        mRadialTimePickerModeButton.setContentDescription(
                mTextInputPickerModeEnabledDescription);
        updateTextInputPicker();
        InputMethodManager imm = InputMethodManager.peekInstance();
        if (imm != null) {
            imm.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        }
        mRadialPickerModeEnabled = true;
    }
}
 
Example 2
Source File: DatePickerSpinnerDelegate.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void updateInputState() {
    // Make sure that if the user changes the value and the IME is active
    // for one of the inputs if this widget, the IME is closed. If the user
    // changed the value via the IME and there is a next input the IME will
    // be shown, otherwise the user chose another means of changing the
    // value and having the IME up makes no sense.
    InputMethodManager inputMethodManager = InputMethodManager.peekInstance();
    if (inputMethodManager != null) {
        if (inputMethodManager.isActive(mYearSpinnerInput)) {
            mYearSpinnerInput.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        } else if (inputMethodManager.isActive(mMonthSpinnerInput)) {
            mMonthSpinnerInput.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        } else if (inputMethodManager.isActive(mDaySpinnerInput)) {
            mDaySpinnerInput.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        }
    }
}
 
Example 3
Source File: TimePickerSpinnerDelegate.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void updateInputState() {
    // Make sure that if the user changes the value and the IME is active
    // for one of the inputs if this widget, the IME is closed. If the user
    // changed the value via the IME and there is a next input the IME will
    // be shown, otherwise the user chose another means of changing the
    // value and having the IME up makes no sense.
    InputMethodManager inputMethodManager = InputMethodManager.peekInstance();
    if (inputMethodManager != null) {
        if (inputMethodManager.isActive(mHourSpinnerInput)) {
            mHourSpinnerInput.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        } else if (inputMethodManager.isActive(mMinuteSpinnerInput)) {
            mMinuteSpinnerInput.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        } else if (inputMethodManager.isActive(mAmPmSpinnerInput)) {
            mAmPmSpinnerInput.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        }
    }
}
 
Example 4
Source File: SuggestionSpan.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Notifies a suggestion selection.
 *
 * @hide
 */
public void notifySelection(Context context, String original, int index) {
    final Intent intent = new Intent();

    if (context == null || mNotificationTargetClassName == null) {
        return;
    }
    // Ensures that only a class in the original IME package will receive the
    // notification.
    if (mSuggestions == null || index < 0 || index >= mSuggestions.length) {
        Log.w(TAG, "Unable to notify the suggestion as the index is out of range index=" + index
                + " length=" + mSuggestions.length);
        return;
    }

    // The package name is not mandatory (legacy from JB), and if the package name
    // is missing, we try to notify the suggestion through the input method manager.
    if (mNotificationTargetPackageName != null) {
        intent.setClassName(mNotificationTargetPackageName, mNotificationTargetClassName);
        intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED);
        intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, original);
        intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, mSuggestions[index]);
        intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, hashCode());
        context.sendBroadcast(intent);
    } else {
        InputMethodManager imm = InputMethodManager.peekInstance();
        if (imm != null) {
            imm.notifySuggestionPicked(this, original, index);
        }
    }
}
 
Example 5
Source File: NumberPicker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the soft input for its input text.
 */
private void showSoftInput() {
    InputMethodManager inputMethodManager = InputMethodManager.peekInstance();
    if (inputMethodManager != null) {
        if (mHasSelectorWheel) {
            mInputText.setVisibility(View.VISIBLE);
        }
        mInputText.requestFocus();
        inputMethodManager.showSoftInput(mInputText, 0);
    }
}
 
Example 6
Source File: NumberPicker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Hides the soft input if it is active for the input text.
 */
private void hideSoftInput() {
    InputMethodManager inputMethodManager = InputMethodManager.peekInstance();
    if (inputMethodManager != null && inputMethodManager.isActive(mInputText)) {
        inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
    }
    if (mHasSelectorWheel) {
        mInputText.setVisibility(View.INVISIBLE);
    }
}
 
Example 7
Source File: AutoCompleteTextView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Closes the drop down if present on screen.</p>
 */
public void dismissDropDown() {
    InputMethodManager imm = InputMethodManager.peekInstance();
    if (imm != null) {
        imm.displayCompletions(this, null);
    }
    mPopup.dismiss();
    mPopupCanBeUpdated = false;
}
 
Example 8
Source File: AutoCompleteTextView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}