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:net.basilwang.StaticAttachmentActivity.java

 private void reloadData(PreferenceCategory logonPreference,
      PreferenceScreen logonAddPreference,
      PreferenceManager preferenceManager) {
   // 2012-11-23 basilwang refresh tabbar title
   refreshActionBarTitle();/*from ww  w .j av a 2s. c o  m*/

   logonPreference.removeAll();
   logonPreference.addPreference(logonAddPreference);
   int accountId = PreferenceManager.getDefaultSharedPreferences(this)
         .getInt(LOGON_ACCOUNT_ID, 0);
   AccountService service = new AccountService(this);
   List<Account> list = service.getAccounts();
   if (list.size() == 0) {
      logonAddPreference.setEnabled(true);

   } else {
      logonAddPreference.setEnabled(false);
      for (Account account : list) {
         PreferenceScreen preferenceItem = preferenceManager
               .createPreferenceScreen(this);
         // CheckBoxPreference checkBoxPreference = new
         // CheckBoxPreference(this);
         // make sure each key is unique
         preferenceItem.setKey(LOGON_ACCOUNT_PREFERENCES);
         preferenceItem.setTitle(PreferenceUtils.getPreferUserName(this));
         if (accountId == account.getId())
            preferenceItem.setSummary(R.string.already_checked);
         // preferenceItem.setChecked(false);
         // checkBoxPreference.setDisableDependentsState(disableDependentsState)
         // checkBoxPreference.setSelectable(false);
         preferenceItem.setOrder(0);
         preferenceItem.setOnPreferenceClickListener(this);
         logonPreference.addPreference(preferenceItem);
      }

   }

}

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

/**
 * Update the "wpcom blogs" preference category to contain a preference for each blog to configure
 * blog-specific settings.//w ww.jav  a 2 s  . c o  m
 */
void updateSelfHostedBlogsPreferenceCategory() {
    PreferenceCategory blogsCategory = (PreferenceCategory) findPreference(
            getActivity().getString(R.string.pref_key_self_hosted));
    blogsCategory.removeAll();
    int order = 0;

    // Add self-hosted blog button
    Preference addBlogPreference = new Preference(getActivity());
    addBlogPreference.setTitle(R.string.add_self_hosted_blog);
    Intent intentWelcome = new Intent(getActivity(), SignInActivity.class);
    intentWelcome.putExtra(SignInActivity.START_FRAGMENT_KEY, SignInActivity.ADD_SELF_HOSTED_BLOG);
    addBlogPreference.setIntent(intentWelcome);
    addBlogPreference.setOrder(order++);
    blogsCategory.addPreference(addBlogPreference);

    // Add self hosted list
    List<Map<String, Object>> accounts = WordPress.wpDB.getAccountsBy("dotcomFlag=0", null);
    addAccounts(blogsCategory, accounts, order);
}

From source file:com.rareventure.gps2.reviewer.SettingsActivity.java

