Search in sources :

Example 61 with Preference

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

the class AdvancedWifiSettings method initPreferences.

private void initPreferences() {
    final Context context = getActivity();
    Intent intent = new Intent(Credentials.INSTALL_AS_USER_ACTION);
    intent.setClassName("com.android.certinstaller", "com.android.certinstaller.CertInstallerMain");
    intent.putExtra(Credentials.EXTRA_INSTALL_AS_UID, android.os.Process.WIFI_UID);
    Preference pref = findPreference(KEY_INSTALL_CREDENTIALS);
    pref.setIntent(intent);
    SwitchPreference enableHs2 = (SwitchPreference) findPreference(KEY_ENABLE_HS2);
    if (enableHs2 != null && getResources().getBoolean(com.android.internal.R.bool.config_passpoint_setting_on)) {
        enableHs2.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            public boolean onPreferenceClick(Preference preference) {
                String key = preference.getKey();
                if (KEY_ENABLE_HS2.equals(key)) {
                    Settings.Global.putInt(getContentResolver(), Settings.Global.WIFI_HOTSPOT2_ENABLED, ((SwitchPreference) preference).isChecked() ? 1 : 0);
                }
                return true;
            }
        });
        enableHs2.setChecked(Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_HOTSPOT2_ENABLED, WIFI_HS2_DISABLED) == WIFI_HS2_ENABLED);
    } else {
        if (enableHs2 != null) {
            getPreferenceScreen().removePreference(enableHs2);
        }
    }
    Intent wifiDirectIntent = new Intent(context, com.android.settings.Settings.WifiP2pSettingsActivity.class);
    Preference wifiDirectPref = findPreference(KEY_WIFI_DIRECT);
    wifiDirectPref.setIntent(wifiDirectIntent);
    // WpsDialog: Create the dialog like WifiSettings does.
    Preference wpsPushPref = findPreference(KEY_WPS_PUSH);
    wpsPushPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference arg0) {
            WpsFragment wpsFragment = new WpsFragment(WpsInfo.PBC);
            wpsFragment.show(getFragmentManager(), KEY_WPS_PUSH);
            return true;
        }
    });
    // WpsDialog: Create the dialog like WifiSettings does.
    Preference wpsPinPref = findPreference(KEY_WPS_PIN);
    wpsPinPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference arg0) {
            WpsFragment wpsFragment = new WpsFragment(WpsInfo.DISPLAY);
            wpsFragment.show(getFragmentManager(), KEY_WPS_PIN);
            return true;
        }
    });
    // Wifi extension requirement
    Preference prioritySettingPref = findPreference(KEY_PRIORITY_SETTINGS);
    if (prioritySettingPref != null) {
        if (!getResources().getBoolean(R.bool.set_wifi_priority)) {
            getPreferenceScreen().removePreference(prioritySettingPref);
        }
    } else {
        Log.d(TAG, "Fail to get priority pref...");
    }
    ListPreference ccodePref = (ListPreference) findPreference(KEY_COUNTRY_CODE);
    if (ccodePref != null) {
        boolean hideWifiRegion = getResources().getBoolean(R.bool.config_hideWifiRegionCode);
        if (hideWifiRegion) {
            removePreference(KEY_COUNTRY_CODE);
        } else {
            ccodePref.setOnPreferenceChangeListener(this);
            String value = mWifiManager.getCountryCode();
            if (value != null) {
                ccodePref.setValue(value);
            } else {
                Log.e(TAG, "Failed to fetch country code");
            }
        }
    }
    mAutoConnectEnablePref = (CheckBoxPreference) findPreference(KEY_AUTO_CONNECT_ENABLE);
    if (mAutoConnectEnablePref != null) {
        if (getResources().getBoolean(R.bool.config_auto_connect_wifi_enabled)) {
            mAutoConnectEnablePref.setChecked(isAutoConnectEnabled());
            mAutoConnectEnablePref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(mAutoConnectEnablePref);
        }
    }
    mCellularToWlanPref = (ListPreference) findPreference(KEY_CELLULAR_TO_WLAN);
    if (mCellularToWlanPref != null) {
        if (getResources().getBoolean(R.bool.cell_to_wifi)) {
            int value = getCellularToWlanValue();
            mCellularToWlanPref.setValue(String.valueOf(value));
            updateCellToWlanSummary(mCellularToWlanPref, value);
            mCellularToWlanPref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(mCellularToWlanPref);
        }
    }
    CheckBoxPreference wlanToCellularHintPref = (CheckBoxPreference) findPreference(KEY_WLAN_TO_CELLULAR_HINT);
    if (wlanToCellularHintPref != null) {
        if (getResources().getBoolean(R.bool.wifi_to_cell)) {
            wlanToCellularHintPref.setChecked(isWlanToCellHintEnable());
            wlanToCellularHintPref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(wlanToCellularHintPref);
        }
    }
    CheckBoxPreference notifyConnectedApPref = (CheckBoxPreference) findPreference(KEY_CONNECT_NOTIFY);
    if (notifyConnectedApPref != null) {
        if (getResources().getBoolean(R.bool.connect_to_cmcc_notify)) {
            notifyConnectedApPref.setChecked(ifNotifyConnect());
            notifyConnectedApPref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(notifyConnectedApPref);
        }
    }
    mCellularToWlanHintPref = (CheckBoxPreference) findPreference(KEY_CELLULAR_TO_WLAN_HINT);
    if (mCellularToWlanHintPref != null) {
        if (getResources().getBoolean(R.bool.cellular_to_wlan_hint)) {
            mCellularToWlanHintPref.setChecked(isCellularToWlanHintEnable());
            mCellularToWlanHintPref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(mCellularToWlanHintPref);
        }
    }
}
Also used : Context(android.content.Context) SwitchPreference(android.support.v14.preference.SwitchPreference) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) Intent(android.content.Intent) ListPreference(android.support.v7.preference.ListPreference) OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) Settings(android.provider.Settings)

