diff options
Diffstat (limited to 'core/java/android/preference')
-rw-r--r-- | core/java/android/preference/PreferenceFragment.java | 1 | ||||
-rw-r--r-- | core/java/android/preference/PreferenceManager.java | 30 | ||||
-rw-r--r-- | core/java/android/preference/RingtonePreference.java | 8 |
3 files changed, 31 insertions, 8 deletions
diff --git a/core/java/android/preference/PreferenceFragment.java b/core/java/android/preference/PreferenceFragment.java index 479497a..7629c31 100644 --- a/core/java/android/preference/PreferenceFragment.java +++ b/core/java/android/preference/PreferenceFragment.java @@ -144,6 +144,7 @@ public abstract class PreferenceFragment extends Fragment implements public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPreferenceManager = new PreferenceManager(getActivity(), FIRST_REQUEST_CODE); + mPreferenceManager.setFragment(this); mPreferenceManager.setOnPreferenceTreeClickListener(this); } diff --git a/core/java/android/preference/PreferenceManager.java b/core/java/android/preference/PreferenceManager.java index fa83897..42150ed 100644 --- a/core/java/android/preference/PreferenceManager.java +++ b/core/java/android/preference/PreferenceManager.java @@ -16,12 +16,7 @@ package android.preference; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; - import android.app.Activity; -import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -34,6 +29,10 @@ import android.content.res.XmlResourceParser; import android.os.Bundle; import android.util.Log; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + /** * Used to help create {@link Preference} hierarchies * from activities or XML. @@ -61,6 +60,11 @@ public class PreferenceManager { private Activity mActivity; /** + * Fragment that owns this instance. + */ + private PreferenceFragment mFragment; + + /** * The context to use. This should always be set. * * @see #mActivity @@ -158,7 +162,21 @@ public class PreferenceManager { setSharedPreferencesName(getDefaultSharedPreferencesName(context)); } - + + /** + * Sets the owning preference fragment + */ + void setFragment(PreferenceFragment fragment) { + mFragment = fragment; + } + + /** + * Returns the owning preference fragment, if any. + */ + PreferenceFragment getFragment() { + return mFragment; + } + /** * Returns a list of {@link Activity} (indirectly) that match a given * {@link Intent}. diff --git a/core/java/android/preference/RingtonePreference.java b/core/java/android/preference/RingtonePreference.java index b46f180..cf14097 100644 --- a/core/java/android/preference/RingtonePreference.java +++ b/core/java/android/preference/RingtonePreference.java @@ -24,7 +24,6 @@ import android.net.Uri; import android.provider.Settings.System; import android.text.TextUtils; import android.util.AttributeSet; -import android.util.Log; /** * A {@link Preference} that allows the user to choose a ringtone from those on the device. @@ -137,7 +136,12 @@ public class RingtonePreference extends Preference implements // Launch the ringtone picker Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); onPrepareRingtonePickerIntent(intent); - getPreferenceManager().getActivity().startActivityForResult(intent, mRequestCode); + PreferenceFragment owningFragment = getPreferenceManager().getFragment(); + if (owningFragment != null) { + owningFragment.startActivityForResult(intent, mRequestCode); + } else { + getPreferenceManager().getActivity().startActivityForResult(intent, mRequestCode); + } } /** |