Search in sources :

Example 46 with PreferenceCategory

use of android.support.v7.preference.PreferenceCategory in project android_packages_apps_Settings by crdroidandroid.

the class LocationSettings method addLocationServices.

/**
 * Add the settings injected by external apps into the "App Settings" category. Hides the
 * category if there are no injected settings.
 *
 * Reloads the settings whenever receives
 * {@link SettingInjectorService#ACTION_INJECTED_SETTING_CHANGED}.
 */
private void addLocationServices(Context context, PreferenceScreen root, boolean lockdownOnLocationAccess) {
    PreferenceCategory categoryLocationServices = (PreferenceCategory) root.findPreference(KEY_LOCATION_SERVICES);
    injector = new SettingsInjector(context);
    // If location access is locked down by device policy then we only show injected settings
    // for the primary profile.
    final Context prefContext = categoryLocationServices.getContext();
    final List<Preference> locationServices = injector.getInjectedSettings(prefContext, lockdownOnLocationAccess ? UserHandle.myUserId() : UserHandle.USER_CURRENT);
    mReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Received settings change intent: " + intent);
            }
            injector.reloadStatusMessages();
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(SettingInjectorService.ACTION_INJECTED_SETTING_CHANGED);
    context.registerReceiver(mReceiver, filter);
    if (locationServices.size() > 0) {
        addPreferencesSorted(locationServices, categoryLocationServices);
    } else {
        // If there's no item to display, remove the whole category.
        root.removePreference(categoryLocationServices);
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) PreferenceCategory(android.support.v7.preference.PreferenceCategory) DimmableIconPreference(com.android.settings.DimmableIconPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(android.support.v7.preference.Preference) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 47 with PreferenceCategory

use of android.support.v7.preference.PreferenceCategory in project android_packages_apps_Settings by crdroidandroid.

the class LocationSettings method createPreferenceHierarchy.

private PreferenceScreen createPreferenceHierarchy() {
    final SettingsActivity activity = (SettingsActivity) getActivity();
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
        root.removeAll();
    }
    addPreferencesFromResource(R.xml.location_settings);
    root = getPreferenceScreen();
    setupManagedProfileCategory(root);
    mLocationMode = root.findPreference(KEY_LOCATION_MODE);
    mLocationMode.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            activity.startPreferencePanel(LocationSettings.this, LocationMode.class.getName(), null, R.string.location_mode_screen_title, null, LocationSettings.this, 0);
            return true;
        }
    });
    RecentLocationApps recentApps = new RecentLocationApps(activity);
    List<RecentLocationApps.Request> recentLocationRequests = recentApps.getAppList();
    final AppLocationPermissionPreferenceController preferenceController = new AppLocationPermissionPreferenceController(activity);
    preferenceController.displayPreference(root);
    mCategoryRecentLocationRequests = (PreferenceCategory) root.findPreference(KEY_RECENT_LOCATION_REQUESTS);
    List<Preference> recentLocationPrefs = new ArrayList<>(recentLocationRequests.size());
    for (final RecentLocationApps.Request request : recentLocationRequests) {
        DimmableIconPreference pref = new DimmableIconPreference(getPrefContext(), request.contentDescription);
        pref.setIcon(request.icon);
        pref.setTitle(request.label);
        pref.setOnPreferenceClickListener(new PackageEntryClickedListener(request.packageName, request.userHandle));
        recentLocationPrefs.add(pref);
    }
    if (recentLocationRequests.size() > 0) {
        addPreferencesSorted(recentLocationPrefs, mCategoryRecentLocationRequests);
    } else {
        // If there's no item to display, add a "No recent apps" item.
        Preference banner = new Preference(getPrefContext());
        banner.setLayoutResource(R.layout.location_list_no_item);
        banner.setTitle(R.string.location_no_recent_apps);
        banner.setSelectable(false);
        mCategoryRecentLocationRequests.addPreference(banner);
    }
    boolean lockdownOnLocationAccess = false;
    // injected location services must not be shown.
    if (mManagedProfile != null && mUm.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, mManagedProfile)) {
        lockdownOnLocationAccess = true;
    }
    addLocationServices(activity, root, lockdownOnLocationAccess);
    refreshLocationMode();
    return root;
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) ArrayList(java.util.ArrayList) RecentLocationApps(com.android.settingslib.location.RecentLocationApps) DimmableIconPreference(com.android.settings.DimmableIconPreference) DimmableIconPreference(com.android.settings.DimmableIconPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(android.support.v7.preference.Preference) SettingsActivity(com.android.settings.SettingsActivity)

Example 48 with PreferenceCategory

use of android.support.v7.preference.PreferenceCategory in project android_packages_apps_Settings by crdroidandroid.

the class WifiDisplaySettings method buildCertificationMenu.

private void buildCertificationMenu(final PreferenceScreen preferenceScreen) {
    if (mCertCategory == null) {
        mCertCategory = new PreferenceCategory(getPrefContext());
        mCertCategory.setTitle(R.string.wifi_display_certification_heading);
        mCertCategory.setOrder(ORDER_CERTIFICATION);
    } else {
        mCertCategory.removeAll();
    }
    preferenceScreen.addPreference(mCertCategory);
    // display session info if there is an active p2p session
    if (!mWifiDisplayStatus.getSessionInfo().getGroupId().isEmpty()) {
        Preference p = new Preference(getPrefContext());
        p.setTitle(R.string.wifi_display_session_info);
        p.setSummary(mWifiDisplayStatus.getSessionInfo().toString());
        mCertCategory.addPreference(p);
        // show buttons for Pause/Resume when a WFD session is established
        if (mWifiDisplayStatus.getSessionInfo().getSessionId() != 0) {
            mCertCategory.addPreference(new Preference(getPrefContext()) {

                @Override
                public void onBindViewHolder(PreferenceViewHolder view) {
                    super.onBindViewHolder(view);
                    Button b = (Button) view.findViewById(R.id.left_button);
                    b.setText(R.string.wifi_display_pause);
                    b.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            mDisplayManager.pauseWifiDisplay();
                        }
                    });
                    b = (Button) view.findViewById(R.id.right_button);
                    b.setText(R.string.wifi_display_resume);
                    b.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            mDisplayManager.resumeWifiDisplay();
                        }
                    });
                }
            });
            mCertCategory.setLayoutResource(R.layout.two_buttons_panel);
        }
    }
    // switch for Listen Mode
    SwitchPreference pref = new SwitchPreference(getPrefContext()) {

        @Override
        protected void onClick() {
            mListen = !mListen;
            setListenMode(mListen);
            setChecked(mListen);
        }
    };
    pref.setTitle(R.string.wifi_display_listen_mode);
    pref.setChecked(mListen);
    mCertCategory.addPreference(pref);
    // switch for Autonomous GO
    pref = new SwitchPreference(getPrefContext()) {

        @Override
        protected void onClick() {
            mAutoGO = !mAutoGO;
            if (mAutoGO) {
                startAutoGO();
            } else {
                stopAutoGO();
            }
            setChecked(mAutoGO);
        }
    };
    pref.setTitle(R.string.wifi_display_autonomous_go);
    pref.setChecked(mAutoGO);
    mCertCategory.addPreference(pref);
    // Drop down list for choosing WPS method (PBC/KEYPAD/DISPLAY)
    ListPreference lp = new ListPreference(getPrefContext());
    lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
            int wpsConfig = Integer.parseInt((String) value);
            if (wpsConfig != mWpsConfig) {
                mWpsConfig = wpsConfig;
                getActivity().invalidateOptionsMenu();
                Settings.Global.putInt(getActivity().getContentResolver(), Settings.Global.WIFI_DISPLAY_WPS_CONFIG, mWpsConfig);
            }
            return true;
        }
    });
    mWpsConfig = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.WIFI_DISPLAY_WPS_CONFIG, WpsInfo.INVALID);
    String[] wpsEntries = { "Default", "PBC", "KEYPAD", "DISPLAY" };
    String[] wpsValues = { "" + WpsInfo.INVALID, "" + WpsInfo.PBC, "" + WpsInfo.KEYPAD, "" + WpsInfo.DISPLAY };
    lp.setKey("wps");
    lp.setTitle(R.string.wifi_display_wps_config);
    lp.setEntries(wpsEntries);
    lp.setEntryValues(wpsValues);
    lp.setValue("" + mWpsConfig);
    lp.setSummary("%1$s");
    mCertCategory.addPreference(lp);
    // Drop down list for choosing listen channel
    lp = new ListPreference(getPrefContext());
    lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
            int channel = Integer.parseInt((String) value);
            if (channel != mListenChannel) {
                mListenChannel = channel;
                getActivity().invalidateOptionsMenu();
                setWifiP2pChannels(mListenChannel, mOperatingChannel);
            }
            return true;
        }
    });
    String[] lcEntries = { "Auto", "1", "6", "11" };
    String[] lcValues = { "0", "1", "6", "11" };
    lp.setKey("listening_channel");
    lp.setTitle(R.string.wifi_display_listen_channel);
    lp.setEntries(lcEntries);
    lp.setEntryValues(lcValues);
    lp.setValue("" + mListenChannel);
    lp.setSummary("%1$s");
    mCertCategory.addPreference(lp);
    // Drop down list for choosing operating channel
    lp = new ListPreference(getPrefContext());
    lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
            int channel = Integer.parseInt((String) value);
            if (channel != mOperatingChannel) {
                mOperatingChannel = channel;
                getActivity().invalidateOptionsMenu();
                setWifiP2pChannels(mListenChannel, mOperatingChannel);
            }
            return true;
        }
    });
    String[] ocEntries = { "Auto", "1", "6", "11", "36" };
    String[] ocValues = { "0", "1", "6", "11", "36" };
    lp.setKey("operating_channel");
    lp.setTitle(R.string.wifi_display_operating_channel);
    lp.setEntries(ocEntries);
    lp.setEntryValues(ocValues);
    lp.setValue("" + mOperatingChannel);
    lp.setSummary("%1$s");
    mCertCategory.addPreference(lp);
}
Also used : SwitchPreference(android.support.v14.preference.SwitchPreference) ListPreference(android.support.v7.preference.ListPreference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) PreferenceCategory(android.support.v7.preference.PreferenceCategory) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) PreferenceViewHolder(android.support.v7.preference.PreferenceViewHolder)

