mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 23:59:21 -04:00
Properly takes into account if a button is swipeable.
This commit is contained in:
parent
17aa7614a8
commit
f114e82422
@ -234,9 +234,8 @@ public class ControlLayout extends FrameLayout
|
||||
}
|
||||
|
||||
ControlButton lastControlButton = null;
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
System.out.println("ON_TOUCH_LAYOUT");
|
||||
//While this is called onTouch, this should only be called from a ControlButton.
|
||||
public boolean onTouch(MotionEvent ev) {
|
||||
if(ev.getActionMasked() == MotionEvent.ACTION_UP || ev.getActionMasked() == MotionEvent.ACTION_CANCEL){
|
||||
if(lastControlButton != null) lastControlButton.onTouchEvent(ev);
|
||||
lastControlButton = null;
|
||||
@ -245,11 +244,13 @@ public class ControlLayout extends FrameLayout
|
||||
|
||||
if(ev.getActionMasked() != MotionEvent.ACTION_MOVE) return false;
|
||||
ArrayList<ControlButton> children = getButtonChildren();
|
||||
|
||||
/*
|
||||
Log.d("getX LAYOUT_CONTROL", String.valueOf(ev.getX()));
|
||||
Log.d("getY LAYOUT_CONTROL", String.valueOf(ev.getY()));
|
||||
Log.d("getRawX LAYOUT_CONTROL", String.valueOf(ev.getRawX()));
|
||||
Log.d("getRawY LAYOUT_CONTROL", String.valueOf(ev.getRawY()));
|
||||
*/
|
||||
//Optimization pass to avoid looking at all children again
|
||||
if(lastControlButton != null){
|
||||
if( ev.getRawX() > lastControlButton.getX() && ev.getRawX() < lastControlButton.getX() + lastControlButton.getWidth() &&
|
||||
ev.getRawY() > lastControlButton.getY() && ev.getRawY() < lastControlButton.getY() + lastControlButton.getHeight()){
|
||||
@ -265,7 +266,7 @@ public class ControlLayout extends FrameLayout
|
||||
Log.d("BOTTOM: LAYOUT_CONTROL", String.valueOf(button.getBottom()));
|
||||
|
||||
*/
|
||||
|
||||
if(!button.getProperties().isSwipeable) continue;
|
||||
if( ev.getRawX() > button.getX() && ev.getRawX() < button.getX() + button.getWidth() &&
|
||||
ev.getRawY() > button.getY() && ev.getRawY() < button.getY() + button.getHeight()){
|
||||
System.out.println("FOUND ONE !");
|
||||
@ -283,8 +284,5 @@ public class ControlLayout extends FrameLayout
|
||||
}
|
||||
}
|
||||
return false;
|
||||
//We actually could go through all our children here.
|
||||
//This isn't the most performance friendly stuff though.
|
||||
//return true;
|
||||
}
|
||||
}
|
||||
|
@ -265,13 +265,13 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
||||
}
|
||||
}
|
||||
isPointerOutOfBounds = true;
|
||||
((ControlLayout) getParent()).onTouchEvent(event);
|
||||
((ControlLayout) getParent()).onTouch(event);
|
||||
break;
|
||||
}
|
||||
|
||||
//Else if we now are in bounds
|
||||
if(isPointerOutOfBounds) {
|
||||
((ControlLayout) getParent()).onTouchEvent(event);
|
||||
((ControlLayout) getParent()).onTouch(event);
|
||||
//RE-press the button
|
||||
if(mProperties.isSwipeable && !mProperties.isToggle){
|
||||
setHolding(true);
|
||||
@ -292,7 +292,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
||||
case MotionEvent.ACTION_UP: // 1
|
||||
case MotionEvent.ACTION_CANCEL: // 3
|
||||
case MotionEvent.ACTION_POINTER_UP: // 6
|
||||
if(isPointerOutOfBounds) ((ControlLayout) getParent()).onTouchEvent(event);
|
||||
if(isPointerOutOfBounds) ((ControlLayout) getParent()).onTouch(event);
|
||||
isPointerOutOfBounds = false;
|
||||
|
||||
if(!triggerToggle(event)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user