Android: Improve stability of gamepad detection
This commit is contained in:
parent
a1b6711402
commit
88b81a6652
|
@ -149,11 +149,13 @@ public class GL2JNIActivity extends Activity {
|
|||
pad.deviceId_deviceDescriptor.put(joy, descriptor);
|
||||
}
|
||||
|
||||
for (int joy :joys) {
|
||||
boolean detected = false;
|
||||
for (int joy : joys) {
|
||||
Integer playerNum = pad.deviceDescriptor_PlayerNum
|
||||
.get(pad.deviceId_deviceDescriptor.get(joy));
|
||||
|
||||
if (playerNum != null) {
|
||||
detected = true;
|
||||
String id = pad.portId[playerNum];
|
||||
pad.custom[playerNum] = prefs.getBoolean(Gamepad.pref_js_modified + id, false);
|
||||
pad.compat[playerNum] = prefs.getBoolean(Gamepad.pref_js_compat + id, false);
|
||||
|
@ -187,11 +189,9 @@ public class GL2JNIActivity extends Activity {
|
|||
pad.getCompatibilityMap(playerNum, id, prefs);
|
||||
}
|
||||
pad.initJoyStickLayout(playerNum);
|
||||
} else {
|
||||
pad.runCompatibilityMode(joy, prefs);
|
||||
}
|
||||
}
|
||||
if (joys.length == 0) {
|
||||
if (joys.length == 0 || !detected) {
|
||||
pad.fullCompatibilityMode(prefs);
|
||||
}
|
||||
|
||||
|
|
|
@ -144,25 +144,22 @@ public class GL2JNINative extends NativeActivity {
|
|||
pad.deviceId_deviceDescriptor.put(joy, descriptor);
|
||||
}
|
||||
|
||||
boolean detected = false;
|
||||
for (int joy : joys) {
|
||||
Integer playerNum = pad.deviceDescriptor_PlayerNum
|
||||
.get(pad.deviceId_deviceDescriptor.get(joy));
|
||||
|
||||
if (playerNum != null) {
|
||||
detected = true;
|
||||
String id = pad.portId[playerNum];
|
||||
pad.custom[playerNum] = prefs.getBoolean(Gamepad.pref_js_modified + id, false);
|
||||
pad.compat[playerNum] = prefs.getBoolean(Gamepad.pref_js_compat + id, false);
|
||||
pad.joystick[playerNum] = prefs.getBoolean(Gamepad.pref_js_merged + id, false);
|
||||
if (InputDevice.getDevice(joy).getName()
|
||||
.contains(Gamepad.controllers_gamekey)) {
|
||||
// if (pad.custom[playerNum]) {
|
||||
// setCustomMapping(id, playerNum);
|
||||
// } else {
|
||||
// pad.map[playerNum] = pad.getConsoleController();
|
||||
// }
|
||||
if (InputDevice.getDevice(joy).getName().contains(Gamepad.controllers_gamekey)) {
|
||||
new Handler().post(new Runnable() {
|
||||
public void run() {
|
||||
Toast.makeText(getApplicationContext(), R.string.controller_unavailable,
|
||||
Toast.makeText(getApplicationContext(),
|
||||
R.string.controller_unavailable,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
|
@ -190,10 +187,11 @@ public class GL2JNINative extends NativeActivity {
|
|||
}
|
||||
pad.initJoyStickLayout(playerNum);
|
||||
pad.playerNumX.put(joy, playerNum);
|
||||
} else {
|
||||
pad.runCompatibilityMode(joy, prefs);
|
||||
}
|
||||
}
|
||||
if (joys.length == 0 || !detected) {
|
||||
pad.fullCompatibilityMode(prefs);
|
||||
}
|
||||
|
||||
app.loadConfigurationPrefs();
|
||||
|
||||
|
|
|
@ -53,8 +53,6 @@ public class MainActivity extends AppCompatActivity implements
|
|||
private SharedPreferences mPrefs;
|
||||
private boolean hasAndroidMarket = false;
|
||||
|
||||
private UncaughtExceptionHandler mUEHandler;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -85,7 +83,7 @@ public class MainActivity extends AppCompatActivity implements
|
|||
displayLogOutput(prior_error);
|
||||
mPrefs.edit().remove("prior_error").apply();
|
||||
} else {
|
||||
mUEHandler = new Thread.UncaughtExceptionHandler() {
|
||||
UncaughtExceptionHandler mUEHandler = new Thread.UncaughtExceptionHandler() {
|
||||
public void uncaughtException(Thread t, Throwable error) {
|
||||
if (error != null) {
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
|
|
@ -170,8 +170,6 @@ public class GenerateLogs extends AsyncTask<String, Integer, String> {
|
|||
log.append(separator);
|
||||
}
|
||||
reader.close();
|
||||
mLogcatProc = null;
|
||||
reader = null;
|
||||
File memory = new File(mContext.get().getFilesDir(), "mem_alloc.txt");
|
||||
if (memory.exists()) {
|
||||
log.append(separator);
|
||||
|
@ -186,9 +184,7 @@ public class GenerateLogs extends AsyncTask<String, Integer, String> {
|
|||
log.append(separator);
|
||||
}
|
||||
fis.close();
|
||||
fis = null;
|
||||
reader.close();
|
||||
reader = null;
|
||||
}
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(logFile));
|
||||
writer.write(log.toString());
|
||||
|
|
|
@ -202,18 +202,14 @@ public class Gamepad {
|
|||
}
|
||||
}
|
||||
|
||||
public void runCompatibilityMode(int joy, SharedPreferences prefs) {
|
||||
public void fullCompatibilityMode(SharedPreferences prefs) {
|
||||
for (int joy = 0; joy < 4; joy++) {
|
||||
if (compat[joy]) {
|
||||
String id = portId[joy];
|
||||
joystick[joy] = prefs.getBoolean(Gamepad.pref_js_merged + id, false);
|
||||
getCompatibilityMap(joy, portId[joy], prefs);
|
||||
initJoyStickLayout(joy);
|
||||
}
|
||||
}
|
||||
|
||||
public void fullCompatibilityMode(SharedPreferences prefs) {
|
||||
for (int n = 0; n < 4; n++) {
|
||||
runCompatibilityMode(n, prefs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue