Merge pull request #81 from bwRavencl/multi-controllers-fixes

Multi Controller Fixes
This commit is contained in:
Stefanos Kornilios Mitsis Poiitidis 2014-01-10 13:42:53 -08:00
commit 36bed71a04
7 changed files with 286 additions and 45 deletions

View File

@ -56,7 +56,7 @@ static u64 tvs_base;
static char CurFileName[256];
// Additonal controllers 2, 3 and 4 connected ?
static bool add_controllers[3] = { false, true, false };
static bool add_controllers[3] = { false, false, false };
u16 kcode[4];
u32 vks[4];

View File

@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/touch_vibration" />
<Switch
android:id="@+id/compoundButtonTouchVibrationEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_1" />
<TextView
android:layout_weight="1"
android:id="@+id/textViewDeviceDescriptorPlayer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_none_selected" />
<Button
android:layout_weight="1"
android:id="@+id/buttonSelectControllerPlayer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/select_controller" />
<Button
android:layout_weight="1"
android:id="@+id/buttonRemoveControllerPlayer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/remove_controller" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_2" />
<TextView
android:layout_weight="1"
android:id="@+id/textViewDeviceDescriptorPlayer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_none_selected" />
<Button
android:layout_weight="1"
android:id="@+id/buttonSelectControllerPlayer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/select_controller" />
<Button
android:layout_weight="1"
android:id="@+id/buttonRemoveControllerPlayer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/remove_controller" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_3" />
<TextView
android:layout_weight="1"
android:id="@+id/textViewDeviceDescriptorPlayer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_none_selected" />
<Button
android:layout_weight="1"
android:id="@+id/buttonSelectControllerPlayer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/select_controller" />
<Button
android:layout_weight="1"
android:id="@+id/buttonRemoveControllerPlayer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/remove_controller" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_4" />
<TextView
android:layout_weight="1"
android:id="@+id/textViewDeviceDescriptorPlayer4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_none_selected" />
<Button
android:layout_weight="1"
android:id="@+id/buttonSelectControllerPlayer4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/select_controller" />
<Button
android:layout_weight="1"
android:id="@+id/buttonRemoveControllerPlayer4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/remove_controller" />
</LinearLayout>
</LinearLayout>

View File

@ -4,6 +4,25 @@
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/touch_vibration" />
<CheckBox
android:id="@+id/compoundButtonTouchVibrationEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -22,7 +41,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_none" />
android:text="@string/controller_none_selected" />
<Button
android:layout_weight="1"
@ -58,7 +77,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_none" />
android:text="@string/controller_none_selected" />
<Button
android:layout_weight="1"
@ -94,7 +113,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_none" />
android:text="@string/controller_none_selected" />
<Button
android:layout_weight="1"
@ -130,7 +149,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_none" />
android:text="@string/controller_none_selected" />
<Button
android:layout_weight="1"

View File

@ -20,11 +20,13 @@
<string name="games_listing">Available Dreamcast Games</string>
<string name="touch_vibration">Touch Vibration</string>
<string name="controller_1">Controller 1</string>
<string name="controller_2">Controller 2</string>
<string name="controller_3">Controller 3</string>
<string name="controller_4">Controller 4</string>
<string name="controller_none">None</string>
<string name="controller_not_connected">Controller Not Connected</string>
<string name="controller_none_selected">No Controller Selected</string>
<string name="select_controller">Select Controller</string>
<string name="remove_controller">Remove Controller</string>
<string name="select_controller_title">Select Controller</string>

View File

