diff options
Diffstat (limited to '')
16 files changed, 66 insertions, 96 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 847174c0a..24eb7592b 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -99,7 +99,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // Main keyboard private Keyboard mKeyboard; - private final KeyDrawParams mKeyDrawParams; + protected final KeyDrawParams mKeyDrawParams; // Key preview private final int mKeyPreviewLayoutId; @@ -171,7 +171,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } } - /* package */ static class KeyDrawParams { + protected static class KeyDrawParams { // XML attributes public final int mKeyTextColor; public final int mKeyTextInactivatedColor; @@ -351,7 +351,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { mDelayAfterPreview = mKeyPreviewDrawParams.mLingerTimeout; mPaint.setAntiAlias(true); - mPaint.setTextAlign(Align.CENTER); } // Read fraction value in TypedArray as float. @@ -729,10 +728,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } } - private static int getCharGeometryCacheKey(char reference, Paint paint) { + private static int getCharGeometryCacheKey(char referenceChar, Paint paint) { final int labelSize = (int)paint.getTextSize(); final Typeface face = paint.getTypeface(); - final int codePointOffset = reference << 15; + final int codePointOffset = referenceChar << 15; if (face == Typeface.DEFAULT) { return codePointOffset + labelSize; } else if (face == Typeface.DEFAULT_BOLD) { @@ -747,41 +746,35 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // Working variable for the following methods. private final Rect mTextBounds = new Rect(); - private float getCharHeight(char[] character, Paint paint) { - final Integer key = getCharGeometryCacheKey(character[0], paint); + private float getCharHeight(char[] referenceChar, Paint paint) { + final Integer key = getCharGeometryCacheKey(referenceChar[0], paint); final Float cachedValue = sTextHeightCache.get(key); if (cachedValue != null) return cachedValue; - paint.getTextBounds(character, 0, 1, mTextBounds); + paint.getTextBounds(referenceChar, 0, 1, mTextBounds); final float height = mTextBounds.height(); sTextHeightCache.put(key, height); return height; } - private float getCharWidth(char[] character, Paint paint) { - final Integer key = getCharGeometryCacheKey(character[0], paint); + private float getCharWidth(char[] referenceChar, Paint paint) { + final Integer key = getCharGeometryCacheKey(referenceChar[0], paint); final Float cachedValue = sTextWidthCache.get(key); if (cachedValue != null) return cachedValue; - paint.getTextBounds(character, 0, 1, mTextBounds); + paint.getTextBounds(referenceChar, 0, 1, mTextBounds); final float width = mTextBounds.width(); sTextWidthCache.put(key, width); return width; } - protected float getLabelWidth(CharSequence label, Paint paint) { + public float getLabelWidth(String label, Paint paint) { paint.getTextBounds(label.toString(), 0, label.length(), mTextBounds); return mTextBounds.width(); } - public float getDefaultLabelWidth(String label, Paint paint) { - paint.setTextSize(mKeyDrawParams.mKeyLabelSize); - paint.setTypeface(mKeyDrawParams.mKeyTextStyle); - return getLabelWidth(label, paint); - } - protected static void drawIcon(Canvas canvas, Drawable icon, int x, int y, int width, int height) { canvas.translate(x, y); @@ -815,6 +808,14 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { canvas.translate(-x, -y); } + public Paint newDefaultLabelPaint() { + final Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setTypeface(mKeyDrawParams.mKeyTextStyle); + paint.setTextSize(mKeyDrawParams.mKeyLabelSize); + return paint; + } + public void cancelAllMessages() { mDrawingHandler.cancelAllMessages(); } diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java index 904a81de4..72a5d0f05 100644 --- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java @@ -296,17 +296,16 @@ public class MoreKeysKeyboard extends Keyboard { final int padding = (int)(view.getResources() .getDimension(R.dimen.more_keys_keyboard_key_horizontal_padding) + (parentKey.hasLabelsInMoreKeys() ? minKeyWidth * LABEL_PADDING_RATIO : 0)); - Paint paint = null; + final Paint paint = view.newDefaultLabelPaint(); + paint.setTextSize(parentKey.hasLabelsInMoreKeys() + ? view.mKeyDrawParams.mKeyLabelSize + : view.mKeyDrawParams.mKeyLetterSize); int maxWidth = minKeyWidth; for (String moreKeySpec : parentKey.mMoreKeys) { final String label = KeySpecParser.getLabel(moreKeySpec); // If the label is single letter, minKeyWidth is enough to hold the label. if (label != null && StringUtils.codePointCount(label) > 1) { - if (paint == null) { - paint = new Paint(); - paint.setAntiAlias(true); - } - final int width = (int)view.getDefaultLabelWidth(label, paint) + padding; + final int width = (int)view.getLabelWidth(label, paint) + padding; if (maxWidth < width) { maxWidth = width; } diff --git a/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java b/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java index 62a9259f9..347383f95 100644 --- a/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java +++ b/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java @@ -17,12 +17,12 @@ package com.android.inputmethod.keyboard; import android.content.Context; -import android.os.Build; import android.util.Log; import android.view.MotionEvent; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.Utils; public class SuddenJumpingTouchEventHandler { private static final String TAG = SuddenJumpingTouchEventHandler.class.getSimpleName(); @@ -49,18 +49,8 @@ public class SuddenJumpingTouchEventHandler { public SuddenJumpingTouchEventHandler(Context context, ProcessMotionEvent view) { mView = view; - final String[] deviceList = context.getResources().getStringArray( - R.array.sudden_jumping_touch_event_device_list); - mNeedsSuddenJumpingHack = needsSuddenJumpingHack(Build.HARDWARE, deviceList); - } - - private static boolean needsSuddenJumpingHack(String deviceName, String[] deviceList) { - for (String device : deviceList) { - if (device.equalsIgnoreCase(deviceName)) { - return true; - } - } - return false; + mNeedsSuddenJumpingHack = Boolean.parseBoolean(Utils.getDeviceOverrideValue( + context.getResources(), R.array.sudden_jumping_touch_event_device_list, "false")); } public void setKeyboard(Keyboard newKeyboard) { diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index 9ffc7d0a2..8ec440500 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -196,8 +196,8 @@ public class BinaryDictionaryFileDumper { } finally { // Ignore exceptions while closing files. try { - // afd.close() will close inputStream, we should not call inputStream.close(). - if (null != afd) afd.close(); + // inputStream.close() will close afd, we should not call afd.close(). + if (null != inputStream) inputStream.close(); } catch (Exception e) { Log.e(TAG, "Exception while closing a cross-process file descriptor : " + e); } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 9fc047b75..c1335fdfe 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -19,7 +19,6 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; -import android.os.Build; import android.util.Log; import android.view.inputmethod.EditorInfo; @@ -322,14 +321,8 @@ public class SettingsValues { return volume; } - final String[] volumePerHardwareList = res.getStringArray(R.array.keypress_volumes); - final String hardwarePrefix = Build.HARDWARE + ","; - for (final String element : volumePerHardwareList) { - if (element.startsWith(hardwarePrefix)) { - return Float.parseFloat(element.substring(element.lastIndexOf(',') + 1)); - } - } - return -1.0f; + return Float.parseFloat( + Utils.getDeviceOverrideValue(res, R.array.keypress_volumes, "-1.0f")); } // Likewise @@ -340,15 +333,9 @@ public class SettingsValues { if (ms >= 0) { return ms; } - final String[] durationPerHardwareList = res.getStringArray( - R.array.keypress_vibration_durations); - final String hardwarePrefix = Build.HARDWARE + ","; - for (final String element : durationPerHardwareList) { - if (element.startsWith(hardwarePrefix)) { - return (int)Long.parseLong(element.substring(element.lastIndexOf(',') + 1)); - } - } - return -1; + + return Integer.parseInt( + Utils.getDeviceOverrideValue(res, R.array.keypress_vibration_durations, "-1")); } // Likewise diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 35b4f12a8..a3589da0a 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -19,9 +19,11 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.res.Resources; import android.inputmethodservice.InputMethodService; import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.os.Environment; import android.os.Handler; import android.os.HandlerThread; @@ -45,6 +47,7 @@ import java.io.PrintWriter; import java.nio.channels.FileChannel; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; public class Utils { private Utils() { @@ -509,4 +512,23 @@ public class Utils { if (TextUtils.isEmpty(info)) return null; return info; } + + private static final String HARDWARE_PREFIX = Build.HARDWARE + ","; + private static final HashMap<Integer, String> sDeviceOverrideValueMap = + new HashMap<Integer, String>(); + + public static String getDeviceOverrideValue(Resources res, int overrideResId, String defValue) { + final Integer key = overrideResId; + if (!sDeviceOverrideValueMap.containsKey(key)) { + String overrideValue = defValue; + for (final String element : res.getStringArray(overrideResId)) { + if (element.startsWith(HARDWARE_PREFIX)) { + overrideValue = element.substring(HARDWARE_PREFIX.length()); + break; + } + } + sDeviceOverrideValueMap.put(key, overrideValue); + } + return sDeviceOverrideValueMap.get(key); + } } diff --git a/tools/makedict/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java index 42dd4df34..42dd4df34 100644 --- a/tools/makedict/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java diff --git a/tools/makedict/src/com/android/inputmethod/latin/makedict/CharGroupInfo.java b/java/src/com/android/inputmethod/latin/makedict/CharGroupInfo.java index 444b11732..444b11732 100644 --- a/tools/makedict/src/com/android/inputmethod/latin/makedict/CharGroupInfo.java +++ b/java/src/com/android/inputmethod/latin/makedict/CharGroupInfo.java diff --git a/java/src/com/android/inputmethod/latin/makedict/Dummy.java b/java/src/com/android/inputmethod/latin/makedict/Dummy.java deleted file mode 100644 index 27ea5ace6..000000000 --- a/java/src/com/android/inputmethod/latin/makedict/Dummy.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * 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.android.inputmethod.latin.makedict; - -public class Dummy { - -} diff --git a/tools/makedict/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java index d19672181..e88ab685a 100644 --- a/tools/makedict/src/com/android/inputmethod/latin/makedict/FusionDictionary.java +++ b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java @@ -21,7 +21,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; -import java.util.List; /** * A dictionary that can fusion heads and tails of words for more compression. @@ -400,16 +399,11 @@ public class FusionDictionary implements Iterable<Word> { * is ignored. * This comparator imposes orderings that are inconsistent with equals. */ - static private class CharGroupComparator implements java.util.Comparator { - public int compare(Object o1, Object o2) { - final CharGroup c1 = (CharGroup)o1; - final CharGroup c2 = (CharGroup)o2; + static private class CharGroupComparator implements java.util.Comparator<CharGroup> { + public int compare(CharGroup c1, CharGroup c2) { if (c1.mChars[0] == c2.mChars[0]) return 0; return c1.mChars[0] < c2.mChars[0] ? -1 : 1; } - public boolean equals(Object o) { - return o instanceof CharGroupComparator; - } } final static private CharGroupComparator CHARGROUP_COMPARATOR = new CharGroupComparator(); @@ -417,7 +411,7 @@ public class FusionDictionary implements Iterable<Word> { * Finds the insertion index of a character within a node. */ private static int findInsertionIndex(final Node node, int character) { - final List data = node.mData; + final ArrayList<CharGroup> data = node.mData; final CharGroup reference = new CharGroup(new int[] { character }, null, null, 0, false /* isShortcutOnly */); int result = Collections.binarySearch(data, reference, CHARGROUP_COMPARATOR); diff --git a/tools/makedict/src/com/android/inputmethod/latin/makedict/MakedictLog.java b/java/src/com/android/inputmethod/latin/makedict/MakedictLog.java index cff8d6fd0..cff8d6fd0 100644 --- a/tools/makedict/src/com/android/inputmethod/latin/makedict/MakedictLog.java +++ b/java/src/com/android/inputmethod/latin/makedict/MakedictLog.java diff --git a/tools/makedict/src/com/android/inputmethod/latin/makedict/PendingAttribute.java b/java/src/com/android/inputmethod/latin/makedict/PendingAttribute.java index 5b41d27f2..5b41d27f2 100644 --- a/tools/makedict/src/com/android/inputmethod/latin/makedict/PendingAttribute.java +++ b/java/src/com/android/inputmethod/latin/makedict/PendingAttribute.java diff --git a/tools/makedict/src/com/android/inputmethod/latin/makedict/UnsupportedFormatException.java b/java/src/com/android/inputmethod/latin/makedict/UnsupportedFormatException.java index bd42fb8fa..bd42fb8fa 100644 --- a/tools/makedict/src/com/android/inputmethod/latin/makedict/UnsupportedFormatException.java +++ b/java/src/com/android/inputmethod/latin/makedict/UnsupportedFormatException.java diff --git a/tools/makedict/src/com/android/inputmethod/latin/makedict/Word.java b/java/src/com/android/inputmethod/latin/makedict/Word.java index c2c01e1f8..c2c01e1f8 100644 --- a/tools/makedict/src/com/android/inputmethod/latin/makedict/Word.java +++ b/java/src/com/android/inputmethod/latin/makedict/Word.java diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java index 3a17f1f64..dd83a0c4e 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java @@ -23,7 +23,6 @@ import android.graphics.drawable.Drawable; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardSwitcher; -import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SuggestedWords; @@ -53,10 +52,8 @@ public class MoreSuggestions extends Keyboard { public int mDividerWidth; public int layout(SuggestedWords suggestions, int fromPos, int maxWidth, int minWidth, - int maxRow, KeyboardView view) { + int maxRow, MoreSuggestionsView view) { clearKeys(); - final Paint paint = new Paint(); - paint.setAntiAlias(true); final Resources res = view.getContext().getResources(); mDivider = res.getDrawable(R.drawable.more_suggestions_divider); // TODO: Drawable itself should have an alpha value. @@ -64,6 +61,7 @@ public class MoreSuggestions extends Keyboard { mDividerWidth = mDivider.getIntrinsicWidth(); final int padding = (int) res.getDimension( R.dimen.more_suggestions_key_horizontal_padding); + final Paint paint = view.newDefaultLabelPaint(); int row = 0; int pos = fromPos, rowStartPos = fromPos; @@ -71,7 +69,7 @@ public class MoreSuggestions extends Keyboard { while (pos < size) { final String word = suggestions.getWord(pos).toString(); // TODO: Should take care of text x-scaling. - mWidths[pos] = (int)view.getDefaultLabelWidth(word, paint) + padding; + mWidths[pos] = (int)view.getLabelWidth(word, paint) + padding; final int numColumn = pos - rowStartPos + 1; final int columnWidth = (maxWidth - mDividerWidth * (numColumn - 1)) / numColumn; diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java index f11b1a4c1..e64e7a685 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java @@ -43,17 +43,17 @@ import com.android.inputmethod.latin.R; public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel { private final int[] mCoordinates = new int[2]; - private final KeyDetector mModalPanelKeyDetector; + final KeyDetector mModalPanelKeyDetector; private final KeyDetector mSlidingPanelKeyDetector; private Controller mController; - private KeyboardActionListener mListener; + KeyboardActionListener mListener; private int mOriginX; private int mOriginY; - private static final TimerProxy EMPTY_TIMER_PROXY = new TimerProxy.Adapter(); + static final TimerProxy EMPTY_TIMER_PROXY = new TimerProxy.Adapter(); - private final KeyboardActionListener mSuggestionsPaneListener = + final KeyboardActionListener mSuggestionsPaneListener = new KeyboardActionListener.Adapter() { @Override public void onPressKey(int primaryCode) { |