Search in sources :

Example 6 with SwitchPreference

use of android.support.v14.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ZenModePrioritySettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.zen_mode_priority_settings);
    final PreferenceScreen root = getPreferenceScreen();
    mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
    mReminders = (SwitchPreference) root.findPreference(KEY_REMINDERS);
    mReminders.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (mDisableListeners)
                return true;
            final boolean val = (Boolean) newValue;
            MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_REMINDERS, val);
            if (DEBUG)
                Log.d(TAG, "onPrefChange allowReminders=" + val);
            savePolicy(getNewPriorityCategories(val, Policy.PRIORITY_CATEGORY_REMINDERS), mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
            return true;
        }
    });
    mEvents = (SwitchPreference) root.findPreference(KEY_EVENTS);
    mEvents.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (mDisableListeners)
                return true;
            final boolean val = (Boolean) newValue;
            MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_EVENTS, val);
            if (DEBUG)
                Log.d(TAG, "onPrefChange allowEvents=" + val);
            savePolicy(getNewPriorityCategories(val, Policy.PRIORITY_CATEGORY_EVENTS), mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
            return true;
        }
    });
    mMessages = (DropDownPreference) root.findPreference(KEY_MESSAGES);
    addSources(mMessages);
    mMessages.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (mDisableListeners)
                return false;
            final int val = Integer.parseInt((String) newValue);
            final boolean allowMessages = val != SOURCE_NONE;
            final int allowMessagesFrom = val == SOURCE_NONE ? mPolicy.priorityMessageSenders : val;
            MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_MESSAGES, val);
            if (DEBUG)
                Log.d(TAG, "onPrefChange allowMessages=" + allowMessages + " allowMessagesFrom=" + ZenModeConfig.sourceToString(allowMessagesFrom));
            savePolicy(getNewPriorityCategories(allowMessages, Policy.PRIORITY_CATEGORY_MESSAGES), mPolicy.priorityCallSenders, allowMessagesFrom, mPolicy.suppressedVisualEffects);
            return true;
        }
    });
    mCalls = (DropDownPreference) root.findPreference(KEY_CALLS);
    addSources(mCalls);
    mCalls.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (mDisableListeners)
                return false;
            final int val = Integer.parseInt((String) newValue);
            final boolean allowCalls = val != SOURCE_NONE;
            final int allowCallsFrom = val == SOURCE_NONE ? mPolicy.priorityCallSenders : val;
            MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_CALLS, val);
            if (DEBUG)
                Log.d(TAG, "onPrefChange allowCalls=" + allowCalls + " allowCallsFrom=" + ZenModeConfig.sourceToString(allowCallsFrom));
            savePolicy(getNewPriorityCategories(allowCalls, Policy.PRIORITY_CATEGORY_CALLS), allowCallsFrom, mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
            return true;
        }
    });
    mRepeatCallers = (SwitchPreference) root.findPreference(KEY_REPEAT_CALLERS);
    mRepeatCallers.setSummary(mContext.getString(R.string.zen_mode_repeat_callers_summary, mContext.getResources().getInteger(com.android.internal.R.integer.config_zen_repeat_callers_threshold)));
    mRepeatCallers.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (mDisableListeners)
                return true;
            final boolean val = (Boolean) newValue;
            MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_REPEAT_CALLS, val);
            if (DEBUG)
                Log.d(TAG, "onPrefChange allowRepeatCallers=" + val);
            int priorityCategories = getNewPriorityCategories(val, NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS);
            savePolicy(priorityCategories, mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
            return true;
        }
    });
    updateControls();
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) DropDownPreference(android.support.v7.preference.DropDownPreference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

Example 7 with SwitchPreference

use of android.support.v14.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DisplaySettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Activity activity = getActivity();
    final ContentResolver resolver = activity.getContentResolver();
    addPreferencesFromResource(R.xml.display_settings);
    PreferenceCategory displayPrefs = (PreferenceCategory) findPreference(KEY_CATEGORY_DISPLAY);
    mScreenSaverPreference = findPreference(KEY_SCREEN_SAVER);
    if (mScreenSaverPreference != null && getResources().getBoolean(com.android.internal.R.bool.config_dreamsSupported) == false) {
        getPreferenceScreen().removePreference(mScreenSaverPreference);
    }
    mScreenTimeoutPreference = (TimeoutListPreference) findPreference(KEY_SCREEN_TIMEOUT);
    if (displayPrefs != null) {
        mAutoBrightnessPreference = (SwitchPreference) findPreference(KEY_AUTO_BRIGHTNESS);
        if (mAutoBrightnessPreference != null) {
            if (isAutomaticBrightnessAvailable(getResources())) {
                mAutoBrightnessPreference.setOnPreferenceChangeListener(this);
            } else {
                displayPrefs.removePreference(mAutoBrightnessPreference);
            }
        }
        if (!NightDisplayController.isAvailable(activity)) {
            removePreference(KEY_NIGHT_DISPLAY);
        }
        mLiftToWakePreference = (SwitchPreference) findPreference(KEY_LIFT_TO_WAKE);
        if (mLiftToWakePreference != null) {
            if (isLiftToWakeAvailable(activity)) {
                mLiftToWakePreference.setOnPreferenceChangeListener(this);
            } else {
                displayPrefs.removePreference(mLiftToWakePreference);
            }
        }
        mTapToWakePreference = (SwitchPreference) findPreference(KEY_TAP_TO_WAKE);
        if (mTapToWakePreference != null) {
            if (isTapToWakeAvailable(getResources())) {
                mTapToWakePreference.setOnPreferenceChangeListener(this);
            } else {
                displayPrefs.removePreference(mTapToWakePreference);
            }
        }
        mCameraGesturePreference = (SwitchPreference) findPreference(KEY_CAMERA_GESTURE);
        if (mCameraGesturePreference != null) {
            if (isCameraGestureAvailable(getResources())) {
                mCameraGesturePreference.setOnPreferenceChangeListener(this);
            } else {
                displayPrefs.removePreference(mCameraGesturePreference);
            }
        }
        DropDownPreference rotatePreference = (DropDownPreference) findPreference(KEY_AUTO_ROTATE);
        if (rotatePreference != null) {
            if (RotationPolicy.isRotationLockToggleVisible(activity)) {
                int rotateLockedResourceId;
                // rotation), then we use a different string to include this information.
                if (allowAllRotations(activity)) {
                    rotateLockedResourceId = R.string.display_auto_rotate_stay_in_current;
                } else {
                    if (RotationPolicy.getRotationLockOrientation(activity) == Configuration.ORIENTATION_PORTRAIT) {
                        rotateLockedResourceId = R.string.display_auto_rotate_stay_in_portrait;
                    } else {
                        rotateLockedResourceId = R.string.display_auto_rotate_stay_in_landscape;
                    }
                }
                rotatePreference.setEntries(new CharSequence[] { activity.getString(R.string.display_auto_rotate_rotate), activity.getString(rotateLockedResourceId) });
                rotatePreference.setEntryValues(new CharSequence[] { "0", "1" });
                rotatePreference.setValueIndex(RotationPolicy.isRotationLocked(activity) ? 1 : 0);
                rotatePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        final boolean locked = Integer.parseInt((String) newValue) != 0;
                        MetricsLogger.action(getActivity(), MetricsEvent.ACTION_ROTATION_LOCK, locked);
                        RotationPolicy.setRotationLock(activity, locked);
                        return true;
                    }
                });
            } else {
                displayPrefs.removePreference(rotatePreference);
            }
        }
        DropDownPreference vrDisplayPref = (DropDownPreference) findPreference(KEY_VR_DISPLAY_PREF);
        if (vrDisplayPref != null) {
            if (isVrDisplayModeAvailable(activity)) {
                vrDisplayPref.setEntries(new CharSequence[] { activity.getString(R.string.display_vr_pref_low_persistence), activity.getString(R.string.display_vr_pref_off) });
                vrDisplayPref.setEntryValues(new CharSequence[] { "0", "1" });
                final Context c = activity;
                int currentUser = ActivityManager.getCurrentUser();
                int current = Settings.Secure.getIntForUser(c.getContentResolver(), Settings.Secure.VR_DISPLAY_MODE, /*default*/
                Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE, currentUser);
                vrDisplayPref.setValueIndex(current);
                vrDisplayPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        int i = Integer.parseInt((String) newValue);
                        int u = ActivityManager.getCurrentUser();
                        if (!Settings.Secure.putIntForUser(c.getContentResolver(), Settings.Secure.VR_DISPLAY_MODE, i, u)) {
                            Log.e(TAG, "Could not change setting for " + Settings.Secure.VR_DISPLAY_MODE);
                        }
                        return true;
                    }
                });
            } else {
                displayPrefs.removePreference(vrDisplayPref);
            }
        }
    }
    mNightModePreference = (ListPreference) findPreference(KEY_NIGHT_MODE);
    if (mNightModePreference != null) {
        final UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
        final int currentNightMode = uiManager.getNightMode();
        mNightModePreference.setValue(String.valueOf(currentNightMode));
        mNightModePreference.setOnPreferenceChangeListener(this);
    }
}
Also used : Context(android.content.Context) PreferenceCategory(android.support.v7.preference.PreferenceCategory) RestrictedPreference(com.android.settingslib.RestrictedPreference) DropDownPreference(android.support.v7.preference.DropDownPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) UiModeManager(android.app.UiModeManager) Activity(android.app.Activity) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener) ContentResolver(android.content.ContentResolver) DropDownPreference(android.support.v7.preference.DropDownPreference)

