aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java18
-rw-r--r--java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java1
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java41
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java25
5 files changed, 73 insertions, 16 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index d5bd7fda3..4a9135310 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -662,10 +662,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
hintY = -mFontMetrics.top + params.mKeyShiftedLetterHintPadding;
paint.setTextAlign(Align.CENTER);
} else { // key.hasHintLetter()
- // The hint label is placed at top-right corner of the key. Used mainly on phone.
+ // The hint letter is placed at top-right corner of the key. Used mainly on phone.
hintX = keyWidth - params.mKeyHintLetterPadding
- getCharWidth(KEY_NUMERIC_HINT_LABEL_REFERENCE_CHAR, paint) / 2;
- hintY = -paint.ascent() + params.mKeyHintLetterPadding;
+ hintY = -paint.ascent();
paint.setTextAlign(Align.CENTER);
}
canvas.drawText(hint, 0, hint.length(), hintX, hintY, paint);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java
index d0f27a9a8..9dc1786c7 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java
@@ -25,7 +25,23 @@ import java.util.HashMap;
/**
* !!!!! DO NOT EDIT THIS FILE !!!!!
- * This file is generated by tools/maketext.
+ *
+ * This file is generated by tools/maketext. The base template file is
+ * tools/maketext/res/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.tmpl
+ *
+ * This file must be updated when any text resources in keyboard layout files have been changed.
+ * These text resources are referred as "!text/<resource_name>" in keyboard XML definitions,
+ * and should be defined in
+ * tools/maketext/res/values-<locale>/donottranslate-more-keys.xml
+ *
+ * To update this file, please run the following commands.
+ * $ cd $ANDROID_BUILD_TOP
+ * $ mmm packages/inputmethods/LatinIME/tools/maketext
+ * $ maketext -java packages/inputmethods/LatinIME/java/src
+ *
+ * The updated source file will be generated to the following path (this file).
+ * packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/internal/
+ * KeyboardTextsSet.java
*/
public final class KeyboardTextsSet {
// Language to texts map.
diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
index 613c20304..994b917a7 100644
--- a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
+++ b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
@@ -366,6 +366,7 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
final Preference pref = mSubtypePrefGroup.getPreference(i);
if (pref instanceof SubtypePreference) {
final InputMethodSubtype subtype = ((SubtypePreference)pref).getSubtype();
+ if (subtype == null) continue;
if (sb.length() > 0) {
sb.append(AdditionalSubtype.PREF_SUBTYPE_SEPARATOR);
}
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
index 97df98e34..cc98010fb 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
@@ -174,6 +174,13 @@ public class BinaryDictInputOutput {
private static final int MAX_TERMINAL_FREQUENCY = 255;
+ // Arbitrary limit to how much passes we consider address size compression should
+ // terminate in. At the time of this writing, our largest dictionary completes
+ // compression in five passes.
+ // If the number of passes exceeds this number, makedict bails with an exception on
+ // suspicion that a bug might be causing an infinite loop.
+ private static final int MAX_PASSES = 24;
+
/**
* A class grouping utility function for our specific character encoding.
*/
@@ -510,14 +517,22 @@ public class BinaryDictInputOutput {
* Each node stores its tentative address. During dictionary address computing, these
* are not final, but they can be used to compute the node size (the node size depends
* on the address of the children because the number of bytes necessary to store an
- * address depends on its numeric value.
+ * address depends on its numeric value. The return value indicates whether the node
+ * contents (as in, any of the addresses stored in the cache fields) have changed with
+ * respect to their previous value.
*
* @param node the node to compute the size of.
* @param dict the dictionary in which the word/attributes are to be found.
+ * @return false if none of the cached addresses inside the node changed, true otherwise.
*/
- private static void computeActualNodeSize(Node node, FusionDictionary dict) {
+ private static boolean computeActualNodeSize(Node node, FusionDictionary dict) {
+ boolean changed = false;
int size = getGroupCountSize(node);
for (CharGroup group : node.mData) {
+ if (group.mCachedAddress != node.mCachedAddress + size) {
+ changed = true;
+ group.mCachedAddress = node.mCachedAddress + size;
+ }
int groupSize = GROUP_FLAGS_SIZE + getGroupCharactersSize(group);
if (group.isTerminal()) groupSize += GROUP_FREQUENCY_SIZE;
if (null != group.mChildren) {
@@ -538,7 +553,11 @@ public class BinaryDictInputOutput {
group.mCachedSize = groupSize;
size += groupSize;
}
- node.mCachedSize = size;
+ if (node.mCachedSize != size) {
+ node.mCachedSize = size;
+ changed = true;
+ }
+ return changed;
}
/**
@@ -594,13 +613,14 @@ public class BinaryDictInputOutput {
changesDone = false;
for (Node n : flatNodes) {
final int oldNodeSize = n.mCachedSize;
- computeActualNodeSize(n, dict);
+ final boolean changed = computeActualNodeSize(n, dict);
final int newNodeSize = n.mCachedSize;
if (oldNodeSize < newNodeSize) throw new RuntimeException("Increased size ?!");
- if (oldNodeSize != newNodeSize) changesDone = true;
+ changesDone |= changed;
}
stackNodes(flatNodes);
++passes;
+ if (passes > MAX_PASSES) throw new RuntimeException("Too many passes - probably a bug");
} while (changesDone);
final Node lastNode = flatNodes.get(flatNodes.size() - 1);
@@ -1122,6 +1142,12 @@ public class BinaryDictInputOutput {
}
}
+ // The word cache here is a stopgap bandaid to help the catastrophic performance
+ // of this method. Since it performs direct, unbuffered random access to the file and
+ // may be called hundreds of thousands of times, the resulting performance is not
+ // reasonable without some kind of cache. Thus:
+ // TODO: perform buffered I/O here and in other places in the code.
+ private static TreeMap<Integer, String> wordCache = new TreeMap<Integer, String>();
/**
* Finds, as a string, the word at the address passed as an argument.
*
@@ -1131,8 +1157,10 @@ public class BinaryDictInputOutput {
* @return the word, as a string.
* @throws IOException if the file can't be read.
*/
- private static String getWordAtAddress(RandomAccessFile source, long headerSize,
+ private static String getWordAtAddress(final RandomAccessFile source, final long headerSize,
int address) throws IOException {
+ final String cachedString = wordCache.get(address);
+ if (null != cachedString) return cachedString;
final long originalPointer = source.getFilePointer();
source.seek(headerSize);
final int count = readCharGroupCount(source);
@@ -1171,6 +1199,7 @@ public class BinaryDictInputOutput {
}
}
source.seek(originalPointer);
+ wordCache.put(address, result);
return result;
}
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
index a17371396..26a9415c4 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
@@ -171,7 +171,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
public boolean mMoreSuggestionsAvailable;
- public final TextView mWordToSaveView;
+ private final TextView mWordToSaveView;
private final TextView mLeftwardsArrowView;
private final TextView mHintToSaveView;
@@ -477,7 +477,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
}
public void layoutAddToDictionaryHint(CharSequence word, ViewGroup stripView,
- int stripWidth, CharSequence hintText) {
+ int stripWidth, CharSequence hintText, OnClickListener listener) {
final int width = stripWidth - mDividerWidth - mPadding * 2;
final TextView wordView = mWordToSaveView;
@@ -508,6 +508,18 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
stripView.addView(hintView);
setLayoutWeight(
hintView, 1.0f - mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT);
+
+ wordView.setOnClickListener(listener);
+ leftArrowView.setOnClickListener(listener);
+ hintView.setOnClickListener(listener);
+ }
+
+ public CharSequence getAddToDictionaryWord() {
+ return (CharSequence)mWordToSaveView.getTag();
+ }
+
+ public boolean isAddToDictionaryShowing(View v) {
+ return v == mWordToSaveView || v == mHintToSaveView || v == mLeftwardsArrowView;
}
private static void setLayoutWeight(View v, float weight, int height) {
@@ -620,7 +632,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
}
mParams = new SuggestionsViewParams(context, attrs, defStyle, mWords, mDividers, mInfos);
- mParams.mWordToSaveView.setOnClickListener(this);
mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null);
mMoreSuggestionsView = (MoreSuggestionsView)mMoreSuggestionsContainer
@@ -676,12 +687,12 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
public boolean isShowingAddToDictionaryHint() {
return mSuggestionsStrip.getChildCount() > 0
- && mSuggestionsStrip.getChildAt(0) == mParams.mWordToSaveView;
+ && mParams.isAddToDictionaryShowing(mSuggestionsStrip.getChildAt(0));
}
public void showAddToDictionaryHint(CharSequence word, CharSequence hintText) {
clear();
- mParams.layoutAddToDictionaryHint(word, mSuggestionsStrip, getWidth(), hintText);
+ mParams.layoutAddToDictionaryHint(word, mSuggestionsStrip, getWidth(), hintText, this);
}
public boolean dismissAddToDictionaryHint() {
@@ -851,8 +862,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
@Override
public void onClick(View view) {
- if (view == mParams.mWordToSaveView) {
- addToDictionary((CharSequence)view.getTag());
+ if (mParams.isAddToDictionaryShowing(view)) {
+ addToDictionary(mParams.getAddToDictionaryWord());
clear();
return;
}