diff options
| author | Menny Even Danan <menny@evendanan.net> | 2016-02-15 03:31:48 +0000 |
|---|---|---|
| committer | Menny Even Danan <menny@evendanan.net> | 2016-02-15 03:37:54 +0000 |
| commit | 07b85016ffff09ea85089bdf8f80514a1ccf0362 (patch) | |
| tree | 8ca0f4f6256fff5882c6565738090d5e21a9bcb5 /src | |
| parent | c134871c2d3e0b764b686f3775169d8529d1da60 (diff) | |
| download | AnySoftKeyboard-07b85016ffff09ea85089bdf8f80514a1ccf0362.tar.gz AnySoftKeyboard-07b85016ffff09ea85089bdf8f80514a1ccf0362.tar.bz2 | |
fixing a few lint issues
Diffstat (limited to 'src')
10 files changed, 25 insertions, 341 deletions
diff --git a/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java b/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java index 2531547c7..cc815de20 100644 --- a/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java +++ b/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java @@ -109,7 +109,7 @@ import java.util.Set; /** * Input method implementation for QWERTY-ish keyboard. */ -public class AnySoftKeyboard extends InputMethodService implements +public abstract class AnySoftKeyboard extends InputMethodService implements OnKeyboardActionListener, OnSharedPreferenceChangeListener, AnyKeyboardContextProvider, SoundPreferencesChangedListener { diff --git a/src/main/java/com/anysoftkeyboard/dictionaries/BTreeDictionary.java b/src/main/java/com/anysoftkeyboard/dictionaries/BTreeDictionary.java index 27568bac4..a7425f001 100644 --- a/src/main/java/com/anysoftkeyboard/dictionaries/BTreeDictionary.java +++ b/src/main/java/com/anysoftkeyboard/dictionaries/BTreeDictionary.java @@ -429,8 +429,6 @@ public abstract class BTreeDictionary extends EditableDictionary { } public void deleteNode(int nodeIndexToDelete) { - assert length >= 0; - length--; if (length > 0) { for (int i = nodeIndexToDelete; i < length; i++) { diff --git a/src/main/java/com/anysoftkeyboard/keyboards/KeyEventStateMachine.java b/src/main/java/com/anysoftkeyboard/keyboards/KeyEventStateMachine.java index b31df5267..5fdc0a46e 100644 --- a/src/main/java/com/anysoftkeyboard/keyboards/KeyEventStateMachine.java +++ b/src/main/java/com/anysoftkeyboard/keyboards/KeyEventStateMachine.java @@ -73,7 +73,7 @@ public class KeyEventStateMachine { private KeyEventState start; - public static enum State {RESET, REWIND, NO_MATCH, PART_MATCH, FULL_MATCH} + public enum State {RESET, REWIND, NO_MATCH, PART_MATCH, FULL_MATCH} private class NFAPart { @@ -158,7 +158,6 @@ public class KeyEventStateMachine { } NFAPart getItem() { - assert (this.count > 0); NFAPart result = this.buffer[this.start]; this.buffer[this.start] = null; this.start = (this.start + 1) % MAX_NFA_DIVIDES; @@ -167,7 +166,6 @@ public class KeyEventStateMachine { } void putItem(NFAPart item) { - assert (this.count < MAX_NFA_DIVIDES); this.buffer[this.end] = item; this.end = (this.end + 1) % MAX_NFA_DIVIDES; this.count++; @@ -216,13 +214,13 @@ public class KeyEventStateMachine { public void addSpecialKeySequence(int[] sequence, int specialKey, int result) { KeyEventState c = this.start; - for (int i = 0; i < sequence.length; i++) { + for (int aSequence : sequence) { if (specialKey != 0) { //special key first c = addNextState(c, specialKey); } //the sequence second - c = addNextState(c, sequence[i]); + c = addNextState(c, aSequence); } c.setCharacter(result); } diff --git a/src/main/java/com/anysoftkeyboard/keyboards/views/PointerTracker.java b/src/main/java/com/anysoftkeyboard/keyboards/views/PointerTracker.java index 7e5efaf87..d1cb8ec49 100644 --- a/src/main/java/com/anysoftkeyboard/keyboards/views/PointerTracker.java +++ b/src/main/java/com/anysoftkeyboard/keyboards/views/PointerTracker.java @@ -26,6 +26,8 @@ import com.anysoftkeyboard.keyboards.Keyboard.Key; import com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.UIHandler; import com.menny.android.anysoftkeyboard.AnyApplication; +import java.util.Locale; + public class PointerTracker { public static class SharedPointerTrackersData { public int lastSentKeyIndex = NOT_A_KEY; @@ -471,7 +473,7 @@ public class PointerTracker { if (isShifted && !TextUtils.isEmpty(anyKey.shiftedKeyLabel)) { return anyKey.shiftedKeyLabel; } else if (!TextUtils.isEmpty(anyKey.label)) { - return isShifted ? anyKey.label.toString().toUpperCase() : anyKey.label; + return isShifted ? anyKey.label.toString().toUpperCase(Locale.getDefault()) : anyKey.label; } else { return Character.toString(getMultiTapCode(key, isShifted)); } diff --git a/src/main/java/com/anysoftkeyboard/spellcheck/AnySpellCheckerService.java b/src/main/java/com/anysoftkeyboard/spellcheck/AnySpellCheckerService.java deleted file mode 100644 index c2cbb154a..000000000 --- a/src/main/java/com/anysoftkeyboard/spellcheck/AnySpellCheckerService.java +++ /dev/null @@ -1,144 +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.spellcheck; - -import android.annotation.TargetApi; -import android.os.Build; -import android.service.textservice.SpellCheckerService; -import android.text.TextUtils; -import android.view.textservice.SuggestionsInfo; -import android.view.textservice.TextInfo; - -import com.anysoftkeyboard.utils.Log; -import com.menny.android.anysoftkeyboard.FeaturesSet; - -/** - * Service for spell checking, using ASK dictionaries and mechanisms. - */ -@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) -public class AnySpellCheckerService extends SpellCheckerService { - static final String TAG = "ASK_SPELL"; - static final boolean DBG = FeaturesSet.DEBUG_LOG; - static final String[] EMPTY_STRING_ARRAY = new String[0]; - - - @Override - public void onCreate() { - super.onCreate(); - } - - @Override - public Session createSession() { - return new AnySpellCheckerSession(); - } - - private static SuggestionsInfo getNotInDictEmptySuggestions() { - return new SuggestionsInfo(0, EMPTY_STRING_ARRAY); - } - - private static SuggestionsInfo getInDictEmptySuggestions() { - return new SuggestionsInfo( - SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY, - EMPTY_STRING_ARRAY); - } - - private static class AnySpellCheckerSession extends Session { - - AnySpellCheckerSession() { - } - - /** - * Finds out whether a particular string should be filtered out of spell - * checking. - * <p/> - * This will loosely match URLs, numbers, symbols. - * - * @param text the string to evaluate. - * @return true if we should filter this text out, false otherwise - */ - private static boolean shouldFilterOut(final String text) { - if (TextUtils.isEmpty(text) || text.length() <= 1) - return true; - - // TODO: check if an equivalent processing can't be done more - // quickly with a - // compiled regexp. - // Filter by first letter - final int firstCodePoint = text.codePointAt(0); - // Filter out words that don't start with a letter or an apostrophe - if (!Character.isLetter(firstCodePoint) && '\'' != firstCodePoint) - return true; - - // Filter contents - final int length = text.length(); - int letterCount = 0; - for (int i = 0; i < length; ++i) { - final int codePoint = text.codePointAt(i); - // Any word containing a '@' is probably an e-mail address - // Any word containing a '/' is probably either an ad-hoc - // combination of two - // words or a URI - in either case we don't want to spell check - // that - if ('@' == codePoint || '/' == codePoint) - return true; - if (Character.isLetter(codePoint)) - ++letterCount; - } - // Guestimate heuristic: perform spell checking if at least 3/4 of - // the characters - // in this word are letters - return (letterCount * 4 < length * 3); - } - - // Note : this must be reentrant - - /** - * Gets a list of suggestions for a specific string. This returns a list - * of possible corrections for the text passed as an argument. It may - * split or group words, and even perform grammatical analysis. - */ - @Override - public SuggestionsInfo onGetSuggestions(final TextInfo textInfo, - final int suggestionsLimit) { - - try { - final String text = textInfo.getText(); - final boolean shouldFilterOut = shouldFilterOut(text); - - Log.d(TAG, "onGetSuggestions for '" + text - + "'. Should filter out? " + shouldFilterOut); - - if (!shouldFilterOut) { - //TODO: let's see if the word is in my dictionaries - } - return getNotInDictEmptySuggestions(); - } catch (RuntimeException e) { - Log.e(TAG, "Exception caught in ASK SpellChecker!"); - e.printStackTrace(); - if (DBG) - throw e;// in production crash the entire stack. Swallow it. - - - return getNotInDictEmptySuggestions(); - } - } - - @Override - public void onCreate() { - } - } -} diff --git a/src/main/java/com/anysoftkeyboard/spellcheck/SuggestionsGatherer.java b/src/main/java/com/anysoftkeyboard/spellcheck/SuggestionsGatherer.java deleted file mode 100644 index ad1a93f46..000000000 --- a/src/main/java/com/anysoftkeyboard/spellcheck/SuggestionsGatherer.java +++ /dev/null @@ -1,178 +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.spellcheck; - -import com.anysoftkeyboard.base.dictionaries.Dictionary; -import com.anysoftkeyboard.utils.ArraysCompatUtils; -import com.anysoftkeyboard.utils.IMEUtil; -import com.anysoftkeyboard.utils.Log; - -import java.util.ArrayList; -import java.util.Collections; - -class SuggestionsGatherer implements Dictionary.WordCallback { - public static class Result { - public final String[] mSuggestions; - public final boolean mHasLikelySuggestions; - - public Result(final String[] gatheredSuggestions, final boolean hasLikelySuggestions) { - mSuggestions = gatheredSuggestions; - mHasLikelySuggestions = hasLikelySuggestions; - } - } - - private final ArrayList<CharSequence> mSuggestions; - private final int[] mScores; - private final String mOriginalText; - private final double mSuggestionThreshold; - private final double mLikelyThreshold; - private final int mMaxLength; - private int mLength = 0; - - // The two following attributes are only ever filled if the requested max length - // is 0 (or less, which is treated the same). - private String mBestSuggestion = null; - private int mBestScore = Integer.MIN_VALUE; // As small as possible - - SuggestionsGatherer(final String originalText, final double suggestionThreshold, - final double likelyThreshold, final int maxLength) { - mOriginalText = originalText; - mSuggestionThreshold = suggestionThreshold; - mLikelyThreshold = likelyThreshold; - mMaxLength = maxLength; - mSuggestions = new ArrayList<>(maxLength + 1); - mScores = new int[mMaxLength]; - } - - @Override - public boolean addWord(char[] word, int wordOffset, int wordLength, - int frequency, Dictionary dictionary) { - final int positionIndex = ArraysCompatUtils.binarySearch(mScores, 0, mLength, frequency); - // binarySearch returns the index if the element exists, and -<insertion index> - 1 - // if it doesn't. See documentation for binarySearch. - final int insertIndex = positionIndex >= 0 ? positionIndex : -positionIndex - 1; - - if (insertIndex == 0 && mLength >= mMaxLength) { - // In the future, we may want to keep track of the best suggestion score even if - // we are asked for 0 suggestions. In this case, we can use the following - // (tested) code to keep it: - // If the maxLength is 0 (should never be less, but if it is, it's treated as 0) - // then we need to keep track of the best suggestion in mBestScore and - // mBestSuggestion. This is so that we know whether the best suggestion makes - // the score cutoff, since we need to know that to return a meaningful - // looksLikeTypo. - // if (0 >= mMaxLength) { - // if (score > mBestScore) { - // mBestScore = score; - // mBestSuggestion = new String(word, wordOffset, wordLength); - // } - // } - return true; - } - if (insertIndex >= mMaxLength) { - // We found a suggestion, but its score is too weak to be kept considering - // the suggestion limit. - return true; - } - - // Compute the normalized score and skip this word if it's normalized score does not - // make the threshold. - final String wordString = new String(word, wordOffset, wordLength); - final double normalizedScore = - IMEUtil.calcNormalizedScore(mOriginalText, wordString, frequency); - if (normalizedScore < mSuggestionThreshold) { - if (AnySpellCheckerService.DBG) - Log.i(AnySpellCheckerService.TAG, wordString + " does not make the score threshold"); - return true; - } - - if (mLength < mMaxLength) { - final int copyLen = mLength - insertIndex; - ++mLength; - System.arraycopy(mScores, insertIndex, mScores, insertIndex + 1, copyLen); - mSuggestions.add(insertIndex, wordString); - } else { - System.arraycopy(mScores, 1, mScores, 0, insertIndex); - mSuggestions.add(insertIndex, wordString); - mSuggestions.remove(0); - } - mScores[insertIndex] = frequency; - - return true; - } - - public SuggestionsGatherer.Result getResults(final int capitalizeType) { - final String[] gatheredSuggestions; - final boolean hasLikelySuggestions; - if (0 == mLength) { - // Either we found no suggestions, or we found some BUT the max length was 0. - // If we found some mBestSuggestion will not be null. If it is null, then - // we found none, regardless of the max length. - if (null == mBestSuggestion) { - gatheredSuggestions = null; - hasLikelySuggestions = false; - } else { - gatheredSuggestions = AnySpellCheckerService.EMPTY_STRING_ARRAY; - final double normalizedScore = - IMEUtil.calcNormalizedScore(mOriginalText, mBestSuggestion, mBestScore); - hasLikelySuggestions = (normalizedScore > mLikelyThreshold); - } - } else { - if (AnySpellCheckerService.DBG) { - if (mLength != mSuggestions.size()) { - Log.e(AnySpellCheckerService.TAG, "Suggestion size is not the same as stored mLength"); - } - for (int i = mLength - 1; i >= 0; --i) { - Log.i(AnySpellCheckerService.TAG, "" + mScores[i] + " " + mSuggestions.get(i)); - } - } - Collections.reverse(mSuggestions); - IMEUtil.removeDupes(mSuggestions); - /* - if (CAPITALIZE_ALL == capitalizeType) { - for (int i = 0; i < mSuggestions.size(); ++i) { - // get(i) returns a CharSequence which is actually a String so .toString() - // should return the same object. - mSuggestions.set(i, mSuggestions.get(i).toString().toUpperCase(locale)); - } - } else if (CAPITALIZE_FIRST == capitalizeType) { - for (int i = 0; i < mSuggestions.size(); ++i) { - // Likewise - mSuggestions.set(i, Utils.toTitleCase(mSuggestions.get(i).toString(), - locale)); - } - } - */ - // This returns a String[], while toArray() returns an Object[] which cannot be cast - // into a String[]. - gatheredSuggestions = mSuggestions.toArray(AnySpellCheckerService.EMPTY_STRING_ARRAY); - - final int bestScore = mScores[mLength - 1]; - final CharSequence bestSuggestion = mSuggestions.get(0); - final double normalizedScore = - IMEUtil.calcNormalizedScore(mOriginalText, bestSuggestion, bestScore); - hasLikelySuggestions = (normalizedScore > mLikelyThreshold); - if (AnySpellCheckerService.DBG) { - Log.i(AnySpellCheckerService.TAG, "Best suggestion : " + bestSuggestion + ", score " + bestScore); - Log.i(AnySpellCheckerService.TAG, "Normalized score = " + normalizedScore - + " (threshold " + mLikelyThreshold - + ") => hasLikelySuggestions = " + hasLikelySuggestions); - } - } - return new Result(gatheredSuggestions, hasLikelySuggestions); - } -}
\ No newline at end of file diff --git a/src/main/res/layout/addon_store_search_pref.xml b/src/main/res/layout/addon_store_search_pref.xml index 94d85e2ac..e3b61a651 100644 --- a/src/main/res/layout/addon_store_search_pref.xml +++ b/src/main/res/layout/addon_store_search_pref.xml @@ -1,4 +1,5 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" android:id="@+id/addon_list_item_layout" android:layout_width="match_parent" android:layout_height="wrap_content" @@ -8,7 +9,8 @@ android:layout_marginTop="6dp" android:minHeight="44dp" android:animateLayoutChanges="true" - android:gravity="center"> + android:gravity="center" + tools:ignore="UnusedAttribute"> <TextView style="@style/Ask.Text.SubTitle" @@ -19,6 +21,7 @@ android:layout_gravity="center" android:text="@string/search_market_for_addons" android:drawableLeft="@drawable/ic_action_search" + android:drawableStart="@drawable/ic_action_search" android:drawablePadding="8dp"/> <TextView diff --git a/src/main/res/layout/send_crash_log_ui.xml b/src/main/res/layout/send_crash_log_ui.xml index 12ce64376..149657f32 100644 --- a/src/main/res/layout/send_crash_log_ui.xml +++ b/src/main/res/layout/send_crash_log_ui.xml @@ -1,12 +1,14 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_margin="8dp" - android:weightSum="1" - android:animateLayoutChanges="true"> + xmlns:tools="http://schemas.android.com/tools" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_margin="8dp" + android:weightSum="1" + android:animateLayoutChanges="true" + tools:ignore="UnusedAttribute"> <TextView android:layout_width="match_parent" @@ -81,6 +83,7 @@ android:layout_height="match_parent" android:text="@string/ime_crashed_send_button" android:drawableRight="@drawable/ic_accept" + android:drawableEnd="@drawable/ic_accept" android:drawablePadding="4dp" android:onClick="onSendCrashReport" /> diff --git a/src/test/java/com/anysoftkeyboard/AnySoftKeyboardTest.java b/src/test/java/com/anysoftkeyboard/AnySoftKeyboardTest.java index 121c61f27..3367e8f51 100644 --- a/src/test/java/com/anysoftkeyboard/AnySoftKeyboardTest.java +++ b/src/test/java/com/anysoftkeyboard/AnySoftKeyboardTest.java @@ -9,6 +9,7 @@ import com.anysoftkeyboard.keyboards.views.AnyKeyboardView; import com.anysoftkeyboard.keyboards.views.CandidateView; import com.menny.android.anysoftkeyboard.AskGradleTestRunner; import com.menny.android.anysoftkeyboard.R; +import com.menny.android.anysoftkeyboard.SoftKeyboard; import org.junit.After; import org.junit.Assert; @@ -23,11 +24,11 @@ import org.robolectric.util.ServiceController; @RunWith(AskGradleTestRunner.class) public class AnySoftKeyboardTest { - private ServiceController<AnySoftKeyboard> mAnySoftKeyboardUnderTest; + private ServiceController<SoftKeyboard> mAnySoftKeyboardUnderTest; @Before public void setUp() throws Exception { - mAnySoftKeyboardUnderTest = Robolectric.buildService(AnySoftKeyboard.class); + mAnySoftKeyboardUnderTest = Robolectric.buildService(SoftKeyboard.class); } @After diff --git a/src/test/java/com/anysoftkeyboard/TestableAnySoftKeyboard.java b/src/test/java/com/anysoftkeyboard/TestableAnySoftKeyboard.java index 2b584e682..852f7e9a4 100644 --- a/src/test/java/com/anysoftkeyboard/TestableAnySoftKeyboard.java +++ b/src/test/java/com/anysoftkeyboard/TestableAnySoftKeyboard.java @@ -27,6 +27,7 @@ import com.anysoftkeyboard.keyboards.KeyboardSwitcher; import com.anysoftkeyboard.keyboards.views.AnyKeyboardView; import com.anysoftkeyboard.keyboards.views.CandidateView; import com.menny.android.anysoftkeyboard.R; +import com.menny.android.anysoftkeyboard.SoftKeyboard; import org.junit.Assert; import org.mockito.Mockito; @@ -39,7 +40,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class TestableAnySoftKeyboard extends AnySoftKeyboard { +public class TestableAnySoftKeyboard extends SoftKeyboard { private Suggest mSpiedSuggest; private TestableKeyboardSwitcher mSpiedKeyboardSwitcher; |
