下面列出了怎么用android.view.textservice.TextServicesManager的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Constructs a SpellCheckerSessionBridge object as well as its SpellCheckerSession object.
* @param nativeSpellCheckerSessionBridge Pointer to the native SpellCheckerSessionBridge.
*/
private SpellCheckerSessionBridge(long nativeSpellCheckerSessionBridge) {
mNativeSpellCheckerSessionBridge = nativeSpellCheckerSessionBridge;
Context context = ContextUtils.getApplicationContext();
final TextServicesManager textServicesManager =
(TextServicesManager) context.getSystemService(
Context.TEXT_SERVICES_MANAGER_SERVICE);
// This combination of parameters will cause the spellchecker to be based off of
// the language specified at "Settings > Language & input > Spell checker > Language".
// If that setting is set to "Use system language" and the system language is not on the
// list of supported spellcheck languages, this call will return null. This call will also
// return null if the user has turned spellchecking off at "Settings > Language & input >
// Spell checker".
mSpellCheckerSession = textServicesManager.newSpellCheckerSession(null, null, this, true);
}
/**
* Constructs a SpellCheckerSessionBridge object as well as its SpellCheckerSession object.
* @param nativeSpellCheckerSessionBridge Pointer to the native SpellCheckerSessionBridge.
*/
private SpellCheckerSessionBridge(long nativeSpellCheckerSessionBridge) {
mNativeSpellCheckerSessionBridge = nativeSpellCheckerSessionBridge;
Context context = ContextUtils.getApplicationContext();
final TextServicesManager textServicesManager =
(TextServicesManager) context.getSystemService(
Context.TEXT_SERVICES_MANAGER_SERVICE);
// This combination of parameters will cause the spellchecker to be based off of
// the language specified at "Settings > Language & input > Spell checker > Language".
// If that setting is set to "Use system language" and the system language is not on the
// list of supported spellcheck languages, this call will return null. This call will also
// return null if the user has turned spellchecking off at "Settings > Language & input >
// Spell checker".
mSpellCheckerSession = textServicesManager.newSpellCheckerSession(null, null, this, true);
}
private void resetSession() {
closeSession();
mTextServicesManager = (TextServicesManager) mTextView.getContext().
getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
if (!mTextServicesManager.isSpellCheckerEnabled()
|| mCurrentLocale == null
|| mTextServicesManager.getCurrentSpellCheckerSubtype(true) == null) {
mSpellCheckerSession = null;
} else {
mSpellCheckerSession = mTextServicesManager.newSpellCheckerSession(
null /* Bundle not currently used by the textServicesManager */,
mCurrentLocale, this,
false /* means any available languages from current spell checker */);
mIsSentenceSpellCheckSupported = true;
}
// Restore SpellCheckSpans in pool
for (int i = 0; i < mLength; i++) {
mIds[i] = -1;
}
mLength = 0;
// Remove existing misspelled SuggestionSpans
mTextView.removeMisspelledSpans((Editable) mTextView.getText());
mSuggestionSpanCache.evictAll();
}
public Object createService(ContextImpl ctx) {
return TextServicesManager.getInstance();
}
public Object createService(ContextImpl ctx) {
return TextServicesManager.getInstance();
}
public Object createService(ContextImpl ctx) {
return TextServicesManager.getInstance();
}
public Object createService(ContextImpl ctx) {
return TextServicesManager.getInstance();
}
public Object createService(ContextImpl ctx) {
return TextServicesManager.getInstance();
}
public Object createService(ContextImpl ctx) {
return TextServicesManager.getInstance();
}
public Object createService(ContextImpl ctx) {
return TextServicesManager.getInstance();
}
@Override
public TextServicesManager createService() {
return TextServicesManager.getInstance();
}
@TargetApi(14)
public static TextServicesManager getTextServicesManager() {
return (TextServicesManager) getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
}