Example usage for android.preference PreferenceCategory addPreference

List of usage examples for android.preference PreferenceCategory addPreference

Introduction

In this page you can find the example usage for android.preference PreferenceCategory addPreference.

Prototype

public boolean addPreference(Preference preference) 

Source Link

Document

Adds a Preference at the correct position based on the preference's order.

Usage

From source file:org.linphone.SettingsFragment.java

private void initAudioSettings() {
    PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_codecs_key));
    if (codecs == null)
        return;//  www  .j  av  a 2 s  .c  o m

    codecs.removeAll();

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    for (final PayloadType pt : lc.getAudioCodecs()) {
        CheckBoxPreference codec = new CheckBoxPreference(LinphoneService.instance());
        codec.setTitle(pt.getMime());
        codec.setSummary(pt.getRate() + " Hz");
        codec.setChecked(lc.isPayloadTypeEnabled(pt));

        codec.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                boolean enable = (Boolean) newValue;
                try {
                    LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable);
                } catch (LinphoneCoreException e) {
                    e.printStackTrace();
                }
                return true;
            }
        });

        codecs.addPreference(codec);
    }

    CheckBoxPreference echoCancellation = (CheckBoxPreference) findPreference(
            getString(R.string.pref_echo_cancellation_key));
    echoCancellation.setChecked(mPrefs.isEchoCancellationEnabled());

    if (mPrefs.isEchoCancellationEnabled()) {
        Preference echoCalibration = findPreference(getString(R.string.pref_echo_canceller_calibration_key));
        echoCalibration
                .setSummary(String.format(getString(R.string.ec_calibrated), mPrefs.getEchoCalibration()));
    }

    CheckBoxPreference adaptiveRateControl = (CheckBoxPreference) findPreference(
            getString(R.string.pref_adaptive_rate_control_key));
    adaptiveRateControl.setChecked(mPrefs.isAdaptiveRateControlEnabled());

    ListPreference adaptiveRateAlgorithm = (ListPreference) findPreference(
            getString(R.string.pref_adaptive_rate_algorithm_key));
    adaptiveRateAlgorithm.setSummary(String.valueOf(mPrefs.getAdaptiveRateAlgorithm()));
    adaptiveRateAlgorithm.setValue(String.valueOf(mPrefs.getAdaptiveRateAlgorithm()));

    ListPreference bitrateLimit = (ListPreference) findPreference(
            getString(R.string.pref_codec_bitrate_limit_key));
    bitrateLimit.setSummary(String.valueOf(mPrefs.getCodecBitrateLimit()));
    bitrateLimit.setValue(String.valueOf(mPrefs.getCodecBitrateLimit()));
}

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

private void loadExternalSettingLinks(PreferenceCategory preferenceCategory) {
    if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
        ExternalLinksProvider externalLinksProvider = new ExternalLinksProvider(getContentResolver());

        for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.SETTINGS)) {

            // only add if it does not exist, in case activity is re-used
            if (findPreference(link.id.toString()) == null) {
                Preference p = new Preference(this);
                p.setTitle(link.name);/*from  w w  w.  j a v a  2 s .co  m*/
                p.setKey(link.id.toString());

                p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Intent externalWebViewIntent = new Intent(getApplicationContext(),
                                ExternalSiteWebView.class);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, link.name);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, link.url);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, link.id);
                        startActivity(externalWebViewIntent);

                        return true;
                    }
                });

                preferenceCategory.addPreference(p);
            }
        }
    }
}

From source file:org.linphone.SettingsFragment.java

