0
votes

I am making an android application in which I am using onScroll gestures to increase or decrease brightness on Upward and downward scroll and on left to right scroll I am increasing and decreasing Song duration onTouch on screen, when I scroll upward and downward on screen its working fine but a little bit interruption with left to right scroll which creates problem. When I scroll left to right it works fine but some interruptions with up to down gestures which is used on screen touch. Please tell me what should I do????

Here is my code.

if (Math.abs(deltaX) < Math.abs(deltaY)) {
    if (Math.abs(deltaY) > SWIPE_THRESHOLD) {
        if (deltaY > leftSidelastX) {
            leftSidelastX = deltaY;
            upBrightness();
            Log.i("", "Left side Slide up");
        } else {
            leftSidelastX = deltaY;
            downBrightness();
            Log.i("", "Left side Slide down");
        }
    }
} else {
    if (Math.abs(deltaX) > SWIPE_THRESHOLD) {
        if (deltaX > leftSidelastX) {
            leftSidelastX = deltaX;
            leftScroll();
            Log.i("", "Left side Slide left");
        } else {
            leftSidelastX = deltaX;
            rightScroll();
            Log.i("", "Left side Slide right");
        }
    }
}
1

1 Answers

0
votes

Your outer If Else structure is the problem. When you swipe Up and down and move it a little to the side you automatically stop the swipe up/down and go to the swipe left/right.

Depending on what you want, you can either remove the If Else structure, when it should be possible to do both at the same time or you need to set a variable if you are currently swiping up and down, set this variable at begin of swiping and always ask for this variable instead. Than you need to reset it on stop swiping.

Solution 1:

if (Math.abs(deltaY) > SWIPE_THRESHOLD) {
    if (deltaY > leftSidelastX) {
        leftSidelastX = deltaY;
        upBrightness();
        Log.i("", "Left side Slide up");
    } else {
        leftSidelastX = deltaY;
        downBrightness();
        Log.i("", "Left side Slide down");
    }
}
if (Math.abs(deltaX) > SWIPE_THRESHOLD) {
    if (deltaX > leftSidelastX) {
        leftSidelastX = deltaX;
        leftScroll();
        Log.i("", "Left side Slide left");
    } else {
        leftSidelastX = deltaX;
        rightScroll();
        Log.i("", "Left side Slide right");
    }
}

Solution 2:

Create variable scroll as empty String as member variable.

if(scroll.equals("UP/DOWN"){
    if (Math.abs(deltaY) > SWIPE_THRESHOLD) {
        if (deltaY > leftSidelastX) {
            leftSidelastX = deltaY;
            upBrightness();
            Log.i("", "Left side Slide up");
        } else {
            leftSidelastX = deltaY;
            downBrightness();
            Log.i("", "Left side Slide down");
        }
    }
} else if(scroll.equals("LEFT/RIGHT")){
    if (Math.abs(deltaX) > SWIPE_THRESHOLD) {
        if (deltaX > leftSidelastX) {
            leftSidelastX = deltaX;
            leftScroll();
            Log.i("", "Left side Slide left");
        } else {
            leftSidelastX = deltaX;
            rightScroll();
            Log.i("", "Left side Slide right");
        }
    }
}else{
    if (Math.abs(deltaX) < Math.abs(deltaY)) {
        scroll = "LEFT/RIGHT";
    }else{
        scroll = "UP/DOWN";
    }
}