Search in sources :

Example 31 with ListPreference

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

the class DevelopmentSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
    mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService(Context.BACKUP_SERVICE));
    mWebViewUpdateService = IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate"));
    mOemUnlockManager = (PersistentDataBlockManager) getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
    mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mDpm = (DevicePolicyManager) getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
    mUm = (UserManager) getSystemService(Context.USER_SERVICE);
    mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    setIfOnlyAvailableForAdmins(true);
    if (isUiRestricted() || !Utils.isDeviceProvisioned(getActivity())) {
        // Block access to developer options if the user is not the owner, if user policy
        // restricts it, or if the device has not been provisioned
        mUnavailable = true;
        setPreferenceScreen(new PreferenceScreen(getPrefContext(), null));
        return;
    }
    addPreferencesFromResource(R.xml.development_prefs);
    final PreferenceGroup debugDebuggingCategory = (PreferenceGroup) findPreference(DEBUG_DEBUGGING_CATEGORY_KEY);
    mEnableAdb = findAndInitSwitchPref(ENABLE_ADB);
    mAdbAlwaysNotify = findAndInitSwitchPref(ADB_ALWAYS_NOTIFY);
    mAdbOverNetwork = findAndInitSwitchPref(ADB_TCPIP);
    mClearAdbKeys = findPreference(CLEAR_ADB_KEYS);
    if (!SystemProperties.getBoolean("ro.adb.secure", false)) {
        if (debugDebuggingCategory != null) {
            debugDebuggingCategory.removePreference(mClearAdbKeys);
        }
    }
    mAllPrefs.add(mClearAdbKeys);
    mEnableTerminal = findAndInitSwitchPref(ENABLE_TERMINAL);
    if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) {
        debugDebuggingCategory.removePreference(mEnableTerminal);
        mEnableTerminal = null;
    }
    mBugreport = findPreference(BUGREPORT);
    mBugreportInPower = findAndInitSwitchPref(BUGREPORT_IN_POWER_KEY);
    mKeepScreenOn = (RestrictedSwitchPreference) findAndInitSwitchPref(KEEP_SCREEN_ON);
    mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
    mEnableOemUnlock = (RestrictedSwitchPreference) findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
    if (!showEnableOemUnlockPreference()) {
        removePreference(mEnableOemUnlock);
        mEnableOemUnlock = null;
    }
    mDebugViewAttributes = findAndInitSwitchPref(DEBUG_VIEW_ATTRIBUTES);
    mForceAllowOnExternal = findAndInitSwitchPref(FORCE_ALLOW_ON_EXTERNAL_KEY);
    mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD);
    mAllPrefs.add(mPassword);
    mForceAuthorizeSubstratumPackages = findAndInitSwitchPref(FORCE_AUTHORIZE_SUBSTRATUM_PACKAGES);
    if (!mUm.isAdminUser()) {
        disableForUser(mEnableAdb);
        disableForUser(mClearAdbKeys);
        disableForUser(mEnableTerminal);
        disableForUser(mPassword);
        disableForUser(mForceAuthorizeSubstratumPackages);
    }
    mDebugAppPref = findPreference(DEBUG_APP_KEY);
    mAllPrefs.add(mDebugAppPref);
    mWaitForDebugger = findAndInitSwitchPref(WAIT_FOR_DEBUGGER_KEY);
    mMockLocationAppPref = findPreference(MOCK_LOCATION_APP_KEY);
    mAllPrefs.add(mMockLocationAppPref);
    mVerifyAppsOverUsb = findAndInitSwitchPref(VERIFY_APPS_OVER_USB_KEY);
    if (!showVerifierSetting()) {
        if (debugDebuggingCategory != null) {
            debugDebuggingCategory.removePreference(mVerifyAppsOverUsb);
        } else {
            mVerifyAppsOverUsb.setEnabled(false);
        }
    }
    mStrictMode = findAndInitSwitchPref(STRICT_MODE_KEY);
    mPointerLocation = findAndInitSwitchPref(POINTER_LOCATION_KEY);
    mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY);
    mShowScreenUpdates = findAndInitSwitchPref(SHOW_SCREEN_UPDATES_KEY);
    mDisableOverlays = findAndInitSwitchPref(DISABLE_OVERLAYS_KEY);
    mShowCpuInfo = findAndInitSwitchPref(SHOW_CPU_INFO_KEY);
    mForceHardwareUi = findAndInitSwitchPref(FORCE_HARDWARE_UI_KEY);
    mForceMsaa = findAndInitSwitchPref(FORCE_MSAA_KEY);
    mTrackFrameTime = addListPreference(TRACK_FRAME_TIME_KEY);
    mShowNonRectClip = addListPreference(SHOW_NON_RECTANGULAR_CLIP_KEY);
    mShowHwScreenUpdates = findAndInitSwitchPref(SHOW_HW_SCREEN_UPDATES_KEY);
    mShowHwLayersUpdates = findAndInitSwitchPref(SHOW_HW_LAYERS_UPDATES_KEY);
    mDebugLayout = findAndInitSwitchPref(DEBUG_LAYOUT_KEY);
    mForceRtlLayout = findAndInitSwitchPref(FORCE_RTL_LAYOUT_KEY);
    mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY);
    mWifiDisplayCertification = findAndInitSwitchPref(WIFI_DISPLAY_CERTIFICATION_KEY);
    mWifiVerboseLogging = findAndInitSwitchPref(WIFI_VERBOSE_LOGGING_KEY);
    mWifiAggressiveHandover = findAndInitSwitchPref(WIFI_AGGRESSIVE_HANDOVER_KEY);
    mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY);
    mMobileDataAlwaysOn = findAndInitSwitchPref(MOBILE_DATA_ALWAYS_ON);
    mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY);
    if ("1".equals(SystemProperties.get("ro.debuggable", "0"))) {
        mLogpersist = addListPreference(SELECT_LOGPERSIST_KEY);
    } else {
        mLogpersist = (ListPreference) findPreference(SELECT_LOGPERSIST_KEY);
        if (mLogpersist != null) {
            mLogpersist.setEnabled(false);
            if (debugDebuggingCategory != null) {
                debugDebuggingCategory.removePreference(mLogpersist);
            }
        }
        mLogpersist = null;
    }
    mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
    mWebViewProvider = addListPreference(WEBVIEW_PROVIDER_KEY);
    mWebViewMultiprocess = findAndInitSwitchPref(WEBVIEW_MULTIPROCESS_KEY);
    mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY);
    mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY);
    mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE);
    mUSBAudio = findAndInitSwitchPref(USB_AUDIO_KEY);
    mForceResizable = findAndInitSwitchPref(FORCE_RESIZABLE_KEY);
    mWindowAnimationScale = findAndInitAnimationScalePreference(WINDOW_ANIMATION_SCALE_KEY);
    mTransitionAnimationScale = findAndInitAnimationScalePreference(TRANSITION_ANIMATION_SCALE_KEY);
    mAnimatorDurationScale = findAndInitAnimationScalePreference(ANIMATOR_DURATION_SCALE_KEY);
    mImmediatelyDestroyActivities = (SwitchPreference) findPreference(IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
    mAllPrefs.add(mImmediatelyDestroyActivities);
    mResetSwitchPrefs.add(mImmediatelyDestroyActivities);
    mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY);
    mShowAllANRs = (SwitchPreference) findPreference(SHOW_ALL_ANRS_KEY);
    mAllPrefs.add(mShowAllANRs);
    mResetSwitchPrefs.add(mShowAllANRs);
    Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
    if (hdcpChecking != null) {
        mAllPrefs.add(hdcpChecking);
        removePreferenceForProduction(hdcpChecking);
    }
    PreferenceScreen convertFbePreference = (PreferenceScreen) findPreference(KEY_CONVERT_FBE);
    try {
        IBinder service = ServiceManager.getService("mount");
        IMountService mountService = IMountService.Stub.asInterface(service);
        if (!mountService.isConvertibleToFBE()) {
            removePreference(KEY_CONVERT_FBE);
        } else if ("file".equals(SystemProperties.get("ro.crypto.type", "none"))) {
            convertFbePreference.setEnabled(false);
            convertFbePreference.setSummary(getResources().getString(R.string.convert_to_file_encryption_done));
        }
    } catch (RemoteException e) {
        removePreference(KEY_CONVERT_FBE);
    }
    mOtaDisableAutomaticUpdate = findAndInitSwitchPref(OTA_DISABLE_AUTOMATIC_UPDATE_KEY);
    if (!SystemProperties.getBoolean("ro.build.ab_update", false)) {
        removePreference(mOtaDisableAutomaticUpdate);
        mOtaDisableAutomaticUpdate = null;
    }
    mColorModePreference = (ColorModePreference) findPreference(KEY_COLOR_MODE);
    mColorModePreference.updateCurrentAndSupported();
    if (mColorModePreference.getColorModeCount() < 2) {
        removePreference(KEY_COLOR_MODE);
        mColorModePreference = null;
    }
    updateWebViewProviderOptions();
    mColorTemperaturePreference = (SwitchPreference) findPreference(COLOR_TEMPERATURE_KEY);
    if (getResources().getBoolean(R.bool.config_enableColorTemperature)) {
        mAllPrefs.add(mColorTemperaturePreference);
        mResetSwitchPrefs.add(mColorTemperaturePreference);
    } else {
        removePreference(COLOR_TEMPERATURE_KEY);
        mColorTemperaturePreference = null;
    }
    mRootAccess = (ListPreference) findPreference(ROOT_ACCESS_KEY);
    mRootAccess.setOnPreferenceChangeListener(this);
    mRootAppops = (Preference) findPreference(ROOT_APPOPS_KEY);
    mRootAppops.setOnPreferenceClickListener(this);
    if (!removeRootOptionsIfRequired()) {
        if (FileUtils.fileExists("/system/xbin/su")) {
            mRootAccess.setEntries(R.array.root_access_entries);
            mRootAccess.setEntryValues(R.array.root_access_values);
        } else {
            mRootAccess.setEntries(R.array.root_access_entries_adb);
            mRootAccess.setEntryValues(R.array.root_access_values_adb);
        }
        mAllPrefs.add(mRootAccess);
        mAllPrefs.add(mRootAppops);
    }
    mDevelopmentTools = (PreferenceScreen) findPreference(DEVELOPMENT_TOOLS);
    mAllPrefs.add(mDevelopmentTools);
}
Also used : IBinder(android.os.IBinder) PreferenceScreen(android.support.v7.preference.PreferenceScreen) ListPreference(android.support.v7.preference.ListPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) IMountService(android.os.storage.IMountService) PreferenceGroup(android.support.v7.preference.PreferenceGroup) RemoteException(android.os.RemoteException)

Example 32 with ListPreference

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

the class ClockSettings method createCustomView.

private PreferenceScreen createCustomView() {
    mCheckPreferences = false;
    addPreferencesFromResource(R.xml.rr_clock);
    PreferenceScreen prefSet = getPreferenceScreen();
    ContentResolver resolver = getActivity().getContentResolver();
    PackageManager pm = getPackageManager();
    Resources systemUiResources;
    try {
        systemUiResources = pm.getResourcesForApplication("com.android.systemui");
    } catch (Exception e) {
        Log.e(TAG, "can't access systemui resources", e);
        return null;
    }
    mStatusBarClock = (ListPreference) findPreference(STATUS_BAR_CLOCK_STYLE);
    mStatusBarAmPm = (ListPreference) findPreference(STATUS_BAR_AM_PM);
    mStatusBarDate = (ListPreference) findPreference(STATUS_BAR_DATE);
    mStatusBarDateStyle = (ListPreference) findPreference(STATUS_BAR_DATE_STYLE);
    mStatusBarDateFormat = (ListPreference) findPreference(STATUS_BAR_DATE_FORMAT);
    mStatusBarClockSeconds = (SwitchPreference) findPreference(STATUS_BAR_CLOCK_SECONDS);
    mStatusBarClockSeconds.setChecked((Settings.System.getInt(getActivity().getApplicationContext().getContentResolver(), Settings.System.STATUS_BAR_CLOCK_SECONDS, 0) == 1));
    mStatusBarClockSeconds.setOnPreferenceChangeListener(this);
    int clockStyle = CMSettings.System.getInt(resolver, CMSettings.System.STATUS_BAR_CLOCK, 0);
    mStatusBarClock.setValue(String.valueOf(clockStyle));
    mStatusBarClock.setSummary(mStatusBarClock.getEntry());
    mStatusBarClock.setOnPreferenceChangeListener(this);
    if (DateFormat.is24HourFormat(getActivity())) {
        mStatusBarAmPm.setEnabled(false);
        mStatusBarAmPm.setSummary(R.string.status_bar_am_pm_info);
    } else {
        int statusBarAmPm = CMSettings.System.getInt(resolver, CMSettings.System.STATUS_BAR_AM_PM, 2);
        mStatusBarAmPm.setValue(String.valueOf(statusBarAmPm));
        mStatusBarAmPm.setSummary(mStatusBarAmPm.getEntry());
        mStatusBarAmPm.setOnPreferenceChangeListener(this);
    }
    int showDate = Settings.System.getInt(resolver, Settings.System.STATUS_BAR_DATE, 0);
    mStatusBarDate.setValue(String.valueOf(showDate));
    mStatusBarDate.setSummary(mStatusBarDate.getEntry());
    mStatusBarDate.setOnPreferenceChangeListener(this);
    int dateStyle = Settings.System.getInt(resolver, Settings.System.STATUS_BAR_DATE_STYLE, 0);
    mStatusBarDateStyle.setValue(String.valueOf(dateStyle));
    mStatusBarDateStyle.setSummary(mStatusBarDateStyle.getEntry());
    mStatusBarDateStyle.setOnPreferenceChangeListener(this);
    mClockDatePosition = (ListPreference) findPreference(PREF_CLOCK_DATE_POSITION);
    mClockDatePosition.setOnPreferenceChangeListener(this);
    mClockDatePosition.setValue(Integer.toString(Settings.System.getInt(resolver, Settings.System.STATUSBAR_CLOCK_DATE_POSITION, 0)));
    mClockDatePosition.setSummary(mClockDatePosition.getEntry());
    mStatusBarDateFormat.setOnPreferenceChangeListener(this);
    mStatusBarDateFormat.setSummary(mStatusBarDateFormat.getEntry());
    if (mStatusBarDateFormat.getValue() == null) {
        mStatusBarDateFormat.setValue("EEE");
    }
    parseClockDateFormats();
    mFontStyle = (ListPreference) findPreference(PREF_FONT_STYLE);
    mFontStyle.setOnPreferenceChangeListener(this);
    mFontStyle.setValue(Integer.toString(Settings.System.getInt(getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_FONT_STYLE, 0)));
    mFontStyle.setSummary(mFontStyle.getEntry());
    mStatusBarClockFontSize = (SeekBarPreference) findPreference(PREF_STATUS_BAR_CLOCK_FONT_SIZE);
    int size = Settings.System.getInt(getContentResolver(), Settings.System.STATUSBAR_CLOCK_FONT_SIZE, 14);
    mStatusBarClockFontSize.setValue(size);
    mStatusBarClockFontSize.setOnPreferenceChangeListener(this);
    setHasOptionsMenu(true);
    mCheckPreferences = true;
    return prefSet;
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) PackageManager(android.content.pm.PackageManager) Resources(android.content.res.Resources) ContentResolver(android.content.ContentResolver)

Example 33 with ListPreference

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

the class CustomLogo method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.custom_logo);
    PreferenceScreen prefSet = getPreferenceScreen();
    // custom logo color
    mCustomLogoColor = (ColorPickerPreference) prefSet.findPreference(KEY_CUSTOM_LOGO_COLOR);
    mCustomLogoColor.setOnPreferenceChangeListener(this);
    int intColor = Settings.System.getInt(getContentResolver(), Settings.System.CUSTOM_LOGO_COLOR, 0xffffffff);
    String hexColor = String.format("#%08x", (0xffffffff & intColor));
    mCustomLogoColor.setSummary(hexColor);
    mCustomLogoColor.setNewPreviewColor(intColor);
    mCustomLogoStyle = (ListPreference) findPreference(KEY_CUSTOM_LOGO_STYLE);
    int LogoStyle = Settings.System.getIntForUser(getContentResolver(), Settings.System.CUSTOM_LOGO_STYLE, 0, UserHandle.USER_CURRENT);
    mCustomLogoStyle.setValue(String.valueOf(LogoStyle));
    mCustomLogoStyle.setSummary(mCustomLogoStyle.getEntry());
    mCustomLogoStyle.setOnPreferenceChangeListener(this);
    mCustomLogoPos = (ListPreference) findPreference(KEY_CUSTOM_LOGO_POS);
    int cLogopos = Settings.System.getIntForUser(getContentResolver(), Settings.System.CUSTOM_LOGO_POSITION, 0, UserHandle.USER_CURRENT);
    mCustomLogoPos.setValue(String.valueOf(cLogopos));
    mCustomLogoPos.setSummary(mCustomLogoPos.getEntry());
    mCustomLogoPos.setOnPreferenceChangeListener(this);
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen)

