mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 08:05:34 -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;
|
ControlButton lastControlButton = null;
|
||||||
@Override
|
//While this is called onTouch, this should only be called from a ControlButton.
|
||||||
public boolean onTouchEvent(MotionEvent ev) {
|
public boolean onTouch(MotionEvent ev) {
|
||||||
System.out.println("ON_TOUCH_LAYOUT");
|
|
||||||
if(ev.getActionMasked() == MotionEvent.ACTION_UP || ev.getActionMasked() == MotionEvent.ACTION_CANCEL){
|
if(ev.getActionMasked() == MotionEvent.ACTION_UP || ev.getActionMasked() == MotionEvent.ACTION_CANCEL){
|
||||||
if(lastControlButton != null) lastControlButton.onTouchEvent(ev);
|
if(lastControlButton != null) lastControlButton.onTouchEvent(ev);
|
||||||
lastControlButton = null;
|
lastControlButton = null;
|
||||||
@ -245,11 +244,13 @@ public class ControlLayout extends FrameLayout
|
|||||||
|
|
||||||
if(ev.getActionMasked() != MotionEvent.ACTION_MOVE) return false;
|
if(ev.getActionMasked() != MotionEvent.ACTION_MOVE) return false;
|
||||||
ArrayList<ControlButton> children = getButtonChildren();
|
ArrayList<ControlButton> children = getButtonChildren();
|
||||||
|
/*
|
||||||
Log.d("getX LAYOUT_CONTROL", String.valueOf(ev.getX()));
|
Log.d("getX LAYOUT_CONTROL", String.valueOf(ev.getX()));
|
||||||
Log.d("getY LAYOUT_CONTROL", String.valueOf(ev.getY()));
|
Log.d("getY LAYOUT_CONTROL", String.valueOf(ev.getY()));
|
||||||
Log.d("getRawX LAYOUT_CONTROL", String.valueOf(ev.getRawX()));
|
Log.d("getRawX LAYOUT_CONTROL", String.valueOf(ev.getRawX()));
|
||||||
Log.d("getRawY LAYOUT_CONTROL", String.valueOf(ev.getRawY()));
|
Log.d("getRawY LAYOUT_CONTROL", String.valueOf(ev.getRawY()));
|
||||||
|
*/
|
||||||
|
//Optimization pass to avoid looking at all children again
|
||||||
if(lastControlButton != null){
|
if(lastControlButton != null){
|
||||||
if( ev.getRawX() > lastControlButton.getX() && ev.getRawX() < lastControlButton.getX() + lastControlButton.getWidth() &&
|
if( ev.getRawX() > lastControlButton.getX() && ev.getRawX() < lastControlButton.getX() + lastControlButton.getWidth() &&
|
||||||
ev.getRawY() > lastControlButton.getY() && ev.getRawY() < lastControlButton.getY() + lastControlButton.getHeight()){
|
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()));
|
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() &&
|
if( ev.getRawX() > button.getX() && ev.getRawX() < button.getX() + button.getWidth() &&
|
||||||
ev.getRawY() > button.getY() && ev.getRawY() < button.getY() + button.getHeight()){
|
ev.getRawY() > button.getY() && ev.getRawY() < button.getY() + button.getHeight()){
|
||||||
System.out.println("FOUND ONE !");
|
System.out.println("FOUND ONE !");
|
||||||
@ -283,8 +284,5 @@ public class ControlLayout extends FrameLayout
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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;
|
isPointerOutOfBounds = true;
|
||||||
((ControlLayout) getParent()).onTouchEvent(event);
|
((ControlLayout) getParent()).onTouch(event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Else if we now are in bounds
|
//Else if we now are in bounds
|
||||||
if(isPointerOutOfBounds) {
|
if(isPointerOutOfBounds) {
|
||||||
((ControlLayout) getParent()).onTouchEvent(event);
|
((ControlLayout) getParent()).onTouch(event);
|
||||||
//RE-press the button
|
//RE-press the button
|
||||||
if(mProperties.isSwipeable && !mProperties.isToggle){
|
if(mProperties.isSwipeable && !mProperties.isToggle){
|
||||||
setHolding(true);
|
setHolding(true);
|
||||||
@ -292,7 +292,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
case MotionEvent.ACTION_UP: // 1
|
case MotionEvent.ACTION_UP: // 1
|
||||||
case MotionEvent.ACTION_CANCEL: // 3
|
case MotionEvent.ACTION_CANCEL: // 3
|
||||||
case MotionEvent.ACTION_POINTER_UP: // 6
|
case MotionEvent.ACTION_POINTER_UP: // 6
|
||||||
if(isPointerOutOfBounds) ((ControlLayout) getParent()).onTouchEvent(event);
|
if(isPointerOutOfBounds) ((ControlLayout) getParent()).onTouch(event);
|
||||||
isPointerOutOfBounds = false;
|
isPointerOutOfBounds = false;
|
||||||
|
|
||||||
if(!triggerToggle(event)) {
|
if(!triggerToggle(event)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user