android.preference.PreferenceScreen Java Examples

The following examples show how to use android.preference.PreferenceScreen. 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: PreferenceFragment.java    From android-support-v4-preferencefragment with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (mHavePrefs) {
        bindPreferences();
    }

    mInitDone = true;

    if (savedInstanceState != null) {
        Bundle container = savedInstanceState.getBundle(PREFERENCES_TAG);
        if (container != null) {
            final PreferenceScreen preferenceScreen = getPreferenceScreen();
            if (preferenceScreen != null) {
                preferenceScreen.restoreHierarchyState(container);
            }
        }
    }
}
 
Example #2
Source File: SettingsFragment.java    From currency with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
                                     Preference preference)
{
    boolean result =
        super.onPreferenceTreeClick(preferenceScreen, preference);

    // Set home as up
    if (preference instanceof PreferenceScreen)
    {
        Dialog dialog = ((PreferenceScreen) preference).getDialog();
        ActionBar actionBar = dialog.getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(false);
    }

    return result;
}
 
Example #3
Source File: ThemeSettingsFragment.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.prefs_screen_theme);
    final PreferenceScreen screen = getPreferenceScreen();
    final Context context = getActivity();
    final Resources res = getResources();
    final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
    final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
    for (int index = 0; index < keyboardThemeIds.length; index++) {
        final KeyboardThemePreference pref = new KeyboardThemePreference(
                context, keyboardThemeNames[index], keyboardThemeIds[index]);
        screen.addPreference(pref);
        pref.setOnRadioButtonClickedListener(this);
    }
    final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
    mSelectedThemeId = keyboardTheme.mThemeId;
}
 
Example #4
Source File: Preferences.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void update_nfc_expiry_preferences(Boolean show_age) {
    try {
        ;
        final PreferenceScreen nfcScreen = (PreferenceScreen) findPreference("xdrip_plus_nfc_settings");
        final String nfc_expiry_days_string = AllPrefsFragment.this.prefs.getString("nfc_expiry_days", "14.5");

        final CheckBoxPreference nfc_show_age = (CheckBoxPreference) findPreference("nfc_show_age");
        nfc_show_age.setSummaryOff("Show the sensor expiry time based on " + nfc_expiry_days_string + " days");
        if (show_age == null) show_age = nfc_show_age.isChecked();
        if (show_age) {
            nfcScreen.removePreference(nfc_expiry_days);
        } else {
            nfc_expiry_days.setOrder(3);
            nfcScreen.addPreference(nfc_expiry_days);
        }
    } catch (NullPointerException e) {
        //
    }
}
 
Example #5
Source File: ConfigBase.java    From HeadsUp with GNU General Public License v2.0 6 votes vote down vote up
private void addPreference(@Nullable PreferenceScreen preferenceScreen,
                           @NonNull Preference preference,
                           Group group) {

    // Remove preference from preference screen
    // if needed.
    if (preferenceScreen != null) {
        if (Device.hasTargetApi(group.option.maxSdkVersion + 1)
                || !Device.hasTargetApi(group.option.minSdkVersion)) {
            removePreference(preferenceScreen, preference);
            return;
        }
    }

    mGroups.add(group);

    if (mStarted) {
        startListeningGroup(group);
    }
}
 
Example #6
Source File: ActivitySettings.java    From NetGuard with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private boolean checkPermissions(String name) {
    PreferenceScreen screen = getPreferenceScreen();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Check if permission was revoked
    if ((name == null || "disable_on_call".equals(name)) && prefs.getBoolean("disable_on_call", false))
        if (!Util.hasPhoneStatePermission(this)) {
            prefs.edit().putBoolean("disable_on_call", false).apply();
            ((TwoStatePreference) screen.findPreference("disable_on_call")).setChecked(false);

            requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_CALL);

            if (name != null)
                return false;
        }

    return true;
}
 
