/** * 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 = ApplicationStatus.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); }
/** * Main initialization of the input method component. Be sure to call * to super class. */ @Override public void onCreate() { super.onCreate(); mInputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); mWordSeparators = getResources().getString(R.string.word_separators); final TextServicesManager tsm = (TextServicesManager) getSystemService( Context.TEXT_SERVICES_MANAGER_SERVICE); mScs = tsm.newSpellCheckerSession(null, null, this, true); }
@Override public void onResume() { super.onResume(); final TextServicesManager tsm = (TextServicesManager) getSystemService( Context.TEXT_SERVICES_MANAGER_SERVICE); mScs = tsm.newSpellCheckerSession(null, null, this, true); if (mScs != null) { // Instantiate TextInfo for each query // TextInfo can be passed a sequence number and a cookie number to identify the result if (isSentenceSpellCheckSupported()) { // Note that getSentenceSuggestions works on JB or later. Log.d(TAG, "Sentence spellchecking supported."); mScs.getSentenceSuggestions(new TextInfo[] {new TextInfo("tgisis")}, 3); mScs.getSentenceSuggestions(new TextInfo[] {new TextInfo( "I wold like to here form you")}, 3); mScs.getSentenceSuggestions(new TextInfo[] {new TextInfo("hell othere")}, 3); } else { // Note that getSuggestions() is a deprecated API. // It is recommended for an application running on Jelly Bean or later // to call getSentenceSuggestions() only. mScs.getSuggestions(new TextInfo("tgis"), 3); mScs.getSuggestions(new TextInfo("hllo"), 3); mScs.getSuggestions(new TextInfo("helloworld"), 3); } } else { Log.e(TAG, "Couldn't obtain the spell checker service."); } }
private void updateTextServicesLocaleLocked() { final TextServicesManager textServicesManager = (TextServicesManager) mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE); final SpellCheckerSubtype subtype = textServicesManager.getCurrentSpellCheckerSubtype(true); final Locale locale; if (subtype != null) { locale = SpellCheckerSubtype.constructLocaleFromString(subtype.getLocale()); } else { locale = null; } mCurrentSpellCheckerLocaleCache = locale; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.spellchecker); check = (Button) findViewById(R.id.checkerbuttoncheck); checktext = (EditText) findViewById(R.id.checkeredittext); suggestbox = (TextView) findViewById(R.id.checkersuggestview); rightbox = (TextView) findViewById(R.id.righttext); preferences = this.getSharedPreferences("team7663.project.camword",Context.MODE_PRIVATE); preferences.edit().putBoolean("team7663.project.camword.OCR.mainoff",true).apply(); checktext.setText(preferences.getString("team7663.project.camword.OCR.savespell","")); TextServicesManager tsm = (TextServicesManager) getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE); scs = tsm.newSpellCheckerSession(null,null, SpellChecker.this,true); MainActivity.spell.setBackgroundResource(R.drawable.spell); check.setOnClickListener(new View.OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v){ value = checktext.getText().toString(); rightbox.setText(""); if(value.isEmpty()==false) { scs.getSuggestions(new TextInfo(value), 5); } } }); }
/** * 返回 {@link TextServicesManager} */ public static TextServicesManager getTextServicesManager() { return (TextServicesManager) get(TEXT_SERVICES_MANAGER_SERVICE); }
@TargetApi(14) public static TextServicesManager getTextServicesManager() { return (TextServicesManager) getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE); }
public static TextServicesManager textServices(Context context) { return (TextServicesManager) context.getSystemService(TEXT_SERVICES_MANAGER_SERVICE); }
public static TextServicesManager textServicesManager() { return (TextServicesManager) get(Context.TEXT_SERVICES_MANAGER_SERVICE); }
/** * Obtain a {@link TextServicesManager} instance associated with specified {@link Context} * * @param context Context * @return {@link TextServicesManager} associated with specified {@link Context} * @throws InvalidContextException if {@link TextServicesManager} can't be obtained * from specified {@link Context} */ @NonNull public static TextServicesManager getTextServicesManager(@NonNull Context context) { return validate(context.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE)); }