diff --git a/Source/Android/AndroidManifest.xml b/Source/Android/AndroidManifest.xml index 2e3964c65f..5b2a3cfee9 100644 --- a/Source/Android/AndroidManifest.xml +++ b/Source/Android/AndroidManifest.xml @@ -38,6 +38,8 @@ + + diff --git a/Source/Android/res/drawable/button_a.png b/Source/Android/res/drawable/button_a.png new file mode 100644 index 0000000000..7e685324ae Binary files /dev/null and b/Source/Android/res/drawable/button_a.png differ diff --git a/Source/Android/res/drawable/button_b.png b/Source/Android/res/drawable/button_b.png new file mode 100644 index 0000000000..21da4c20f1 Binary files /dev/null and b/Source/Android/res/drawable/button_b.png differ diff --git a/Source/Android/res/drawable/button_start.png b/Source/Android/res/drawable/button_start.png new file mode 100644 index 0000000000..e79a9269ee Binary files /dev/null and b/Source/Android/res/drawable/button_start.png differ diff --git a/Source/Android/res/layout/emulation_view.xml b/Source/Android/res/layout/emulation_view.xml index 62cbbe703e..c4648b577b 100644 --- a/Source/Android/res/layout/emulation_view.xml +++ b/Source/Android/res/layout/emulation_view.xml @@ -11,4 +11,12 @@ android:focusable="false" android:focusableInTouchMode="false"/> + + + \ No newline at end of file diff --git a/Source/Android/res/layout/input_overlay_config_layout.xml b/Source/Android/res/layout/input_overlay_config_layout.xml new file mode 100644 index 0000000000..868f0b3166 --- /dev/null +++ b/Source/Android/res/layout/input_overlay_config_layout.xml @@ -0,0 +1,32 @@ + + + + + + + + + \ No newline at end of file diff --git a/Source/Android/res/xml/input_prefs.xml b/Source/Android/res/xml/input_prefs.xml index 899e559480..5dc15ac75e 100644 --- a/Source/Android/res/xml/input_prefs.xml +++ b/Source/Android/res/xml/input_prefs.xml @@ -2,86 +2,90 @@ + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + \ No newline at end of file diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/AboutFragment.java b/Source/Android/src/org/dolphinemu/dolphinemu/AboutFragment.java index 8b29e607d7..3695bfa40b 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/AboutFragment.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/AboutFragment.java @@ -20,7 +20,7 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.List; -import org.dolphinemu.dolphinemu.settings.VideoSettingsFragment; +import org.dolphinemu.dolphinemu.settings.video.VideoSettingsFragment; /** * Represents the about screen. diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/EmulationActivity.java b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/EmulationActivity.java index 912fc021c5..8b8f4e0551 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/EmulationActivity.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/EmulationActivity.java @@ -21,8 +21,8 @@ import android.view.WindowManager.LayoutParams; import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.R; -import org.dolphinemu.dolphinemu.settings.InputConfigFragment; -import org.dolphinemu.dolphinemu.settings.VideoSettingsFragment; +import org.dolphinemu.dolphinemu.settings.input.InputConfigFragment; +import org.dolphinemu.dolphinemu.settings.video.VideoSettingsFragment; import java.util.List; diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlay.java b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlay.java new file mode 100644 index 0000000000..c2272fdc5f --- /dev/null +++ b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlay.java @@ -0,0 +1,64 @@ +package org.dolphinemu.dolphinemu.emulation.overlay; + +import java.util.HashSet; +import java.util.Set; + +import android.content.Context; +import android.graphics.Canvas; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.SurfaceView; +import android.view.View; +import android.view.View.OnTouchListener; + +/** + * Draws the interactive input overlay on top of the + * {@link NativeGLSurfaceView} that is rendering emulation. + */ +public final class InputOverlay extends SurfaceView implements OnTouchListener +{ + private final Set overlayItems = new HashSet(); + + /** + * Constructor + * + * @param context The current {@link Context}. + * @param attrs {@link AttributeSet} for parsing XML attributes. + */ + public InputOverlay(Context context, AttributeSet attrs) + { + super(context, attrs); + + // Force draw + setWillNotDraw(false); + + // Request focus for the overlay so it has priority on presses. + requestFocus(); + } + + @Override + public boolean onTouch(View v, MotionEvent event) + { + switch (event.getAction()) + { + case MotionEvent.ACTION_DOWN: + { + // TODO: Handle down presses. + return true; + } + } + + return false; + } + + @Override + public void onDraw(Canvas canvas) + { + super.onDraw(canvas); + + for (InputOverlayItem item : overlayItems) + { + item.draw(canvas); + } + } +} diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayItem.java b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayItem.java new file mode 100644 index 0000000000..a45578b263 --- /dev/null +++ b/Source/Android/src/org/dolphinemu/dolphinemu/emulation/overlay/InputOverlayItem.java @@ -0,0 +1,107 @@ +package org.dolphinemu.dolphinemu.emulation.overlay; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.drawable.BitmapDrawable; + +/** + * Represents a drawable image for the {@link InputOverlay} + */ +public final class InputOverlayItem +{ + // The image as a BitmapDrawable + private BitmapDrawable drawable; + + // Width and height of the underlying image. + private int width; + private int height; + + // X and Y coordinates to display this item at. + private int x; + private int y; + + // Image scale factor. + private float scaleFactor = 1.0f; + + // Rectangle that we draw this item to. + private Rect drawRect; + + /** + * Constructor. + * + * @param res Reference to the app resources for fetching display metrics. + * @param resId Resource ID of the {@link BitmapDrawable} to encapsulate. + */ + public InputOverlayItem(Resources res, int resId) + { + // Idiot-proof the constructor. + if (res == null) + throw new IllegalArgumentException("res cannot be null"); + + // Everything is valid, decode the filename as a bitmap. + drawable = (BitmapDrawable) res.getDrawable(resId); + Bitmap image = drawable.getBitmap(); + + // Set width/height + width = image.getWidth(); + height = image.getHeight(); + + // Initialize rectangle to zero width, height, x, and y. + drawRect = new Rect(); + } + + /** + * Constructor + * + * @param res Reference to the app resources for fetching display metrics. + * @param resId Resource ID of the {@link BitmapDrawable} to encapsulate. + * @param x X coordinate on the screen to place the control. + * @param y Y coordinate on the screen to place the control. + */ + public InputOverlayItem(Resources res, int resId, int x, int y) + { + this(res, resId); + + setPosition(x, y); + } + + /** + * Sets the position of this item on the screen. + * + * @param x New x-coordinate for this image. + * @param y New y-coordinate for this image. + */ + public void setPosition(int x, int y) + { + this.x = x; + this.y = y; + + drawRect.set(x, y, x + (int)(width * scaleFactor), y + (int)(height * scaleFactor)); + drawable.setBounds(drawRect); + } + + /** + * Sets a new scaling factor for the current image. + * + * @param scaleFactor The new scaling factor. Note that 1.0 is normal size. + */ + public void setScaleFactor(float scaleFactor) + { + this.scaleFactor = scaleFactor; + + // Adjust for the new scale factor. + setPosition(x, y); + } + + /** + * Draws this item to a given canvas. + * + * @param canvas The canvas to draw this item to. + */ + public void draw(Canvas canvas) + { + drawable.draw(canvas); + } +} diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/settings/PrefsActivity.java b/Source/Android/src/org/dolphinemu/dolphinemu/settings/PrefsActivity.java index 51153866e1..5368475319 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/settings/PrefsActivity.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/settings/PrefsActivity.java @@ -7,6 +7,9 @@ package org.dolphinemu.dolphinemu.settings; import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.settings.cpu.CPUSettingsFragment; +import org.dolphinemu.dolphinemu.settings.input.InputConfigFragment; +import org.dolphinemu.dolphinemu.settings.video.VideoSettingsFragment; import android.app.ActionBar; import android.app.ActionBar.Tab; diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/settings/CPUSettingsFragment.java b/Source/Android/src/org/dolphinemu/dolphinemu/settings/cpu/CPUSettingsFragment.java similarity index 96% rename from Source/Android/src/org/dolphinemu/dolphinemu/settings/CPUSettingsFragment.java rename to Source/Android/src/org/dolphinemu/dolphinemu/settings/cpu/CPUSettingsFragment.java index 47f0cb7d35..77caec2b83 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/settings/CPUSettingsFragment.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/settings/cpu/CPUSettingsFragment.java @@ -4,7 +4,7 @@ * Refer to the license.txt file included. */ -package org.dolphinemu.dolphinemu.settings; +package org.dolphinemu.dolphinemu.settings.cpu; import org.dolphinemu.dolphinemu.R; diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/settings/InputConfigFragment.java b/Source/Android/src/org/dolphinemu/dolphinemu/settings/input/InputConfigFragment.java similarity index 95% rename from Source/Android/src/org/dolphinemu/dolphinemu/settings/InputConfigFragment.java rename to Source/Android/src/org/dolphinemu/dolphinemu/settings/input/InputConfigFragment.java index a23f1b4a3f..2ada44ccff 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/settings/InputConfigFragment.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/settings/input/InputConfigFragment.java @@ -4,12 +4,13 @@ * Refer to the license.txt file included. */ -package org.dolphinemu.dolphinemu.settings; +package org.dolphinemu.dolphinemu.settings.input; import android.app.AlertDialog; import android.app.Fragment; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.preference.Preference; @@ -115,9 +116,17 @@ public final class InputConfigFragment extends PreferenceFragment // Everything is set, show the dialog. dialog.show(); + return true; } - return true; + if (pref.getKey().equals("inputOverlayConfigPref")) + { + Intent inputOverlayConfig = new Intent(getActivity(), InputOverlayConfigActivity.class); + startActivity(inputOverlayConfig); + return true; + } + + return false; } /** diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/settings/input/InputOverlayConfigActivity.java b/Source/Android/src/org/dolphinemu/dolphinemu/settings/input/InputOverlayConfigActivity.java new file mode 100644 index 0000000000..3084c181d1 --- /dev/null +++ b/Source/Android/src/org/dolphinemu/dolphinemu/settings/input/InputOverlayConfigActivity.java @@ -0,0 +1,27 @@ +/** + * Copyright 2013 Dolphin Emulator Project + * Licensed under GPLv2 + * Refer to the license.txt file included. + */ + +package org.dolphinemu.dolphinemu.settings.input; + +import org.dolphinemu.dolphinemu.R; + +import android.app.Activity; +import android.os.Bundle; + +/** + * {@link Activity} used for configuring the input overlay. + */ +public final class InputOverlayConfigActivity extends Activity +{ + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + + // Set the initial layout. + setContentView(R.layout.input_overlay_config_layout); + } +} diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/settings/input/InputOverlayConfigButton.java b/Source/Android/src/org/dolphinemu/dolphinemu/settings/input/InputOverlayConfigButton.java new file mode 100644 index 0000000000..cca596e85c --- /dev/null +++ b/Source/Android/src/org/dolphinemu/dolphinemu/settings/input/InputOverlayConfigButton.java @@ -0,0 +1,52 @@ +/** + * Copyright 2013 Dolphin Emulator Project + * Licensed under GPLv2 + * Refer to the license.txt file included. + */ + +package org.dolphinemu.dolphinemu.settings.input; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.view.View.OnTouchListener; +import android.widget.Button; + +/** + * A movable {@link Button} for use within the + * input overlay configuration screen. + */ +public final class InputOverlayConfigButton extends Button implements OnTouchListener +{ + /** + * Constructor + * + * @param context The current {@link Context}. + * @param attribs {@link AttributeSet} for parsing XML attributes. + */ + public InputOverlayConfigButton(Context context, AttributeSet attribs) + { + super(context, attribs); + + // Set the button as its own OnTouchListener. + setOnTouchListener(this); + } + + @Override + public boolean onTouch(View v, MotionEvent event) + { + switch(event.getAction()) + { + // Only change the X/Y coordinates when we move the button. + case MotionEvent.ACTION_MOVE: + { + setX(getX() + event.getX()); + setY(getY() + event.getY()); + return true; + } + } + + return false; + } +} diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/settings/VideoSettingsFragment.java b/Source/Android/src/org/dolphinemu/dolphinemu/settings/video/VideoSettingsFragment.java similarity index 99% rename from Source/Android/src/org/dolphinemu/dolphinemu/settings/VideoSettingsFragment.java rename to Source/Android/src/org/dolphinemu/dolphinemu/settings/video/VideoSettingsFragment.java index fffea888a7..47f9ef475f 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/settings/VideoSettingsFragment.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/settings/video/VideoSettingsFragment.java @@ -4,7 +4,7 @@ * Refer to the license.txt file included. */ -package org.dolphinemu.dolphinemu.settings; +package org.dolphinemu.dolphinemu.settings.video; import android.app.Activity; import android.content.SharedPreferences;