本文整理汇总了Java中android.provider.UserDictionary.Words类的典型用法代码示例。如果您正苦于以下问题:Java Words类的具体用法?Java Words怎么用?Java Words使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Words类属于android.provider.UserDictionary包,在下文中一共展示了Words类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: UserDictionary
import android.provider.UserDictionary.Words; //导入依赖的package包/类
public UserDictionary(Context context, String locale) {
super(context, Suggest.DIC_USER);
mLocale = locale;
// Perform a managed query. The Activity will handle closing and requerying the cursor
// when needed.
ContentResolver cres = context.getContentResolver();
cres.registerContentObserver(Words.CONTENT_URI, true, mObserver = new ContentObserver(null) {
@Override
public void onChange(boolean self) {
setRequiresReload(true);
}
});
loadDictionary();
}
开发者ID:PhilippC,项目名称:keepass2android,代码行数:17,代码来源:UserDictionary.java
示例2: addWordsLocked
import android.provider.UserDictionary.Words; //导入依赖的package包/类
private void addWordsLocked(final Cursor cursor) {
if (cursor == null) return;
if (cursor.moveToFirst()) {
final int indexWord = cursor.getColumnIndex(Words.WORD);
final int indexFrequency = cursor.getColumnIndex(Words.FREQUENCY);
while (!cursor.isAfterLast()) {
final String word = cursor.getString(indexWord);
final int frequency = cursor.getInt(indexFrequency);
final int adjustedFrequency = scaleFrequencyFromDefaultToLatinIme(frequency);
// Safeguard against adding really long words.
if (word.length() <= MAX_WORD_LENGTH) {
runGCIfRequiredLocked(true /* mindsBlockByGC */);
addUnigramLocked(word, adjustedFrequency, false /* isNotAWord */,
false /* isPossiblyOffensive */,
BinaryDictionary.NOT_A_VALID_TIMESTAMP);
}
cursor.moveToNext();
}
}
}
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:21,代码来源:UserBinaryDictionary.java
示例3: onCreate
import android.provider.UserDictionary.Words; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView dictListView = (ListView) findViewById(R.id.dictionary_list_view);
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query(UserDictionary.Words.CONTENT_URI, null, null, null, null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.listview_layout, cursor, COLUMNS_TO_BE_FOUND, LAYOUT_ITEMS_TO_FILL, 0);
dictListView.setAdapter(adapter);
registerForContextMenu(dictListView);
}
开发者ID:SuperHaker,项目名称:Fictionary,代码行数:12,代码来源:MainActivity.java
示例4: addWords
import android.provider.UserDictionary.Words; //导入依赖的package包/类
private void addWords(final Cursor cursor) {
final boolean hasShortcutColumn = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
clearFusionDictionary();
if (cursor == null) return;
if (cursor.moveToFirst()) {
final int indexWord = cursor.getColumnIndex(Words.WORD);
final int indexShortcut = hasShortcutColumn ? cursor.getColumnIndex(SHORTCUT) : 0;
final int indexFrequency = cursor.getColumnIndex(Words.FREQUENCY);
while (!cursor.isAfterLast()) {
final String word = cursor.getString(indexWord);
final String shortcut = hasShortcutColumn ? cursor.getString(indexShortcut) : null;
final int frequency = cursor.getInt(indexFrequency);
final int adjustedFrequency = scaleFrequencyFromDefaultToLatinIme(frequency);
// Safeguard against adding really long words.
if (word.length() < MAX_WORD_LENGTH) {
super.addWord(word, null, adjustedFrequency, false /* isNotAWord */);
}
if (null != shortcut && shortcut.length() < MAX_WORD_LENGTH) {
super.addWord(shortcut, word, adjustedFrequency, true /* isNotAWord */);
}
cursor.moveToNext();
}
}
}
开发者ID:slightfoot,项目名称:android-kioskime,代码行数:25,代码来源:UserBinaryDictionary.java
示例5: addWord
import android.provider.UserDictionary.Words; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static void addWord(final Context context, final String word, final int freq,
final String shortcut, final Locale locale) {
if (hasNewerAddWord()) {
CompatUtils.invoke(Words.class, null, METHOD_addWord, context, word, freq, shortcut,
locale);
} else {
// Fall back to the pre-JellyBean method.
final int localeType;
if (null == locale) {
localeType = Words.LOCALE_TYPE_ALL;
} else {
final Locale currentLocale = context.getResources().getConfiguration().locale;
if (locale.equals(currentLocale)) {
localeType = Words.LOCALE_TYPE_CURRENT;
} else {
localeType = Words.LOCALE_TYPE_ALL;
}
}
Words.addWord(context, word, freq, localeType);
}
}
开发者ID:slightfoot,项目名称:android-kioskime,代码行数:23,代码来源:UserDictionaryCompatUtils.java
示例6: addWord
import android.provider.UserDictionary.Words; //导入依赖的package包/类
/**
* Adds a word to the dictionary and makes it persistent.
* @param word the word to add. If the word is capitalized, then the dictionary will
* recognize it as a capitalized word when searched.
* @param frequency the frequency of occurrence of the word. A frequency of 255 is considered
* the highest.
* @TODO use a higher or float range for frequency
*/
@Override
public synchronized void addWord(String word, int frequency) {
// Force load the dictionary here synchronously
if (getRequiresReload()) loadDictionaryAsync();
// Safeguard against adding long words. Can cause stack overflow.
if (word.length() >= getMaxWordLength()) return;
super.addWord(word, frequency);
// Update the user dictionary provider
final ContentValues values = new ContentValues(5);
values.put(Words.WORD, word);
values.put(Words.FREQUENCY, frequency);
values.put(Words.LOCALE, mLocale);
values.put(Words.APP_ID, 0);
final ContentResolver contentResolver = getContext().getContentResolver();
new Thread("addWord") {
public void run() {
contentResolver.insert(Words.CONTENT_URI, values);
}
}.start();
// In case the above does a synchronous callback of the change observer
setRequiresReload(false);
}
开发者ID:PhilippC,项目名称:keepass2android,代码行数:35,代码来源:UserDictionary.java
示例7: AndroidWordLevelSpellCheckerSession
import android.provider.UserDictionary.Words; //导入依赖的package包/类
AndroidWordLevelSpellCheckerSession(final AndroidSpellCheckerService service) {
mService = service;
final ContentResolver cres = service.getContentResolver();
mObserver = new ContentObserver(null) {
@Override
public void onChange(boolean self) {
mSuggestionsCache.clearCache();
}
};
cres.registerContentObserver(Words.CONTENT_URI, true, mObserver);
}
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:13,代码来源:AndroidWordLevelSpellCheckerSession.java
示例8: loadDictionaryAsync
import android.provider.UserDictionary.Words; //导入依赖的package包/类
@Override
public void loadDictionaryAsync() {
Cursor cursor = getContext().getContentResolver()
.query(Words.CONTENT_URI, PROJECTION, "(locale IS NULL) or (locale=?)",
new String[] { mLocale }, null);
addWords(cursor);
}
开发者ID:klausw,项目名称:hackerskeyboard,代码行数:8,代码来源:UserDictionary.java
示例9: getChangedWordForUri
import android.provider.UserDictionary.Words; //导入依赖的package包/类
private String getChangedWordForUri(final Uri uri) {
final Cursor cursor = mContext.getContentResolver().query(uri,
PROJECTION_QUERY, null, null, null);
if (cursor == null) return null;
try {
if (!cursor.moveToFirst()) return null;
final int indexWord = cursor.getColumnIndex(Words.WORD);
return cursor.getString(indexWord);
} finally {
cursor.close();
}
}
开发者ID:slightfoot,项目名称:android-kioskime,代码行数:13,代码来源:UserBinaryDictionary.java
示例10: isEnabled
import android.provider.UserDictionary.Words; //导入依赖的package包/类
public boolean isEnabled() {
final ContentResolver cr = mContext.getContentResolver();
final ContentProviderClient client = cr.acquireContentProviderClient(Words.CONTENT_URI);
if (client != null) {
client.release();
return true;
} else {
return false;
}
}
开发者ID:slightfoot,项目名称:android-kioskime,代码行数:11,代码来源:UserBinaryDictionary.java
示例11: UserBinaryDictionary
import android.provider.UserDictionary.Words; //导入依赖的package包/类
public UserBinaryDictionary(final Context context, final String locale,
final boolean alsoUseMoreRestrictiveLocales) {
super(context, getFilenameWithLocale(NAME, locale), Dictionary.TYPE_USER);
if (null == locale) throw new NullPointerException(); // Catch the error earlier
if (SubtypeLocale.NO_LANGUAGE.equals(locale)) {
// If we don't have a locale, insert into the "all locales" user dictionary.
mLocale = USER_DICTIONARY_ALL_LANGUAGES;
} else {
mLocale = locale;
}
mAlsoUseMoreRestrictiveLocales = alsoUseMoreRestrictiveLocales;
// Perform a managed query. The Activity will handle closing and re-querying the cursor
// when needed.
ContentResolver cres = context.getContentResolver();
mObserver = new ContentObserver(null) {
@Override
public void onChange(final boolean self) {
// This hook is deprecated as of API level 16 (Build.VERSION_CODES.JELLY_BEAN),
// but should still be supported for cases where the IME is running on an older
// version of the platform.
onChange(self, null);
}
// The following hook is only available as of API level 16
// (Build.VERSION_CODES.JELLY_BEAN), and as such it will only work on JellyBean+
// devices. On older versions of the platform, the hook above will be called instead.
@Override
public void onChange(final boolean self, final Uri uri) {
setRequiresReload(true);
// We want to report back to Latin IME in case the user just entered the word.
// If the user changed the word in the dialog box, then we want to replace
// what was entered in the text field.
if (null == uri || !(context instanceof LatinIME)) return;
final long changedRowId = ContentUris.parseId(uri);
if (-1 == changedRowId) return; // Unknown content... Not sure why we're here
final String changedWord = getChangedWordForUri(uri);
((LatinIME)context).onWordAddedToUserDictionary(changedWord);
}
};
cres.registerContentObserver(Words.CONTENT_URI, true, mObserver);
loadDictionary();
}
开发者ID:slightfoot,项目名称:android-kioskime,代码行数:44,代码来源:UserBinaryDictionary.java
示例12: loadDictionaryAsync
import android.provider.UserDictionary.Words; //导入依赖的package包/类
@Override
public void loadDictionaryAsync() {
// Split the locale. For example "en" => ["en"], "de_DE" => ["de", "DE"],
// "en_US_foo_bar_qux" => ["en", "US", "foo_bar_qux"] because of the limit of 3.
// This is correct for locale processing.
// For this example, we'll look at the "en_US_POSIX" case.
final String[] localeElements =
TextUtils.isEmpty(mLocale) ? new String[] {} : mLocale.split("_", 3);
final int length = localeElements.length;
final StringBuilder request = new StringBuilder("(locale is NULL)");
String localeSoFar = "";
// At start, localeElements = ["en", "US", "POSIX"] ; localeSoFar = "" ;
// and request = "(locale is NULL)"
for (int i = 0; i < length; ++i) {
// i | localeSoFar | localeElements
// 0 | "" | ["en", "US", "POSIX"]
// 1 | "en_" | ["en", "US", "POSIX"]
// 2 | "en_US_" | ["en", "en_US", "POSIX"]
localeElements[i] = localeSoFar + localeElements[i];
localeSoFar = localeElements[i] + "_";
// i | request
// 0 | "(locale is NULL)"
// 1 | "(locale is NULL) or (locale=?)"
// 2 | "(locale is NULL) or (locale=?) or (locale=?)"
request.append(" or (locale=?)");
}
// At the end, localeElements = ["en", "en_US", "en_US_POSIX"]; localeSoFar = en_US_POSIX_"
// and request = "(locale is NULL) or (locale=?) or (locale=?) or (locale=?)"
final String[] requestArguments;
// If length == 3, we already have all the arguments we need (common prefix is meaningless
// inside variants
if (mAlsoUseMoreRestrictiveLocales && length < 3) {
request.append(" or (locale like ?)");
// The following creates an array with one more (null) position
final String[] localeElementsWithMoreRestrictiveLocalesIncluded =
Arrays.copyOf(localeElements, length + 1);
localeElementsWithMoreRestrictiveLocalesIncluded[length] =
localeElements[length - 1] + "_%";
requestArguments = localeElementsWithMoreRestrictiveLocalesIncluded;
// If for example localeElements = ["en"]
// then requestArguments = ["en", "en_%"]
// and request = (locale is NULL) or (locale=?) or (locale like ?)
// If localeElements = ["en", "en_US"]
// then requestArguments = ["en", "en_US", "en_US_%"]
} else {
requestArguments = localeElements;
}
final Cursor cursor = mContext.getContentResolver().query(
Words.CONTENT_URI, PROJECTION_QUERY, request.toString(), requestArguments, null);
try {
addWords(cursor);
} finally {
if (null != cursor) cursor.close();
}
}
开发者ID:slightfoot,项目名称:android-kioskime,代码行数:58,代码来源:UserBinaryDictionary.java
注:本文中的android.provider.UserDictionary.Words类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论