环境: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();
}