Example 8 with SwitchPreference

use of android.support.v14.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WirelessSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
    }
    log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
    mContext = getActivity();
    mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mPm = getPackageManager();
    mUm = (UserManager) getSystemService(Context.USER_SERVICE);
    addPreferencesFromResource(R.xml.wireless_settings);
    final boolean isAdmin = mUm.isAdminUser();
    final Activity activity = getActivity();
    mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
    SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
    RestrictedPreference androidBeam = (RestrictedPreference) findPreference(KEY_ANDROID_BEAM_SETTINGS);
    PreferenceScreen nfcPayment = (PreferenceScreen) findPreference(KEY_NFC_PAYMENT_SETTINGS);
    PreferenceCategory nfcCategory = (PreferenceCategory) findPreference(KEY_NFC_CATEGORY_SETTINGS);
    mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
    mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam, nfcPayment);
    mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
    String toggleable = Settings.Global.getString(activity.getContentResolver(), Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
    //enable/disable wimax depending on the value in config.xml
    final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean(com.android.internal.R.bool.config_wimaxEnabled);
    if (!isWimaxEnabled || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
        PreferenceScreen root = getPreferenceScreen();
        Preference ps = findPreference(KEY_WIMAX_SETTINGS);
        if (ps != null)
            root.removePreference(ps);
    } else {
        if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX) && isWimaxEnabled) {
            Preference ps = findPreference(KEY_WIMAX_SETTINGS);
            ps.setDependency(KEY_TOGGLE_AIRPLANE);
        }
    }
    // Manually set dependencies for Wifi when not toggleable.
    if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
        findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
    }
    // TODO: http://b/23693383
    if (!isAdmin || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_VPN, UserHandle.myUserId())) {
        removePreference(KEY_VPN_SETTINGS);
    }
    // Manually set dependencies for Bluetooth when not toggleable.
    if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
    // No bluetooth-dependent items in the list. Code kept in case one is added later.
    }
    // Manually set dependencies for NFC when not toggleable.
    if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
        findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
        findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
        findPreference(KEY_NFC_PAYMENT_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
    }
    // Remove NFC if not available
    mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
    if (mNfcAdapter == null) {
        getPreferenceScreen().removePreference(nfcCategory);
        mNfcEnabler = null;
    } else if (!mPm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
        // Only show if we have the HCE feature
        nfcCategory.removePreference(nfcPayment);
    }
    // if it's a wifi-only device, or for MSIM devices
    if (!isAdmin || Utils.isWifiOnly(getActivity()) || Utils.showSimCardTile(getActivity()) || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
        removePreference(KEY_MOBILE_NETWORK_SETTINGS);
        removePreference(KEY_MANAGE_MOBILE_PLAN);
    }
    // Remove Mobile Network Settings and Manage Mobile Plan
    // if config_show_mobile_plan sets false.
    final boolean isMobilePlanEnabled = this.getResources().getBoolean(R.bool.config_show_mobile_plan);
    if (!isMobilePlanEnabled) {
        Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
        if (pref != null) {
            removePreference(KEY_MANAGE_MOBILE_PLAN);
        }
    }
    // Remove Airplane Mode settings if it's a stationary device such as a TV.
    if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
        removePreference(KEY_TOGGLE_AIRPLANE);
    }
    // Enable Proxy selector settings if allowed.
    Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
    final DevicePolicyManager mDPM = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    // proxy UI disabled until we have better app support
    getPreferenceScreen().removePreference(mGlobalProxy);
    mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
    // Disable Tethering if it's not allowed or if it's a wifi-only device
    final ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    final boolean adminDisallowedTetherConfig = RestrictedLockUtils.checkIfRestrictionEnforced(activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
    if ((!cm.isTetheringSupported() && !adminDisallowedTetherConfig) || RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
        getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
    } else if (!adminDisallowedTetherConfig) {
        Preference p = findPreference(KEY_TETHER_SETTINGS);
        p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));
        // Grey out if provisioning is not available.
        p.setEnabled(!TetherSettings.isProvisioningNeededButUnavailable(getActivity()));
    }
    // Remove network reset if not allowed
    if (RestrictedLockUtils.hasBaseUserRestriction(activity, UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId())) {
        removePreference(KEY_NETWORK_RESET);
    }
    // Enable link to CMAS app settings depending on the value in config.xml.
    boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(com.android.internal.R.bool.config_cellBroadcastAppLinks);
    try {
        if (isCellBroadcastAppLinkEnabled) {
            if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver") == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
                // CMAS app disabled
                isCellBroadcastAppLinkEnabled = false;
            }
        }
    } catch (IllegalArgumentException ignored) {
        // CMAS app not installed
        isCellBroadcastAppLinkEnabled = false;
    }
    if (!mUm.isAdminUser() || !isCellBroadcastAppLinkEnabled || RestrictedLockUtils.hasBaseUserRestriction(mContext, UserManager.DISALLOW_CONFIG_CELL_BROADCASTS, UserHandle.myUserId())) {
        removePreference(KEY_CELL_BROADCAST_SETTINGS);
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SwitchPreference(android.support.v14.preference.SwitchPreference) NfcEnabler(com.android.settings.nfc.NfcEnabler) ConnectivityManager(android.net.ConnectivityManager) Activity(android.app.Activity) RestrictedPreference(com.android.settingslib.RestrictedPreference) PreferenceCategory(android.support.v7.preference.PreferenceCategory) RestrictedPreference(com.android.settingslib.RestrictedPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference)

Example 9 with SwitchPreference

use of android.support.v14.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ScreenPinningSettings method updateDisplay.

public void updateDisplay() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
        root.removeAll();
    }
    if (isLockToAppEnabled(getActivity())) {
        addPreferencesFromResource(R.xml.screen_pinning_settings);
        root = getPreferenceScreen();
        mUseScreenLock = (SwitchPreference) root.findPreference(KEY_USE_SCREEN_LOCK);
        mUseScreenLock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                return setScreenLockUsed((boolean) newValue);
            }
        });
        mUseScreenLock.setChecked(isScreenLockUsed());
        mUseScreenLock.setTitle(getCurrentSecurityTitle());
    }
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

Example 10 with SwitchPreference

use of android.support.v14.preference.SwitchPreference 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)

Aggregations

SwitchPreference (android.support.v14.preference.SwitchPreference)30 Preference (android.support.v7.preference.Preference)16 PreferenceScreen (android.support.v7.preference.PreferenceScreen)16 Context (android.content.Context)8 ContentResolver (android.content.ContentResolver)7 ListPreference (android.support.v7.preference.ListPreference)7 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)6 PreferenceCategory (android.support.v7.preference.PreferenceCategory)5 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)5 RestrictedPreference (com.android.settingslib.RestrictedPreference)4 Activity (android.app.Activity)3 Intent (android.content.Intent)3 PreferenceGroup (android.support.v7.preference.PreferenceGroup)3 PackageItemInfo (android.content.pm.PackageItemInfo)2 Settings (android.provider.Settings)2 DropDownPreference (android.support.v7.preference.DropDownPreference)2 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)2 ArrayList (java.util.ArrayList)2 FragmentManager (android.app.FragmentManager)1 UiModeManager (android.app.UiModeManager)1