use of android.view.inputmethod.InputMethodManager in project android_frameworks_base by ParanoidAndroid.
the class TextServicesManagerService method getCurrentSpellCheckerSubtype.
// TODO: Respect allowImplicitlySelectedSubtype
// TODO: Save SpellCheckerSubtype by supported languages by looking at "locale".
@Override
public SpellCheckerSubtype getCurrentSpellCheckerSubtype(String locale, boolean allowImplicitlySelectedSubtype) {
// TODO: Make this work even for non-current users?
if (!calledFromValidUser()) {
return null;
}
synchronized (mSpellCheckerMap) {
final String subtypeHashCodeStr = mSettings.getSelectedSpellCheckerSubtype();
if (DBG) {
Slog.w(TAG, "getCurrentSpellCheckerSubtype: " + subtypeHashCodeStr);
}
final SpellCheckerInfo sci = getCurrentSpellChecker(null);
if (sci == null || sci.getSubtypeCount() == 0) {
if (DBG) {
Slog.w(TAG, "Subtype not found.");
}
return null;
}
final int hashCode;
if (!TextUtils.isEmpty(subtypeHashCodeStr)) {
hashCode = Integer.valueOf(subtypeHashCodeStr);
} else {
hashCode = 0;
}
if (hashCode == 0 && !allowImplicitlySelectedSubtype) {
return null;
}
String candidateLocale = null;
if (hashCode == 0) {
// Spell checker language settings == "auto"
final InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
final InputMethodSubtype currentInputMethodSubtype = imm.getCurrentInputMethodSubtype();
if (currentInputMethodSubtype != null) {
final String localeString = currentInputMethodSubtype.getLocale();
if (!TextUtils.isEmpty(localeString)) {
// 1. Use keyboard locale if available in the spell checker
candidateLocale = localeString;
}
}
}
if (candidateLocale == null) {
// 2. Use System locale if available in the spell checker
candidateLocale = mContext.getResources().getConfiguration().locale.toString();
}
}
SpellCheckerSubtype candidate = null;
for (int i = 0; i < sci.getSubtypeCount(); ++i) {
final SpellCheckerSubtype scs = sci.getSubtypeAt(i);
if (hashCode == 0) {
final String scsLocale = scs.getLocale();
if (candidateLocale.equals(scsLocale)) {
return scs;
} else if (candidate == null) {
if (candidateLocale.length() >= 2 && scsLocale.length() >= 2 && candidateLocale.startsWith(scsLocale)) {
// Fall back to the applicable language
candidate = scs;
}
}
} else if (scs.hashCode() == hashCode) {
if (DBG) {
Slog.w(TAG, "Return subtype " + scs.hashCode() + ", input= " + locale + ", " + scs.getLocale());
}
// 3. Use the user specified spell check language
return scs;
}
}
// spell check languages
return candidate;
}
}
use of android.view.inputmethod.InputMethodManager in project android_frameworks_base by ParanoidAndroid.
the class ButtonActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ButtonActivity instance = this;
final Button myButton = new Button(this);
myButton.setClickable(true);
myButton.setText("Keyboard UP!");
myButton.setId(BUTTON_ID);
myButton.setFocusableInTouchMode(true);
myButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
InputMethodManager imm = InputMethodManager.getInstance();
if (mKeyboardIsActive) {
imm.hideSoftInputFromInputMethod(v.getWindowToken(), 0);
myButton.setText("Keyboard UP!");
} else {
myButton.requestFocusFromTouch();
imm.showSoftInput(v, 0);
myButton.setText("Keyboard DOWN!");
}
mKeyboardIsActive = !mKeyboardIsActive;
}
});
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(myButton);
setContentView(layout);
mRootView = layout;
}
use of android.view.inputmethod.InputMethodManager in project HoloEverywhere by Prototik.
the class SearchView method setImeVisibility.
private void setImeVisibility(final boolean visible) {
if (visible) {
post(mShowImeRunnable);
} else {
removeCallbacks(mShowImeRunnable);
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(getWindowToken(), 0);
}
}
}
use of android.view.inputmethod.InputMethodManager in project HoloEverywhere by Prototik.
the class AutoCompleteTextView method dismissDropDown.
public void dismissDropDown() {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.displayCompletions(this, null);
}
mPopup.dismiss();
mPopupCanBeUpdated = false;
}
use of android.view.inputmethod.InputMethodManager in project HoloEverywhere by Prototik.
the class AutoCompleteTextView method buildImeCompletions.
private void buildImeCompletions() {
final ListAdapter adapter = mAdapter;
if (adapter != null) {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
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);
}
}
}
Aggregations