Example usage for android.preference PreferenceScreen removePreference

List of usage examples for android.preference PreferenceScreen removePreference

Introduction

In this page you can find the example usage for android.preference PreferenceScreen removePreference.

Prototype

public boolean removePreference(Preference preference) 

Source Link

Document

Removes a Preference from this group.

Usage

From source file:org.wordpress.android.ui.prefs.SettingsFragment.java

private void hidePostSignatureCategory() {
    PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference(
            getActivity().getString(R.string.pref_key_settings_root));
    PreferenceCategory postSignature = (PreferenceCategory) findPreference(
            getActivity().getString(R.string.pref_key_post_sig_section));
    if (preferenceScreen != null && postSignature != null) {
        preferenceScreen.removePreference(postSignature);
    }//from  w w  w . ja v a 2  s .  c  om
}

From source file:org.wordpress.android.ui.prefs.SettingsFragment.java

private void addWpComSignIn(PreferenceCategory wpComCategory, int order) {
    if (WordPress.hasDotComToken(getActivity())) {
        String username = mSettings.getString(WordPress.WPCOM_USERNAME_PREFERENCE, null);
        Preference usernamePref = new Preference(getActivity());
        usernamePref.setTitle(getString(R.string.username));
        usernamePref.setSummary(username);
        usernamePref.setSelectable(false);
        usernamePref.setOrder(order);/* ww  w .ja va 2  s  . co m*/
        wpComCategory.addPreference(usernamePref);

        Preference createWPComBlogPref = new Preference(getActivity());
        createWPComBlogPref.setTitle(getString(R.string.create_new_blog_wpcom));
        Intent intent = new Intent(getActivity(), NewBlogActivity.class);
        createWPComBlogPref.setIntent(intent);
        createWPComBlogPref.setOrder(order + 1);
        wpComCategory.addPreference(createWPComBlogPref);
    } else {
        Preference signInPref = new Preference(getActivity());
        signInPref.setTitle(getString(R.string.sign_in));
        signInPref.setOnPreferenceClickListener(signInPreferenceClickListener);
        wpComCategory.addPreference(signInPref);

        PreferenceScreen rootScreen = (PreferenceScreen) findPreference(
                getActivity().getString(R.string.pref_key_settings_root));
        PreferenceGroup notificationsGroup = (PreferenceGroup) findPreference(
                getActivity().getString(R.string.pref_key_notifications_section));
        if (notificationsGroup != null) {
            rootScreen.removePreference(notificationsGroup);
        }
    }
}

From source file:com.provision.alarmemi.paper.fragments.SetAlarmFragment.java

private void hideCategory() {
    category1 = (PreferenceCategory) findPreference("category1");
    category2 = (PreferenceCategory) findPreference("category2");
    PreferenceScreen preferenceScreen = getPreferenceScreen();
    preferenceScreen.removePreference(category1);
    preferenceScreen.removePreference(category2);
}

From source file:com.android.switchaccess.SwitchAccessPreferenceActivity.java

private void adjustHighlightingPrefs() {
    PreferenceScreen mainPrefScreen = (PreferenceScreen) findPreference(
            getString(R.string.main_pref_screen_key));
    if (isOptionScanningEnabled(this)) {
        // Configure the switch names. User-facing numbers start at 1
        int[] highlightPrefKeys = { R.string.pref_highlight_0_key, R.string.pref_highlight_1_key,
                R.string.pref_highlight_2_key, R.string.pref_highlight_3_key, R.string.pref_highlight_4_key };
        for (int i = 0; i < highlightPrefKeys.length; i++) {
            findPreference(getString(highlightPrefKeys[i]))
                    .setTitle(String.format(getString(R.string.option_scan_switch_format), i + 1));
        }/*  www.ja  v a 2 s.c  o  m*/
        mainPrefScreen.removePreference(findPreference(getString(R.string.pref_standard_highlight_key)));
    } else {
        mainPrefScreen.removePreference(findPreference(getString(R.string.pref_highlights_key)));
    }
}

From source file:org.mozilla.gecko.fxa.activities.FxAccountStatusFragment.java

/**
 * Remove all traces of debug buttons. By default, no debug buttons are shown.
 */// ww  w  .  ja va  2  s . c  om
protected void removeDebugButtons() {
    final PreferenceScreen statusScreen = (PreferenceScreen) ensureFindPreference("status_screen");
    final PreferenceCategory debugCategory = (PreferenceCategory) ensureFindPreference("debug_category");
    statusScreen.removePreference(debugCategory);
}

From source file:nl.hnogames.domoticz.Preference.Preference.java