private void createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
    this.setPreferenceScreen(root);

    isCollectData = new CheckBoxPreference(this);
    isCollectData.setTitle(R.string.collect_gps_data);
    isCollectData.setSummary(R.string.collect_gps_data_desc);
    root.addPreference(isCollectData);/*from w ww .  j  a  va 2s  . c  o m*/
    isCollectData.setOnPreferenceClickListener(this);

    percTimeGpsOn = new SeekBarDialogPreference(this, getText(R.string.title_perc_time_gps_on),
            getText(R.string.desc_perc_time_gps_on),
            getResources().getInteger(R.dimen.perc_time_gps_on_min_value),
            getResources().getInteger(R.dimen.perc_time_gps_on_max_value),
            getResources().getInteger(R.dimen.perc_time_gps_on_steps),
            getResources().getInteger(R.dimen.perc_time_gps_on_log_scale),
            getText(R.string.seekbar_perc_printf_format).toString(), null);
    percTimeGpsOn.setOnPreferenceChangeListener(this);
    root.addPreference(percTimeGpsOn);

    minBatteryLife = new SeekBarDialogPreference(this, getText(R.string.title_min_battery_life_perc),
            getText(R.string.desc_min_battery_life_perc),
            getResources().getInteger(R.dimen.min_battery_level_min_value),
            getResources().getInteger(R.dimen.min_battery_level_max_value),
            getResources().getInteger(R.dimen.min_battery_level_steps),
            getResources().getInteger(R.dimen.min_battery_level_log_scale),
            getText(R.string.seekbar_perc_printf_format).toString(), null);
    minBatteryLife.setOnPreferenceChangeListener(this);
    root.addPreference(minBatteryLife);

    enableToolTips = new CheckBoxPreference(this);
    enableToolTips.setTitle(R.string.enable_tooltips);
    enableToolTips.setKey("enable_tooltips");
    root.addPreference(enableToolTips);
    enableToolTips.setOnPreferenceClickListener(this);

    useMetricUnits = new CheckBoxPreference(this);
    useMetricUnits.setTitle(R.string.use_metric_units);
    useMetricUnits.setChecked(GTG.prefs.useMetric);
    root.addPreference(useMetricUnits);

    //note that we can't use setIntent() for these preferences, since that would
    // be interpreted as an outside action causing us to lose the password is set flag

    colorblindSettings = getPreferenceManager().createPreferenceScreen(this);
    //        screenPref.setKey("screen_preference");
    //        colorblindSettings.setIntent(new Intent(this, ChooseColorsScreen.class));
    colorblindSettings.setTitle(R.string.colorblind_title);
    colorblindSettings.setSummary(R.string.colorblind_summary);
    colorblindSettings.setOnPreferenceClickListener(this);

    root.addPreference(colorblindSettings);

    mapFontSize = new SeekBarDialogPreference(this, getText(R.string.title_map_font_size),
            getText(R.string.desc_map_font_size), getResources().getInteger(R.dimen.map_font_size_min_value),
            getResources().getInteger(R.dimen.map_font_size_max_value),
            getResources().getInteger(R.dimen.map_font_size_steps),
            getResources().getInteger(R.dimen.map_font_size_log_scale), "%1.0f", null);
    mapFontSize.setOnPreferenceChangeListener(this);
    root.addPreference(mapFontSize);

    enablePassword = new CheckBoxPreference(this);
    enablePassword.setTitle(R.string.enable_password);
    enablePassword.setKey("enable_password");
    root.addPreference(enablePassword);
    enablePassword.setOnPreferenceClickListener(this);

    changePassword = new Preference(this);
    changePassword.setTitle(R.string.change_password);
    root.addPreference(changePassword);
    changePassword.setDependency("enable_password");
    changePassword.setOnPreferenceClickListener(this);

    passwordTimeout = new SeekBarDialogPreference(this, getText(R.string.title_password_timeout),
            getText(R.string.desc_password_timeout), 0, passwordTimeoutStrs.length - 1,
            passwordTimeoutStrs.length, 0, null, new SeekBarWithText.CustomUpdateTextView() {
                @Override
                public String updateText(float value) {
                    return passwordTimeoutStrs[(int) value];
                }
            });
    passwordTimeout.setOnPreferenceChangeListener(this);
    root.addPreference(passwordTimeout);

    createBackupFilePref = getPreferenceManager().createPreferenceScreen(this);
    createBackupFilePref.setTitle(R.string.create_backup_pref);
    root.addPreference(createBackupFilePref);
    createBackupFilePref.setOnPreferenceClickListener(this);

    restoreBackupFilePref = getPreferenceManager().createPreferenceScreen(this);
    restoreBackupFilePref.setTitle(R.string.restore_backup_pref);
    root.addPreference(restoreBackupFilePref);
    restoreBackupFilePref.setOnPreferenceClickListener(this);

    allowErrorReporting = new CheckBoxPreference(this);
    allowErrorReporting.setTitle(R.string.allow_error_reporting);
    allowErrorReporting.setSummary(R.string.allow_error_reporting_summary);
    allowErrorReporting.setChecked(GTG.isAcraEnabled(this));
    root.addPreference(allowErrorReporting);

    aboutPref = getPreferenceManager().createPreferenceScreen(this);
    aboutPref.setOnPreferenceClickListener(this);
    aboutPref.setTitle(R.string.about);
    root.addPreference(aboutPref);

    PreferenceCategory advancedCategory = new PreferenceCategory(this);
    advancedCategory.setTitle("Advanced");
    root.addPreference(advancedCategory);

    writeGpsWakeLockDebugFile = new CheckBoxPreference(this);
    writeGpsWakeLockDebugFile.setTitle(R.string.write_to_gps_wake_lock_log);
    writeGpsWakeLockDebugFile.setSummary(String.format(getString(R.string.write_to_gps_wake_lock_log_summary),
            getString(R.string.gps_wake_lock_filename)));
    writeGpsWakeLockDebugFile.setChecked(GTG.prefs.writeGpsWakeLockDebug);
    writeGpsWakeLockDebugFile.setOnPreferenceClickListener(this);

    advancedCategory.addPreference(writeGpsWakeLockDebugFile);
}

