RingtonePreference getEntry method

2.3k views Asked by At

I want to display current selected value in my preferences screen in summary label.

For ListPreference, I used getEntry method in

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

method, my class is:

public class AlarmPropertiesActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener

For EditTextPreference, I used getText method

I try get default value for RingtonePreference, but I have not found any get method for that.

Anybody help me?

BR Kolesar

2

There are 2 answers

0
Kevin Wittek On

I have the same problem. Tried to go over the SharedPreferences value, but unfortunately the uri leads to an id like named file.

private void updateSummary(Preference p, SharedPreferences sharedPrefs) {
    if (p instanceof ListPreference) {

        ListPreference listPref = (ListPreference) p;
        p.setSummary(listPref.getEntry());

    } else if (p instanceof RingtonePreference) {

        /* 
         * This is kind of a longshot, since we are not able to get the entry directly and
         * so we have to go the route via the shared preferences.
         */

        RingtonePreference ringPref = (RingtonePreference) p;
        String ringtoneKey = ringPref.getKey();
        String ringtonePath = sharedPrefs.getString(ringtoneKey, "");
        ringPref.setSummary(ringtonePath);

    }
}

The path is something like this: content://media/internal/audio/media/25

So this is no suitable solution. But I noticed, that for example the GoogleTalk app doesn't show the selected notification sound as well. GoogleMail on the other hand shows it.

0
Waza_Be On

This one works for me ;-)

if (pref instanceof RingtonePreference) {

            Log.i("***", "RingtonePreference " + pref.getKey());
            final RingtonePreference ringPref = (RingtonePreference) pref;
            ringPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference,
                        Object newValue) {
                    Log.i("***", "Changed " + newValue.toString());
                    Ringtone ringtone = RingtoneManager.getRingtone(
                            SettingsActivity.this, Uri.parse((String) newValue));
                    ringPref.setSummary(ringtone.getTitle(SettingsActivity.this));
                    return true;
                }
            });
            String ringtonePath=pref.getSharedPreferences().getString(pref.getKey(), "defValue");
            Ringtone ringtone = RingtoneManager.getRingtone(
                    SettingsActivity.this, Uri.parse((String) ringtonePath));
            ringPref.setSummary(ringtone.getTitle(SettingsActivity.this));

        }