private void setPreferences() {
    final android.preference.SwitchPreference MultiServerPreference = (android.preference.SwitchPreference) findPreference(
            "enableMultiServers");
    android.preference.Preference ServerSettings = findPreference("server_settings");
    android.preference.Preference PermissionsSettings = findPreference("permissionssettings");
    android.preference.Preference NotificationLogged = findPreference("notification_show_logs");
    android.preference.Preference fetchServerConfig = findPreference("server_force_fetch_config");
    android.preference.Preference resetApplication = findPreference("reset_settings");
    android.preference.ListPreference displayLanguage = (ListPreference) findPreference("displayLanguage");
    final android.preference.Preference registrationId = findPreference("notification_registration_id");
    android.preference.Preference GeoSettings = findPreference("geo_settings");
    android.preference.SwitchPreference WearPreference = (android.preference.SwitchPreference) findPreference(
            "enableWearItems");
    android.preference.Preference NFCPreference = findPreference("nfc_settings");
    android.preference.Preference QRCodePreference = findPreference("qrcode_settings");
    android.preference.Preference SpeechPreference = findPreference("speech_settings");
    android.preference.SwitchPreference EnableNFCPreference = (android.preference.SwitchPreference) findPreference(
            "enableNFC");
    android.preference.SwitchPreference EnableQRCodePreference = (android.preference.SwitchPreference) findPreference(
            "enableQRCode");
    android.preference.SwitchPreference EnableSpeechPreference = (android.preference.SwitchPreference) findPreference(
            "enableSpeech");
    android.preference.SwitchPreference EnableTalkBackPreference = (android.preference.SwitchPreference) findPreference(
            "talkBack");
    MultiSelectListPreference drawerItems = (MultiSelectListPreference) findPreference("enable_menu_items");
    @SuppressWarnings("SpellCheckingInspection")
    android.preference.SwitchPreference AlwaysOnPreference = (android.preference.SwitchPreference) findPreference(
            "alwayson");
    @SuppressWarnings("SpellCheckingInspection")
    android.preference.PreferenceScreen preferenceScreen = (android.preference.PreferenceScreen) findPreference(
            "settingsscreen");
    android.preference.PreferenceCategory premiumCategory = (android.preference.PreferenceCategory) findPreference(
            "premium_category");
    android.preference.Preference premiumPreference = findPreference("premium_settings");
    NotificationsMultiSelectListPreference notificationsMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference(
            "suppressNotifications");
    NotificationsMultiSelectListPreference alarmMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference(
            "alarmNotifications");
    android.preference.SwitchPreference ThemePreference = (android.preference.SwitchPreference) findPreference(
            "darkTheme");
    android.preference.Preference FingerPrintSettingsPreference = findPreference("SecuritySettings");
    android.preference.SwitchPreference FingerPrintPreference = (android.preference.SwitchPreference) findPreference(
            "enableSecurity");

    if (!BuildConfig.DEBUG) {
        PreferenceCategory oAndroidAutoCategory = (android.preference.PreferenceCategory) findPreference(
                "androidautocategory");
        PreferenceScreen oNotificationScreen = (android.preference.PreferenceScreen) findPreference(
                "notificationscreen");
        oNotificationScreen.removePreference(oAndroidAutoCategory);
    }//from www  .  jav  a  2 s  . c  om

    List<String> notifications = mSharedPrefs.getReceivedNotifications();
    if (notifications == null || notifications.size() <= 0) {
        notificationsMultiSelectListPreference.setEnabled(false);
        alarmMultiSelectListPreference.setEnabled(false);
    } else {
        notificationsMultiSelectListPreference.setEnabled(true);
        alarmMultiSelectListPreference.setEnabled(true);
    }

    PermissionsSettings
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    permissionHelper.openSettingsScreen();
                    return true;
                }
            });

    drawerItems.setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
            try {
                final HashSet selectedDrawerItems = (HashSet) newValue;
                if (selectedDrawerItems.size() < 1) {
                    showSnackbar(mContext.getString(R.string.error_atLeastOneItemInDrawer));
                    return false;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                return false;
            }
            return true;
        }
    });

    ThemePreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_theme));
                        return false;
                    } else {
                        ((SettingsActivity) getActivity()).reloadSettings();
                        return true;
                    }
                }
            });

    MultiServerPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.multi_server));
                        return false;
                    }
                    return true;
                }
            });

    ServerSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (!MultiServerPreference.isChecked()) {
                Intent intent = new Intent(mContext, ServerSettingsActivity.class);
                startActivity(intent);
            } else {
                Intent intent = new Intent(mContext, ServerListSettingsActivity.class);
                startActivity(intent);
            }
            return true;
        }
    });

    FingerPrintSettingsPreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    mContext.startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
                    return true;
                }
            });

    fetchServerConfig
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    UsefulBits.getServerConfigForActiveServer(mContext, true, new ConfigReceiver() {
                        @Override
                        public void onReceiveConfig(ConfigInfo settings) {
                            showSnackbar(mContext.getString(R.string.fetched_server_config_success));
                        }

                        @Override
                        public void onError(Exception error) {
                            showSnackbar(mContext.getString(R.string.fetched_server_config_failed));
                        }
                    }, null);
                    return true;
                }
            });

    displayLanguage
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    showRestartMessage();
                    return true;
                }
            });

    registrationId.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (!PermissionsUtil.canAccessDeviceState(mContext)) {
                    permissionHelper.request(PermissionsUtil.INITIAL_DEVICE_PERMS);
                } else {
                    pushGCMRegistrationIds();
                }
            } else {
                pushGCMRegistrationIds();
            }
            return true;
        }
    });

    GeoSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                showPremiumSnackbar(getString(R.string.geofence));
                return false;
            } else {
                Intent intent = new Intent(mContext, GeoSettingsActivity.class);
                startActivity(intent);
                return true;
            }
        }
    });

    EnableNFCPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_nfc));
                        return false;
                    }

                    if (NfcAdapter.getDefaultAdapter(mContext) == null) {
                        showSnackbar(mContext.getString(R.string.nfc_not_supported));
                        return false;
                    }
                    return true;
                }
            });

    EnableQRCodePreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_QRCode));
                        return false;
                    }

                    return true;
                }
            });

    EnableSpeechPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_Speech));
                        return false;
                    }
                    return true;
                }
            });

    EnableTalkBackPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_talk_back));
                        return false;
                    }
                    return true;
                }
            });

    NFCPreference.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                showPremiumSnackbar(getString(R.string.category_nfc));
                return false;
            } else {
                Intent intent = new Intent(mContext, NFCSettingsActivity.class);
                startActivity(intent);
                return true;
            }
        }
    });

    QRCodePreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_QRCode));
                        return false;
                    } else {
                        Intent intent = new Intent(mContext, QRCodeSettingsActivity.class);
                        startActivity(intent);
                        return true;
                    }
                }
            });

    SpeechPreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_Speech));
                        return false;
                    } else {
                        Intent intent = new Intent(mContext, SpeechSettingsActivity.class);
                        startActivity(intent);
                        return true;
                    }
                }
            });

    WearPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_wear));
                        return false;
                    }
                    return true;
                }
            });

    AlwaysOnPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.always_on_title));
                        return false;
                    }
                    return true;
                }
            });

    NotificationLogged
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    //show dialog
                    List<String> logs = mSharedPrefs.getLoggedNotifications();
                    if (logs != null && logs.size() > 0) {
                        Collections.reverse(logs);
                        new MaterialDialog.Builder(mContext)
                                .title(mContext.getString(R.string.notification_show_title))
                                .items((CharSequence[]) logs.toArray(new String[0])).show();
                    } else
                        UsefulBits.showSimpleToast(mContext, getString(R.string.notification_show_nothing),
                                Toast.LENGTH_LONG);
                    return true;
                }
            });

    //noinspection PointlessBooleanExpression
    if (!BuildConfig.LITE_VERSION) {
        preferenceScreen.removePreference(premiumCategory);
    } else {
        premiumPreference
                .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(android.preference.Preference preference) {
                        String packageID = mContext.getPackageName() + ".premium";
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("market://details?id=" + packageID)));
                        } catch (android.content.ActivityNotFoundException ignored) {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("https://play.google.com/store/apps/details?id=" + packageID)));
                        }

                        return true;
                    }
                });
    }

    resetApplication
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        new MaterialDialog.Builder(mContext).title(R.string.category_Reset)
                                .content(R.string.are_you_sure).positiveText(R.string.ok)
                                .negativeText(R.string.cancel)
                                .onPositive(new MaterialDialog.SingleButtonCallback() {
                                    @SuppressLint("NewApi")
                                    @Override
                                    public void onClick(@NonNull MaterialDialog dialog,
                                            @NonNull DialogAction which) {
                                        ((ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE))
                                                .clearApplicationUserData();
                                    }
                                }).show();
                    } else {
                        startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
                    }
                    return true;
                }
            });

    FingerPrintPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @SuppressLint("NewApi")
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object o) {
                    if (mSharedPrefs.isStartupSecurityEnabled())
                        return true;
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_startup_security));
                        return false;
                    } else {
                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                            UsefulBits.showSimpleToast(mContext, getString(R.string.fingerprint_not_supported),
                                    Toast.LENGTH_LONG);
                            return false;
                        }
                        if (!PermissionsUtil.canAccessFingerprint(mContext)) {
                            permissionHelper.request(PermissionsUtil.INITIAL_FINGERPRINT_PERMS);
                        } else {
                            FingerprintManager fingerprintManager = (FingerprintManager) mContext
                                    .getSystemService(Context.FINGERPRINT_SERVICE);
                            if (ActivityCompat.checkSelfPermission(mContext,
                                    Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
                                return false;
                            }
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                if (!fingerprintManager.isHardwareDetected()) {
                                    return false;
                                } else if (!fingerprintManager.hasEnrolledFingerprints()) {
                                    UsefulBits.showSimpleToast(mContext,
                                            getString(R.string.fingerprint_not_setup_in_android),
                                            Toast.LENGTH_LONG);
                                    return false;
                                } else {
                                    new MaterialDialog.Builder(mContext)
                                            .title(R.string.category_startup_security)
                                            .content(R.string.fingerprint_sure).positiveText(R.string.ok)
                                            .negativeText(R.string.cancel)
                                            .onPositive(new MaterialDialog.SingleButtonCallback() {
                                                @Override
                                                public void onClick(@NonNull MaterialDialog dialog,
                                                        @NonNull DialogAction which) {
                                                    mSharedPrefs.setStartupSecurityEnabled(true);
                                                    ((SettingsActivity) getActivity()).reloadSettings();
                                                }
                                            }).show();

                                    return false;
                                }
                            }
                        }
                    }
                    return false;
                }
            });
}

