From 4e29f2ae8b95b1c33772e7506db1f6fbc2181883 Mon Sep 17 00:00:00 2001 From: Karim Mreisi Date: Sat, 24 Jan 2015 10:26:28 +0100 Subject: [PATCH] add real digital pad and new digital buttons --- .../input/virtual_controller/AnalogStick.java | 37 +- .../virtual_controller/DigitalButton.java | 172 +++++++++ .../input/virtual_controller/DigitalPad.java | 276 ++++++++++++++ .../virtual_controller/VirtualController.java | 355 ++++++++---------- 4 files changed, 635 insertions(+), 205 deletions(-) create mode 100644 app/src/main/java/com/limelight/binding/input/virtual_controller/DigitalButton.java create mode 100644 app/src/main/java/com/limelight/binding/input/virtual_controller/DigitalPad.java diff --git a/app/src/main/java/com/limelight/binding/input/virtual_controller/AnalogStick.java b/app/src/main/java/com/limelight/binding/input/virtual_controller/AnalogStick.java index 4a3ac283..709b73ca 100644 --- a/app/src/main/java/com/limelight/binding/input/virtual_controller/AnalogStick.java +++ b/app/src/main/java/com/limelight/binding/input/virtual_controller/AnalogStick.java @@ -21,7 +21,7 @@ public class AnalogStick extends View MOVED } - private static final boolean _PRINT_DEBUG_INFORMATION = false; + private static final boolean _PRINT_DEBUG_INFORMATION = true; public interface AnalogStickListener { @@ -33,6 +33,11 @@ public class AnalogStick extends View listeners.add(listener); } + public void setOnTouchListener(OnTouchListener listener) + { + onTouchListener = listener; + } + private static final void _DBG(String text) { if (_PRINT_DEBUG_INFORMATION) @@ -41,6 +46,9 @@ public class AnalogStick extends View } } + private int normalColor = 0x88888888; + private int pressedColor = 0x880000FF; + float radius_complete = 0; float radius_dead_zone = 0; float radius_analog_stick = 0; @@ -52,6 +60,7 @@ public class AnalogStick extends View _STICK_STATE stick_state = _STICK_STATE.NO_MOVEMENT; List listeners = new ArrayList(); + OnTouchListener onTouchListener = null; public AnalogStick(Context context) { @@ -93,9 +102,9 @@ public class AnalogStick extends View @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { - radius_complete = getPercent(getCorrectWidth() / 2, 90); - radius_dead_zone = getPercent(getCorrectWidth() / 2, 10); - radius_analog_stick = getPercent(getCorrectWidth() / 2, 20); + radius_complete = getPercent(getCorrectWidth() / 2, 95); + radius_dead_zone = getPercent(getCorrectWidth() / 2, 20); + radius_analog_stick = getPercent(getCorrectWidth() / 2, 30); super.onSizeChanged(w, h, oldw, oldh); } @@ -103,11 +112,14 @@ public class AnalogStick extends View @Override protected void onDraw(Canvas canvas) { + // set transparent background + canvas.drawColor(Color.TRANSPARENT); + Paint paint = new Paint(); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(getPercent(getCorrectWidth() / 2, 2)); - paint.setColor(Color.YELLOW); + paint.setColor(normalColor); // draw outer circle canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_complete, paint); @@ -122,14 +134,14 @@ public class AnalogStick extends View { case NO_MOVEMENT: { - paint.setColor(Color.BLUE); + paint.setColor(normalColor); canvas.drawCircle(position_stick_x, position_stick_y, radius_analog_stick, paint); break; } case MOVED: { - paint.setColor(Color.CYAN); + paint.setColor(pressedColor); canvas.drawCircle(position_stick_x, position_stick_y, radius_analog_stick, paint); break; @@ -138,11 +150,9 @@ public class AnalogStick extends View } else { - paint.setColor(Color.RED); + paint.setColor(normalColor); canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_analog_stick, paint); } - // set transparent background - canvas.drawColor(Color.TRANSPARENT); super.onDraw(canvas); } @@ -244,7 +254,7 @@ public class AnalogStick extends View position_stick_x = getWidth() / 2 - correlated_x; position_stick_y = getHeight() / 2 - correlated_y; - // check if analog stick is inside of dead zone + // check if analog stick is outside of dead zone if (movement_radius > radius_dead_zone) { moveActionCallback(movement_x, movement_y); @@ -260,6 +270,11 @@ public class AnalogStick extends View @Override public boolean onTouchEvent(MotionEvent event) { + if (onTouchListener != null) + { + return onTouchListener.onTouch(this, event); + } + // get masked (not specific to a pointer) action int action = event.getActionMasked(); diff --git a/app/src/main/java/com/limelight/binding/input/virtual_controller/DigitalButton.java b/app/src/main/java/com/limelight/binding/input/virtual_controller/DigitalButton.java new file mode 100644 index 00000000..f648e427 --- /dev/null +++ b/app/src/main/java/com/limelight/binding/input/virtual_controller/DigitalButton.java @@ -0,0 +1,172 @@ +package com.limelight.binding.input.virtual_controller; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.view.MotionEvent; +import android.view.View; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Karim on 24.01.2015. + */ +public class DigitalButton extends View +{ + private static final boolean _PRINT_DEBUG_INFORMATION = true; + + private int normalColor = 0x88888888; + private int pressedColor = 0x880000FF; + private String text; + + + public interface DigitalButtonListener + { + void onClick(); + + void onRelease(); + } + + public void addDigitalButtonListener(DigitalButtonListener listener) + { + listeners.add(listener); + } + + public void setOnTouchListener(OnTouchListener listener) + { + onTouchListener = listener; + } + + private static final void _DBG(String text) + { + if (_PRINT_DEBUG_INFORMATION) + { + System.out.println("DigitalButton: " + text); + } + } + + List listeners = new ArrayList(); + OnTouchListener onTouchListener = null; + + boolean clicked; + + public DigitalButton(Context context) + { + super(context); + + clicked = false; + } + + public void setText(String text) + { + this.text = text; + + invalidate(); + } + + private float getPercent(float value, float percent) + { + return value / 100 * percent; + } + + private int getCorrectWidth() + { + return getWidth() > getHeight() ? getHeight() : getWidth(); + } + + @Override + protected void onDraw(Canvas canvas) + { + // set transparent background + canvas.drawColor(Color.TRANSPARENT); + + Paint paint = new Paint(); + + paint.setTextSize(getPercent(getCorrectWidth(), 50)); + paint.setTextAlign(Paint.Align.CENTER); + paint.setStrokeWidth(3); + + paint.setColor(clicked ? pressedColor : normalColor); + paint.setStyle(Paint.Style.STROKE); + canvas.drawRect( + 1, 1, + getWidth() - 1, getHeight() - 1, + paint + ); + + paint.setStyle(Paint.Style.FILL_AND_STROKE); + canvas.drawText(text, + getPercent(getWidth(), 50), getPercent(getHeight(), 75), + paint); + + super.onDraw(canvas); + } + + private void onClickCallback() + { + _DBG("clicked"); + + // notify listeners + for (DigitalButtonListener listener : listeners) + { + listener.onClick(); + } + } + + private void onReleaseCallback() + { + _DBG("released"); + + // notify listeners + for (DigitalButtonListener listener : listeners) + { + listener.onRelease(); + } + } + + + @Override + public boolean onTouchEvent(MotionEvent event) + { + /* + if (onTouchListener != null) + { + return onTouchListener.onTouch(this, event); + } + */ + // get masked (not specific to a pointer) action + int action = event.getActionMasked(); + + switch (action) + { + case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_POINTER_DOWN: + { + clicked = true; + onClickCallback(); + + invalidate(); + + return true; + } + case MotionEvent.ACTION_CANCEL: + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_POINTER_UP: + { + clicked = false; + onReleaseCallback(); + + invalidate(); + + return true; + } + default: + { + } + } + + return super.onTouchEvent(event); + } +} diff --git a/app/src/main/java/com/limelight/binding/input/virtual_controller/DigitalPad.java b/app/src/main/java/com/limelight/binding/input/virtual_controller/DigitalPad.java new file mode 100644 index 00000000..760d6d6d --- /dev/null +++ b/app/src/main/java/com/limelight/binding/input/virtual_controller/DigitalPad.java @@ -0,0 +1,276 @@ +package com.limelight.binding.input.virtual_controller; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.view.MotionEvent; +import android.view.View; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Karim Mreisi on 23.01.2015. + */ +public class DigitalPad extends View +{ + public final static int DIGITAL_PAD_DIRECTION_NO_DIRECTION = 0; + 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_RIGHT = 4; + public final static int DIGITAL_PAD_DIRECTION_DOWN = 8; + + private int normalColor = 0x88888888; + private int pressedColor = 0x880000FF; + + private static final boolean _PRINT_DEBUG_INFORMATION = true; + + public interface DigitalPadListener + { + void onDirectionChange(int direction); + } + + public void addDigitalPadListener (DigitalPadListener listener) + { + listeners.add(listener); + } + + public void setOnTouchListener(OnTouchListener listener) + { + onTouchListener = listener; + } + + private static final void _DBG(String text) + { + if (_PRINT_DEBUG_INFORMATION) + { + System.out.println("DigitalPad: " + text); + } + } + + List listeners = new ArrayList(); + OnTouchListener onTouchListener = null; + + int direction; + + public DigitalPad(Context context) + { + super(context); + + direction = DIGITAL_PAD_DIRECTION_NO_DIRECTION; + } + + private float getPercent(float value, float percent) + { + return value / 100 * percent; + } + + private int getCorrectWidth() + { + return getWidth() > getHeight() ? getHeight() : getWidth(); + } + + @Override + protected void onDraw(Canvas canvas) + { + // set transparent background + canvas.drawColor(Color.TRANSPARENT); + + Paint paint = new Paint(); + + paint.setTextSize(getPercent(getCorrectWidth(), 20)); + paint.setTextAlign(Paint.Align.CENTER); + paint.setStrokeWidth(3); + + // draw no direction rect + paint.setStyle(Paint.Style.STROKE); + paint.setColor(direction == DIGITAL_PAD_DIRECTION_NO_DIRECTION ? pressedColor : normalColor); + canvas.drawRect( + getPercent(getWidth(), 36), getPercent(getHeight(), 36), + getPercent(getWidth(), 63), getPercent(getHeight(), 63), + paint + ); + + // draw left rect + paint.setColor((direction & DIGITAL_PAD_DIRECTION_LEFT) > 0 ? pressedColor : normalColor); + paint.setStyle(Paint.Style.FILL_AND_STROKE); + canvas.drawText("LF", + getPercent(getWidth(), 16.5f), getPercent(getHeight(), 58), + paint); + paint.setStyle(Paint.Style.STROKE); + canvas.drawRect( + 0, getPercent(getHeight(), 33), + getPercent(getWidth(), 33), getPercent(getHeight(), 66), + paint + ); + + // draw left up line + paint.setColor(( + (direction & DIGITAL_PAD_DIRECTION_LEFT) > 0 && + (direction & DIGITAL_PAD_DIRECTION_UP) > 0 + ) ? pressedColor : normalColor + ); + paint.setStyle(Paint.Style.STROKE); + canvas.drawLine( + 0, getPercent(getWidth(), 33), + getPercent(getWidth(), 33), 0, + paint + ); + + // draw up rect + paint.setColor((direction & DIGITAL_PAD_DIRECTION_UP) > 0 ? pressedColor : normalColor); + paint.setStyle(Paint.Style.FILL_AND_STROKE); + canvas.drawText("UP", + getPercent(getWidth(), 49.5f), getPercent(getHeight(), 25), + paint); + paint.setStyle(Paint.Style.STROKE); + canvas.drawRect( + getPercent(getWidth(), 33), 0, + getPercent(getWidth(), 66), getPercent(getHeight(), 33), + paint + ); + + // draw up right line + paint.setColor(( + (direction & DIGITAL_PAD_DIRECTION_UP) > 0 && + (direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0 + ) ? pressedColor : normalColor + ); + paint.setStyle(Paint.Style.STROKE); + canvas.drawLine( + getPercent(getWidth(), 66), 0, + getPercent(getWidth(), 100), getPercent(getHeight(), 33), + paint + ); + + // draw right rect + paint.setColor((direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0 ? pressedColor : normalColor); + paint.setStyle(Paint.Style.FILL_AND_STROKE); + canvas.drawText("RI", + getPercent(getWidth(), 82.5f), getPercent(getHeight(), 58), + paint); + paint.setStyle(Paint.Style.STROKE); + canvas.drawRect( + getPercent(getWidth(), 66), getPercent(getHeight(), 33), + getPercent(getWidth(), 100), getPercent(getHeight(), 66), + paint + ); + + // draw right down line + paint.setColor(( + (direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0 && + (direction & DIGITAL_PAD_DIRECTION_DOWN) > 0 + ) ? pressedColor : normalColor + ); + paint.setStyle(Paint.Style.STROKE); + canvas.drawLine( + getPercent(getWidth(), 100), getPercent(getHeight(), 66), + getPercent(getWidth(), 66), getPercent(getHeight(), 100), + paint + ); + + // draw down rect + paint.setColor((direction & DIGITAL_PAD_DIRECTION_DOWN) > 0 ? pressedColor : normalColor); + paint.setStyle(Paint.Style.FILL_AND_STROKE); + canvas.drawText("DW", + getPercent(getWidth(), 49.5f), getPercent(getHeight(), 91), + paint); + paint.setStyle(Paint.Style.STROKE); + canvas.drawRect( + getPercent(getWidth(), 33), getPercent(getHeight(), 66), + getPercent(getWidth(), 66), getPercent(getHeight(), 100), + paint + ); + + // draw down left line + paint.setColor(( + (direction & DIGITAL_PAD_DIRECTION_DOWN) > 0 && + (direction & DIGITAL_PAD_DIRECTION_LEFT) > 0 + ) ? pressedColor : normalColor + ); + paint.setStyle(Paint.Style.STROKE); + canvas.drawLine( + getPercent(getWidth(), 33), getPercent(getHeight(), 100), + getPercent(getWidth(), 0), getPercent(getHeight(), 66), + paint + ); + + super.onDraw(canvas); + } + + private void newDirectionCallback(int direction) + { + _DBG("direction: " + direction); + + // notify listeners + for (DigitalPadListener listener : listeners) + { + listener.onDirectionChange(direction); + } + } + + @Override + public boolean onTouchEvent(MotionEvent event) + { + if (onTouchListener != null) + { + return onTouchListener.onTouch(this, event); + } + + // get masked (not specific to a pointer) action + int action = event.getActionMasked(); + + switch (action) + { + case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_POINTER_DOWN: + { + direction = 0; + + if (event.getX() < getPercent(getWidth(), 33)) + { + direction |= DIGITAL_PAD_DIRECTION_LEFT; + } + + if (event.getX() > getPercent(getWidth(), 66)) + { + direction |= DIGITAL_PAD_DIRECTION_RIGHT; + } + + if (event.getY() > getPercent(getHeight(), 66)) + { + direction |= DIGITAL_PAD_DIRECTION_DOWN; + } + + if (event.getY() < getPercent(getHeight(), 33)) + { + direction |= DIGITAL_PAD_DIRECTION_UP; + } + + newDirectionCallback(direction); + + invalidate(); + + return true; + } + case MotionEvent.ACTION_CANCEL: + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_POINTER_UP: + { + direction = 0; + + newDirectionCallback(direction); + + invalidate(); + + return true; + } + default: + { + } + } + + return super.onTouchEvent(event); + } +} diff --git a/app/src/main/java/com/limelight/binding/input/virtual_controller/VirtualController.java b/app/src/main/java/com/limelight/binding/input/virtual_controller/VirtualController.java index e99e265e..cdd86c23 100644 --- a/app/src/main/java/com/limelight/binding/input/virtual_controller/VirtualController.java +++ b/app/src/main/java/com/limelight/binding/input/virtual_controller/VirtualController.java @@ -36,10 +36,7 @@ public class VirtualController private FrameLayout frame_layout = null; private RelativeLayout relative_layout = null; - private RelativeLayout.LayoutParams layoutParamsButtonDPadLeft = null; - private RelativeLayout.LayoutParams layoutParamsButtonDPadRight = null; - private RelativeLayout.LayoutParams layoutParamsButtonDPadUp = null; - private RelativeLayout.LayoutParams layoutParamsButtonDPadDown = null; + private RelativeLayout.LayoutParams layoutParamsDPad = null; private RelativeLayout.LayoutParams layoutParamsButtonA = null; private RelativeLayout.LayoutParams layoutParamsButtonB = null; @@ -57,19 +54,16 @@ public class VirtualController private Button buttonSelect = null; private Button buttonESC = null; - private Button buttonDPadLeft = null; - private Button buttonDPadRight = null; - private Button buttonDPadUp = null; - private Button buttonDPadDown = null; + private DigitalPad digitalPad = null; - private Button buttonA = null; - private Button buttonB = null; - private Button buttonX = null; - private Button buttonY = null; - private Button buttonLT = null; - private Button buttonRT = null; - private Button buttonLB = null; - private Button buttonRB = null; + private DigitalButton buttonA = null; + private DigitalButton buttonB = null; + private DigitalButton buttonX = null; + private DigitalButton buttonY = null; + private DigitalButton buttonLT = null; + private DigitalButton buttonRT = null; + private DigitalButton buttonLB = null; + private DigitalButton buttonRB = null; private AnalogStick stick = null; @@ -132,10 +126,7 @@ public class VirtualController { relative_layout.removeAllViews(); - layoutParamsButtonDPadLeft = new RelativeLayout.LayoutParams(getPercentageV(10), getPercentageV(10)); - layoutParamsButtonDPadRight = new RelativeLayout.LayoutParams(getPercentageV(10), getPercentageV(10)); - layoutParamsButtonDPadUp = new RelativeLayout.LayoutParams(getPercentageV(10), getPercentageV(10)); - layoutParamsButtonDPadDown = new RelativeLayout.LayoutParams(getPercentageV(10), getPercentageV(10)); + layoutParamsDPad = new RelativeLayout.LayoutParams(getPercentageV(30), getPercentageV(30)); layoutParamsParamsStick = new RelativeLayout.LayoutParams(getPercentageV(40), getPercentageV(40)); layoutParamsParamsStick2 = new RelativeLayout.LayoutParams(getPercentageV(40), getPercentageV(40)); @@ -150,10 +141,7 @@ public class VirtualController layoutParamsButtonLB = new RelativeLayout.LayoutParams(getPercentageV(10), getPercentageV(10)); layoutParamsButtonRB = new RelativeLayout.LayoutParams(getPercentageV(10), getPercentageV(10)); - setPercentilePosition(layoutParamsButtonDPadLeft, 5, 45); - setPercentilePosition(layoutParamsButtonDPadRight, 15, 45); - setPercentilePosition(layoutParamsButtonDPadUp, 10, 35); - setPercentilePosition(layoutParamsButtonDPadDown, 10, 55); + setPercentilePosition(layoutParamsDPad, 10, 35); setPercentilePosition(layoutParamsParamsStick, 22, 78); setPercentilePosition(layoutParamsParamsStick2, 78, 78); @@ -169,13 +157,11 @@ public class VirtualController setPercentilePosition(layoutParamsButtonLB, 85, 28); setPercentilePosition(layoutParamsButtonRB, 92, 23); - relative_layout.addView(buttonDPadLeft, layoutParamsButtonDPadLeft); - relative_layout.addView(buttonDPadRight, layoutParamsButtonDPadRight); - relative_layout.addView(buttonDPadUp, layoutParamsButtonDPadUp); - relative_layout.addView(buttonDPadDown, layoutParamsButtonDPadDown); + relative_layout.addView(digitalPad, layoutParamsDPad); relative_layout.addView(stick, layoutParamsParamsStick); relative_layout.addView(stick2, layoutParamsParamsStick2); + relative_layout.addView(buttonA, layoutParamsButtonA); relative_layout.addView(buttonB, layoutParamsButtonB); relative_layout.addView(buttonX, layoutParamsButtonX); @@ -204,197 +190,188 @@ public class VirtualController frame_layout.addView(relative_layout); - buttonDPadLeft = new Button(context); - buttonDPadLeft.setText("LF"); - buttonDPadLeft.setOnTouchListener(new View.OnTouchListener() - { - @Override - public boolean onTouch(View v, MotionEvent event) - { - onButtonTouchEvent(v, event, ControllerPacket.LEFT_FLAG); + digitalPad = new DigitalPad(context); + digitalPad.addDigitalPadListener(new DigitalPad.DigitalPadListener() + { + @Override + public void onDirectionChange(int direction) + { + do + { + if (direction == DigitalPad.DIGITAL_PAD_DIRECTION_NO_DIRECTION) + { + inputMap &= ~ControllerPacket.LEFT_FLAG; + inputMap &= ~ControllerPacket.RIGHT_FLAG; + inputMap &= ~ControllerPacket.UP_FLAG; + inputMap &= ~ControllerPacket.DOWN_FLAG; - return false; - } - }); + break; + } - buttonDPadRight = new Button(context); - buttonDPadRight.setText("RI"); - buttonDPadRight.setOnTouchListener(new View.OnTouchListener() - { - @Override - public boolean onTouch(View v, MotionEvent event) - { - onButtonTouchEvent(v, event, ControllerPacket.RIGHT_FLAG); + if ((direction & DigitalPad.DIGITAL_PAD_DIRECTION_LEFT) > 0) + { + inputMap |= ControllerPacket.LEFT_FLAG; + } - return false; - } - }); + if ((direction & DigitalPad.DIGITAL_PAD_DIRECTION_RIGHT) > 0) + { + inputMap |= ControllerPacket.RIGHT_FLAG; + } - buttonDPadUp = new Button(context); - buttonDPadUp.setText("UP"); - buttonDPadUp.setOnTouchListener(new View.OnTouchListener() - { - @Override - public boolean onTouch(View v, MotionEvent event) - { - onButtonTouchEvent(v, event, ControllerPacket.UP_FLAG); + if ((direction & DigitalPad.DIGITAL_PAD_DIRECTION_UP) > 0) + { + inputMap |= ControllerPacket.UP_FLAG; + } - return false; - } - }); + if ((direction & DigitalPad.DIGITAL_PAD_DIRECTION_DOWN) > 0) + { + inputMap |= ControllerPacket.DOWN_FLAG; + } + } + while (false); - buttonDPadDown = new Button(context); - buttonDPadDown.setText("DW"); - buttonDPadDown.setOnTouchListener(new View.OnTouchListener() - { - @Override - public boolean onTouch(View v, MotionEvent event) - { - onButtonTouchEvent(v, event, ControllerPacket.DOWN_FLAG); + sendControllerInputPacket(); + } + }); - return false; - } - }); - - buttonX = new Button(context); + buttonX = new DigitalButton(context); buttonX.setText("X"); - buttonX.setOnTouchListener(new View.OnTouchListener() - { - @Override - public boolean onTouch(View v, MotionEvent event) - { - onButtonTouchEvent(v, event, ControllerPacket.X_FLAG); + buttonX.addDigitalButtonListener(new DigitalButton.DigitalButtonListener() { + @Override + public void onClick() { + inputMap |= ControllerPacket.X_FLAG; + sendControllerInputPacket(); + } - return false; - } - }); + @Override + public void onRelease() { + inputMap &= ControllerPacket.X_FLAG; + sendControllerInputPacket(); + } + }); - buttonY = new Button(context); + buttonY = new DigitalButton(context); buttonY.setText("Y"); - buttonY.setOnTouchListener(new View.OnTouchListener() - { - @Override - public boolean onTouch(View v, MotionEvent event) - { - onButtonTouchEvent(v, event, ControllerPacket.Y_FLAG); + buttonY.addDigitalButtonListener(new DigitalButton.DigitalButtonListener() + { + @Override + public void onClick() + { + inputMap |= ControllerPacket.Y_FLAG; + sendControllerInputPacket(); + } - return false; - } - }); + @Override + public void onRelease() + { + inputMap &= ControllerPacket.Y_FLAG; + sendControllerInputPacket(); + } + }); - buttonA = new Button(context); + buttonA = new DigitalButton(context); buttonA.setText("A"); - buttonA.setOnTouchListener(new View.OnTouchListener() - { - @Override - public boolean onTouch(View v, MotionEvent event) - { - onButtonTouchEvent(v, event, ControllerPacket.A_FLAG); + buttonA.addDigitalButtonListener(new DigitalButton.DigitalButtonListener() { + @Override + public void onClick() { + inputMap |= ControllerPacket.A_FLAG; + sendControllerInputPacket(); + } - return false; - } - }); + @Override + public void onRelease() { + inputMap &= ControllerPacket.A_FLAG; + sendControllerInputPacket(); + } + }); - buttonB = new Button(context); + buttonB = new DigitalButton(context); buttonB.setText("B"); - buttonB.setOnTouchListener(new View.OnTouchListener() - { - @Override - public boolean onTouch(View v, MotionEvent event) - { - onButtonTouchEvent(v, event, ControllerPacket.B_FLAG); + buttonB.addDigitalButtonListener(new DigitalButton.DigitalButtonListener() { + @Override + public void onClick() { + inputMap |= ControllerPacket.B_FLAG; + sendControllerInputPacket(); + } - return false; - } - }); + @Override + public void onRelease() { + inputMap &= ControllerPacket.B_FLAG; + sendControllerInputPacket(); + } + }); - buttonLT = new Button(context); + buttonLT = new DigitalButton(context); buttonLT.setText("LT"); - buttonLT.setOnTouchListener(new View.OnTouchListener() { + buttonLT.addDigitalButtonListener(new DigitalButton.DigitalButtonListener() + { @Override - public boolean onTouch(View v, MotionEvent event) { - // get masked (not specific to a pointer) action - int action = event.getActionMasked(); + public void onClick() + { + leftTrigger = (byte) (1 * 0xFF); - switch (action) { - case MotionEvent.ACTION_DOWN: - case MotionEvent.ACTION_POINTER_DOWN: { - leftTrigger = (byte) (1 * 0xFF); + sendControllerInputPacket(); + } - sendControllerInputPacket(); + @Override + public void onRelease() + { + leftTrigger = (byte) (0 * 0xFF); - break; - } - - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_POINTER_UP: { - leftTrigger = (byte) (0 * 0xFF); - - sendControllerInputPacket(); - - break; - } - } - - return false; + sendControllerInputPacket(); } }); - buttonRT = new Button(context); + buttonRT = new DigitalButton(context); buttonRT.setText("RT"); - buttonRT.setOnTouchListener(new View.OnTouchListener() { + buttonRT.addDigitalButtonListener(new DigitalButton.DigitalButtonListener() + { @Override - public boolean onTouch(View v, MotionEvent event) { - // get masked (not specific to a pointer) action - int action = event.getActionMasked(); + public void onClick() + { + rightTrigger = (byte) (0xFF); - switch (action) { - case MotionEvent.ACTION_DOWN: - case MotionEvent.ACTION_POINTER_DOWN: { - rightTrigger = (byte) (1 * 0xFF); + sendControllerInputPacket(); + } - sendControllerInputPacket(); + @Override + public void onRelease() + { + rightTrigger = (byte) (0); - break; - } - - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_POINTER_UP: { - rightTrigger = (byte) (0 * 0xFF); - - sendControllerInputPacket(); - - break; - } - } - - return false; + sendControllerInputPacket(); } }); - buttonLB = new Button(context); + buttonLB = new DigitalButton(context); buttonLB.setText("LB"); - buttonLB.setOnTouchListener(new View.OnTouchListener() - { + buttonLB.addDigitalButtonListener(new DigitalButton.DigitalButtonListener() { @Override - public boolean onTouch(View v, MotionEvent event) - { - onButtonTouchEvent(v, event, ControllerPacket.LB_FLAG); + public void onClick() { + inputMap |= ControllerPacket.LB_FLAG; + sendControllerInputPacket(); + } - return false; + @Override + public void onRelease() { + inputMap &= ControllerPacket.LB_FLAG; + sendControllerInputPacket(); } }); - buttonRB = new Button(context); + buttonRB = new DigitalButton(context); buttonRB.setText("RB"); - buttonRB.setOnTouchListener(new View.OnTouchListener() - { + buttonRB.addDigitalButtonListener(new DigitalButton.DigitalButtonListener() { @Override - public boolean onTouch(View v, MotionEvent event) - { - onButtonTouchEvent(v, event, ControllerPacket.RB_FLAG); + public void onClick() { + inputMap |= ControllerPacket.RB_FLAG; + sendControllerInputPacket(); + } - return false; + @Override + public void onRelease() { + inputMap &= ControllerPacket.RB_FLAG; + sendControllerInputPacket(); } }); @@ -450,40 +427,30 @@ public class VirtualController frame_layout.addView(relative_layout); - buttonDPadLeft = new Button(context); - buttonDPadLeft.setText("LF"); + digitalPad = new DigitalPad(context); - buttonDPadRight = new Button(context); - buttonDPadRight.setText("RI"); - - buttonDPadUp = new Button(context); - buttonDPadUp.setText("UP"); - - buttonDPadDown = new Button(context); - buttonDPadDown.setText("DW"); - - buttonX = new Button(context); + buttonX = new DigitalButton(context); buttonX.setText("X"); - buttonY = new Button(context); + buttonY = new DigitalButton(context); buttonY.setText("Y"); - buttonA = new Button(context); + buttonA = new DigitalButton(context); buttonA.setText("A"); - buttonB = new Button(context); + buttonB = new DigitalButton(context); buttonB.setText("B"); - buttonLT = new Button(context); + buttonLT = new DigitalButton(context); buttonLT.setText("LT"); - buttonRT = new Button(context); + buttonRT = new DigitalButton(context); buttonRT.setText("RT"); - buttonLB = new Button(context); + buttonLB = new DigitalButton(context); buttonLB.setText("LB"); - buttonRB = new Button(context); + buttonRB = new DigitalButton(context); buttonRB.setText("RB"); stick = new AnalogStick(context);