android14Launcher3屏蔽上拉手势唤出应用抽屉

环境:android14,launcher3;
客户需求:距离底部较近的一段距离内屏蔽上拉手势唤出应用抽屉。
追踪上拉行为触发的代码执行流程,决定在一下代码中进行修改:
packages/apps/Launcher3/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
在调试过程中可以发现,launcher的桌面是一个y轴倒过来的坐标系,且纵坐标是从屏幕顶部到底部逐渐减小。一下修改中thresholdY坐标位置以下的部分,是无法触发唤出应用抽屉的。
public boolean onControllerInterceptTouchEvent(MotionEvent ev)方法中对上拉事件进行处理,修改部分已添加注释说明,其余代码为源码部分

//添加全局变量
float initialTouchY = 0;//add by Xu-24 : Record the initial position of the touch swipe
@Override
public boolean onControllerInterceptTouchEvent(MotionEvent ev) {

    //start add by Xu-24: If you swipe up below the bottom height y of the screen, the app list is not pulled up
    final int screenHeight = mLauncher.getResources().getDisplayMetrics().heightPixels;
    final float startY = ev.getY(); // Gets the Y position where the slide begins
    // The height of the bottom of the screen y, according to the distance of the bottom of the screen y, the pull-up event will not pull out the list of apps
    final float y = screenHeight * 0.18f;
    final float thresholdY = screenHeight - y; // Allows pull-up to bring up the maximum coordinates of the app list


    // In the case of ACTION_DOWN events, record the location of the first touch
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        initialTouchY = startY;
    }

    // If it's a ACTION_MOVE event, determine the direction of the slide
    if (ev.getAction() == MotionEvent.ACTION_MOVE) {
        float deltaY = startY - initialTouchY; // Calculate the shift difference
        // If you swipe up below the bottom height y of the screen, the app list is not pulled up
        if (initialTouchY > thresholdY && deltaY < 0) {
            return false;
        }
    }
    //end by Xu-24


    
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        mNoIntercept = !canInterceptTouch(ev);
        if (mNoIntercept) {
            return false;
        }

        // Now figure out which direction scroll events the controller will start
        // calling the callbacks.
        final int directionsToDetectScroll;
        boolean ignoreSlopWhenSettling = false;

        if (mCurrentAnimation != null) {
            directionsToDetectScroll = SingleAxisSwipeDetector.DIRECTION_BOTH;
            ignoreSlopWhenSettling = true;
        } else {
            directionsToDetectScroll = getSwipeDirection();
            if (directionsToDetectScroll == 0) {
                mNoIntercept = true;
                return false;
            }
        }
        mDetector.setDetectableScrollConditions(
                directionsToDetectScroll, ignoreSlopWhenSettling);
    }

    if (mNoIntercept) {
        return false;
    }

    onControllerTouchEvent(ev);
    return mDetector.isDraggingOrSettling();
}
  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值