下面列出了android.view.inputmethod.InputMethodManager#peekInstance ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
}
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);
}
}
}
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);
}
}
}
/**
* 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);
}
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* <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;
}
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);
}
}
}