[Android] Change input configuration to a fragment.
This commit is contained in:
parent
ee26564c65
commit
d1baa8edd9
|
@ -18,7 +18,6 @@
|
||||||
android:name=".DolphinEmulator"
|
android:name=".DolphinEmulator"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
||||||
android:screenOrientation="landscape"
|
|
||||||
android:configChanges="locale|keyboard|keyboardHidden|navigation|fontScale|uiMode" >
|
android:configChanges="locale|keyboard|keyboardHidden|navigation|fontScale|uiMode" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
@ -31,7 +30,7 @@
|
||||||
android:configChanges="orientation|locale|keyboard|keyboardHidden|navigation|fontScale|uiMode" >
|
android:configChanges="orientation|locale|keyboard|keyboardHidden|navigation|fontScale|uiMode" >
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name="org.dolphinemu.dolphinemu.InputConfigActivity"
|
android:name=".InputConfigFragment"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:configChanges="orientation|locale|keyboard|keyboardHidden|navigation|fontScale|uiMode" >
|
android:configChanges="orientation|locale|keyboard|keyboardHidden|navigation|fontScale|uiMode" >
|
||||||
</activity>
|
</activity>
|
||||||
|
|
|
@ -222,7 +222,7 @@ public class DolphinEmulator<MainActivity> extends Activity
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
InputDevice input = event.getDevice();
|
InputDevice input = event.getDevice();
|
||||||
NativeLibrary.onGamePadEvent(InputConfigActivity.getInputDesc(input), event.getKeyCode(), action);
|
NativeLibrary.onGamePadEvent(InputConfigFragment.getInputDesc(input), event.getKeyCode(), action);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -240,7 +240,7 @@ public class DolphinEmulator<MainActivity> extends Activity
|
||||||
{
|
{
|
||||||
InputDevice.MotionRange range;
|
InputDevice.MotionRange range;
|
||||||
range = motions.get(a);
|
range = motions.get(a);
|
||||||
NativeLibrary.onGamePadMoveEvent(InputConfigActivity.getInputDesc(input), range.getAxis(), event.getAxisValue(range.getAxis()));
|
NativeLibrary.onGamePadMoveEvent(InputConfigFragment.getInputDesc(input), range.getAxis(), event.getAxisValue(range.getAxis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -10,9 +10,7 @@ import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.ActionBarDrawerToggle;
|
import android.support.v4.app.ActionBarDrawerToggle;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.view.Menu;
|
import android.view.*;
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
@ -28,7 +26,8 @@ import java.util.List;
|
||||||
public class GameListActivity extends Activity
|
public class GameListActivity extends Activity
|
||||||
implements GameListFragment.OnGameListZeroListener{
|
implements GameListFragment.OnGameListZeroListener{
|
||||||
|
|
||||||
private int mCurPage = 0;
|
private int mCurFragmentNum = 0;
|
||||||
|
private Fragment mCurFragment;
|
||||||
enum keyTypes {TYPE_STRING, TYPE_BOOL};
|
enum keyTypes {TYPE_STRING, TYPE_BOOL};
|
||||||
|
|
||||||
private ActionBarDrawerToggle mDrawerToggle;
|
private ActionBarDrawerToggle mDrawerToggle;
|
||||||
|
@ -92,15 +91,15 @@ public class GameListActivity extends Activity
|
||||||
|
|
||||||
private void recreateFragment()
|
private void recreateFragment()
|
||||||
{
|
{
|
||||||
Fragment fragment = new GameListFragment();
|
mCurFragment = new GameListFragment();
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
|
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
|
||||||
}
|
}
|
||||||
private void SwitchPage(int toPage)
|
private void SwitchPage(int toPage)
|
||||||
{
|
{
|
||||||
if (mCurPage == toPage)
|
if (mCurFragmentNum == toPage)
|
||||||
return;
|
return;
|
||||||
switch (mCurPage)
|
switch (mCurFragmentNum)
|
||||||
{
|
{
|
||||||
// Settings
|
// Settings
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -145,8 +144,24 @@ public class GameListActivity extends Activity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0: // Settings
|
|
||||||
case 3: // Gamepad settings
|
case 3: // Gamepad settings
|
||||||
|
{
|
||||||
|
InputConfigAdapter adapter = ((InputConfigFragment)mCurFragment).getAdapter();
|
||||||
|
for (int a = 0; a < adapter.getCount(); ++a)
|
||||||
|
{
|
||||||
|
InputConfigItem o = adapter.getItem(a);
|
||||||
|
String config = o.getConfig();
|
||||||
|
String bind = o.getBind();
|
||||||
|
String ConfigValues[] = config.split("-");
|
||||||
|
String Key = ConfigValues[0];
|
||||||
|
String Value = ConfigValues[1];
|
||||||
|
NativeLibrary.SetConfig("Dolphin.ini", Key, Value, bind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0: // Game List
|
||||||
|
case 1: // Folder browser
|
||||||
|
case 4: // About
|
||||||
/* Do Nothing */
|
/* Do Nothing */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -154,10 +169,10 @@ public class GameListActivity extends Activity
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
mCurPage = 0;
|
mCurFragmentNum = 0;
|
||||||
Fragment fragment = new GameListFragment();
|
mCurFragment = new GameListFragment();
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
|
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -168,24 +183,28 @@ public class GameListActivity extends Activity
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
Toast.makeText(mMe, "Loading up settings", Toast.LENGTH_SHORT).show();
|
Toast.makeText(mMe, "Loading up settings", Toast.LENGTH_SHORT).show();
|
||||||
mCurPage = 2;
|
mCurFragmentNum = 2;
|
||||||
Fragment fragment = new PrefsFragment();
|
mCurFragment = new PrefsFragment();
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
|
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
{
|
||||||
Toast.makeText(mMe, "Loading up gamepad config", Toast.LENGTH_SHORT).show();
|
Toast.makeText(mMe, "Loading up gamepad config", Toast.LENGTH_SHORT).show();
|
||||||
Intent ConfigIntent = new Intent(mMe, InputConfigActivity.class);
|
mCurFragmentNum = 3;
|
||||||
startActivityForResult(ConfigIntent, 3);
|
mCurFragment = new InputConfigFragment();
|
||||||
break;
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
|
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
Toast.makeText(mMe, "Loading up About", Toast.LENGTH_SHORT).show();
|
Toast.makeText(mMe, "Loading up About", Toast.LENGTH_SHORT).show();
|
||||||
mCurPage = 4;
|
mCurFragmentNum = 4;
|
||||||
Fragment fragment = new AboutFragment();
|
mCurFragment = new AboutFragment();
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
|
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -264,5 +283,25 @@ public class GameListActivity extends Activity
|
||||||
SwitchPage(0);
|
SwitchPage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface OnGameConfigListener {
|
||||||
|
public boolean onMotionEvent(MotionEvent event);
|
||||||
|
public boolean onKeyEvent(KeyEvent event);
|
||||||
|
}
|
||||||
|
// Gets move(triggers, joystick) events
|
||||||
|
@Override
|
||||||
|
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
||||||
|
if (mCurFragmentNum == 3)
|
||||||
|
if (((OnGameConfigListener)mCurFragment).onMotionEvent(event))
|
||||||
|
return true;
|
||||||
|
return super.dispatchGenericMotionEvent(event);
|
||||||
|
}
|
||||||
|
// Gets button presses
|
||||||
|
@Override
|
||||||
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
|
if (mCurFragmentNum == 3)
|
||||||
|
if (((OnGameConfigListener)mCurFragment).onKeyEvent(event))
|
||||||
|
return true;
|
||||||
|
return super.dispatchKeyEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
package org.dolphinemu.dolphinemu;
|
package org.dolphinemu.dolphinemu;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ListActivity;
|
import android.app.Fragment;
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.InputDevice;
|
import android.view.*;
|
||||||
import android.view.KeyEvent;
|
import android.widget.AdapterView;
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -21,7 +18,10 @@ import java.util.List;
|
||||||
* Licensed under GPLv2
|
* Licensed under GPLv2
|
||||||
* Refer to the license.txt file included.
|
* Refer to the license.txt file included.
|
||||||
*/
|
*/
|
||||||
public class InputConfigActivity extends ListActivity {
|
public class InputConfigFragment extends Fragment
|
||||||
|
implements GameListActivity.OnGameConfigListener{
|
||||||
|
private Activity m_activity;
|
||||||
|
private ListView mDrawerList;
|
||||||
private InputConfigAdapter adapter;
|
private InputConfigAdapter adapter;
|
||||||
private int configPosition = 0;
|
private int configPosition = 0;
|
||||||
boolean Configuring = false;
|
boolean Configuring = false;
|
||||||
|
@ -43,9 +43,9 @@ public class InputConfigActivity extends ListActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState)
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
List<InputConfigItem> Input = new ArrayList<InputConfigItem>();
|
List<InputConfigItem> Input = new ArrayList<InputConfigItem>();
|
||||||
int a = 0;
|
int a = 0;
|
||||||
|
|
||||||
|
@ -71,42 +71,49 @@ public class InputConfigActivity extends ListActivity {
|
||||||
Input.add(a++, new InputConfigItem("Trigger L", "Android-InputL"));
|
Input.add(a++, new InputConfigItem("Trigger L", "Android-InputL"));
|
||||||
Input.add(a++, new InputConfigItem("Trigger R", "Android-InputR"));
|
Input.add(a++, new InputConfigItem("Trigger R", "Android-InputR"));
|
||||||
|
|
||||||
adapter = new InputConfigAdapter(this, R.layout.folderbrowser, Input);
|
adapter = new InputConfigAdapter(m_activity, R.layout.folderbrowser, Input);
|
||||||
setListAdapter(adapter);
|
View rootView = inflater.inflate(R.layout.gamelist_listview, container, false);
|
||||||
}
|
mDrawerList = (ListView) rootView.findViewById(R.id.gamelist);
|
||||||
@Override
|
|
||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
|
||||||
super.onListItemClick(l, v, position, id);
|
|
||||||
InputConfigItem o = adapter.getItem(position);
|
|
||||||
switch(position)
|
|
||||||
{
|
|
||||||
case 0: // On screen controls
|
|
||||||
String newBind;
|
|
||||||
if (o.getBind().equals("True"))
|
|
||||||
{
|
|
||||||
Toast.makeText(this, "Not Drawing on screen controls", Toast.LENGTH_SHORT).show();
|
|
||||||
newBind = "False";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Toast.makeText(this, "Drawing on screen controls", Toast.LENGTH_SHORT).show();
|
|
||||||
newBind = "True";
|
|
||||||
}
|
|
||||||
adapter.remove(o);
|
|
||||||
o.setBind(newBind);
|
|
||||||
adapter.insert(o, position);
|
|
||||||
break;
|
|
||||||
default: // gamepad controls
|
|
||||||
Toast.makeText(this, "Press button to configure " + o.getName(), Toast.LENGTH_SHORT).show();
|
|
||||||
configPosition = position;
|
|
||||||
Configuring = true;
|
|
||||||
firstEvent = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
mDrawerList.setAdapter(adapter);
|
||||||
|
mDrawerList.setOnItemClickListener(mMenuItemClickListener);
|
||||||
|
return mDrawerList;
|
||||||
}
|
}
|
||||||
|
private AdapterView.OnItemClickListener mMenuItemClickListener = new AdapterView.OnItemClickListener()
|
||||||
|
{
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||||
|
{
|
||||||
|
InputConfigItem o = adapter.getItem(position);
|
||||||
|
switch(position)
|
||||||
|
{
|
||||||
|
case 0: // On screen controls
|
||||||
|
String newBind;
|
||||||
|
if (o.getBind().equals("True"))
|
||||||
|
{
|
||||||
|
Toast.makeText(m_activity, "Not Drawing on screen controls", Toast.LENGTH_SHORT).show();
|
||||||
|
newBind = "False";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Toast.makeText(m_activity, "Drawing on screen controls", Toast.LENGTH_SHORT).show();
|
||||||
|
newBind = "True";
|
||||||
|
}
|
||||||
|
adapter.remove(o);
|
||||||
|
o.setBind(newBind);
|
||||||
|
adapter.insert(o, position);
|
||||||
|
break;
|
||||||
|
default: // gamepad controls
|
||||||
|
Toast.makeText(m_activity, "Press button to configure " + o.getName(), Toast.LENGTH_SHORT).show();
|
||||||
|
configPosition = position;
|
||||||
|
Configuring = true;
|
||||||
|
firstEvent = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static ArrayList<Float> m_values = new ArrayList<Float>();
|
static ArrayList<Float> m_values = new ArrayList<Float>();
|
||||||
// Gets move(triggers, joystick) events
|
|
||||||
void AssignBind(String bind)
|
void AssignBind(String bind)
|
||||||
{
|
{
|
||||||
InputConfigItem o = adapter.getItem(configPosition);
|
InputConfigItem o = adapter.getItem(configPosition);
|
||||||
|
@ -114,12 +121,16 @@ public class InputConfigActivity extends ListActivity {
|
||||||
o.setBind(bind);
|
o.setBind(bind);
|
||||||
adapter.insert(o, configPosition);
|
adapter.insert(o, configPosition);
|
||||||
}
|
}
|
||||||
|
public InputConfigAdapter getAdapter()
|
||||||
|
{
|
||||||
|
return adapter;
|
||||||
|
}
|
||||||
|
// Called from GameListActivity
|
||||||
|
public boolean onMotionEvent(MotionEvent event)
|
||||||
|
{
|
||||||
|
if (((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0))
|
||||||
|
return false;
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
|
||||||
if (((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)) {
|
|
||||||
return super.dispatchGenericMotionEvent(event);
|
|
||||||
}
|
|
||||||
InputDevice input = event.getDevice();
|
InputDevice input = event.getDevice();
|
||||||
List<InputDevice.MotionRange> motions = input.getMotionRanges();
|
List<InputDevice.MotionRange> motions = input.getMotionRanges();
|
||||||
if (Configuring)
|
if (Configuring)
|
||||||
|
@ -140,12 +151,12 @@ public class InputConfigActivity extends ListActivity {
|
||||||
range = motions.get(a);
|
range = motions.get(a);
|
||||||
if (m_values.get(a) > (event.getAxisValue(range.getAxis()) + 0.5f))
|
if (m_values.get(a) > (event.getAxisValue(range.getAxis()) + 0.5f))
|
||||||
{
|
{
|
||||||
AssignBind("Device '" + InputConfigActivity.getInputDesc(input) + "'-Axis " + range.getAxis() + "-");
|
AssignBind("Device '" + InputConfigFragment.getInputDesc(input) + "'-Axis " + range.getAxis() + "-");
|
||||||
Configuring = false;
|
Configuring = false;
|
||||||
}
|
}
|
||||||
else if (m_values.get(a) < (event.getAxisValue(range.getAxis()) - 0.5f))
|
else if (m_values.get(a) < (event.getAxisValue(range.getAxis()) - 0.5f))
|
||||||
{
|
{
|
||||||
AssignBind("Device '" + InputConfigActivity.getInputDesc(input) + "'-Axis " + range.getAxis() + "+");
|
AssignBind("Device '" + InputConfigFragment.getInputDesc(input) + "'-Axis " + range.getAxis() + "+");
|
||||||
Configuring = false;
|
Configuring = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,10 +164,8 @@ public class InputConfigActivity extends ListActivity {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public boolean onKeyEvent(KeyEvent event)
|
||||||
// Gets button presses
|
{
|
||||||
@Override
|
|
||||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
|
||||||
Log.w("Dolphinemu", "Got Event " + event.getAction());
|
Log.w("Dolphinemu", "Got Event " + event.getAction());
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case KeyEvent.ACTION_DOWN:
|
case KeyEvent.ACTION_DOWN:
|
||||||
|
@ -164,7 +173,7 @@ public class InputConfigActivity extends ListActivity {
|
||||||
if (Configuring)
|
if (Configuring)
|
||||||
{
|
{
|
||||||
InputDevice input = event.getDevice();
|
InputDevice input = event.getDevice();
|
||||||
AssignBind("Device '" + InputConfigActivity.getInputDesc(input) + "'-Button " + event.getKeyCode());
|
AssignBind("Device '" + InputConfigFragment.getInputDesc(input) + "'-Button " + event.getKeyCode());
|
||||||
Configuring = false;
|
Configuring = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -172,24 +181,20 @@ public class InputConfigActivity extends ListActivity {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.dispatchKeyEvent(event);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onAttach(Activity activity) {
|
||||||
for (int a = 0; a < adapter.getCount(); ++a)
|
super.onAttach(activity);
|
||||||
{
|
|
||||||
InputConfigItem o = adapter.getItem(a);
|
// This makes sure that the container activity has implemented
|
||||||
String config = o.getConfig();
|
// the callback interface. If not, it throws an exception
|
||||||
String bind = o.getBind();
|
try {
|
||||||
String ConfigValues[] = config.split("-");
|
m_activity = activity;
|
||||||
String Key = ConfigValues[0];
|
} catch (ClassCastException e) {
|
||||||
String Value = ConfigValues[1];
|
throw new ClassCastException(activity.toString()
|
||||||
NativeLibrary.SetConfig("Dolphin.ini", Key, Value, bind);
|
+ " must implement OnGameListZeroListener");
|
||||||
}
|
}
|
||||||
Intent intent = new Intent();
|
|
||||||
setResult(Activity.RESULT_OK, intent);
|
|
||||||
this.finish();
|
|
||||||
super.onBackPressed();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue