Search in sources :

Example 21 with SwitchPreference

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

the class DevelopmentSettings method resetDangerousOptions.

private void resetDangerousOptions() {
    mDontPokeProperties = true;
    for (int i = 0; i < mResetSwitchPrefs.size(); i++) {
        SwitchPreference cb = mResetSwitchPrefs.get(i);
        if (cb.isChecked()) {
            cb.setChecked(false);
            onPreferenceTreeClick(cb);
        }
    }
    resetDebuggerOptions();
    writeLogpersistOption(null, true);
    writeLogdSizeOption(null);
    resetRootAccessOptions();
    resetAdbNotifyOptions();
    writeAnimationScaleOption(0, mWindowAnimationScale, null);
    writeAnimationScaleOption(1, mTransitionAnimationScale, null);
    writeAnimationScaleOption(2, mAnimatorDurationScale, null);
    // Only poke the color space setting if we control it.
    if (usingDevelopmentColorSpace()) {
        writeSimulateColorSpace(-1);
    }
    writeOverlayDisplayDevicesOptions(null);
    writeAppProcessLimitOptions(null);
    mHaveDebugSettings = false;
    updateAllOptions();
    mDontPokeProperties = false;
    pokeSystemProperties();
}
Also used : RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) SwitchPreference(android.support.v14.preference.SwitchPreference)

Example 22 with SwitchPreference

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

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 23 with SwitchPreference

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

the class BatterySettings method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    ContentResolver resolver = getActivity().getContentResolver();
    boolean value;
    if (preference == mBatteryBarChargingAnimation) {
        Settings.System.putInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR_ANIMATE, ((SwitchPreference) preference).isChecked() ? 1 : 0);
        return true;
    } else if (preference == mBatteryBarUseGradient) {
        Settings.System.putInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR_USE_GRADIENT_COLOR, ((SwitchPreference) preference).isChecked() ? 1 : 0);
        return true;
    }
    return false;
}
Also used : SwitchPreference(android.support.v14.preference.SwitchPreference) ContentResolver(android.content.ContentResolver)

Example 24 with SwitchPreference

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

the class PhysicalKeyboardFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String s) {
    Activity activity = Preconditions.checkNotNull(getActivity());
    addPreferencesFromResource(R.xml.physical_keyboard_settings);
    mIm = Preconditions.checkNotNull(activity.getSystemService(InputManager.class));
    mSettings = new InputMethodUtils.InputMethodSettings(activity.getResources(), getContentResolver(), new HashMap<>(), new ArrayList<>(), UserHandle.myUserId(), false);
    mKeyboardAssistanceCategory = Preconditions.checkNotNull((PreferenceCategory) findPreference(KEYBOARD_ASSISTANCE_CATEGORY));
    mShowVirtualKeyboardSwitch = Preconditions.checkNotNull((SwitchPreference) mKeyboardAssistanceCategory.findPreference(SHOW_VIRTUAL_KEYBOARD_SWITCH));
    findPreference(KEYBOARD_SHORTCUTS_HELPER).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            toggleKeyboardShortcutsMenu();
            return true;
        }
    });
}
Also used : InputMethodUtils(com.android.internal.inputmethod.InputMethodUtils) HashMap(java.util.HashMap) PreferenceCategory(android.support.v7.preference.PreferenceCategory) SwitchPreference(android.support.v14.preference.SwitchPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) ArrayList(java.util.ArrayList) Activity(android.app.Activity)

Example 25 with SwitchPreference

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

the class SecuritySettings method createPreferenceHierarchy.

/**
     * Important!
     *
     * Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
     * logic or adding/removing preferences here.
     */
