Consolidate main dictionary files.
This change is a preparation for upcoming optimizations on dictionary file loading. * We can consolidate dictionary files because we are no longer relying on Asset Manager. * Stopping compressing dictionary files as planning to use mmap() on the region in the apk file. * Probably we won't rely on Asset Manager. Instead we'll probably use offset and size obtained from AssetFileDescriptor. Change-Id: Id57dce512fd3d2397a58628f8264bd824194da76main
parent
a96574fdd5
commit
458249e703
|
@ -13,7 +13,8 @@ LOCAL_JNI_SHARED_LIBRARIES := libjni_latinime
|
||||||
|
|
||||||
LOCAL_STATIC_JAVA_LIBRARIES := android-common
|
LOCAL_STATIC_JAVA_LIBRARIES := android-common
|
||||||
|
|
||||||
#LOCAL_AAPT_FLAGS := -0 .dict
|
# Do not compress dictionary files to mmap dict data runtime
|
||||||
|
LOCAL_AAPT_FLAGS := -0 .dict
|
||||||
|
|
||||||
# Include all the resources regardless of system supported locales
|
# Include all the resources regardless of system supported locales
|
||||||
LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
|
LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
/*
|
|
||||||
**
|
|
||||||
** Copyright 2010, 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.
|
|
||||||
*/
|
|
||||||
-->
|
|
||||||
|
|
||||||
<dictionary>
|
|
||||||
<part name = "main" />
|
|
||||||
</dictionary>
|
|
|
@ -71,8 +71,8 @@ public class BinaryDictionary extends Dictionary {
|
||||||
* @param context application context for reading resources
|
* @param context application context for reading resources
|
||||||
* @param resId the resource containing the raw binary dictionary
|
* @param resId the resource containing the raw binary dictionary
|
||||||
*/
|
*/
|
||||||
public BinaryDictionary(Context context, int[] resId, int dicTypeId) {
|
public BinaryDictionary(Context context, int resId, int dicTypeId) {
|
||||||
if (resId != null && resId.length > 0 && resId[0] != 0) {
|
if (resId != 0) {
|
||||||
loadDictionary(context, resId);
|
loadDictionary(context, resId);
|
||||||
}
|
}
|
||||||
mDicTypeId = dicTypeId;
|
mDicTypeId = dicTypeId;
|
||||||
|
@ -111,23 +111,14 @@ public class BinaryDictionary extends Dictionary {
|
||||||
int[] inputCodes, int inputCodesLength, char[] outputChars, int[] frequencies,
|
int[] inputCodes, int inputCodesLength, char[] outputChars, int[] frequencies,
|
||||||
int maxWordLength, int maxBigrams, int maxAlternatives);
|
int maxWordLength, int maxBigrams, int maxAlternatives);
|
||||||
|
|
||||||
private final void loadDictionary(Context context, int[] resId) {
|
private final void loadDictionary(Context context, int resId) {
|
||||||
InputStream[] is = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
// merging separated dictionary into one if dictionary is separated
|
is = context.getResources().openRawResource(resId);
|
||||||
int total = 0;
|
final int total = is.available();
|
||||||
is = new InputStream[resId.length];
|
|
||||||
for (int i = 0; i < resId.length; i++) {
|
|
||||||
is[i] = context.getResources().openRawResource(resId[i]);
|
|
||||||
total += is[i].available();
|
|
||||||
}
|
|
||||||
|
|
||||||
mNativeDictDirectBuffer =
|
mNativeDictDirectBuffer =
|
||||||
ByteBuffer.allocateDirect(total).order(ByteOrder.nativeOrder());
|
ByteBuffer.allocateDirect(total).order(ByteOrder.nativeOrder());
|
||||||
int got = 0;
|
final int got = Channels.newChannel(is).read(mNativeDictDirectBuffer);
|
||||||
for (int i = 0; i < resId.length; i++) {
|
|
||||||
got += Channels.newChannel(is[i]).read(mNativeDictDirectBuffer);
|
|
||||||
}
|
|
||||||
if (got != total) {
|
if (got != total) {
|
||||||
Log.e(TAG, "Read " + got + " bytes, expected " + total);
|
Log.e(TAG, "Read " + got + " bytes, expected " + total);
|
||||||
} else {
|
} else {
|
||||||
|
@ -140,11 +131,7 @@ public class BinaryDictionary extends Dictionary {
|
||||||
Log.w(TAG, "No available memory for binary dictionary");
|
Log.w(TAG, "No available memory for binary dictionary");
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (is != null) {
|
if (is != null) is.close();
|
||||||
for (int i = 0; i < is.length; i++) {
|
|
||||||
is[i].close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w(TAG, "Failed to close input stream");
|
Log.w(TAG, "Failed to close input stream");
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,15 +99,15 @@ public class InputLanguageSelection extends PreferenceActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasDictionary(Locale locale) {
|
private boolean hasDictionary(Locale locale) {
|
||||||
Resources res = getResources();
|
final Resources res = getResources();
|
||||||
Configuration conf = res.getConfiguration();
|
final Configuration conf = res.getConfiguration();
|
||||||
Locale saveLocale = conf.locale;
|
final Locale saveLocale = conf.locale;
|
||||||
boolean haveDictionary = false;
|
boolean haveDictionary = false;
|
||||||
conf.locale = locale;
|
conf.locale = locale;
|
||||||
res.updateConfiguration(conf, res.getDisplayMetrics());
|
res.updateConfiguration(conf, res.getDisplayMetrics());
|
||||||
|
|
||||||
int[] dictionaries = LatinIME.getDictionary(res);
|
int mainDicResId = LatinIME.getMainDictionaryResourceId(res);
|
||||||
BinaryDictionary bd = new BinaryDictionary(this, dictionaries, Suggest.DIC_MAIN);
|
BinaryDictionary bd = new BinaryDictionary(this, mainDicResId, Suggest.DIC_MAIN);
|
||||||
|
|
||||||
// Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of
|
// Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of
|
||||||
// 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words.
|
// 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words.
|
||||||
|
|
|
@ -347,49 +347,19 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a dictionary or multiple separated dictionary
|
* Returns a main dictionary resource id
|
||||||
* @return returns array of dictionary resource ids
|
* @return main dictionary resource id
|
||||||
*/
|
*/
|
||||||
public static int[] getDictionary(Resources res) {
|
public static int getMainDictionaryResourceId(Resources res) {
|
||||||
|
final String MAIN_DIC_NAME = "main";
|
||||||
String packageName = LatinIME.class.getPackage().getName();
|
String packageName = LatinIME.class.getPackage().getName();
|
||||||
XmlResourceParser xrp = res.getXml(R.xml.dictionary);
|
return res.getIdentifier(MAIN_DIC_NAME, "raw", packageName);
|
||||||
ArrayList<Integer> dictionaries = new ArrayList<Integer>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
int current = xrp.getEventType();
|
|
||||||
while (current != XmlPullParser.END_DOCUMENT) {
|
|
||||||
if (current == XmlPullParser.START_TAG) {
|
|
||||||
String tag = xrp.getName();
|
|
||||||
if (tag != null) {
|
|
||||||
if (tag.equals("part")) {
|
|
||||||
String dictFileName = xrp.getAttributeValue(null, "name");
|
|
||||||
dictionaries.add(res.getIdentifier(dictFileName, "raw", packageName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xrp.next();
|
|
||||||
current = xrp.getEventType();
|
|
||||||
}
|
|
||||||
} catch (XmlPullParserException e) {
|
|
||||||
Log.e(TAG, "Dictionary XML parsing failure");
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Dictionary XML IOException");
|
|
||||||
}
|
|
||||||
|
|
||||||
int count = dictionaries.size();
|
|
||||||
int[] dict = new int[count];
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
dict[i] = dictionaries.get(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dict;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSuggest() {
|
private void initSuggest() {
|
||||||
updateAutoTextEnabled();
|
updateAutoTextEnabled();
|
||||||
String locale = mSubtypeSwitcher.getInputLocaleStr();
|
String locale = mSubtypeSwitcher.getInputLocaleStr();
|
||||||
|
|
||||||
Resources orig = getResources();
|
|
||||||
Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(new Locale(locale));
|
Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(new Locale(locale));
|
||||||
if (mSuggest != null) {
|
if (mSuggest != null) {
|
||||||
mSuggest.close();
|
mSuggest.close();
|
||||||
|
@ -397,8 +367,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
final SharedPreferences prefs = mPrefs;
|
final SharedPreferences prefs = mPrefs;
|
||||||
mQuickFixes = prefs.getBoolean(Settings.PREF_QUICK_FIXES, true);
|
mQuickFixes = prefs.getBoolean(Settings.PREF_QUICK_FIXES, true);
|
||||||
|
|
||||||
int[] dictionaries = getDictionary(orig);
|
final Resources res = mResources;
|
||||||
mSuggest = new Suggest(this, dictionaries);
|
int mainDicResId = getMainDictionaryResourceId(res);
|
||||||
|
mSuggest = new Suggest(this, mainDicResId);
|
||||||
loadAndSetAutoCorrectionThreshold(prefs);
|
loadAndSetAutoCorrectionThreshold(prefs);
|
||||||
if (mUserDictionary != null) mUserDictionary.close();
|
if (mUserDictionary != null) mUserDictionary.close();
|
||||||
mUserDictionary = new UserDictionary(this, locale);
|
mUserDictionary = new UserDictionary(this, locale);
|
||||||
|
@ -418,8 +389,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
mSuggest.setContactsDictionary(mContactsDictionary);
|
mSuggest.setContactsDictionary(mContactsDictionary);
|
||||||
mSuggest.setAutoDictionary(mAutoDictionary);
|
mSuggest.setAutoDictionary(mAutoDictionary);
|
||||||
updateCorrectionMode();
|
updateCorrectionMode();
|
||||||
mWordSeparators = mResources.getString(R.string.word_separators);
|
mWordSeparators = res.getString(R.string.word_separators);
|
||||||
mSentenceSeparators = mResources.getString(R.string.sentence_separators);
|
mSentenceSeparators = res.getString(R.string.sentence_separators);
|
||||||
|
|
||||||
mSubtypeSwitcher.changeSystemLocale(savedLocale);
|
mSubtypeSwitcher.changeSystemLocale(savedLocale);
|
||||||
}
|
}
|
||||||
|
@ -859,10 +830,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onEvaluateFullscreenMode() {
|
public boolean onEvaluateFullscreenMode() {
|
||||||
DisplayMetrics dm = getResources().getDisplayMetrics();
|
final Resources res = mResources;
|
||||||
|
DisplayMetrics dm = res.getDisplayMetrics();
|
||||||
float displayHeight = dm.heightPixels;
|
float displayHeight = dm.heightPixels;
|
||||||
// If the display is more than X inches high, don't go to fullscreen mode
|
// If the display is more than X inches high, don't go to fullscreen mode
|
||||||
float dimen = getResources().getDimension(R.dimen.max_height_for_fullscreen);
|
float dimen = res.getDimension(R.dimen.max_height_for_fullscreen);
|
||||||
if (displayHeight > dimen) {
|
if (displayHeight > dimen) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1874,7 +1846,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
} else if (Settings.PREF_RECORRECTION_ENABLED.equals(key)) {
|
} else if (Settings.PREF_RECORRECTION_ENABLED.equals(key)) {
|
||||||
mReCorrectionEnabled = sharedPreferences.getBoolean(
|
mReCorrectionEnabled = sharedPreferences.getBoolean(
|
||||||
Settings.PREF_RECORRECTION_ENABLED,
|
Settings.PREF_RECORRECTION_ENABLED,
|
||||||
getResources().getBoolean(R.bool.default_recorrection_enabled));
|
mResources.getBoolean(R.bool.default_recorrection_enabled));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2006,11 +1978,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSuggestionVisibility(SharedPreferences prefs) {
|
private void updateSuggestionVisibility(SharedPreferences prefs) {
|
||||||
|
final Resources res = mResources;
|
||||||
final String suggestionVisiblityStr = prefs.getString(
|
final String suggestionVisiblityStr = prefs.getString(
|
||||||
Settings.PREF_SHOW_SUGGESTIONS_SETTING,
|
Settings.PREF_SHOW_SUGGESTIONS_SETTING,
|
||||||
mResources.getString(R.string.prefs_suggestion_visibility_default_value));
|
res.getString(R.string.prefs_suggestion_visibility_default_value));
|
||||||
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
|
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
|
||||||
if (suggestionVisiblityStr.equals(mResources.getString(visibility))) {
|
if (suggestionVisiblityStr.equals(res.getString(visibility))) {
|
||||||
mSuggestionVisibility = visibility;
|
mSuggestionVisibility = visibility;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
|
|
||||||
private int mCorrectionMode = CORRECTION_BASIC;
|
private int mCorrectionMode = CORRECTION_BASIC;
|
||||||
|
|
||||||
public Suggest(Context context, int[] dictionaryResId) {
|
public Suggest(Context context, int dictionaryResId) {
|
||||||
mMainDict = new BinaryDictionary(context, dictionaryResId, DIC_MAIN);
|
mMainDict = new BinaryDictionary(context, dictionaryResId, DIC_MAIN);
|
||||||
initPool();
|
initPool();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,20 @@ LOCAL_SRC_FILES := \
|
||||||
|
|
||||||
#FLAG_DBG := true
|
#FLAG_DBG := true
|
||||||
|
|
||||||
ifneq ($(TARGET_ARCH),x86)
|
TARGETING_UNBUNDLED_FROYO := true
|
||||||
ifneq ($(FLAG_DBG), true)
|
|
||||||
LOCAL_NDK_VERSION := 4
|
ifeq ($(TARGET_ARCH), x86)
|
||||||
|
TARGETING_UNBUNDLED_FROYO := false
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LOCAL_SDK_VERSION := 8
|
ifeq ($(FLAG_DBG), true)
|
||||||
endif #TARGET_ARCH = x86
|
TARGETING_UNBUNDLED_FROYO := false
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGETING_UNBUNDLED_FROYO), true)
|
||||||
|
LOCAL_NDK_VERSION := 4
|
||||||
|
LOCAL_SDK_VERSION := 8
|
||||||
|
endif
|
||||||
|
|
||||||
LOCAL_MODULE := libjni_latinime
|
LOCAL_MODULE := libjni_latinime
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue