aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java3
-rw-r--r--src/main/java/com/anysoftkeyboard/WordComposer.java341
-rw-r--r--src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific.java2
-rw-r--r--src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific_V11.java7
-rw-r--r--src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific_V3.java2
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/BTreeDictionary.java7
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/Dictionary.java157
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/DictionaryASyncLoader.java7
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/DictionaryAddOnAndBuilder.java1
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/DictionaryFactory.java2
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/EditableDictionary.java40
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/Suggest.java4
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/UserDictionary.java10
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/WordsCursor.java63
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/content/AndroidUserDictionary.java3
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/content/ContactsDictionary.java2
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/jni/BinaryDictionary.java5
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/jni/ResourceBinaryDictionary.java4
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/sqlite/AbbreviationsDictionary.java5
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/sqlite/AutoDictionary.java2
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/sqlite/SQLiteUserDictionaryBase.java3
-rw-r--r--src/main/java/com/anysoftkeyboard/dictionaries/sqlite/WordsSQLiteConnection.java5
-rw-r--r--src/main/java/com/anysoftkeyboard/spellcheck/SuggestionsGatherer.java5
-rw-r--r--src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/AbbreviationDictionaryEditorFragment.java2
-rw-r--r--src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/BackupUserWordsAsyncTask.java2
-rw-r--r--src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/RestoreUserWordsAsyncTask.java10
-rw-r--r--src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/UserDictionaryEditorFragment.java4
27 files changed, 51 insertions, 647 deletions
diff --git a/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java b/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java
index 5cb96b2eb..2eeecf535 100644
--- a/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java
+++ b/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java
@@ -55,9 +55,10 @@ import android.widget.Toast;
import com.anysoftkeyboard.LayoutSwitchAnimationListener.AnimationType;
import com.anysoftkeyboard.api.KeyCodes;
+import com.anysoftkeyboard.base.dictionaries.WordComposer;
import com.anysoftkeyboard.devicespecific.Clipboard;
import com.anysoftkeyboard.dictionaries.DictionaryAddOnAndBuilder;
-import com.anysoftkeyboard.dictionaries.EditableDictionary;
+import com.anysoftkeyboard.base.dictionaries.EditableDictionary;
import com.anysoftkeyboard.dictionaries.ExternalDictionaryFactory;
import com.anysoftkeyboard.dictionaries.Suggest;
import com.anysoftkeyboard.dictionaries.TextEntryState;
diff --git a/src/main/java/com/anysoftkeyboard/WordComposer.java b/src/main/java/com/anysoftkeyboard/WordComposer.java
deleted file mode 100644
index 4079f12b5..000000000
--- a/src/main/java/com/anysoftkeyboard/WordComposer.java
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- * Copyright (c) 2013 Menny Even-Danan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.anysoftkeyboard;
-
-import com.anysoftkeyboard.dictionaries.content.AndroidUserDictionary;
-import com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView;
-import com.anysoftkeyboard.utils.Log;
-import com.menny.android.anysoftkeyboard.FeaturesSet;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * A place to store the currently composing word with information such as adjacent key codes as well
- */
-public class WordComposer {
- private static final String CHEWBACCAONTHEDRUMS = "chewbacca";
- private static final String TAG = "ASK _WC";
- /**
- * The list of unicode values for each keystroke (including surrounding keys)
- */
- private final ArrayList<int[]> mCodes = new ArrayList<>(AndroidUserDictionary.MAX_WORD_LENGTH);
-
- /**
- * This holds arrays for reuse. Will not exceed AndroidUserDictionary.MAX_WORD_LENGTH
- */
- private final List<int[]> mArraysToReuse = new ArrayList<>(AndroidUserDictionary.MAX_WORD_LENGTH);
-
- /**
- * The word chosen from the candidate list, until it is committed.
- */
- private CharSequence mPreferredWord;
-
- private final StringBuilder mTypedWord = new StringBuilder(AndroidUserDictionary.MAX_WORD_LENGTH);
-
- private int mCursorPosition;
- private int mGlobalCursorPosition;
-
- private int mCapsCount;
-
- private boolean mAutoCapitalized;
-
- /**
- * Whether the user chose to capitalize the first char of the word.
- */
- private boolean mIsFirstCharCapitalized;
-
- public WordComposer() {
- }
-/*
- WordComposer(WordComposer copy) {
- mCodes = new ArrayList<int[]>(copy.mCodes);
- mPreferredWord = copy.mPreferredWord;
- mTypedWord = new StringBuilder(copy.mTypedWord);
- mCapsCount = copy.mCapsCount;
- mAutoCapitalized = copy.mAutoCapitalized;
- mIsFirstCharCapitalized = copy.mIsFirstCharCapitalized;
- }
-*/
-
- /**
- * Clear out the keys registered so far.
- */
- public void reset() {
- //moving arrays back to re-use list
- for (int[] array : mCodes) {
- mArraysToReuse.add(array);
- }
- mCodes.clear();
- mIsFirstCharCapitalized = false;
- mPreferredWord = null;
- mTypedWord.setLength(0);
- mCapsCount = 0;
- mCursorPosition = 0;
- mGlobalCursorPosition = 0;
- }
-
- /**
- * Number of keystrokes in the composing word.
- *
- * @return the number of keystrokes
- */
- public int length() {
- return mTypedWord.length();
- }
-
- /**
- * Cursor position
- */
- public int cursorPosition() {
- return mCursorPosition;
- }
-
- public int globalCursorPosition() {
- return mGlobalCursorPosition;
- }
-
- public void setGlobalCursorPosition(int position) {
- mGlobalCursorPosition = position;
- }
-
- public boolean setCursorPostion(int position/*, int candidatesStartPosition*/) {
- if (position < 0 || position > length())//note: the cursor can be AFTER the word, so it can be equal to size()
- {
- Log.w(TAG, "New cursor position is invalid! It is outside the word (size " + length() + ", new position " + position + ". Disregarding!!!!");
- return false;
- }
- final boolean changed = mCursorPosition != position;
- mCursorPosition = position;
- return changed;
- //mCandidatesStartPosition = candidatesStartPosition;
- }
- /*
- public boolean hasUserMovedCursor(int cursorPosition)
- {
- if (AnyApplication.DEBUG)
- {
- Log.d(TAG, "Current cursor position inside word is "+mCursorPosition+", and word starts at "+mCandidatesStartPosition+". Input's cursor is at "+cursorPosition);
- }
- return (cursorPosition != (mCursorPosition + mCandidatesStartPosition));
- }
-
- public boolean hasUserMovedCursorInsideOfWord(int cursorPosition)
- {
- if (AnyApplication.DEBUG)
- {
- Log.d(TAG, "Current word length is "+mTypedWord.length()+", and word starts at "+mCandidatesStartPosition+". Input's cursor is at "+cursorPosition);
- }
- return (cursorPosition >= mCandidatesStartPosition && cursorPosition <= (mCandidatesStartPosition+mTypedWord.length()));
- }
- */
-
- /**
- * Returns the codes at a particular position in the word.
- *
- * @param index the position in the word
- * @return the unicode for the pressed and surrounding keys
- */
- public int[] getCodesAt(int index) {
- return mCodes.get(index);
- }
-
- /**
- * Add a new keystroke, with codes[0] containing the pressed key's unicode and the rest of
- * the array containing unicode for adjacent keys, sorted by reducing probability/proximity.
- *
- * @param codes the array of unicode values
- */
- public boolean add(int primaryCode, int[] codes) {
-
- mTypedWord.insert(mCursorPosition, (char) primaryCode);
- /*if (codes != null)
- {
- for(int i=0; i<codes.length; i++)
- {
- if (codes[i] > 32) codes[i] = Character.toLowerCase(codes[i]);
- }
- }*/
-
- correctPrimaryJuxtapos(primaryCode, codes);
- //this will return a copy of the codes array, stored in an array with sufficent storage
- int[] reusableArray = getReusableArray(codes);
- mCodes.add(mCursorPosition, reusableArray);
- mCursorPosition++;
- if (Character.isUpperCase((char) primaryCode)) mCapsCount++;
-
- if (mTypedWord.length() == CHEWBACCAONTHEDRUMS.length()) {
- if (mTypedWord.toString().equalsIgnoreCase(CHEWBACCAONTHEDRUMS)) {
- return true;
- }
- }
-
- return false;
- }
-
- private int[] getReusableArray(int[] codes) {
- while (mArraysToReuse.size() > 0) {
- int[] possibleArray = mArraysToReuse.remove(0);
- //is it usable in this situation?
- if (possibleArray.length >= codes.length) {
- System.arraycopy(codes, 0, possibleArray, 0, codes.length);
- if (possibleArray.length > codes.length)
- Arrays.fill(possibleArray, codes.length, possibleArray.length, AnyKeyboardBaseView.NOT_A_KEY);
- Log.d(TAG, "Found an array to reuse with length " + possibleArray.length);
- return possibleArray;
- }
- }
- //if I got here, it means that the reusableArray does not contain a long enough array
- Log.d(TAG, "Creating a new array with length " + codes.length);
- int[] newArray = new int[codes.length];
- mArraysToReuse.add(newArray);
- return getReusableArray(codes);
- }
-
- /**
- * Swaps the first and second values in the codes array if the primary code is not the first
- * value in the array but the second. This happens when the preferred key is not the key that
- * the user released the finger on.
- *
- * @param primaryCode the preferred character
- * @param nearByKeyCodes array of codes based on distance from touch point
- */
- private static void correctPrimaryJuxtapos(int primaryCode, int[] nearByKeyCodes) {
- /*if (codes.length < 2) return;
- if (codes[0] > 0 && codes[1] > 0 && codes[0] != primaryCode && codes[1] == primaryCode) {
- codes[1] = codes[0];
- codes[0] = primaryCode;
- }*/
- if (nearByKeyCodes != null && nearByKeyCodes.length > 1 && primaryCode != nearByKeyCodes[0] && primaryCode != Character.toLowerCase((char) nearByKeyCodes[0])) {
- int swappedItem = nearByKeyCodes[0];
- nearByKeyCodes[0] = primaryCode;
- boolean found = false;
- for (int i = 1; i < nearByKeyCodes.length; i++) {
- if (nearByKeyCodes[i] == primaryCode) {
- nearByKeyCodes[i] = swappedItem;
- found = true;
- break;
- }
- }
- if (!found) //reverting
- nearByKeyCodes[0] = swappedItem;
- }
- }
-
- /**
- * Delete the last keystroke as a result of hitting backspace.
- */
- public void deleteLast() {
- if (mCursorPosition > 0) {
- //removing from the codes list, and taking it back to the reusable list
- mArraysToReuse.add(mCodes.remove(mCursorPosition - 1));
- //final int lastPos = mTypedWord.length() - 1;
- char last = mTypedWord.charAt(mCursorPosition - 1);
- mTypedWord.deleteCharAt(mCursorPosition - 1);
- mCursorPosition--;
- if (Character.isUpperCase(last)) mCapsCount--;
- }
- }
-
- /**
- * Returns the word as it was typed, without any correction applied.
- *
- * @return the word that was typed so far
- */
- public CharSequence getTypedWord() {
- int wordSize = mCodes.size();
- if (wordSize == 0) {
- return "";
- }
- return mTypedWord;
- }
-
- public void setFirstCharCapitalized(boolean capitalized) {
- mIsFirstCharCapitalized = capitalized;
- }
-
- /**
- * Whether or not the user typed a capital letter as the first letter in the word
- *
- * @return capitalization preference
- */
- public boolean isFirstCharCapitalized() {
- return mIsFirstCharCapitalized;
- }
-
- /**
- * Whether or not all of the user typed chars are upper case
- *
- * @return true if all user typed chars are upper case, false otherwise
- */
- public boolean isAllUpperCase() {
- return (mCapsCount > 0) && (mCapsCount == length());
- }
-
- /**
- * Stores the user's selected word, before it is actually committed to the text field.
- *
- * @param preferred
- */
- public void setPreferredWord(CharSequence preferred) {
- mPreferredWord = preferred;
- }
-
- public CharSequence getPreferredWord() {
- return mPreferredWord;
- }
-
- /**
- * Returns true if more than one character is upper case, otherwise returns false.
- */
- public boolean isMostlyCaps() {
- return mCapsCount > 1;
- }
-
- /**
- * Saves the reason why the word is capitalized - whether it was automatic or
- * due to the user hitting shift in the middle of a sentence.
- *
- * @param auto whether it was an automatic capitalization due to start of sentence
- */
- public void setAutoCapitalized(boolean auto) {
- mAutoCapitalized = auto;
- }
-
- /**
- * Returns whether the word was automatically capitalized.
- *
- * @return whether the word was automatically capitalized
- */
- public boolean isAutoCapitalized() {
- return mAutoCapitalized;
- }
-
- public void logCodes() {
- if (!FeaturesSet.DEBUG_LOG) return;
- Log.d(TAG, "Word: " + mTypedWord + ", prefered word:" + mPreferredWord);
- int i = 0;
- for (int[] codes : mCodes) {
- String codesString = "Codes #" + i + ": ";
- for (int c : codes) {
- codesString += "" + c + ",";
- }
- Log.d(TAG, codesString);
- }
- }
-}
diff --git a/src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific.java b/src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific.java
index 2fe7a4a0d..cd29b31a1 100644
--- a/src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific.java
+++ b/src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific.java
@@ -22,7 +22,7 @@ import android.view.GestureDetector;
import android.view.inputmethod.InputConnection;
import com.anysoftkeyboard.IndirectlyInstantiated;
-import com.anysoftkeyboard.WordComposer;
+import com.anysoftkeyboard.base.dictionaries.WordComposer;
@IndirectlyInstantiated
public interface DeviceSpecific {
diff --git a/src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific_V11.java b/src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific_V11.java
index 84419e8f8..4b5f82024 100644
--- a/src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific_V11.java
+++ b/src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific_V11.java
@@ -22,7 +22,7 @@ import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.InputConnection;
import com.anysoftkeyboard.IndirectlyInstantiated;
-import com.anysoftkeyboard.WordComposer;
+import com.anysoftkeyboard.base.dictionaries.WordComposer;
@TargetApi(11)
@IndirectlyInstantiated
@@ -33,8 +33,7 @@ public class DeviceSpecific_V11 extends DeviceSpecific_V8 {
}
@Override
- public void commitCorrectionToInputConnection(InputConnection ic,
- WordComposer word) {
+ public void commitCorrectionToInputConnection(InputConnection ic, WordComposer word) {
super.commitCorrectionToInputConnection(ic, word);
CorrectionInfo correctionInfo = new CorrectionInfo(
word.globalCursorPosition() - word.getTypedWord().length(),
@@ -45,6 +44,6 @@ public class DeviceSpecific_V11 extends DeviceSpecific_V8 {
@Override
public boolean isHardwareAcceleratedCanvas(Canvas canvas) {
- return canvas != null || canvas.isHardwareAccelerated();
+ return canvas != null && canvas.isHardwareAccelerated();
}
}
diff --git a/src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific_V3.java b/src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific_V3.java
index d6d46037f..cebaa812b 100644
--- a/src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific_V3.java
+++ b/src/main/java/com/anysoftkeyboard/devicespecific/DeviceSpecific_V3.java
@@ -24,7 +24,7 @@ import android.view.GestureDetector;
import android.view.inputmethod.InputConnection;
import com.anysoftkeyboard.IndirectlyInstantiated;
-import com.anysoftkeyboard.WordComposer;
+import com.anysoftkeyboard.base.dictionaries.WordComposer;
@TargetApi(3)
@IndirectlyInstantiated
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/BTreeDictionary.java b/src/main/java/com/anysoftkeyboard/dictionaries/BTreeDictionary.java
index f204dde28..f63bc84f4 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/BTreeDictionary.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/BTreeDictionary.java
@@ -22,7 +22,10 @@ import android.database.ContentObserver;
import android.database.Cursor;
import android.text.TextUtils;
-import com.anysoftkeyboard.WordComposer;
+import com.anysoftkeyboard.base.dictionaries.Dictionary;
+import com.anysoftkeyboard.base.dictionaries.EditableDictionary;
+import com.anysoftkeyboard.base.dictionaries.WordComposer;
+import com.anysoftkeyboard.base.dictionaries.WordsCursor;
import com.anysoftkeyboard.utils.Log;
import com.menny.android.anysoftkeyboard.AnyApplication;
import com.menny.android.anysoftkeyboard.FeaturesSet;
@@ -207,7 +210,7 @@ public abstract class BTreeDictionary extends EditableDictionary {
protected abstract void AddWordToStorage(String word, int frequency);
@Override
- public void getWords(final WordComposer codes, final WordCallback callback) {
+ public void getWords(final WordComposer codes, final Dictionary.WordCallback callback) {
if (isLoading() || isClosed()) return;
mInputLength = codes.length();
mMaxDepth = mInputLength * 2;
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/Dictionary.java b/src/main/java/com/anysoftkeyboard/dictionaries/Dictionary.java
deleted file mode 100644
index af688bea0..000000000
--- a/src/main/java/com/anysoftkeyboard/dictionaries/Dictionary.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (c) 2013 Menny Even-Danan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.anysoftkeyboard.dictionaries;
-
-import com.anysoftkeyboard.WordComposer;
-
-/**
- * Abstract base class for a dictionary that can do a fuzzy search for words based on a set of key
- * strokes.
- */
-abstract public class Dictionary {
- private static final String TAG = "ASK_DICT";
-
- public static final int MAX_WORD_FREQUENCY = 255;
-
- /**
- * Whether or not to replicate the typed word in the suggested list, even if it's valid.
- */
- protected static final boolean INCLUDE_TYPED_WORD_IF_VALID = false;
-
- /**
- * The weight to give to a word if it's length is the same as the number of typed characters.
- */
- protected static final int FULL_WORD_FREQ_MULTIPLIER = 3;
-
- /**
- * The weight to give to a letter if it is typed.
- */
- protected static final int TYPED_LETTER_MULTIPLIER = 3;
-
- /**
- * Interface to be implemented by classes requesting words to be fetched from the dictionary.
- *
- * @see #getWords(WordComposer, WordCallback)
- */
- public interface WordCallback {
- /**
- * Adds a word to a list of suggestions. The word is expected to be ordered based on
- * the provided frequency.
- *
- * @param word the character array containing the word
- * @param wordOffset starting offset of the word in the character array
- * @param wordLength length of valid characters in the character array
- * @param frequency the frequency of occurence. This is normalized between 1 and 255, but
- * can exceed those limits
- * @return true if the word was added, false if no more words are required
- */
- boolean addWord(char[] word, int wordOffset, int wordLength, int frequency, Dictionary from);
- }
-
- private volatile boolean mLoadingResources = true;
- protected final Object mResourceMonitor = new Object();
- private final String mDictionaryName;
- private volatile boolean mClosed = false;
-
- protected Dictionary(String dictionaryName) {
- mDictionaryName = dictionaryName;
- }
-
- protected boolean isLoading() {
- return mLoadingResources;
- }
-
- /**
- * Searches for words in the dictionary that match the characters in the composer. Matched
- * words are added through the callback object.
- *
- * @param composer the key sequence to match
- * @param callback the callback object to send matched words to as possible candidates
- * @see WordCallback#addWord(char[], int, int, int, com.anysoftkeyboard.dictionaries.Dictionary)
- */
- abstract public void getWords(final WordComposer composer, final WordCallback callback);
-
- /**
- * Checks if the given word occurs in the dictionary
- *
- * @param word the word to search for. The search should be case-insensitive.
- * @return true if the word exists, false otherwise
- */
- abstract public boolean isValidWord(CharSequence word);
-
- /**
- * Compares the contents of the character array with the typed word and returns true if they
- * are the same.
- *
- * @param word the array of characters that make up the word
- * @param length the number of valid characters in the character array
- * @param typedWord the word to compare with
- * @return true if they are the same, false otherwise.
- */
- static protected final boolean same(final char[] word, final int length, final CharSequence typedWord) {
- if (typedWord.length() != length) {
- return false;
- }
- for (int i = 0; i < length; i++) {
- if (word[i] != typedWord.charAt(i)) {
- return false;
- }
- }
- return true;
- }
-
- public final void close() {
- if (mClosed)
- return;
- mClosed = true;
- synchronized (mResourceMonitor) {
- closeAllResources();
- }
- }
-
- public final boolean isClosed() {
- return mClosed;
- }
-
- protected abstract void closeAllResources();
-
- public final void loadDictionary() {
- if (mClosed)
- return;
- synchronized (mResourceMonitor) {
- try {
- mLoadingResources = true;
- if (mClosed)
- return;
- loadAllResources();
- } finally {
- mLoadingResources = false;
- }
- }
- }
-
- protected abstract void loadAllResources();
-
- public final String getDictionaryName() {
- return mDictionaryName;
- }
-
- @Override
- public String toString() {
- return mDictionaryName;
- }
-}
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/DictionaryASyncLoader.java b/src/main/java/com/anysoftkeyboard/dictionaries/DictionaryASyncLoader.java
index 5312298ad..09c82b1bb 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/DictionaryASyncLoader.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/DictionaryASyncLoader.java
@@ -1,6 +1,8 @@
package com.anysoftkeyboard.dictionaries;
import android.os.AsyncTask;
+
+import com.anysoftkeyboard.base.dictionaries.Dictionary;
import com.anysoftkeyboard.utils.Log;
import java.lang.ref.WeakReference;
@@ -17,7 +19,7 @@ public class DictionaryASyncLoader extends AsyncTask<Dictionary, Void, Dictionar
private Exception mException = null;
public DictionaryASyncLoader(Listener listener) {
- mListener = new WeakReference<Listener>(listener);
+ mListener = new WeakReference<>(listener);
}
@Override
@@ -53,9 +55,8 @@ public class DictionaryASyncLoader extends AsyncTask<Dictionary, Void, Dictionar
}
}
- public static interface Listener {
+ public interface Listener {
void onDictionaryLoadingDone(Dictionary dictionary);
-
void onDictionaryLoadingFailed(Dictionary dictionary, Exception exception);
}
}
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/DictionaryAddOnAndBuilder.java b/src/main/java/com/anysoftkeyboard/dictionaries/DictionaryAddOnAndBuilder.java
index f00707b16..dcaa47ecd 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/DictionaryAddOnAndBuilder.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/DictionaryAddOnAndBuilder.java
@@ -18,6 +18,7 @@ package com.anysoftkeyboard.dictionaries;
import android.content.Context;
import com.anysoftkeyboard.addons.AddOnImpl;
+import com.anysoftkeyboard.base.dictionaries.Dictionary;
import com.anysoftkeyboard.dictionaries.jni.BinaryDictionary;
import com.anysoftkeyboard.dictionaries.jni.ResourceBinaryDictionary;
import com.anysoftkeyboard.utils.Log;
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/DictionaryFactory.java b/src/main/java/com/anysoftkeyboard/dictionaries/DictionaryFactory.java
index a563282e0..4d9bc7ee8 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/DictionaryFactory.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/DictionaryFactory.java
@@ -18,6 +18,8 @@ package com.anysoftkeyboard.dictionaries;
import android.content.Context;
+import com.anysoftkeyboard.base.dictionaries.Dictionary;
+import com.anysoftkeyboard.base.dictionaries.EditableDictionary;
import com.anysoftkeyboard.dictionaries.content.ContactsDictionary;
import com.anysoftkeyboard.dictionaries.sqlite.AutoDictionary;
import com.anysoftkeyboard.utils.Log;
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/EditableDictionary.java b/src/main/java/com/anysoftkeyboard/dictionaries/EditableDictionary.java
deleted file mode 100644
index d2c36d55b..000000000
--- a/src/main/java/com/anysoftkeyboard/dictionaries/EditableDictionary.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2013 Menny Even-Danan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.anysoftkeyboard.dictionaries;
-
-
-public abstract class EditableDictionary extends Dictionary {
-
- protected EditableDictionary(String dictionaryName) {
- super(dictionaryName);
- }
-
- /**
- * 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
- */
- public abstract boolean addWord(String word, int frequency);
-
- public abstract WordsCursor getWordsCursor();
-
- public abstract void deleteWord(String word);
-}
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/Suggest.java b/src/main/java/com/anysoftkeyboard/dictionaries/Suggest.java
index e271c7480..82b32ff06 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/Suggest.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/Suggest.java
@@ -21,7 +21,8 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
-import com.anysoftkeyboard.WordComposer;
+import com.anysoftkeyboard.base.dictionaries.Dictionary;
+import com.anysoftkeyboard.base.dictionaries.WordComposer;
import com.anysoftkeyboard.dictionaries.sqlite.AbbreviationsDictionary;
import com.anysoftkeyboard.utils.CompatUtils;
import com.anysoftkeyboard.utils.IMEUtil;
@@ -184,7 +185,6 @@ public class Suggest implements Dictionary.WordCallback {
* Number of suggestions to generate from the input key sequence. This has
* to be a number between 1 and 100 (inclusive).
*
- * @param maxSuggestions
* @throws IllegalArgumentException if the number is out of range
*/
public void setMaxSuggestions(int maxSuggestions) {
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/UserDictionary.java b/src/main/java/com/anysoftkeyboard/dictionaries/UserDictionary.java
index fd4f7e466..216ce8799 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/UserDictionary.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/UserDictionary.java
@@ -17,7 +17,10 @@
package com.anysoftkeyboard.dictionaries;
import android.content.Context;
-import com.anysoftkeyboard.WordComposer;
+
+import com.anysoftkeyboard.base.dictionaries.EditableDictionary;
+import com.anysoftkeyboard.base.dictionaries.WordComposer;
+import com.anysoftkeyboard.base.dictionaries.WordsCursor;
import com.anysoftkeyboard.dictionaries.content.AndroidUserDictionary;
import com.anysoftkeyboard.dictionaries.sqlite.FallbackUserDictionary;
import com.anysoftkeyboard.utils.Log;
@@ -46,10 +49,7 @@ public class UserDictionary extends EditableDictionary {
@Override
public final boolean isValidWord(CharSequence word) {
- if (mActualDictionary != null)
- return mActualDictionary.isValidWord(word);
- else
- return false;
+ return mActualDictionary != null && mActualDictionary.isValidWord(word);
}
@Override
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/WordsCursor.java b/src/main/java/com/anysoftkeyboard/dictionaries/WordsCursor.java
deleted file mode 100644
index 8ea6096d9..000000000
--- a/src/main/java/com/anysoftkeyboard/dictionaries/WordsCursor.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2013 Menny Even-Danan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.anysoftkeyboard.dictionaries;
-
-import android.database.Cursor;
-import android.database.sqlite.SQLiteDatabase;
-
-public class WordsCursor {
- private final Cursor mCursor;
-
- public WordsCursor(Cursor cursor) {
- mCursor = cursor;
- }
-
- public Cursor getCursor() {
- return mCursor;
- }
-
- public void close() {
- if (!mCursor.isClosed()) mCursor.close();
- }
-
- public int getCurrentWordId() {
- return mCursor.getInt(0);
- }
-
- public String getCurrentWord() {
- return mCursor.getString(1);
- }
- public int getCurrentWordFrequency() {
- return mCursor.getInt(2);
- }
-
- public static class SqliteWordsCursor extends WordsCursor {
- private final SQLiteDatabase mDb;
-
- public SqliteWordsCursor(SQLiteDatabase db, Cursor cursor) {
- super(cursor);
- mDb = db;
- }
-
- @Override
- public void close() {
- super.close();
- if (mDb.isOpen())
- mDb.close();
- }
- }
-} \ No newline at end of file
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/content/AndroidUserDictionary.java b/src/main/java/com/anysoftkeyboard/dictionaries/content/AndroidUserDictionary.java
index ecf2cab2a..e34544e2a 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/content/AndroidUserDictionary.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/content/AndroidUserDictionary.java
@@ -24,8 +24,9 @@ import android.database.Cursor;
import android.net.Uri;
import android.provider.UserDictionary.Words;
import android.text.TextUtils;
+
+import com.anysoftkeyboard.base.dictionaries.WordsCursor;
import com.anysoftkeyboard.dictionaries.BTreeDictionary;
-import com.anysoftkeyboard.dictionaries.WordsCursor;
import com.anysoftkeyboard.utils.Log;
public class AndroidUserDictionary extends BTreeDictionary {
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/content/ContactsDictionary.java b/src/main/java/com/anysoftkeyboard/dictionaries/content/ContactsDictionary.java
index c475bd483..d129c3cf1 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/content/ContactsDictionary.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/content/ContactsDictionary.java
@@ -23,8 +23,8 @@ import android.database.ContentObserver;
import android.database.Cursor;
import android.provider.ContactsContract.Contacts;
+import com.anysoftkeyboard.base.dictionaries.WordsCursor;
import com.anysoftkeyboard.dictionaries.BTreeDictionary;
-import com.anysoftkeyboard.dictionaries.WordsCursor;
@TargetApi(7)
public class ContactsDictionary extends BTreeDictionary {
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/jni/BinaryDictionary.java b/src/main/java/com/anysoftkeyboard/dictionaries/jni/BinaryDictionary.java
index ea5b51ad9..85b0d2a74 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/jni/BinaryDictionary.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/jni/BinaryDictionary.java
@@ -17,8 +17,9 @@
package com.anysoftkeyboard.dictionaries.jni;
import android.content.res.AssetFileDescriptor;
-import com.anysoftkeyboard.WordComposer;
-import com.anysoftkeyboard.dictionaries.Dictionary;
+
+import com.anysoftkeyboard.base.dictionaries.Dictionary;
+import com.anysoftkeyboard.base.dictionaries.WordComposer;
import com.anysoftkeyboard.utils.Log;
import java.io.FileDescriptor;
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/jni/ResourceBinaryDictionary.java b/src/main/java/com/anysoftkeyboard/dictionaries/jni/ResourceBinaryDictionary.java
index 5f0f32a7c..aac12670c 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/jni/ResourceBinaryDictionary.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/jni/ResourceBinaryDictionary.java
@@ -20,8 +20,8 @@ import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
-import com.anysoftkeyboard.WordComposer;
-import com.anysoftkeyboard.dictionaries.Dictionary;
+import com.anysoftkeyboard.base.dictionaries.Dictionary;
+import com.anysoftkeyboard.base.dictionaries.WordComposer;
import com.anysoftkeyboard.utils.IMEUtil.GCUtils;
import com.anysoftkeyboard.utils.IMEUtil.GCUtils.MemRelatedOperation;
import com.anysoftkeyboard.utils.Log;
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/AbbreviationsDictionary.java b/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/AbbreviationsDictionary.java
index 61f131ec3..0c48cfd0b 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/AbbreviationsDictionary.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/AbbreviationsDictionary.java
@@ -18,13 +18,10 @@ package com.anysoftkeyboard.dictionaries.sqlite;
import android.content.Context;
import android.support.annotation.NonNull;
-import android.text.TextUtils;
-import com.anysoftkeyboard.WordComposer;
-import com.anysoftkeyboard.dictionaries.Dictionary;
+import com.anysoftkeyboard.base.dictionaries.WordComposer;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/AutoDictionary.java b/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/AutoDictionary.java
index 23cb60130..06a70ed2f 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/AutoDictionary.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/AutoDictionary.java
@@ -18,7 +18,7 @@ package com.anysoftkeyboard.dictionaries.sqlite;
import android.content.Context;
import com.anysoftkeyboard.AnySoftKeyboard;
-import com.anysoftkeyboard.WordComposer;
+import com.anysoftkeyboard.base.dictionaries.WordComposer;
import com.anysoftkeyboard.utils.Log;
import com.menny.android.anysoftkeyboard.AnyApplication;
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/SQLiteUserDictionaryBase.java b/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/SQLiteUserDictionaryBase.java
index f438cef10..c19fa5355 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/SQLiteUserDictionaryBase.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/SQLiteUserDictionaryBase.java
@@ -20,8 +20,9 @@ import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.database.sqlite.SQLiteException;
+
+import com.anysoftkeyboard.base.dictionaries.WordsCursor;
import com.anysoftkeyboard.dictionaries.BTreeDictionary;
-import com.anysoftkeyboard.dictionaries.WordsCursor;
import com.anysoftkeyboard.utils.Log;
public abstract class SQLiteUserDictionaryBase extends BTreeDictionary {
diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/WordsSQLiteConnection.java b/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/WordsSQLiteConnection.java
index a80a1ba95..cf708d250 100644
--- a/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/WordsSQLiteConnection.java
+++ b/src/main/java/com/anysoftkeyboard/dictionaries/sqlite/WordsSQLiteConnection.java
@@ -22,7 +22,8 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;
-import com.anysoftkeyboard.dictionaries.WordsCursor;
+
+import com.anysoftkeyboard.base.dictionaries.WordsCursor;
import com.anysoftkeyboard.utils.Log;
public class WordsSQLiteConnection extends SQLiteOpenHelper {
@@ -128,8 +129,6 @@ public class WordsSQLiteConnection extends SQLiteOpenHelper {
/**
* This is a compatibility function: SQLiteOpenHelper.getDatabaseName exists only in API14
- *
- * @return
*/
public String getDbFilename() {
return mDbName;
diff --git a/src/main/java/com/anysoftkeyboard/spellcheck/SuggestionsGatherer.java b/src/main/java/com/anysoftkeyboard/spellcheck/SuggestionsGatherer.java
index a1e0e17b4..ad1a93f46 100644
--- a/src/main/java/com/anysoftkeyboard/spellcheck/SuggestionsGatherer.java
+++ b/src/main/java/com/anysoftkeyboard/spellcheck/SuggestionsGatherer.java
@@ -16,8 +16,7 @@
package com.anysoftkeyboard.spellcheck;
-import com.anysoftkeyboard.dictionaries.Dictionary;
-import com.anysoftkeyboard.dictionaries.Dictionary.WordCallback;
+import com.anysoftkeyboard.base.dictionaries.Dictionary;
import com.anysoftkeyboard.utils.ArraysCompatUtils;
import com.anysoftkeyboard.utils.IMEUtil;
import com.anysoftkeyboard.utils.Log;
@@ -25,7 +24,7 @@ import com.anysoftkeyboard.utils.Log;
import java.util.ArrayList;
import java.util.Collections;
-class SuggestionsGatherer implements WordCallback {
+class SuggestionsGatherer implements Dictionary.WordCallback {
public static class Result {
public final String[] mSuggestions;
public final boolean mHasLikelySuggestions;
diff --git a/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/AbbreviationDictionaryEditorFragment.java b/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/AbbreviationDictionaryEditorFragment.java
index 0aea58667..84f2aeda0 100644
--- a/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/AbbreviationDictionaryEditorFragment.java
+++ b/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/AbbreviationDictionaryEditorFragment.java
@@ -9,7 +9,7 @@ import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
-import com.anysoftkeyboard.dictionaries.EditableDictionary;
+import com.anysoftkeyboard.base.dictionaries.EditableDictionary;
import com.anysoftkeyboard.dictionaries.sqlite.AbbreviationsDictionary;
import com.menny.android.anysoftkeyboard.R;
diff --git a/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/BackupUserWordsAsyncTask.java b/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/BackupUserWordsAsyncTask.java
index e19bd954c..a5f1cfec5 100644
--- a/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/BackupUserWordsAsyncTask.java
+++ b/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/BackupUserWordsAsyncTask.java
@@ -23,8 +23,8 @@ import android.provider.UserDictionary.Words;
import android.text.TextUtils;
import android.widget.Toast;
+import com.anysoftkeyboard.base.dictionaries.WordsCursor;
import com.anysoftkeyboard.dictionaries.UserDictionary;
-import com.anysoftkeyboard.dictionaries.WordsCursor;
import com.anysoftkeyboard.utils.Log;
import com.anysoftkeyboard.utils.XmlWriter;
import com.menny.android.anysoftkeyboard.R;
diff --git a/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/RestoreUserWordsAsyncTask.java b/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/RestoreUserWordsAsyncTask.java
index 8204973db..a05195332 100644
--- a/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/RestoreUserWordsAsyncTask.java
+++ b/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/RestoreUserWordsAsyncTask.java
@@ -39,6 +39,7 @@ import javax.xml.parsers.SAXParserFactory;
final class RestoreUserWordsAsyncTask extends UserWordsEditorAsyncTask {
protected static final String TAG = "ASK RestoreUDict";
+ private final Object mLoadMonitor = new Object();
private final Context mAppContext;
private final String mFilename;
private String mLocale;
@@ -87,9 +88,8 @@ final class RestoreUserWordsAsyncTask extends UserWordsEditorAsyncTask {
if (localName.equals("wordlist")) {
mLocale = attributes.getValue("locale");
- synchronized (mLocale) {
- Log.d(TAG, "Building dictionary for locale "
- + mLocale);
+ synchronized (mLoadMonitor) {
+ Log.d(TAG, "Building dictionary for locale " + mLocale);
publishProgress();
// waiting for dictionary to be ready.
try {
@@ -127,7 +127,7 @@ final class RestoreUserWordsAsyncTask extends UserWordsEditorAsyncTask {
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
- synchronized (mLocale) {
+ synchronized (mLoadMonitor) {
if (mDictionary != null) {
mDictionary.close();
}
@@ -166,7 +166,7 @@ final class RestoreUserWordsAsyncTask extends UserWordsEditorAsyncTask {
activity.fillLanguagesSpinner();
} catch (BadTokenException e) {
// activity gone away!
- // nevermind
+ // never mind
}
}
} \ No newline at end of file
diff --git a/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/UserDictionaryEditorFragment.java b/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/UserDictionaryEditorFragment.java
index f000891f9..dc8aa26d0 100644
--- a/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/UserDictionaryEditorFragment.java
+++ b/src/main/java/com/anysoftkeyboard/ui/settings/wordseditor/UserDictionaryEditorFragment.java
@@ -40,9 +40,9 @@ import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
-import com.anysoftkeyboard.dictionaries.EditableDictionary;
+import com.anysoftkeyboard.base.dictionaries.EditableDictionary;
+import com.anysoftkeyboard.base.dictionaries.WordsCursor;
import com.anysoftkeyboard.dictionaries.UserDictionary;
-import com.anysoftkeyboard.dictionaries.WordsCursor;
import com.anysoftkeyboard.keyboards.KeyboardAddOnAndBuilder;
import com.anysoftkeyboard.keyboards.KeyboardFactory;
import com.anysoftkeyboard.utils.Log;