Example usage for android.preference PreferenceScreen getRootAdapter

List of usage examples for android.preference PreferenceScreen getRootAdapter

Introduction

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

Prototype

public ListAdapter getRootAdapter() 

Source Link

Document

Returns an adapter that can be attached to a PreferenceActivity or PreferenceFragment to show the preferences contained in this PreferenceScreen .

Usage

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

private void updateLoginInfo() {

    String username = FsSettings.getUserName();
    String password = FsSettings.getPassWord();

    Cat.v("Updating login summary");
    PreferenceScreen loginPreference = findPref("login");
    loginPreference.setSummary(username + " : " + transformPassword(password));
    ((BaseAdapter) loginPreference.getRootAdapter()).notifyDataSetChanged();

    EditTextPreference usernamePref = findPref("username");
    usernamePref.setSummary(username);//from   w  w w.  j  a va  2s  . c o m

    EditTextPreference passWordPref = findPref("password");
    passWordPref.setSummary(transformPassword(password));
}

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

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

    mContext = getActivity();/*from w w  w .j  a v  a2s  . c  o m*/

    // Disables silence service if the app is used without TUMOnline access
    CheckBoxPreference silent = (CheckBoxPreference) findPreference("silent_mode");
    if (!new AccessTokenManager(mContext).hasValidAccessToken()) {
        silent.setEnabled(false);
    }

    // Click listener for preference list entries. Used to simulate a button
    // (since it is not possible to add a button to the preferences screen)
    findPreference("button_wizard").setOnPreferenceClickListener(this);
    findPreference("button_clear_cache").setOnPreferenceClickListener(this);
    findPreference("facebook").setOnPreferenceClickListener(this);
    findPreference("github").setOnPreferenceClickListener(this);
    findPreference("first_run").setOnPreferenceClickListener(this);
    findPreference("licenses").setOnPreferenceClickListener(this);
    findPreference("feedback").setOnPreferenceClickListener(this);
    findPreference("privacy").setOnPreferenceClickListener(this);

    // Set summary for these preferences
    setSummary("card_cafeteria_default_G");
    setSummary("card_cafeteria_default_K");
    setSummary("card_cafeteria_default_W");
    setSummary("card_role");
    setSummary("card_stations_default_G");
    setSummary("card_stations_default_C");
    setSummary("card_stations_default_K");
    setSummary("card_default_campus");
    setSummary("silent_mode_set_to");
    setSummary("background_mode_set_to");

    // Register the change listener to react immediately on changes
    PreferenceManager.getDefaultSharedPreferences(mContext).registerOnSharedPreferenceChangeListener(this);

    // Populate news sources
    populateNewsSources();

    // Open a card's preference screen if selected from it's context menu
    Bundle bundle = getArguments();
    if (bundle != null && bundle.containsKey(Const.PREFERENCE_SCREEN)) {
        final String key = bundle.getString(Const.PREFERENCE_SCREEN);

        PreferenceScreen screen = (PreferenceScreen) findPreference("cards_pref_container");
        final PreferenceScreen cardPreferenceScreen = (PreferenceScreen) findPreference(key);
        cardPreferenceScreen.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                initializeActionBar(cardPreferenceScreen);
                return true;
            }
        });

        final ListAdapter listAdapter = screen.getRootAdapter();
        final int itemsCount = listAdapter.getCount();
        for (int i = 0; i < itemsCount; ++i) {
            if (listAdapter.getItem(i).equals(cardPreferenceScreen)) {
                screen.onItemClick(null, null, i, 0);
                break;
            }
        }
    }
}

From source file:com.anprosit.android.dagger.ui.v4.PreferenceFragment.java

private void bindPreferences() {
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    if (preferenceScreen != null) {
        preferenceScreen.bind(getListView());
    }//  ww  w . jav  a2s  .c o  m

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        // Workaround android bug for SDK 10 and below - see
        // https://github.com/android/platform_frameworks_base/commit/2d43d283fc0f22b08f43c6db4da71031168e7f59
        getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // If the list has headers, subtract them from the index.
                if (parent instanceof ListView) {
                    position -= ((ListView) parent).getHeaderViewsCount();
                }

                Object item = preferenceScreen.getRootAdapter().getItem(position);
                if (!(item instanceof Preference))
                    return;

                final Preference preference = (Preference) item;
                try {
                    Method performClick = Preference.class.getDeclaredMethod("performClick",
                            PreferenceScreen.class);
                    performClick.setAccessible(true);
                    performClick.invoke(preference, preferenceScreen);
                } catch (InvocationTargetException e) {
                } catch (IllegalAccessException e) {
                } catch (NoSuchMethodException e) {
                }
            }
        });
    }
}

