本文整理汇总了Java中android.preference.PreferenceGroup.getPreference方法的典型用法代码示例。如果您正苦于以下问题:Java PreferenceGroup.getPreference方法的具体用法?Java PreferenceGroup.getPreference怎么用?Java PreferenceGroup.getPreference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.PreferenceGroup
的用法示例。
在下文中一共展示了PreferenceGroup.getPreference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setChildrenStarted
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
private void setChildrenStarted(PreferenceGroup group, boolean started) {
final int count = group.getPreferenceCount();
for (int i = 0; i < count; i++) {
Preference pref = group.getPreference(i);
if (pref instanceof ApplicationLightPreference) {
ApplicationLightPreference ap = (ApplicationLightPreference) pref;
if (started) {
ap.onStart();
} else {
ap.onStop();
}
} else if (pref instanceof PreferenceGroup) {
setChildrenStarted((PreferenceGroup) pref, started);
}
}
}
示例2: onPause
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
@Override
protected void onPause() {
super.onPause();
// Save the selected languages
String checkedLanguages = "";
PreferenceGroup parent = getPreferenceScreen();
int count = parent.getPreferenceCount();
for (int i = 0; i < count; i++) {
CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i);
if (pref.isChecked()) {
Locale locale = mAvailableLanguages.get(i).locale;
checkedLanguages += get5Code(locale) + ",";
}
}
if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
Editor editor = sp.edit();
editor.putString(KP2AKeyboard.PREF_SELECTED_LANGUAGES, checkedLanguages);
SharedPreferencesCompat.apply(editor);
}
示例3: findWordListPreference
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
private WordListPreference findWordListPreference(final String id) {
final PreferenceGroup prefScreen = getPreferenceScreen();
if (null == prefScreen) {
Log.e(TAG, "Could not find the preference group");
return null;
}
for (int i = prefScreen.getPreferenceCount() - 1; i >= 0; --i) {
final Preference pref = prefScreen.getPreference(i);
if (pref instanceof WordListPreference) {
final WordListPreference wlPref = (WordListPreference)pref;
if (id.equals(wlPref.mWordlistId)) {
return wlPref;
}
}
}
Log.e(TAG, "Could not find the preference for a word list id " + id);
return null;
}
示例4: bind
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
private void bind(PreferenceGroup group) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
for (int i = 0; i < group.getPreferenceCount(); i++) {
Preference p = group.getPreference(i);
if (p instanceof PreferenceGroup) {
bind((PreferenceGroup) p);
} else {
if (p instanceof CheckBoxPreference) {
;
} else {
Object val = sp.getAll().get(p.getKey());
p.setSummary(val == null ? "" : ("" + val));
p.setOnPreferenceChangeListener(this);
}
}
}
}
示例5: onPause
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
@Override
protected void onPause() {
super.onPause();
// Save the selected languages
String checkedLanguages = "";
PreferenceGroup parent = getPreferenceScreen();
int count = parent.getPreferenceCount();
for (int i = 0; i < count; i++) {
CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i);
if (pref.isChecked()) {
Locale locale = mAvailableLanguages.get(i).locale;
checkedLanguages += get5Code(locale) + ",";
}
}
if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
Editor editor = sp.edit();
editor.putString(LatinIME.PREF_SELECTED_LANGUAGES, checkedLanguages);
SharedPreferencesCompat.apply(editor);
}
示例6: restoreDefaults
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
/**
* Restores the default preferences, which are contained by a specific preference group.
*
* @param preferenceGroup
* The preference group, whose preferences should be restored, as an instance of the
* class {@link PreferenceGroup}. The preference group may not be null
* @param sharedPreferences
* The shared preferences, which should be used to restore the preferences, as an
* instance of the type {@link SharedPreferences}. The shared preferences may not be
* null
*/
private void restoreDefaults(@NonNull final PreferenceGroup preferenceGroup,
@NonNull final SharedPreferences sharedPreferences) {
for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) {
Preference preference = preferenceGroup.getPreference(i);
if (preference instanceof PreferenceGroup) {
restoreDefaults((PreferenceGroup) preference, sharedPreferences);
} else if (preference.getKey() != null && !preference.getKey().isEmpty()) {
Object oldValue = sharedPreferences.getAll().get(preference.getKey());
if (notifyOnRestoreDefaultValueRequested(preference, oldValue)) {
sharedPreferences.edit().remove(preference.getKey()).apply();
preferenceGroup.removePreference(preference);
preferenceGroup.addPreference(preference);
Object newValue = sharedPreferences.getAll().get(preference.getKey());
notifyOnRestoredDefaultValue(preference, oldValue, newValue);
} else {
preferenceGroup.removePreference(preference);
preferenceGroup.addPreference(preference);
}
}
}
}
示例7: putAllPreferences
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
private void putAllPreferences(PreferenceGroup group) {
int c = 0;
String advancedPrefix = mActivity.getString(string.pref_advanced_prefix);
while(c < group.getPreferenceCount()) {
String key;
Preference preference = group.getPreference(c);
if(preference instanceof PreferenceGroup) {
putAllPreferences((PreferenceGroup)preference);
key = preference.getKey();
} else {
key = String.format("%s.%s", group.getKey(), preference.getKey());
}
setProperty(key, String.valueOf(!preference.getKey().startsWith(advancedPrefix)));
c++;
}
}
示例8: hideAdvancedPreferences
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
private void hideAdvancedPreferences(PreferenceGroup group) {
if(mAdvancedSettings.showAll()) {
return;
}
int c = 0;
while(c < group.getPreferenceCount()) {
Preference pref = group.getPreference(c);
if(!mAdvancedSettings.isVisible(group, pref)) {
group.removePreference(pref);
} else {
if(pref instanceof PreferenceGroup) {
hideAdvancedPreferences((PreferenceGroup)pref);
}
c++;
}
}
}
示例9: recursiveDelete
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
/**
* Recursively traverses the tree from the given group as the route and
* tries to delete the preference. Traversal stops once the preference
* was found and removed.
*/
private boolean recursiveDelete(PreferenceGroup group, Preference preference) {
if (group == null) {
Log.d(TAG, "attempting to delete from null preference group");
return false;
}
if (preference == null) {
Log.d(TAG, "attempting to delete null preference");
return false;
}
if (group.removePreference(preference)) {
// Removal was successful.
return true;
}
for (int i = 0; i < group.getPreferenceCount(); ++i) {
Preference pref = group.getPreference(i);
if (pref instanceof PreferenceGroup) {
if (recursiveDelete((PreferenceGroup) pref, preference)) {
return true;
}
}
}
return false;
}
示例10: fixListSummaries
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
/**
* Since the "%s" summary is currently broken, this sets the preference
* change listener for all {@link ListPreference} views to fill in the
* summary with the current entry value.
*/
private void fixListSummaries(PreferenceGroup group) {
if (group == null) {
return;
}
final int count = group.getPreferenceCount();
for (int i = 0; i < count; i++) {
final Preference preference = group.getPreference(i);
if (preference instanceof PreferenceGroup) {
fixListSummaries((PreferenceGroup) preference);
} else if (preference instanceof ListPreference) {
// First make sure the current summary is correct, then set the
// listener. This is necessary for summaries to show correctly
// on SDKs < 14.
mPreferenceChangeListener.onPreferenceChange(preference,
((ListPreference) preference).getValue());
preference.setOnPreferenceChangeListener(mPreferenceChangeListener);
}
}
}
示例11: fixListSummaries
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
/**
* Since the "%s" summary is currently broken, this sets the preference
* change listener for all {@link ListPreference} views to fill in the
* summary with the current entry value.
* TODO: %s works in L, but is broken in JB MR0, so check this as we move the min
* level.
*/
private void fixListSummaries(PreferenceGroup root) {
if (root == null) {
return;
}
final int count = root.getPreferenceCount();
for (int i = 0; i < count; i++) {
final Preference preference = root.getPreference(i);
if (preference instanceof ListPreference) {
fixUnboundPrefSummary(preference);
preference.setOnPreferenceChangeListener(mPreferenceChangeListener);
} else if (preference instanceof PreferenceGroup) {
fixListSummaries((PreferenceGroup) preference);
}
}
}
示例12: initGatewayEditTextPreference
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
private void initGatewayEditTextPreference(Preference preference) {
if (preference instanceof PreferenceGroup) {
PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
for (int i=0; i<preferenceGroup.getPreferenceCount(); i++) {
if (preferenceGroup.getPreference(i).getTitle().equals("Gateway")) {
PreferenceCategory preferenceCategory = (PreferenceCategory) preferenceGroup.getPreference(i);
initGatewayEditTextPreference(preferenceCategory.getPreference(0));
} else {
initGatewayEditTextPreference(preferenceGroup.getPreference(i));
}
}
} else if (preference instanceof EditTextPreference) {
// TODO wrong ClassCastException ?!?!
gatewayEditTextPreference = (GatewayEditTextPreference) preference;
}
}
示例13: onResume
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
@Override
public void onResume() {
super.onResume();
PreferenceScreen preferenceScreen = getPreferenceScreen();
for (int i = 0; i < preferenceScreen.getPreferenceCount(); i++) {
Preference preference = preferenceScreen.getPreference(i);
if (preference instanceof PreferenceGroup) {
PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
for (int j = 0; j < preferenceGroup.getPreferenceCount(); j++) {
Preference subPref = preferenceGroup.getPreference(j);
updatePreference(subPref, subPref.getKey());
}
} else {
updatePreference(preference, preference.getKey());
}
}
}
示例14: getParentGroup
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
private static PreferenceGroup getParentGroup(PreferenceGroup preferenceGroup, Preference preference) {
for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) {
Preference childPreference = preferenceGroup.getPreference(i);
if (childPreference == preference) {
return preferenceGroup;
}
if (childPreference instanceof PreferenceGroup) {
PreferenceGroup foundPreferenceGroup = getParentGroup((PreferenceGroup) childPreference,
preference);
if (foundPreferenceGroup != null) {
return foundPreferenceGroup;
}
}
}
return null;
}
示例15: onActivityCreated
import android.preference.PreferenceGroup; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
PreferenceScreen preferenceScreen = getPreferenceScreen();
SharedPreferenceListener sharedPreferenceListener = new SharedPreferenceListener();
for(int idPreference = 0; idPreference < preferenceScreen.getPreferenceCount(); idPreference++) {
Preference preference = preferenceScreen.getPreference(idPreference);
if(preference instanceof PreferenceGroup) {
PreferenceGroup preferenceGroup = (PreferenceGroup)preference;
for(int IdGroupReference = 0; IdGroupReference < preferenceGroup.getPreferenceCount(); IdGroupReference++) {
preference = preferenceGroup.getPreference(IdGroupReference);
preference.setOnPreferenceChangeListener(sharedPreferenceListener);
}
} else {
preference.setOnPreferenceChangeListener(sharedPreferenceListener);
}
}
}