Example #7
Source File: SensorSettingsActivity.java    From mytracks with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle bundle) {
  super.onCreate(bundle);
  addPreferencesFromResource(R.xml.sensor_settings);

  boolean hasAntSupport = AntInterface.hasAntSupport(this);

  configSensorType(hasAntSupport);

  findPreference(getString(R.string.settings_sensor_bluetooth_pairing_key))
      .setOnPreferenceClickListener(new OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
          Intent settingsIntent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
          startActivity(settingsIntent);
          return true;
        }
      });

  if (!hasAntSupport) {
    PreferenceScreen rootPreferenceScreen = (PreferenceScreen) findPreference(
        getString(R.string.settings_sensor_root_key));
    rootPreferenceScreen.removePreference(
        findPreference(getString(R.string.settings_sensor_ant_key)));
  }
}
 
Example #8
Source File: PreferenceFragment.java    From datmusic-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (mHavePrefs) {
        bindPreferences();
    }

    mInitDone = true;

    if (savedInstanceState != null) {
        Bundle container = savedInstanceState.getBundle(PREFERENCES_TAG);
        if (container != null) {
            final PreferenceScreen preferenceScreen = getPreferenceScreen();
            if (preferenceScreen != null) {
                preferenceScreen.restoreHierarchyState(container);
            }
        }
    }
}
 
Example #9
Source File: SettingsFragment.java    From JPPF with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  try {
    super.onCreate(savedInstanceState);
    // Load the preferences screen from an XML resource
    addPreferencesFromResource(R.xml.preferences);
    String[] pickerKeys = { PreferenceUtils.TRUST_STORE_LOCATION_KEY, PreferenceUtils.KEY_STORE_LOCATION_KEY };
    for (String key: pickerKeys) {
      FilechoserEditTextPreference picker = (FilechoserEditTextPreference) findPreference(key);
      picker.setFragment(this);
    }
    PreferenceScreen pref = (PreferenceScreen) findPreference("pref_security");
    if (SUPPORTED_CIPHER_SUITES.isEmpty()) {
      SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
      ENABLED_CIPHER_SUITES.addAll(Arrays.asList(ssf.getDefaultCipherSuites()));
      SUPPORTED_CIPHER_SUITES.addAll(Arrays.asList(ssf.getSupportedCipherSuites()));
    }
    MultiSelectListPreference ciphersPref = (MultiSelectListPreference) findPreference(PreferenceUtils.ENABLED_CIPHER_SUITES_KEY);
    ciphersPref.setDefaultValue(ENABLED_CIPHER_SUITES.toArray(new String[ENABLED_CIPHER_SUITES.size()]));
    ciphersPref.setEntryValues(SUPPORTED_CIPHER_SUITES.toArray(new String[SUPPORTED_CIPHER_SUITES.size()]));
    ciphersPref.setEntries(SUPPORTED_CIPHER_SUITES.toArray(new String[SUPPORTED_CIPHER_SUITES.size()]));
  } catch(Throwable t) {
    t.printStackTrace();
  }
}
 
Example #10
Source File: SettingsActivity.java    From Equate with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Helper Class to setup the default Unit Type preference list in code
 */
private void setUpUnitTypePrefs() {
   PreferenceScreen screen = getPreferenceScreen();
   MultiSelectListPreference listPref = new MultiSelectListPreference(super.getActivity());
   listPref.setOrder(0);
   listPref.setDialogTitle(R.string.unit_select_title);
   listPref.setKey(UNIT_TYPE_PREF_KEY);
   listPref.setSummary(R.string.unit_select_summary);
   listPref.setTitle(R.string.unit_select_title);
   listPref.setEntries(getUnitTypeNameArray(getResources()));

   String[] keyArray = getUnitTypeKeyArray(getResources());
   listPref.setEntryValues(keyArray);

   final Set<String> result = new HashSet<>();
   Collections.addAll(result, keyArray);

   listPref.setDefaultValue(result);

   screen.addPreference(listPref);
}
 
