Android input专题–触摸事件中Split相关课程笔记

  • Post author:
  • Post category:其他


Android input专题–触摸事件中Split相关课程笔记

  1. 应用层面Activity的Window最常见控制可以通过设置windowEnableSplitTouch

    在values/styles.xml中的theme中设置, 可将theme设置给Application或者Activity,但是这个属性控制的是Window的属性。
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowEnableSplitTouch">true</item>    <!-- 加入的配置-->
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

其实Activity默认是有设置的:

  protected DecorView generateDecor(int featureId) {
        // System process doesn't have application context and in that case we need to directly use
        // the context we have. Otherwise we want the application context, so we don't cling to the
        // activity.
        Context context;
        if (mUseDecorContext) {
            Context applicationContext = getContext().getApplicationContext();
            if (applicationContext == null) {
                context = getContext();
            } else {
                context = new DecorContext(applicationContext, getContext());
                if (mTheme != -1) {
                    context.setTheme(mTheme);
                }
            }
        } else {
            context = getContext();
        }
        return new DecorView(context, featureId, this, getAttributes());
    }

    protected ViewGroup generateLayout(DecorView decor) {
        // Apply data from current theme.

     //省略部分
        if (a.getBoolean(R.styleable.Window_windowShowWallpaper, false)) {
            setFlags(FLAG_SHOW_WALLPAPER, FLAG_SHOW_WALLPAPER&(~getForcedWindowFlags()));
        }

        if (a.getBoolean(R.styleable.Window_windowEnableSplitTouch,
                getContext().getApplicationInfo().targetSdkVersion
                        >= android.os.Build.VERSION_CODES.HONEYCOMB)) {
            setFlags(FLAG_SPLIT_TOUCH, FLAG_SPLIT_TOUCH&(~getForcedWindowFlags()));
        }
//省略部分
        }

这里只是应用层面的控制,那么InputDispatcher部分是桌面处理的呢?

其实这一部分主要逻辑集中在findTouchedWindowTargetsLocked方法中对isSplit处理,

总结为以下2点:

1、只有当多指时候才存在对触摸事件进行分离的情况,如果单指压根不涉及

2、只有当触摸的原window和新window都同时支持FLAG_SPLIT_TOUCH才可以达到两个window都响应触摸事件,不然只会传递给原window

在这里插入图片描述