由于项目没有设计返回键,一旦进入别的应用,就无法回到桌面。只能通过串口输入input keyevent 4(返回键)来返回桌面,为了方便调试,在Framework 中监听手势,实现返回功能。
在frameworks\base\services\core\java\com\androID\server\policy\PhoneWindowManager中有这么一段代码
mSystemGestures = new SystemGesturesPointerEventListener(context, new SystemGesturesPointerEventListener.Callbacks() { @OverrIDe public voID onSwipeFromtop() { Log.i("gyx","onSwipeFromtop"); if (mStatusbar != null) { requestTransIEntbars(mStatusbar); } } @OverrIDe public voID onSwipeFromBottom() { Log.i("gyx","onSwipeFromBottom"); if (mNavigationbar != null && mNavigationbarposition == NAV_bar_BottOM) { requestTransIEntbars(mNavigationbar); } } @OverrIDe public voID onSwipeFromright() { Log.i("gyx","onSwipeFromright"); sendKeyCode(4); Log.i("gyx","sendKeyCode 4"); if (mNavigationbar != null && mNavigationbarposition == NAV_bar_RIGHT) { requestTransIEntbars(mNavigationbar); } } @OverrIDe public voID onSwipeFromleft() { Log.i("gyx","onSwipeFromleft"); if (mNavigationbar != null && mNavigationbarposition == NAV_bar_left) { requestTransIEntbars(mNavigationbar); } } @OverrIDe public voID onFling(int duration) { 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 onm ouseHoverAttop() { 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 onm ouseHoverAtBottom() { 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 onm ouseLeaveFromEdge() { mHandler.removeMessages(MSG_REQUEST_TRANSIENT_barS); } });
代码中监听了手势 *** 作,其中onSwipeFromright()就是当从屏幕的右侧向左滑动时会触发,只要在这里加入返回的功能即可;
实现返回按键的功能代码如下
private voID sendKeyCode(final int keyCode) { new Thread(new Runnable() { @OverrIDe public voID run() { try { // 创建一个Instrumentation对象 Instrumentation inst = new Instrumentation(); // 调用inst对象的按键模拟方法 inst.sendKeyDownUpSync(keyCode); } catch (Exception e) { e.printstacktrace(); } } }).start(); }
总结
以上是内存溢出为你收集整理的Android PhoneWindowManager监听屏幕右侧向左滑动实现返回功能全部内容,希望文章能够帮你解决Android PhoneWindowManager监听屏幕右侧向左滑动实现返回功能所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)