From source file:be.ppareit.swiftp.gui.PreferenceFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    Resources resources = getResources();

    TwoStatePreference runningPref = findPref("running_switch");
    updateRunningState();/*from  www.j  a  va2 s . com*/
    runningPref.setOnPreferenceChangeListener((preference, newValue) -> {
        if ((Boolean) newValue) {
            startServer();
        } else {
            stopServer();
        }
        return true;
    });

    PreferenceScreen prefScreen = findPref("preference_screen");
    Preference marketVersionPref = findPref("market_version");
    marketVersionPref.setOnPreferenceClickListener(preference -> {
        // start the market at our application
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse("market://details?id=be.ppareit.swiftp"));
        try {
            // this can fail if there is no market installed
            startActivity(intent);
        } catch (Exception e) {
            Cat.e("Failed to launch the market.");
            e.printStackTrace();
        }
        return false;
    });
    if (!App.isFreeVersion()) {
        prefScreen.removePreference(marketVersionPref);
    }

    updateLoginInfo();

    EditTextPreference usernamePref = findPref("username");
    usernamePref.setOnPreferenceChangeListener((preference, newValue) -> {
        String newUsername = (String) newValue;
        if (preference.getSummary().equals(newUsername))
            return false;
        if (!newUsername.matches("[a-zA-Z0-9]+")) {
            Toast.makeText(getActivity(), R.string.username_validation_error, Toast.LENGTH_LONG).show();
            return false;
        }
        stopServer();
        return true;
    });

    mPassWordPref = findPref("password");
    mPassWordPref.setOnPreferenceChangeListener((preference, newValue) -> {
        stopServer();
        return true;
    });
    mAutoconnectListPref = findPref("autoconnect_preference");
    mAutoconnectListPref.setOnPopulateListener(pref -> {
        Cat.d("autoconnect populate listener");

        WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext()
                .getSystemService(Context.WIFI_SERVICE);
        List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks();
        if (configs == null) {
            Cat.e("Unable to receive wifi configurations, bark at user and bail");
            Toast.makeText(getActivity(), R.string.autoconnect_error_enable_wifi_for_access_points,
                    Toast.LENGTH_LONG).show();
            return;
        }
        CharSequence[] ssids = new CharSequence[configs.size()];
        CharSequence[] niceSsids = new CharSequence[configs.size()];
        for (int i = 0; i < configs.size(); ++i) {
            ssids[i] = configs.get(i).SSID;
            String ssid = configs.get(i).SSID;
            if (ssid.length() > 2 && ssid.startsWith("\"") && ssid.endsWith("\"")) {
                ssid = ssid.substring(1, ssid.length() - 1);
            }
            niceSsids[i] = ssid;
        }
        pref.setEntries(niceSsids);
        pref.setEntryValues(ssids);
    });
    mAutoconnectListPref.setOnPreferenceClickListener(preference -> {
        Cat.d("Clicked");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ActivityCompat.checkSelfPermission(getContext(),
                    Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) {
                if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                        Manifest.permission.ACCESS_COARSE_LOCATION)) {
                    new AlertDialog.Builder(getContext()).setTitle(R.string.request_coarse_location_dlg_title)
                            .setMessage(R.string.request_coarse_location_dlg_message)
                            .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                                requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
                                        ACCESS_COARSE_LOCATION_REQUEST_CODE);
                            }).setOnCancelListener(dialog -> {
                                mAutoconnectListPref.getDialog().cancel();
                            }).create().show();
                } else {
                    requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
                            ACCESS_COARSE_LOCATION_REQUEST_CODE);
                }
            }
        }
        return false;
    });

    EditTextPreference portnum_pref = findPref("portNum");
    portnum_pref.setSummary(sp.getString("portNum", resources.getString(R.string.portnumber_default)));
    portnum_pref.setOnPreferenceChangeListener((preference, newValue) -> {
        String newPortnumString = (String) newValue;
        if (preference.getSummary().equals(newPortnumString))
            return false;
        int portnum = 0;
        try {
            portnum = Integer.parseInt(newPortnumString);
        } catch (Exception e) {
            Cat.d("Error parsing port number! Moving on...");
        }
        if (portnum <= 0 || 65535 < portnum) {
            Toast.makeText(getActivity(), R.string.port_validation_error, Toast.LENGTH_LONG).show();
            return false;
        }
        preference.setSummary(newPortnumString);
        stopServer();
        return true;
    });

    Preference chroot_pref = findPref("chrootDir");
    chroot_pref.setSummary(FsSettings.getChrootDirAsString());
    chroot_pref.setOnPreferenceClickListener(preference -> {
        AlertDialog folderPicker = new FolderPickerDialogBuilder(getActivity(), FsSettings.getChrootDir())
                .setSelectedButton(R.string.select, path -> {
                    if (preference.getSummary().equals(path))
                        return;
                    if (!FsSettings.setChrootDir(path))
                        return;
                    // TODO: this is a hotfix, create correct resources, improve UI/UX
                    final File root = new File(path);
                    if (!root.canRead()) {
                        Toast.makeText(getActivity(), "Notice that we can't read/write in this folder.",
                                Toast.LENGTH_LONG).show();
                    } else if (!root.canWrite()) {
                        Toast.makeText(getActivity(),
                                "Notice that we can't write in this folder, reading will work. Writing in sub folders might work.",
                                Toast.LENGTH_LONG).show();
                    }

                    preference.setSummary(path);
                    stopServer();
                }).setNegativeButton(R.string.cancel, null).create();
        folderPicker.show();
        return true;
    });

    final CheckBoxPreference wakelock_pref = findPref("stayAwake");
    wakelock_pref.setOnPreferenceChangeListener((preference, newValue) -> {
        stopServer();
        return true;
    });

    final CheckBoxPreference writeExternalStorage_pref = findPref("writeExternalStorage");
    String externalStorageUri = FsSettings.getExternalStorageUri();
    if (externalStorageUri == null) {
        writeExternalStorage_pref.setChecked(false);
    }
    writeExternalStorage_pref.setOnPreferenceChangeListener((preference, newValue) -> {
        if ((boolean) newValue) {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
            startActivityForResult(intent, ACTION_OPEN_DOCUMENT_TREE);
            return false;
        } else {
            FsSettings.setExternalStorageUri(null);
            return true;
        }
    });

    ListPreference theme = findPref("theme");
    theme.setSummary(theme.getEntry());
    theme.setOnPreferenceChangeListener((preference, newValue) -> {
        theme.setSummary(theme.getEntry());
        getActivity().recreate();
        return true;
    });

    Preference help = findPref("help");
    help.setOnPreferenceClickListener(preference -> {
        Cat.v("On preference help clicked");
        Context context = getActivity();
        AlertDialog ad = new AlertDialog.Builder(context).setTitle(R.string.help_dlg_title)
                .setMessage(R.string.help_dlg_message).setPositiveButton(android.R.string.ok, null).create();
        ad.show();
        Linkify.addLinks((TextView) ad.findViewById(android.R.id.message), Linkify.ALL);
        return true;
    });

    Preference about = findPref("about");
    about.setOnPreferenceClickListener(preference -> {
        startActivity(new Intent(getActivity(), AboutActivity.class));
        return true;
    });

}

From source file:com.owncloud.android.ui.activity.Preferences.java

@SuppressWarnings("deprecation")
@Override/*w w  w  .j a v  a 2 s .  c  o m*/
public void onCreate(Bundle savedInstanceState) {

    if (ThemeUtils.themingEnabled()) {
        setTheme(R.style.FallbackThemingTheme);
    }

    getDelegate().installViewFactory();
    getDelegate().onCreate(savedInstanceState);
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    ActionBar actionBar = getDelegate().getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    ThemeUtils.setColoredTitle(actionBar, getString(R.string.actionbar_settings));
    actionBar.setBackgroundDrawable(new ColorDrawable(ThemeUtils.primaryColor()));
    getWindow().getDecorView().setBackgroundDrawable(
            new ColorDrawable(ResourcesCompat.getColor(getResources(), R.color.background_color, null)));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(ThemeUtils.primaryDarkColor());
    }

    Drawable backArrow = getResources().getDrawable(R.drawable.ic_arrow_back);
    actionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow, ThemeUtils.fontColor()));

    int accentColor = ThemeUtils.primaryAccentColor();

    // retrieve user's base uri
    setupBaseUri();

    // For adding content description tag to a title field in the action bar
    int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
    View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
    if (actionBarTitleView != null) { // it's null in Android 2.x
        getWindow().getDecorView().findViewById(actionBarTitleId)
                .setContentDescription(getString(R.string.actionbar_settings));
    }
    // Load package info
    String temp;
    try {
        PackageInfo pkg = getPackageManager().getPackageInfo(getPackageName(), 0);
        temp = pkg.versionName;
    } catch (NameNotFoundException e) {
        temp = "";
        Log_OC.e(TAG, "Error while showing about dialog", e);
    }
    final String appVersion = temp;

    // Register context menu for list of preferences.
    registerForContextMenu(getListView());

    // General
    PreferenceCategory preferenceCategoryGeneral = (PreferenceCategory) findPreference("general");
    preferenceCategoryGeneral
            .setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_general), accentColor));

    // Synced folders
    PreferenceCategory preferenceCategorySyncedFolders = (PreferenceCategory) findPreference(
            "synced_folders_category");
    preferenceCategorySyncedFolders
            .setTitle(ThemeUtils.getColoredTitle(getString(R.string.drawer_synced_folders), accentColor));
    PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference("preference_screen");

    if (!getResources().getBoolean(R.bool.syncedFolder_light)) {
        preferenceScreen.removePreference(preferenceCategorySyncedFolders);
    } else {
        // Upload on WiFi
        final ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
        final Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());

        final SwitchPreference pUploadOnWifiCheckbox = (SwitchPreference) findPreference(
                "synced_folder_on_wifi");
        pUploadOnWifiCheckbox
                .setChecked(arbitraryDataProvider.getBooleanValue(account, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI));

        pUploadOnWifiCheckbox.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                arbitraryDataProvider.storeOrUpdateKeyValue(account.name, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI,
                        String.valueOf(pUploadOnWifiCheckbox.isChecked()));

                return true;
            }
        });

        Preference pSyncedFolder = findPreference("synced_folders_configure_folders");
        if (pSyncedFolder != null) {
            if (getResources().getBoolean(R.bool.syncedFolder_light)
                    && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                pSyncedFolder.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Intent syncedFoldersIntent = new Intent(getApplicationContext(),
                                SyncedFoldersActivity.class);
                        syncedFoldersIntent.putExtra(SyncedFoldersActivity.EXTRA_SHOW_SIDEBAR, false);
                        startActivity(syncedFoldersIntent);
                        return true;
                    }
                });
            } else {
                preferenceCategorySyncedFolders.removePreference(pSyncedFolder);
            }
        }
    }

    PreferenceCategory preferenceCategoryDetails = (PreferenceCategory) findPreference("details");
    preferenceCategoryDetails
            .setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_details), accentColor));

    boolean fPassCodeEnabled = getResources().getBoolean(R.bool.passcode_enabled);
    pCode = (SwitchPreference) findPreference(PassCodeActivity.PREFERENCE_SET_PASSCODE);
    if (pCode != null && fPassCodeEnabled) {
        pCode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                Intent i = new Intent(getApplicationContext(), PassCodeActivity.class);
                Boolean incoming = (Boolean) newValue;

                i.setAction(incoming ? PassCodeActivity.ACTION_REQUEST_WITH_RESULT
                        : PassCodeActivity.ACTION_CHECK_WITH_RESULT);

                startActivityForResult(i, incoming ? ACTION_REQUEST_PASSCODE : ACTION_CONFIRM_PASSCODE);

                // Don't update just yet, we will decide on it in onActivityResult
                return false;
            }
        });
    } else {
        preferenceCategoryDetails.removePreference(pCode);
    }

    boolean fPrintEnabled = getResources().getBoolean(R.bool.fingerprint_enabled);
    fPrint = (SwitchPreference) findPreference(PREFERENCE_USE_FINGERPRINT);
    if (fPrint != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (FingerprintActivity.isFingerprintCapable(MainApp.getAppContext()) && fPrintEnabled) {
                fPrint.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        Boolean incoming = (Boolean) newValue;

                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            if (FingerprintActivity.isFingerprintReady(MainApp.getAppContext())) {
                                SharedPreferences appPrefs = PreferenceManager
                                        .getDefaultSharedPreferences(getApplicationContext());
                                SharedPreferences.Editor editor = appPrefs.edit();
                                editor.putBoolean("use_fingerprint", incoming);
                                editor.apply();
                                return true;
                            } else {
                                if (incoming) {
                                    Toast.makeText(MainApp.getAppContext(), R.string.prefs_fingerprint_notsetup,
                                            Toast.LENGTH_LONG).show();
                                    fPrint.setChecked(false);
                                }
                                SharedPreferences appPrefs = PreferenceManager
                                        .getDefaultSharedPreferences(getApplicationContext());
                                SharedPreferences.Editor editor = appPrefs.edit();
                                editor.putBoolean("use_fingerprint", false);
                                editor.apply();
                                return false;
                            }
                        } else {
                            return false;
                        }
                    }
                });
                if (!FingerprintActivity.isFingerprintReady(MainApp.getAppContext())) {
                    fPrint.setChecked(false);
                }

            } else {
                preferenceCategoryDetails.removePreference(fPrint);
            }
        } else {
            preferenceCategoryDetails.removePreference(fPrint);
        }
    }

    boolean fShowHiddenFilesEnabled = getResources().getBoolean(R.bool.show_hidden_files_enabled);
    mShowHiddenFiles = (SwitchPreference) findPreference("show_hidden_files");

    if (fShowHiddenFilesEnabled) {
        mShowHiddenFiles.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                SharedPreferences appPrefs = PreferenceManager
                        .getDefaultSharedPreferences(getApplicationContext());
                SharedPreferences.Editor editor = appPrefs.edit();
                editor.putBoolean("show_hidden_files_pref", mShowHiddenFiles.isChecked());
                editor.apply();
                return true;
            }
        });
    } else {
        preferenceCategoryDetails.removePreference(mShowHiddenFiles);
    }

    mExpertMode = (SwitchPreference) findPreference(EXPERT_MODE);

    if (getResources().getBoolean(R.bool.syncedFolder_light)) {
        preferenceCategoryDetails.removePreference(mExpertMode);
    } else {
        mExpertMode = (SwitchPreference) findPreference(EXPERT_MODE);
        mExpertMode.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                SharedPreferences appPrefs = PreferenceManager
                        .getDefaultSharedPreferences(getApplicationContext());
                SharedPreferences.Editor editor = appPrefs.edit();
                editor.putBoolean(EXPERT_MODE, mExpertMode.isChecked());
                editor.apply();

                if (mExpertMode.isChecked()) {
                    Log_OC.startLogging(getApplicationContext());
                } else {
                    if (!BuildConfig.DEBUG
                            && !getApplicationContext().getResources().getBoolean(R.bool.logger_enabled)) {
                        Log_OC.stopLogging();
                    }
                }

                return true;
            }
        });
    }

    PreferenceCategory preferenceCategoryMore = (PreferenceCategory) findPreference("more");
    preferenceCategoryMore
            .setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_more), accentColor));

    boolean calendarContactsEnabled = getResources().getBoolean(R.bool.davdroid_integration_enabled);
    Preference pCalendarContacts = findPreference("calendar_contacts");
    if (pCalendarContacts != null) {
        if (calendarContactsEnabled) {
            pCalendarContacts.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    try {
                        launchDavDroidLogin();
                    } catch (Throwable t) {
                        Log_OC.e(TAG, "Base Uri for account could not be resolved to call DAVdroid!", t);
                        Toast.makeText(MainApp.getAppContext(),
                                R.string.prefs_calendar_contacts_address_resolve_error, Toast.LENGTH_SHORT)
                                .show();
                    }
                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pCalendarContacts);
        }
    }

    boolean contactsBackupEnabled = !getResources().getBoolean(R.bool.show_drawer_contacts_backup)
            && getResources().getBoolean(R.bool.contacts_backup);
    Preference pContactsBackup = findPreference("contacts");
    if (pCalendarContacts != null) {
        if (contactsBackupEnabled) {
            pContactsBackup.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Intent contactsIntent = new Intent(getApplicationContext(),
                            ContactsPreferenceActivity.class);
                    contactsIntent.putExtra(ContactsPreferenceActivity.EXTRA_SHOW_SIDEBAR, false);
                    startActivity(contactsIntent);
                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pContactsBackup);
        }
    }

    if (!fShowHiddenFilesEnabled && !fPrintEnabled && !fPassCodeEnabled) {
        preferenceScreen.removePreference(preferenceCategoryDetails);
    }

    boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
    Preference pHelp = findPreference("help");
    if (pHelp != null) {
        if (helpEnabled) {
            pHelp.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String helpWeb = getString(R.string.url_help);
                    if (helpWeb != null && helpWeb.length() > 0) {
                        Uri uriUrl = Uri.parse(helpWeb);
                        Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
                        startActivity(intent);
                    }
                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pHelp);
        }
    }

    boolean recommendEnabled = getResources().getBoolean(R.bool.recommend_enabled);
    Preference pRecommend = findPreference("recommend");
    if (pRecommend != null) {
        if (recommendEnabled) {
            pRecommend.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {

                    Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("text/plain");
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                    String appName = getString(R.string.app_name);
                    String downloadUrlGooglePlayStore = getString(R.string.url_app_download);
                    String downloadUrlFDroid = getString(R.string.fdroid_link);
                    String downloadUrls = String.format(getString(R.string.recommend_urls),
                            downloadUrlGooglePlayStore, downloadUrlFDroid);

                    String recommendSubject = String.format(getString(R.string.recommend_subject), appName);
                    String recommendText = String.format(getString(R.string.recommend_text), appName,
                            downloadUrls);

                    intent.putExtra(Intent.EXTRA_SUBJECT, recommendSubject);
                    intent.putExtra(Intent.EXTRA_TEXT, recommendText);
                    startActivity(intent);

                    return true;

                }
            });
        } else {
            preferenceCategoryMore.removePreference(pRecommend);
        }
    }

    boolean feedbackEnabled = getResources().getBoolean(R.bool.feedback_enabled);
    Preference pFeedback = findPreference("feedback");
    if (pFeedback != null) {
        if (feedbackEnabled) {
            pFeedback.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String feedbackMail = getString(R.string.mail_feedback);
                    String feedback = getText(R.string.prefs_feedback) + " - android v" + appVersion;
                    Intent intent = new Intent(Intent.ACTION_SENDTO);
                    intent.setType("text/plain");
                    intent.putExtra(Intent.EXTRA_SUBJECT, feedback);

                    intent.setData(Uri.parse(feedbackMail));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);

                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pFeedback);
        }
    }

    SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    boolean loggerEnabled = getResources().getBoolean(R.bool.logger_enabled) || BuildConfig.DEBUG
            || appPrefs.getBoolean(EXPERT_MODE, false);
    Preference pLogger = findPreference("logger");
    if (pLogger != null) {
        if (loggerEnabled) {
            pLogger.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Intent loggerIntent = new Intent(getApplicationContext(), LogHistoryActivity.class);
                    startActivity(loggerIntent);

                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pLogger);
        }
    }

    boolean imprintEnabled = getResources().getBoolean(R.bool.imprint_enabled);
    Preference pImprint = findPreference("imprint");
    if (pImprint != null) {
        if (imprintEnabled) {
            pImprint.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String imprintWeb = getString(R.string.url_imprint);
                    if (imprintWeb != null && imprintWeb.length() > 0) {
                        Uri uriUrl = Uri.parse(imprintWeb);
                        Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
                        startActivity(intent);
                    }
                    //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pImprint);
        }
    }

    mPrefStoragePath = (ListPreference) findPreference(PreferenceKeys.STORAGE_PATH);
    if (mPrefStoragePath != null) {
        StoragePoint[] storageOptions = DataStorageProvider.getInstance().getAvailableStoragePoints();
        String[] entries = new String[storageOptions.length];
        String[] values = new String[storageOptions.length];
        for (int i = 0; i < storageOptions.length; ++i) {
            entries[i] = storageOptions[i].getDescription();
            values[i] = storageOptions[i].getPath();
        }
        mPrefStoragePath.setEntries(entries);
        mPrefStoragePath.setEntryValues(values);

        mPrefStoragePath.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                String newPath = (String) newValue;
                if (mStoragePath.equals(newPath)) {
                    return true;
                }

                StorageMigration storageMigration = new StorageMigration(Preferences.this, mStoragePath,
                        newPath);

                storageMigration.setStorageMigrationProgressListener(Preferences.this);

                storageMigration.migrate();

                return false;
            }
        });
    }

    // About category
    PreferenceCategory preferenceCategoryAbout = (PreferenceCategory) findPreference("about");
    preferenceCategoryAbout
            .setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_about), accentColor));

    /* About App */
    pAboutApp = findPreference("about_app");
    if (pAboutApp != null) {
        pAboutApp.setTitle(String.format(getString(R.string.about_android), getString(R.string.app_name)));
        pAboutApp.setSummary(String.format(getString(R.string.about_version), appVersion));
    }

    // source code
    boolean sourcecodeEnabled = getResources().getBoolean(R.bool.sourcecode_enabled);
    Preference sourcecodePreference = findPreference("sourcecode");
    if (sourcecodePreference != null) {
        String sourcecodeUrl = getString(R.string.sourcecode_url);

        if (sourcecodeEnabled && !sourcecodeUrl.isEmpty()) {
            sourcecodePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Uri uriUrl = Uri.parse(sourcecodeUrl);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
                    startActivity(intent);
                    return true;
                }
            });
        } else {
            preferenceCategoryAbout.removePreference(sourcecodePreference);
        }
    }

    // license
    boolean licenseEnabled = getResources().getBoolean(R.bool.license_enabled);
    Preference licensePreference = findPreference("license");
    if (licensePreference != null) {
        String licenseUrl = getString(R.string.license_url);

        if (licenseEnabled && !licenseUrl.isEmpty()) {
            licensePreference.setSummary(R.string.prefs_gpl_v2);
            licensePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Uri uriUrl = Uri.parse(licenseUrl);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
                    startActivity(intent);
                    return true;
                }
            });
        } else {
            preferenceCategoryAbout.removePreference(licensePreference);
        }
    }

    // privacy
    boolean privacyEnabled = getResources().getBoolean(R.bool.privacy_enabled);
    Preference privacyPreference = findPreference("privacy");
    if (privacyPreference != null) {
        if (privacyEnabled) {
            privacyPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String privacyUrl = getString(R.string.privacy_url);
                    if (privacyUrl.length() > 0) {
                        Intent externalWebViewIntent = new Intent(getApplicationContext(),
                                ExternalSiteWebView.class);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE,
                                getResources().getString(R.string.privacy));
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, privacyUrl);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, -1);
                        startActivity(externalWebViewIntent);
                    }
                    return true;
                }
            });
        } else {
            preferenceCategoryAbout.removePreference(privacyPreference);
        }
    }

    loadExternalSettingLinks(preferenceCategoryMore);

    loadStoragePath();
}

