summaryrefslogtreecommitdiff
path: root/Source/Android/src/org
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2013-11-15 12:26:17 -0500
committerLioncash <mathew1800@gmail.com>2013-11-15 12:26:17 -0500
commit07765aa6f0f84992fbb61e16025bd343821cc378 (patch)
tree35fe78a805ff41b7bab5938ba20524a990f5a91c /Source/Android/src/org
parent1e90a838f2bb77ead35eac5c0f270d3727732e38 (diff)
[Android] Documentation and some cleanup.
Diffstat (limited to 'Source/Android/src/org')
-rw-r--r--Source/Android/src/org/dolphinemu/dolphinemu/NativeLibrary.java11
-rw-r--r--Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlay.java100
-rw-r--r--Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableButton.java2
-rw-r--r--Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableJoystick.java26
4 files changed, 71 insertions, 68 deletions
diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/src/org/dolphinemu/dolphinemu/NativeLibrary.java
index 58b33d393d..07bea528ba 100644
--- a/Source/Android/src/org/dolphinemu/dolphinemu/NativeLibrary.java
+++ b/Source/Android/src/org/dolphinemu/dolphinemu/NativeLibrary.java
@@ -45,7 +45,7 @@ public final class NativeLibrary
/**
* Button states
*/
- public class ButtonState
+ public static final class ButtonState
{
public static final int RELEASED = 0;
public static final int PRESSED = 1;
@@ -60,12 +60,13 @@ public final class NativeLibrary
public static native void onTouchEvent(int Button, int Action);
/**
- * Handles touch events.
+ * Handles axis-related touch events.
*
- * @param Button Key code identifying which button was pressed.
- * @param Action Mask for the action being performed.
+ * @param Axis Axis ID for the type of axis being altered. (Example: Main stick up, down, left, right, etc).
+ * @param force How 'far down' the joystick is pushed down. 0.0f indicates center (or no force),
+ * 1.0f indicates max force (or joystick pushed all the way down in any arbitrary direction).
*/
- public static native void onTouchAxisEvent(int Axis, float loc);
+ public static native void onTouchAxisEvent(int Axis, float force);
/**
* Handles button press events for a gamepad.
diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlay.java b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlay.java
index c3b4e5c734..359f25f17e 100644
--- a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlay.java
+++ b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlay.java
@@ -13,9 +13,7 @@ import android.graphics.*;
import android.graphics.drawable.Drawable;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.MotionEvent;
-import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener;
@@ -26,21 +24,16 @@ import org.dolphinemu.dolphinemu.R;
import java.util.HashSet;
import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Semaphore;
/**
* Draws the interactive input overlay on top of the
* {@link NativeGLSurfaceView} that is rendering emulation.
*/
-public final class InputOverlay extends SurfaceView implements OnTouchListener, Runnable
+public final class InputOverlay extends SurfaceView implements OnTouchListener
{
private final Set<InputOverlayDrawableButton> overlayButtons = new HashSet<InputOverlayDrawableButton>();
private final Set<InputOverlayDrawableJoystick> overlayJoysticks = new HashSet<InputOverlayDrawableJoystick>();
- Semaphore _sema;
- SurfaceHolder surfaceHolder;
- Thread thread = null;
/**
* Constructor
*
@@ -68,56 +61,40 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener,
// Request focus for the overlay so it has priority on presses.
requestFocus();
- _sema = new Semaphore(0);
-
- surfaceHolder = getHolder();
- surfaceHolder.setFormat(PixelFormat.TRANSPARENT);
- thread = new Thread(this);
- thread.start();
}
- private boolean Draw()
+
+ @Override
+ public void draw(Canvas canvas)
{
- if(surfaceHolder.getSurface().isValid()){
- // Draw everything
- Canvas canvas = surfaceHolder.lockCanvas();
- canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
- for (InputOverlayDrawableButton item : overlayButtons)
- item.draw(canvas);
- for (InputOverlayDrawableJoystick item : overlayJoysticks)
- item.Draw(canvas);
- surfaceHolder.unlockCanvasAndPost(canvas);
- return true;
+ super.onDraw(canvas);
+
+ for (InputOverlayDrawableButton button : overlayButtons)
+ {
+ button.draw(canvas);
}
- return false;
- }
- @Override
- public void run() {
- boolean didFirstPost = false;
- while(!didFirstPost)
- if (Draw())
- didFirstPost = true;
- while(true){
- try
- {
- _sema.acquire();
- Draw();
- } catch (InterruptedException ex) {}
+
+ for (InputOverlayDrawableJoystick joystick: overlayJoysticks)
+ {
+ joystick.draw(canvas);
}
}
+
@Override
public boolean onTouch(View v, MotionEvent event)
{
// Determine the button state to apply based on the MotionEvent action flag.
// TODO: This will not work when Axis support is added. Make sure to refactor this when that time comes
// The reason it won't work is that when moving an axis, you would get the event MotionEvent.ACTION_MOVE.
+ //
+ // TODO: Refactor this so we detect either Axis movements or button presses so we don't run two loops all the time.
+ //
int buttonState = (event.getAction() == MotionEvent.ACTION_DOWN) ? ButtonState.PRESSED : ButtonState.RELEASED;
-
- for (InputOverlayDrawableButton item : overlayButtons)
+ for (InputOverlayDrawableButton button : overlayButtons)
{
// Check if there was a touch within the bounds of a drawable.
- if (item.getBounds().contains((int)event.getX(), (int)event.getY()))
+ if (button.getBounds().contains((int)event.getX(), (int)event.getY()))
{
- switch (item.getId())
+ switch (button.getId())
{
case ButtonType.BUTTON_A:
NativeLibrary.onTouchEvent(ButtonType.BUTTON_A, buttonState);
@@ -136,16 +113,18 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener,
}
}
}
- for (InputOverlayDrawableJoystick item : overlayJoysticks)
+
+ for (InputOverlayDrawableJoystick joystick : overlayJoysticks)
{
- item.TrackEvent(event);
- int[] axisIDs = item.getAxisIDs();
- float[] axises = item.getAxisValues();
+ joystick.TrackEvent(event);
+ int[] axisIDs = joystick.getAxisIDs();
+ float[] axises = joystick.getAxisValues();
for (int a = 0; a < 4; ++a)
+ {
NativeLibrary.onTouchAxisEvent(axisIDs[a], axises[a]);
+ }
}
- _sema.release();
return true;
}
@@ -214,20 +193,37 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener,
return overlayDrawable;
}
+
+ /**
+ * Initializes an {@link InputOverlayDrawableJoystick}
+ *
+ * @param context The current {@link Context}
+ * @param resOuter Resource ID for the outer image of the joystick (the static image that shows the circular bounds).
+ * @param resInner Resource ID for the inner image of the joystick (the one you actually move around).
+ * @param axisUp Identifier for this type of axis.
+ * @param axisDown Identifier for this type of axis.
+ * @param axisLeft Identifier for this type of axis.
+ * @param axisRight Identifier for this type of axis.
+ *
+ * @return the initialized {@link InputOverlayDrawableJoystick}.
+ */
private static InputOverlayDrawableJoystick initializeOverlayJoystick(Context context, int resOuter, int resInner, int axisUp, int axisDown, int axisLeft, int axisRight)
{
// Resources handle for fetching the initial Drawable resource.
final Resources res = context.getResources();
- // SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableButton.
+ // SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableJoystick.
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
- // Initialize the InputOverlayDrawableButton.
+ // Initialize the InputOverlayDrawableJoystick.
final Bitmap bitmapOuter = BitmapFactory.decodeResource(res, resOuter);
final Bitmap bitmapInner = BitmapFactory.decodeResource(res, resInner);
- // Now set the bounds for the InputOverlayDrawableButton.
- // This will dictate where on the screen (and the what the size) the InputOverlayDrawableButton will be.
+ // TODO: Load coordinates for the drawable from the SharedPreference keys
+ // made from the overlay configuration window in the settings.
+
+ // Now set the bounds for the InputOverlayDrawableJoystick.
+ // This will dictate where on the screen (and the what the size) the InputOverlayDrawableJoystick will be.
int outerSize = bitmapOuter.getWidth() + 256;
int X = 0;
int Y = 0;
diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableButton.java b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableButton.java
index 12343b586f..4c63f9541b 100644
--- a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableButton.java
+++ b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableButton.java
@@ -14,7 +14,7 @@ import android.graphics.drawable.BitmapDrawable;
* Custom {@link BitmapDrawable} that is capable
* of storing it's own ID.
*/
-public class InputOverlayDrawableButton extends BitmapDrawable
+public final class InputOverlayDrawableButton extends BitmapDrawable
{
// The ID identifying what type of button this Drawable represents.
private int buttonType;
diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableJoystick.java b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableJoystick.java
index 0ceb5b9186..a115305fa2 100644
--- a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableJoystick.java
+++ b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayDrawableJoystick.java
@@ -14,22 +14,21 @@ import android.graphics.drawable.BitmapDrawable;
import android.view.MotionEvent;
/**
- * Custom {@link android.graphics.drawable.BitmapDrawable} that is capable
+ * Custom {@link BitmapDrawable} that is capable
* of storing it's own ID.
*/
-public class InputOverlayDrawableJoystick extends BitmapDrawable
+public final class InputOverlayDrawableJoystick extends BitmapDrawable
{
- // The ID identifying what type of button this Drawable represents.
- private int axisIDs[] = {0, 0, 0, 0};
- private float axises[] = {0f, 0f};
+ private final int[] axisIDs = {0, 0, 0, 0};
+ private final float[] axises = {0f, 0f};
+ private final BitmapDrawable ringInner;
private int trackid = -1;
- private BitmapDrawable ringInner;
/**
* Constructor
*
- * @param res {@link android.content.res.Resources} instance.
- * @param bitmapOuter {@link android.graphics.Bitmap} to use with this Drawable.
+ * @param res {@link Resources} instance.
+ * @param bitmapOuter {@link Bitmap} to use with this Drawable.
* @param axisUp Identifier for this type of axis.
* @param axisDown Identifier for this type of axis.
* @param axisLeft Identifier for this type of axis.
@@ -51,11 +50,15 @@ public class InputOverlayDrawableJoystick extends BitmapDrawable
this.axisIDs[2] = axisLeft;
this.axisIDs[3] = axisRight;
}
- public void Draw(Canvas canvas)
+
+ @Override
+ public void draw(Canvas canvas)
{
- this.draw(canvas);
+ super.draw(canvas);
+
ringInner.draw(canvas);
}
+
public void TrackEvent(MotionEvent event)
{
int pointerIndex = event.getActionIndex();
@@ -95,6 +98,7 @@ public class InputOverlayDrawableJoystick extends BitmapDrawable
SetInnerBounds();
}
+
public float[] getAxisValues()
{
float[] joyaxises = new float[4];
@@ -120,10 +124,12 @@ public class InputOverlayDrawableJoystick extends BitmapDrawable
}
return joyaxises;
}
+
public int[] getAxisIDs()
{
return axisIDs;
}
+
private void SetInnerBounds()
{
float floatX = this.getBounds().centerX();