List of usage examples for android.preference Preference.OnPreferenceClickListener Preference.OnPreferenceClickListener
Preference.OnPreferenceClickListener
From source file:org.opendatakit.services.preferences.fragments.DeviceSettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PropertiesSingleton props = ((IOdkAppPropertiesActivity) this.getActivity()).getProps(); addPreferencesFromResource(R.xml.device_preferences); // not super safe, but we're just putting in this mode to help // administrate // would require code to access it boolean adminMode; adminMode = (this.getArguments() == null) ? false : (this.getArguments().containsKey(IntentConsts.INTENT_KEY_SETTINGS_IN_ADMIN_MODE) ? this.getArguments().getBoolean(IntentConsts.INTENT_KEY_SETTINGS_IN_ADMIN_MODE) : false);// w ww . ja v a 2 s . c om String adminPwd = props.getProperty(CommonToolProperties.KEY_ADMIN_PW); boolean adminConfigured = (adminPwd != null && adminPwd.length() != 0); PreferenceCategory deviceCategory = (PreferenceCategory) findPreference( CommonToolProperties.GROUPING_DEVICE_CATEGORY); boolean fontAvailable = !adminConfigured || props.getBooleanProperty(CommonToolProperties.KEY_CHANGE_FONT_SIZE); mFontSizePreference = (ListPreference) findPreference(CommonToolProperties.KEY_FONT_SIZE); if (props.containsKey(CommonToolProperties.KEY_FONT_SIZE)) { String chosenFontSize = props.getProperty(CommonToolProperties.KEY_FONT_SIZE); CharSequence entryValues[] = mFontSizePreference.getEntryValues(); for (int i = 0; i < entryValues.length; i++) { String entry = entryValues[i].toString(); if (entry.equals(chosenFontSize)) { mFontSizePreference.setValue(entry); mFontSizePreference.setSummary(mFontSizePreference.getEntries()[i]); } } } mFontSizePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int index = ((ListPreference) preference).findIndexOfValue(newValue.toString()); String entry = (String) ((ListPreference) preference).getEntries()[index]; preference.setSummary(entry); PropertiesSingleton props = ((IOdkAppPropertiesActivity) DeviceSettingsFragment.this.getActivity()) .getProps(); props.setProperty(CommonToolProperties.KEY_FONT_SIZE, newValue.toString()); return true; } }); mFontSizePreference.setEnabled(fontAvailable || adminMode); boolean splashAvailable = !adminConfigured || props.getBooleanProperty(CommonToolProperties.KEY_CHANGE_SPLASH_SETTINGS); mShowSplashPreference = (CheckBoxPreference) findPreference(CommonToolProperties.KEY_SHOW_SPLASH); if (props.containsKey(CommonToolProperties.KEY_SHOW_SPLASH)) { boolean checked = props.getBooleanProperty(CommonToolProperties.KEY_SHOW_SPLASH); mShowSplashPreference.setChecked(checked); } mShowSplashPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { PropertiesSingleton props = ((IOdkAppPropertiesActivity) DeviceSettingsFragment.this.getActivity()) .getProps(); props.setProperty(CommonToolProperties.KEY_SHOW_SPLASH, newValue.toString()); return true; } }); mShowSplashPreference.setEnabled(adminMode || splashAvailable); mSplashPathPreference = (PreferenceScreen) findPreference(CommonToolProperties.KEY_SPLASH_PATH); if (props.containsKey(CommonToolProperties.KEY_SPLASH_PATH)) { mSplashPathPreference.setSummary(props.getProperty(CommonToolProperties.KEY_SPLASH_PATH)); } mSplashPathPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { private void launchImageChooser() { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.setType("image/*"); DeviceSettingsFragment.this.startActivityForResult(i, AppPropertiesActivity.SPLASH_IMAGE_CHOOSER); } @Override public boolean onPreferenceClick(Preference preference) { // if you have a value, you can clear it or select new. CharSequence cs = mSplashPathPreference.getSummary(); if (cs != null && cs.toString().contains("/")) { final CharSequence[] items = { getString(R.string.select_another_image), getString(R.string.use_odk_default) }; AlertDialog.Builder builder = new AlertDialog.Builder( DeviceSettingsFragment.this.getActivity()); builder.setTitle(getString(R.string.change_splash_path)); builder.setNeutralButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (items[item].equals(getString(R.string.select_another_image))) { launchImageChooser(); } else { PropertiesSingleton props = ((IOdkAppPropertiesActivity) DeviceSettingsFragment.this .getActivity()).getProps(); String path = getString(R.string.default_splash_path); props.setProperty(CommonToolProperties.KEY_SPLASH_PATH, path); mSplashPathPreference.setSummary(path); } } }); AlertDialog alert = builder.create(); alert.show(); } else { launchImageChooser(); } return true; } }); mSplashPathPreference.setEnabled(adminMode || splashAvailable); if (!adminMode && (!fontAvailable || !splashAvailable)) { deviceCategory.setTitle(R.string.device_restrictions_apply); } }
From source file:com.readystatesoftware.ghostlog.GhostLogSettingsFragment.java
private static void setupOpenSourceInfoPreference(final Activity activity, Preference preference) { preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override//w w w . ja va 2 s. c o m public boolean onPreferenceClick(Preference preference) { FragmentManager fm = activity.getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); Fragment prev = fm.findFragmentByTag("dialog"); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); new OpenSourceLicensesDialog().show(ft, "dialog"); return true; } }); }
From source file:com.readystatesoftware.ghostlog.GhostLogSettingsFragment.java
private static void setupVersionPref(final Activity activity, Preference preference) { preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override// w ww. j av a 2 s .c om public boolean onPreferenceClick(Preference preference) { FragmentManager fm = activity.getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); Fragment prev = fm.findFragmentByTag("dialog"); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); new AboutDialog().show(ft, "dialog"); return true; } }); }