From 81dd0de8a160a92817fbf3c3bb2226e6c8eddbfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 21 Aug 2015 17:41:41 -0700 Subject: [PATCH] Start using string switches (Java 1.7) --- .../java/com/moez/QKSMS/mmssms/ApnUtils.java | 26 ++-- .../QKSMS/ui/settings/SettingsFragment.java | 134 ++++++++++-------- 2 files changed, 93 insertions(+), 67 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/mmssms/ApnUtils.java b/QKSMS/src/main/java/com/moez/QKSMS/mmssms/ApnUtils.java index 1ec90120..3c5d56bd 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/mmssms/ApnUtils.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/mmssms/ApnUtils.java @@ -150,16 +150,22 @@ public class ApnUtils { for (int i = 0; i < parser.getAttributeCount(); i++) { String name = parser.getAttributeName(i); String value = parser.getAttributeValue(i); - if ("mmsc".equals(name)) { - apn.mmsc = value; - } else if ("mmsproxy".equals(name)) { - apn.proxy = value; - } else if ("mmsport".equals(name)) { - apn.port = value; - } else if ("carrier".equals(name)) { - apn.name = value; - } else if ("port".equals(name)) { - port = value; + switch (name) { + case "mmsc": + apn.mmsc = value; + break; + case "mmsproxy": + apn.proxy = value; + break; + case "mmsport": + apn.port = value; + break; + case "carrier": + apn.name = value; + break; + case "port": + port = value; + break; } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index ba524e81..758f4aa3 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -405,66 +405,86 @@ public class SettingsFragment extends PreferenceFragment implements valueString ); - if (key.equals(BACKGROUND)) { - ThemeManager.setTheme(ThemeManager.Theme.fromString((String) newValue)); - } else if (key.equals(STATUS_TINT)) { - ThemeManager.setStatusBarTintEnabled((Boolean) newValue); - } else if (key.equals(FONT_FAMILY)) { - preference.setSummary(mFontFamilies[Integer.parseInt("" + newValue)]); - } else if (key.equals(FONT_SIZE)) { - preference.setSummary(mFontSizes[Integer.parseInt("" + newValue)]); - } else if (key.equals(FONT_WEIGHT)) { - int i = Integer.parseInt("" + newValue); - preference.setSummary(mFontWeights[i == 2 ? 0 : 1]); - } else if (key.equals(COLOUR_SENT)) { - ThemeManager.setSentBubbleColored((Boolean) newValue); - } else if (key.equals(COLOUR_RECEIVED)) { - ThemeManager.setReceivedBubbleColored((Boolean) newValue); - } else if (key.equals(NIGHT_AUTO)) { - updateAlarmManager(mContext, (Boolean) newValue); - } else if (key.equals(DAY_START) || key.equals(NIGHT_START)) { - updateAlarmManager(mContext, true); - } else if (key.equals(SLIDING_TAB)) { - mContext.setSlidingTabEnabled((Boolean) newValue); - } else if (key.equals(YAPPY)) { - if ((Boolean) newValue) { + switch (key) { + case BACKGROUND: + ThemeManager.setTheme(ThemeManager.Theme.fromString((String) newValue)); + break; + case STATUS_TINT: + ThemeManager.setStatusBarTintEnabled((Boolean) newValue); + break; + case FONT_FAMILY: + preference.setSummary(mFontFamilies[Integer.parseInt("" + newValue)]); + break; + case FONT_SIZE: + preference.setSummary(mFontSizes[Integer.parseInt("" + newValue)]); + break; + case FONT_WEIGHT: + int i = Integer.parseInt("" + newValue); + preference.setSummary(mFontWeights[i == 2 ? 0 : 1]); + break; + case COLOUR_SENT: + ThemeManager.setSentBubbleColored((Boolean) newValue); + break; + case COLOUR_RECEIVED: + ThemeManager.setReceivedBubbleColored((Boolean) newValue); + break; + case NIGHT_AUTO: + updateAlarmManager(mContext, (Boolean) newValue); + break; + case NIGHT_START: + updateAlarmManager(mContext, true); + break; + case SLIDING_TAB: + mContext.setSlidingTabEnabled((Boolean) newValue); + break; + case YAPPY: + if ((Boolean) newValue) { + try { + EndlessJabberInterface.EnableIntegration(mContext, EndlessJabber.class, true, false); + } catch (Exception e) { + e.printStackTrace(); + } + if (!EndlessJabberInterface.IsInstalled(mContext)) { + EndlessJabberInterface.OpenGooglePlayLink(mContext); + } + } else { + try { + EndlessJabberInterface.DisableIntegration(mContext, EndlessJabber.class); + } catch (Exception e) { + e.printStackTrace(); + } + } + break; + case QUICKCOMPOSE: + NotificationManager.initQuickCompose(getActivity(), (Boolean) newValue, !(Boolean) newValue); + break; + case MMSC_URL: + case MMS_PROXY: + case MMS_PORT: + preference.setSummary(newValue.toString()); + break; + case MAX_MMS_ATTACHMENT_SIZE: + // Update the summary in the list preference + ListPreference listpref = (ListPreference) preference; + int index = listpref.findIndexOfValue((String) newValue); + preference.setSummary(mMaxMmsAttachmentSizes[index]); + // Update the SMS helper static class with the new option + SmsHelper.setMaxAttachmentSizeSetting(mContext, (String) newValue); + break; + case SYSTEM_BAR_FLAT: + ThemeManager.setSystemBarFlatEnabled((Boolean) newValue); + break; + case STATUS_COMPAT: + ThemeManager.setStatusBarTintCompat((Boolean) newValue); + break; + case DELAY_DURATION: try { - EndlessJabberInterface.EnableIntegration(mContext, EndlessJabber.class, true, false); + int duration = Integer.parseInt((String) newValue); + if (duration < 1 || duration > 30) throw new Exception("Duration out of bounds"); } catch (Exception e) { - e.printStackTrace(); + Toast.makeText(mContext, R.string.delayed_duration_bounds_error, Toast.LENGTH_SHORT).show(); } - if (!EndlessJabberInterface.IsInstalled(mContext)) { - EndlessJabberInterface.OpenGooglePlayLink(mContext); - } - } else { - try { - EndlessJabberInterface.DisableIntegration(mContext, EndlessJabber.class); - } catch (Exception e) { - e.printStackTrace(); - } - } - } else if (key.equals(QUICKCOMPOSE)) { - NotificationManager.initQuickCompose(getActivity(), (Boolean) newValue, !(Boolean) newValue); - } else if (key.equals(MMSC_URL) || key.equals(MMS_PROXY) || key.equals(MMS_PORT)) { - preference.setSummary(newValue.toString()); - } else if (key.equals(MAX_MMS_ATTACHMENT_SIZE)) { - // Update the summary in the list preference - ListPreference listpref = (ListPreference) preference; - int index = listpref.findIndexOfValue((String) newValue); - preference.setSummary(mMaxMmsAttachmentSizes[index]); - // Update the SMS helper static class with the new option - SmsHelper.setMaxAttachmentSizeSetting(mContext, (String) newValue); - } else if (key.equals(SYSTEM_BAR_FLAT)) { - ThemeManager.setSystemBarFlatEnabled((Boolean) newValue); - } else if (key.equals(STATUS_COMPAT)) { - ThemeManager.setStatusBarTintCompat((Boolean) newValue); - } else if (key.equals(DELAY_DURATION)) { - try { - int duration = Integer.parseInt((String) newValue); - if (duration < 1 || duration > 30) throw new Exception("Duration out of bounds"); - } catch (Exception e) { - Toast.makeText(mContext, R.string.delayed_duration_bounds_error, Toast.LENGTH_SHORT).show(); - } + break; } return true;