mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-18 07:53:07 +00:00
address some more warnings
This commit is contained in:
parent
6c0f1361d9
commit
ac1cc0a690
9 changed files with 184 additions and 252 deletions
|
@ -51,7 +51,6 @@ import java.util.Locale;
|
|||
*/
|
||||
public final class BinaryDictionaryFileDumper {
|
||||
private static final String TAG = BinaryDictionaryFileDumper.class.getSimpleName();
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
/**
|
||||
* The size of the temporary buffer to copy files.
|
||||
|
@ -63,10 +62,8 @@ public final class BinaryDictionaryFileDumper {
|
|||
private static final byte[] MAGIC_NUMBER_VERSION_2 =
|
||||
new byte[] { (byte)0x9B, (byte)0xC1, (byte)0x3A, (byte)0xFE };
|
||||
|
||||
private static final boolean SHOULD_VERIFY_MAGIC_NUMBER =
|
||||
DecoderSpecificConstants.SHOULD_VERIFY_MAGIC_NUMBER;
|
||||
private static final boolean SHOULD_VERIFY_CHECKSUM =
|
||||
DecoderSpecificConstants.SHOULD_VERIFY_CHECKSUM;
|
||||
private static final boolean SHOULD_VERIFY_MAGIC_NUMBER = DecoderSpecificConstants.SHOULD_VERIFY_MAGIC_NUMBER;
|
||||
private static final boolean SHOULD_VERIFY_CHECKSUM = DecoderSpecificConstants.SHOULD_VERIFY_CHECKSUM;
|
||||
|
||||
private static final String[] DICTIONARY_PROJECTION = {"id"};
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ final public class BinaryDictionaryGetter {
|
|||
public static final String ASSETS_DICTIONARY_FOLDER = "dicts";
|
||||
|
||||
// The key considered to read the version attribute in a dictionary file.
|
||||
private static String VERSION_KEY = "version";
|
||||
private static final String VERSION_KEY = "version";
|
||||
|
||||
// Prevents this from being instantiated
|
||||
private BinaryDictionaryGetter() {}
|
||||
|
@ -225,15 +225,7 @@ final public class BinaryDictionaryGetter {
|
|||
// Version 18 is the first one to include the whitelist
|
||||
// Obviously this is a big ## HACK ##
|
||||
return Integer.parseInt(version) >= 18;
|
||||
} catch (java.io.FileNotFoundException e) {
|
||||
return false;
|
||||
} catch (java.io.IOException e) {
|
||||
return false;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
} catch (BufferUnderflowException e) {
|
||||
return false;
|
||||
} catch (UnsupportedFormatException e) {
|
||||
} catch (IOException | NumberFormatException | BufferUnderflowException | UnsupportedFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -276,8 +268,7 @@ final public class BinaryDictionaryGetter {
|
|||
final AssetFileAddress afa = AssetFileAddress.makeFromFileName(f.getPath());
|
||||
if (null != afa) fileList.add(afa);
|
||||
} else {
|
||||
Log.e(TAG, "Found a cached dictionary file for " + locale.toString()
|
||||
+ " but cannot read or use it");
|
||||
Log.e(TAG, "Found a cached dictionary file for " + locale + " but cannot read or use it");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
|
|||
* This class automatically creates and releases up to 3 facilitator instances using LRU policy.
|
||||
*/
|
||||
public class DictionaryFacilitatorLruCache {
|
||||
private static final String TAG = "DictionaryFacilitatorLruCache";
|
||||
private static final String TAG = "DictFacilitatorLruCache";
|
||||
private static final int WAIT_FOR_LOADING_MAIN_DICT_IN_MILLISECONDS = 1000;
|
||||
private static final int MAX_RETRY_COUNT_FOR_WAITING_FOR_LOADING_DICT = 5;
|
||||
|
||||
|
|
|
@ -34,10 +34,10 @@ import java.util.List;
|
|||
* A class for detecting Emoji-Alt physical key.
|
||||
*/
|
||||
final class EmojiAltPhysicalKeyDetector {
|
||||
private static final String TAG = "EmojiAltPhysicalKeyDetector";
|
||||
private static final String TAG = "EmojiAltPhysKeyDetector";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private List<EmojiHotKeys> mHotKeysList;
|
||||
private final List<EmojiHotKeys> mHotKeysList;
|
||||
|
||||
private static class HotKeySet extends HashSet<Pair<Integer, Integer>> { }
|
||||
|
||||
|
@ -120,7 +120,7 @@ final class EmojiAltPhysicalKeyDetector {
|
|||
}
|
||||
|
||||
public EmojiAltPhysicalKeyDetector(@NonNull final Resources resources) {
|
||||
mHotKeysList = new ArrayList<EmojiHotKeys>();
|
||||
mHotKeysList = new ArrayList<>();
|
||||
|
||||
final HotKeySet emojiSwitchSet = parseHotKeys(
|
||||
resources, R.array.keyboard_switcher_emoji);
|
||||
|
@ -192,8 +192,8 @@ final class EmojiAltPhysicalKeyDetector {
|
|||
Log.w(TAG, "Expected 2 integers in " + name + "[" + i + "] : " + values[i]);
|
||||
}
|
||||
try {
|
||||
final Integer keyCode = Integer.parseInt(valuePair[0]);
|
||||
final Integer metaState = Integer.parseInt(valuePair[1]);
|
||||
final int keyCode = Integer.parseInt(valuePair[0]);
|
||||
final int metaState = Integer.parseInt(valuePair[1]);
|
||||
final Pair<Integer, Integer> key = Pair.create(
|
||||
keyCode, KeyEvent.normalizeMetaState(metaState));
|
||||
keySet.add(key);
|
||||
|
|
|
@ -169,15 +169,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
}
|
||||
|
||||
private static void asyncExecuteTaskWithLock(final Lock lock, final Runnable task) {
|
||||
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lock.lock();
|
||||
try {
|
||||
task.run();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD).execute(() -> {
|
||||
lock.lock();
|
||||
try {
|
||||
task.run();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -199,12 +196,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
asyncExecuteTaskWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
closeBinaryDictionary();
|
||||
}
|
||||
});
|
||||
asyncExecuteTaskWithWriteLock(this::closeBinaryDictionary);
|
||||
}
|
||||
|
||||
protected Map<String, String> getHeaderAttributeMap() {
|
||||
|
@ -220,12 +212,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
}
|
||||
|
||||
private void removeBinaryDictionary() {
|
||||
asyncExecuteTaskWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
removeBinaryDictionaryLocked();
|
||||
}
|
||||
});
|
||||
asyncExecuteTaskWithWriteLock(this::removeBinaryDictionaryLocked);
|
||||
}
|
||||
|
||||
void removeBinaryDictionaryLocked() {
|
||||
|
@ -248,12 +235,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
}
|
||||
|
||||
public void clear() {
|
||||
asyncExecuteTaskWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
removeBinaryDictionaryLocked();
|
||||
createOnMemoryBinaryDictionaryLocked();
|
||||
}
|
||||
asyncExecuteTaskWithWriteLock(() -> {
|
||||
removeBinaryDictionaryLocked();
|
||||
createOnMemoryBinaryDictionaryLocked();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -261,14 +245,11 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
* Check whether GC is needed and run GC if required.
|
||||
*/
|
||||
public void runGCIfRequired(final boolean mindsBlockByGC) {
|
||||
asyncExecuteTaskWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getBinaryDictionary() == null) {
|
||||
return;
|
||||
}
|
||||
runGCIfRequiredLocked(mindsBlockByGC);
|
||||
asyncExecuteTaskWithWriteLock(() -> {
|
||||
if (getBinaryDictionary() == null) {
|
||||
return;
|
||||
}
|
||||
runGCIfRequiredLocked(mindsBlockByGC);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -280,17 +261,13 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
|
||||
private void updateDictionaryWithWriteLock(@NonNull final Runnable updateTask) {
|
||||
reloadDictionaryIfRequired();
|
||||
final Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getBinaryDictionary() == null) {
|
||||
return;
|
||||
}
|
||||
runGCIfRequiredLocked(true /* mindsBlockByGC */);
|
||||
updateTask.run();
|
||||
asyncExecuteTaskWithWriteLock(() -> {
|
||||
if (getBinaryDictionary() == null) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
asyncExecuteTaskWithWriteLock(task);
|
||||
runGCIfRequiredLocked(true /* mindsBlockByGC */);
|
||||
updateTask.run();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -299,13 +276,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
public void addUnigramEntry(final String word, final int frequency,
|
||||
final String shortcutTarget, final int shortcutFreq, final boolean isNotAWord,
|
||||
final boolean isPossiblyOffensive, final int timestamp) {
|
||||
updateDictionaryWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
addUnigramLocked(word, frequency, shortcutTarget, shortcutFreq,
|
||||
isNotAWord, isPossiblyOffensive, timestamp);
|
||||
}
|
||||
});
|
||||
updateDictionaryWithWriteLock(() -> addUnigramLocked(word, frequency, shortcutTarget,
|
||||
shortcutFreq, isNotAWord, isPossiblyOffensive, timestamp));
|
||||
}
|
||||
|
||||
protected void addUnigramLocked(final String word, final int frequency,
|
||||
|
@ -322,18 +294,15 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
*/
|
||||
public void removeUnigramEntryDynamically(final String word) {
|
||||
reloadDictionaryIfRequired();
|
||||
asyncExecuteTaskWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary == null) {
|
||||
return;
|
||||
}
|
||||
runGCIfRequiredLocked(true /* mindsBlockByGC */);
|
||||
if (!binaryDictionary.removeUnigramEntry(word)) {
|
||||
if (DEBUG) {
|
||||
Log.i(TAG, "Cannot remove unigram entry: " + word);
|
||||
}
|
||||
asyncExecuteTaskWithWriteLock(() -> {
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary == null) {
|
||||
return;
|
||||
}
|
||||
runGCIfRequiredLocked(true /* mindsBlockByGC */);
|
||||
if (!binaryDictionary.removeUnigramEntry(word)) {
|
||||
if (DEBUG) {
|
||||
Log.i(TAG, "Cannot remove unigram entry: " + word);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -345,15 +314,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
public void addNgramEntry(@NonNull final NgramContext ngramContext, final String word,
|
||||
final int frequency, final int timestamp) {
|
||||
reloadDictionaryIfRequired();
|
||||
asyncExecuteTaskWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getBinaryDictionary() == null) {
|
||||
return;
|
||||
}
|
||||
runGCIfRequiredLocked(true /* mindsBlockByGC */);
|
||||
addNgramEntryLocked(ngramContext, word, frequency, timestamp);
|
||||
asyncExecuteTaskWithWriteLock(() -> {
|
||||
if (getBinaryDictionary() == null) {
|
||||
return;
|
||||
}
|
||||
runGCIfRequiredLocked(true /* mindsBlockByGC */);
|
||||
addNgramEntryLocked(ngramContext, word, frequency, timestamp);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -372,19 +338,16 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
*/
|
||||
public void updateEntriesForWord(@NonNull final NgramContext ngramContext,
|
||||
final String word, final boolean isValidWord, final int count, final int timestamp) {
|
||||
updateDictionaryWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary == null) {
|
||||
return;
|
||||
}
|
||||
if (!binaryDictionary.updateEntriesForWordWithNgramContext(ngramContext, word,
|
||||
isValidWord, count, timestamp)) {
|
||||
if (DEBUG) {
|
||||
Log.e(TAG, "Cannot update counter. word: " + word
|
||||
+ " context: " + ngramContext.toString());
|
||||
}
|
||||
updateDictionaryWithWriteLock(() -> {
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary == null) {
|
||||
return;
|
||||
}
|
||||
if (!binaryDictionary.updateEntriesForWordWithNgramContext(ngramContext, word,
|
||||
isValidWord, count, timestamp)) {
|
||||
if (DEBUG) {
|
||||
Log.e(TAG, "Cannot update counter. word: " + word
|
||||
+ " context: " + ngramContext);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -410,21 +373,16 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
@NonNull final ArrayList<WordInputEventForPersonalization> inputEvents,
|
||||
final UpdateEntriesForInputEventsCallback callback) {
|
||||
reloadDictionaryIfRequired();
|
||||
asyncExecuteTaskWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary == null) {
|
||||
return;
|
||||
}
|
||||
binaryDictionary.updateEntriesForInputEvents(
|
||||
inputEvents.toArray(
|
||||
new WordInputEventForPersonalization[inputEvents.size()]));
|
||||
} finally {
|
||||
if (callback != null) {
|
||||
callback.onFinished();
|
||||
}
|
||||
asyncExecuteTaskWithWriteLock(() -> {
|
||||
try {
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary == null) {
|
||||
return;
|
||||
}
|
||||
binaryDictionary.updateEntriesForInputEvents(inputEvents.toArray(new WordInputEventForPersonalization[0]));
|
||||
} finally {
|
||||
if (callback != null) {
|
||||
callback.onFinished();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -601,32 +559,28 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
return;
|
||||
}
|
||||
final File dictFile = mDictFile;
|
||||
asyncExecuteTaskWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (!dictFile.exists() || isNeededToRecreate()) {
|
||||
// If the dictionary file does not exist or contents have been updated,
|
||||
// generate a new one.
|
||||
asyncExecuteTaskWithWriteLock(() -> {
|
||||
try {
|
||||
if (!dictFile.exists() || isNeededToRecreate()) {
|
||||
// If the dictionary file does not exist or contents have been updated,
|
||||
// generate a new one.
|
||||
createNewDictionaryLocked();
|
||||
} else if (getBinaryDictionary() == null) {
|
||||
// Otherwise, load the existing dictionary.
|
||||
loadBinaryDictionaryLocked();
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary != null && !(isValidDictionaryLocked()
|
||||
// TODO: remove the check below
|
||||
&& matchesExpectedBinaryDictFormatVersionForThisType(binaryDictionary.getFormatVersion()))) {
|
||||
// Binary dictionary or its format version is not valid. Regenerate
|
||||
// the dictionary file. createNewDictionaryLocked will remove the
|
||||
// existing files if appropriate.
|
||||
createNewDictionaryLocked();
|
||||
} else if (getBinaryDictionary() == null) {
|
||||
// Otherwise, load the existing dictionary.
|
||||
loadBinaryDictionaryLocked();
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary != null && !(isValidDictionaryLocked()
|
||||
// TODO: remove the check below
|
||||
&& matchesExpectedBinaryDictFormatVersionForThisType(
|
||||
binaryDictionary.getFormatVersion()))) {
|
||||
// Binary dictionary or its format version is not valid. Regenerate
|
||||
// the dictionary file. createNewDictionaryLocked will remove the
|
||||
// existing files if appropriate.
|
||||
createNewDictionaryLocked();
|
||||
}
|
||||
}
|
||||
clearNeedsToRecreate();
|
||||
} finally {
|
||||
isReloading.set(false);
|
||||
}
|
||||
clearNeedsToRecreate();
|
||||
} finally {
|
||||
isReloading.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -636,18 +590,15 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
*/
|
||||
@Override
|
||||
public void onFinishInput() {
|
||||
asyncExecuteTaskWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary == null) {
|
||||
return;
|
||||
}
|
||||
if (binaryDictionary.needsToRunGC(false /* mindsBlockByGC */)) {
|
||||
binaryDictionary.flushWithGCIfHasUpdated();
|
||||
} else {
|
||||
binaryDictionary.flush();
|
||||
}
|
||||
asyncExecuteTaskWithWriteLock(() -> {
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary == null) {
|
||||
return;
|
||||
}
|
||||
if (binaryDictionary.needsToRunGC(false /* mindsBlockByGC */)) {
|
||||
binaryDictionary.flushWithGCIfHasUpdated();
|
||||
} else {
|
||||
binaryDictionary.flush();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -670,12 +621,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
@UsedForTesting
|
||||
public void waitAllTasksForTests() {
|
||||
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
asyncExecuteTaskWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
});
|
||||
asyncExecuteTaskWithWriteLock(countDownLatch::countDown);
|
||||
try {
|
||||
countDownLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -694,35 +640,31 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
reloadDictionaryIfRequired();
|
||||
final String tag = TAG;
|
||||
final String dictName = mDictName;
|
||||
asyncExecuteTaskWithLock(mLock.readLock(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(tag, "Dump dictionary: " + dictName + " for " + mLocale);
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final DictionaryHeader header = binaryDictionary.getHeader();
|
||||
Log.d(tag, "Format version: " + binaryDictionary.getFormatVersion());
|
||||
Log.d(tag, CombinedFormatUtils.formatAttributeMap(
|
||||
header.mDictionaryOptions.mAttributes));
|
||||
} catch (final UnsupportedFormatException e) {
|
||||
Log.d(tag, "Cannot fetch header information.", e);
|
||||
}
|
||||
int token = 0;
|
||||
do {
|
||||
final BinaryDictionary.GetNextWordPropertyResult result =
|
||||
binaryDictionary.getNextWordProperty(token);
|
||||
final WordProperty wordProperty = result.mWordProperty;
|
||||
if (wordProperty == null) {
|
||||
Log.d(tag, " dictionary is empty.");
|
||||
break;
|
||||
}
|
||||
Log.d(tag, wordProperty.toString());
|
||||
token = result.mNextToken;
|
||||
} while (token != 0);
|
||||
asyncExecuteTaskWithLock(mLock.readLock(), () -> {
|
||||
Log.d(tag, "Dump dictionary: " + dictName + " for " + mLocale);
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final DictionaryHeader header = binaryDictionary.getHeader();
|
||||
Log.d(tag, "Format version: " + binaryDictionary.getFormatVersion());
|
||||
Log.d(tag, CombinedFormatUtils.formatAttributeMap(header.mDictionaryOptions.mAttributes));
|
||||
} catch (final UnsupportedFormatException e) {
|
||||
Log.d(tag, "Cannot fetch header information.", e);
|
||||
}
|
||||
int token = 0;
|
||||
do {
|
||||
final BinaryDictionary.GetNextWordPropertyResult result =
|
||||
binaryDictionary.getNextWordProperty(token);
|
||||
final WordProperty wordProperty = result.mWordProperty;
|
||||
if (wordProperty == null) {
|
||||
Log.d(tag, " dictionary is empty.");
|
||||
break;
|
||||
}
|
||||
Log.d(tag, wordProperty.toString());
|
||||
token = result.mNextToken;
|
||||
} while (token != 0);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -733,31 +675,27 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
reloadDictionaryIfRequired();
|
||||
final AsyncResultHolder<WordProperty[]> result =
|
||||
new AsyncResultHolder<>("WordPropertiesForSync");
|
||||
asyncExecuteTaskWithLock(mLock.readLock(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final ArrayList<WordProperty> wordPropertyList = new ArrayList<>();
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary == null) {
|
||||
return;
|
||||
}
|
||||
int token = 0;
|
||||
do {
|
||||
// TODO: We need a new API that returns *new* un-synced data.
|
||||
final BinaryDictionary.GetNextWordPropertyResult nextWordPropertyResult =
|
||||
binaryDictionary.getNextWordProperty(token);
|
||||
final WordProperty wordProperty = nextWordPropertyResult.mWordProperty;
|
||||
if (wordProperty == null) {
|
||||
break;
|
||||
}
|
||||
wordPropertyList.add(wordProperty);
|
||||
token = nextWordPropertyResult.mNextToken;
|
||||
} while (token != 0);
|
||||
result.set(wordPropertyList.toArray(new WordProperty[wordPropertyList.size()]));
|
||||
asyncExecuteTaskWithLock(mLock.readLock(), () -> {
|
||||
final ArrayList<WordProperty> wordPropertyList = new ArrayList<>();
|
||||
final BinaryDictionary binaryDictionary = getBinaryDictionary();
|
||||
if (binaryDictionary == null) {
|
||||
return;
|
||||
}
|
||||
int token = 0;
|
||||
do {
|
||||
// TODO: We need a new API that returns *new* un-synced data.
|
||||
final BinaryDictionary.GetNextWordPropertyResult nextWordPropertyResult =
|
||||
binaryDictionary.getNextWordProperty(token);
|
||||
final WordProperty wordProperty = nextWordPropertyResult.mWordProperty;
|
||||
if (wordProperty == null) {
|
||||
break;
|
||||
}
|
||||
wordPropertyList.add(wordProperty);
|
||||
token = nextWordPropertyResult.mNextToken;
|
||||
} while (token != 0);
|
||||
result.set(wordPropertyList.toArray(new WordProperty[0]));
|
||||
});
|
||||
// TODO: Figure out the best timeout duration for this API.
|
||||
return result.get(DEFAULT_WORD_PROPERTIES_FOR_SYNC,
|
||||
TIMEOUT_FOR_READ_OPS_IN_MILLISECONDS);
|
||||
return result.get(DEFAULT_WORD_PROPERTIES_FOR_SYNC, TIMEOUT_FOR_READ_OPS_IN_MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,12 +16,11 @@
|
|||
|
||||
package org.dslul.openboard.inputmethod.latin;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
|
||||
import androidx.core.view.inputmethod.EditorInfoCompat;
|
||||
|
||||
import org.dslul.openboard.inputmethod.latin.common.StringUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.InputTypeUtils;
|
||||
|
||||
|
@ -94,14 +93,10 @@ public final class InputAttributes {
|
|||
}
|
||||
// inputClass == InputType.TYPE_CLASS_TEXT
|
||||
final int variation = inputType & InputType.TYPE_MASK_VARIATION;
|
||||
final boolean flagNoSuggestions =
|
||||
0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
||||
final boolean flagMultiLine =
|
||||
0 != (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE);
|
||||
final boolean flagAutoCorrect =
|
||||
0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
|
||||
final boolean flagAutoComplete =
|
||||
0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
|
||||
final boolean flagNoSuggestions = 0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
||||
final boolean flagMultiLine = 0 != (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE);
|
||||
final boolean flagAutoCorrect = 0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
|
||||
final boolean flagAutoComplete = 0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
|
||||
|
||||
// TODO: Have a helper method in InputTypeUtils
|
||||
// Make sure that passwords are not displayed in {@link SuggestionStripView}.
|
||||
|
@ -140,7 +135,10 @@ public final class InputAttributes {
|
|||
&& InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD != variation;
|
||||
|
||||
|
||||
mNoLearning = flagNoSuggestions || (editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING) != 0;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
mNoLearning = flagNoSuggestions || (editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING) != 0;
|
||||
else
|
||||
mNoLearning = flagNoSuggestions;
|
||||
}
|
||||
|
||||
public boolean isTypeNull() {
|
||||
|
|
|
@ -43,7 +43,7 @@ public class RichInputMethodSubtype {
|
|||
private static final String TAG = RichInputMethodSubtype.class.getSimpleName();
|
||||
|
||||
private static final HashMap<Locale, Locale> sLocaleMap = initializeLocaleMap();
|
||||
private static final HashMap<Locale, Locale> initializeLocaleMap() {
|
||||
private static HashMap<Locale, Locale> initializeLocaleMap() {
|
||||
final HashMap<Locale, Locale> map = new HashMap<>();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
// Locale#forLanguageTag is available on API Level 21+.
|
||||
|
@ -182,12 +182,18 @@ public class RichInputMethodSubtype {
|
|||
+ "," + Constants.Subtype.ExtraValue.EMOJI_CAPABLE;
|
||||
@NonNull
|
||||
private static final RichInputMethodSubtype DUMMY_NO_LANGUAGE_SUBTYPE =
|
||||
new RichInputMethodSubtype(new InputMethodSubtype(
|
||||
R.string.subtype_no_language_qwerty, R.drawable.ic_ime_switcher_dark,
|
||||
SubtypeLocaleUtils.NO_LANGUAGE, KEYBOARD_MODE,
|
||||
EXTRA_VALUE_OF_DUMMY_NO_LANGUAGE_SUBTYPE,
|
||||
false /* isAuxiliary */, false /* overridesImplicitlyEnabledSubtype */,
|
||||
SUBTYPE_ID_OF_DUMMY_NO_LANGUAGE_SUBTYPE));
|
||||
new RichInputMethodSubtype(new InputMethodSubtype.InputMethodSubtypeBuilder()
|
||||
.setSubtypeNameResId(R.string.subtype_no_language_qwerty)
|
||||
.setSubtypeIconResId(R.drawable.ic_ime_switcher_dark)
|
||||
.setSubtypeLocale(SubtypeLocaleUtils.NO_LANGUAGE)
|
||||
.setSubtypeMode(KEYBOARD_MODE)
|
||||
.setSubtypeExtraValue(EXTRA_VALUE_OF_DUMMY_NO_LANGUAGE_SUBTYPE)
|
||||
.setIsAuxiliary(false)
|
||||
.setOverridesImplicitlyEnabledSubtype(false)
|
||||
.setSubtypeId(SUBTYPE_ID_OF_DUMMY_NO_LANGUAGE_SUBTYPE)
|
||||
.setIsAsciiCapable(true)
|
||||
.build());
|
||||
|
||||
// Caveat: We probably should remove this when we add an Emoji subtype in {@link R.xml.method}.
|
||||
// Dummy Emoji subtype. See {@link R.xml.method}.
|
||||
private static final int SUBTYPE_ID_OF_DUMMY_EMOJI_SUBTYPE = 0xd78b2ed0;
|
||||
|
@ -195,13 +201,17 @@ public class RichInputMethodSubtype {
|
|||
"KeyboardLayoutSet=" + SubtypeLocaleUtils.EMOJI
|
||||
+ "," + Constants.Subtype.ExtraValue.EMOJI_CAPABLE;
|
||||
@NonNull
|
||||
private static final RichInputMethodSubtype DUMMY_EMOJI_SUBTYPE = new RichInputMethodSubtype(
|
||||
new InputMethodSubtype(
|
||||
R.string.subtype_emoji, R.drawable.ic_ime_switcher_dark,
|
||||
SubtypeLocaleUtils.NO_LANGUAGE, KEYBOARD_MODE,
|
||||
EXTRA_VALUE_OF_DUMMY_EMOJI_SUBTYPE,
|
||||
false /* isAuxiliary */, false /* overridesImplicitlyEnabledSubtype */,
|
||||
SUBTYPE_ID_OF_DUMMY_EMOJI_SUBTYPE));
|
||||
private static final RichInputMethodSubtype DUMMY_EMOJI_SUBTYPE =
|
||||
new RichInputMethodSubtype(new InputMethodSubtype.InputMethodSubtypeBuilder()
|
||||
.setSubtypeNameResId(R.string.subtype_emoji)
|
||||
.setSubtypeIconResId(R.drawable.ic_ime_switcher_dark)
|
||||
.setSubtypeLocale(SubtypeLocaleUtils.NO_LANGUAGE)
|
||||
.setSubtypeMode(KEYBOARD_MODE)
|
||||
.setSubtypeExtraValue(EXTRA_VALUE_OF_DUMMY_EMOJI_SUBTYPE)
|
||||
.setIsAuxiliary(false)
|
||||
.setOverridesImplicitlyEnabledSubtype(false)
|
||||
.setSubtypeId(SUBTYPE_ID_OF_DUMMY_EMOJI_SUBTYPE)
|
||||
.build());
|
||||
private static RichInputMethodSubtype sNoLanguageSubtype;
|
||||
private static RichInputMethodSubtype sEmojiSubtype;
|
||||
|
||||
|
@ -210,8 +220,7 @@ public class RichInputMethodSubtype {
|
|||
RichInputMethodSubtype noLanguageSubtype = sNoLanguageSubtype;
|
||||
if (noLanguageSubtype == null) {
|
||||
final InputMethodSubtype rawNoLanguageSubtype = RichInputMethodManager.getInstance()
|
||||
.findSubtypeByLocaleAndKeyboardLayoutSet(
|
||||
SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY);
|
||||
.findSubtypeByLocaleAndKeyboardLayoutSet(SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.QWERTY);
|
||||
if (rawNoLanguageSubtype != null) {
|
||||
noLanguageSubtype = new RichInputMethodSubtype(rawNoLanguageSubtype);
|
||||
}
|
||||
|
@ -221,8 +230,7 @@ public class RichInputMethodSubtype {
|
|||
return noLanguageSubtype;
|
||||
}
|
||||
Log.w(TAG, "Can't find any language with QWERTY subtype");
|
||||
Log.w(TAG, "No input method subtype found; returning dummy subtype: "
|
||||
+ DUMMY_NO_LANGUAGE_SUBTYPE);
|
||||
Log.w(TAG, "No input method subtype found; returning dummy subtype: " + DUMMY_NO_LANGUAGE_SUBTYPE);
|
||||
return DUMMY_NO_LANGUAGE_SUBTYPE;
|
||||
}
|
||||
|
||||
|
@ -231,8 +239,7 @@ public class RichInputMethodSubtype {
|
|||
RichInputMethodSubtype emojiSubtype = sEmojiSubtype;
|
||||
if (emojiSubtype == null) {
|
||||
final InputMethodSubtype rawEmojiSubtype = RichInputMethodManager.getInstance()
|
||||
.findSubtypeByLocaleAndKeyboardLayoutSet(
|
||||
SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.EMOJI);
|
||||
.findSubtypeByLocaleAndKeyboardLayoutSet(SubtypeLocaleUtils.NO_LANGUAGE, SubtypeLocaleUtils.EMOJI);
|
||||
if (rawEmojiSubtype != null) {
|
||||
emojiSubtype = new RichInputMethodSubtype(rawEmojiSubtype);
|
||||
}
|
||||
|
@ -242,8 +249,7 @@ public class RichInputMethodSubtype {
|
|||
return emojiSubtype;
|
||||
}
|
||||
Log.w(TAG, "Can't find emoji subtype");
|
||||
Log.w(TAG, "No input method subtype found; returning dummy subtype: "
|
||||
+ DUMMY_EMOJI_SUBTYPE);
|
||||
Log.w(TAG, "No input method subtype found; returning dummy subtype: " + DUMMY_EMOJI_SUBTYPE);
|
||||
return DUMMY_EMOJI_SUBTYPE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,7 +203,7 @@ public class SuggestedWords {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
public static final SuggestedWords getEmptyInstance() {
|
||||
public static SuggestedWords getEmptyInstance() {
|
||||
return SuggestedWords.EMPTY;
|
||||
}
|
||||
|
||||
|
@ -347,7 +347,7 @@ public class SuggestedWords {
|
|||
return (mKindAndFlags & KIND_FLAG_EXACT_MATCH_WITH_INTENTIONAL_OMISSION) != 0;
|
||||
}
|
||||
|
||||
public boolean isAprapreateForAutoCorrection() {
|
||||
public boolean isAppropriateForAutoCorrection() {
|
||||
return (mKindAndFlags & KIND_FLAG_APPROPRIATE_FOR_AUTO_CORRECTION) != 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.dslul.openboard.inputmethod.latin.utils;
|
|||
|
||||
import static android.view.KeyEvent.KEYCODE_SPACE;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
|
@ -37,6 +38,7 @@ public final class AutoCorrectionUtils {
|
|||
// Purely static class: can't instantiate.
|
||||
}
|
||||
|
||||
@SuppressLint("ObsoleteSdkInt") // SDK_INT is 0 in unit tests
|
||||
public static boolean suggestionExceedsThreshold(final SuggestedWordInfo suggestion,
|
||||
final String consideredWord, final float threshold) {
|
||||
if (null != suggestion) {
|
||||
|
@ -44,15 +46,15 @@ public final class AutoCorrectionUtils {
|
|||
if (suggestion.isKindOf(SuggestedWordInfo.KIND_WHITELIST)) {
|
||||
return true;
|
||||
}
|
||||
// TODO: return suggestion.isAprapreateForAutoCorrection();
|
||||
if (!suggestion.isAprapreateForAutoCorrection()) {
|
||||
// TODO: return suggestion.isAppropriateForAutoCorrection();
|
||||
if (!suggestion.isAppropriateForAutoCorrection()) {
|
||||
return false;
|
||||
}
|
||||
final int autoCorrectionSuggestionScore = suggestion.mScore;
|
||||
// TODO: when the normalized score of the first suggestion is nearly equals to
|
||||
// the normalized score of the second suggestion, behave less aggressive.
|
||||
final float normalizedScore;
|
||||
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT == 0) // SDK_INT is 0 in unit tests
|
||||
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT == 0)
|
||||
normalizedScore = calcNormalizedScore(StringUtils.toCodePointArray(consideredWord), StringUtils.toCodePointArray(suggestion.mWord), autoCorrectionSuggestionScore, editDistance(consideredWord, suggestion.mWord));
|
||||
else
|
||||
normalizedScore = BinaryDictionaryUtils.calcNormalizedScore(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue