[Android] Implement a very basic version of the input overlay configuration screen.

Still a bit of a mess, but this will get cleaned up during finalizations.
This commit is contained in:
Lioncash 2013-10-25 16:52:46 -04:00
parent 1267877e80
commit 9f36081a8f
17 changed files with 395 additions and 87 deletions

View File

@ -38,6 +38,8 @@
<activity android:name="org.dolphinemu.dolphinemu.emulation.EmulationActivity"
android:screenOrientation="landscape" />
<activity android:name="org.dolphinemu.dolphinemu.settings.input.InputOverlayConfigActivity"/>
<activity
android:name="org.dolphinemu.dolphinemu.settings.PrefsActivity"
android:label="@string/settings" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -11,4 +11,12 @@
android:focusable="false"
android:focusableInTouchMode="false"/>
<!-- This is the onscreen input overlay -->
<org.dolphinemu.dolphinemu.emulation.overlay.InputOverlay
android:id="@+id/emulationControlOverlay"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"/>
</merge>

View File

@ -0,0 +1,32 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/inputLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<org.dolphinemu.dolphinemu.settings.input.InputOverlayConfigButton
android:id="@+id/buttonA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/button_a" />
<org.dolphinemu.dolphinemu.settings.input.InputOverlayConfigButton
android:id="@+id/buttonStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/buttonB"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/button_start" />
<org.dolphinemu.dolphinemu.settings.input.InputOverlayConfigButton
android:id="@+id/buttonB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/buttonStart"
android:background="@drawable/button_b" />
</RelativeLayout>

View File

@ -2,86 +2,90 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/input_settings">
<Preference
android:key="inputOverlayConfigPref"
android:title="Butts"/>
<PreferenceScreen android:title="@string/gamecube_bindings">
<Preference
android:key="InputA"
android:title="@string/button_a" />
<PreferenceScreen android:title="@string/gamecube_bindings">
<Preference
android:key="InputA"
android:title="@string/button_a" />
<Preference
android:key="InputB"
android:title="@string/button_b" />
<Preference
android:key="InputX"
android:title="@string/button_x" />
<Preference
android:key="InputY"
android:title="@string/button_y" />
<Preference
android:key="InputZ"
android:title="@string/button_z" />
<Preference
android:key="InputStart"
android:title="@string/button_start" />
<Preference
android:key="DPadUp"
android:title="@string/dpad_up" />
<Preference
android:key="DPadDown"
android:title="@string/dpad_down" />
<Preference
android:key="DPadLeft"
android:title="@string/dpad_left" />
<Preference
android:key="DPadRight"
android:title="@string/dpad_right" />
<Preference
android:key="MainUp"
android:title="@string/main_stick_up" />
<Preference
android:key="MainDown"
android:title="@string/main_stick_down" />
<Preference
android:key="MainLeft"
android:title="@string/main_stick_left" />
<Preference
android:key="MainRight"
android:title="@string/main_stick_right" />
<Preference
android:key="CStickUp"
android:title="@string/c_stick_up" />
<Preference
android:key="CStickDown"
android:title="@string/c_stick_down" />
<Preference
android:key="CStickLeft"
android:title="@string/c_stick_left" />
<Preference
android:key="CStickRight"
android:title="@string/c_stick_right" />
<Preference
android:key="InputL"
android:title="@string/trigger_left" />
<Preference
android:key="InputB"
android:title="@string/button_b" />
<Preference
android:key="InputX"
android:title="@string/button_x" />
<Preference
android:key="InputY"
android:title="@string/button_y" />
<Preference
android:key="InputZ"
android:title="@string/button_z" />
<Preference
android:key="InputStart"
android:title="@string/button_start" />
<Preference
android:key="DPadUp"
android:title="@string/dpad_up" />
<Preference
android:key="DPadDown"
android:title="@string/dpad_down" />
<Preference
android:key="DPadLeft"
android:title="@string/dpad_left" />
<Preference
android:key="DPadRight"
android:title="@string/dpad_right" />
<Preference
android:key="MainUp"
android:title="@string/main_stick_up" />
<Preference
android:key="MainDown"
android:title="@string/main_stick_down" />
<Preference
android:key="MainLeft"
android:title="@string/main_stick_left" />
<Preference
android:key="MainRight"
android:title="@string/main_stick_right" />
<Preference
android:key="CStickUp"
android:title="@string/c_stick_up" />
<Preference
android:key="CStickDown"
android:title="@string/c_stick_down" />
<Preference
android:key="CStickLeft"
android:title="@string/c_stick_left" />
<Preference
android:key="CStickRight"
android:title="@string/c_stick_right" />
<Preference
android:key="InputL"
android:title="@string/trigger_left" />
<Preference
android:key="InputR"
android:title="@string/trigger_right" />
</PreferenceScreen>
<Preference
android:key="InputR"
android:title="@string/trigger_right" />
</PreferenceScreen>
</PreferenceScreen>

View File

@ -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.

View File

@ -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;

View File

@ -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<InputOverlayItem> overlayItems = new HashSet<InputOverlayItem>();
/**
* 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);
}
}
}

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
/**

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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;