From source file:com.guipenedo.pokeradar.activities.settings.PokemonFilterSettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    getDelegate().installViewFactory();/* w w w  . java2  s.  c o  m*/
    getDelegate().onCreate(savedInstanceState);
    super.onCreate(savedInstanceState);
    PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(this);
    PreferenceCategory category = new PreferenceCategory(this);
    category.setTitle(R.string.filter_pokemons);
    screen.addPreference(category);
    try {
        JSONArray pokemonList = new JSONArray(Utils.loadJSONFromFile(this, "pokemon.json"));
        for (int i = 0; i < pokemonList.length(); i++) {
            JSONObject pokemon = pokemonList.getJSONObject(i);
            CheckBoxPreference checkBox = new CheckBoxPreference(this);
            checkBox.setTitle(pokemon.getString("Name"));
            checkBox.setIcon(new BitmapDrawable(getResources(),
                    Utils.bitmapForPokemon(this, Integer.parseInt(pokemon.getString("Number")))));
            checkBox.setDefaultValue(true);
            checkBox.setSummary(String.format(getString(R.string.setting_filter_pokemon_summary),
                    pokemon.getString("Name")));
            checkBox.setKey("pref_key_show_pokemon_" + Integer.parseInt(pokemon.getString("Number")));
            category.addPreference(checkBox);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    setPreferenceScreen(screen);
}

From source file:com.nttec.everychan.chans.makaba.MakabaModule.java

/**   ?  ( .. https) */
private void addDomainPreferences(PreferenceGroup group) {
    Context context = group.getContext();
    Preference.OnPreferenceChangeListener updateDomainListener = new Preference.OnPreferenceChangeListener() {
        @Override//from   ww w .j  a v  a 2s .  c om
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals(getSharedKey(PREF_KEY_DOMAIN))) {
                updateDomain((String) newValue,
                        preferences.getBoolean(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA), true));
                return true;
            } else if (preference.getKey().equals(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA))) {
                updateDomain(preferences.getString(getSharedKey(PREF_KEY_DOMAIN), DEFAULT_DOMAIN),
                        (boolean) newValue);
                return true;
            }
            return false;
        }
    };
    PreferenceCategory domainCat = new PreferenceCategory(context);
    domainCat.setTitle(R.string.makaba_prefs_domain_category);
    group.addPreference(domainCat);
    EditTextPreference domainPref = new EditTextPreference(context); //  
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.getEditText().setHint(DEFAULT_DOMAIN);
    domainPref.getEditText().setSingleLine();
    domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    domainPref.setOnPreferenceChangeListener(updateDomainListener);
    domainCat.addPreference(domainPref);
    CheckBoxPreference httpsPref = new LazyPreferences.CheckBoxPreference(context); //? "? https"
    httpsPref.setTitle(R.string.pref_use_https);
    httpsPref.setSummary(R.string.pref_use_https_summary);
    httpsPref.setKey(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA));
    httpsPref.setDefaultValue(true);
    httpsPref.setOnPreferenceChangeListener(updateDomainListener);
    domainCat.addPreference(httpsPref);
}

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

private void addAccounts(PreferenceCategory category, List<Map<String, Object>> blogs, int order) {
    for (Map<String, Object> account : blogs) {
        String blogName = StringUtils.unescapeHTML(account.get("blogName").toString());
        int accountId = (Integer) account.get("id");

        Preference blogSettingsPreference = new Preference(getActivity());
        blogSettingsPreference.setTitle(blogName);

        try {//ww w . j a  v  a 2 s .co  m
            // set blog hostname as preference summary if it differs from the blog name
            URL blogUrl = new URL(account.get("url").toString());
            if (!blogName.equals(blogUrl.getHost())) {
                blogSettingsPreference.setSummary(blogUrl.getHost());
            }
        } catch (MalformedURLException e) {
            // do nothing
        }

        Intent intent = new Intent(getActivity(), BlogPreferencesActivity.class);
        intent.putExtra("id", accountId);
        blogSettingsPreference.setIntent(intent);
        blogSettingsPreference.setOrder(order++);
        category.addPreference(blogSettingsPreference);
    }
}

From source file:org.namelessrom.devicecontrol.ui.fragments.preferences.MainPreferencesFragment.java

