android 8 源码 将鼠标/触摸屏 消息传出,供app使用

路径,新加文件:

frameworks\base\core\java\com\android\internal\widget\PointerLocationView1.java
 @Override
 public void onPointerEvent(MotionEvent event) {
        final int action = event.getAction();


        if (action == MotionEvent.ACTION_DOWN
                || (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) {
            +Log.i("Pointer", "into onPointerEvent ==MotionEvent.ACTION_DOWN==>> " + action);
        }

        if (action == MotionEvent.ACTION_UP
                || action == MotionEvent.ACTION_CANCEL
                || (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_UP) {
            +Log.i("Pointer", "into onPointerEvent ==MotionEvent.ACTION_UP1==>> " + action);
            +Intent intent = new Intent("android.intent.action.TOUCH_EVENT");
            +context.sendBroadcastAsUser(intent,UserHandle.ALL);
        }

        invalidate();
    }

调用:

frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.java

public void updateSettings() {
  ...

 

if (mSystemReady) {
                int pointerLocation = Settings.System.getIntForUser(resolver,
                        Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);                
                if (mPointerLocationMode != pointerLocation) {
                    mPointerLocationMode = pointerLocation;
                    mHandler.sendEmptyMessage(pointerLocation != 0 ?
                            MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
                }
                
                Log.d(TAG, "updateSettings==>>mPointerLocationMode==>>"+mPointerLocationMode+"=pointerLocation=>>"+pointerLocation);
                +mHandler.sendEmptyMessage(MSG_ENABLE_POINTER_LOCATION_1);
}
private class PolicyHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            	   + case MSG_ENABLE_POINTER_LOCATION_1:
                   + enablePointerLocation1();
                   + break;
                case MSG_ENABLE_POINTER_LOCATION:
                    enablePointerLocation();
                    break;


                ...
private void enablePointerLocation1() {
        if (mPointerLocationView1 == null) {
            mPointerLocationView1 = new PointerLocationView1(mContext);
            mPointerLocationView1.setPrintCoords(false);
            WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT);
            lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
            lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
            if (ActivityManager.isHighEndGfx()) {
                lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
                lp.privateFlags |=
                        WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
            }
            lp.format = PixelFormat.TRANSLUCENT;
            lp.setTitle("PointerLocation");
            WindowManager wm = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
            lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
            wm.addView(mPointerLocationView1, lp);
            mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView1);
        }
    }

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值