private void initAccounts() {
    PreferenceCategory accounts = (PreferenceCategory) findPreference(getString(R.string.pref_sipaccounts_key));
    accounts.removeAll();//from   w w  w. j  a v a2 s.c  om

    // Get already configured extra accounts
    int defaultAccountID = mPrefs.getDefaultAccountIndex();
    int nbAccounts = mPrefs.getAccountCount();
    for (int i = 0; i < nbAccounts; i++) {
        final int accountId = i;
        // For each, add menus to configure it
        String username = mPrefs.getAccountUsername(accountId);
        String domain = mPrefs.getAccountDomain(accountId);
        LedPreference account = new LedPreference(LinphoneService.instance());

        if (username == null) {
            account.setTitle(getString(R.string.pref_sipaccount));
        } else {
            account.setTitle(username + "@" + domain);
        }

        if (defaultAccountID == i) {
            account.setSummary(R.string.default_account_flag);
        }

        account.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                MainActivity.instance().displayAccountSettings(accountId);
                return false;
            }
        });
        updateAccountLed(account, username, domain, mPrefs.isAccountEnabled(i));
        accounts.addPreference(account);
    }
}

From source file:de.grobox.blitzmail.MainActivity.java

private void addSendNowPref(final Context c) {
    JSONObject mails = MailStorage.getMails(this);

    if (mails != null && mails.length() > 0) {
        PreferenceCategory targetCategory = (PreferenceCategory) findPreference("pref_sending");

        Preference pref = new Preference(this);
        pref.setKey("pref_send_now");
        pref.setTitle(R.string.pref_send_now);
        pref.setSummary(//w ww . jav a  2  s. c  o m
                String.format(getResources().getString(R.string.pref_send_now_summary), mails.length()));

        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                if (BuildConfig.PRO)
                    sendNow();
                else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(c);

                    builder.setTitle(c.getString(R.string.app_name));
                    builder.setMessage(c.getString(R.string.error_lite_version));
                    builder.setIcon(android.R.drawable.ic_dialog_info);

                    // Add the buttons
                    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            Uri uri = Uri.parse(
                                    "https://play.google.com/store/apps/details?id=de.grobox.blitzmail.pro");
                            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                            if (intent.resolveActivity(c.getPackageManager()) != null) {
                                c.startActivity(intent);
                            }
                            dialog.dismiss();
                        }
                    });
                    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                        }
                    });

                    // Create and show the AlertDialog
                    AlertDialog dialog = builder.create();
                    dialog.setCanceledOnTouchOutside(false);
                    dialog.show();
                }

                return true;
            }
        });

        targetCategory.addPreference(pref);
    }
}

From source file:org.linphone.SettingsFragment.java

private void initVideoSettings() {
    initializePreferredVideoSizePreferences(
            (ListPreference) findPreference(getString(R.string.pref_preferred_video_size_key)));

    PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_video_codecs_key));

    if (codecs == null)
        return;//from  w w w . j  a v a 2s  . c  o  m

    codecs.removeAll();

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    for (final PayloadType pt : lc.getVideoCodecs()) {
        CheckBoxPreference codec = new CheckBoxPreference(LinphoneService.instance());
        codec.setTitle(pt.getMime());

        if (!pt.getMime().equals("VP8")) {
            if (getResources().getBoolean(R.bool.disable_all_patented_codecs_for_markets)) {
                continue;
            } else {
                if (!Version.hasFastCpuWithAsmOptim() && pt.getMime().equals("H264")) {
                    // Android without neon doesn't support H264
                    Log.w("CPU does not have asm optimisations available, disabling H264");
                    continue;
                }
            }
        }
        codec.setChecked(lc.isPayloadTypeEnabled(pt));

        codec.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                boolean enable = (Boolean) newValue;
                try {
                    LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable);
                } catch (LinphoneCoreException e) {
                    e.printStackTrace();
                }
                return true;
            }
        });

        codecs.addPreference(codec);
    }

    ((CheckBoxPreference) findPreference(getString(R.string.pref_video_enable_key)))
            .setChecked(mPrefs.isVideoEnabled());
    ((CheckBoxPreference) findPreference(getString(R.string.pref_video_use_front_camera_key)))
            .setChecked(mPrefs.useFrontCam());
    ((CheckBoxPreference) findPreference(getString(R.string.pref_video_initiate_call_with_video_key)))
            .setChecked(mPrefs.shouldInitiateVideoCall());
    //((CheckBoxPreference) findPreference(getString(R.string.pref_video_automatically_share_my_video_key))).setChecked(mPrefs.shouldAutomaticallyShareMyVideo());
    ((CheckBoxPreference) findPreference(getString(R.string.pref_video_automatically_accept_video_key)))
            .setChecked(mPrefs.shouldAutomaticallyAcceptVideoRequests());
}