private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
        root.removeAll();
    }
    addPreferencesFromResource(R.xml.security_settings);
    root = getPreferenceScreen();
    // Add options for lock/unlock screen
    final int resid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, mManagedPasswordProvider, MY_USER_ID);
    addPreferencesFromResource(resid);
    // DO or PO installed in the user may disallow to change password.
    disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, MY_USER_ID);
    mProfileChallengeUserId = Utils.getManagedProfileId(mUm, MY_USER_ID);
    if (mProfileChallengeUserId != UserHandle.USER_NULL && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) {
        addPreferencesFromResource(R.xml.security_settings_profile);
        addPreferencesFromResource(R.xml.security_settings_unification);
        final int profileResid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, mManagedPasswordProvider, mProfileChallengeUserId);
        addPreferencesFromResource(profileResid);
        maybeAddFingerprintPreference(root, mProfileChallengeUserId);
        if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) {
            final Preference lockPreference = root.findPreference(KEY_UNLOCK_SET_OR_CHANGE_PROFILE);
            final String summary = getContext().getString(R.string.lock_settings_profile_unified_summary);
            lockPreference.setSummary(summary);
            lockPreference.setEnabled(false);
            // PO may disallow to change password for the profile, but screen lock and managed
            // profile's lock is the same. Disable main "Screen lock" menu.
            disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, mProfileChallengeUserId);
        } else {
            // PO may disallow to change profile password, and the profile's password is
            // separated from screen lock password. Disable profile specific "Screen lock" menu.
            disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE_PROFILE, mProfileChallengeUserId);
        }
    }
    Preference unlockSetOrChange = findPreference(KEY_UNLOCK_SET_OR_CHANGE);
    if (unlockSetOrChange instanceof GearPreference) {
        ((GearPreference) unlockSetOrChange).setOnGearClickListener(this);
    }
    // Add options for device encryption
    mIsAdmin = mUm.isAdminUser();
    if (mIsAdmin) {
        if (LockPatternUtils.isDeviceEncryptionEnabled()) {
            // The device is currently encrypted.
            addPreferencesFromResource(R.xml.security_settings_encrypted);
        } else {
            // This device supports encryption but isn't encrypted.
            addPreferencesFromResource(R.xml.security_settings_unencrypted);
        }
    }
    // Fingerprint and trust agents
    PreferenceGroup securityCategory = (PreferenceGroup) root.findPreference(KEY_SECURITY_CATEGORY);
    if (securityCategory != null) {
        maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId());
        addTrustAgentSettings(securityCategory);
    }
    mVisiblePatternProfile = (SwitchPreference) root.findPreference(KEY_VISIBLE_PATTERN_PROFILE);
    mUnifyProfile = (SwitchPreference) root.findPreference(KEY_UNIFICATION);
    // Append the rest of the settings
    addPreferencesFromResource(R.xml.security_settings_misc);
    // Do not display SIM lock for devices without an Icc card
    CarrierConfigManager cfgMgr = (CarrierConfigManager) getActivity().getSystemService(Context.CARRIER_CONFIG_SERVICE);
    PersistableBundle b = cfgMgr.getConfig();
    PreferenceGroup iccLockGroup = (PreferenceGroup) root.findPreference(KEY_SIM_LOCK);
    Preference iccLock = root.findPreference(KEY_SIM_LOCK_SETTINGS);
    if (!mIsAdmin || b.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
        root.removePreference(iccLockGroup);
    } else {
        SubscriptionManager subMgr = SubscriptionManager.from(getActivity());
        TelephonyManager tm = TelephonyManager.getDefault();
        int numPhones = tm.getPhoneCount();
        boolean hasAnySim = false;
        for (int i = 0; i < numPhones; i++) {
            final Preference pref;
            if (numPhones > 1) {
                SubscriptionInfo sir = subMgr.getActiveSubscriptionInfoForSimSlotIndex(i);
                if (sir == null) {
                    continue;
                }
                pref = new Preference(getActivity());
                pref.setOrder(iccLock.getOrder());
                pref.setTitle(getString(R.string.sim_card_lock_settings_title, i + 1));
                pref.setSummary(sir.getDisplayName());
                Intent intent = new Intent(getActivity(), com.android.settings.Settings.IccLockSettingsActivity.class);
                intent.putExtra(IccLockSettings.EXTRA_SUB_ID, sir.getSubscriptionId());
                intent.putExtra(IccLockSettings.EXTRA_SUB_DISPLAY_NAME, sir.getDisplayName());
                intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, true);
                pref.setIntent(intent);
                iccLockGroup.addPreference(pref);
            } else {
                pref = iccLock;
            }
            // Do not display SIM lock for devices without an Icc card
            hasAnySim |= tm.hasIccCard(i);
            int simState = tm.getSimState(i);
            boolean simPresent = simState != TelephonyManager.SIM_STATE_ABSENT && simState != TelephonyManager.SIM_STATE_UNKNOWN && simState != TelephonyManager.SIM_STATE_CARD_IO_ERROR;
            if (!simPresent) {
                pref.setEnabled(false);
            }
        }
        if (!hasAnySim) {
            root.removePreference(iccLockGroup);
        } else if (numPhones > 1) {
            iccLockGroup.removePreference(iccLock);
        }
    }
    if (Settings.System.getInt(getContentResolver(), Settings.System.LOCK_TO_APP_ENABLED, 0) != 0) {
        root.findPreference(KEY_SCREEN_PINNING).setSummary(getResources().getString(R.string.switch_on_text));
    }
    // Show password
    mShowPassword = (SwitchPreference) root.findPreference(KEY_SHOW_PASSWORD);
    mResetCredentials = (RestrictedPreference) root.findPreference(KEY_RESET_CREDENTIALS);
    // Credential storage
    final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
    // needs to be initialized for onResume()
    mKeyStore = KeyStore.getInstance();
    if (!RestrictedLockUtils.hasBaseUserRestriction(getActivity(), UserManager.DISALLOW_CONFIG_CREDENTIALS, MY_USER_ID)) {
        RestrictedPreference userCredentials = (RestrictedPreference) root.findPreference(KEY_USER_CREDENTIALS);
        userCredentials.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
        RestrictedPreference credentialStorageType = (RestrictedPreference) root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE);
        credentialStorageType.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
        RestrictedPreference installCredentials = (RestrictedPreference) root.findPreference(KEY_CREDENTIALS_INSTALL);
        installCredentials.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
        mResetCredentials.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
        final int storageSummaryRes = mKeyStore.isHardwareBacked() ? R.string.credential_storage_type_hardware : R.string.credential_storage_type_software;
        credentialStorageType.setSummary(storageSummaryRes);
    } else {
        PreferenceGroup credentialsManager = (PreferenceGroup) root.findPreference(KEY_CREDENTIALS_MANAGER);
        credentialsManager.removePreference(root.findPreference(KEY_RESET_CREDENTIALS));
        credentialsManager.removePreference(root.findPreference(KEY_CREDENTIALS_INSTALL));
        credentialsManager.removePreference(root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE));
        credentialsManager.removePreference(root.findPreference(KEY_USER_CREDENTIALS));
    }
    // Application install
    PreferenceGroup deviceAdminCategory = (PreferenceGroup) root.findPreference(KEY_DEVICE_ADMIN_CATEGORY);
    mToggleAppInstallation = (RestrictedSwitchPreference) findPreference(KEY_TOGGLE_INSTALL_APPLICATIONS);
    mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
    // Side loading of apps.
    // Disable for restricted profiles. For others, check if policy disallows it.
    mToggleAppInstallation.setEnabled(!um.getUserInfo(MY_USER_ID).isRestricted());
    if (RestrictedLockUtils.hasBaseUserRestriction(getActivity(), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, MY_USER_ID) || RestrictedLockUtils.hasBaseUserRestriction(getActivity(), UserManager.DISALLOW_INSTALL_APPS, MY_USER_ID)) {
        mToggleAppInstallation.setEnabled(false);
    }
    if (mToggleAppInstallation.isEnabled()) {
        mToggleAppInstallation.checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
        if (!mToggleAppInstallation.isDisabledByAdmin()) {
            mToggleAppInstallation.checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_APPS);
        }
    }
    // Advanced Security features
    PreferenceGroup advancedCategory = (PreferenceGroup) root.findPreference(KEY_ADVANCED_SECURITY);
    if (advancedCategory != null) {
        Preference manageAgents = advancedCategory.findPreference(KEY_MANAGE_TRUST_AGENTS);
        if (manageAgents != null && !mLockPatternUtils.isSecure(MY_USER_ID)) {
            manageAgents.setEnabled(false);
            manageAgents.setSummary(R.string.disabled_because_no_backup_security);
        }
    }
    // The above preferences come and go based on security state, so we need to update
    // the index. This call is expected to be fairly cheap, but we may want to do something
    // smarter in the future.
    Index.getInstance(getActivity()).updateFromClassNameResource(SecuritySettings.class.getName(), true, true);
    for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) {
        final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]);
        if (pref != null)
            pref.setOnPreferenceChangeListener(this);
    }
    return root;
}
Also used : CarrierConfigManager(android.telephony.CarrierConfigManager) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SubscriptionInfo(android.telephony.SubscriptionInfo) Intent(android.content.Intent) SubscriptionManager(android.telephony.SubscriptionManager) PersistableBundle(android.os.PersistableBundle) RestrictedPreference(com.android.settingslib.RestrictedPreference) RestrictedPreference(com.android.settingslib.RestrictedPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) TelephonyManager(android.telephony.TelephonyManager) UserManager(android.os.UserManager) PreferenceGroup(android.support.v7.preference.PreferenceGroup) FingerprintSettings(com.android.settings.fingerprint.FingerprintSettings) CMSettings(cyanogenmod.providers.CMSettings) 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