[Android] Build the configuration window for the overlay programmatically. Moved the overlay configuration classes into their own package. Also launch the overlay config activity through the preference XML via an embedded Intent. Lets us remove code explicitly handling this.

This commit is contained in:
Lioncash 2013-11-25 14:23:28 -05:00
parent 7718c9959e
commit 76843b450b
7 changed files with 73 additions and 114 deletions

View File

@ -40,7 +40,7 @@
android:screenOrientation="landscape" />
<activity
android:name="org.dolphinemu.dolphinemu.settings.input.InputOverlayConfigActivity"
android:name="org.dolphinemu.dolphinemu.settings.input.overlayconfig.OverlayConfigActivity"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

View File

@ -1,56 +0,0 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/inputLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipChildren="false"
android:clipToPadding="false" >
<org.dolphinemu.dolphinemu.settings.input.InputOverlayConfigButton
android:id="@+id/button_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:layout_alignParentEnd="false"
android:layout_alignParentLeft="false"
android:layout_alignParentRight="false"
android:layout_alignParentStart="false"
android:layout_alignParentTop="false"
android:layout_alignWithParentIfMissing="false"
android:layout_centerHorizontal="false"
android:layout_centerInParent="false"
android:layout_centerVertical="false"
android:background="@drawable/button_a" />
<org.dolphinemu.dolphinemu.settings.input.InputOverlayConfigButton
android:id="@+id/button_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:layout_alignParentEnd="false"
android:layout_alignParentLeft="false"
android:layout_alignParentRight="false"
android:layout_alignParentStart="false"
android:layout_alignParentTop="false"
android:layout_alignWithParentIfMissing="false"
android:layout_centerHorizontal="false"
android:layout_centerInParent="false"
android:layout_centerVertical="false"
android:background="@drawable/button_b" />
<org.dolphinemu.dolphinemu.settings.input.InputOverlayConfigButton
android:id="@+id/button_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:layout_alignParentEnd="false"
android:layout_alignParentLeft="false"
android:layout_alignParentRight="false"
android:layout_alignParentStart="false"
android:layout_alignParentTop="false"
android:layout_alignWithParentIfMissing="false"
android:layout_centerHorizontal="false"
android:layout_centerInParent="false"
android:layout_centerVertical="false"
android:background="@drawable/button_start" />
</RelativeLayout>

View File

@ -5,7 +5,11 @@
<Preference
android:key="inputOverlayConfigPref"
android:summary="@string/input_overlay_layout_desc"
android:title="@string/input_overlay_layout"/>
android:title="@string/input_overlay_layout">
<intent
android:targetPackage="org.dolphinemu.dolphinemu"
android:targetClass="org.dolphinemu.dolphinemu.settings.input.overlayconfig.OverlayConfigActivity"/>
</Preference>
<!-- Gamecube controller bindings -->
<PreferenceScreen

View File

@ -9,12 +9,10 @@ package org.dolphinemu.dolphinemu.settings.input;
import java.util.List;
import android.app.Fragment;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.view.InputDevice;
import org.dolphinemu.dolphinemu.NativeLibrary;
@ -102,18 +100,4 @@ public final class InputConfigFragment extends PreferenceFragment
return fakeid;
}
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference pref)
{
// If the user has clicked the option to configure the input overlay.
if (pref.getTitle().equals(getString(R.string.input_overlay_layout)))
{
Intent inputOverlayConfig = new Intent(getActivity(), InputOverlayConfigActivity.class);
startActivity(inputOverlayConfig);
return true;
}
return false;
}
}

View File

@ -1,27 +0,0 @@
/**
* 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,39 @@
/**
* Copyright 2013 Dolphin Emulator Project
* Licensed under GPLv2
* Refer to the license.txt file included.
*/
package org.dolphinemu.dolphinemu.settings.input.overlayconfig;
import org.dolphinemu.dolphinemu.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RelativeLayout;
/**
* {@link Activity} used for configuring the input overlay.
*/
public final class OverlayConfigActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Initialize all of the buttons to add.
final OverlayConfigButton buttonA = new OverlayConfigButton(this, "button_a", R.drawable.button_a);
final OverlayConfigButton buttonB = new OverlayConfigButton(this, "button_b", R.drawable.button_b);
final OverlayConfigButton buttonS = new OverlayConfigButton(this, "button_start", R.drawable.button_start);
// Add the buttons to the layout
final RelativeLayout configLayout = new RelativeLayout(this);
configLayout.addView(buttonA);
configLayout.addView(buttonB);
configLayout.addView(buttonS);
// Now set the layout
setContentView(configLayout);
}
}

View File

@ -4,12 +4,11 @@
* Refer to the license.txt file included.
*/
package org.dolphinemu.dolphinemu.settings.input;
package org.dolphinemu.dolphinemu.settings.input.overlayconfig;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
@ -19,30 +18,48 @@ import android.widget.Button;
* A movable {@link Button} for use within the
* input overlay configuration screen.
*/
public final class InputOverlayConfigButton extends Button implements OnTouchListener
public final class OverlayConfigButton extends Button implements OnTouchListener
{
// SharedPreferences instance that the button positions are cached to.
private final SharedPreferences sharedPrefs;
// The String ID for this button.
//
// This ID is used upon releasing this button as the key for saving
// the X and Y coordinates of this button. This same key is also used
// for setting the coordinates of the button on the actual overlay during emulation.
//
// They can be accessed through SharedPreferences respectively as follows:
//
// SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(this);
// float buttonX = sPrefs.getFloat(buttonId+"-X", -1f);
// float buttonY = sPrefs.getFloat(buttonId+"-Y", -1f);
//
private final String buttonId;
/**
* Constructor
*
* @param context The current {@link Context}.
* @param attribs {@link AttributeSet} for parsing XML attributes.
* @param context the current {@link Context}.
* @param buttonId the String ID for this button.
* @param drawableId the Drawable ID for the image to represent this OverlayConfigButton.
*/
public InputOverlayConfigButton(Context context, AttributeSet attribs)
public OverlayConfigButton(Context context, String buttonId, int drawableId)
{
super(context, attribs);
super(context);
// Set the button ID.
this.buttonId = buttonId;
// Set the button as its own OnTouchListener.
setOnTouchListener(this);
// Set the button's icon that represents it.
setBackground(context.getResources().getDrawable(drawableId));
// Get the SharedPreferences instance.
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
// String ID of this button.
final String buttonId = getResources().getResourceEntryName(getId());
// Check if this button has previous values set that aren't the default.
final float x = sharedPrefs.getFloat(buttonId+"-X", -1f);
final float y = sharedPrefs.getFloat(buttonId+"-Y", -1f);
@ -73,14 +90,12 @@ public final class InputOverlayConfigButton extends Button implements OnTouchLis
// is when we save all of the information.
case MotionEvent.ACTION_UP:
{
// String ID of this button.
String buttonId = getResources().getResourceEntryName(getId());
// Add the current X and Y positions of this button into SharedPreferences.
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putFloat(buttonId+"-X", getX());
editor.putFloat(buttonId+"-Y", getY());
editor.commit();
return true;
}
}