summaryrefslogtreecommitdiff
path: root/core/java/android/preference/Preference.java
diff options
context:
space:
mode:
authorFilip Pavlis <pavlis@google.com>2017-01-10 19:17:09 +0000
committerFilip Pavlis <pavlis@google.com>2017-01-12 16:03:11 +0000
commitcba645896f53ca7b5508d6ebcc60d93a640cd19d (patch)
tree5b09bb2bb3c8da41d2e6b411a090f31aecb4bfba /core/java/android/preference/Preference.java
parentd61cc80acac3441826707422423d5881522d8d32 (diff)
Add getParent() on Preference.
Preference class now keeps track of its PreferenceGroup parent which makes it easier to remove it from the preference hierarchy. This required a new API method. Test: Separate CTS CL being submitted along this one, see the topic. BUG: 30599046 Change-Id: Ia9f274ef0315cb09a8c558e781b10f57efd28406
Diffstat (limited to 'core/java/android/preference/Preference.java')
-rw-r--r--core/java/android/preference/Preference.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/java/android/preference/Preference.java b/core/java/android/preference/Preference.java
index 8303bca34bee..089eaeceac55 100644
--- a/core/java/android/preference/Preference.java
+++ b/core/java/android/preference/Preference.java
@@ -145,6 +145,8 @@ public class Preference implements Comparable<Preference> {
private List<Preference> mDependents;
+ private PreferenceGroup mParentGroup;
+
private boolean mBaseMethodCalled;
/**
@@ -1238,6 +1240,16 @@ public class Preference implements Comparable<Preference> {
registerDependency();
}
+ /**
+ * Assigns a {@link PreferenceGroup} as the parent of this Preference. Set null to remove
+ * the current parent.
+ *
+ * @param parentGroup Parent preference group of this Preference or null if none.
+ */
+ void assignParent(@Nullable PreferenceGroup parentGroup) {
+ mParentGroup = parentGroup;
+ }
+
private void registerDependency() {
if (TextUtils.isEmpty(mDependencyKey)) return;
@@ -1401,6 +1413,17 @@ public class Preference implements Comparable<Preference> {
}
/**
+ * Returns the {@link PreferenceGroup} which is this Preference assigned to or null if this
+ * preference is not assigned to any group or is a root Preference.
+ *
+ * @return The parent PreferenceGroup or null if not attached to any.
+ */
+ @Nullable
+ public PreferenceGroup getParent() {
+ return mParentGroup;
+ }
+
+ /**
* Called when this Preference is being removed from the hierarchy. You
* should remove any references to this Preference that you know about. Make
* sure to call through to the superclass implementation.