Example #11
Source File: SwitchAccessPreferenceActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
private void assignTtsSettingsIntentOrRemovePref() {
  PreferenceScreen preferenceScreen =
      (PreferenceScreen)
          findPreference(R.string.pref_key_category_switch_access_speech_sound_vibration);
  Preference ttsSettingsPreference =
      findPreference(R.string.pref_key_switch_access_tts_settings);

  if (preferenceScreen == null || ttsSettingsPreference == null) {
    return;
  }

  Intent ttsSettingsIntent = new Intent(TTS_SETTINGS_INTENT);
  ttsSettingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  if (canHandleIntent(ttsSettingsIntent)) {
    ttsSettingsPreference.setIntent(ttsSettingsIntent);
  } else {
    // We should remove the preference if there is no TTS Settings intent filter in settings
    // app.
    preferenceScreen.removePreference(ttsSettingsPreference);
  }
}
 
Example #12
Source File: SettingsFragment.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    switch (preference.getKey()) {
        case PreferenceKey.ADJUST_SIZE:
        case PreferenceKey.PREF_USER:
        case PreferenceKey.PREF_BLACK_LIST:
        case "pref_keyword":
            Intent intent = new Intent(getActivity(), LauncherSubActivity.class);
            intent.putExtra("fragment", preference.getFragment());
            startActivity(intent);
            break;
        default:
            return super.onPreferenceTreeClick(preferenceScreen, preference);

    }
    return true;
}
 
Example #13
Source File: PreferenceFragmentBase.java    From HeadsUp with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (mHavePrefs) {
        bindPreferences();
    }

    mInitDone = true;

    if (savedInstanceState != null) {
        Bundle container = savedInstanceState.getBundle(PREFERENCES_TAG);
        if (container != null) {
            final PreferenceScreen preferenceScreen = getPreferenceScreen();
            if (preferenceScreen != null) {
                preferenceScreen.restoreHierarchyState(container);
            }
        }
    }
}
 
Example #14
Source File: Settings.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
@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());
        }
    }
}
 
Example #15
Source File: DevelopmentSettings.java    From haystack with GNU General Public License v3.0 6 votes vote down vote up
@DexWrap
@Override
/*<7.0*/ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
//>7.0// public boolean onPreferenceTreeClick(Preference preference) {
    if (Utils.isMonkeyRunning()) {
        return false;
    }
    if (mFakeSignatureGlobalPreference != null) {
        if (preference == mFakeSignatureGlobalPreference) {
            writeFakeSignatureGlobalSettingWithWarningDialog(mFakeSignatureGlobalPreference.isChecked());
            return false;
        }
    }
    /*<7.0*/ return onPreferenceTreeClick(preferenceScreen, preference);
    //>7.0// return onPreferenceTreeClick(preference);
}
 
Example #16
Source File: DeviceAdminSample.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Retrieve the useful instance variables
    mActivity = (DeviceAdminSample) getActivity();
    mDPM = mActivity.mDPM;
    mDeviceAdminSample = mActivity.mDeviceAdminSample;
    mAdminActive = mActivity.isActiveAdmin();

    // Configure the shared UI elements (if they exist)
    mResetPassword = (EditTextPreference) findPreference(KEY_RESET_PASSWORD);
    mSetPassword = (PreferenceScreen) findPreference(KEY_SET_PASSWORD);

    if (mResetPassword != null) {
        mResetPassword.setOnPreferenceChangeListener(this);
    }
    if (mSetPassword != null) {
        mSetPassword.setOnPreferenceClickListener(this);
    }
}
 
Example #17
Source File: SingleWebsitePreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void clearStoredData() {
    mSite.clearAllStoredData(
            new Website.StoredDataClearedCallback() {
                @Override
                public void onStoredDataCleared() {
                    PreferenceScreen preferenceScreen = getPreferenceScreen();
                    preferenceScreen.removePreference(
                            preferenceScreen.findPreference(PREF_CLEAR_DATA));
                    if (!hasUsagePreferences()) {
                        preferenceScreen.removePreference(
                                preferenceScreen.findPreference(PREF_USAGE));
                    }
                    popBackIfNoSettings();
                }
            });
}
 