Example 34 with ListPreference

use of android.support.v7.preference.ListPreference 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 35 with ListPreference

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

the class NetworkTrafficSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.network_traffic_settings);
    ContentResolver resolver = getActivity().getContentResolver();
    PreferenceScreen prefSet = getPreferenceScreen();
    loadResources();
    mNetTrafficState = (ListPreference) prefSet.findPreference(NETWORK_TRAFFIC_STATE);
    mNetTrafficUnit = (ListPreference) prefSet.findPreference(NETWORK_TRAFFIC_UNIT);
    mNetTrafficPeriod = (ListPreference) prefSet.findPreference(NETWORK_TRAFFIC_PERIOD);
    mNetTrafficAutohide = (SwitchPreference) prefSet.findPreference(NETWORK_TRAFFIC_AUTOHIDE);
    mNetTrafficAutohide.setChecked((Settings.System.getInt(getContentResolver(), Settings.System.NETWORK_TRAFFIC_AUTOHIDE, 0) == 1));
    mNetTrafficAutohide.setOnPreferenceChangeListener(this);
    mNetTrafficAutohideThreshold = (SeekBarPreference) prefSet.findPreference(NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD);
    int netTrafficAutohideThreshold = Settings.System.getInt(resolver, Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD, 10);
    mNetTrafficAutohideThreshold.setValue(netTrafficAutohideThreshold / 1);
    mNetTrafficAutohideThreshold.setOnPreferenceChangeListener(this);
    mNetTrafficColor = (ColorPickerPreference) prefSet.findPreference(NETWORK_TRAFFIC_COLOR);
    mNetTrafficColor.setOnPreferenceChangeListener(this);
    int intColor = Settings.System.getInt(getContentResolver(), Settings.System.NETWORK_TRAFFIC_COLOR, 0xffffffff);
    String hexColor = String.format("#%08x", (0xffffffff & intColor));
    mNetTrafficColor.setSummary(hexColor);
    mNetTrafficColor.setNewPreviewColor(intColor);
    // TrafficStats will return UNSUPPORTED if the device does not support it.
    if (TrafficStats.getTotalTxBytes() != TrafficStats.UNSUPPORTED && TrafficStats.getTotalRxBytes() != TrafficStats.UNSUPPORTED) {
        mNetTrafficVal = Settings.System.getInt(resolver, Settings.System.NETWORK_TRAFFIC_STATE, 0);
        int intIndex = mNetTrafficVal & (MASK_UP + MASK_DOWN);
        intIndex = mNetTrafficState.findIndexOfValue(String.valueOf(intIndex));
        if (intIndex <= 0) {
            mNetTrafficUnit.setEnabled(false);
            mNetTrafficPeriod.setEnabled(false);
            mNetTrafficAutohide.setEnabled(false);
            mNetTrafficAutohideThreshold.setEnabled(false);
            mNetTrafficColor.setEnabled(false);
        }
        mNetTrafficState.setValueIndex(intIndex >= 0 ? intIndex : 0);
        mNetTrafficState.setSummary(mNetTrafficState.getEntry());
        mNetTrafficState.setOnPreferenceChangeListener(this);
        mNetTrafficUnit.setValueIndex(getBit(mNetTrafficVal, MASK_UNIT) ? 1 : 0);
        mNetTrafficUnit.setSummary(mNetTrafficUnit.getEntry());
        mNetTrafficUnit.setOnPreferenceChangeListener(this);
        intIndex = (mNetTrafficVal & MASK_PERIOD) >>> 16;
        intIndex = mNetTrafficPeriod.findIndexOfValue(String.valueOf(intIndex));
        mNetTrafficPeriod.setValueIndex(intIndex >= 0 ? intIndex : 1);
        mNetTrafficPeriod.setSummary(mNetTrafficPeriod.getEntry());
        mNetTrafficPeriod.setOnPreferenceChangeListener(this);
    } else {
        prefSet.removePreference(findPreference(NETWORK_TRAFFIC_STATE));
        prefSet.removePreference(findPreference(NETWORK_TRAFFIC_UNIT));
        prefSet.removePreference(findPreference(NETWORK_TRAFFIC_PERIOD));
        prefSet.removePreference(findPreference(NETWORK_TRAFFIC_AUTOHIDE));
        prefSet.removePreference(findPreference(NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD));
        prefSet.removePreference(findPreference(NETWORK_TRAFFIC_COLOR));
    }
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) ContentResolver(android.content.ContentResolver)

Aggregations

PreferenceScreen (android.support.v7.preference.PreferenceScreen)28 ListPreference (android.support.v7.preference.ListPreference)23 ContentResolver (android.content.ContentResolver)17 Preference (android.support.v7.preference.Preference)13 SwitchPreference (android.support.v14.preference.SwitchPreference)9 Resources (android.content.res.Resources)8 Intent (android.content.Intent)6 Context (android.content.Context)5 Activity (android.app.Activity)3 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)3 PreferenceCategory (android.support.v7.preference.PreferenceCategory)3 RestrictionEntry (android.content.RestrictionEntry)2 MultiSelectListPreference (android.support.v14.preference.MultiSelectListPreference)2 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)2 View (android.view.View)2 HashSet (java.util.HashSet)2 UiModeManager (android.app.UiModeManager)1 BluetoothAdapter (android.bluetooth.BluetoothAdapter)1 BluetoothPan (android.bluetooth.BluetoothPan)1 IntentFilter (android.content.IntentFilter)1