From source file:com.limelight.testvideosdk.PreferenceFragment.java

private void bindPreferences() {
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    if (preferenceScreen != null) {
        preferenceScreen.bind(getListView());
    }/*from   w ww.  ja  v  a2s  .  c om*/
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        // Workaround android bug for SDK 10 and below - see
        // https://github.com/android/platform_frameworks_base/commit/2d43d283fc0f22b08f43c6db4da71031168e7f59
        getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // If the list has headers, subtract them from the
                // index.
                if (parent instanceof ListView) {
                    position -= ((ListView) parent).getHeaderViewsCount();
                }
                Object item = preferenceScreen.getRootAdapter().getItem(position);
                if (!(item instanceof Preference))
                    return;
                final Preference preference = (Preference) item;
                try {
                    Method performClick = Preference.class.getDeclaredMethod("performClick",
                            PreferenceScreen.class);
                    performClick.setAccessible(true);
                    performClick.invoke(preference, preferenceScreen);
                } catch (InvocationTargetException e) {
                } catch (IllegalAccessException e) {
                } catch (NoSuchMethodException e) {
                }
            }
        });
    }
}

From source file:tm.alashow.datmusic.ui.widget.preferencefragment.PreferenceFragment.java

private void bindPreferences() {
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    if (preferenceScreen != null) {
        preferenceScreen.bind(getListView());
    }// w  ww  .j a  v  a 2  s .  co m

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        // Workaround android bug for SDK 10 and below - see
        // https://github.com/android/platform_frameworks_base/commit/2d43d283fc0f22b08f43c6db4da71031168e7f59
        getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // If the list has headers, subtract them from the index.
                if (parent instanceof ListView) {
                    position -= ((ListView) parent).getHeaderViewsCount();
                }

                Object item = preferenceScreen.getRootAdapter().getItem(position);
                if (!(item instanceof Preference)) {
                    return;
                }

                final Preference preference = (Preference) item;
                try {
                    Method performClick = Preference.class.getDeclaredMethod("performClick",
                            PreferenceScreen.class);
                    performClick.setAccessible(true);
                    performClick.invoke(preference, preferenceScreen);
                } catch (InvocationTargetException e) {
                } catch (IllegalAccessException e) {
                } catch (NoSuchMethodException e) {
                }
            }
        });
    }
}

From source file:com.zoromatic.flashlight.PreferenceFragment.java

private void bindPreferences() {
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    if (preferenceScreen != null) {
        preferenceScreen.bind(getListView());

        ListView list = getListView();

        if (list != null && list.getCount() > 0) {
            for (int i = 0; i < list.getCount(); i++) {
                View view = getViewByPosition(i, list);

                if (view != null) {
                    setListViewItem(view);
                }//ww w  .  j  av  a 2  s.  co  m
            }
        }
    }

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        // Workaround android bug for SDK 10 and below - see
        // https://github.com/android/platform_frameworks_base/commit/2d43d283fc0f22b08f43c6db4da71031168e7f59
        getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // If the list has headers, subtract them from the index.
                if (parent instanceof ListView) {
                    position -= ((ListView) parent).getHeaderViewsCount();
                }

                Object item = preferenceScreen.getRootAdapter().getItem(position);
                if (!(item instanceof Preference))
                    return;

                final Preference preference = (Preference) item;
                try {
                    Method performClick = Preference.class.getDeclaredMethod("performClick",
                            PreferenceScreen.class);
                    performClick.setAccessible(true);
                    performClick.invoke(preference, preferenceScreen);
                } catch (InvocationTargetException e) {
                } catch (IllegalAccessException e) {
                } catch (NoSuchMethodException e) {
                }
            }
        });
    }
}