Example 62 with Preference

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

the class DeveloperPreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    mViewHolder = holder;
    if (donateLink != null) {
        final OnClickListener openDonate = new OnClickListener() {

            @Override
            public void onClick(View v) {
                Uri donateURL = Uri.parse(donateLink);
                final Intent intent = new Intent(Intent.ACTION_VIEW, donateURL);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                getContext().startActivity(intent);
            }
        };
        donateButton.setOnClickListener(openDonate);
    } else {
        donateButton.setVisibility(View.GONE);
    }
    final OnPreferenceClickListener opengplus = new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (gplusName != null) {
                Uri gplusURL = Uri.parse("https://plus.google.com/+" + gplusName);
                final Intent intent = new Intent(Intent.ACTION_VIEW, gplusURL);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                getContext().startActivity(intent);
            }
            return true;
        }
    };
    // changed to clicking the preference to open gplus
    // it was a hit or miss to click the gplus icon
    this.setOnPreferenceClickListener(opengplus);
    UrlImageViewHelper.setUrlDrawable(this.photoView, getGravatarUrl(devEmail), R.drawable.ic_null, UrlImageViewHelper.CACHE_DURATION_ONE_WEEK);
    if (gplusName == null)
        gplusButton.setVisibility(View.INVISIBLE);
    devName.setText(nameDev);
}
Also used : Preference(android.support.v7.preference.Preference) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri)

Example 63 with Preference

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

the class ConfigureWifiSettings method initPreferences.