@Override
public void onCreate(final Bundle bundle) {
    super.onCreate(bundle);
    addPreferencesFromResource(R.xml._device_control);

    final DeviceConfiguration configuration = DeviceConfiguration.get(getActivity());

    mExtensiveLogging = (CustomTogglePreference) findPreference(DeviceConfiguration.EXTENSIVE_LOGGING);
    if (mExtensiveLogging != null) {
        mExtensiveLogging.setChecked(configuration.extensiveLogging);
        mExtensiveLogging.setOnPreferenceChangeListener(this);
    }/*  w w w  .  jav  a 2  s.  c o m*/

    PreferenceCategory category = (PreferenceCategory) findPreference("prefs_general");
    mSetOnBoot = (CustomPreference) findPreference("prefs_set_on_boot");

    mShowLauncher = (CustomTogglePreference) findPreference(DeviceConfiguration.SHOW_LAUNCHER);
    if (mShowLauncher != null) {
        if (Application.IS_NAMELESS) {
            mShowLauncher.setChecked(configuration.showLauncher);
            mShowLauncher.setOnPreferenceChangeListener(this);
        } else {
            category.removePreference(mShowLauncher);
        }
    }

    mSkipChecks = (CustomTogglePreference) findPreference(DeviceConfiguration.SKIP_CHECKS);
    if (mSkipChecks != null) {
        mSkipChecks.setChecked(configuration.skipChecks);
        mSkipChecks.setOnPreferenceChangeListener(this);
    }

    category = (PreferenceCategory) findPreference("prefs_app");

    if (Utils.existsInFile(Scripts.BUILD_PROP, "ro.nameless.secret=1")) {
        mMonkeyPref = new CustomTogglePreference(getActivity());
        mMonkeyPref.setKey(DeviceConfiguration.MONKEY);
        mMonkeyPref.setTitle(R.string.become_a_monkey);
        mMonkeyPref.setSummaryOn(R.string.is_monkey);
        mMonkeyPref.setSummaryOff(R.string.no_monkey);
        mMonkeyPref.setChecked(DeviceConfiguration.get(getActivity()).monkey);
        mMonkeyPref.setOnPreferenceChangeListener(this);
        category.addPreference(mMonkeyPref);
    }

    mDarkTheme = (CustomTogglePreference) findPreference(DeviceConfiguration.DARK_THEME);
    mDarkTheme.setChecked(Application.get().isDarkTheme());
    mDarkTheme.setOnPreferenceChangeListener(this);

    mSwipeOnContent = (CustomTogglePreference) findPreference(DeviceConfiguration.SWIPE_ON_CONTENT);
    mSwipeOnContent.setChecked(configuration.swipeOnContent);
    mSwipeOnContent.setOnPreferenceChangeListener(this);

    mShowPollfish = (CustomTogglePreference) findPreference(DeviceConfiguration.SHOW_POLLFISH);
    mShowPollfish.setChecked(configuration.showPollfish);
    mShowPollfish.setOnPreferenceChangeListener(this);

    setupVersionPreference();
}

From source file:de.tum.in.tumcampus.fragments.SettingsFragment.java

private void populateNewsSources() {
    PreferenceCategory news_sources = (PreferenceCategory) findPreference("card_news_sources");
    NewsManager cm = new NewsManager(mContext);
    Cursor cur = cm.getNewsSources();
    if (cur.moveToFirst()) {
        do {/*from   w  w w.j  a  v  a  2s .  c o m*/
            final CheckBoxPreference pref = new CheckBoxPreference(mContext);
            pref.setKey("card_news_source_" + cur.getString(0));
            pref.setDefaultValue(true);
            if (Build.VERSION.SDK_INT >= 11) {
                // Load news source icon in background and set it
                final String url = cur.getString(1);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        NetUtils net = new NetUtils(mContext);
                        final Bitmap bmp = net.downloadImageToBitmap(url);
                        mContext.runOnUiThread(new Runnable() {
                            @TargetApi(11)
                            @Override
                            public void run() {
                                pref.setIcon(new BitmapDrawable(getResources(), bmp));
                            }
                        });
                    }
                }).start();
            }
            pref.setTitle(cur.getString(2));
            news_sources.addPreference(pref);
        } while (cur.moveToNext());
    }
    cur.close();
}

From source file:com.probam.updater.activity.GooActivity.java

