Android MTK 6750 系統語言與輸入法

需求一:要求只保留中文和英文兩種語言
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.
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章