Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Android] Change input configuration to a fragment.
  • Loading branch information
Sonicadvance1 committed Jul 16, 2013
1 parent ee26564 commit d1baa8e
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 92 deletions.
3 changes: 1 addition & 2 deletions Source/Android/AndroidManifest.xml
Expand Up @@ -18,7 +18,6 @@
android:name=".DolphinEmulator"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="landscape"
android:configChanges="locale|keyboard|keyboardHidden|navigation|fontScale|uiMode" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -31,7 +30,7 @@
android:configChanges="orientation|locale|keyboard|keyboardHidden|navigation|fontScale|uiMode" >
</activity>
<activity
android:name="org.dolphinemu.dolphinemu.InputConfigActivity"
android:name=".InputConfigFragment"
android:label="@string/app_name"
android:configChanges="orientation|locale|keyboard|keyboardHidden|navigation|fontScale|uiMode" >
</activity>
Expand Down
Expand Up @@ -222,7 +222,7 @@ public boolean dispatchKeyEvent(KeyEvent event) {
return false;
}
InputDevice input = event.getDevice();
NativeLibrary.onGamePadEvent(InputConfigActivity.getInputDesc(input), event.getKeyCode(), action);
NativeLibrary.onGamePadEvent(InputConfigFragment.getInputDesc(input), event.getKeyCode(), action);
return true;
}
return false;
Expand All @@ -240,7 +240,7 @@ public boolean dispatchGenericMotionEvent(MotionEvent event) {
{
InputDevice.MotionRange range;
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;
Expand Down
81 changes: 60 additions & 21 deletions Source/Android/src/org/dolphinemu/dolphinemu/GameListActivity.java
Expand Up @@ -10,9 +10,7 @@
import android.preference.PreferenceManager;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.*;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
Expand All @@ -28,7 +26,8 @@
public class GameListActivity extends Activity
implements GameListFragment.OnGameListZeroListener{

private int mCurPage = 0;
private int mCurFragmentNum = 0;
private Fragment mCurFragment;
enum keyTypes {TYPE_STRING, TYPE_BOOL};

private ActionBarDrawerToggle mDrawerToggle;
Expand Down Expand Up @@ -92,15 +91,15 @@ public void onDrawerOpened(View drawerView) {

private void recreateFragment()
{
Fragment fragment = new GameListFragment();
mCurFragment = new GameListFragment();
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)
{
if (mCurPage == toPage)
if (mCurFragmentNum == toPage)
return;
switch (mCurPage)
switch (mCurFragmentNum)
{
// Settings
case 2:
Expand Down Expand Up @@ -145,19 +144,35 @@ private void SwitchPage(int toPage)
}
}
break;
case 0: // 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 */
break;
}
switch(toPage)
{
case 0:
{
mCurPage = 0;
Fragment fragment = new GameListFragment();
mCurFragmentNum = 0;
mCurFragment = new GameListFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
}
break;
case 1:
Expand All @@ -168,24 +183,28 @@ private void SwitchPage(int toPage)
case 2:
{
Toast.makeText(mMe, "Loading up settings", Toast.LENGTH_SHORT).show();
mCurPage = 2;
Fragment fragment = new PrefsFragment();
mCurFragmentNum = 2;
mCurFragment = new PrefsFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
}
break;
case 3:
{
Toast.makeText(mMe, "Loading up gamepad config", Toast.LENGTH_SHORT).show();
Intent ConfigIntent = new Intent(mMe, InputConfigActivity.class);
startActivityForResult(ConfigIntent, 3);
break;
mCurFragmentNum = 3;
mCurFragment = new InputConfigFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
}
break;
case 4:
{
Toast.makeText(mMe, "Loading up About", Toast.LENGTH_SHORT).show();
mCurPage = 4;
Fragment fragment = new AboutFragment();
mCurFragmentNum = 4;
mCurFragment = new AboutFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
fragmentManager.beginTransaction().replace(R.id.content_frame, mCurFragment).commit();
}
break;
default:
Expand Down Expand Up @@ -264,5 +283,25 @@ public void onBackPressed()
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;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.app.Fragment;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.*;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

Expand All @@ -21,7 +18,10 @@
* Licensed under GPLv2
* 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 int configPosition = 0;
boolean Configuring = false;
Expand All @@ -43,9 +43,9 @@ static public String getInputDesc(InputDevice input)
}
}
@Override
public void onCreate(Bundle savedInstanceState)
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
List<InputConfigItem> Input = new ArrayList<InputConfigItem>();
int a = 0;

Expand All @@ -71,55 +71,66 @@ public void onCreate(Bundle savedInstanceState)
Input.add(a++, new InputConfigItem("Trigger L", "Android-InputL"));
Input.add(a++, new InputConfigItem("Trigger R", "Android-InputR"));

adapter = new InputConfigAdapter(this, R.layout.folderbrowser, Input);
setListAdapter(adapter);
adapter = new InputConfigAdapter(m_activity, R.layout.folderbrowser, Input);
View rootView = inflater.inflate(R.layout.gamelist_listview, container, false);
mDrawerList = (ListView) rootView.findViewById(R.id.gamelist);

mDrawerList.setAdapter(adapter);
mDrawerList.setOnItemClickListener(mMenuItemClickListener);
return mDrawerList;
}
@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)
private AdapterView.OnItemClickListener mMenuItemClickListener = new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
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;
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>();
// Gets move(triggers, joystick) events

void AssignBind(String bind)
{
InputConfigItem o = adapter.getItem(configPosition);
adapter.remove(o);
o.setBind(bind);
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();
List<InputDevice.MotionRange> motions = input.getMotionRanges();
if (Configuring)
Expand All @@ -140,56 +151,50 @@ public boolean dispatchGenericMotionEvent(MotionEvent event) {
range = motions.get(a);
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;
}
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;
}
}
}
}
return true;
}

// Gets button presses
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
public boolean onKeyEvent(KeyEvent event)
{
Log.w("Dolphinemu", "Got Event " + event.getAction());
switch (event.getAction()) {
case KeyEvent.ACTION_DOWN:
case KeyEvent.ACTION_UP:
if (Configuring)
{
InputDevice input = event.getDevice();
AssignBind("Device '" + InputConfigActivity.getInputDesc(input) + "'-Button " + event.getKeyCode());
AssignBind("Device '" + InputConfigFragment.getInputDesc(input) + "'-Button " + event.getKeyCode());
Configuring = false;
return true;
}
default:
break;
}

return super.dispatchKeyEvent(event);
return false;
}

@Override
public void onBackPressed() {
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);
public void onAttach(Activity activity) {
super.onAttach(activity);

// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
m_activity = activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnGameListZeroListener");
}
Intent intent = new Intent();
setResult(Activity.RESULT_OK, intent);
this.finish();
super.onBackPressed();
}
}

0 comments on commit d1baa8e

Please sign in to comment.