本文整理匯總了Java中android.support.v7.preference.PreferenceScreen.findPreference方法的典型用法代碼示例。如果您正苦於以下問題:Java PreferenceScreen.findPreference方法的具體用法?Java PreferenceScreen.findPreference怎麽用?Java PreferenceScreen.findPreference使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.preference.PreferenceScreen
的用法示例。
在下文中一共展示了PreferenceScreen.findPreference方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreatePreferences
import android.support.v7.preference.PreferenceScreen; //導入方法依賴的package包/類
@Override
public void onCreatePreferences(Bundle bundle, String s)
{
super.onCreatePreferences(bundle, s);
// Get our screen which is created in Skin SettingsFragment
PreferenceScreen screen = getPreferenceScreen();
// Get profile preference
PreferenceCategory category = (PreferenceCategory) screen.findPreference(KEY_PROFILE);
// If category exists, we should add mole mapper specific things. If not, that means we
// are not consented so we have no data to set.
if(category != null)
{
// Example Preference
Preference checkBoxPref = new Preference(screen.getContext());
checkBoxPref.setKey(KEY_EXAMPLE);
checkBoxPref.setTitle("Example Title");
checkBoxPref.setSummary("You need to extend your settings fragment from Skin's " +
"Settings fragment and then modify any preferences that you'd like");
category.addPreference(checkBoxPref);
}
}
示例2: onPreferenceChange
import android.support.v7.preference.PreferenceScreen; //導入方法依賴的package包/類
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
PreferenceScreen ps = getPreferenceScreen();
Boolean newChecked = (Boolean)newValue;
if (newChecked.booleanValue() == false) {
int checkedCount = 0;
for (String k : POI_KEYS) {
if (preference.getKey().equals(k)) continue;
CheckBoxPreference cbp = (CheckBoxPreference)ps.findPreference(k);
if (cbp.isChecked()) {
checkedCount++;
}
}
if (checkedCount == 0) {
Toast.makeText(getActivity(), R.string.prompt_at_least_one_poi, Toast.LENGTH_SHORT).show();
return false;
}
}
return true;
}
示例3: onCreatePreferences
import android.support.v7.preference.PreferenceScreen; //導入方法依賴的package包/類
@Override
public void onCreatePreferences(Bundle bundle, String s) {
super.addPreferencesFromResource(R.xml.rss_settings);
// Get our screen which is created in Skin SettingsFragment
PreferenceScreen screen = getPreferenceScreen();
screen.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
profileCategory = (PreferenceCategory) screen.findPreference(KEY_PROFILE);
privacyCategory = (PreferenceCategory) screen.findPreference(KEY_PRIVACY);
sharingScope = privacyCategory.findPreference(KEY_SHARING_OPTIONS);
generalCategory = (PreferenceCategory) screen.findPreference(KEY_GENERAL);
leaveStudy = generalCategory.findPreference(KEY_LEAVE_STUDY);
joinStudy = generalCategory.findPreference(KEY_JOIN_STUDY);
// Set version string
screen.findPreference(KEY_VERSION).setSummary(getVersionString());
}
示例4: setupLibrariesPreference
import android.support.v7.preference.PreferenceScreen; //導入方法依賴的package包/類
/**
* Adds libraries to its PreferenceCategory programmatically.
*/
private void setupLibrariesPreference(PreferenceScreen preferenceScreen) {
PreferenceCategory preferenceCategory = (PreferenceCategory)
preferenceScreen.findPreference(getString(R.string.pref_key_libraries));
Context context = preferenceCategory.getContext();
for (@Size(2) String[] libraryInfos : getLibrariesInfos()) {
Preference preference = new Preference(context);
preference.setTitle(libraryInfos[0]);
preference.setPersistent(false);
// put this library's license path to extra
preference.getExtras().putString(EXTRAS_LIBRARY_OR_FILE_OPEN_SOURCE_LICENSE_FILE_PATH,
ASSET_PATH_OPEN_SOURCE_LICENSES_LIBRARY + libraryInfos[1]);
preferenceCategory.addPreference(preference);
}
}
示例5: setupFilesPreference
import android.support.v7.preference.PreferenceScreen; //導入方法依賴的package包/類
/**
* Adds files to its PreferenceCategory programmatically.
*/
private void setupFilesPreference(PreferenceScreen preferenceScreen) {
PreferenceCategory preferenceCategory = (PreferenceCategory)
preferenceScreen.findPreference(getString(R.string.pref_key_files));
Context context = preferenceCategory.getContext();
for (@Size(2) String[] fileInfos : getFilesInfo()) {
Preference preference = new Preference(context);
preference.setTitle(fileInfos[0]);
preference.setPersistent(false);
// put this file's license path to extra
preference.getExtras().putString(EXTRAS_LIBRARY_OR_FILE_OPEN_SOURCE_LICENSE_FILE_PATH,
ASSET_PATH_OPEN_SOURCE_LICENSES_FILE + fileInfos[1]);
preferenceCategory.addPreference(preference);
}
}
示例6: updateContent
import android.support.v7.preference.PreferenceScreen; //導入方法依賴的package包/類
private void updateContent() {
PreferenceScreen root = getPreferenceScreen();
if (McsService.isConnected()) {
root.findPreference(PREF_GCM_STATUS).setSummary(getString(R.string.gcm_state_connected, DateUtils.getRelativeTimeSpanString(McsService.getStartTimestamp(), System.currentTimeMillis(), 0)));
} else {
root.findPreference(PREF_GCM_STATUS).setSummary(getString(R.string.gcm_state_disconnected));
}
PreferenceCategory appList = (PreferenceCategory) root.findPreference(PREF_GCM_APPS);
appList.removeAll();
List<GcmDatabase.App> list = database.getAppList();
if (!list.isEmpty()) {
List<Preference> appListPrefs = new ArrayList<>();
PackageManager pm = getContext().getPackageManager();
for (GcmDatabase.App app : list) {
try {
pm.getApplicationInfo(app.packageName, 0);
appListPrefs.add(new GcmAppPreference(getPreferenceManager().getContext(), app));
} catch (PackageManager.NameNotFoundException e) {
final List<GcmDatabase.Registration> registrations = database.getRegistrationsByApp(app.packageName);
if (registrations.isEmpty()) {
database.removeApp(app.packageName);
} else {
appListPrefs.add(new GcmAppPreference(getPreferenceManager().getContext(), app));
}
}
}
addPreferencesSorted(appListPrefs, appList);
} else {
// If there's no item to display, add a "None" item.
Preference banner = new Preference(getPreferenceManager().getContext());
banner.setLayoutResource(R.layout.list_no_item);
banner.setTitle(R.string.list_no_item_none);
banner.setSelectable(false);
appList.addPreference(banner);
}
}
示例7: onCreatePreferences
import android.support.v7.preference.PreferenceScreen; //導入方法依賴的package包/類
@Override
public void onCreatePreferences(Bundle bundle, String s)
{
super.onCreatePreferences(bundle, s);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(
getContext());
// Get our screen which is created in Skin SettingsFragment
PreferenceScreen screen = getPreferenceScreen();
// Get profile preference
PreferenceCategory category = (PreferenceCategory) screen.findPreference(KEY_PROFILE);
// If category exists, we should add mole mapper specific things. If not, that means we
// are not consented so we have no data to set.
if(category != null)
{
// Occupation Preference
Preference checkBoxPref = new Preference(screen.getContext());
checkBoxPref.setKey(KEY_PROFILE_PROFESSION);
checkBoxPref.setTitle(R.string.profession);
checkBoxPref.setSummary(R.string.profession_unknown); // Set to prevent a "jump" when first entering the screen
category.addPreference(checkBoxPref);
}
// Create the app category to place out two rpefs
PreferenceCategory appCategory = new PreferenceCategory(screen.getContext());
appCategory.setKey(KEY_APP);
appCategory.setTitle(R.string.settings_app);
appCategory.setOrder(1);
screen.addPreference(appCategory);
// Generate values for the mole naming convention pref
MoleNameHelper.Gender[] values = MoleNameHelper.Gender.values();
String[] entries = new String[values.length];
String[] entryValues = new String[values.length];
for(int i = 0; i < values.length; i++)
{
MoleNameHelper.Gender gender = values[i];
entries[i] = getString(gender.getNameResourceId());
entryValues[i] = Integer.toString(i);
}
// Create ListPreference and add to "App" category
String defaultNamingConvention = Integer.toString(MoleNameHelper.Gender.RANDOM.ordinal());
ListPreference namingConventionPref = new ListPreference(screen.getContext());
namingConventionPref.setTitle(R.string.settings_app_mole_name_scheme);
namingConventionPref.setKey(KEY_APP_MOLE_NAMING);
namingConventionPref.setDefaultValue(defaultNamingConvention);
namingConventionPref.setEntries(entries);
namingConventionPref.setEntryValues(entryValues);
namingConventionPref.setDialogTitle(R.string.settings_app_mole_name_scheme);
String currentNamingConvInt = sharedPreferences.getString(KEY_APP_MOLE_NAMING,
defaultNamingConvention);
int currentNamingOrdinal = Integer.parseInt(currentNamingConvInt);
namingConventionPref.setSummary(values[currentNamingOrdinal].getNameResourceId());
appCategory.addPreference(namingConventionPref);
}