android.preference.RingtonePreference Java Examples

The following examples show how to use android.preference.RingtonePreference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SettingsFragment.java    From ToDoList with Apache License 2.0 6 votes vote down vote up
public void intView(){
    preferenceScreen = getPreferenceScreen();
    mRingtone = (RingtonePreference) preferenceScreen.findPreference(KEY_RINGTONE);
    mFocus = (SwitchPreference) preferenceScreen.findPreference(KEY_FOCUS);
    mChangePassWord = (Preference) preferenceScreen.findPreference(KEY_PWD);
    mExitLogin = (Preference) preferenceScreen.findPreference(KEY_EXIT);
    Uri uri = Uri.parse(SPUtils.get(getActivity(), KEY_RINGTONE, "").toString());
    Log.i(TAG, "铃声" + getRingtonName(uri));
    if (getRingtonName(uri).equals("未知铃声")){
        mRingtone.setSummary("默认铃声");
    } else {
        mRingtone.setSummary(getRingtonName(uri));
    }
    mFocus.setChecked(getIsFocus(getActivity()));

}
 
Example #2
Source File: PreferencesUtil.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (preference instanceof RingtonePreference) {
    } else if (preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        editTextPreference.setSummary(editTextPreference.getText());
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #3
Source File: SettingsActivity.java    From android-espresso-revealed with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.pref_notification);
    setHasOptionsMenu(true);

    // Bind the summaries of EditText/List/Dialog/Ringtone preferences
    // to their values. When their values change, their summaries are
    // updated to reflect the new value, per the Android Design
    // guidelines.
    bindPreferenceSummaryToValue(findPreference("notifications_new_message_ringtone"));
    preferenceScreen = getPreferenceScreen();
    sendNotificationPreference = (Preference) this.findPreference("notifications_send");
    sendNotificationWithDelayPreference = (Preference) this.findPreference("notifications_with_delay_send");
    switchPreference = (SwitchPreference) this.findPreference("notifications_new_message");
    ringtonePreference = (RingtonePreference) this.findPreference("notifications_new_message_ringtone");
    vibratePreference = (CheckBoxPreference) this.findPreference("notifications_new_message_vibrate");
    notificationsSlider = (SliderPreference) this.findPreference("notifications_slider");
    setNotificationPreferences();
    sendNotificationPreference.setOnPreferenceClickListener(sendNotificationListener);
    sendNotificationWithDelayPreference.setOnPreferenceClickListener(sendNotificationWithDelayListener);
    switchPreference.setOnPreferenceClickListener(switchPreferenceListener);
}
 
