|
|
|
@ -4,10 +4,8 @@ import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
|
|
import android.app.ListActivity;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.res.Resources;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.View.OnTouchListener;
|
|
|
|
@ -32,74 +30,8 @@ public class BeastModePreferences extends ListActivity {
|
|
|
|
|
|
|
|
|
|
public static final String BEAST_MODE_PREF_ITEM_SEPARATOR = ";"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
private static final String BEAST_MODE_MORE_ITEM_SPECIAL_CHAR = "-"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
private static final String BEAST_MODE_MIGRATE_PREF = "beast_mode_migrate"; //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
private HashMap<String, String> prefsToDescriptions;
|
|
|
|
|
|
|
|
|
|
// Migration function to fix the fact that I stupidly chose to use the control
|
|
|
|
|
// set names (which are localized and subject to change) as the values in the beast
|
|
|
|
|
// mode preferences
|
|
|
|
|
public static void migrateBeastModePreferences(Context context) {
|
|
|
|
|
boolean hasMigratedBeastMode = Preferences.getBoolean(BEAST_MODE_MIGRATE_PREF, false);
|
|
|
|
|
if (hasMigratedBeastMode) return;
|
|
|
|
|
String setPref = Preferences.getStringValue(BEAST_MODE_ORDER_PREF);
|
|
|
|
|
if (setPref == null) {
|
|
|
|
|
Preferences.setBoolean(BEAST_MODE_MIGRATE_PREF, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArrayList<String> defaults = new ArrayList<String>();
|
|
|
|
|
String[] defaultOrder = context.getResources().getStringArray(R.array.TEA_control_sets);
|
|
|
|
|
for (int i = 1; i < defaultOrder.length; i++) {
|
|
|
|
|
String s = defaultOrder[i];
|
|
|
|
|
if (s.contains(BEAST_MODE_MORE_ITEM_SPECIAL_CHAR)) {
|
|
|
|
|
String[] split = s.split(BEAST_MODE_MORE_ITEM_SPECIAL_CHAR);
|
|
|
|
|
for (String component : split) {
|
|
|
|
|
if (!TextUtils.isEmpty(component)) {
|
|
|
|
|
s = component;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
defaults.add(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArrayList<String> setOrder = new ArrayList<String>();
|
|
|
|
|
String[] setOrderArray = setPref.split(BEAST_MODE_PREF_ITEM_SEPARATOR);
|
|
|
|
|
for (String s : setOrderArray) {
|
|
|
|
|
|
|
|
|
|
setOrder.add(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String[] prefKeys = context.getResources().getStringArray(R.array.TEA_control_sets_prefs);
|
|
|
|
|
|
|
|
|
|
StringBuilder newPref = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
//Try to match old preference string to new preference string by index in defaults array
|
|
|
|
|
for (String pref : setOrder) {
|
|
|
|
|
int index = defaults.indexOf(pref);
|
|
|
|
|
if (index > -1 && index < prefKeys.length) {
|
|
|
|
|
newPref.append(prefKeys[index]);
|
|
|
|
|
newPref.append(BEAST_MODE_PREF_ITEM_SEPARATOR);
|
|
|
|
|
} else { // Should never get here--weird error if we do
|
|
|
|
|
// Failed to successfully migrate--reset to defaults
|
|
|
|
|
StringBuilder resetToDefaults = new StringBuilder();
|
|
|
|
|
for (String s : prefKeys) {
|
|
|
|
|
resetToDefaults.append(s);
|
|
|
|
|
resetToDefaults.append(BEAST_MODE_PREF_ITEM_SEPARATOR);
|
|
|
|
|
}
|
|
|
|
|
Preferences.setString(BEAST_MODE_ORDER_PREF, resetToDefaults.toString());
|
|
|
|
|
Preferences.setBoolean(BEAST_MODE_MIGRATE_PREF, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Preferences.setString(BEAST_MODE_ORDER_PREF, newPref.toString());
|
|
|
|
|
Preferences.setBoolean(BEAST_MODE_MIGRATE_PREF, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
@ -120,8 +52,7 @@ public class BeastModePreferences extends ListActivity {
|
|
|
|
|
|
|
|
|
|
items = new ArrayList<String>();
|
|
|
|
|
for (String s : itemsArray) {
|
|
|
|
|
|
|
|
|
|
if (!s.equals(getResources().getString(R.string.TEA_control_title))){
|
|
|
|
|
if (!s.equals(getResources().getString(R.string.TEA_ctrl_title_pref))){
|
|
|
|
|
items.add(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -163,7 +94,7 @@ public class BeastModePreferences extends ListActivity {
|
|
|
|
|
|
|
|
|
|
private void buildDescriptionMap(Resources r) {
|
|
|
|
|
String[] keys = r.getStringArray(R.array.TEA_control_sets_prefs);
|
|
|
|
|
String[] descriptions = r.getStringArray(R.array.TEA_control_sets);
|
|
|
|
|
String[] descriptions = r.getStringArray(R.array.TEA_control_sets_beast);
|
|
|
|
|
for (int i = 0; i < keys.length && i < descriptions.length; i++) {
|
|
|
|
|
prefsToDescriptions.put(keys[i], descriptions[i]);
|
|
|
|
|
}
|
|
|
|
|