From source file:net.freifunk.android.discover.SettingsActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.pref_data_sync);

    // get data via the key
    ArrayList<NodeMap> nodeMapArrayList = new ArrayList<NodeMap>(MapMaster.getInstance().getMaps().values());
    PreferenceCategory communities = (PreferenceCategory) findPreference("communities");

    // sort by Name
    Collections.sort(nodeMapArrayList, new NodeMapComparator());

    if (nodeMapArrayList != null && communities != null) {
        for (final NodeMap nm : nodeMapArrayList) {

            PreferenceScreen communityPreferenceScreen = getPreferenceManager()
                    .createPreferenceScreen(SettingsActivity.this);

            communityPreferenceScreen.setTitle(nm.getMapName());
            communityPreferenceScreen.setKey(nm.getMapName());

            final CheckBoxPreference deactivateCommunityPreference = new CheckBoxPreference(
                    SettingsActivity.this);

            // TODO: move Strings to resources
            deactivateCommunityPreference.setTitle("Community aktiv");
            deactivateCommunityPreference
                    .setSummary("deaktivieren, falls Community nicht auf der Karte angezeigt werden soll");
            deactivateCommunityPreference.setKey("community_deactivate_" + nm.getMapName());
            deactivateCommunityPreference.setChecked(nm.isActive());
            deactivateCommunityPreference
                    .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

                        @Override
                        public boolean onPreferenceChange(Preference preference, Object newValue) {

                            Database db = Database.getInstance(null);

                            boolean newActive = newValue.toString().equals("true") ? true : false;

                            nm.setActive(newActive);
                            db.addNodeMap(nm);

                            // reload if set to active
                            if (newActive) {
                                nm.loadNodes();
                            } else {
                                nm.updateNodes();
                            }/*from   ww  w  . ja  v  a 2s . co m*/

                            return true;
                        }
                    });

            EditTextPreference editCommunityPreference = new EditTextPreference(SettingsActivity.this);

            // TODO: move Strings to resources
            editCommunityPreference.setTitle("URL bearbeiten");
            editCommunityPreference.setSummary("aendern, falls eine andere Quelle genutzt werden soll.");
            editCommunityPreference.setKey("community_edit_" + nm.getMapName());
            editCommunityPreference.setText(nm.getMapUrl());

            editCommunityPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {

                    Database db = Database.getInstance(null);

                    // remove old nodes from map
                    nm.setActive(false);
                    EventBus.getInstance().post(new NodeResult(NodeResult.NodeResultType.UPDATE_NODES, nm));

                    // we should probably do this async as well
                    db.deleteAllNodesForMap(nm);

                    // load new nodes
                    NodeMap newMap = new NodeMap(nm.getMapName(), (String) newValue, true);
                    db.addNodeMap(newMap);

                    //HashMap<String, NodeMap> nodeResult = new HashMap<String, NodeMap>(1);
                    //nodeResult.put(nm.getMapName(), nm);

                    newMap.updateNodes();
                    //EventBus.getInstance().post(new NodeResult(NodeResult.NodeResultType.LOAD_NODES, nm));
                    //EventBus.getInstance().post(new NodeResult(NodeResult.NodeResultType.UPDATE_MAP, nodeResult));

                    return true;
                }
            });

            communityPreferenceScreen.addPreference(deactivateCommunityPreference);
            communityPreferenceScreen.addPreference(editCommunityPreference);

            communities.addPreference(communityPreferenceScreen);
        }
    }

    setupActionBar();

}