Example #4
Source File: PreferencesUtil.java    From text_converter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (preference instanceof RingtonePreference) {
    } else if (preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        editTextPreference.setSummary(editTextPreference.getText());
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #5
Source File: PreferencesUtil.java    From ncalc with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (preference instanceof RingtonePreference) {
    } else if (preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        editTextPreference.setSummary(editTextPreference.getText());
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #6
Source File: PreferencesUtil.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (preference instanceof RingtonePreference) {
    } else if (preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        editTextPreference.setSummary(editTextPreference.getText());
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #7
Source File: PreferencesUtil.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (preference instanceof RingtonePreference) {
    } else if (preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        editTextPreference.setSummary(editTextPreference.getText());
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #8
Source File: Preferences.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();
    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #9
Source File: SettingsFragment.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);

    mChatRingtoneKey = getString(R.string.pref_chat_ringtone);
    mChatRingtonePreference = (RingtonePreference) findPreference(mChatRingtoneKey);
    mChatRingtonePreference.setOnPreferenceChangeListener(this);
    updateRingtonePreferenceSummary(SharedPreferenceHelper
                                            .getString(R.string.pref_chat_ringtone));
}
 
Example #10
Source File: Preferences.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();
    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #11
Source File: SettingsActivity.java    From android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        if (TextUtils.isEmpty(stringValue)) {
            preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                preference.setSummary(null);
            } else {
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #12
Source File: SettingsFragment.java    From ClockPlus with GNU General Public License v3.0 5 votes vote down vote up
private void setSummary(SharedPreferences prefs, String key) {
    Preference pref = findPreference(key);
    // Setting a ListPreference's summary value to "%s" in XML automatically updates the
    // preference's summary to display the selected value.
    if (pref instanceof RingtonePreference) {
        Uri ringtoneUri = Uri.parse(prefs.getString(key, ""));
        Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), ringtoneUri);
        pref.setSummary(ringtone.getTitle(getActivity()));
    }
}
 
Example #13
Source File: SettingsActivity.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                        index >= 0
                                ? listPreference.getEntries()[index]
                                : null);

    } else if (preference instanceof RingtonePreference) {
        if (TextUtils.isEmpty(stringValue)) {
            preference.setSummary(R.string.pref_ringtone_silent);
        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                preference.setSummary(null);
            } else {
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }
    } else {
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #14
Source File: Preferences.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();
    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #15
Source File: Preferences.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();
    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #16
Source File: SettingsActivity.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        if (TextUtils.isEmpty(stringValue)) {
            preference.setSummary("Silent");
        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                preference.setSummary(null);
            } else {
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }
    } else {
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #17
Source File: SettingsActivity.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        if (TextUtils.isEmpty(stringValue)) {
            preference.setSummary("Silent");
        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                preference.setSummary(null);
            } else {
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }
    } else {
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #18
Source File: SettingsActivity.java    From Android-Audio-Recorder with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        Ringtone ringtone = RingtoneManager.getRingtone(
                preference.getContext(), Uri.parse(stringValue));

        if (ringtone == null) {
            // Clear the summary if there was a lookup error.
            preference.setSummary(null);
        } else {
            // Set the summary to reflect the new ringtone display
            // name.
            String name = ringtone.getTitle(preference.getContext());
            preference.setSummary(name);
        }
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #19
Source File: SettingsActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();
    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (preference instanceof RingtonePreference) {
        if (TextUtils.isEmpty(stringValue)) {
            preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                preference.setSummary(null);
            } else {
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }
    } else {
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #20
Source File: SettingsActivity.java    From XMouse with MIT License 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary("Silent");

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #21
Source File: RingtonePreferenceAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public RingtonePreferenceAssert(RingtonePreference actual) {
  super(actual, RingtonePreferenceAssert.class);
}
 
Example #22
Source File: SettingsActivity.java    From android_app_cputempinstatusbar with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
	String stringValue = value==null?"":value.toString();
	PreferenceManager pm = preference.getPreferenceManager();
	
	// get color_mode
	String sColorMode="0";
	int color_mode = 0;
	try {
		if(preference.getKey().equals("color_mode"))
			sColorMode = stringValue;
		else
			sColorMode = PreferenceManager.getDefaultSharedPreferences(
					preference.getContext()).getString("color_mode", "0");
		color_mode = Integer.parseInt(sColorMode);
	}
	catch(Exception e){
	}
	
	switch(color_mode) {
	case 1:
		pm.findPreference("configured_color").setEnabled(true);
		pm.findPreference("color_low").setEnabled(false);
		pm.findPreference("color_middle").setEnabled(false);
		pm.findPreference("color_high").setEnabled(false);
		pm.findPreference("temp_middle").setEnabled(false);
		pm.findPreference("temp_high").setEnabled(false);
		break;
	case 2:
		pm.findPreference("configured_color").setEnabled(false);
		pm.findPreference("color_low").setEnabled(true);
		pm.findPreference("color_middle").setEnabled(true);
		pm.findPreference("color_high").setEnabled(true);
		pm.findPreference("temp_middle").setEnabled(true);
		pm.findPreference("temp_high").setEnabled(true);
		break;
	case 0:
	default:
		pm.findPreference("configured_color").setEnabled(false);
		pm.findPreference("color_low").setEnabled(false);
		pm.findPreference("color_middle").setEnabled(false);
		pm.findPreference("color_high").setEnabled(false);
		pm.findPreference("temp_middle").setEnabled(false);
		pm.findPreference("temp_high").setEnabled(false);
		break;
	}
	
	if (preference instanceof ListPreference) {
		// For list preferences, look up the correct display value in
		// the preference's 'entries' list.
		ListPreference listPreference = (ListPreference) preference;
		int index = listPreference.findIndexOfValue(stringValue);

		// Set the summary to reflect the new value.
		preference
				.setSummary(index >= 0 ? listPreference.getEntries()[index]
						: null);

	} else if (preference instanceof RingtonePreference) {
		// For ringtone preferences, look up the correct display value
		// using RingtoneManager.
		if (TextUtils.isEmpty(stringValue)) {
			// Empty values correspond to 'silent' (no ringtone).
			// preference.setSummary(R.string.pref_ringtone_silent);

		} else {
			Ringtone ringtone = RingtoneManager.getRingtone(
					preference.getContext(), Uri.parse(stringValue));

			if (ringtone == null) {
				// Clear the summary if there was a lookup error.
				preference.setSummary(null);
			} else {
				// Set the summary to reflect the new ringtone display
				// name.
				String name = ringtone
						.getTitle(preference.getContext());
				preference.setSummary(name);
			}
		}

	} else if(!(preference instanceof ColorPickerPreference) && !(preference instanceof CheckBoxPreference)) {
		// For all other preferences, set the summary to the value's
		// simple string representation.
		preference.setSummary(stringValue);
	}
	return true;
}
 
Example #23
Source File: SettingsFragment.java    From smartcard-reader with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference
                .setSummary(index >= 0 ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);
        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone
                        .getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #24
Source File: BaseSettingsActivity.java    From BetterWeather with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            //preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else if (preference instanceof AppChooserPreference) {

        preference.setSummary(AppChooserPreference.getDisplayValue(preference.getContext(), stringValue));

    } else if (preference instanceof WeatherLocationPreference) {
        preference.setSummary(WeatherLocationPreference.getDisplayValue(preference.getContext(), stringValue));
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #25
Source File: SettingsActivity.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
	String stringValue = value.toString();

	if (preference instanceof ListPreference) {
		// For list preferences, look up the correct display value in
		// the preference's 'entries' list.
		ListPreference listPreference = (ListPreference) preference;
		int index = listPreference.findIndexOfValue(stringValue);

		// Set the summary to reflect the new value.
		preference
				.setSummary(index >= 0 ? listPreference.getEntries()[index]
						: null);

	} else if (preference instanceof RingtonePreference) {
		// For ringtone preferences, look up the correct display value
		// using RingtoneManager.
		if (TextUtils.isEmpty(stringValue)) {
			// Empty values correspond to 'silent' (no ringtone).
			preference.setSummary(R.string.pref_ringtone_silent);

		} else {
			Ringtone ringtone = RingtoneManager.getRingtone(
					preference.getContext(), Uri.parse(stringValue));

			if (ringtone == null) {
				// Clear the summary if there was a lookup error.
				preference.setSummary(null);
			} else {
				// Set the summary to reflect the new ringtone display
				// name.
				String name = ringtone
						.getTitle(preference.getContext());
				preference.setSummary(name);
			}
		}

	} else {
		// For all other preferences, set the summary to the value's
		// simple string representation.
		preference.setSummary(stringValue);
	}
	return true;
}
 
