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);
        }
    }

 

 

 

 

你可能感兴趣的:(android1)