[Android] Use a HashMap in PrefsFragment.java instead of two CharSequence arrays.

This way, we hold the [key|value] pairs together in one object and reduce overall code clutter.
This commit is contained in:
Lioncash 2013-08-12 19:41:23 -04:00
parent 00b034f991
commit 3b272d81b4
1 changed files with 19 additions and 26 deletions

View File

@ -1,5 +1,7 @@
package org.dolphinemu.dolphinemu; package org.dolphinemu.dolphinemu;
import java.util.HashMap;
import android.app.Activity; import android.app.Activity;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -138,36 +140,28 @@ public class PrefsFragment extends PreferenceFragment {
addPreferencesFromResource(R.layout.prefs); addPreferencesFromResource(R.layout.prefs);
final ListPreference etp = new ListPreference(m_activity); final ListPreference etp = new ListPreference(m_activity);
CharSequence[] _entries; final HashMap<CharSequence, CharSequence> entries = new HashMap<CharSequence, CharSequence>();
CharSequence[] _entryvalues;
if (Build.CPU_ABI.contains("x86")) if (Build.CPU_ABI.contains("x86"))
{ {
_entries = new CharSequence[] { entries.put("Interpreter", "0");
"Interpreter", entries.put("JIT64 Recompiler", "1");
"JIT64 Recompiler", entries.put("JITIL Recompiler", "2");
"JITIL Recompiler",
};
_entryvalues = new CharSequence[] {"0", "1", "2"};
} }
else if (Build.CPU_ABI.contains("arm")) else if (Build.CPU_ABI.contains("arm"))
{ {
_entries = new CharSequence[] { entries.put("Interpreter", "0");
"Interpreter", entries.put("JIT ARM Recompiler", "3");
"JIT ARM Recompiler",
};
_entryvalues = new CharSequence[] {"0", "3"};
} }
else else
{ {
_entries = new CharSequence[] { entries.put("Interpreter", "0");
"Interpreter",
};
_entryvalues = new CharSequence[] {"0"};
} }
etp.setEntries(_entries); // Convert the key/value sections to arrays respectively so the list can be set.
etp.setEntryValues(_entryvalues); // If Java had proper generics it wouldn't look this disgusting.
etp.setEntries(entries.keySet().toArray(new CharSequence[entries.size()]));
etp.setEntryValues(entries.values().toArray(new CharSequence[entries.size()]));
etp.setKey("cpupref"); etp.setKey("cpupref");
etp.setTitle("CPU Core"); etp.setTitle("CPU Core");
etp.setSummary("Emulation core to use"); etp.setSummary("Emulation core to use");
@ -185,17 +179,16 @@ public class PrefsFragment extends PreferenceFragment {
final ListPreference videobackend = new ListPreference(m_activity); final ListPreference videobackend = new ListPreference(m_activity);
_entries = new CharSequence[] { // Add available graphics renderers to the hashmap to add to the list.
"Software Renderer", entries.clear();
}; entries.put("Software Renderer", "Software Renderer"); // TODO: I think this is a bug? The value shouldn't be the same as the key?
_entryvalues = new CharSequence[] {"Software Renderer"};
videobackend.setKey("gpupref"); videobackend.setKey("gpupref");
videobackend.setTitle("Video Backend"); videobackend.setTitle("Video Backend");
videobackend.setSummary("Video backend to use"); videobackend.setSummary("Video backend to use");
videobackend.setEntries(_entries); videobackend.setEntries(entries.keySet().toArray(new CharSequence[entries.size()]));
videobackend.setEntryValues(_entryvalues); videobackend.setEntryValues(entries.values().toArray(new CharSequence[entries.size()]));
mCategory.addPreference(videobackend); mCategory.addPreference(videobackend);
} }