上下半屏调节音量,半屏调节亮度

Half screen swipe up and down for volume and half for brightness

我想了解用户是在屏幕右侧还是左侧滑动。我想提高音量是用户在屏幕右侧向上滑动,如果用户在屏幕左侧滑动则增加亮度。我能够阅读 向上、向下和向右、向左滑动,但我想阅读 swipeUpRight、swipeDownRight 和 swipeUpLeft、swipeDownLeft

private final class GestureListener extends SimpleOnGestureListener {

        private static final int SWIPE_THRESHOLD = 100;
        private static final int SWIPE_VELOCITY_THRESHOLD = 100;

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            boolean result = false;
            try {
                float diffY = e2.getY() - e1.getY();
                float diffX = e2.getX() - e1.getX();
                /*Log.e("TAG", "Y: " + e1.getY() + " , " + e2.getY());
                Log.e("TAG", "diffY: " + diffY);
                Log.e("TAG", "X: " + e1.getX() + " , " + e2.getX());*/
                Log.e("TAG", "X: " + Math.abs(diffX));
                Log.e("TAG", "Y: " + Math.abs(diffY));
                if (Math.abs(diffX) > Math.abs(diffY)) {
                    if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
                        if (diffX > 0) {
                            onSwipeRight();
                        } else {
                            onSwipeLeft();
                        }
                        result = true;
                    }
                } else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
                    if (diffY > 0) {
                        onSwipeBottomRight();
                    } else {
                        onSwipeTopRight();
                    }
                    result = true;
                }
            } catch (Exception exception) {
                exception.printStackTrace();
            }
            return result;
        }
    }

你有没有试过这些方法:

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
   int halfWidth = getWindow().getDecorView().getWidth() / 2;
    if (e1.getX() < halfWidth) {
      //leftSide code
    else{
      //rightSide code
    }
}