Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "Align "from code" parent-child preference flow with "from XML""
Browse files Browse the repository at this point in the history
  • Loading branch information
tjohns authored and Gerrit Code Review committed Mar 11, 2014
2 parents c046b48 + 4ececa3 commit 9d56355
Showing 1 changed file with 8 additions and 7 deletions.
Expand Up @@ -32,17 +32,18 @@

public class PreferencesFromCode extends PreferenceActivity {

private static final String PARENT_CHECKBOX_PREFERENCE = "parent_checkbox_preference";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setPreferenceScreen(createPreferenceHierarchy());
}

private PreferenceScreen createPreferenceHierarchy() {
// Root
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
setPreferenceScreen(root);
populatePreferenceHierarchy(root);
}

private void populatePreferenceHierarchy(PreferenceScreen root) {
// Inline preferences
PreferenceCategory inlinePrefCat = new PreferenceCategory(this);
inlinePrefCat.setTitle(R.string.inline_preferences);
Expand Down Expand Up @@ -132,6 +133,7 @@ private PreferenceScreen createPreferenceHierarchy() {
parentCheckBoxPref.setTitle(R.string.title_parent_preference);
parentCheckBoxPref.setSummary(R.string.summary_parent_preference);
prefAttrsCat.addPreference(parentCheckBoxPref);
parentCheckBoxPref.setKey(PARENT_CHECKBOX_PREFERENCE);

// Visual child toggle preference
// See res/values/attrs.xml for the <declare-styleable> that defines
Expand All @@ -144,8 +146,7 @@ private PreferenceScreen createPreferenceHierarchy() {
a.getResourceId(R.styleable.TogglePrefAttrs_android_preferenceLayoutChild,
0));
prefAttrsCat.addPreference(childCheckBoxPref);
childCheckBoxPref.setDependency(PARENT_CHECKBOX_PREFERENCE);
a.recycle();

return root;
}
}

0 comments on commit 9d56355

Please sign in to comment.