Commit 9447a4c6 authored by Grigory Fedorov's avatar Grigory Fedorov

PreferenceSummaryHelper: new method getPreferenceTitle - to get title from...

PreferenceSummaryHelper: new method getPreferenceTitle - to get title from title and summary resource string.
parent c5f7e373
...@@ -26,25 +26,47 @@ import android.preference.PreferenceGroup; ...@@ -26,25 +26,47 @@ import android.preference.PreferenceGroup;
*/ */
public final class PreferenceSummaryHelper { public final class PreferenceSummaryHelper {
private PreferenceSummaryHelper() { private PreferenceSummaryHelper() {
} }
public static void updateSummary(PreferenceGroup group) { public static void updateSummary(PreferenceGroup group) {
for (int index = 0; index < group.getPreferenceCount(); index++) { for (int index = 0; index < group.getPreferenceCount(); index++) {
Preference preference = group.getPreference(index); Preference preference = group.getPreference(index);
if (preference instanceof PreferenceGroup) if (preference instanceof PreferenceGroup) {
updateSummary((PreferenceGroup) preference); updateSummary((PreferenceGroup) preference);
String title = preference.getTitle().toString(); }
int delimeter = title.indexOf("\n"); String titleAndSummary = preference.getTitle().toString();
if (delimeter == -1)
continue; if (!isTitleAndSummary(titleAndSummary)) {
preference.setTitle(title.substring(0, delimeter)); continue;
if (preference instanceof DialogPreference) }
((DialogPreference) preference).setDialogTitle(preference
.getTitle()); preference.setTitle(getPreferenceTitle(titleAndSummary));
preference if (preference instanceof DialogPreference) {
.setSummary(title.substring(delimeter + 1, title.length())); ((DialogPreference) preference).setDialogTitle(preference.getTitle());
} }
} preference.setSummary(getPreferenceSummary(titleAndSummary));
}
}
private static boolean isTitleAndSummary(String titleAndSummary) {
return titleAndSummary.contains("\n");
}
public static String getPreferenceTitle(String titleAndSummary) {
int delimiter = titleAndSummary.indexOf("\n");
if (delimiter == -1) {
return titleAndSummary;
}
return titleAndSummary.substring(0, delimiter);
}
private static String getPreferenceSummary(String titleAndSummary) {
int delimiter = titleAndSummary.indexOf("\n");
if (delimiter == -1) {
return "";
}
return titleAndSummary.substring(delimiter + 1, titleAndSummary.length());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment