From d1baa8edd949f64c26464b65cd135cd0acff2cd7 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Tue, 16 Jul 2013 06:30:50 -0500 Subject: [Android] Change input configuration to a fragment. --- Source/Android/AndroidManifest.xml | 3 +- .../org/dolphinemu/dolphinemu/DolphinEmulator.java | 4 +- .../dolphinemu/dolphinemu/GameListActivity.java | 81 ++++++--- .../dolphinemu/dolphinemu/InputConfigActivity.java | 195 -------------------- .../dolphinemu/dolphinemu/InputConfigFragment.java | 200 +++++++++++++++++++++ 5 files changed, 263 insertions(+), 220 deletions(-) delete mode 100644 Source/Android/src/org/dolphinemu/dolphinemu/InputConfigActivity.java create mode 100644 Source/Android/src/org/dolphinemu/dolphinemu/InputConfigFragment.java (limited to 'Source/Android') diff --git a/Source/Android/AndroidManifest.xml b/Source/Android/AndroidManifest.xml index 3cd0b19614..a0194eb6e0 100644 --- a/Source/Android/AndroidManifest.xml +++ b/Source/Android/AndroidManifest.xml @@ -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" > @@ -31,7 +30,7 @@ android:configChanges="orientation|locale|keyboard|keyboardHidden|navigation|fontScale|uiMode" > diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java b/Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java index af2f2df326..a883cd7b49 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java @@ -222,7 +222,7 @@ public class DolphinEmulator extends Activity 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; @@ -240,7 +240,7 @@ public class DolphinEmulator extends Activity { 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; diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/GameListActivity.java b/Source/Android/src/org/dolphinemu/dolphinemu/GameListActivity.java index 2c8a0e61a8..3606c462d2 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/GameListActivity.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/GameListActivity.java @@ -10,9 +10,7 @@ import android.os.Bundle; 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; @@ -28,7 +26,8 @@ import java.util.List; 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; @@ -92,15 +91,15 @@ public class GameListActivity extends Activity 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: @@ -145,8 +144,24 @@ public class GameListActivity extends Activity } } 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; } @@ -154,10 +169,10 @@ public class GameListActivity extends Activity { 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: @@ -168,24 +183,28 @@ public class GameListActivity extends Activity 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: @@ -264,5 +283,25 @@ public class GameListActivity extends Activity 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); + } } diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/InputConfigActivity.java b/Source/Android/src/org/dolphinemu/dolphinemu/InputConfigActivity.java deleted file mode 100644 index 0057901eec..0000000000 --- a/Source/Android/src/org/dolphinemu/dolphinemu/InputConfigActivity.java +++ /dev/null @@ -1,195 +0,0 @@ -package org.dolphinemu.dolphinemu; - -import android.app.Activity; -import android.app.ListActivity; -import android.content.Intent; -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.widget.ListView; -import android.widget.Toast; - -import java.util.ArrayList; -import java.util.List; - -/** - * Copyright 2013 Dolphin Emulator Project - * Licensed under GPLv2 - * Refer to the license.txt file included. - */ -public class InputConfigActivity extends ListActivity { - private InputConfigAdapter adapter; - private int configPosition = 0; - boolean Configuring = false; - boolean firstEvent = true; - - static public String getInputDesc(InputDevice input) - { - if (input == null) - return "null"; // Happens when the inputdevice is from an unknown source - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) - return input.getDescriptor(); - else - { - List motions = input.getMotionRanges(); - String fakeid = ""; - for (InputDevice.MotionRange range : motions) - fakeid += range.getAxis(); - return fakeid; - } - } - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - List Input = new ArrayList(); - int a = 0; - - Input.add(a++, new InputConfigItem("Draw on-screen controls", "Android-ScreenControls", "True")); - Input.add(a++, new InputConfigItem("Button A", "Android-InputA")); - Input.add(a++, new InputConfigItem("Button B", "Android-InputB")); - Input.add(a++, new InputConfigItem("Button Start", "Android-InputStart")); - Input.add(a++, new InputConfigItem("Button X", "Android-InputX")); - Input.add(a++, new InputConfigItem("Button Y", "Android-InputY")); - Input.add(a++, new InputConfigItem("Button Z", "Android-InputZ")); - Input.add(a++, new InputConfigItem("D-Pad Up", "Android-DPadUp")); - Input.add(a++, new InputConfigItem("D-Pad Down", "Android-DPadDown")); - Input.add(a++, new InputConfigItem("D-Pad Left", "Android-DPadLeft")); - Input.add(a++, new InputConfigItem("D-Pad Right", "Android-DPadRight")); - Input.add(a++, new InputConfigItem("Main Stick Up", "Android-MainUp")); - Input.add(a++, new InputConfigItem("Main Stick Down", "Android-MainDown")); - Input.add(a++, new InputConfigItem("Main Stick Left", "Android-MainLeft")); - Input.add(a++, new InputConfigItem("Main Stick Right", "Android-MainRight")); - Input.add(a++, new InputConfigItem("C Stick Up", "Android-CStickUp")); - Input.add(a++, new InputConfigItem("C Stick Down", "Android-CStickDown")); - Input.add(a++, new InputConfigItem("C Stick Left", "Android-CStickLeft")); - Input.add(a++, new InputConfigItem("C Stick Right", "Android-CStickRight")); - 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); - } - @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; - } - - } - static ArrayList m_values = new ArrayList(); - // Gets move(triggers, joystick) events - void AssignBind(String bind) - { - InputConfigItem o = adapter.getItem(configPosition); - adapter.remove(o); - o.setBind(bind); - adapter.insert(o, configPosition); - } - - @Override - public boolean dispatchGenericMotionEvent(MotionEvent event) { - if (((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)) { - return super.dispatchGenericMotionEvent(event); - } - InputDevice input = event.getDevice(); - List motions = input.getMotionRanges(); - if (Configuring) - { - if (firstEvent) - { - m_values.clear(); - for (InputDevice.MotionRange range : motions) { - m_values.add(event.getAxisValue(range.getAxis())); - } - firstEvent = false; - } - else - { - for (int a = 0; a < motions.size(); ++a) - { - InputDevice.MotionRange range; - range = motions.get(a); - if (m_values.get(a) > (event.getAxisValue(range.getAxis()) + 0.5f)) - { - AssignBind("Device '" + InputConfigActivity.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() + "+"); - Configuring = false; - } - } - } - } - return true; - } - - // Gets button presses - @Override - public boolean dispatchKeyEvent(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()); - Configuring = false; - return true; - } - default: - break; - } - - return super.dispatchKeyEvent(event); - } - - @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); - } - Intent intent = new Intent(); - setResult(Activity.RESULT_OK, intent); - this.finish(); - super.onBackPressed(); - } -} diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/InputConfigFragment.java b/Source/Android/src/org/dolphinemu/dolphinemu/InputConfigFragment.java new file mode 100644 index 0000000000..3a6e855c3b --- /dev/null +++ b/Source/Android/src/org/dolphinemu/dolphinemu/InputConfigFragment.java @@ -0,0 +1,200 @@ +package org.dolphinemu.dolphinemu; + +import android.app.Activity; +import android.app.Fragment; +import android.os.Build; +import android.os.Bundle; +import android.util.Log; +import android.view.*; +import android.widget.AdapterView; +import android.widget.ListView; +import android.widget.Toast; + +import java.util.ArrayList; +import java.util.List; + +/** + * Copyright 2013 Dolphin Emulator Project + * Licensed under GPLv2 + * Refer to the license.txt file included. + */ +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; + boolean firstEvent = true; + + static public String getInputDesc(InputDevice input) + { + if (input == null) + return "null"; // Happens when the inputdevice is from an unknown source + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) + return input.getDescriptor(); + else + { + List motions = input.getMotionRanges(); + String fakeid = ""; + for (InputDevice.MotionRange range : motions) + fakeid += range.getAxis(); + return fakeid; + } + } + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) + { + List Input = new ArrayList(); + int a = 0; + + Input.add(a++, new InputConfigItem("Draw on-screen controls", "Android-ScreenControls", "True")); + Input.add(a++, new InputConfigItem("Button A", "Android-InputA")); + Input.add(a++, new InputConfigItem("Button B", "Android-InputB")); + Input.add(a++, new InputConfigItem("Button Start", "Android-InputStart")); + Input.add(a++, new InputConfigItem("Button X", "Android-InputX")); + Input.add(a++, new InputConfigItem("Button Y", "Android-InputY")); + Input.add(a++, new InputConfigItem("Button Z", "Android-InputZ")); + Input.add(a++, new InputConfigItem("D-Pad Up", "Android-DPadUp")); + Input.add(a++, new InputConfigItem("D-Pad Down", "Android-DPadDown")); + Input.add(a++, new InputConfigItem("D-Pad Left", "Android-DPadLeft")); + Input.add(a++, new InputConfigItem("D-Pad Right", "Android-DPadRight")); + Input.add(a++, new InputConfigItem("Main Stick Up", "Android-MainUp")); + Input.add(a++, new InputConfigItem("Main Stick Down", "Android-MainDown")); + Input.add(a++, new InputConfigItem("Main Stick Left", "Android-MainLeft")); + Input.add(a++, new InputConfigItem("Main Stick Right", "Android-MainRight")); + Input.add(a++, new InputConfigItem("C Stick Up", "Android-CStickUp")); + Input.add(a++, new InputConfigItem("C Stick Down", "Android-CStickDown")); + Input.add(a++, new InputConfigItem("C Stick Left", "Android-CStickLeft")); + Input.add(a++, new InputConfigItem("C Stick Right", "Android-CStickRight")); + Input.add(a++, new InputConfigItem("Trigger L", "Android-InputL")); + Input.add(a++, new InputConfigItem("Trigger R", "Android-InputR")); + + 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; + } + 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 m_values = new ArrayList(); + + 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; + + InputDevice input = event.getDevice(); + List motions = input.getMotionRanges(); + if (Configuring) + { + if (firstEvent) + { + m_values.clear(); + for (InputDevice.MotionRange range : motions) { + m_values.add(event.getAxisValue(range.getAxis())); + } + firstEvent = false; + } + else + { + for (int a = 0; a < motions.size(); ++a) + { + InputDevice.MotionRange range; + range = motions.get(a); + if (m_values.get(a) > (event.getAxisValue(range.getAxis()) + 0.5f)) + { + AssignBind("Device '" + InputConfigFragment.getInputDesc(input) + "'-Axis " + range.getAxis() + "-"); + Configuring = false; + } + else if (m_values.get(a) < (event.getAxisValue(range.getAxis()) - 0.5f)) + { + AssignBind("Device '" + InputConfigFragment.getInputDesc(input) + "'-Axis " + range.getAxis() + "+"); + Configuring = false; + } + } + } + } + return true; + } + 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 '" + InputConfigFragment.getInputDesc(input) + "'-Button " + event.getKeyCode()); + Configuring = false; + return true; + } + default: + break; + } + + return false; + } + + @Override + 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"); + } + } +} -- cgit v1.2.3