Android Pointer location功能研究

56 篇文章 0 订阅
51 篇文章 2 订阅

frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java

private void enablePointerLocation() {
    if (mPointerLocationView != null) {
        return;
    }

    mPointerLocationView = new PointerLocationView(mContext);
    mPointerLocationView.setPrintCoords(false);
    final 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;
    lp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
    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 - display " + getDisplayId());
    lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
    final WindowManager wm = mContext.getSystemService(WindowManager.class);
    wm.addView(mPointerLocationView, lp);
    mDisplayContent.registerPointerEventListener(mPointerLocationView);
}

private void disablePointerLocation() {
    if (mPointerLocationView == null) {
        return;
    }

    mDisplayContent.unregisterPointerEventListener(mPointerLocationView);
    final WindowManager wm = mContext.getSystemService(WindowManager.class);
    wm.removeView(mPointerLocationView);
    mPointerLocationView = null;
}

主要就是通过 WindowManager 添加了一个 PointerLocationView

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值