类的概述:接收屏幕开关、系统关闭对话框事件,启动、关闭输入法service,弹出选择输入法的对话框等等。
(1)SimpleStringSplitter
TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
mStringColonSplitter.setString(enabledStr); //Sets the string to split
mStringColonSplitter.next(); //Returns the next object and advances the iterator.
TextUtils.SimpleStringSplitter A simple string splitter.
If the final character in the string to split is the delimiter then no empty string will be returned for the empty string after that delimeter. That is, splitting"a,b," on comma will return "a", "b", not "a", "b", "".
(2)
将i转化为16进制形式的字符串
Integer.toHexString(int i);
Returns an integer hash code for the parameter.
System.identityHashCode(Object anObject);
(3)EditorInfo
An EditorInfo describes several attributes of a text editing object that an input method is communicating with (typically an EditText), most importantly the type of text content it contains.
(4)注册观察者类
ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(Settings.Secure.getUriFor(
Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
(5)获取/设置默认的输入方法
String curInputMethodId = Settings.Secure.getString(mContext.getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD);
Settings.Secure.putString(mContext.getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD, "");
(6)应用service 信息application service
curIm是InputMethodInfo的实例
//getServiceInfo()
Retrieve all of the information we know about a particular service class.
Parameters:
component The full component name (i.e. com.google.apps.media/com.google.apps.media.BackgroundPlayback) of a Service class.
flags Additional option flags. Use any combination of GET_META_DATA
,GET_SHARED_LIBRARY_FILES
, to modify the data returned.
ServiceInfo si = mContext.getPackageManager().getServiceInfo(
curIm.getComponent(), 0);
(7) 注册广播接收器Context.registerReceiver()
IntentFilter screenOnOffFilt = new IntentFilter();
mContext.registerReceiver(new ScreenOnOffReceiver(), screenOnOffFilt);
The system may broadcast Intents that are "sticky" -- these stay around after the broadcast as finished, to be sent to any later registrations. If your IntentFilter matches one of these sticky Intents, that Intent will be returned by this function and sent to your receiver as if it had just been broadcast.
(8)获取其他app 的资源
InputMethodInfo imi ;
Resources res = mContext.createPackageContext(
imi.getPackageName(), 0).getResources();
InputMethodInfo.getPackageName()
//Return the .apk package that implements this input method.
Context.createPackageContext()
//Return a new Context object for the given application name.
(9)IInterface.asBinder()
Retrieve the Binder object associated with this interface. You must use this instead of a plain cast, so that proxy objects can return the correct result.
(10)线程安全
如果你的代码所在的进程中有多个线程在同时运行,而这些线程可能会同时运行这段代码。如果每次运行结果和单线程运行的结果是一样的,而且其他的变量的值也和预期的是一样的,就是线程安全的。
(11)InputMethod的Flag
InputMethod.SHOW_FORCED //Flag for showSoftInput
: this show has been forced to happen by the user. If set, the input method should remain visible until deliberated dismissed by the user in its UI.
InputMethod.SHOW_EXPLICIT //Flag for showSoftInput
: this show has been explicitly requested by the user. If not set, the system has decided it may be a good idea to show the input method based on a navigation operation in the UI.
(12)InputMethodManager的Flag
InputMethodManager.SHOW_FORCED //Flag for showSoftInput
to indicate that the user has forced the input method open (such as by long-pressing menu) so it should not be closed until they explicitly do so.
InputMethodManager.SHOW_IMPLICIT //Flag for showSoftInput
to indicate that this is an implicit request to show the input window, not as the result of a direct request by the user. The window may not be shown in this case.
(13)启动输入法service
mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE);
mCurIntent.setComponent(info.getComponent());
mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL,
com.android.internal.R.string.input_method_binding_label);
mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0));
mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE)
(14)获得和intent相关的具体组件
Retrieve the concrete component associated with the intent.
mCurIntent.getComponent()
(15)解除和service的绑定
mContext.unbindService(this);
Disconnect from an application service. You will no longer receive calls as the service is restarted, and the service is now allowed to stop at any time.
(15)输入法风格
WindowManager.LayoutParams.TYPE_INPUT_METHOD
WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; //Mask forsoftInputMode
of the bits that determine the way that the window should be adjusted to accommodate the soft input window.
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; //Adjustment option for softInputMode
: set to allow the window to be resized when an input method is shown, so that its contents are not covered by the input method. This can not be combined with SOFT_INPUT_ADJUST_PAN
; if neither of these are set, then the system will try to pick one or the other depending on the contents of the window.
WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION //Bit for softInputMode
: set when the user has navigated forward to the window. This is normally set automatically for you by the system, though you may want to set it in certain cases when you are displaying a window yourself. This flag will always be cleared automatically after the window is displayed.
(16)设置状态栏图标
final StatusBarManagerService mStatusBar;
mStatusBar.setIcon("ime", packageName, iconId, 0);
mStatusBar.setIconVisibility("ime", true);
(17)判断窗口是否需要输入法
WindowManager.LayoutParams.mayUseInputMethod(windowFlags)
//Returns true if such a window should be behind/interact with an input method, false if not.
(18)EditorInfo
An EditorInfo describes several attributes of a text editing object that an input method is communicating with (typically an EditText), most importantly the type of text content it contains.
(19)获取application的Flag信息
inputMethod.getServiceInfo().applicationInfo.flags
(20)buildInputMethodListLocked()方法
PackageManager pm = mContext.getPackageManager();
final Configuration config = mContext.getResources().getConfiguration();
final boolean haveHardKeyboard = config.keyboard == Configuration.KEYBOARD_QWERTY;
List services = pm.queryIntentServices(
new Intent(InputMethod.SERVICE_INTERFACE),
PackageManager.GET_META_DATA);、
ResolveInfo ri = services.get(i);
ServiceInfo si = ri.serviceInfo;
ComponentName compName = new ComponentName(si.packageName, si.name);
(21)输入法选择对话框
TypedArray a = context.obtainStyledAttributes(null,
com.android.internal.R.styleable.DialogPreference,
com.android.internal.R.attr.alertDialogStyle, 0);
mDialogBuilder = new AlertDialog.Builder(context)
.setTitle(com.android.internal.R.string.select_input_method)
.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface dialog) {
hideInputMethodMenu();
}
})
.setIcon(a.getDrawable(
com.android.internal.R.styleable.DialogPreference_dialogTitle));
a.recycle();
mDialogBuilder.setSingleChoiceItems(mItems, checkedItem,
new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
synchronized (mMethodMap) {
if (mIms == null || mIms.length <= which) {
return;
}
InputMethodInfo im = mIms[which];
hideInputMethodMenu();
if (im != null) {
setInputMethodLocked(im.getId());
}
}
}
});
mSwitchingDialog = mDialogBuilder.create();
mSwitchingDialog.getWindow().setType(
WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
mSwitchingDialog.show();