@ -17,6 +17,8 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;
@ -26,7 +28,7 @@ public class ControllersFragment extends Fragment {
private Activity parentActivity;
private int listenForButton = 0;
private AlertDialog alertDialogSelectController;
private SharedPreferences mPrefs;
private SharedPreferences sharedPreferences;
// Container Activity must implement this interface
public interface OnClickListener {
@ -44,7 +46,15 @@ public class ControllersFragment extends Fragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
parentActivity = getActivity();
mPrefs = PreferenceManager.getDefaultSharedPreferences(parentActivity);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(parentActivity);
CompoundButton compoundButtonTouchVibrationEnabled = (CompoundButton) getView()
.findViewById(R.id.compoundButtonTouchVibrationEnabled);
compoundButtonTouchVibrationEnabled.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
sharedPreferences.edit().putBoolean("touch_vibration_enabled", isChecked).commit();
}
});
Button buttonSelectControllerPlayer1 = (Button) getView()
.findViewById(R.id.buttonSelectControllerPlayer1);
@ -107,14 +117,23 @@ public class ControllersFragment extends Fragment {
}
});
updateVibration();
updateControllers();
}
private void updateVibration() {
boolean touchVibrationEnabled = sharedPreferences.getBoolean("touch_vibration_enabled", true);
CompoundButton compoundButtonTouchVibrationEnabled = (CompoundButton) getView()
.findViewById(R.id.compoundButtonTouchVibrationEnabled);
compoundButtonTouchVibrationEnabled.setChecked(touchVibrationEnabled);
}
private void updateControllers() {
String deviceDescriptorPlayer1 = mPrefs.getString("device_descriptor_player_1", null);
String deviceDescriptorPlayer2 = mPrefs.getString("device_descriptor_player_2", null);
String deviceDescriptorPlayer3 = mPrefs.getString("device_descriptor_player_3", null);
String deviceDescriptorPlayer4 = mPrefs.getString("device_descriptor_player_4", null);
String deviceDescriptorPlayer1 = sharedPreferences.getString("device_descriptor_player_1", null);
String deviceDescriptorPlayer2 = sharedPreferences.getString("device_descriptor_player_2", null);
String deviceDescriptorPlayer3 = sharedPreferences.getString("device_descriptor_player_3", null);
String deviceDescriptorPlayer4 = sharedPreferences.getString("device_descriptor_player_4", null);
String labelPlayer1 = null, labelPlayer2 = null, labelPlayer3 = null, labelPlayer4 = null;
@ -138,48 +157,68 @@ public class ControllersFragment extends Fragment {
.findViewById(R.id.textViewDeviceDescriptorPlayer1);
Button buttonRemoveControllerPlayer1 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer1);
if (deviceDescriptorPlayer1 != null) {
if (labelPlayer1 != null) {
textViewDeviceDescriptorPlayer1.setText(labelPlayer1);
buttonRemoveControllerPlayer1.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer1.setText(getString(R.string.controller_none));
buttonRemoveControllerPlayer1.setEnabled(false);
if (deviceDescriptorPlayer1 != null) {
textViewDeviceDescriptorPlayer1.setText(getString(R.string.controller_not_connected) + " (" + deviceDescriptorPlayer1 + ")");
buttonRemoveControllerPlayer1.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer1.setText(getString(R.string.controller_none_selected));
buttonRemoveControllerPlayer1.setEnabled(false);
}
}
TextView textViewDeviceDescriptorPlayer2 = (TextView) getView()
.findViewById(R.id.textViewDeviceDescriptorPlayer2);
Button buttonRemoveControllerPlayer2 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer2);
if (deviceDescriptorPlayer2 != null) {
if (labelPlayer2 != null) {
textViewDeviceDescriptorPlayer2.setText(labelPlayer2);
buttonRemoveControllerPlayer2.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer2.setText(getString(R.string.controller_none));
buttonRemoveControllerPlayer2.setEnabled(false);
if (deviceDescriptorPlayer2 != null) {
textViewDeviceDescriptorPlayer2.setText(getString(R.string.controller_not_connected) + " (" + deviceDescriptorPlayer2 + ")");
buttonRemoveControllerPlayer2.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer2.setText(getString(R.string.controller_none_selected));
buttonRemoveControllerPlayer2.setEnabled(false);
}
}
TextView textViewDeviceDescriptorPlayer3 = (TextView) getView()
.findViewById(R.id.textViewDeviceDescriptorPlayer3);
Button buttonRemoveControllerPlayer3 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer3);
if (deviceDescriptorPlayer3 != null) {
if (labelPlayer3 != null) {
textViewDeviceDescriptorPlayer3.setText(labelPlayer3);
buttonRemoveControllerPlayer3.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer3.setText(getString(R.string.controller_none));
buttonRemoveControllerPlayer3.setEnabled(false);
if (deviceDescriptorPlayer3 != null) {
textViewDeviceDescriptorPlayer3.setText(getString(R.string.controller_not_connected) + " (" + deviceDescriptorPlayer3 + ")");
buttonRemoveControllerPlayer3.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer3.setText(getString(R.string.controller_none_selected));
buttonRemoveControllerPlayer3.setEnabled(false);
}
}
TextView textViewDeviceDescriptorPlayer4 = (TextView) getView()
.findViewById(R.id.textViewDeviceDescriptorPlayer4);
Button buttonRemoveControllerPlayer4 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer4);
if (deviceDescriptorPlayer4 != null) {
if (labelPlayer4 != null) {
textViewDeviceDescriptorPlayer4.setText(labelPlayer4);
buttonRemoveControllerPlayer4.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer4.setText(getString(R.string.controller_none));
buttonRemoveControllerPlayer4.setEnabled(false);
if (deviceDescriptorPlayer4 != null) {
textViewDeviceDescriptorPlayer4.setText(getString(R.string.controller_not_connected) + " (" + deviceDescriptorPlayer4 + ")");
buttonRemoveControllerPlayer4.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer4.setText(getString(R.string.controller_none_selected));
buttonRemoveControllerPlayer4.setEnabled(false);
}
}
}
@ -196,47 +235,49 @@ public class ControllersFragment extends Fragment {
}
});
builder.setOnKeyListener(new Dialog.OnKeyListener() {
//@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
mapDevice(event);
return true;
return mapDevice(keyCode, event);
}
});
alertDialogSelectController = builder.create();
alertDialogSelectController.show();
}
private void mapDevice(KeyEvent event) {
private boolean mapDevice(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_BACK ||
keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
return false;
String descriptor = InputDevice.getDevice(event.getDeviceId()).getDescriptor();
if (descriptor == null)
return;
return false;
String deviceDescriptorPlayer1 = mPrefs.getString("device_descriptor_player_1", null);
String deviceDescriptorPlayer2 = mPrefs.getString("device_descriptor_player_2", null);
String deviceDescriptorPlayer3 = mPrefs.getString("device_descriptor_player_3", null);
String deviceDescriptorPlayer4 = mPrefs.getString("device_descriptor_player_4", null);
String deviceDescriptorPlayer1 = sharedPreferences.getString("device_descriptor_player_1", null);
String deviceDescriptorPlayer2 = sharedPreferences.getString("device_descriptor_player_2", null);
String deviceDescriptorPlayer3 = sharedPreferences.getString("device_descriptor_player_3", null);
String deviceDescriptorPlayer4 = sharedPreferences.getString("device_descriptor_player_4", null);
if (descriptor.equals(deviceDescriptorPlayer1) || descriptor.equals(deviceDescriptorPlayer2) ||
descriptor.equals(deviceDescriptorPlayer3) || descriptor.equals(deviceDescriptorPlayer4)) {
Toast.makeText(parentActivity, getString(R.string.controller_already_in_use), Toast.LENGTH_SHORT).show();
return;
return true;
}
switch(listenForButton) {
case 0:
return;
return false;
case 1:
mPrefs.edit().putString("device_descriptor_player_1", descriptor).commit();
sharedPreferences.edit().putString("device_descriptor_player_1", descriptor).commit();
break;
case 2:
mPrefs.edit().putString("device_descriptor_player_2", descriptor).commit();
sharedPreferences.edit().putString("device_descriptor_player_2", descriptor).commit();
break;
case 3:
mPrefs.edit().putString("device_descriptor_player_3", descriptor).commit();
sharedPreferences.edit().putString("device_descriptor_player_3", descriptor).commit();
break;
case 4:
mPrefs.edit().putString("device_descriptor_player_4", descriptor).commit();
sharedPreferences.edit().putString("device_descriptor_player_4", descriptor).commit();
break;
}
@ -245,21 +286,23 @@ public class ControllersFragment extends Fragment {
listenForButton = 0;
alertDialogSelectController.cancel();
updateControllers();
return true;
}
private void removeController(int playerNum) {
switch(playerNum) {
case 1:
mPrefs.edit().putString("device_descriptor_player_1", null).commit();
sharedPreferences.edit().putString("device_descriptor_player_1", null).commit();
break;
case 2:
mPrefs.edit().putString("device_descriptor_player_2", null).commit();
sharedPreferences.edit().putString("device_descriptor_player_2", null).commit();
break;
case 3:
mPrefs.edit().putString("device_descriptor_player_3", null).commit();
sharedPreferences.edit().putString("device_descriptor_player_3", null).commit();
break;
case 4:
mPrefs.edit().putString("device_descriptor_player_4", null).commit();
sharedPreferences.edit().putString("device_descriptor_player_4", null).commit();
break;
}

View File

@ -9,7 +9,6 @@ import tv.ouya.console.api.OuyaController;
import com.reicast.emulator.GL2JNIView.EmuThread;
import android.content.SharedPreferences;
import android.view.InputDevice;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;

View File

@ -9,12 +9,14 @@ import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import android.content.res.Configuration;
import android.content.SharedPreferences;
import android.graphics.PixelFormat;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.opengl.GLSurfaceView;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.MotionEvent;
@ -105,6 +107,8 @@ class GL2JNIView extends GLSurfaceView
};
Renderer rend;
private boolean touchVibrationEnabled;
public GL2JNIView(Context context,String newFileName,boolean translucent,int depth,int stencil)
@ -112,6 +116,9 @@ class GL2JNIView extends GLSurfaceView
super(context);
setKeepScreenOn(true);
vib=(Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
touchVibrationEnabled = prefs.getBoolean("touch_vibration_enabled", true);
// This is the game we are going to run
fileName = newFileName;
@ -309,7 +316,8 @@ class GL2JNIView extends GLSurfaceView
if (vjoy[j][4]>=-2)
{
if (vjoy[j][5]==0)
vib.vibrate(50);
if (touchVibrationEnabled)
vib.vibrate(50);
vjoy[j][5]=2;
}