本文整理汇总了Java中android.view.textservice.TextInfo类的典型用法代码示例。如果您正苦于以下问题:Java TextInfo类的具体用法?Java TextInfo怎么用?Java TextInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextInfo类属于android.view.textservice包,在下文中一共展示了TextInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSplitWords
import android.view.textservice.TextInfo; //导入依赖的package包/类
public SentenceTextInfoParams getSplitWords(TextInfo originalTextInfo) {
final WordIterator wordIterator = mWordIterator;
final CharSequence originalText =
TextInfoCompatUtils.getCharSequenceOrString(originalTextInfo);
final int cookie = originalTextInfo.getCookie();
final int start = -1;
final int end = originalText.length();
final ArrayList<SentenceWordItem> wordItems = new ArrayList<>();
int wordStart = wordIterator.getBeginningOfNextWord(originalText, start);
int wordEnd = wordIterator.getEndOfWord(originalText, wordStart);
while (wordStart <= end && wordEnd != -1 && wordStart != -1) {
if (wordEnd >= start && wordEnd > wordStart) {
final TextInfo ti = TextInfoCompatUtils.newInstance(originalText, wordStart,
wordEnd, cookie, originalText.subSequence(wordStart, wordEnd).hashCode());
wordItems.add(new SentenceWordItem(ti, wordStart, wordEnd));
}
wordStart = wordIterator.getBeginningOfNextWord(originalText, wordEnd);
if (wordStart == -1) {
break;
}
wordEnd = wordIterator.getEndOfWord(originalText, wordStart);
}
return new SentenceTextInfoParams(originalTextInfo, wordItems);
}
示例2: onGetSentenceSuggestionsMultiple
import android.view.textservice.TextInfo; //导入依赖的package包/类
@Override
public SentenceSuggestionsInfo[] onGetSentenceSuggestionsMultiple(TextInfo[] textInfos,
int suggestionsLimit) {
final SentenceSuggestionsInfo[] retval = splitAndSuggest(textInfos, suggestionsLimit);
if (retval == null || retval.length != textInfos.length) {
return retval;
}
for (int i = 0; i < retval.length; ++i) {
final SentenceSuggestionsInfo tempSsi =
fixWronglyInvalidatedWordWithSingleQuote(textInfos[i], retval[i]);
if (tempSsi != null) {
retval[i] = tempSsi;
}
}
return retval;
}
示例3: onGetSentenceSuggestionsMultiple
import android.view.textservice.TextInfo; //导入依赖的package包/类
@Override
public SentenceSuggestionsInfo[] onGetSentenceSuggestionsMultiple(TextInfo[] textInfos,
int suggestionsLimit) {
final SentenceSuggestionsInfo[] retval =
super.onGetSentenceSuggestionsMultiple(textInfos, suggestionsLimit);
if (retval == null || retval.length != textInfos.length) {
return retval;
}
for (int i = 0; i < retval.length; ++i) {
final SentenceSuggestionsInfo tempSsi =
fixWronglyInvalidatedWordWithSingleQuote(textInfos[i], retval[i]);
if (tempSsi != null) {
retval[i] = tempSsi;
}
}
return retval;
}
示例4: onGetSuggestionsMultiple
import android.view.textservice.TextInfo; //导入依赖的package包/类
@Override
public SuggestionsInfo[] onGetSuggestionsMultiple(TextInfo[] textInfos,
int suggestionsLimit, boolean sequentialWords) {
long ident = Binder.clearCallingIdentity();
try {
final int length = textInfos.length;
final SuggestionsInfo[] retval = new SuggestionsInfo[length];
for (int i = 0; i < length; ++i) {
final String prevWord;
if (sequentialWords && i > 0) {
final String prevWordCandidate = textInfos[i - 1].getText();
// Note that an empty string would be used to indicate the initial word
// in the future.
prevWord = TextUtils.isEmpty(prevWordCandidate) ? null : prevWordCandidate;
} else {
prevWord = null;
}
retval[i] = onGetSuggestionsInternal(textInfos[i], prevWord, suggestionsLimit);
retval[i].setCookieAndSequence(textInfos[i].getCookie(),
textInfos[i].getSequence());
}
return retval;
} finally {
Binder.restoreCallingIdentity(ident);
}
}
示例5: updateCandidates
import android.view.textservice.TextInfo; //导入依赖的package包/类
/**
* Update the list of available candidates from the current composing
* text. This will need to be filled in by however you are determining
* candidates.
*/
private void updateCandidates() {
if (!mCompletionOn) {
if (mComposing.length() > 0) {
ArrayList<String> list = new ArrayList<String>();
list.add(mComposing.toString());
mScs.getSentenceSuggestions(new TextInfo[] {new TextInfo(mComposing.toString())}, 5);
setSuggestions(list, true, true);
} else {
setSuggestions(null, false, false);
}
}
}
示例6: onResume
import android.view.textservice.TextInfo; //导入依赖的package包/类
@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.");
}
}
示例7: onGetSuggestions
import android.view.textservice.TextInfo; //导入依赖的package包/类
@Override
public SuggestionsInfo onGetSuggestions(final TextInfo textInfo, final int suggestionsLimit) {
long ident = Binder.clearCallingIdentity();
try {
return onGetSuggestionsInternal(textInfo, suggestionsLimit);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:10,代码来源:AndroidWordLevelSpellCheckerSession.java
示例8: splitAndSuggest
import android.view.textservice.TextInfo; //导入依赖的package包/类
/**
* Get sentence suggestions for specified texts in an array of TextInfo. This is taken from
* SpellCheckerService#onGetSentenceSuggestionsMultiple that we can't use because it's
* using private variables.
* The default implementation splits the input text to words and returns
* {@link SentenceSuggestionsInfo} which contains suggestions for each word.
* This function will run on the incoming IPC thread.
* So, this is not called on the main thread,
* but will be called in series on another thread.
* @param textInfos an array of the text metadata
* @param suggestionsLimit the maximum number of suggestions to be returned
* @return an array of {@link SentenceSuggestionsInfo} returned by
* {@link android.service.textservice.SpellCheckerService.Session#onGetSuggestions(TextInfo, int)}
*/
private SentenceSuggestionsInfo[] splitAndSuggest(TextInfo[] textInfos, int suggestionsLimit) {
if (textInfos == null || textInfos.length == 0) {
return SentenceLevelAdapter.getEmptySentenceSuggestionsInfo();
}
SentenceLevelAdapter sentenceLevelAdapter;
synchronized(this) {
sentenceLevelAdapter = mSentenceLevelAdapter;
if (sentenceLevelAdapter == null) {
final String localeStr = getLocale();
if (!TextUtils.isEmpty(localeStr)) {
sentenceLevelAdapter = new SentenceLevelAdapter(mResources,
new Locale(localeStr));
mSentenceLevelAdapter = sentenceLevelAdapter;
}
}
}
if (sentenceLevelAdapter == null) {
return SentenceLevelAdapter.getEmptySentenceSuggestionsInfo();
}
final int infosSize = textInfos.length;
final SentenceSuggestionsInfo[] retval = new SentenceSuggestionsInfo[infosSize];
for (int i = 0; i < infosSize; ++i) {
final SentenceLevelAdapter.SentenceTextInfoParams textInfoParams =
sentenceLevelAdapter.getSplitWords(textInfos[i]);
final ArrayList<SentenceLevelAdapter.SentenceWordItem> mItems =
textInfoParams.mItems;
final int itemsSize = mItems.size();
final TextInfo[] splitTextInfos = new TextInfo[itemsSize];
for (int j = 0; j < itemsSize; ++j) {
splitTextInfos[j] = mItems.get(j).mTextInfo;
}
retval[i] = SentenceLevelAdapter.reconstructSuggestions(
textInfoParams, onGetSuggestionsMultiple(
splitTextInfos, suggestionsLimit, true));
}
return retval;
}
示例9: onGetSuggestionsMultiple
import android.view.textservice.TextInfo; //导入依赖的package包/类
@Override
public SuggestionsInfo[] onGetSuggestionsMultiple(TextInfo[] textInfos,
int suggestionsLimit, boolean sequentialWords) {
long ident = Binder.clearCallingIdentity();
try {
final int length = textInfos.length;
final SuggestionsInfo[] retval = new SuggestionsInfo[length];
for (int i = 0; i < length; ++i) {
final CharSequence prevWord;
if (sequentialWords && i > 0) {
final TextInfo prevTextInfo = textInfos[i - 1];
final CharSequence prevWordCandidate =
TextInfoCompatUtils.getCharSequenceOrString(prevTextInfo);
// Note that an empty string would be used to indicate the initial word
// in the future.
prevWord = TextUtils.isEmpty(prevWordCandidate) ? null : prevWordCandidate;
} else {
prevWord = null;
}
final NgramContext ngramContext =
new NgramContext(new NgramContext.WordInfo(prevWord));
final TextInfo textInfo = textInfos[i];
retval[i] = onGetSuggestionsInternal(textInfo, ngramContext, suggestionsLimit);
retval[i].setCookieAndSequence(textInfo.getCookie(), textInfo.getSequence());
}
return retval;
} finally {
Binder.restoreCallingIdentity(ident);
}
}
示例10: newInstance
import android.view.textservice.TextInfo; //导入依赖的package包/类
@UsedForTesting
public static TextInfo newInstance(CharSequence charSequence, int start, int end, int cookie,
int sequenceNumber) {
if (TEXT_INFO_CONSTRUCTOR_FOR_CHAR_SEQUENCE != null) {
return (TextInfo) CompatUtils.newInstance(TEXT_INFO_CONSTRUCTOR_FOR_CHAR_SEQUENCE,
charSequence, start, end, cookie, sequenceNumber);
}
return new TextInfo(charSequence.subSequence(start, end).toString(), cookie,
sequenceNumber);
}
示例11: requestTextCheck
import android.view.textservice.TextInfo; //导入依赖的package包/类
/**
* Queries the input text against the SpellCheckerSession.
* @param text Text to be queried.
*/
@CalledByNative
private void requestTextCheck(String text) {
// SpellCheckerSession thinks that any word ending with a period is a typo.
// We trim the period off before sending the text for spellchecking in order to avoid
// unnecessary red underlines when the user ends a sentence with a period.
// Filed as an Android bug here: https://code.google.com/p/android/issues/detail?id=183294
if (text.endsWith(".")) {
text = text.substring(0, text.length() - 1);
}
mSpellCheckerSession.getSentenceSuggestions(new TextInfo[] {new TextInfo(text)}, 0);
}
示例12: requestTextCheck
import android.view.textservice.TextInfo; //导入依赖的package包/类
/**
* Queries the input text against the SpellCheckerSession.
* @param text Text to be queried.
*/
@CalledByNative
private void requestTextCheck(String text) {
// SpellCheckerSession thinks that any word ending with a period is a typo.
// We trim the period off before sending the text for spellchecking in order to avoid
// unnecessary red underlines when the user ends a sentence with a period.
// Filed as an Android bug here: https://code.google.com/p/android/issues/detail?id=183294
if (text.endsWith(".")) {
text = text.substring(0, text.length() - 1);
}
mStartMs = SystemClock.elapsedRealtime();
mSpellCheckerSession.getSentenceSuggestions(new TextInfo[] {new TextInfo(text)}, 0);
}
示例13: onCreate
import android.view.textservice.TextInfo; //导入依赖的package包/类
@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);
}
}
});
}
示例14: onGetSuggestions
import android.view.textservice.TextInfo; //导入依赖的package包/类
@Override
public SuggestionsInfo onGetSuggestions(final TextInfo textInfo,
final int suggestionsLimit) {
long ident = Binder.clearCallingIdentity();
try {
return onGetSuggestionsInternal(textInfo, suggestionsLimit);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
示例15: SentenceWordItem
import android.view.textservice.TextInfo; //导入依赖的package包/类
public SentenceWordItem(TextInfo ti, int start, int end) {
mTextInfo = ti;
mStart = start;
mLength = end - start;
}