Example 49 with PreferenceCategory

use of android.support.v7.preference.PreferenceCategory in project android_packages_apps_Settings by SudaMod.

the class EnterpriseSetDefaultAppsListPreferenceController method updateUi.

private void updateUi() {
    final Context prefContext = mParent.getPreferenceManager().getContext();
    final PreferenceScreen screen = mParent.getPreferenceScreen();
    if (screen == null) {
        return;
    }
    if (!mEnterprisePrivacyFeatureProvider.isInCompMode() && mUsers.size() == 1) {
        createPreferences(prefContext, screen, mApps.get(0));
    } else {
        for (int i = 0; i < mUsers.size(); i++) {
            final UserInfo userInfo = mUsers.get(i);
            final PreferenceCategory category = new PreferenceCategory(prefContext);
            screen.addPreference(category);
            if (userInfo.isManagedProfile()) {
                category.setTitle(R.string.managed_device_admin_title);
            } else {
                category.setTitle(R.string.personal_device_admin_title);
            }
            category.setOrder(i);
            createPreferences(prefContext, category, mApps.get(i));
        }
    }
}
Also used : Context(android.content.Context) PreferenceScreen(android.support.v7.preference.PreferenceScreen) PreferenceCategory(android.support.v7.preference.PreferenceCategory) UserInfo(android.content.pm.UserInfo)