@SuppressWarnings("deprecation")
@Override/*from w w  w . j a v  a 2  s  . co m*/
protected void onCreate(Bundle savedInstanceState) {

    boolean useDarkTheme = ManagerFactory.getPreferencesManager(this).isDarkTheme();
    setTheme(useDarkTheme ? R.style.DarkTheme : R.style.AppTheme);

    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.layout.empty_pref_screen);

    PreferenceScreen pScreen = getPreferenceScreen();
    mInfos = new HashMap<String, PackageInfo>();

    if (CURRENT_NAVIGATION == null) {

        Preference preference = null;

        preference = new Preference(this);
        preference.getExtras().putBoolean("BROWSING_ALL", false);
        preference.getExtras().putBoolean("FOLDER", true);
        preference.getExtras().putString("PATH", "/devs");
        preference.setKey(Constants.GOO_SEARCH_URL + "/devs&ro_board=" + mDevice);
        preference.setTitle(R.string.goo_browse_all_compatible);
        pScreen.addPreference(preference);

        preference = new Preference(this);
        preference.getExtras().putBoolean("BROWSING_ALL", true);
        preference.getExtras().putBoolean("FOLDER", true);
        preference.getExtras().putString("PATH", "/devs");
        preference.setKey(Constants.GOO_SEARCH_URL + "/devs");
        preference.setTitle(R.string.goo_browse_all);
        pScreen.addPreference(preference);

        preference = new Preference(this);
        preference.getExtras().putBoolean("BROWSING_ALL", false);
        preference.getExtras().putBoolean("FOLDER", false);
        preference.getExtras().putString("PATH", "");
        preference.setKey("watchlist");
        preference.setTitle(R.string.goo_browse_watchlist);
        pScreen.addPreference(preference);

    } else {

        if ("watchlist".equals(CURRENT_FOLDER)) {

            PreferenceCategory category = new PreferenceCategory(this);
            category.setKey("category");
            category.setTitle(
                    getResources().getString(R.string.goo_category_title, new Object[] { CURRENT_FOLDER }));
            pScreen.addPreference(category);
            refreshWatchlist();
        } else {

            PreferenceCategory category = new PreferenceCategory(this);
            category.setTitle(
                    getResources().getString(R.string.goo_category_title, new Object[] { CURRENT_FOLDER }));
            pScreen.addPreference(category);
            try {

                JSONObject object = (JSONObject) new JSONTokener(CURRENT_NAVIGATION).nextValue();
                JSONArray list = object.getJSONArray("list");

                for (int i = 0; i < list.length(); i++) {

                    JSONObject result = list.getJSONObject(i);
                    String fileName = result.optString("filename");

                    if (fileName != null && !"".equals(fileName.trim())) {

                        String path = result.optString("path");

                        if (!BROWSING_ALL && !mDevice.equals(result.optString("ro_board"))) {
                            continue;
                        }

                        GooPackage info = new GooPackage(result, -1);
                        mInfos.put(path, info);

                        Preference preference = new Preference(this);
                        preference.getExtras().putBoolean("FOLDER", false);
                        preference.setKey(path);
                        preference.setTitle(fileName);
                        preference.setSummary(path);
                        category.addPreference(preference);

                    } else {

                        String folder = result.optString("folder");
                        String folderName = folder.substring(folder.lastIndexOf("/") + 1);

                        Preference preference = new FolderPreference(this, folder, false);
                        preference.getExtras().putBoolean("BROWSING_ALL", BROWSING_ALL);
                        preference.getExtras().putBoolean("FOLDER", true);
                        preference.getExtras().putString("PATH", folder);
                        if (!BROWSING_ALL) {
                            preference.setKey(Constants.GOO_SEARCH_URL + folder + "&ro_board=" + mDevice);
                        } else {
                            preference.setKey(Constants.GOO_SEARCH_URL + folder);
                        }
                        preference.setTitle(folderName);
                        preference.setSummary(folder);
                        category.addPreference(preference);
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                Toast.makeText(this, R.string.goo_browse_error, Toast.LENGTH_LONG).show();
            }
        }
    }
    if (DIALOG != null)
        DIALOG.dismiss();

    DIALOG = null;

    ListView listView = getListView();
    listView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            ListAdapter listAdapter = listView.getAdapter();
            Object obj = listAdapter.getItem(position);
            if (obj != null && obj instanceof View.OnLongClickListener) {
                View.OnLongClickListener longListener = (View.OnLongClickListener) obj;
                return longListener.onLongClick(view);
            }
            return false;
        }
    });
}