mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-21 20:13:06 +00:00
Android Studio auto-reformat of new virtual controller code
This commit is contained in:
parent
b6bd48584f
commit
2736bd9165
@ -18,13 +18,21 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class AnalogStick extends VirtualControllerElement {
|
public class AnalogStick extends VirtualControllerElement {
|
||||||
|
|
||||||
/** outer radius size in percent of the ui element */
|
/**
|
||||||
|
* outer radius size in percent of the ui element
|
||||||
|
*/
|
||||||
public static final int SIZE_RADIUS_COMPLETE = 90;
|
public static final int SIZE_RADIUS_COMPLETE = 90;
|
||||||
/** analog stick size in percent of the ui element */
|
/**
|
||||||
|
* analog stick size in percent of the ui element
|
||||||
|
*/
|
||||||
public static final int SIZE_RADIUS_ANALOG_STICK = 90;
|
public static final int SIZE_RADIUS_ANALOG_STICK = 90;
|
||||||
/** dead zone size in percent of the ui element */
|
/**
|
||||||
|
* dead zone size in percent of the ui element
|
||||||
|
*/
|
||||||
public static final int SIZE_RADIUS_DEADZONE = 90;
|
public static final int SIZE_RADIUS_DEADZONE = 90;
|
||||||
/** time frame for a double click */
|
/**
|
||||||
|
* time frame for a double click
|
||||||
|
*/
|
||||||
public final static long timeoutDoubleClick = 250;
|
public final static long timeoutDoubleClick = 250;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,6 +42,7 @@ public class AnalogStick extends VirtualControllerElement {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* onMovement event will be fired on real analog stick movement (outside of the deadzone).
|
* onMovement event will be fired on real analog stick movement (outside of the deadzone).
|
||||||
|
*
|
||||||
* @param x horizontal position, value from -1.0 ... 0 .. 1.0
|
* @param x horizontal position, value from -1.0 ... 0 .. 1.0
|
||||||
* @param y vertical position, value from -1.0 ... 0 .. 1.0
|
* @param y vertical position, value from -1.0 ... 0 .. 1.0
|
||||||
*/
|
*/
|
||||||
@ -73,35 +82,47 @@ public class AnalogStick extends VirtualControllerElement {
|
|||||||
DOUBLE
|
DOUBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
/** configuration if the analog stick should be displayed as circle or square*/
|
/**
|
||||||
|
* configuration if the analog stick should be displayed as circle or square
|
||||||
|
*/
|
||||||
private boolean circle_stick = true; // TODO: implement square sick for simulations
|
private boolean circle_stick = true; // TODO: implement square sick for simulations
|
||||||
|
|
||||||
/** outer radius, this size will be automatically updated on resize */
|
/**
|
||||||
private float radius_complete = 0;
|
* outer radius, this size will be automatically updated on resize
|
||||||
/** analog stick radius, this size will be automatically updated on resize */
|
*/
|
||||||
|
private float radius_complete = 0;
|
||||||
|
/**
|
||||||
|
* analog stick radius, this size will be automatically updated on resize
|
||||||
|
*/
|
||||||
private float radius_analog_stick = 0;
|
private float radius_analog_stick = 0;
|
||||||
/** dead zone radius, this size will be automatically updated on resize */
|
/**
|
||||||
private float radius_dead_zone = 0;
|
* dead zone radius, this size will be automatically updated on resize
|
||||||
|
*/
|
||||||
|
private float radius_dead_zone = 0;
|
||||||
|
|
||||||
/** horizontal position in relation to the center of the element */
|
/**
|
||||||
|
* horizontal position in relation to the center of the element
|
||||||
|
*/
|
||||||
private float relative_x = 0;
|
private float relative_x = 0;
|
||||||
/** vertical position in relation to the center of the element */
|
/**
|
||||||
|
* vertical position in relation to the center of the element
|
||||||
|
*/
|
||||||
private float relative_y = 0;
|
private float relative_y = 0;
|
||||||
|
|
||||||
|
|
||||||
private double movement_radius = 0;
|
private double movement_radius = 0;
|
||||||
private double movement_angle = 0;
|
private double movement_angle = 0;
|
||||||
|
|
||||||
private float position_stick_x = 0;
|
private float position_stick_x = 0;
|
||||||
private float position_stick_y = 0;
|
private float position_stick_y = 0;
|
||||||
|
|
||||||
private Paint paint = new Paint();
|
private Paint paint = new Paint();
|
||||||
|
|
||||||
private STICK_STATE stick_state = STICK_STATE.NO_MOVEMENT;
|
private STICK_STATE stick_state = STICK_STATE.NO_MOVEMENT;
|
||||||
private CLICK_STATE click_state = CLICK_STATE.SINGLE;
|
private CLICK_STATE click_state = CLICK_STATE.SINGLE;
|
||||||
|
|
||||||
private List<AnalogStickListener> listeners = new ArrayList<>();
|
private List<AnalogStickListener> listeners = new ArrayList<>();
|
||||||
private long timeLastClick = 0;
|
private long timeLastClick = 0;
|
||||||
|
|
||||||
private static double getMovementRadius(float x, float y) {
|
private static double getMovementRadius(float x, float y) {
|
||||||
// corner cases
|
// corner cases
|
||||||
@ -147,16 +168,16 @@ public class AnalogStick extends VirtualControllerElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnalogStick(VirtualController controller, Context context) {
|
public AnalogStick(VirtualController controller, Context context) {
|
||||||
super(controller, context);
|
super(controller, context);
|
||||||
// reset stick position
|
// reset stick position
|
||||||
position_stick_x = getWidth() / 2;
|
position_stick_x = getWidth() / 2;
|
||||||
position_stick_y = getHeight() / 2;
|
position_stick_y = getHeight() / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAnalogStickListener(AnalogStickListener listener) {
|
public void addAnalogStickListener(AnalogStickListener listener) {
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyOnMovement(float x, float y) {
|
private void notifyOnMovement(float x, float y) {
|
||||||
_DBG("movement x: " + x + " movement y: " + y);
|
_DBG("movement x: " + x + " movement y: " + y);
|
||||||
@ -190,65 +211,65 @@ public class AnalogStick extends VirtualControllerElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColors(int normalColor, int pressedColor) {
|
public void setColors(int normalColor, int pressedColor) {
|
||||||
this.normalColor = normalColor;
|
this.normalColor = normalColor;
|
||||||
this.pressedColor = pressedColor;
|
this.pressedColor = pressedColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
// calculate new radius sizes depending
|
// calculate new radius sizes depending
|
||||||
radius_complete = getPercent(getCorrectWidth() / 2, 90);
|
radius_complete = getPercent(getCorrectWidth() / 2, 90);
|
||||||
radius_dead_zone = getPercent(getCorrectWidth() / 2, 30);
|
radius_dead_zone = getPercent(getCorrectWidth() / 2, 30);
|
||||||
radius_analog_stick = getPercent(getCorrectWidth() / 2, 20);
|
radius_analog_stick = getPercent(getCorrectWidth() / 2, 20);
|
||||||
|
|
||||||
super.onSizeChanged(w, h, oldw, oldh);
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onElementDraw(Canvas canvas) {
|
protected void onElementDraw(Canvas canvas) {
|
||||||
// set transparent background
|
// set transparent background
|
||||||
canvas.drawColor(Color.TRANSPARENT);
|
canvas.drawColor(Color.TRANSPARENT);
|
||||||
|
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
paint.setStrokeWidth(getPercent(getCorrectWidth() / 2, 2));
|
paint.setStrokeWidth(getPercent(getCorrectWidth() / 2, 2));
|
||||||
|
|
||||||
// draw outer circle
|
// draw outer circle
|
||||||
if (!isPressed() || click_state == CLICK_STATE.SINGLE) {
|
if (!isPressed() || click_state == CLICK_STATE.SINGLE) {
|
||||||
paint.setColor(normalColor);
|
paint.setColor(normalColor);
|
||||||
} else {
|
} else {
|
||||||
paint.setColor(pressedColor);
|
paint.setColor(pressedColor);
|
||||||
}
|
}
|
||||||
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_complete, paint);
|
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_complete, paint);
|
||||||
|
|
||||||
paint.setColor(normalColor);
|
paint.setColor(normalColor);
|
||||||
// draw dead zone
|
// draw dead zone
|
||||||
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_dead_zone, paint);
|
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_dead_zone, paint);
|
||||||
|
|
||||||
// draw stick depending on state
|
// draw stick depending on state
|
||||||
switch (stick_state) {
|
switch (stick_state) {
|
||||||
case NO_MOVEMENT: {
|
case NO_MOVEMENT: {
|
||||||
paint.setColor(normalColor);
|
paint.setColor(normalColor);
|
||||||
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_analog_stick, paint);
|
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_analog_stick, paint);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MOVED_IN_DEAD_ZONE: {
|
case MOVED_IN_DEAD_ZONE: {
|
||||||
paint.setColor(normalColor);
|
paint.setColor(normalColor);
|
||||||
canvas.drawCircle(position_stick_x, position_stick_y, radius_analog_stick, paint);
|
canvas.drawCircle(position_stick_x, position_stick_y, radius_analog_stick, paint);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MOVED_ACTIVE: {
|
case MOVED_ACTIVE: {
|
||||||
paint.setColor(pressedColor);
|
paint.setColor(pressedColor);
|
||||||
canvas.drawCircle(position_stick_x, position_stick_y, radius_analog_stick, paint);
|
canvas.drawCircle(position_stick_x, position_stick_y, radius_analog_stick, paint);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePosition() {
|
private void updatePosition() {
|
||||||
// get 100% way
|
// get 100% way
|
||||||
float complete = (radius_complete - radius_analog_stick - radius_dead_zone);
|
float complete = (radius_complete - radius_analog_stick - radius_dead_zone);
|
||||||
|
|
||||||
// calculate relative way
|
// calculate relative way
|
||||||
float correlated_y = (float) (Math.sin(Math.PI / 2 - movement_angle) * (movement_radius));
|
float correlated_y = (float) (Math.sin(Math.PI / 2 - movement_angle) * (movement_radius));
|
||||||
@ -267,21 +288,21 @@ public class AnalogStick extends VirtualControllerElement {
|
|||||||
notifyOnMovement(-(1 / complete) *
|
notifyOnMovement(-(1 / complete) *
|
||||||
(correlated_x - (correlated_x > 0 ? radius_dead_zone : -radius_dead_zone)), (1 / complete) *
|
(correlated_x - (correlated_x > 0 ? radius_dead_zone : -radius_dead_zone)), (1 / complete) *
|
||||||
(correlated_y - (correlated_y > 0 ? radius_dead_zone : -radius_dead_zone)));
|
(correlated_y - (correlated_y > 0 ? radius_dead_zone : -radius_dead_zone)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onElementTouchEvent(MotionEvent event) {
|
public boolean onElementTouchEvent(MotionEvent event) {
|
||||||
// save last click state
|
// save last click state
|
||||||
CLICK_STATE lastClickState = click_state;
|
CLICK_STATE lastClickState = click_state;
|
||||||
|
|
||||||
// get absolute way for each axis
|
// get absolute way for each axis
|
||||||
relative_x = -(getWidth() / 2 - event.getX());
|
relative_x = -(getWidth() / 2 - event.getX());
|
||||||
relative_y = -(getHeight() / 2 - event.getY());
|
relative_y = -(getHeight() / 2 - event.getY());
|
||||||
|
|
||||||
// get radius and angel of movement from center
|
// get radius and angel of movement from center
|
||||||
movement_radius = getMovementRadius(relative_x, relative_y);
|
movement_radius = getMovementRadius(relative_x, relative_y);
|
||||||
movement_angle = getAngle(relative_x, relative_y);
|
movement_angle = getAngle(relative_x, relative_y);
|
||||||
|
|
||||||
// chop radius if out of outer circle and already pressed
|
// chop radius if out of outer circle and already pressed
|
||||||
if (movement_radius > (radius_complete - radius_analog_stick)) {
|
if (movement_radius > (radius_complete - radius_analog_stick)) {
|
||||||
@ -293,7 +314,7 @@ public class AnalogStick extends VirtualControllerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handle event depending on action
|
// handle event depending on action
|
||||||
switch (event.getActionMasked()) {
|
switch (event.getActionMasked()) {
|
||||||
// down event (touch event)
|
// down event (touch event)
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
case MotionEvent.ACTION_POINTER_DOWN: {
|
case MotionEvent.ACTION_POINTER_DOWN: {
|
||||||
@ -322,18 +343,18 @@ public class AnalogStick extends VirtualControllerElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPressed()) {
|
if (isPressed()) {
|
||||||
// when is pressed calculate new positions (will trigger movement if necessary)
|
// when is pressed calculate new positions (will trigger movement if necessary)
|
||||||
updatePosition();
|
updatePosition();
|
||||||
} else {
|
} else {
|
||||||
stick_state = STICK_STATE.NO_MOVEMENT;
|
stick_state = STICK_STATE.NO_MOVEMENT;
|
||||||
notifyOnRevoke();
|
notifyOnRevoke();
|
||||||
// not longer pressed reset analog stick
|
// not longer pressed reset analog stick
|
||||||
notifyOnMovement(0, 0);
|
notifyOnMovement(0, 0);
|
||||||
}
|
}
|
||||||
// refresh view
|
// refresh view
|
||||||
invalidate();
|
invalidate();
|
||||||
// accept the touch event
|
// accept the touch event
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,212 +24,212 @@ public class DigitalButton extends VirtualControllerElement {
|
|||||||
/**
|
/**
|
||||||
* Listener interface to update registered observers.
|
* Listener interface to update registered observers.
|
||||||
*/
|
*/
|
||||||
public interface DigitalButtonListener {
|
public interface DigitalButtonListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onClick event will be fired on button click.
|
* onClick event will be fired on button click.
|
||||||
*/
|
*/
|
||||||
void onClick();
|
void onClick();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onLongClick event will be fired on button long click.
|
* onLongClick event will be fired on button long click.
|
||||||
*/
|
*/
|
||||||
void onLongClick();
|
void onLongClick();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onRelease event will be fired on button unpress.
|
* onRelease event will be fired on button unpress.
|
||||||
*/
|
*/
|
||||||
void onRelease();
|
void onRelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private class TimerLongClickTimerTask extends TimerTask {
|
private class TimerLongClickTimerTask extends TimerTask {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
onLongClickCallback();
|
onLongClickCallback();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private List<DigitalButtonListener> listeners = new ArrayList<DigitalButtonListener>();
|
|
||||||
private String text = "";
|
|
||||||
private int icon = -1;
|
|
||||||
private long timerLongClickTimeout = 3000;
|
|
||||||
private Timer timerLongClick = null;
|
|
||||||
private TimerLongClickTimerTask longClickTimerTask = null;
|
|
||||||
|
|
||||||
private int layer;
|
|
||||||
private DigitalButton movingButton = null;
|
|
||||||
|
|
||||||
boolean inRange(float x, float y) {
|
|
||||||
return (this.getX() < x && this.getX() + this.getWidth() > x) &&
|
|
||||||
(this.getY() < y && this.getY() + this.getHeight() > y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean checkMovement(float x, float y, DigitalButton movingButton) {
|
|
||||||
// check if the movement happened in the same layer
|
|
||||||
if (movingButton.layer != this.layer) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// save current pressed state
|
|
||||||
boolean wasPressed = isPressed();
|
|
||||||
|
|
||||||
// check if the movement directly happened on the button
|
|
||||||
if ((this.movingButton == null || movingButton == this.movingButton)
|
|
||||||
&& this.inRange(x, y)) {
|
|
||||||
// set button pressed state depending on moving button pressed state
|
|
||||||
if (this.isPressed() != movingButton.isPressed()) {
|
|
||||||
this.setPressed(movingButton.isPressed());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// check if the movement is outside of the range and the movement button
|
|
||||||
// is the saved moving button
|
|
||||||
else if (movingButton == this.movingButton) {
|
|
||||||
this.setPressed(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if a change occurred
|
|
||||||
if (wasPressed != isPressed()) {
|
|
||||||
if (isPressed()) {
|
|
||||||
// is pressed set moving button and emit click event
|
|
||||||
this.movingButton = movingButton;
|
|
||||||
onClickCallback();
|
|
||||||
} else {
|
|
||||||
// no longer pressed reset moving button and emit release event
|
|
||||||
this.movingButton = null;
|
|
||||||
onReleaseCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
invalidate();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkMovementForAllButtons(float x, float y) {
|
|
||||||
for (VirtualControllerElement element : virtualController.getElements()) {
|
|
||||||
if (element != this && element instanceof DigitalButton){
|
|
||||||
((DigitalButton)element).checkMovement(x, y, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DigitalButton(VirtualController controller, int layer, Context context) {
|
|
||||||
super(controller, context);
|
|
||||||
this.layer = layer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDigitalButtonListener(DigitalButtonListener listener) {
|
private List<DigitalButtonListener> listeners = new ArrayList<DigitalButtonListener>();
|
||||||
|
private String text = "";
|
||||||
|
private int icon = -1;
|
||||||
|
private long timerLongClickTimeout = 3000;
|
||||||
|
private Timer timerLongClick = null;
|
||||||
|
private TimerLongClickTimerTask longClickTimerTask = null;
|
||||||
|
|
||||||
|
private int layer;
|
||||||
|
private DigitalButton movingButton = null;
|
||||||
|
|
||||||
|
boolean inRange(float x, float y) {
|
||||||
|
return (this.getX() < x && this.getX() + this.getWidth() > x) &&
|
||||||
|
(this.getY() < y && this.getY() + this.getHeight() > y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkMovement(float x, float y, DigitalButton movingButton) {
|
||||||
|
// check if the movement happened in the same layer
|
||||||
|
if (movingButton.layer != this.layer) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// save current pressed state
|
||||||
|
boolean wasPressed = isPressed();
|
||||||
|
|
||||||
|
// check if the movement directly happened on the button
|
||||||
|
if ((this.movingButton == null || movingButton == this.movingButton)
|
||||||
|
&& this.inRange(x, y)) {
|
||||||
|
// set button pressed state depending on moving button pressed state
|
||||||
|
if (this.isPressed() != movingButton.isPressed()) {
|
||||||
|
this.setPressed(movingButton.isPressed());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check if the movement is outside of the range and the movement button
|
||||||
|
// is the saved moving button
|
||||||
|
else if (movingButton == this.movingButton) {
|
||||||
|
this.setPressed(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if a change occurred
|
||||||
|
if (wasPressed != isPressed()) {
|
||||||
|
if (isPressed()) {
|
||||||
|
// is pressed set moving button and emit click event
|
||||||
|
this.movingButton = movingButton;
|
||||||
|
onClickCallback();
|
||||||
|
} else {
|
||||||
|
// no longer pressed reset moving button and emit release event
|
||||||
|
this.movingButton = null;
|
||||||
|
onReleaseCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
invalidate();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkMovementForAllButtons(float x, float y) {
|
||||||
|
for (VirtualControllerElement element : virtualController.getElements()) {
|
||||||
|
if (element != this && element instanceof DigitalButton) {
|
||||||
|
((DigitalButton) element).checkMovement(x, y, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DigitalButton(VirtualController controller, int layer, Context context) {
|
||||||
|
super(controller, context);
|
||||||
|
this.layer = layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDigitalButtonListener(DigitalButtonListener listener) {
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIcon(int id) {
|
public void setIcon(int id) {
|
||||||
this.icon = id;
|
this.icon = id;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onElementDraw(Canvas canvas) {
|
protected void onElementDraw(Canvas canvas) {
|
||||||
// set transparent background
|
// set transparent background
|
||||||
canvas.drawColor(Color.TRANSPARENT);
|
canvas.drawColor(Color.TRANSPARENT);
|
||||||
|
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
|
|
||||||
paint.setTextSize(getPercent(getCorrectWidth(), 50));
|
paint.setTextSize(getPercent(getCorrectWidth(), 50));
|
||||||
paint.setTextAlign(Paint.Align.CENTER);
|
paint.setTextAlign(Paint.Align.CENTER);
|
||||||
paint.setStrokeWidth(3);
|
paint.setStrokeWidth(3);
|
||||||
|
|
||||||
paint.setColor(isPressed() ? pressedColor : normalColor);
|
paint.setColor(isPressed() ? pressedColor : normalColor);
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
canvas.drawRect(1, 1, getWidth() - 1, getHeight() - 1, paint);
|
canvas.drawRect(1, 1, getWidth() - 1, getHeight() - 1, paint);
|
||||||
|
|
||||||
if (icon != -1) {
|
if (icon != -1) {
|
||||||
Drawable d = getResources().getDrawable(icon);
|
Drawable d = getResources().getDrawable(icon);
|
||||||
d.setBounds(5, 5, getWidth() - 5, getHeight() - 5);
|
d.setBounds(5, 5, getWidth() - 5, getHeight() - 5);
|
||||||
d.draw(canvas);
|
d.draw(canvas);
|
||||||
} else {
|
} else {
|
||||||
paint.setStyle(Paint.Style.FILL_AND_STROKE);
|
paint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||||
canvas.drawText(text, getPercent(getWidth(), 50), getPercent(getHeight(), 73), paint);
|
canvas.drawText(text, getPercent(getWidth(), 50), getPercent(getHeight(), 73), paint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onClickCallback() {
|
private void onClickCallback() {
|
||||||
_DBG("clicked");
|
_DBG("clicked");
|
||||||
// notify listeners
|
// notify listeners
|
||||||
for (DigitalButtonListener listener : listeners) {
|
for (DigitalButtonListener listener : listeners) {
|
||||||
listener.onClick();
|
listener.onClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
timerLongClick = new Timer();
|
timerLongClick = new Timer();
|
||||||
longClickTimerTask = new TimerLongClickTimerTask();
|
longClickTimerTask = new TimerLongClickTimerTask();
|
||||||
timerLongClick.schedule(longClickTimerTask, timerLongClickTimeout);
|
timerLongClick.schedule(longClickTimerTask, timerLongClickTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onLongClickCallback() {
|
private void onLongClickCallback() {
|
||||||
_DBG("long click");
|
_DBG("long click");
|
||||||
// notify listeners
|
// notify listeners
|
||||||
for (DigitalButtonListener listener : listeners) {
|
for (DigitalButtonListener listener : listeners) {
|
||||||
listener.onLongClick();
|
listener.onLongClick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onReleaseCallback() {
|
private void onReleaseCallback() {
|
||||||
_DBG("released");
|
_DBG("released");
|
||||||
// notify listeners
|
// notify listeners
|
||||||
for (DigitalButtonListener listener : listeners) {
|
for (DigitalButtonListener listener : listeners) {
|
||||||
listener.onRelease();
|
listener.onRelease();
|
||||||
}
|
}
|
||||||
timerLongClick.cancel();
|
timerLongClick.cancel();
|
||||||
longClickTimerTask.cancel();
|
longClickTimerTask.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onElementTouchEvent(MotionEvent event) {
|
public boolean onElementTouchEvent(MotionEvent event) {
|
||||||
// get masked (not specific to a pointer) action
|
// get masked (not specific to a pointer) action
|
||||||
float x = getX() + event.getX();
|
float x = getX() + event.getX();
|
||||||
float y = getY() + event.getY();
|
float y = getY() + event.getY();
|
||||||
int action = event.getActionMasked();
|
int action = event.getActionMasked();
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
case MotionEvent.ACTION_POINTER_DOWN: {
|
case MotionEvent.ACTION_POINTER_DOWN: {
|
||||||
movingButton = null;
|
movingButton = null;
|
||||||
setPressed(true);
|
setPressed(true);
|
||||||
onClickCallback();
|
onClickCallback();
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_MOVE: {
|
case MotionEvent.ACTION_MOVE: {
|
||||||
checkMovementForAllButtons(x, y);
|
checkMovementForAllButtons(x, y);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
case MotionEvent.ACTION_POINTER_UP: {
|
case MotionEvent.ACTION_POINTER_UP: {
|
||||||
setPressed(false);
|
setPressed(false);
|
||||||
onReleaseCallback();
|
onReleaseCallback();
|
||||||
|
|
||||||
checkMovementForAllButtons(x, y);
|
checkMovementForAllButtons(x, y);
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,205 +14,205 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DigitalPad extends VirtualControllerElement {
|
public class DigitalPad extends VirtualControllerElement {
|
||||||
public final static int DIGITAL_PAD_DIRECTION_NO_DIRECTION = 0;
|
public final static int DIGITAL_PAD_DIRECTION_NO_DIRECTION = 0;
|
||||||
int direction = DIGITAL_PAD_DIRECTION_NO_DIRECTION;
|
int direction = DIGITAL_PAD_DIRECTION_NO_DIRECTION;
|
||||||
public final static int DIGITAL_PAD_DIRECTION_LEFT = 1;
|
public final static int DIGITAL_PAD_DIRECTION_LEFT = 1;
|
||||||
public final static int DIGITAL_PAD_DIRECTION_UP = 2;
|
public final static int DIGITAL_PAD_DIRECTION_UP = 2;
|
||||||
public final static int DIGITAL_PAD_DIRECTION_RIGHT = 4;
|
public final static int DIGITAL_PAD_DIRECTION_RIGHT = 4;
|
||||||
public final static int DIGITAL_PAD_DIRECTION_DOWN = 8;
|
public final static int DIGITAL_PAD_DIRECTION_DOWN = 8;
|
||||||
List<DigitalPadListener> listeners = new ArrayList<DigitalPadListener>();
|
List<DigitalPadListener> listeners = new ArrayList<DigitalPadListener>();
|
||||||
|
|
||||||
public DigitalPad(VirtualController controller, Context context) {
|
public DigitalPad(VirtualController controller, Context context) {
|
||||||
super(controller, context);
|
super(controller, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDigitalPadListener(DigitalPadListener listener) {
|
public void addDigitalPadListener(DigitalPadListener listener) {
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onElementDraw(Canvas canvas) {
|
protected void onElementDraw(Canvas canvas) {
|
||||||
// set transparent background
|
// set transparent background
|
||||||
canvas.drawColor(Color.TRANSPARENT);
|
canvas.drawColor(Color.TRANSPARENT);
|
||||||
|
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
|
|
||||||
paint.setTextSize(getPercent(getCorrectWidth(), 20));
|
paint.setTextSize(getPercent(getCorrectWidth(), 20));
|
||||||
paint.setTextAlign(Paint.Align.CENTER);
|
paint.setTextAlign(Paint.Align.CENTER);
|
||||||
paint.setStrokeWidth(3);
|
paint.setStrokeWidth(3);
|
||||||
|
|
||||||
if (direction == DIGITAL_PAD_DIRECTION_NO_DIRECTION) {
|
if (direction == DIGITAL_PAD_DIRECTION_NO_DIRECTION) {
|
||||||
// draw no direction rect
|
// draw no direction rect
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
paint.setColor(normalColor);
|
paint.setColor(normalColor);
|
||||||
canvas.drawRect(
|
canvas.drawRect(
|
||||||
getPercent(getWidth(), 36), getPercent(getHeight(), 36),
|
getPercent(getWidth(), 36), getPercent(getHeight(), 36),
|
||||||
getPercent(getWidth(), 63), getPercent(getHeight(), 63),
|
getPercent(getWidth(), 63), getPercent(getHeight(), 63),
|
||||||
paint
|
paint
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw left rect
|
// draw left rect
|
||||||
paint.setColor(
|
paint.setColor(
|
||||||
(direction & DIGITAL_PAD_DIRECTION_LEFT) > 0 ? pressedColor : normalColor);
|
(direction & DIGITAL_PAD_DIRECTION_LEFT) > 0 ? pressedColor : normalColor);
|
||||||
paint.setStyle(Paint.Style.FILL_AND_STROKE);
|
paint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||||
canvas.drawText("LF",
|
canvas.drawText("LF",
|
||||||
getPercent(getWidth(), 16.5f), getPercent(getHeight(), 56),
|
getPercent(getWidth(), 16.5f), getPercent(getHeight(), 56),
|
||||||
paint);
|
paint);
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
canvas.drawRect(
|
canvas.drawRect(
|
||||||
0, getPercent(getHeight(), 33),
|
0, getPercent(getHeight(), 33),
|
||||||
getPercent(getWidth(), 33), getPercent(getHeight(), 66),
|
getPercent(getWidth(), 33), getPercent(getHeight(), 66),
|
||||||
paint
|
paint
|
||||||
);
|
);
|
||||||
|
|
||||||
// draw left up line
|
// draw left up line
|
||||||
paint.setColor((
|
paint.setColor((
|
||||||
(direction & DIGITAL_PAD_DIRECTION_LEFT) > 0 &&
|
(direction & DIGITAL_PAD_DIRECTION_LEFT) > 0 &&
|
||||||
(direction & DIGITAL_PAD_DIRECTION_UP) > 0
|
(direction & DIGITAL_PAD_DIRECTION_UP) > 0
|
||||||
) ? pressedColor : normalColor
|
) ? pressedColor : normalColor
|
||||||
);
|
);
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
canvas.drawLine(
|
canvas.drawLine(
|
||||||
0, getPercent(getHeight(), 33),
|
0, getPercent(getHeight(), 33),
|
||||||
getPercent(getWidth(), 33), 0,
|
getPercent(getWidth(), 33), 0,
|
||||||
paint
|
paint
|
||||||
);
|
);
|
||||||
|
|
||||||
// draw up rect
|
// draw up rect
|
||||||
paint.setColor(
|
paint.setColor(
|
||||||
(direction & DIGITAL_PAD_DIRECTION_UP) > 0 ? pressedColor : normalColor);
|
(direction & DIGITAL_PAD_DIRECTION_UP) > 0 ? pressedColor : normalColor);
|
||||||
paint.setStyle(Paint.Style.FILL_AND_STROKE);
|
paint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||||
canvas.drawText("UP",
|
canvas.drawText("UP",
|
||||||
getPercent(getWidth(), 49.5f), getPercent(getHeight(), 23),
|
getPercent(getWidth(), 49.5f), getPercent(getHeight(), 23),
|
||||||
paint);
|
paint);
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
canvas.drawRect(
|
canvas.drawRect(
|
||||||
getPercent(getWidth(), 33), 0,
|
getPercent(getWidth(), 33), 0,
|
||||||
getPercent(getWidth(), 66), getPercent(getHeight(), 33),
|
getPercent(getWidth(), 66), getPercent(getHeight(), 33),
|
||||||
paint
|
paint
|
||||||
);
|
);
|
||||||
|
|
||||||
// draw up right line
|
// draw up right line
|
||||||
paint.setColor((
|
paint.setColor((
|
||||||
(direction & DIGITAL_PAD_DIRECTION_UP) > 0 &&
|
(direction & DIGITAL_PAD_DIRECTION_UP) > 0 &&
|
||||||
(direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0
|
(direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0
|
||||||
) ? pressedColor : normalColor
|
) ? pressedColor : normalColor
|
||||||
);
|
);
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
canvas.drawLine(
|
canvas.drawLine(
|
||||||
getPercent(getWidth(), 66), 0,
|
getPercent(getWidth(), 66), 0,
|
||||||
getPercent(getWidth(), 100), getPercent(getHeight(), 33),
|
getPercent(getWidth(), 100), getPercent(getHeight(), 33),
|
||||||
paint
|
paint
|
||||||
);
|
);
|
||||||
|
|
||||||
// draw right rect
|
// draw right rect
|
||||||
paint.setColor(
|
paint.setColor(
|
||||||
(direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0 ? pressedColor : normalColor);
|
(direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0 ? pressedColor : normalColor);
|
||||||
paint.setStyle(Paint.Style.FILL_AND_STROKE);
|
paint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||||
canvas.drawText("RI",
|
canvas.drawText("RI",
|
||||||
getPercent(getWidth(), 82.5f), getPercent(getHeight(), 56),
|
getPercent(getWidth(), 82.5f), getPercent(getHeight(), 56),
|
||||||
paint);
|
paint);
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
canvas.drawRect(
|
canvas.drawRect(
|
||||||
getPercent(getWidth(), 66), getPercent(getHeight(), 33),
|
getPercent(getWidth(), 66), getPercent(getHeight(), 33),
|
||||||
getPercent(getWidth(), 100), getPercent(getHeight(), 66),
|
getPercent(getWidth(), 100), getPercent(getHeight(), 66),
|
||||||
paint
|
paint
|
||||||
);
|
);
|
||||||
|
|
||||||
// draw right down line
|
// draw right down line
|
||||||
paint.setColor((
|
paint.setColor((
|
||||||
(direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0 &&
|
(direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0 &&
|
||||||
(direction & DIGITAL_PAD_DIRECTION_DOWN) > 0
|
(direction & DIGITAL_PAD_DIRECTION_DOWN) > 0
|
||||||
) ? pressedColor : normalColor
|
) ? pressedColor : normalColor
|
||||||
);
|
);
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
canvas.drawLine(
|
canvas.drawLine(
|
||||||
getPercent(getWidth(), 100), getPercent(getHeight(), 66),
|
getPercent(getWidth(), 100), getPercent(getHeight(), 66),
|
||||||
getPercent(getWidth(), 66), getPercent(getHeight(), 100),
|
getPercent(getWidth(), 66), getPercent(getHeight(), 100),
|
||||||
paint
|
paint
|
||||||
);
|
);
|
||||||
|
|
||||||
// draw down rect
|
// draw down rect
|
||||||
paint.setColor(
|
paint.setColor(
|
||||||
(direction & DIGITAL_PAD_DIRECTION_DOWN) > 0 ? pressedColor : normalColor);
|
(direction & DIGITAL_PAD_DIRECTION_DOWN) > 0 ? pressedColor : normalColor);
|
||||||
paint.setStyle(Paint.Style.FILL_AND_STROKE);
|
paint.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||||
canvas.drawText("DW",
|
canvas.drawText("DW",
|
||||||
getPercent(getWidth(), 49.5f), getPercent(getHeight(), 89),
|
getPercent(getWidth(), 49.5f), getPercent(getHeight(), 89),
|
||||||
paint);
|
paint);
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
canvas.drawRect(
|
canvas.drawRect(
|
||||||
getPercent(getWidth(), 33), getPercent(getHeight(), 66),
|
getPercent(getWidth(), 33), getPercent(getHeight(), 66),
|
||||||
getPercent(getWidth(), 66), getPercent(getHeight(), 100),
|
getPercent(getWidth(), 66), getPercent(getHeight(), 100),
|
||||||
paint
|
paint
|
||||||
);
|
);
|
||||||
|
|
||||||
// draw down left line
|
// draw down left line
|
||||||
paint.setColor((
|
paint.setColor((
|
||||||
(direction & DIGITAL_PAD_DIRECTION_DOWN) > 0 &&
|
(direction & DIGITAL_PAD_DIRECTION_DOWN) > 0 &&
|
||||||
(direction & DIGITAL_PAD_DIRECTION_LEFT) > 0
|
(direction & DIGITAL_PAD_DIRECTION_LEFT) > 0
|
||||||
) ? pressedColor : normalColor
|
) ? pressedColor : normalColor
|
||||||
);
|
);
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
canvas.drawLine(
|
canvas.drawLine(
|
||||||
getPercent(getWidth(), 33), getPercent(getHeight(), 100),
|
getPercent(getWidth(), 33), getPercent(getHeight(), 100),
|
||||||
getPercent(getWidth(), 0), getPercent(getHeight(), 66),
|
getPercent(getWidth(), 0), getPercent(getHeight(), 66),
|
||||||
paint
|
paint
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void newDirectionCallback(int direction) {
|
private void newDirectionCallback(int direction) {
|
||||||
_DBG("direction: " + direction);
|
_DBG("direction: " + direction);
|
||||||
|
|
||||||
// notify listeners
|
// notify listeners
|
||||||
for (DigitalPadListener listener : listeners) {
|
for (DigitalPadListener listener : listeners) {
|
||||||
listener.onDirectionChange(direction);
|
listener.onDirectionChange(direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onElementTouchEvent(MotionEvent event) {
|
public boolean onElementTouchEvent(MotionEvent event) {
|
||||||
// get masked (not specific to a pointer) action
|
// get masked (not specific to a pointer) action
|
||||||
switch (event.getActionMasked()) {
|
switch (event.getActionMasked()) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
case MotionEvent.ACTION_POINTER_DOWN:
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
case MotionEvent.ACTION_MOVE: {
|
case MotionEvent.ACTION_MOVE: {
|
||||||
direction = 0;
|
direction = 0;
|
||||||
|
|
||||||
if (event.getX() < getPercent(getWidth(), 33)) {
|
if (event.getX() < getPercent(getWidth(), 33)) {
|
||||||
direction |= DIGITAL_PAD_DIRECTION_LEFT;
|
direction |= DIGITAL_PAD_DIRECTION_LEFT;
|
||||||
}
|
}
|
||||||
if (event.getX() > getPercent(getWidth(), 66)) {
|
if (event.getX() > getPercent(getWidth(), 66)) {
|
||||||
direction |= DIGITAL_PAD_DIRECTION_RIGHT;
|
direction |= DIGITAL_PAD_DIRECTION_RIGHT;
|
||||||
}
|
}
|
||||||
if (event.getY() > getPercent(getHeight(), 66)) {
|
if (event.getY() > getPercent(getHeight(), 66)) {
|
||||||
direction |= DIGITAL_PAD_DIRECTION_DOWN;
|
direction |= DIGITAL_PAD_DIRECTION_DOWN;
|
||||||
}
|
}
|
||||||
if (event.getY() < getPercent(getHeight(), 33)) {
|
if (event.getY() < getPercent(getHeight(), 33)) {
|
||||||
direction |= DIGITAL_PAD_DIRECTION_UP;
|
direction |= DIGITAL_PAD_DIRECTION_UP;
|
||||||
}
|
}
|
||||||
newDirectionCallback(direction);
|
newDirectionCallback(direction);
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
case MotionEvent.ACTION_POINTER_UP: {
|
case MotionEvent.ACTION_POINTER_UP: {
|
||||||
direction = 0;
|
direction = 0;
|
||||||
newDirectionCallback(direction);
|
newDirectionCallback(direction);
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface DigitalPadListener {
|
public interface DigitalPadListener {
|
||||||
void onDirectionChange(int direction);
|
void onDirectionChange(int direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,26 +7,27 @@ package com.limelight.binding.input.virtual_controller;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
public class LeftTrigger extends DigitalButton {
|
public class LeftTrigger extends DigitalButton {
|
||||||
public LeftTrigger(final VirtualController controller, final int layer, final Context context) {
|
public LeftTrigger(final VirtualController controller, final int layer, final Context context) {
|
||||||
super(controller, layer, context);
|
super(controller, layer, context);
|
||||||
addDigitalButtonListener(new DigitalButton.DigitalButtonListener() {
|
addDigitalButtonListener(new DigitalButton.DigitalButtonListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
VirtualController.ControllerInputContext inputContext =
|
VirtualController.ControllerInputContext inputContext =
|
||||||
controller.getControllerInputContext();
|
controller.getControllerInputContext();
|
||||||
inputContext.leftTrigger = (byte)0xFF;
|
inputContext.leftTrigger = (byte) 0xFF;
|
||||||
|
|
||||||
controller.sendControllerInputContext();
|
controller.sendControllerInputContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLongClick() {}
|
public void onLongClick() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRelease() {
|
public void onRelease() {
|
||||||
VirtualController.ControllerInputContext inputContext =
|
VirtualController.ControllerInputContext inputContext =
|
||||||
controller.getControllerInputContext();
|
controller.getControllerInputContext();
|
||||||
inputContext.leftTrigger = (byte)0x00;
|
inputContext.leftTrigger = (byte) 0x00;
|
||||||
|
|
||||||
controller.sendControllerInputContext();
|
controller.sendControllerInputContext();
|
||||||
}
|
}
|
||||||
|
@ -9,41 +9,41 @@ import android.content.Context;
|
|||||||
import com.limelight.nvstream.input.ControllerPacket;
|
import com.limelight.nvstream.input.ControllerPacket;
|
||||||
|
|
||||||
public class RightAnalogStick extends AnalogStick {
|
public class RightAnalogStick extends AnalogStick {
|
||||||
public RightAnalogStick(final VirtualController controller, final Context context) {
|
public RightAnalogStick(final VirtualController controller, final Context context) {
|
||||||
super(controller, context);
|
super(controller, context);
|
||||||
|
|
||||||
addAnalogStickListener(new AnalogStick.AnalogStickListener() {
|
addAnalogStickListener(new AnalogStick.AnalogStickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onMovement(float x, float y) {
|
public void onMovement(float x, float y) {
|
||||||
VirtualController.ControllerInputContext inputContext =
|
VirtualController.ControllerInputContext inputContext =
|
||||||
controller.getControllerInputContext();
|
controller.getControllerInputContext();
|
||||||
inputContext.rightStickX = (short) (x * 0x7FFE);
|
inputContext.rightStickX = (short) (x * 0x7FFE);
|
||||||
inputContext.rightStickY = (short) (y * 0x7FFE);
|
inputContext.rightStickY = (short) (y * 0x7FFE);
|
||||||
|
|
||||||
controller.sendControllerInputContext();
|
controller.sendControllerInputContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDoubleClick() {
|
public void onDoubleClick() {
|
||||||
VirtualController.ControllerInputContext inputContext =
|
VirtualController.ControllerInputContext inputContext =
|
||||||
controller.getControllerInputContext();
|
controller.getControllerInputContext();
|
||||||
inputContext.inputMap |= ControllerPacket.RS_CLK_FLAG;
|
inputContext.inputMap |= ControllerPacket.RS_CLK_FLAG;
|
||||||
|
|
||||||
controller.sendControllerInputContext();
|
controller.sendControllerInputContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRevoke() {
|
public void onRevoke() {
|
||||||
VirtualController.ControllerInputContext inputContext =
|
VirtualController.ControllerInputContext inputContext =
|
||||||
controller.getControllerInputContext();
|
controller.getControllerInputContext();
|
||||||
inputContext.inputMap &= ~ControllerPacket.RS_CLK_FLAG;
|
inputContext.inputMap &= ~ControllerPacket.RS_CLK_FLAG;
|
||||||
|
|
||||||
controller.sendControllerInputContext();
|
controller.sendControllerInputContext();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,26 +7,27 @@ package com.limelight.binding.input.virtual_controller;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
public class RightTrigger extends DigitalButton {
|
public class RightTrigger extends DigitalButton {
|
||||||
public RightTrigger(final VirtualController controller, final int layer, final Context context) {
|
public RightTrigger(final VirtualController controller, final int layer, final Context context) {
|
||||||
super(controller, layer, context);
|
super(controller, layer, context);
|
||||||
addDigitalButtonListener(new DigitalButton.DigitalButtonListener() {
|
addDigitalButtonListener(new DigitalButton.DigitalButtonListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
VirtualController.ControllerInputContext inputContext =
|
VirtualController.ControllerInputContext inputContext =
|
||||||
controller.getControllerInputContext();
|
controller.getControllerInputContext();
|
||||||
inputContext.rightTrigger = (byte)0xFF;
|
inputContext.rightTrigger = (byte) 0xFF;
|
||||||
|
|
||||||
controller.sendControllerInputContext();
|
controller.sendControllerInputContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLongClick() {}
|
public void onLongClick() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRelease() {
|
public void onRelease() {
|
||||||
VirtualController.ControllerInputContext inputContext =
|
VirtualController.ControllerInputContext inputContext =
|
||||||
controller.getControllerInputContext();
|
controller.getControllerInputContext();
|
||||||
inputContext.rightTrigger = (byte)0x00;
|
inputContext.rightTrigger = (byte) 0x00;
|
||||||
|
|
||||||
controller.sendControllerInputContext();
|
controller.sendControllerInputContext();
|
||||||
}
|
}
|
||||||
|
@ -18,132 +18,132 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class VirtualController {
|
public class VirtualController {
|
||||||
public class ControllerInputContext {
|
public class ControllerInputContext {
|
||||||
public short inputMap = 0x0000;
|
public short inputMap = 0x0000;
|
||||||
public byte leftTrigger = 0x00;
|
public byte leftTrigger = 0x00;
|
||||||
public byte rightTrigger = 0x00;
|
public byte rightTrigger = 0x00;
|
||||||
public short rightStickX = 0x0000;
|
public short rightStickX = 0x0000;
|
||||||
public short rightStickY = 0x0000;
|
public short rightStickY = 0x0000;
|
||||||
public short leftStickX = 0x0000;
|
public short leftStickX = 0x0000;
|
||||||
public short leftStickY = 0x0000;
|
public short leftStickY = 0x0000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ControllerMode {
|
public enum ControllerMode {
|
||||||
Active,
|
Active,
|
||||||
Configuration
|
Configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final boolean _PRINT_DEBUG_INFORMATION = true;
|
private static final boolean _PRINT_DEBUG_INFORMATION = true;
|
||||||
|
|
||||||
private NvConnection connection = null;
|
private NvConnection connection = null;
|
||||||
private Context context = null;
|
private Context context = null;
|
||||||
|
|
||||||
private FrameLayout frame_layout = null;
|
private FrameLayout frame_layout = null;
|
||||||
private RelativeLayout relative_layout = null;
|
private RelativeLayout relative_layout = null;
|
||||||
|
|
||||||
ControllerMode currentMode = ControllerMode.Active;
|
ControllerMode currentMode = ControllerMode.Active;
|
||||||
ControllerInputContext inputContext = new ControllerInputContext();
|
ControllerInputContext inputContext = new ControllerInputContext();
|
||||||
|
|
||||||
private RelativeLayout.LayoutParams layoutParamsButtonConfigure = null;
|
private RelativeLayout.LayoutParams layoutParamsButtonConfigure = null;
|
||||||
private Button buttonConfigure = null;
|
private Button buttonConfigure = null;
|
||||||
|
|
||||||
private List<VirtualControllerElement> elements = new ArrayList<VirtualControllerElement>();
|
private List<VirtualControllerElement> elements = new ArrayList<VirtualControllerElement>();
|
||||||
|
|
||||||
public VirtualController(final NvConnection conn, FrameLayout layout, final Context context) {
|
public VirtualController(final NvConnection conn, FrameLayout layout, final Context context) {
|
||||||
this.connection = conn;
|
this.connection = conn;
|
||||||
this.frame_layout = layout;
|
this.frame_layout = layout;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
relative_layout = new RelativeLayout(context);
|
relative_layout = new RelativeLayout(context);
|
||||||
|
|
||||||
frame_layout.addView(relative_layout);
|
frame_layout.addView(relative_layout);
|
||||||
|
|
||||||
buttonConfigure = new Button(context);
|
buttonConfigure = new Button(context);
|
||||||
buttonConfigure.setBackgroundResource(R.drawable.settings);
|
buttonConfigure.setBackgroundResource(R.drawable.settings);
|
||||||
buttonConfigure.setOnClickListener(new View.OnClickListener() {
|
buttonConfigure.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (currentMode == ControllerMode.Configuration) {
|
if (currentMode == ControllerMode.Configuration) {
|
||||||
currentMode = ControllerMode.Active;
|
currentMode = ControllerMode.Active;
|
||||||
} else {
|
} else {
|
||||||
currentMode = ControllerMode.Configuration;
|
currentMode = ControllerMode.Configuration;
|
||||||
}
|
}
|
||||||
Toast.makeText(context, "CHANGE MODE " + currentMode, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "CHANGE MODE " + currentMode, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
relative_layout.invalidate();
|
relative_layout.invalidate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeElements() {
|
public void removeElements() {
|
||||||
for (VirtualControllerElement element : elements) {
|
for (VirtualControllerElement element : elements) {
|
||||||
relative_layout.removeView(element);
|
relative_layout.removeView(element);
|
||||||
elements.remove(element);
|
elements.remove(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addElement(VirtualControllerElement element, int x, int y, int width, int height) {
|
public void addElement(VirtualControllerElement element, int x, int y, int width, int height) {
|
||||||
elements.add(element);
|
elements.add(element);
|
||||||
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, height);
|
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, height);
|
||||||
layoutParams.setMargins(x, y, 0, 0);
|
layoutParams.setMargins(x, y, 0, 0);
|
||||||
|
|
||||||
relative_layout.addView(element, layoutParams);
|
relative_layout.addView(element, layoutParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<VirtualControllerElement> getElements() {
|
public List<VirtualControllerElement> getElements() {
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void _DBG(String text) {
|
private static final void _DBG(String text) {
|
||||||
if (_PRINT_DEBUG_INFORMATION) {
|
if (_PRINT_DEBUG_INFORMATION) {
|
||||||
System.out.println("VirtualController: " + text);
|
System.out.println("VirtualController: " + text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshLayout() {
|
public void refreshLayout() {
|
||||||
relative_layout.removeAllViews();
|
relative_layout.removeAllViews();
|
||||||
removeElements();
|
removeElements();
|
||||||
|
|
||||||
layoutParamsButtonConfigure = new RelativeLayout.LayoutParams(50, 50);
|
layoutParamsButtonConfigure = new RelativeLayout.LayoutParams(50, 50);
|
||||||
relative_layout.addView(buttonConfigure, layoutParamsButtonConfigure);
|
relative_layout.addView(buttonConfigure, layoutParamsButtonConfigure);
|
||||||
|
|
||||||
VirtualControllerConfigurationLoader.createDefaultLayout(this, context);
|
VirtualControllerConfigurationLoader.createDefaultLayout(this, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControllerMode getControllerMode () {
|
public ControllerMode getControllerMode() {
|
||||||
return currentMode;
|
return currentMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControllerInputContext getControllerInputContext () {
|
public ControllerInputContext getControllerInputContext() {
|
||||||
return inputContext;
|
return inputContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendControllerInputContext() {
|
public void sendControllerInputContext() {
|
||||||
sendControllerInputPacket();
|
sendControllerInputPacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendControllerInputPacket() {
|
private void sendControllerInputPacket() {
|
||||||
try {
|
try {
|
||||||
_DBG("INPUT_MAP + " + inputContext.inputMap);
|
_DBG("INPUT_MAP + " + inputContext.inputMap);
|
||||||
_DBG("LEFT_TRIGGER " + inputContext.leftTrigger);
|
_DBG("LEFT_TRIGGER " + inputContext.leftTrigger);
|
||||||
_DBG("RIGHT_TRIGGER " + inputContext.rightTrigger);
|
_DBG("RIGHT_TRIGGER " + inputContext.rightTrigger);
|
||||||
_DBG("LEFT STICK X: " + inputContext.leftStickX + " Y: " + inputContext.leftStickY);
|
_DBG("LEFT STICK X: " + inputContext.leftStickX + " Y: " + inputContext.leftStickY);
|
||||||
_DBG("RIGHT STICK X: " + inputContext.rightStickX + " Y: " + inputContext.rightStickY);
|
_DBG("RIGHT STICK X: " + inputContext.rightStickX + " Y: " + inputContext.rightStickY);
|
||||||
_DBG("RIGHT STICK X: " + inputContext.rightStickX + " Y: " + inputContext.rightStickY);
|
_DBG("RIGHT STICK X: " + inputContext.rightStickX + " Y: " + inputContext.rightStickY);
|
||||||
|
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
connection.sendControllerInput(
|
connection.sendControllerInput(
|
||||||
inputContext.inputMap,
|
inputContext.inputMap,
|
||||||
inputContext.leftTrigger,
|
inputContext.leftTrigger,
|
||||||
inputContext.rightTrigger,
|
inputContext.rightTrigger,
|
||||||
inputContext.leftStickX,
|
inputContext.leftStickX,
|
||||||
inputContext.leftStickY,
|
inputContext.leftStickY,
|
||||||
inputContext.rightStickX,
|
inputContext.rightStickX,
|
||||||
inputContext.rightStickY
|
inputContext.rightStickY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,64 +20,65 @@ import java.util.List;
|
|||||||
|
|
||||||
public class VirtualControllerConfigurationLoader {
|
public class VirtualControllerConfigurationLoader {
|
||||||
private static final String PROFILE_PATH = "profiles";
|
private static final String PROFILE_PATH = "profiles";
|
||||||
private static int getPercent(
|
|
||||||
int percent,
|
|
||||||
int total) {
|
|
||||||
return (int) (((float) total / (float) 100) * (float) percent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DigitalPad createDigitalPad(
|
private static int getPercent(
|
||||||
final VirtualController controller,
|
int percent,
|
||||||
final Context context) {
|
int total) {
|
||||||
|
return (int) (((float) total / (float) 100) * (float) percent);
|
||||||
|
}
|
||||||
|
|
||||||
DigitalPad digitalPad = new DigitalPad(controller, context);
|
private static DigitalPad createDigitalPad(
|
||||||
digitalPad.addDigitalPadListener(new DigitalPad.DigitalPadListener() {
|
final VirtualController controller,
|
||||||
@Override
|
final Context context) {
|
||||||
public void onDirectionChange(int direction) {
|
|
||||||
VirtualController.ControllerInputContext inputContext =
|
DigitalPad digitalPad = new DigitalPad(controller, context);
|
||||||
|
digitalPad.addDigitalPadListener(new DigitalPad.DigitalPadListener() {
|
||||||
|
@Override
|
||||||
|
public void onDirectionChange(int direction) {
|
||||||
|
VirtualController.ControllerInputContext inputContext =
|
||||||
controller.getControllerInputContext();
|
controller.getControllerInputContext();
|
||||||
|
|
||||||
if (direction == DigitalPad.DIGITAL_PAD_DIRECTION_NO_DIRECTION) {
|
if (direction == DigitalPad.DIGITAL_PAD_DIRECTION_NO_DIRECTION) {
|
||||||
inputContext.inputMap &= ~ControllerPacket.LEFT_FLAG;
|
inputContext.inputMap &= ~ControllerPacket.LEFT_FLAG;
|
||||||
inputContext.inputMap &= ~ControllerPacket.RIGHT_FLAG;
|
inputContext.inputMap &= ~ControllerPacket.RIGHT_FLAG;
|
||||||
inputContext.inputMap &= ~ControllerPacket.UP_FLAG;
|
inputContext.inputMap &= ~ControllerPacket.UP_FLAG;
|
||||||
inputContext.inputMap &= ~ControllerPacket.DOWN_FLAG;
|
inputContext.inputMap &= ~ControllerPacket.DOWN_FLAG;
|
||||||
|
|
||||||
controller.sendControllerInputContext();
|
controller.sendControllerInputContext();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((direction & DigitalPad.DIGITAL_PAD_DIRECTION_LEFT) > 0) {
|
if ((direction & DigitalPad.DIGITAL_PAD_DIRECTION_LEFT) > 0) {
|
||||||
inputContext.inputMap |= ControllerPacket.LEFT_FLAG;
|
inputContext.inputMap |= ControllerPacket.LEFT_FLAG;
|
||||||
}
|
}
|
||||||
if ((direction & DigitalPad.DIGITAL_PAD_DIRECTION_RIGHT) > 0) {
|
if ((direction & DigitalPad.DIGITAL_PAD_DIRECTION_RIGHT) > 0) {
|
||||||
inputContext.inputMap |= ControllerPacket.RIGHT_FLAG;
|
inputContext.inputMap |= ControllerPacket.RIGHT_FLAG;
|
||||||
}
|
}
|
||||||
if ((direction & DigitalPad.DIGITAL_PAD_DIRECTION_UP) > 0) {
|
if ((direction & DigitalPad.DIGITAL_PAD_DIRECTION_UP) > 0) {
|
||||||
inputContext.inputMap |= ControllerPacket.UP_FLAG;
|
inputContext.inputMap |= ControllerPacket.UP_FLAG;
|
||||||
}
|
}
|
||||||
if ((direction & DigitalPad.DIGITAL_PAD_DIRECTION_DOWN) > 0) {
|
if ((direction & DigitalPad.DIGITAL_PAD_DIRECTION_DOWN) > 0) {
|
||||||
inputContext.inputMap |= ControllerPacket.DOWN_FLAG;
|
inputContext.inputMap |= ControllerPacket.DOWN_FLAG;
|
||||||
}
|
}
|
||||||
controller.sendControllerInputContext();
|
controller.sendControllerInputContext();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return digitalPad;
|
return digitalPad;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DigitalButton createDigitalButton(
|
private static DigitalButton createDigitalButton(
|
||||||
final int keyShort,
|
final int keyShort,
|
||||||
final int keyLong,
|
final int keyLong,
|
||||||
final int layer,
|
final int layer,
|
||||||
final String text,
|
final String text,
|
||||||
final int icon,
|
final int icon,
|
||||||
final VirtualController controller,
|
final VirtualController controller,
|
||||||
final Context context) {
|
final Context context) {
|
||||||
DigitalButton button = new DigitalButton(controller, layer, context);
|
DigitalButton button = new DigitalButton(controller, layer, context);
|
||||||
button.setText(text);
|
button.setText(text);
|
||||||
button.setIcon(icon);
|
button.setIcon(icon);
|
||||||
|
|
||||||
button.addDigitalButtonListener(new DigitalButton.DigitalButtonListener() {
|
button.addDigitalButtonListener(new DigitalButton.DigitalButtonListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
VirtualController.ControllerInputContext inputContext =
|
VirtualController.ControllerInputContext inputContext =
|
||||||
@ -107,90 +108,90 @@ public class VirtualControllerConfigurationLoader {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DigitalButton createLeftTrigger(
|
private static DigitalButton createLeftTrigger(
|
||||||
final int layer,
|
final int layer,
|
||||||
final String text,
|
final String text,
|
||||||
final int icon,
|
final int icon,
|
||||||
final VirtualController controller,
|
final VirtualController controller,
|
||||||
final Context context) {
|
final Context context) {
|
||||||
LeftTrigger button = new LeftTrigger(controller, layer, context);
|
LeftTrigger button = new LeftTrigger(controller, layer, context);
|
||||||
button.setText(text);
|
button.setText(text);
|
||||||
button.setIcon(icon);
|
button.setIcon(icon);
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DigitalButton createRightTrigger(
|
private static DigitalButton createRightTrigger(
|
||||||
final int layer,
|
final int layer,
|
||||||
final String text,
|
final String text,
|
||||||
final int icon,
|
final int icon,
|
||||||
final VirtualController controller,
|
final VirtualController controller,
|
||||||
final Context context) {
|
final Context context) {
|
||||||
RightTrigger button = new RightTrigger(controller, layer, context);
|
RightTrigger button = new RightTrigger(controller, layer, context);
|
||||||
button.setText(text);
|
button.setText(text);
|
||||||
button.setIcon(icon);
|
button.setIcon(icon);
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AnalogStick createLeftStick(
|
private static AnalogStick createLeftStick(
|
||||||
final VirtualController controller,
|
final VirtualController controller,
|
||||||
final Context context) {
|
final Context context) {
|
||||||
return new LeftAnalogStick(controller, context);
|
return new LeftAnalogStick(controller, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AnalogStick createRightStick(
|
private static AnalogStick createRightStick(
|
||||||
final VirtualController controller,
|
final VirtualController controller,
|
||||||
final Context context) {
|
final Context context) {
|
||||||
return new RightAnalogStick(controller, context);
|
return new RightAnalogStick(controller, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createDefaultLayout(final VirtualController controller, final Context context) {
|
public static void createDefaultLayout(final VirtualController controller, final Context context) {
|
||||||
|
|
||||||
DisplayMetrics screen = context.getResources().getDisplayMetrics();
|
DisplayMetrics screen = context.getResources().getDisplayMetrics();
|
||||||
|
|
||||||
controller.addElement(createDigitalPad(controller, context),
|
controller.addElement(createDigitalPad(controller, context),
|
||||||
getPercent(5, screen.widthPixels),
|
getPercent(5, screen.widthPixels),
|
||||||
getPercent(10, screen.heightPixels),
|
getPercent(10, screen.heightPixels),
|
||||||
getPercent(30, screen.widthPixels),
|
getPercent(30, screen.widthPixels),
|
||||||
getPercent(40, screen.heightPixels)
|
getPercent(40, screen.heightPixels)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller.addElement(createDigitalButton(
|
controller.addElement(createDigitalButton(
|
||||||
ControllerPacket.A_FLAG, 0, 1, "A", -1, controller, context),
|
ControllerPacket.A_FLAG, 0, 1, "A", -1, controller, context),
|
||||||
getPercent(75, screen.widthPixels),
|
getPercent(75, screen.widthPixels),
|
||||||
getPercent(40, screen.heightPixels),
|
getPercent(40, screen.heightPixels),
|
||||||
getPercent(10, screen.widthPixels),
|
getPercent(10, screen.widthPixels),
|
||||||
getPercent(10, screen.heightPixels)
|
getPercent(10, screen.heightPixels)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller.addElement(createDigitalButton(
|
controller.addElement(createDigitalButton(
|
||||||
ControllerPacket.B_FLAG, 0, 1, "B", -1, controller, context),
|
ControllerPacket.B_FLAG, 0, 1, "B", -1, controller, context),
|
||||||
getPercent(85, screen.widthPixels),
|
getPercent(85, screen.widthPixels),
|
||||||
getPercent(30, screen.heightPixels),
|
getPercent(30, screen.heightPixels),
|
||||||
getPercent(10, screen.widthPixels),
|
getPercent(10, screen.widthPixels),
|
||||||
getPercent(10, screen.heightPixels)
|
getPercent(10, screen.heightPixels)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller.addElement(createDigitalButton(
|
controller.addElement(createDigitalButton(
|
||||||
ControllerPacket.X_FLAG, 0, 1, "X", -1, controller, context),
|
ControllerPacket.X_FLAG, 0, 1, "X", -1, controller, context),
|
||||||
getPercent(65, screen.widthPixels),
|
getPercent(65, screen.widthPixels),
|
||||||
getPercent(30, screen.heightPixels),
|
getPercent(30, screen.heightPixels),
|
||||||
getPercent(10, screen.widthPixels),
|
getPercent(10, screen.widthPixels),
|
||||||
getPercent(10, screen.heightPixels)
|
getPercent(10, screen.heightPixels)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller.addElement(createDigitalButton(
|
controller.addElement(createDigitalButton(
|
||||||
ControllerPacket.Y_FLAG, 0, 1, "Y", -1, controller, context),
|
ControllerPacket.Y_FLAG, 0, 1, "Y", -1, controller, context),
|
||||||
getPercent(75, screen.widthPixels),
|
getPercent(75, screen.widthPixels),
|
||||||
getPercent(20, screen.heightPixels),
|
getPercent(20, screen.heightPixels),
|
||||||
getPercent(10, screen.widthPixels),
|
getPercent(10, screen.widthPixels),
|
||||||
getPercent(10, screen.heightPixels)
|
getPercent(10, screen.heightPixels)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller.addElement(createLeftTrigger(
|
controller.addElement(createLeftTrigger(
|
||||||
0, "LT", -1, controller, context),
|
0, "LT", -1, controller, context),
|
||||||
getPercent(65, screen.widthPixels),
|
getPercent(65, screen.widthPixels),
|
||||||
getPercent(20, screen.heightPixels),
|
getPercent(20, screen.heightPixels),
|
||||||
getPercent(10, screen.widthPixels),
|
getPercent(10, screen.widthPixels),
|
||||||
@ -198,43 +199,43 @@ public class VirtualControllerConfigurationLoader {
|
|||||||
);
|
);
|
||||||
|
|
||||||
controller.addElement(createRightTrigger(
|
controller.addElement(createRightTrigger(
|
||||||
0, "RT", -1, controller, context),
|
0, "RT", -1, controller, context),
|
||||||
getPercent(85, screen.widthPixels),
|
getPercent(85, screen.widthPixels),
|
||||||
getPercent(20, screen.heightPixels),
|
getPercent(20, screen.heightPixels),
|
||||||
getPercent(10, screen.widthPixels),
|
getPercent(10, screen.widthPixels),
|
||||||
getPercent(10, screen.heightPixels)
|
getPercent(10, screen.heightPixels)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller.addElement(createLeftStick(controller, context),
|
controller.addElement(createLeftStick(controller, context),
|
||||||
getPercent(5, screen.widthPixels),
|
getPercent(5, screen.widthPixels),
|
||||||
getPercent(50, screen.heightPixels),
|
getPercent(50, screen.heightPixels),
|
||||||
getPercent(40, screen.widthPixels),
|
getPercent(40, screen.widthPixels),
|
||||||
getPercent(50, screen.heightPixels)
|
getPercent(50, screen.heightPixels)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller.addElement(createRightStick(controller, context),
|
controller.addElement(createRightStick(controller, context),
|
||||||
getPercent(55, screen.widthPixels),
|
getPercent(55, screen.widthPixels),
|
||||||
getPercent(50, screen.heightPixels),
|
getPercent(50, screen.heightPixels),
|
||||||
getPercent(40, screen.widthPixels),
|
getPercent(40, screen.widthPixels),
|
||||||
getPercent(50, screen.heightPixels)
|
getPercent(50, screen.heightPixels)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller.addElement(createDigitalButton(
|
controller.addElement(createDigitalButton(
|
||||||
ControllerPacket.SPECIAL_BUTTON_FLAG, 0, 2, "SELECT", -1, controller, context),
|
ControllerPacket.SPECIAL_BUTTON_FLAG, 0, 2, "SELECT", -1, controller, context),
|
||||||
getPercent(40, screen.widthPixels),
|
getPercent(40, screen.widthPixels),
|
||||||
getPercent(90, screen.heightPixels),
|
getPercent(90, screen.heightPixels),
|
||||||
getPercent(10, screen.widthPixels),
|
getPercent(10, screen.widthPixels),
|
||||||
getPercent(10, screen.heightPixels)
|
getPercent(10, screen.heightPixels)
|
||||||
);
|
);
|
||||||
|
|
||||||
controller.addElement(createDigitalButton(
|
controller.addElement(createDigitalButton(
|
||||||
ControllerPacket.PLAY_FLAG, 0, 3, "PLAY", -1, controller, context),
|
ControllerPacket.PLAY_FLAG, 0, 3, "PLAY", -1, controller, context),
|
||||||
getPercent(50, screen.widthPixels),
|
getPercent(50, screen.widthPixels),
|
||||||
getPercent(90, screen.heightPixels),
|
getPercent(90, screen.heightPixels),
|
||||||
getPercent(10, screen.widthPixels),
|
getPercent(10, screen.widthPixels),
|
||||||
getPercent(10, screen.heightPixels)
|
getPercent(10, screen.heightPixels)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NOT IMPLEMENTED YET,
|
NOT IMPLEMENTED YET,
|
||||||
|
@ -18,81 +18,81 @@ import org.json.JSONObject;
|
|||||||
//import yuku.ambilwarna.AmbilWarnaDialog;
|
//import yuku.ambilwarna.AmbilWarnaDialog;
|
||||||
|
|
||||||
public abstract class VirtualControllerElement extends View {
|
public abstract class VirtualControllerElement extends View {
|
||||||
protected static boolean _PRINT_DEBUG_INFORMATION = false;
|
protected static boolean _PRINT_DEBUG_INFORMATION = false;
|
||||||
|
|
||||||
protected VirtualController virtualController;
|
protected VirtualController virtualController;
|
||||||
|
|
||||||
protected int normalColor = 0xF0888888;
|
protected int normalColor = 0xF0888888;
|
||||||
protected int pressedColor = 0xF00000FF;
|
protected int pressedColor = 0xF00000FF;
|
||||||
|
|
||||||
protected int startSize_x;
|
protected int startSize_x;
|
||||||
protected int startSize_y;
|
protected int startSize_y;
|
||||||
|
|
||||||
float position_pressed_x = 0;
|
float position_pressed_x = 0;
|
||||||
float position_pressed_y = 0;
|
float position_pressed_y = 0;
|
||||||
|
|
||||||
private enum Mode {
|
private enum Mode {
|
||||||
Normal,
|
Normal,
|
||||||
Resize,
|
Resize,
|
||||||
Move
|
Move
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mode currentMode = Mode.Normal;
|
private Mode currentMode = Mode.Normal;
|
||||||
|
|
||||||
protected VirtualControllerElement(VirtualController controller, Context context) {
|
protected VirtualControllerElement(VirtualController controller, Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
this.virtualController = controller;
|
this.virtualController = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void moveElement(int pressed_x, int pressed_y, int x, int y) {
|
protected void moveElement(int pressed_x, int pressed_y, int x, int y) {
|
||||||
int newPos_x = (int)getX() + x - pressed_x;
|
int newPos_x = (int) getX() + x - pressed_x;
|
||||||
int newPos_y = (int)getY() + y - pressed_y;
|
int newPos_y = (int) getY() + y - pressed_y;
|
||||||
|
|
||||||
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
|
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
|
||||||
|
|
||||||
layoutParams.leftMargin = newPos_x > 0 ? newPos_x : 0;
|
layoutParams.leftMargin = newPos_x > 0 ? newPos_x : 0;
|
||||||
layoutParams.topMargin = newPos_y > 0 ? newPos_y : 0;
|
layoutParams.topMargin = newPos_y > 0 ? newPos_y : 0;
|
||||||
layoutParams.rightMargin = 0;
|
layoutParams.rightMargin = 0;
|
||||||
layoutParams.bottomMargin = 0;
|
layoutParams.bottomMargin = 0;
|
||||||
|
|
||||||
requestLayout();
|
requestLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void resizeElement(int pressed_x, int pressed_y, int width, int height) {
|
protected void resizeElement(int pressed_x, int pressed_y, int width, int height) {
|
||||||
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
|
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
|
||||||
|
|
||||||
int newHeight = height + (startSize_y - pressed_y);
|
int newHeight = height + (startSize_y - pressed_y);
|
||||||
int newWidth = width + (startSize_x - pressed_x);
|
int newWidth = width + (startSize_x - pressed_x);
|
||||||
|
|
||||||
layoutParams.height = newHeight > 20 ? newHeight : 20;
|
layoutParams.height = newHeight > 20 ? newHeight : 20;
|
||||||
layoutParams.width = newWidth > 20 ? newWidth : 20;
|
layoutParams.width = newWidth > 20 ? newWidth : 20;
|
||||||
|
|
||||||
requestLayout();
|
requestLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
if (virtualController.getControllerMode() == VirtualController.ControllerMode.
|
if (virtualController.getControllerMode() == VirtualController.ControllerMode.
|
||||||
Configuration) {
|
Configuration) {
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
|
|
||||||
paint.setColor(pressedColor);
|
paint.setColor(pressedColor);
|
||||||
paint.setStrokeWidth(3);
|
paint.setStrokeWidth(3);
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
|
|
||||||
canvas.drawRect(0, 0,
|
canvas.drawRect(0, 0,
|
||||||
getWidth(), getHeight(),
|
getWidth(), getHeight(),
|
||||||
paint);
|
paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
onElementDraw(canvas);
|
onElementDraw(canvas);
|
||||||
|
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
protected void actionShowNormalColorChooser() {
|
protected void actionShowNormalColorChooser() {
|
||||||
AmbilWarnaDialog colorDialog = new AmbilWarnaDialog(getContext(), normalColor, true, new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
AmbilWarnaDialog colorDialog = new AmbilWarnaDialog(getContext(), normalColor, true, new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(AmbilWarnaDialog dialog)
|
public void onCancel(AmbilWarnaDialog dialog)
|
||||||
@ -123,20 +123,20 @@ public abstract class VirtualControllerElement extends View {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected void actionEnableMove() {
|
protected void actionEnableMove() {
|
||||||
currentMode = Mode.Move;
|
currentMode = Mode.Move;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void actionEnableResize() {
|
protected void actionEnableResize() {
|
||||||
currentMode = Mode.Resize;
|
currentMode = Mode.Resize;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void actionCancel() {
|
protected void actionCancel() {
|
||||||
currentMode = Mode.Normal;
|
currentMode = Mode.Normal;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showConfigurationDialog() {
|
protected void showConfigurationDialog() {
|
||||||
try {
|
try {
|
||||||
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getContext());
|
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getContext());
|
||||||
|
|
||||||
@ -186,30 +186,30 @@ public abstract class VirtualControllerElement extends View {
|
|||||||
AlertDialog alert = alertBuilder.create();
|
AlertDialog alert = alertBuilder.create();
|
||||||
// show menu
|
// show menu
|
||||||
alert.show();
|
alert.show();
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
if (virtualController.getControllerMode() == VirtualController.ControllerMode.Active) {
|
if (virtualController.getControllerMode() == VirtualController.ControllerMode.Active) {
|
||||||
return onElementTouchEvent(event);
|
return onElementTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (event.getActionMasked()) {
|
switch (event.getActionMasked()) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
case MotionEvent.ACTION_POINTER_DOWN: {
|
case MotionEvent.ACTION_POINTER_DOWN: {
|
||||||
position_pressed_x = event.getX();
|
position_pressed_x = event.getX();
|
||||||
position_pressed_y = event.getY();
|
position_pressed_y = event.getY();
|
||||||
startSize_x = getWidth();
|
startSize_x = getWidth();
|
||||||
startSize_y = getHeight();
|
startSize_y = getHeight();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_MOVE: {
|
case MotionEvent.ACTION_MOVE: {
|
||||||
switch (currentMode) {
|
switch (currentMode) {
|
||||||
case Move: {
|
case Move: {
|
||||||
moveElement(
|
moveElement(
|
||||||
(int) position_pressed_x,
|
(int) position_pressed_x,
|
||||||
(int) position_pressed_y,
|
(int) position_pressed_y,
|
||||||
@ -217,7 +217,7 @@ public abstract class VirtualControllerElement extends View {
|
|||||||
(int) event.getY());
|
(int) event.getY());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Resize: {
|
case Resize: {
|
||||||
resizeElement(
|
resizeElement(
|
||||||
(int) position_pressed_x,
|
(int) position_pressed_x,
|
||||||
(int) position_pressed_y,
|
(int) position_pressed_y,
|
||||||
@ -225,56 +225,57 @@ public abstract class VirtualControllerElement extends View {
|
|||||||
(int) event.getY());
|
(int) event.getY());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Normal: {
|
case Normal: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
case MotionEvent.ACTION_POINTER_UP: {
|
case MotionEvent.ACTION_POINTER_UP: {
|
||||||
currentMode = Mode.Normal;
|
currentMode = Mode.Normal;
|
||||||
showConfigurationDialog();
|
showConfigurationDialog();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected void onElementDraw(Canvas canvas);
|
abstract protected void onElementDraw(Canvas canvas);
|
||||||
abstract public boolean onElementTouchEvent(MotionEvent event);
|
|
||||||
|
|
||||||
protected static final void _DBG(String text) {
|
abstract public boolean onElementTouchEvent(MotionEvent event);
|
||||||
if (_PRINT_DEBUG_INFORMATION) {
|
|
||||||
System.out.println(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColors(int normalColor, int pressedColor) {
|
protected static final void _DBG(String text) {
|
||||||
this.normalColor = normalColor;
|
if (_PRINT_DEBUG_INFORMATION) {
|
||||||
this.pressedColor = pressedColor;
|
System.out.println(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
invalidate();
|
public void setColors(int normalColor, int pressedColor) {
|
||||||
}
|
this.normalColor = normalColor;
|
||||||
|
this.pressedColor = pressedColor;
|
||||||
|
|
||||||
protected final float getPercent(float value, float percent) {
|
invalidate();
|
||||||
return value / 100 * percent;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected final int getCorrectWidth() {
|
protected final float getPercent(float value, float percent) {
|
||||||
|
return value / 100 * percent;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final int getCorrectWidth() {
|
||||||
return getWidth() > getHeight() ? getHeight() : getWidth();
|
return getWidth() > getHeight() ? getHeight() : getWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
public JSONObject getConfiguration () {
|
public JSONObject getConfiguration () {
|
||||||
JSONObject configuration = new JSONObject();
|
JSONObject configuration = new JSONObject();
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConfiguration (JSONObject configuration) {
|
public void loadConfiguration (JSONObject configuration) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user