Example #18
Source File: PreferencesActivity.java    From tapchat-android with Apache License 2.0 6 votes vote down vote up
@Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    String key = preference.getKey();

    if (key != null && key.equals("networks")) {
        startActivity(new Intent(this, NetworksActivity.class));
        return true;

    } else if (key != null && key.equals("logout")) {
        new AlertDialog.Builder(PreferencesActivity.this)
            .setMessage(R.string.logout_text)
            .setPositiveButton(R.string.logout, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    mServiceConnection.getService().logout();
                    startActivity(new Intent(PreferencesActivity.this, WelcomeActivity.class));
                    finish();
                }
            })
            .setNegativeButton(android.R.string.cancel, null)
            .show();
        return true;
    }
    return false;
}
 
Example #19
Source File: SubScreenFragment.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
static void updateListPreferenceSummaryToCurrentValue(final String prefKey,
        final PreferenceScreen screen) {
    // Because the "%s" summary trick of {@link ListPreference} doesn't work properly before
    // KitKat, we need to update the summary programmatically.
    final ListPreference listPreference = (ListPreference)screen.findPreference(prefKey);
    if (listPreference == null) {
        return;
    }
    final CharSequence entries[] = listPreference.getEntries();
    final int entryIndex = listPreference.findIndexOfValue(listPreference.getValue());
    listPreference.setSummary(entryIndex < 0 ? null : entries[entryIndex]);
}
 
Example #20
Source File: PreferenceFragment.java    From datmusic-android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the root of the preference hierarchy that this fragment is showing.
 *
 * @param preferenceScreen The root {@link PreferenceScreen} of the preference hierarchy.
 */
public void setPreferenceScreen(PreferenceScreen preferenceScreen) {
    if (PreferenceManagerCompat.setPreferences(mPreferenceManager, preferenceScreen) && preferenceScreen != null) {
        mHavePrefs = true;
        if (mInitDone) {
            postBindPreferences();
        }
    }
}
 
Example #21
Source File: Preferences.java    From Androzic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);
	setHasOptionsMenu(true);

	Bundle arguments = getArguments();

	if (arguments == null)
		return;

	String resource = arguments.getString("resource");
	if (resource != null)
	{
		int res = getActivity().getResources().getIdentifier(resource, "xml", getActivity().getPackageName());
		addPreferencesFromResource(res);
	}

	if (arguments.getBoolean("disable", false))
	{
		PreferenceScreen screen = getPreferenceScreen();
		for (int i = 0; i < screen.getPreferenceCount(); i++)
		{
			getPreferenceScreen().getPreference(i).setEnabled(false);
		}
	}
	
	help = arguments.getInt("help", 0);
}
 
Example #22
Source File: ResourceSettings.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sets the default values for the preference screen
 */
private void initPreferences() {

    // Binary file location
    EditTextPreference binaryFileLocation = (EditTextPreference) findPreference(Constants.PREFERENCE_STORAGE_DIRECTORY);
    if (TextUtils.isEmpty(binaryFileLocation.getText())) {
        binaryFileLocation.setText(EnvironmentUtil.getProcedureDirectory());
    }

    // Image downscale factor
    EditTextPreference imageDownscale = (EditTextPreference) findPreference(Constants.PREFERENCE_IMAGE_SCALE);
    if (TextUtils.isEmpty(imageDownscale.getText())) {
        imageDownscale.setText("" + Constants.IMAGE_SCALE_FACTOR);
    }
    imageDownscale.getEditText().setKeyListener(new DigitsKeyListener());

    // View all edu resources
    PreferenceScreen resourcePref = (PreferenceScreen) findPreference("s_education_resource");
    Intent intent = EducationResourceList.getIntent(Intent.ACTION_PICK,
            Audience.ALL);
    intent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_VIEW));
    resourcePref.setIntent(intent);

    // SD card loading procedures
    PreferenceScreen intentPref = (PreferenceScreen) findPreference("s_procedures");
    intentPref.setIntent(new Intent("org.sana.android.activity.IMPORT_PROCEDURE"));
    //intentPref.setIntent(new Intent(ResourceSettings.this, 
    //		ProcedureSdImporter.class));
}
 