From source file:com.almalence.opencam.PluginManager.java

@Override
public void loadHeaderContent(String settings, PreferenceFragment pf) {
    List<Plugin> activePlugins = new ArrayList<Plugin>();
    List<Plugin> inactivePlugins = new ArrayList<Plugin>();

    boolean hasInactive = false;

    loadStandardSettingsBefore(pf, settings);
    if ("general_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_general_more);
        ApplicationScreen.instance.onAdvancePreferenceCreate(pf);
    } else if ("general_image_size".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_general_image_size);
        if (CameraController.isUseCamera2()) {
            Preference pref;//from  w ww  .j a v  a2s.  c  o  m
            if (null != (pref = pf.findPreference(ApplicationScreen.sImageSizeMultishotBackPref))
                    || null != (pref = pf.findPreference(ApplicationScreen.sImageSizeMultishotFrontPref))) {
                pref.setTitle(ApplicationScreen.getAppResources()
                        .getString(R.string.Pref_Comon_SmartMultishot_And_Super_ImageSize_Title));
            }
        }
        ApplicationScreen.instance.onPreferenceCreate(pf);
    } else if ("vf_settings".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_vf_common);
    } else if ("vf_more".equals(settings)) {
        for (int i = 0; i < listVF.size(); i++) {
            Plugin pg = listVF.get(i);
            if (activeVF.contains(pg.getID()))
                activePlugins.add(pg);
            else
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, activePlugins, false);

        pf.addPreferencesFromResource(R.xml.preferences_vf_more);

        if (activePlugins.size() != listVF.size() && isPreferenecesAvailable(inactivePlugins, false))
            pf.addPreferencesFromResource(R.xml.preferences_vf_inactive);

        ApplicationScreen.instance.onAdvancePreferenceCreate(pf); //Some vf advance preferences may be related to entire application instead of some special vf plugin
    } else if ("vf_inactive_settings".equals(settings)) {
        for (int i = 0; i < listVF.size(); i++) {
            Plugin pg = listVF.get(i);
            if (!activeVF.contains(pg.getID()))
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, inactivePlugins, false);
    } else if ("save_configuration".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_general_saveconfiguration);
    } else if ("export_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_export_common);
    } else if ("export_timestamp".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_export_timestamp);
    } else if ("shooting_settings".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_modes);
    } else if ("capture_expobracketing_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_capture_expobracketing_more);
    } else if ("processing_expobracketing_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_processing_hdr_more);
    } else if ("capture_night_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_capture_night_more);
    } else if ("processing_night_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_processing_night_more);
        if (CameraController.isUseCamera2()) {
            PreferenceScreen prefScr;
            if (null != (prefScr = (PreferenceScreen) pf.findPreference("nightProcessingMoreScreen"))) {
                Preference pref;
                if (null != (pref = pf.findPreference("keepcolorsPref"))) {
                    prefScr.removePreference(pref);
                }
            }
        }
    } else if ("capture_preshot_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_capture_preshot_more);
    } else if ("capture_panorama_more".equals(settings)) {
        pf.addPreferencesFromResource(R.xml.preferences_capture_panoramaaugmented_more);
        Plugin panoramaPlugin = pluginList.get(activeCapture);
        panoramaPlugin.onPreferenceCreate(pf);
    } else if ("dro".equals(settings)) {
        AddModeSettings("single", pf);
    } else if ("burst".equals(settings)) {
        AddModeSettings("burstmode", pf);
    } else if ("expobracketing".equals(settings)) {
        AddModeSettings("expobracketing", pf);
    } else if ("hdr".equals(settings)) {
        AddModeSettings("hdrmode", pf);
    } else if ("night".equals(settings)) {
        AddModeSettings("nightmode", pf);
    } else if ("super".equals(settings)) {
        AddModeSettings("super", pf);
    } else if ("video".equals(settings)) {
        AddModeSettings("video", pf);
    } else if ("preshot".equals(settings)) {
        AddModeSettings("pixfix", pf);
    } else if ("multishot".equals(settings)) {
        AddModeSettings("multishot", pf);
    } else if ("panorama_augmented".equals(settings)) {
        AddModeSettings("panorama_augmented", pf);
    } else if ("bestshotmode".equals(settings)) {
        AddModeSettings("bestshotmode", pf);
    } else if ("saving_settings".equals(settings)) {
        // for (int i = 0; i < listFilter.size(); i++)
        // {
        // Plugin pg = listFilter.get(i);
        // if (activeFilter.contains(pg.getID()))
        // activePlugins.add(pg);
        // else
        // inactivePlugins.add(pg);
        // }
        // if (activePlugins.size() != listFilter.size() &&
        // isPreferenecesAvailable(inactivePlugins, false))
        // hasInactive = true;
        addHeadersContent(pf, activePlugins, false);

        activePlugins.clear();
        inactivePlugins.clear();
        for (int i = 0; i < listExport.size(); i++) {
            Plugin pg = listExport.get(i);
            if (activeExport.contains(pg.getID()))
                activePlugins.add(pg);
            else
                inactivePlugins.add(pg);
        }
        if (activePlugins.size() != listExport.size() && isPreferenecesAvailable(inactivePlugins, false))
            hasInactive = true;
        addHeadersContent(pf, activePlugins, false);

        if (hasInactive)
            pf.addPreferencesFromResource(R.xml.preferences_saving_inactive);
    } else if ("saving_inactive_settings".equals(settings)) {
        // for (int i = 0; i < listFilter.size(); i++)
        // {
        // Plugin pg = listFilter.get(i);
        // if (!activeFilter.contains(pg.getID()))
        // inactivePlugins.add(pg);
        // }
        addHeadersContent(pf, inactivePlugins, false);

        activePlugins.clear();
        for (int i = 0; i < listExport.size(); i++) {
            Plugin pg = listExport.get(i);
            if (!activeExport.contains(pg.getID()))
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, inactivePlugins, false);
    } else if ("advanced".equals(settings)) {
        loadCommonAdvancedSettings(pf);

        for (int i = 0; i < listVF.size(); i++) {
            Plugin pg = listVF.get(i);
            if (activeVF.contains(pg.getID()))
                activePlugins.add(pg);
            else
                inactivePlugins.add(pg);
        }
        if (isPreferenecesAvailable(inactivePlugins, true))
            hasInactive = true;
        addHeadersContent(pf, activePlugins, true);

        activePlugins.clear();
        inactivePlugins.clear();
        for (int i = 0; i < listCapture.size(); i++) {
            Plugin pg = listCapture.get(i);
            if (activeCapture.equals(pg.getID()))
                activePlugins.add(pg);
            else
                inactivePlugins.add(pg);
        }
        if (isPreferenecesAvailable(inactivePlugins, true))
            hasInactive = true;
        addHeadersContent(pf, activePlugins, true);

        activePlugins.clear();
        inactivePlugins.clear();
        for (int i = 0; i < listProcessing.size(); i++) {
            Plugin pg = listProcessing.get(i);
            if (activeProcessing.equals(pg.getID()))
                activePlugins.add(pg);
            else
                inactivePlugins.add(pg);
        }
        if (isPreferenecesAvailable(inactivePlugins, true))
            hasInactive = true;
        addHeadersContent(pf, activePlugins, true);

        activePlugins.clear();
        inactivePlugins.clear();
        // for (int i = 0; i < listFilter.size(); i++)
        // {
        // Plugin pg = listFilter.get(i);
        // if (activeFilter.contains(pg.getID()))
        // activePlugins.add(pg);
        // else
        // inactivePlugins.add(pg);
        // }
        if (isPreferenecesAvailable(inactivePlugins, true))
            hasInactive = true;
        addHeadersContent(pf, activePlugins, true);

        activePlugins.clear();
        inactivePlugins.clear();
        for (int i = 0; i < listExport.size(); i++) {
            Plugin pg = listExport.get(i);
            if (activeExport.equals(pg.getID()))
                activePlugins.add(pg);
            else
                inactivePlugins.add(pg);
        }
        if (isPreferenecesAvailable(inactivePlugins, true))
            hasInactive = true;
        addHeadersContent(pf, activePlugins, true);

        if (hasInactive)
            pf.addPreferencesFromResource(R.xml.preferences_advance_inactive);
    } else if ("advanced_inactive".equals(settings)) {
        for (int i = 0; i < listVF.size(); i++) {
            Plugin pg = listVF.get(i);
            if (!activeVF.contains(pg.getID()))
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, inactivePlugins, true);

        inactivePlugins.clear();
        for (int i = 0; i < listCapture.size(); i++) {
            Plugin pg = listCapture.get(i);
            if (!activeCapture.equals(pg.getID()))
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, inactivePlugins, true);

        inactivePlugins.clear();
        for (int i = 0; i < listProcessing.size(); i++) {
            Plugin pg = listProcessing.get(i);
            if (!activeProcessing.equals(pg.getID()))
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, inactivePlugins, true);

        inactivePlugins.clear();
        // for (int i = 0; i < listFilter.size(); i++)
        // {
        // Plugin pg = listFilter.get(i);
        // if (!activeFilter.contains(pg.getID()))
        // inactivePlugins.add(pg);
        // }
        addHeadersContent(pf, inactivePlugins, true);

        inactivePlugins.clear();
        for (int i = 0; i < listExport.size(); i++) {
            Plugin pg = listExport.get(i);
            if (!activeExport.equals(pg.getID()))
                inactivePlugins.add(pg);
        }
        addHeadersContent(pf, inactivePlugins, true);
    } else if ("plugins_settings".equals(settings)) {
        pf.getActivity().finish();
        Preferences.closePrefs();
        MainScreen.setShowStore(true);
    }
}

