需求一:要求只保留中文和英文两种语言
xxxx/frameworks/base/core/res/res/values/locale_config.xml
<string-array translatable="false" name="supported_locales">
<item>af-NA</item> <!-- Afrikaans (Namibia) -->
<item>af-ZA</item> <!-- Afrikaans (South Africa) -->
<item>agq-CM</item> <!-- Aghem (Cameroon) -->
<item>ak-GH</item> <!-- Akan (Ghana) -->
..............
.............
.............
<item>zh-Hant-TW</item> <!-- Chinese (Traditional Han,Taiwan) -->
<item>zu-ZA</item> <!-- Zulu (South Africa) -->
</string-array>
supported_locales中只保留English:
<string-array translatable="false" name="supported_locales">
<item>en-US</item> <!-- English (United States) -->
</string-array>
需求二:解决在settings中添加语言时会自动切换切换输入法问题
frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
synchronized(mMethodMap) {
//yh
//resetStateIfCurrentLocaleChangedLocked();
}
}
}, filter);
需求三:切换语言切换输入法
xxxx/packages/apps/Settings/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java
+import android.os.SystemProperties;
+import android.view.inputmethod.InputMethodManager;
private static final String TAG = "LocaleDragAndDropAdapter";
private static final String CFGKEY_SELECTED_LOCALES = "selectedLocales";
+private static final String NewInputMethodName = "com.android.inputmethod.latin/.LatinIME";
+private static final String NewInputMethodName2 = "com.sohu.inputmethod.sogou/.SogouIME";
void onItemMove(int fromPosition, int toPosition) {
if (fromPosition >= 0 && toPosition >= 0) {
final LocaleStore.LocaleInfo saved = mFeedItemList.get(fromPosition);
mFeedItemList.remove(fromPosition);
mFeedItemList.add(toPosition, saved);
///
if(toPosition==0&&saved.toString().equals("en-US"))
{
((InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE))
.setInputMethod(null, NewInputMethodName);
}else if(toPosition==0&&saved.toString().equals("zh-CN")){
((InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE))
.setInputMethod(null, NewInputMethodName2);
}
/
} else {
// TODO: It looks like sometimes the RecycleView tries to swap item -1
// I did not see it in a while, but if it happens, investigate and file a bug.
Log.e(TAG, String.format(Locale.US,
"Negative position in onItemMove %d -> %d", fromPosition, toPosition));
}
notifyItemChanged(fromPosition); // to update the numbers
notifyItemChanged(toPosition);
notifyItemMoved(fromPosition, toPosition);
// We don't call doTheUpdate() here because this method is called for each item swap.
// So if we drag something across several positions it will be called several times.
}