Example 50 with PreferenceCategory

use of android.support.v7.preference.PreferenceCategory in project android_packages_apps_Settings by SudaMod.

the class WifiSettings method addPreferences.

private void addPreferences() {
    addPreferencesFromResource(R.xml.wifi_settings);
    mConnectedAccessPointPreferenceCategory = (PreferenceCategory) findPreference(PREF_KEY_CONNECTED_ACCESS_POINTS);
    mAccessPointsPreferenceCategory = (PreferenceCategory) findPreference(PREF_KEY_ACCESS_POINTS);
    mAdditionalSettingsPreferenceCategory = (PreferenceCategory) findPreference(PREF_KEY_ADDITIONAL_SETTINGS);
    mConfigureWifiSettingsPreference = findPreference(PREF_KEY_CONFIGURE_WIFI_SETTINGS);
    mSavedNetworksPreference = findPreference(PREF_KEY_SAVED_NETWORKS);
    Context prefContext = getPrefContext();
    mAddPreference = new Preference(prefContext);
    mAddPreference.setIcon(R.drawable.ic_menu_add_inset);
    mAddPreference.setTitle(R.string.wifi_add_network);
    mStatusMessagePreference = new LinkablePreference(prefContext);
    mUserBadgeCache = new AccessPointPreference.UserBadgeCache(getPackageManager());
}
Also used : Context(android.content.Context) AccessPointPreference(com.android.settingslib.wifi.AccessPointPreference) Preference(android.support.v7.preference.Preference) AccessPointPreference(com.android.settingslib.wifi.AccessPointPreference)

Aggregations

PreferenceCategory (android.support.v7.preference.PreferenceCategory)166 Preference (android.support.v7.preference.Preference)105 PreferenceScreen (android.support.v7.preference.PreferenceScreen)75 Intent (android.content.Intent)35 Context (android.content.Context)34 SwitchPreference (android.support.v14.preference.SwitchPreference)31 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)27 ArrayList (java.util.ArrayList)24 ComponentName (android.content.ComponentName)22 ListPreference (android.support.v7.preference.ListPreference)18 Bundle (android.os.Bundle)16 PreferenceGroup (android.support.v7.preference.PreferenceGroup)14 DimmableIconPreference (com.android.settings.DimmableIconPreference)14 ContentResolver (android.content.ContentResolver)13 LayoutPreference (com.android.settings.applications.LayoutPreference)13 PreferenceManager (android.support.v7.preference.PreferenceManager)12 MasterSwitchPreference (com.android.settings.widget.MasterSwitchPreference)12 FooterPreference (com.android.settingslib.widget.FooterPreference)12 Test (org.junit.Test)12 Activity (android.app.Activity)9