Add basic Moga support to the input configuration menus

This commit is contained in:
TwistedUmbrella 2014-01-26 04:46:05 -05:00
parent 4307068022
commit de5954decc
2 changed files with 115 additions and 25 deletions

View File

@ -1,5 +1,11 @@
package com.reicast.emulator;
import com.bda.controller.Controller;
import com.bda.controller.ControllerListener;
import com.bda.controller.MotionEvent;
import com.bda.controller.StateEvent;
import com.reicast.emulator.MOGAInput.ExampleControllerListener;
import de.ankri.views.Switch;
import android.annotation.TargetApi;
import android.app.Activity;
@ -8,8 +14,10 @@ import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
@ -34,6 +42,8 @@ public class InputFragment extends Fragment {
private SharedPreferences sharedPreferences;
private Switch switchTouchVibrationEnabled;
public MOGAInput moga = new MOGAInput();
// Container Activity must implement this interface
public interface OnClickListener {
public void onMainBrowseSelected(String path_entry, boolean games);
@ -50,6 +60,8 @@ public class InputFragment extends Fragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
parentActivity = getActivity();
moga.onCreate(parentActivity);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(parentActivity);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
@ -316,6 +328,11 @@ public class InputFragment extends Fragment {
String descriptor = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (moga.isActive[listenForButton]) {
MogaListener config = new MogaListener(listenForButton);
moga.mController.setListener(config, new Handler());
descriptor = config.getController();
}
descriptor = InputDevice.getDevice(event.getDeviceId())
.getDescriptor();
} else {
@ -381,4 +398,38 @@ public class InputFragment extends Fragment {
updateControllers();
}
class MogaListener implements ControllerListener
{
private int playerNum;
private String controllerId;
public MogaListener(int playerNum) {
this.playerNum = playerNum;
}
public void onKeyEvent(com.bda.controller.KeyEvent event) {
controllerId = String.valueOf(event.getControllerId());
}
public void onMotionEvent(MotionEvent arg0) {
}
public String getController() {
return controllerId;
}
public void onStateEvent(StateEvent event) {
if (event.getState() == StateEvent.STATE_CONNECTION && event.getAction() == MOGAInput.ACTION_CONNECTED) {
int mControllerVersion = moga.mController.getState(Controller.STATE_CURRENT_PRODUCT_VERSION);
if (mControllerVersion == Controller.ACTION_VERSION_MOGAPRO) {
moga.isActive[playerNum] = true;
} else if (mControllerVersion == Controller.ACTION_VERSION_MOGA) {
moga.isActive[playerNum] = true;
}
}
}
}
}

View File

@ -94,8 +94,10 @@ public class MainActivity extends FragmentActivity implements
// firstFragment.setArguments(getIntent().getExtras());
// Add the fragment to the 'fragment_container' FrameLayout
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, firstFragment, "MAIN_BROWSER").commit();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, firstFragment,
"MAIN_BROWSER").commit();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
@ -243,8 +245,8 @@ public class MainActivity extends FragmentActivity implements
String versionName = "";
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(
getPackageName(), 0);
PackageInfo pInfo = getPackageManager()
.getPackageInfo(getPackageName(), 0);
versionName = pInfo.versionName;
} catch (NameNotFoundException e) {
e.printStackTrace();
@ -255,8 +257,7 @@ public class MainActivity extends FragmentActivity implements
.setCancelable(false)
.setPositiveButton("Dismiss",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
@ -275,8 +276,9 @@ public class MainActivity extends FragmentActivity implements
public boolean onTouch(View v, MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
// vib.vibrate(50);
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + getPackageName())));
startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse("market://details?id="
+ getPackageName())));
return true;
} else
return false;
@ -498,22 +500,22 @@ public class MainActivity extends FragmentActivity implements
e.printStackTrace();
}
alertDialogBuilder
.setMessage(getString(R.string.about_text, versionName))
.setCancelable(false)
.setPositiveButton("Dismiss",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.dismiss();
}
});
alertDialogBuilder
.setMessage(getString(R.string.about_text, versionName))
.setCancelable(false)
.setPositiveButton("Dismiss",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.dismiss();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
// show it
alertDialog.show();
break;
case 5:
@ -620,9 +622,10 @@ public class MainActivity extends FragmentActivity implements
args.putString("browse_entry", null);
args.putBoolean("games_entry", false);
fragment.setArguments(args);
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, fragment, "MAIN_BROWSER")
.commit();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, fragment,
"MAIN_BROWSER").commit();
}
return true;
}
@ -631,4 +634,40 @@ public class MainActivity extends FragmentActivity implements
return super.onKeyDown(keyCode, event);
}
@Override
protected void onPause() {
super.onPause();
InputFragment fragment = (InputFragment) getSupportFragmentManager()
.findFragmentByTag("INPUT_FRAG");
if (fragment != null && fragment.isVisible()) {
if (fragment.moga != null) {
fragment.moga.onPause();
}
}
}
@Override
protected void onDestroy() {
super.onDestroy();
InputFragment fragment = (InputFragment) getSupportFragmentManager()
.findFragmentByTag("INPUT_FRAG");
if (fragment != null && fragment.isVisible()) {
if (fragment.moga != null) {
fragment.moga.onDestroy();
}
}
}
@Override
protected void onResume() {
super.onResume();
InputFragment fragment = (InputFragment) getSupportFragmentManager()
.findFragmentByTag("INPUT_FRAG");
if (fragment != null && fragment.isVisible()) {
if (fragment.moga != null) {
fragment.moga.onResume();
}
}
}
}