Example #26
Source File: SettingActivity.java    From SimplePomodoro-android with MIT License 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
	String stringValue = value.toString();
	if (preference instanceof ListPreference) {
		ListPreference listPreference = (ListPreference) preference;
		int index = listPreference.findIndexOfValue(stringValue);

		// Set the summary to reflect the new value.
		preference
				.setSummary(index >= 0 ? listPreference.getEntries()[index]
						: null);

	} else if (preference instanceof RingtonePreference) {
		// For ringtone preferences, look up the correct display value
		// using RingtoneManager.
		if (TextUtils.isEmpty(stringValue)) {
			// Empty values correspond to 'silent' (no ringtone).
			preference.setSummary(R.string.pref_ringtone_silent);

		} else {
			Ringtone ringtone = RingtoneManager.getRingtone(
					preference.getContext(), Uri.parse(stringValue));

			if (ringtone == null) {
				// Clear the summary if there was a lookup error.
				preference.setSummary(null);
			} else {
				// Set the summary to reflect the new ringtone display
				// name.
				String name = ringtone
						.getTitle(preference.getContext());
				preference.setSummary(name);
			}
		}

	} else {
		// For all other preferences, set the summary to the value's
		// simple string representation.
		preference.setSummary(stringValue);
	}
	return true;
}
 
Example #27
Source File: SettingsActivity.java    From android-auto-call-recorder with MIT License 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    String stringValue = newValue.toString();

    Log.d(TAG, "new value = " + newValue);

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display newValue in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new newValue.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display newValue
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the newValue's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #28
Source File: SettingsActivity.java    From KinoCast with MIT License 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example #29
Source File: UserSettingsActivity.java    From sensorhub with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value)
{
    String stringValue = value.toString();
    
    if (preference instanceof EditTextPreference)
    {
        if (stringValue == null || stringValue.length() == 0)
        {
            preference.getEditor().clear();
            preference.getEditor().commit();
            
        }
    }

    if (preference instanceof ListPreference)
    {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    }
    else if (preference instanceof RingtonePreference)
    {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue))
        {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);

        }
        else
        {
            Ringtone ringtone = RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null)
            {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            }
            else
            {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    }
    else
    {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    
    return true;
}
 
Example #30
Source File: SettingsActivity.java    From SwitchPreferenceCompat with MIT License 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);

    } else if (preference instanceof RingtonePreference) {
        // For ringtone preferences, look up the correct display value
        // using RingtoneManager.
        if (TextUtils.isEmpty(stringValue)) {
            // Empty values correspond to 'silent' (no ringtone).
            preference.setSummary(R.string.pref_ringtone_silent);

        } else {
            Ringtone ringtone = RingtoneManager.getRingtone(
                    preference.getContext(), Uri.parse(stringValue));

            if (ringtone == null) {
                // Clear the summary if there was a lookup error.
                preference.setSummary(null);
            } else {
                // Set the summary to reflect the new ringtone display
                // name.
                String name = ringtone.getTitle(preference.getContext());
                preference.setSummary(name);
            }
        }

    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}