diff options
author | 2011-01-09 16:32:58 +0900 | |
---|---|---|
committer | 2011-01-09 16:53:33 +0900 | |
commit | 90d96615bcb71af7ccbb2318b588aa78c4308e5a (patch) | |
tree | 675a69ee4343846acd7e6c135d7c122297cf81ce /java/src | |
parent | 7a42a46069d799c01f1da233d1add2ff974ac834 (diff) | |
download | latinime-90d96615bcb71af7ccbb2318b588aa78c4308e5a.tar.gz latinime-90d96615bcb71af7ccbb2318b588aa78c4308e5a.tar.xz latinime-90d96615bcb71af7ccbb2318b588aa78c4308e5a.zip |
Clean up: Update variable names to comply with spec of ApplicationInfo.
ApplicationInfo.sourceDir may or may not be apk file name. It can be a directory as well.
The spec just says it's "Full path to the location of this package".
Also, added error handling in loadDictionary().
Change-Id: I5e64d0aba4b1ec7634f4b3ac5537e7a774433ece
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/latin/BinaryDictionary.java | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 9f934c6ef..f7e67673a 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -55,7 +55,7 @@ public class BinaryDictionary extends Dictionary { try { System.loadLibrary("jni_latinime"); } catch (UnsatisfiedLinkError ule) { - Log.e("BinaryDictionary", "Could not load native library jni_latinime"); + Log.e(TAG, "Could not load native library jni_latinime"); } } @@ -71,7 +71,7 @@ public class BinaryDictionary extends Dictionary { mDicTypeId = dicTypeId; } - private native int openNative(String apkFileName, long dictOffset, long dictSize, + private native int openNative(String sourceDir, long dictOffset, long dictSize, int typedLetterMultiplier, int fullWordMultiplier, int maxWordLength, int maxWords, int maxAlternatives); private native void closeNative(int dict); @@ -84,12 +84,21 @@ public class BinaryDictionary extends Dictionary { int maxWordLength, int maxBigrams, int maxAlternatives); private final void loadDictionary(Context context, int resId) { - final AssetFileDescriptor afd = context.getResources().openRawResourceFd(resId); - mNativeDict = openNative(context.getApplicationInfo().sourceDir, - afd.getStartOffset(), afd.getLength(), - TYPED_LETTER_MULTIPLIER, FULL_WORD_FREQ_MULTIPLIER, - MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES); - mDictLength = afd.getLength(); + try { + final AssetFileDescriptor afd = context.getResources().openRawResourceFd(resId); + if (afd == null) { + Log.e(TAG, "Found the resource but it is compressed. resId=" + resId); + return; + } + mNativeDict = openNative(context.getApplicationInfo().sourceDir, + afd.getStartOffset(), afd.getLength(), + TYPED_LETTER_MULTIPLIER, FULL_WORD_FREQ_MULTIPLIER, + MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES); + mDictLength = afd.getLength(); + } catch (android.content.res.Resources.NotFoundException e) { + Log.e(TAG, "Could not find the resource. resId=" + resId); + return; + } } @Override @@ -165,7 +174,7 @@ public class BinaryDictionary extends Dictionary { } public long getSize() { - return mDictLength; // This value is initialized on the call to openNative() + return mDictLength; // This value is initialized in loadDictionary() } @Override |