private void initPreferences() {
    List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
    if (configs == null || configs.size() == 0) {
        removePreference(KEY_SAVED_NETWORKS);
    }
    if (!mWifiManager.hasCarrierConfiguredNetworks()) {
        removePreference(KEY_CONNECT_CARRIER_NETWORKS);
    } else {
        SwitchPreference connectToCarrierNetworks = (SwitchPreference) findPreference(KEY_CONNECT_CARRIER_NETWORKS);
        if (connectToCarrierNetworks != null) {
            connectToCarrierNetworks.setChecked(Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_CONNECT_CARRIER_NETWORKS, 0) == 1);
        }
    }
    SwitchPreference notifyOpenNetworks = (SwitchPreference) findPreference(KEY_NOTIFY_OPEN_NETWORKS);
    notifyOpenNetworks.setChecked(Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1);
    notifyOpenNetworks.setEnabled(mWifiManager.isWifiEnabled());
    final Context context = getActivity();
    if (avoidBadWifiConfig()) {
        // Hide preference toggle, always avoid bad wifi networks.
        removePreference(KEY_CELLULAR_FALLBACK);
    } else {
        // Show preference toggle, initialized based on current settings value.
        boolean currentSetting = avoidBadWifiCurrentSettings();
        SwitchPreference pref = (SwitchPreference) findPreference(KEY_CELLULAR_FALLBACK);
        // change if the resources change, but if that happens the activity will be recreated...
        if (pref != null) {
            pref.setChecked(currentSetting);
        }
    }
    mWifiAssistantPreference = (AppListSwitchPreference) findPreference(KEY_WIFI_ASSISTANT);
    Collection<NetworkScorerAppManager.NetworkScorerAppData> scorers = NetworkScorerAppManager.getAllValidScorers(context);
    if (UserManager.get(context).isAdminUser() && !scorers.isEmpty()) {
        mWifiAssistantPreference.setOnPreferenceChangeListener(this);
        initWifiAssistantPreference(scorers);
    } else if (mWifiAssistantPreference != null) {
        getPreferenceScreen().removePreference(mWifiAssistantPreference);
    }
    ListPreference sleepPolicyPref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
    if (sleepPolicyPref != null) {
        if (Utils.isWifiOnly(context)) {
            sleepPolicyPref.setEntries(R.array.wifi_sleep_policy_entries_wifi_only);
        }
        sleepPolicyPref.setOnPreferenceChangeListener(this);
        int value = Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_SLEEP_POLICY, Settings.Global.WIFI_SLEEP_POLICY_NEVER);
        String stringValue = String.valueOf(value);
        sleepPolicyPref.setValue(stringValue);
        updateSleepPolicySummary(sleepPolicyPref, stringValue);
    }
}
Also used : Context(android.content.Context) WifiConfiguration(android.net.wifi.WifiConfiguration) AppListSwitchPreference(com.android.settings.AppListSwitchPreference) SwitchPreference(android.support.v14.preference.SwitchPreference) ListPreference(android.support.v7.preference.ListPreference)

Example 64 with Preference

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

the class DevelopmentSettings method setPrefsEnabledState.

private void setPrefsEnabledState(boolean enabled) {
    for (int i = 0; i < mAllPrefs.size(); i++) {
        Preference pref = mAllPrefs.get(i);
        pref.setEnabled(enabled && !mDisabledPrefs.contains(pref));
    }
    updateAllOptions();
}
Also used : ListPreference(android.support.v7.preference.ListPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference)

Example 65 with Preference

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

the class TrustAgentSettings method updateAgents.

private void updateAgents() {
    final Context context = getActivity();
    if (mAvailableAgents == null) {
        mAvailableAgents = findAvailableTrustAgents();
    }
    if (mLockPatternUtils == null) {
        mLockPatternUtils = new LockPatternUtils(getActivity());
    }
    loadActiveAgents();
    PreferenceGroup category = (PreferenceGroup) getPreferenceScreen().findPreference("trust_agents");
    category.removeAll();
    final EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(context, DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS, UserHandle.myUserId());
    final int count = mAvailableAgents.size();
    for (int i = 0; i < count; i++) {
        AgentInfo agent = mAvailableAgents.valueAt(i);
        final RestrictedSwitchPreference preference = new RestrictedSwitchPreference(getPrefContext());
        preference.useAdminDisabledSummary(true);
        agent.preference = preference;
        preference.setPersistent(false);
        preference.setTitle(agent.label);
        preference.setIcon(agent.icon);
        preference.setPersistent(false);
        preference.setOnPreferenceChangeListener(this);
        preference.setChecked(mActiveAgents.contains(agent.component));
        if (admin != null && mDpm.getTrustAgentConfiguration(null, agent.component) == null) {
            preference.setChecked(false);
            preference.setDisabledByAdmin(admin);
        }
        category.addPreference(agent.preference);
    }
}
Also used : Context(android.content.Context) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) LockPatternUtils(com.android.internal.widget.LockPatternUtils) PreferenceGroup(android.support.v7.preference.PreferenceGroup) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)

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