Start using string switches (Java 1.7)

This commit is contained in:
Daniel Martí
2015-08-21 17:41:41 -07:00
parent 283408b922
commit 81dd0de8a1
2 changed files with 93 additions and 67 deletions
@@ -150,16 +150,22 @@ public class ApnUtils {
for (int i = 0; i < parser.getAttributeCount(); i++) { for (int i = 0; i < parser.getAttributeCount(); i++) {
String name = parser.getAttributeName(i); String name = parser.getAttributeName(i);
String value = parser.getAttributeValue(i); String value = parser.getAttributeValue(i);
if ("mmsc".equals(name)) { switch (name) {
case "mmsc":
apn.mmsc = value; apn.mmsc = value;
} else if ("mmsproxy".equals(name)) { break;
case "mmsproxy":
apn.proxy = value; apn.proxy = value;
} else if ("mmsport".equals(name)) { break;
case "mmsport":
apn.port = value; apn.port = value;
} else if ("carrier".equals(name)) { break;
case "carrier":
apn.name = value; apn.name = value;
} else if ("port".equals(name)) { break;
case "port":
port = value; port = value;
break;
} }
} }
@@ -405,28 +405,39 @@ public class SettingsFragment extends PreferenceFragment implements
valueString valueString
); );
if (key.equals(BACKGROUND)) { switch (key) {
case BACKGROUND:
ThemeManager.setTheme(ThemeManager.Theme.fromString((String) newValue)); ThemeManager.setTheme(ThemeManager.Theme.fromString((String) newValue));
} else if (key.equals(STATUS_TINT)) { break;
case STATUS_TINT:
ThemeManager.setStatusBarTintEnabled((Boolean) newValue); ThemeManager.setStatusBarTintEnabled((Boolean) newValue);
} else if (key.equals(FONT_FAMILY)) { break;
case FONT_FAMILY:
preference.setSummary(mFontFamilies[Integer.parseInt("" + newValue)]); preference.setSummary(mFontFamilies[Integer.parseInt("" + newValue)]);
} else if (key.equals(FONT_SIZE)) { break;
case FONT_SIZE:
preference.setSummary(mFontSizes[Integer.parseInt("" + newValue)]); preference.setSummary(mFontSizes[Integer.parseInt("" + newValue)]);
} else if (key.equals(FONT_WEIGHT)) { break;
case FONT_WEIGHT:
int i = Integer.parseInt("" + newValue); int i = Integer.parseInt("" + newValue);
preference.setSummary(mFontWeights[i == 2 ? 0 : 1]); preference.setSummary(mFontWeights[i == 2 ? 0 : 1]);
} else if (key.equals(COLOUR_SENT)) { break;
case COLOUR_SENT:
ThemeManager.setSentBubbleColored((Boolean) newValue); ThemeManager.setSentBubbleColored((Boolean) newValue);
} else if (key.equals(COLOUR_RECEIVED)) { break;
case COLOUR_RECEIVED:
ThemeManager.setReceivedBubbleColored((Boolean) newValue); ThemeManager.setReceivedBubbleColored((Boolean) newValue);
} else if (key.equals(NIGHT_AUTO)) { break;
case NIGHT_AUTO:
updateAlarmManager(mContext, (Boolean) newValue); updateAlarmManager(mContext, (Boolean) newValue);
} else if (key.equals(DAY_START) || key.equals(NIGHT_START)) { break;
case NIGHT_START:
updateAlarmManager(mContext, true); updateAlarmManager(mContext, true);
} else if (key.equals(SLIDING_TAB)) { break;
case SLIDING_TAB:
mContext.setSlidingTabEnabled((Boolean) newValue); mContext.setSlidingTabEnabled((Boolean) newValue);
} else if (key.equals(YAPPY)) { break;
case YAPPY:
if ((Boolean) newValue) { if ((Boolean) newValue) {
try { try {
EndlessJabberInterface.EnableIntegration(mContext, EndlessJabber.class, true, false); EndlessJabberInterface.EnableIntegration(mContext, EndlessJabber.class, true, false);
@@ -443,28 +454,37 @@ public class SettingsFragment extends PreferenceFragment implements
e.printStackTrace(); e.printStackTrace();
} }
} }
} else if (key.equals(QUICKCOMPOSE)) { break;
case QUICKCOMPOSE:
NotificationManager.initQuickCompose(getActivity(), (Boolean) newValue, !(Boolean) newValue); NotificationManager.initQuickCompose(getActivity(), (Boolean) newValue, !(Boolean) newValue);
} else if (key.equals(MMSC_URL) || key.equals(MMS_PROXY) || key.equals(MMS_PORT)) { break;
case MMSC_URL:
case MMS_PROXY:
case MMS_PORT:
preference.setSummary(newValue.toString()); preference.setSummary(newValue.toString());
} else if (key.equals(MAX_MMS_ATTACHMENT_SIZE)) { break;
case MAX_MMS_ATTACHMENT_SIZE:
// Update the summary in the list preference // Update the summary in the list preference
ListPreference listpref = (ListPreference) preference; ListPreference listpref = (ListPreference) preference;
int index = listpref.findIndexOfValue((String) newValue); int index = listpref.findIndexOfValue((String) newValue);
preference.setSummary(mMaxMmsAttachmentSizes[index]); preference.setSummary(mMaxMmsAttachmentSizes[index]);
// Update the SMS helper static class with the new option // Update the SMS helper static class with the new option
SmsHelper.setMaxAttachmentSizeSetting(mContext, (String) newValue); SmsHelper.setMaxAttachmentSizeSetting(mContext, (String) newValue);
} else if (key.equals(SYSTEM_BAR_FLAT)) { break;
case SYSTEM_BAR_FLAT:
ThemeManager.setSystemBarFlatEnabled((Boolean) newValue); ThemeManager.setSystemBarFlatEnabled((Boolean) newValue);
} else if (key.equals(STATUS_COMPAT)) { break;
case STATUS_COMPAT:
ThemeManager.setStatusBarTintCompat((Boolean) newValue); ThemeManager.setStatusBarTintCompat((Boolean) newValue);
} else if (key.equals(DELAY_DURATION)) { break;
case DELAY_DURATION:
try { try {
int duration = Integer.parseInt((String) newValue); int duration = Integer.parseInt((String) newValue);
if (duration < 1 || duration > 30) throw new Exception("Duration out of bounds"); if (duration < 1 || duration > 30) throw new Exception("Duration out of bounds");
} catch (Exception e) { } catch (Exception e) {
Toast.makeText(mContext, R.string.delayed_duration_bounds_error, Toast.LENGTH_SHORT).show(); Toast.makeText(mContext, R.string.delayed_duration_bounds_error, Toast.LENGTH_SHORT).show();
} }
break;
} }
return true; return true;