From source file:im.vector.fragments.VectorRoomSettingsFragment.java

/**
     * Refresh the banned users list./*from   w  ww .  ja va2s  .  co  m*/
     */
    private void refreshBannedMembersList() {
        ArrayList<RoomMember> bannedMembers = new ArrayList<>();
        Collection<RoomMember> members = mRoom.getMembers();

        if (null != members) {
            for (RoomMember member : members) {
                if (TextUtils.equals(member.membership, RoomMember.MEMBERSHIP_BAN)) {
                    bannedMembers.add(member);
                }
            }
        }

        Collections.sort(bannedMembers, new Comparator<RoomMember>() {
            @Override
            public int compare(RoomMember m1, RoomMember m2) {
                return m1.getUserId().toLowerCase(VectorApp.getApplicationLocale())
                        .compareTo(m2.getUserId().toLowerCase(VectorApp.getApplicationLocale()));
            }
        });

        PreferenceScreen preferenceScreen = getPreferenceScreen();

        preferenceScreen.removePreference(mBannedMembersSettingsCategoryDivider);
        preferenceScreen.removePreference(mBannedMembersSettingsCategory);
        mBannedMembersSettingsCategory.removeAll();

        if (bannedMembers.size() > 0) {
            preferenceScreen.addPreference(mBannedMembersSettingsCategoryDivider);
            preferenceScreen.addPreference(mBannedMembersSettingsCategory);

            for (RoomMember member : bannedMembers) {
                VectorCustomActionEditTextPreference preference = new VectorCustomActionEditTextPreference(
                        getActivity());

                final String userId = member.getUserId();

                preference.setTitle(userId);
                preference.setKey(BANNED_PREFERENCE_KEY_BASE + userId);

                preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Intent startRoomInfoIntent = new Intent(getActivity(), VectorMemberDetailsActivity.class);
                        startRoomInfoIntent.putExtra(VectorMemberDetailsActivity.EXTRA_MEMBER_ID, userId);
                        startRoomInfoIntent.putExtra(VectorMemberDetailsActivity.EXTRA_ROOM_ID, mRoom.getRoomId());
                        startRoomInfoIntent.putExtra(VectorMemberDetailsActivity.EXTRA_MATRIX_ID,
                                mSession.getCredentials().userId);
                        getActivity().startActivity(startRoomInfoIntent);
                        return false;
                    }
                });

                mBannedMembersSettingsCategory.addPreference(preference);
            }
        }
    }