功能实现:在该地方监听手势滑动,可以实现顶部、底部、左边、右边滑动弹出窗口出来,例如我们手机左右滑动退出程序就可以在这里实现。 代码路径:
android/frameworks/base/servicescore/java/com/android/server/policy/PhoneWindowManager.java
修改地方: 在PhoneWindowManager.java中init方法中用到手势,这里可以监听手势(左边滑动、右边滑动、顶部滑动、底部滑动、点击)
@Override
public void init(Context context, IWindowManager windowManager,
WindowManagerFuncs windowManagerFuncs) {
mContext = context;
mWindowManager = windowManager;
mSystemGestures = new SystemGesturesPointerEventListener(context,
new SystemGesturesPointerEventListener.Callbacks() {
@Override
public void onSwipeFromTop() {
Log.i("wangqi", "onSwipeFromTop() " );
if (mStatusBar != null) {
requestTransientBars(mStatusBar);
}
}
@Override
public void onSwipeFromBottom() {
Log.i("wangqi", "onSwipeFromBottom() " );
if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_BOTTOM) {
requestTransientBars(mNavigationBar);
}
}
@Override
public void onSwipeFromRight() {
Log.i("wangqi", "onSwipeFromRight() " );
if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_RIGHT) {
requestTransientBars(mNavigationBar);
}
}
@Override
public void onSwipeFromLeft() {
Log.i("wangqi", "onSwipeFromLeft() " );
if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_LEFT) {
requestTransientBars(mNavigationBar);
}
}
@Override
public void onFling(int duration) {
Log.i("wangqi", "onFling() " );
if (mPowerManagerInternal != null) {
mPowerManagerInternal.powerHint(
PowerHint.INTERACTION, duration);
}
}
@Override
public void onDebug() {
// no-op
}
@Override
public void onDown() {
mOrientationListener.onTouchStart();
}
@Override
public void onUpOrCancel() {
mOrientationListener.onTouchEnd();
}
@Override
public void onMouseHoverAtTop() {
Log.i("wangqi", "onMouseHoverAtTop() " );
mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
mHandler.sendMessageDelayed(msg, 500);
}
@Override
public void onMouseHoverAtBottom() {
Log.i("wangqi", "onMouseHoverAtBottom() " );
mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
mHandler.sendMessageDelayed(msg, 500);
}
@Override
public void onMouseLeaveFromEdge() {
mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
}
});
}
日志打印
08-17 21:30:50.234 2432 2456 I wq892373445: onFling()
08-17 21:30:51.475 2432 2456 I wq892373445: onSwipeFromTop()
08-17 21:30:51.572 2432 2456 I wq892373445: onFling()
08-17 21:30:54.069 2432 2456 I wq892373445: onSwipeFromTop()
08-17 21:30:54.193 2432 2456 I wq892373445: onFling()
08-17 21:30:58.378 2432 2456 I wq892373445: onSwipeFromLeft()
08-17 21:30:58.531 2432 2456 I wq892373445: onFling()
08-17 21:31:00.467 2432 2456 I wq892373445: onSwipeFromRight()
08-17 21:31:00.578 2432 2456 I wq892373445: onFling()
08-17 21:31:02.308 2432 2456 I wq892373445: onSwipeFromBottom()
08-17 21:31:02.391 2432 2456 I wq892373445: onFling()
|