--------------http://blog.csdn.net/DrakeBlue/article/details/39049495
Android系统在外接物理键盘的时候,可以在Settings的Language&Input设置中,将默认的输入设置设为软键盘还是物理键盘。
Android系统在检测到有外接USB键盘的时候,默认是启用物理键盘,而软键盘将会隐藏。如果需要启用软键盘,需要将物理键盘OFF掉。
现在,我们修改源代码,将这个物理键盘默认改为OFF。
通过Settings的代码,我们找到该Dialog是通过IIputMethodManager.aidl的showInputMethodPickerFromClient()方法通知另外的地方弹出的对话。
而showInputMethodPickerFromClient()方法的实现是在frameworks/base/services/java/com/android/server/InputMethodManagerService.java中。
1795行,方法//
@Override
public void showInputMethodPickerFromClient(IInputMethodClient client) {
synchronized (mMethodMap) {
if (mCurClient == null || client == null
|| mCurClient.client.asBinder() != client.asBinder()) {
Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid "
+ Binder.getCallingUid() + ": " + client);
}
// Always call subtype picker, because subtype picker is a superset of input method
// picker.
mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER);
}
}
该Handler的处理在2050行;
@Override
public boolean handleMessage(Message msg) {
HandlerCaller.SomeArgs args;
switch (msg.what) {
case MSG_SHOW_IM_PICKER:
showInputMethodMenu();
return true;
case MSG_SHOW_IM_SUBTYPE_PICKER:
showInputMethodSubtypeMenu();
return true;
......
......
继续跟踪showInputMethodSubtypeMenu()方法; 2317行
private void showInputMethodSubtypeMenu() {
showInputMethodMenuInternal(true);
}
最后找到关键方法showInputMethodMenuInternal(); 2344行;
这个方法主要是获取系统输入法,然后进行弹框显示。而我们的物理键盘默认设置看在下面代码片段中。
final Switch hardKeySwitch = ((Switch)mSwitchingDialogTitleView.findViewById(
com.android.internal.R.id.hard_keyboard_switch));
Log.d(TAG, "input isEnabled: " + mWindowManagerService.isHardKeyboardEnabled());
hardKeySwitch.setChecked(mWindowManagerService.isHardKeyboardEnabled());
hardKeySwitch.setOnCheckedChangeListener(
new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(
CompoundButton buttonView, boolean isChecked) {
mWindowManagerService.setHardKeyboardEnabled(isChecked);
}
});
我们看到该Switch的Checked设置是在调用的WindowManagerService的一个boolean值的get方法。接着往里走
/frameworks/base/services/java/com/android/server/wm/WindowManagerService.java
关键代码:行6618 computeScreenConfigurationLocked()方法中
boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
if (hardKeyboardAvailable != mHardKeyboardAvailable) {
mHardKeyboardAvailable = hardKeyboardAvailable;
mHardKeyboardEnabled = !hardKeyboardAvailable;
mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
}
if (!mHardKeyboardEnabled) {
config.keyboard = Configuration.KEYBOARD_NOKEYS;
}
这里将会读取物理键盘是否可用,如果可用将会赋值给mHardKeyboardEnabled为true,然后hardKeySwitch set的值将会是这个可用的true,
我这里将hardKeyboardAvailable取反赋给mHardKeyboardEnabled。