Search in sources :

Example 46 with Preference

use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class OmniSwitch method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.omniswitch);
    PreferenceScreen prefSet = getPreferenceScreen();
    ContentResolver resolver = getActivity().getContentResolver();
    mOmniSwitchSettings = (Preference) prefSet.findPreference(OMNISWITCH_START_SETTINGS);
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) ContentResolver(android.content.ContentResolver)

Example 47 with Preference

use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ActionFragment method onPreferenceScreenLoaded.

/**
     * load our button lists and ActionPreferences map button action targets from preference keys
     * and defaults config maps subclass is required to set desired Defaults interface int
     * ActionContants
     */
protected void onPreferenceScreenLoaded(Defaults defaults) {
    mDefaults = defaults;
    final PreferenceScreen prefScreen = getPreferenceScreen();
    for (int i = 0; i < prefScreen.getPreferenceCount(); i++) {
        Preference pref = prefScreen.getPreference(i);
        if (pref instanceof PreferenceCategory) {
            PreferenceCategory cat = (PreferenceCategory) pref;
            for (int j = 0; j < cat.getPreferenceCount(); j++) {
                Preference child = cat.getPreference(j);
                if (child instanceof ActionPreference) {
                    mPrefHolder.add((ActionPreference) child);
                }
            }
        } else if (pref instanceof ActionPreference) {
            mPrefHolder.add((ActionPreference) pref);
        }
    }
    loadAndSetConfigs();
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) ActionPreference(com.android.settings.rr.Preferences.ActionPreference) Preference(android.support.v7.preference.Preference) PreferenceCategory(android.support.v7.preference.PreferenceCategory) ActionPreference(com.android.settings.rr.Preferences.ActionPreference)

Example 48 with Preference

use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ManageAccountsSettings method updatePreferenceIntents.

/**
     * Filters through the preference list provided by GoogleLoginService.
     *
     * This method removes all the invalid intent from the list, adds account name as extra into the
     * intent, and hack the location settings to start it as a fragment.
     */
private void updatePreferenceIntents(PreferenceScreen prefs) {
    final PackageManager pm = getActivity().getPackageManager();
    for (int i = 0; i < prefs.getPreferenceCount(); ) {
        Preference pref = prefs.getPreference(i);
        Intent intent = pref.getIntent();
        if (intent != null) {
            // preference click event here directly.
            if (intent.getAction().equals(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)) {
                // The OnPreferenceClickListener overrides the click event completely. No intent
                // will get fired.
                pref.setOnPreferenceClickListener(new FragmentStarter(LocationSettings.class.getName(), R.string.location_settings_title));
            } else {
                ResolveInfo ri = pm.resolveActivityAsUser(intent, PackageManager.MATCH_DEFAULT_ONLY, mUserHandle.getIdentifier());
                if (ri == null) {
                    prefs.removePreference(pref);
                    continue;
                } else {
                    intent.putExtra(ACCOUNT_KEY, mFirstAccount);
                    intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                    pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                        @Override
                        public boolean onPreferenceClick(Preference preference) {
                            Intent prefIntent = preference.getIntent();
                            /*
                                 * Check the intent to see if it resolves to a exported=false
                                 * activity that doesn't share a uid with the authenticator.
                                 *
                                 * Otherwise the intent is considered unsafe in that it will be
                                 * exploiting the fact that settings has system privileges.
                                 */
                            if (isSafeIntent(pm, prefIntent)) {
                                getActivity().startActivityAsUser(prefIntent, mUserHandle);
                            } else {
                                Log.e(TAG, "Refusing to launch authenticator intent because" + "it exploits Settings permissions: " + prefIntent);
                            }
                            return true;
                        }
                    });
                }
            }
        }
        i++;
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) PackageManager(android.content.pm.PackageManager) AccountPreference(com.android.settings.AccountPreference) Preference(android.support.v7.preference.Preference) Intent(android.content.Intent)

Example 49 with Preference

