Default Voice Control/输入法校准、自动校准、首字母大写、按键声音
最后更新于:2022-04-01 14:48:33
今天给大家分享MTK平台系统编程与修改的另一个部分,分别是输入法校准、自动校准默认关、首字母大写默认开、按键声音默认关、Voice Control 移除系统中文,默认
英文,下面一个一个的介绍给大家
①Language & input> Android Keyboard>Auto Correction > Uncheck as Default(Off) 语言输入-安卓键盘-自动校准默认关
根据红色框关键词用命令行在settings下执行热词检索:
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a3a55be.jpg)
~~~
.../mnt/disk3/jsp/xxx8382$ find packages/apps/Settings/ -name "*.xml" | xargs grep "Very aggressive" -l
~~~
搜索无果,于是扩大搜索范围,键入如下命令行
~~~
.../mnt/disk3/jsp/xxx8382$ find packages/ -name "*.xml" | xargs grep "Very aggressive" -l
packages/inputmethods/LatinIME/java/res/values/strings.xml
packages/inputmethods/LatinIME/java/res/values-en-rIN/strings.xml
packages/inputmethods/LatinIME/java/res/values-en-rGB/strings.xml
~~~
得到3条结果,进入查看得到热词 auto_correction_threshold_mode_very_aggressive 搜索热词
~~~
android5@ubuntu2015:/mnt/disk3/jsp/xxx8382$ find packages/ -name "*.xml" | xargs grep "auto_correction_threshold_mode_very_aggressive" -l
packages/inputmethods/LatinIME/java/res/values-es/strings.xml
packages/inputmethods/LatinIME/java/res/values-ms-rMY/strings.xml
packages/inputmethods/LatinIME/java/res/values-my/strings.xml
packages/inputmethods/LatinIME/java/res/values-ky-rKG/strings.xml
packages/inputmethods/LatinIME/java/res/values-hu/strings.xml
packages/inputmethods/LatinIME/java/res/values-ne-rNP/strings.xml
packages/inputmethods/LatinIME/java/res/values-pl/strings.xml
packages/inputmethods/LatinIME/java/res/values-lo-rLA/strings.xml
packages/inputmethods/LatinIME/java/res/values/strings.xml
packages/inputmethods/LatinIME/java/res/values/config-auto-correction-thresholds.xml
~~~
查看 config-auto-correction-thresholds.xml 文件 ,查找如下代码
~~~
<!-- The index of the auto correction threshold values array. -->
<string name="auto_correction_threshold_mode_index_off" translatable="false">0</string>
<string name="auto_correction_threshold_mode_index_modest" translatable="false">1</string>
<string name="auto_correction_threshold_mode_index_aggressive" translatable="false">2</string>
<string name="auto_correction_threshold_mode_index_very_aggressive" translatable="false">3</string>
<!-- The array of the auto correction threshold settings values. -->
<string-array name="auto_correction_threshold_mode_indexes" translatable="false">
<item>@string/auto_correction_threshold_mode_index_off</item>
<item>@string/auto_correction_threshold_mode_index_modest</item>
<item>@string/auto_correction_threshold_mode_index_aggressive</item>
<item>@string/auto_correction_threshold_mode_index_very_aggressive</item>
</string-array>
<!-- The array of the human readable auto correction threshold settings entries. -->
<string-array name="auto_correction_threshold_modes" translatable="false">
<item>@string/auto_correction_threshold_mode_off</item>
<item>@string/auto_correction_threshold_mode_modest</item>
<item>@string/auto_correction_threshold_mode_aggressive</item>
<item>@string/auto_correction_threshold_mode_very_aggressive</item>
</string-array>
~~~
继续热词搜索追踪
~~~
jsp@ubuntu2015:/mnt/disk3/jsp/RMT8382$ find packages/ -name "*.xml" | xargs grep "auto_correction_threshold_modes" -l
packages/inputmethods/LatinIME/java/res/values/config-auto-correction-thresholds.xml
packages/inputmethods/LatinIME/java/res/xml/prefs_screen_correction.xml
~~~
查看 prefs_screen_correction.xml 文件 修改如下,运用 Beyond Compare 工具直接copy
~~~
<ListPreference
android:key="auto_correction_threshold"
android:title="@string/auto_correction"
android:summary="@string/auto_correction_summary"
android:entryValues="@array/auto_correction_threshold_mode_indexes"
android:entries="@array/auto_correction_threshold_modes"
android:defaultValue="@string/auto_correction_threshold_mode_index_off"
android:persistent="true" />
~~~
就可以重新修改默认值,重新编译工程,刷机即可看到效果
重新刷机第一次开机之后的效果图:
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a3b86a6.jpg)
②系统输入法自动大写默认开/输入法按键音效默认关/输入法拼写校准默认开-修改
热词检索命令
~~~
android5@ubuntu2015:/mnt/disk3/jsp/RMT8382$ find packages/ -name "*.xml" | xargs grep "按键音效" -l
packages/inputmethods/LatinIME/java/res/values-zh-rCN/strings.xml
android5@ubuntu2015:/mnt/disk3/jsp/RMT8382$ find packages/ -name "*.xml" | xargs grep "sound_on_keypress" -l
packages/inputmethods/LatinIME/java/res/values-es/strings.xml
packages/inputmethods/LatinIME/java/res/values-ms-rMY/strings.xml
packages/inputmethods/LatinIME/java/res/values-my/strings.xml
packages/inputmethods/LatinIME/java/res/values-ky-rKG/strings.xml
packages/inputmethods/LatinIME/java/res/values-hu/strings.xml
packages/inputmethods/LatinIME/java/res/values-ne-rNP/strings.xml
packages/inputmethods/LatinIME/java/res/values-pl/strings.xml
packages/inputmethods/LatinIME/java/res/values-lo-rLA/strings.xml
packages/inputmethods/LatinIME/java/res/values/strings.xml
packages/inputmethods/LatinIME/java/res/values-es-rUS/strings.xml
packages/inputmethods/LatinIME/java/res/values-bn/strings.xml
packages/inputmethods/LatinIME/java/res/values-tl/strings.xml
packages/inputmethods/LatinIME/java/res/xml/prefs_screen_preferences.xml
~~~
查看 prefs_screen_preferences.xml 文件,检索热词
~~~
jsp@ubuntu2015:/mnt/disk3/jsp/xxx8382$ find packages/ -name "*.xml" | xargs grep "config_default_sound_enabled" -l
packages/inputmethods/LatinIME/java/res/values/config-per-form-factor.xml
~~~
其实在prefs_screen_preferences.xml 可以直接修改,根据需求修改如下:
~~~
#首字母大写开
<CheckBoxPreference
android:key="auto_cap"
android:title="@string/auto_cap"
android:summary="@string/auto_cap_summary"
android:defaultValue="true"
android:persistent="true" />
#输入法按键音效关
<CheckBoxPreference
android:key="sound_on"
android:title="@string/sound_on_keypress"
android:defaultValue="false"
android:persistent="true" />
#输入法拼写校准默认开
<CheckBoxPreference
android:key="vibrate_on"
android:title="@string/vibrate_on_keypress"
android:defaultValue="@bool/config_default_vibration_enabled"
android:persistent="true" />
~~~
刷机第一次启动的效果:
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a3cf9e7.jpg)
③setting - voice control - language for voice control -Keep only english 设置-声音控制-语言只留英语去掉中文
最初效果图,默认简体中文:![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a3e308f.jpg)
定位到settings下检索关键字
~~~
jsp@ubuntu2015:/mnt/disk3/jsp/xxx8382$ find packages/apps/Settings/ -type f|xargs grep "繁體中文" -l
~~~
搜索无果,扩大检索范围
~~~
jsp@ubuntu2015:/mnt/disk3/jsp/xxx8382$ find ./ -type f|xargs grep "繁體中文" -l
~~~
发现结果根本不是想要的,而且由于源码较大,所以这个果断放弃,采用另一个方案,使用Eclipse工具来检索,这是笔者介绍给大家的一个非常实用的方法,以后绝对会用
得着不管是检索资料还是反编译apk等,都很实用
连接USB打开debugging,打开Eclipse → 打开 DDMS 点击设备 如下界面操作:
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a401f74.jpg)
检索包名 com.mediatek.voicecommand
~~~
android5@ubuntu2015:/mnt/disk3/jsp/RMT8382$ find -name "*.xml"|xargs grep "com.mediatek.voicecommand" -l
./vendor/mediatek/proprietary/packages/apps/VoiceCommand/tests/AndroidManifest.xml
./vendor/mediatek/proprietary/packages/apps/VoiceCommand/res/xml/voice_ui_available_preference.xml
./vendor/mediatek/proprietary/packages/apps/VoiceCommand/res/xml/voiceprocessinfo.xml
./vendor/mediatek/proprietary/packages/apps/VoiceCommand/AndroidManifest.xml
~~~
得到如上结果,大大缩小我们要查找的范围,继续之前的检索
~~~
android5@ubuntu2015:/mnt/disk3/jsp/RMT8382$ find vendor/mediatek/proprietary/packages/apps/VoiceCommand -type f|xargs grep "繁體中文" -l
vendor/mediatek/proprietary/packages/apps/VoiceCommand/res/xml/voicelanguage.xml
~~~
得到 voicelanguage.xml 资源文件,继续下一步检索
~~~
android5@ubuntu2015:/mnt/disk3/jsp/RMT8382$ find -name "*.java"|xargs grep "voicelanguage" -l
./out/target/common/R/com/mediatek/voicecommand/R.java
./out/target/common/obj/APPS/VoiceCommand_intermediates/src/com/mediatek/voicecommand/R.java
~~~
搜到的都不是想要的,继续检索,在当前目录下,看某个java文件调用了刚刚DDMS解析的 list 资源 id
~~~
android5@ubuntu2015:/mnt/disk3/jsp/RMT8382$ find vendor/mediatek/proprietary/packages/apps/VoiceCommand -name "*.java"|xargs grep "list" -l
vendor/mediatek/proprietary/packages/apps/VoiceCommand/tests/src/com/mediatek/voicecommand/tests/VoiceCommandTest.java
vendor/mediatek/proprietary/packages/apps/VoiceCommand/src/com/mediatek/voicecommand/ui/settings/VoiceUiSettings.java
vendor/mediatek/proprietary/packages/apps/VoiceCommand/src/com/mediatek/voicecommand/mgr/ConfigurationManager.java
vendor/mediatek/proprietary/packages/apps/VoiceCommand/src/com/mediatek/voicecommand/mgr/AppDataManager.java
vendor/mediatek/proprietary/packages/apps/VoiceCommand/src/com/mediatek/voicecommand/business/VoiceContacts.java
vendor/mediatek/proprietary/packages/apps/VoiceCommand/src/com/mediatek/voicecommand/business/VoiceWakeupMode.java
vendor/mediatek/proprietary/packages/apps/VoiceCommand/src/com/mediatek/voicecommand/service/VoiceCommandManagerStub.java
vendor/mediatek/proprietary/packages/apps/VoiceCommand/src/com/mediatek/voicecommand/cfg/ConfigurationXML.java
~~~
打开 VoiceUiSettings.java 查看系统代码,检索到相关资源
~~~
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
if (KEY_VOICE_UI_LANGUAGE.equals(preference.getKey())) {// 这就是Preference 被点击之后跳转的选项,也就是Voice Control 选项
Intent intent = new Intent(
"com.mediatek.voicecommand.VOICE_CONTROL_LANGUAGE");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return true;
} else if
......
}
~~~
根据 Activity action 检索Acticity 名称
~~~
jsp@ubuntu2015:/mnt/disk3/jsp/xxx8382$ find vendor/mediatek/proprietary/packages/apps/VoiceCommand -name "*.xml"|xargs grep "com.mediatek.voicecommand.VOICE_CONTROL_LANGUAGE" -l
vendor/mediatek/proprietary/packages/apps/VoiceCommand/AndroidManifest.xml
~~~
得到如下 Activity :
~~~
<activity android:name=".ui.settings.VoiceUiAvailableLanguageActivity" android:label="@string/voice_ui_language_title" android:taskAffinity="com.android.settings" android:configChanges="orientation|keyboardHidden|keyboard|navigation" android:parentActivityName=".ui.settings.VoiceUiSettings">
<intent-filter>
<action android:name="com.mediatek.voicecommand.VOICE_CONTROL_LANGUAGE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
~~~
查看 VoiceUiAvailableLanguageActivity 代码
~~~
@Override
public void onCreate(Bundle savedInstanceState) {
Xlog.d(TAG, "OnCreate VoiceUiAvailableLanguageFragment");
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.voice_ui_available_langs);
mVoiceConfigMgr = ConfigurationManager.getInstance(this);
if (mVoiceConfigMgr == null) {
Xlog.e(TAG, "ConfigurationManager is null");
return;
}
mAvailableLangs = mVoiceConfigMgr.getLanguageList(); // 继续查看 ConfigurationManager getLanguageList() 代码
// mDefaultLanguage = mVoiceConfigMgr.getCurrentLanguage();// 这里 mDefaultLanguage int 默认为 0
......
}
}
~~~
ConfigurationManager getLanguageList() 代码
~~~
public String[] getLanguageList() {
int size = mLanguageList.size();
if (size == 0) {
return null;
}
String[] language = new String[size];
// Log.i(VoiceCommandManagerService.TAG, "mLanguageList = "+ size);
for (int i = 0; i < size; i++) {
language[i] = mLanguageList.get(i).mName;
}
return language;
}
~~~
mLanguageList 变量赋值的地方:
~~~
/*
* ConfigurationManager for control configuration
*
* @param context
*/
private ConfigurationManager(Context context) {
......
mCurrentLanguageIndex = mConfigurationXML
.readVoiceLanguangeFromXml(mLanguageList);// 来自 ConfigurationXML 的 readVoiceLanguangeFromXml 函数
......
}
~~~
继续查看 ConfigurationXML 的 readVoiceLanguangeFromXml 函数
~~~
/**
* Read language info from res.
*
* @param languageList
* language list instance
*/
public int readVoiceLanguangeFromXml(
......
XmlPullParser parser = mContext.getResources().getXml(// 这里就是加载语言选项 xml 的地方,下面贴上 xml 内容
R.xml.voicelanguage);
if (parser == null) {
Log.e(TAG, "readVoiceLanguangeFromXml Got execption");
return curIndex;
}
......
}
~~~
voicelanguage.xml 内容:
~~~
<?xml version="1.0" encoding="UTF-8"?>
<!-- Engineer-Jsp add remove 1 and 2 item default 0 -->
<Languages>
<Language TypeName="English" ID="0" Code="en-US" FileName="keyword/3.xml" />
<DefaultLanguage ID="0" />
</Languages>
<!--
<Language TypeName="简体中文" ID="1" Code="zh-CN" FileName="keyword/1.xml" />
<Language TypeName="繁體中文" ID="2" Code="zh-TW" FileName="keyword/2.xml" />
-->
~~~
这里已经是我改过的,需求是去掉所有中文只留英文选项,修改 TypeName="English" 的 ID 和 DefaultLanguage ID 都为 0 之后保存,继续修改java逻辑
回到我们的 VoiceUiAvailableLanguageActivity ,只需要注释掉几句代码就OK了
~~~
@Override
public void onCreate(Bundle savedInstanceState) {
Xlog.d(TAG, "OnCreate VoiceUiAvailableLanguageFragment");
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.voice_ui_available_langs);
mVoiceConfigMgr = ConfigurationManager.getInstance(this);
if (mVoiceConfigMgr == null) {
Xlog.e(TAG, "ConfigurationManager is null");
return;
}
mAvailableLangs = mVoiceConfigMgr.getLanguageList();
// mDefaultLanguage = mVoiceConfigMgr.getCurrentLanguage();//注释此句代码,因为 mDefaultLanguage 默认为0,不再需要其他选项,自己默认为0
......
}
~~~
~~~
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
if (preference instanceof RadioButtonPreference) {
// selectLanguage((RadioButtonPreference) preference); // 注释掉此句,不过不注释也不影响,只是多做了一些操作而已,都是多余的
Xlog.d(TAG, "default language changed to " + mAvailableLangs[mDefaultLanguage]);
finish();
}
return true;
}
~~~
selectLanguage 函数代码:
~~~
private void selectLanguage(RadioButtonPreference preference) {
if (mLastSelectedPref != null) {
if (mLastSelectedPref == preference) {
return;
}
mLastSelectedPref.setChecked(false);
}
mDefaultLanguage = Integer.parseInt(preference.getKey().toString());
Xlog.d(TAG, "set default language to " + mAvailableLangs[mDefaultLanguage]);
mVoiceConfigMgr.setCurrentLanguage(mDefaultLanguage);
preference.setChecked(true);
mLastSelectedPref = preference;
}
~~~
最后make自己的系统工程,重新烧录可看效果
效果图:
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a418682.jpg)