mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 08:35:37 -04:00
Modified ControlButton to be more extensible.
Add support for new properties. Deprecated property *hidden* removed
This commit is contained in:
parent
77248316d6
commit
b365d8ff84
@ -17,14 +17,14 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
{
|
{
|
||||||
private Paint mRectPaint;
|
private Paint mRectPaint;
|
||||||
|
|
||||||
private GestureDetector mGestureDetector;
|
protected GestureDetector mGestureDetector;
|
||||||
private ControlData mProperties;
|
protected ControlData mProperties;
|
||||||
private SelectionEndHandleView mHandleView;
|
protected SelectionEndHandleView mHandleView;
|
||||||
|
|
||||||
private boolean mModifiable = false;
|
protected boolean mModifiable = false;
|
||||||
private boolean mCanTriggerLongClick = true;
|
protected boolean mCanTriggerLongClick = true;
|
||||||
|
|
||||||
private boolean mChecked = false;
|
protected boolean mChecked = false;
|
||||||
|
|
||||||
public ControlButton(ControlLayout layout, ControlData properties) {
|
public ControlButton(ControlLayout layout, ControlData properties) {
|
||||||
super(layout.getContext());
|
super(layout.getContext());
|
||||||
@ -61,7 +61,6 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
|
|
||||||
public void setProperties(ControlData properties, boolean changePos) {
|
public void setProperties(ControlData properties, boolean changePos) {
|
||||||
mProperties = properties;
|
mProperties = properties;
|
||||||
mProperties.opacity = mProperties.hidden ? 1 : mProperties.opacity;
|
|
||||||
|
|
||||||
properties.update();
|
properties.update();
|
||||||
|
|
||||||
@ -73,13 +72,6 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
setTranslationY(moveY = properties.y);
|
setTranslationY(moveY = properties.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
GradientDrawable gd = new GradientDrawable();
|
|
||||||
gd.setColor(mProperties.bgColor);
|
|
||||||
gd.setStroke(mProperties.strokeWidth, mProperties.strokeColor);
|
|
||||||
gd.setCornerRadius(mProperties.cornerRadius);
|
|
||||||
setBackground(gd);
|
|
||||||
|
|
||||||
|
|
||||||
if (properties.specialButtonListener == null) {
|
if (properties.specialButtonListener == null) {
|
||||||
// A non-special button or inside custom controls screen so skip listener
|
// A non-special button or inside custom controls screen so skip listener
|
||||||
} else if (properties.specialButtonListener instanceof View.OnClickListener) {
|
} else if (properties.specialButtonListener instanceof View.OnClickListener) {
|
||||||
@ -97,12 +89,33 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
setLayoutParams(new FrameLayout.LayoutParams((int) properties.width, (int) properties.height));
|
setLayoutParams(new FrameLayout.LayoutParams((int) properties.width, (int) properties.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setBackground(){
|
||||||
|
GradientDrawable gd = new GradientDrawable();
|
||||||
|
gd.setColor(mProperties.bgColor);
|
||||||
|
gd.setStroke(computeStrokeWidth(mProperties.strokeWidth), mProperties.strokeColor);
|
||||||
|
gd.setCornerRadius(computeCornerRadius(mProperties.cornerRadius));
|
||||||
|
|
||||||
|
setBackground(gd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int computeStrokeWidth(float widthInPercent){
|
||||||
|
float maxSize = Math.max(mProperties.width, mProperties.height);
|
||||||
|
return (int)((maxSize/2) * (widthInPercent/100));
|
||||||
|
}
|
||||||
|
|
||||||
|
public float computeCornerRadius(float radiusInPercent){
|
||||||
|
float minSize = Math.min(mProperties.width, mProperties.height);
|
||||||
|
return (minSize/2) * (radiusInPercent/100);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLayoutParams(ViewGroup.LayoutParams params) {
|
public void setLayoutParams(ViewGroup.LayoutParams params) {
|
||||||
super.setLayoutParams(params);
|
super.setLayoutParams(params);
|
||||||
|
|
||||||
mProperties.width = params.width;
|
mProperties.width = params.width;
|
||||||
mProperties.height = params.height;
|
mProperties.height = params.height;
|
||||||
|
setBackground();
|
||||||
|
|
||||||
|
|
||||||
// Re-calculate position
|
// Re-calculate position
|
||||||
mProperties.update();
|
mProperties.update();
|
||||||
@ -147,7 +160,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View p1) {
|
public boolean onLongClick(View v) {
|
||||||
if (mCanTriggerLongClick && mModifiable) {
|
if (mCanTriggerLongClick && mModifiable) {
|
||||||
if (mHandleView.isShowing()) {
|
if (mHandleView.isShowing()) {
|
||||||
mHandleView.hide();
|
mHandleView.hide();
|
||||||
@ -157,7 +170,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mHandleView.show();
|
mHandleView.show(this);
|
||||||
} catch (Throwable th) {
|
} catch (Throwable th) {
|
||||||
th.printStackTrace();
|
th.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -167,6 +180,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
return mCanTriggerLongClick;
|
return mCanTriggerLongClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setHolding(boolean isDown) {
|
private void setHolding(boolean isDown) {
|
||||||
if (mProperties.holdAlt) {
|
if (mProperties.holdAlt) {
|
||||||
CallbackBridge.holdingAlt = isDown;
|
CallbackBridge.holdingAlt = isDown;
|
||||||
@ -191,8 +205,8 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private float moveX, moveY;
|
protected float moveX, moveY;
|
||||||
private float downX, downY;
|
protected float downX, downY;
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
if (!mModifiable) {
|
if (!mModifiable) {
|
||||||
@ -261,7 +275,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
return super.onTouchEvent(event);
|
return super.onTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendKeyPresses(MotionEvent event, boolean isDown){
|
public void sendKeyPresses(MotionEvent event, boolean isDown){
|
||||||
for(int keycode : mProperties.keycodes){
|
for(int keycode : mProperties.keycodes){
|
||||||
if(keycode >= 0){
|
if(keycode >= 0){
|
||||||
MainActivity.sendKeyPress(keycode, CallbackBridge.getCurrentMods(), isDown);
|
MainActivity.sendKeyPress(keycode, CallbackBridge.getCurrentMods(), isDown);
|
||||||
|
@ -79,8 +79,6 @@ public class ControlData implements Cloneable
|
|||||||
public int strokeWidth;
|
public int strokeWidth;
|
||||||
public float cornerRadius;
|
public float cornerRadius;
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public boolean hidden;
|
|
||||||
public boolean holdCtrl;
|
public boolean holdCtrl;
|
||||||
public boolean holdAlt;
|
public boolean holdAlt;
|
||||||
public boolean holdShift;
|
public boolean holdShift;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user