use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppLaunchSettings method buildStateDropDown.

private void buildStateDropDown() {
    if (mIsBrowser) {
        // Browsers don't show the app-link prefs
        mAppLinkState.setShouldDisableView(true);
        mAppLinkState.setEnabled(false);
        mAppDomainUrls.setShouldDisableView(true);
        mAppDomainUrls.setEnabled(false);
    } else {
        // Designed order of states in the dropdown:
        //
        // * always
        // * ask
        // * never
        mAppLinkState.setEntries(new CharSequence[] { getString(R.string.app_link_open_always), getString(R.string.app_link_open_ask), getString(R.string.app_link_open_never) });
        mAppLinkState.setEntryValues(new CharSequence[] { Integer.toString(INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS), Integer.toString(INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK), Integer.toString(INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER) });
        mAppLinkState.setEnabled(mHasDomainUrls);
        if (mHasDomainUrls) {
            // Present 'undefined' as 'ask' because the OS treats them identically for
            // purposes of the UI (and does the right thing around pending domain
            // verifications that might arrive after the user chooses 'ask' in this UI).
            final int state = mPm.getIntentVerificationStatusAsUser(mPackageName, UserHandle.myUserId());
            mAppLinkState.setValue(Integer.toString((state == INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED) ? INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK : state));
            // Set the callback only after setting the initial selected item
            mAppLinkState.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    return updateAppLinkState(Integer.parseInt((String) newValue));
                }
            });
        }
    }
}
Also used : Preference(android.support.v7.preference.Preference) DropDownPreference(android.support.v7.preference.DropDownPreference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

Example 50 with Preference

use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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(LocationMode.class.getName(), null, R.string.location_mode_screen_title, null, LocationSettings.this, 0);
            return true;
        }
    });
    mAgpsEnabled = getActivity().getResources().getBoolean(R.bool.config_agps_enabled);
    mAssistedGps = (CheckBoxPreference) root.findPreference(KEY_ASSISTED_GPS);
    if (!mAgpsEnabled) {
        root.removePreference(mAssistedGps);
    }
    if (mAssistedGps != null) {
        mAssistedGps.setChecked(Settings.Global.getInt(getContentResolver(), Settings.Global.ASSISTED_GPS_ENABLED, 0) == 1);
    }
    mCategoryRecentLocationRequests = (PreferenceCategory) root.findPreference(KEY_RECENT_LOCATION_REQUESTS);
    RecentLocationApps recentApps = new RecentLocationApps(activity);
    List<RecentLocationApps.Request> recentLocationRequests = recentApps.getAppList();
    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);
        if (request.isHighBattery) {
            pref.setSummary(R.string.location_high_battery_use);
        } else {
            pref.setSummary(R.string.location_low_battery_use);
        }
        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) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) DimmableIconPreference(com.android.settings.DimmableIconPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(android.support.v7.preference.Preference) SettingsActivity(com.android.settings.SettingsActivity)

Aggregations

Preference (android.support.v7.preference.Preference)122 PreferenceScreen (android.support.v7.preference.PreferenceScreen)44 SwitchPreference (android.support.v14.preference.SwitchPreference)33 Intent (android.content.Intent)27 ListPreference (android.support.v7.preference.ListPreference)27 Context (android.content.Context)17 PreferenceCategory (android.support.v7.preference.PreferenceCategory)17 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)15 ArrayList (java.util.ArrayList)14 PackageManager (android.content.pm.PackageManager)11 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)11 PreferenceGroup (android.support.v7.preference.PreferenceGroup)11 TwoStatePreference (android.support.v7.preference.TwoStatePreference)11 Activity (android.app.Activity)10 View (android.view.View)10 Bundle (android.os.Bundle)9 TextView (android.widget.TextView)8 AlertDialog (android.support.v7.app.AlertDialog)7 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)7 DimmableIconPreference (com.android.settings.DimmableIconPreference)7