Example #23
Source File: GankIoActivity.java    From stynico with MIT License 5 votes vote down vote up
@Override
   public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)
   {
SharedPreferences sp = preference.getSharedPreferences();
boolean ON_OFF = sp.getBoolean("auto_send_message", false);
boolean next_screen = sp.getBoolean("next_screen_checkbox_preference", false);
String text = sp.getString("auto_send_message_text", "");
String listtext = sp.getString("auto_send_message_frequency", "");
return true;
   }
 
Example #24
Source File: GankIoActivity.java    From stynico with MIT License 5 votes vote down vote up
@Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)
  {
SharedPreferences sp = preference.getSharedPreferences();
boolean ON_OFF = sp.getBoolean("auto_send_message", false);
boolean next_screen = sp.getBoolean("next_screen_checkbox_preference", false);
String text = sp.getString("auto_send_message_text", "");
String listtext = sp.getString("auto_send_message_frequency", "");
return true;
  }
 
Example #25
Source File: PreferenceCompatFragment.java    From Audinaut with GNU General Public License v3.0 5 votes vote down vote up
private void bindPreferences() {
    PreferenceScreen localPreferenceScreen = getPreferenceScreen();
    if (localPreferenceScreen != null) {
        ListView localListView = getListView();
        localPreferenceScreen.bind(localListView);
    }
}
 
Example #26
Source File: SettingsFragment.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setHasOptionsMenu(true);
    setInputMethodSettingsCategoryTitle(R.string.language_selection_title);
    setSubtypeEnablerTitle(R.string.select_language);
    addPreferencesFromResource(R.xml.prefs);
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    preferenceScreen.setTitle(
            ApplicationUtils.getActivityTitleResId(getActivity(), SettingsActivity.class));
    if (!ProductionFlags.ENABLE_ACCOUNT_SIGN_IN) {
        final Preference accountsPreference = findPreference(Settings.SCREEN_ACCOUNTS);
        preferenceScreen.removePreference(accountsPreference);
    }
}
 
Example #27
Source File: PreferenceFragmentBase.java    From HeadsUp with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
                                     Preference preference) {
    return preference.getFragment() != null
            && getActivity() instanceof PreferenceFragmentBase.OnPreferenceStartFragmentCallback
            && ((PreferenceFragmentBase.OnPreferenceStartFragmentCallback) getActivity())
            .onPreferenceStartFragment(this, preference);
}
 
Example #28
Source File: PreferenceFragmentCompat.java    From MaxLock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressWarnings("SimplifiableIfStatement")
@Override
public boolean onPreferenceTreeClick(final PreferenceScreen preferenceScreen, final Preference preference) {
    // if (preference.getFragment() != null &&
    if (getActivity() instanceof OnPreferenceStartFragmentCallback) {
        return ((OnPreferenceStartFragmentCallback) getActivity()).onPreferenceStartFragment(this, preference);
    }
    return false;
}
 
Example #29
Source File: PreferenceDialogFragment.java    From meatspace-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Inflates the given XML resource and adds the preference hierarchy to the current
 * preference hierarchy.
 *
 * @param preferencesResId The XML resource ID to inflate.
 */
public void addPreferencesFromResource(int preferencesResId) {
    try {
        Method m = PreferenceManager.class.getDeclaredMethod("inflateFromResource", Context.class, int.class, PreferenceScreen.class);
        m.setAccessible(true);
        PreferenceScreen prefScreen = (PreferenceScreen) m.invoke(mPreferenceManager, getActivity(), preferencesResId, getPreferenceScreen());
        setPreferenceScreen(prefScreen);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #30
Source File: SettingsMiscFragment.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    switch (preference.getKey()) {
        case Constants.PREFERENCE_ISSUE_REPORTER:
            Intent intent = new Intent(getActivity(), ReportIssueActivity.class);
            startActivity(intent);
    }
    return super.onPreferenceTreeClick(preferenceScreen, preference);
}