private void NetworkTrafficColorReset() { Settings.System.putInt( getContentResolver(), Settings.System.NETWORK_TRAFFIC_COLOR, DEFAULT_TRAFFIC_COLOR); mNetTrafficColor.setNewPreviewColor(DEFAULT_TRAFFIC_COLOR); String hexColor = String.format("#%08x", (0xffffffff & DEFAULT_TRAFFIC_COLOR)); mNetTrafficColor.setSummary(hexColor); }
public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference == mNetTrafficState) { int intState = Integer.valueOf((String) newValue); mNetTrafficVal = setBit(mNetTrafficVal, MASK_UP, getBit(intState, MASK_UP)); mNetTrafficVal = setBit(mNetTrafficVal, MASK_DOWN, getBit(intState, MASK_DOWN)); Settings.System.putInt( getActivity().getContentResolver(), Settings.System.NETWORK_TRAFFIC_STATE, mNetTrafficVal); int index = mNetTrafficState.findIndexOfValue((String) newValue); mNetTrafficState.setSummary(mNetTrafficState.getEntries()[index]); updateNetworkTrafficState(index); return true; } else if (preference == mNetTrafficColor) { String hex = ColorPickerPreference.convertToARGB(Integer.valueOf(String.valueOf(newValue))); preference.setSummary(hex); int intHex = ColorPickerPreference.convertToColorInt(hex); Settings.System.putInt(getContentResolver(), Settings.System.NETWORK_TRAFFIC_COLOR, intHex); return true; } else if (preference == mNetTrafficUnit) { mNetTrafficVal = setBit(mNetTrafficVal, MASK_UNIT, ((String) newValue).equals("1")); Settings.System.putInt( getActivity().getContentResolver(), Settings.System.NETWORK_TRAFFIC_STATE, mNetTrafficVal); int index = mNetTrafficUnit.findIndexOfValue((String) newValue); mNetTrafficUnit.setSummary(mNetTrafficUnit.getEntries()[index]); return true; } else if (preference == mNetTrafficPeriod) { int intState = Integer.valueOf((String) newValue); mNetTrafficVal = setBit(mNetTrafficVal, MASK_PERIOD, false) + (intState << 16); Settings.System.putInt( getActivity().getContentResolver(), Settings.System.NETWORK_TRAFFIC_STATE, mNetTrafficVal); int index = mNetTrafficPeriod.findIndexOfValue((String) newValue); mNetTrafficPeriod.setSummary(mNetTrafficPeriod.getEntries()[index]); return true; } else if (preference == mNetTrafficAutohide) { boolean value = (Boolean) newValue; Settings.System.putInt( getActivity().getContentResolver(), Settings.System.NETWORK_TRAFFIC_AUTOHIDE, value ? 1 : 0); return true; } else if (preference == mNetTrafficAutohideThreshold) { int threshold = (Integer) newValue; Settings.System.putInt( getActivity().getContentResolver(), Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD, threshold * 1); return true; } return false; }
private void updateNetworkTrafficState(int mIndex) { if (mIndex <= 0) { mNetTrafficUnit.setEnabled(false); mNetTrafficColor.setEnabled(false); mNetTrafficPeriod.setEnabled(false); mNetTrafficAutohide.setEnabled(false); mNetTrafficAutohideThreshold.setEnabled(false); } else { mNetTrafficUnit.setEnabled(true); mNetTrafficColor.setEnabled(true); mNetTrafficPeriod.setEnabled(true); mNetTrafficAutohide.setEnabled(true); mNetTrafficAutohideThreshold.setEnabled(true); } }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference == menuDisplayLocation) { int val = Integer.parseInt((String) newValue); Settings.System.putInt(mContentRes, Settings.System.MENU_LOCATION, val); refreshSettings(); mNavBarMenuDisplay.setEnabled(val < 4 ? true : false); return true; } else if (preference == mNavBarMenuDisplay) { Settings.System.putInt( mContentRes, Settings.System.MENU_VISIBILITY, Integer.parseInt((String) newValue)); return true; } else if (preference == mNavigationBarWidth) { String newVal = (String) newValue; int dp = Integer.parseInt(newVal); int width = mapChosenDpToPixels(dp); Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_WIDTH, width); return true; } else if (preference == mNavigationBarHeight) { String newVal = (String) newValue; int dp = Integer.parseInt(newVal); int height = mapChosenDpToPixels(dp); Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_HEIGHT, height); return true; } else if (preference == mNavBarHideTimeout) { int val = Integer.parseInt((String) newValue); Settings.System.putInt(mContentRes, Settings.System.NAV_HIDE_TIMEOUT, val); return true; } else if (preference == mNavigationBarHeightLandscape) { String newVal = (String) newValue; int dp = Integer.parseInt(newVal); int height = mapChosenDpToPixels(dp); Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_HEIGHT_LANDSCAPE, height); return true; } else if (preference == mNavigationColor) { String hex = ColorPickerPreference.convertToARGB(Integer.valueOf(String.valueOf(newValue))); preference.setSummary(hex); int intHex = ColorPickerPreference.convertToColorInt(hex) & 0x00FFFFFF; Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_COLOR, intHex); refreshSettings(); return true; } else if (preference == mNavigationBarColor) { String hex = ColorPickerPreference.convertToARGB(Integer.valueOf(String.valueOf(newValue))); preference.setSummary(hex); int intHex = ColorPickerPreference.convertToColorInt(hex); Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_TINT, intHex); refreshSettings(); return true; } else if (preference == mNavigationBarGlowColor) { String hex = ColorPickerPreference.convertToARGB(Integer.valueOf(String.valueOf(newValue))); preference.setSummary(hex); int intHex = ColorPickerPreference.convertToColorInt(hex); Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_GLOW_TINT, intHex); refreshSettings(); return true; } else if (preference == mGlowTimes) { // format is (on|off) both in MS String value = (String) newValue; String[] breakIndex = value.split("\\|"); int onTime = Integer.valueOf(breakIndex[0]); int offTime = Integer.valueOf(breakIndex[1]); Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_GLOW_DURATION[0], offTime); Settings.System.putInt(mContentRes, Settings.System.NAVIGATION_BAR_GLOW_DURATION[1], onTime); updateGlowTimesSummary(); return true; } else if (preference == mButtonAlpha) { float val = Float.parseFloat((String) newValue); Settings.System.putFloat( mContentRes, Settings.System.NAVIGATION_BAR_BUTTON_ALPHA, val * 0.01f); refreshSettings(); return true; } else if (preference == mDragHandleOpacity) { String newVal = (String) newValue; int op = Integer.parseInt(newVal); Settings.System.putInt(mContentRes, Settings.System.DRAG_HANDLE_OPACITY, op); return true; } else if (preference == mDragHandleWidth) { String newVal = (String) newValue; int dp = Integer.parseInt(newVal); // int height = mapChosenDpToPixels(dp); Settings.System.putInt(mContentRes, Settings.System.DRAG_HANDLE_WEIGHT, dp); return true; } else if (preference == mWidthPort) { float val = Float.parseFloat((String) newValue); Settings.System.putFloat(mContentRes, Settings.System.NAVIGATION_BAR_WIDTH_PORT, val * 0.4f); return true; } else if (preference == mWidthLand) { float val = Float.parseFloat((String) newValue); Settings.System.putFloat(mContentRes, Settings.System.NAVIGATION_BAR_WIDTH_LAND, val * 0.4f); return true; } return false; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle(R.string.title_navbar); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.navbar_settings); PreferenceScreen prefs = getPreferenceScreen(); mPicker = new ShortcutPickerHelper(this, this); mPackMan = getPackageManager(); mResources = mContext.getResources(); // Get NavBar Actions mActionCodes = NavBarHelpers.getNavBarActions(); mActions = new String[mActionCodes.length]; int actionqty = mActions.length; for (int i = 0; i < actionqty; i++) { mActions[i] = AwesomeConstants.getProperName(mContext, mActionCodes[i]); } menuDisplayLocation = (ListPreference) findPreference(PREF_MENU_UNLOCK); menuDisplayLocation.setOnPreferenceChangeListener(this); menuDisplayLocation.setValue( Settings.System.getInt(mContentRes, Settings.System.MENU_LOCATION, 0) + ""); mNavBarMenuDisplay = (ListPreference) findPreference(PREF_NAVBAR_MENU_DISPLAY); mNavBarMenuDisplay.setOnPreferenceChangeListener(this); mNavBarMenuDisplay.setValue( Settings.System.getInt(mContentRes, Settings.System.MENU_VISIBILITY, 0) + ""); mNavBarHideEnable = (CheckBoxPreference) findPreference(NAVBAR_HIDE_ENABLE); mNavBarHideEnable.setChecked( Settings.System.getBoolean(mContentRes, Settings.System.NAV_HIDE_ENABLE, false)); final int defaultDragOpacity = Settings.System.getInt(mContentRes, Settings.System.DRAG_HANDLE_OPACITY, 50); mDragHandleOpacity = (SeekBarPreference) findPreference(DRAG_HANDLE_OPACITY); mDragHandleOpacity.setInitValue((int) (defaultDragOpacity)); mDragHandleOpacity.setOnPreferenceChangeListener(this); final int defaultDragWidth = Settings.System.getInt(mContentRes, Settings.System.DRAG_HANDLE_WEIGHT, 5); mDragHandleWidth = (SeekBarPreference) findPreference(DRAG_HANDLE_WIDTH); mDragHandleWidth.setInitValue((int) (defaultDragWidth)); mDragHandleWidth.setOnPreferenceChangeListener(this); mNavBarHideTimeout = (ListPreference) findPreference(NAVBAR_HIDE_TIMEOUT); mNavBarHideTimeout.setOnPreferenceChangeListener(this); mNavBarHideTimeout.setValue( Settings.System.getInt(mContentRes, Settings.System.NAV_HIDE_TIMEOUT, 3000) + ""); boolean hasNavBarByDefault = mContext.getResources().getBoolean(com.android.internal.R.bool.config_showNavigationBar); mEnableNavigationBar = (CheckBoxPreference) findPreference(ENABLE_NAVIGATION_BAR); mEnableNavigationBar.setChecked( Settings.System.getBoolean( mContentRes, Settings.System.NAVIGATION_BAR_SHOW, hasNavBarByDefault)); mNavigationColor = (ColorPickerPreference) findPreference(NAVIGATION_BAR_COLOR); mNavigationColor.setOnPreferenceChangeListener(this); mNavigationBarColor = (ColorPickerPreference) findPreference(PREF_NAV_COLOR); mNavigationBarColor.setOnPreferenceChangeListener(this); mColorizeAllIcons = (CheckBoxPreference) findPreference("navigation_bar_allcolor"); mColorizeAllIcons.setChecked( Settings.System.getBoolean(mContentRes, Settings.System.NAVIGATION_BAR_ALLCOLOR, false)); mNavigationBarGlowColor = (ColorPickerPreference) findPreference(PREF_NAV_GLOW_COLOR); mNavigationBarGlowColor.setOnPreferenceChangeListener(this); mGlowTimes = (ListPreference) findPreference(PREF_GLOW_TIMES); mGlowTimes.setOnPreferenceChangeListener(this); final float defaultButtonAlpha = Settings.System.getFloat(mContentRes, Settings.System.NAVIGATION_BAR_BUTTON_ALPHA, 0.6f); mButtonAlpha = (SeekBarPreference) findPreference("button_transparency"); mButtonAlpha.setInitValue((int) (defaultButtonAlpha * 100)); mButtonAlpha.setOnPreferenceChangeListener(this); mWidthHelp = (Preference) findPreference("width_help"); float defaultPort = Settings.System.getFloat(mContentRes, Settings.System.NAVIGATION_BAR_WIDTH_PORT, 0f); mWidthPort = (SeekBarPreference) findPreference("width_port"); mWidthPort.setInitValue((int) (defaultPort * 2.5f)); mWidthPort.setOnPreferenceChangeListener(this); float defaultLand = Settings.System.getFloat(mContentRes, Settings.System.NAVIGATION_BAR_WIDTH_LAND, 0f); mWidthLand = (SeekBarPreference) findPreference("width_land"); mWidthLand.setInitValue((int) (defaultLand * 2.5f)); mWidthLand.setOnPreferenceChangeListener(this); mNavigationBarHeight = (ListPreference) findPreference("navigation_bar_height"); mNavigationBarHeight.setOnPreferenceChangeListener(this); mNavigationBarHeightLandscape = (ListPreference) findPreference("navigation_bar_height_landscape"); mNavigationBarHeightLandscape.setOnPreferenceChangeListener(this); mNavigationBarWidth = (ListPreference) findPreference("navigation_bar_width"); mNavigationBarWidth.setOnPreferenceChangeListener(this); mConfigureWidgets = findPreference(NAVIGATION_BAR_WIDGETS); mMenuArrowKeysCheckBox = (CheckBoxPreference) findPreference(PREF_MENU_ARROWS); mMenuArrowKeysCheckBox.setChecked( Settings.System.getBoolean( mContentRes, Settings.System.NAVIGATION_BAR_MENU_ARROW_KEYS, true)); // don't allow devices that must use a navigation bar to disable it if (hasNavBarByDefault) { prefs.removePreference(mEnableNavigationBar); } PreferenceGroup pg = (PreferenceGroup) prefs.findPreference("advanced_cat"); if (isTablet(mContext)) { mNavigationBarHeight.setTitle(R.string.system_bar_height_title); mNavigationBarHeight.setSummary(R.string.system_bar_height_summary); mNavigationBarHeightLandscape.setTitle(R.string.system_bar_height_landscape_title); mNavigationBarHeightLandscape.setSummary(R.string.system_bar_height_landscape_summary); pg.removePreference(mNavigationBarWidth); mNavBarHideEnable.setEnabled(false); mDragHandleOpacity.setEnabled(false); mDragHandleWidth.setEnabled(false); mNavBarHideTimeout.setEnabled(false); } else { // Phones&Phablets don't have SystemBar pg.removePreference(mWidthPort); pg.removePreference(mWidthLand); pg.removePreference(mWidthHelp); } if (Integer.parseInt(menuDisplayLocation.getValue()) == 4) { mNavBarMenuDisplay.setEnabled(false); } // Only show the hardware keys config on a device that does not have a navbar IWindowManager windowManager = IWindowManager.Stub.asInterface(ServiceManager.getService(Context.WINDOW_SERVICE)); if (hasNavBarByDefault) { // Let's assume they don't have hardware keys getPreferenceScreen().removePreference(findPreference(KEY_HARDWARE_KEYS)); } refreshSettings(); setHasOptionsMenu(true); updateGlowTimesSummary(); }
private PreferenceScreen createCustomView() { mCheckPreferences = false; PreferenceScreen prefSet = getPreferenceScreen(); if (prefSet != null) { prefSet.removeAll(); } addPreferencesFromResource(R.xml.status_bar_clock_style); prefSet = getPreferenceScreen(); 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; } mClockStyle = (ListPreference) findPreference(PREF_ENABLE); mClockStyle.setOnPreferenceChangeListener(this); mClockStyle.setValue( Integer.toString( Settings.System.getInt( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_STYLE, 0))); mClockStyle.setSummary(mClockStyle.getEntry()); mClockAmPmStyle = (ListPreference) prefSet.findPreference(PREF_AM_PM_STYLE); mClockAmPmStyle.setOnPreferenceChangeListener(this); mClockAmPmStyle.setValue( Integer.toString( Settings.System.getInt( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_AM_PM_STYLE, 0))); boolean is24hour = DateFormat.is24HourFormat(getActivity()); if (is24hour) { mClockAmPmStyle.setSummary(R.string.status_bar_am_pm_info); } else { mClockAmPmStyle.setSummary(mClockAmPmStyle.getEntry()); } mClockAmPmStyle.setEnabled(!is24hour); mColorPicker = (ColorPickerPreference) findPreference(PREF_COLOR_PICKER); mColorPicker.setOnPreferenceChangeListener(this); int intColor = Settings.System.getInt( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_COLOR, -2); if (intColor == -2) { intColor = systemUiResources.getColor( systemUiResources.getIdentifier( "com.android.systemui:color/status_bar_clock_color", null, null)); mColorPicker.setSummary(getResources().getString(R.string.default_string)); } else { String hexColor = String.format("#%08x", (0xffffffff & intColor)); mColorPicker.setSummary(hexColor); } mColorPicker.setNewPreviewColor(intColor); mClockDateDisplay = (ListPreference) findPreference(PREF_CLOCK_DATE_DISPLAY); mClockDateDisplay.setOnPreferenceChangeListener(this); mClockDateDisplay.setValue( Integer.toString( Settings.System.getInt( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, 0))); mClockDateDisplay.setSummary(mClockDateDisplay.getEntry()); mClockDateStyle = (ListPreference) findPreference(PREF_CLOCK_DATE_STYLE); mClockDateStyle.setOnPreferenceChangeListener(this); mClockDateStyle.setValue( Integer.toString( Settings.System.getInt( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_STYLE, 2))); mClockDateStyle.setSummary(mClockDateStyle.getEntry()); mClockDateFormat = (ListPreference) findPreference(PREF_CLOCK_DATE_FORMAT); mClockDateFormat.setOnPreferenceChangeListener(this); if (mClockDateFormat.getValue() == null) { mClockDateFormat.setValue("EEE"); } parseClockDateFormats(); mStatusBarClock = (CheckBoxPreference) prefSet.findPreference(STATUS_BAR_CLOCK); mStatusBarClock.setChecked( (Settings.System.getInt( getActivity().getApplicationContext().getContentResolver(), Settings.System.STATUS_BAR_CLOCK, 1) == 1)); mStatusBarClock.setOnPreferenceChangeListener(this); boolean mClockDateToggle = Settings.System.getInt( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, 0) != 0; if (!mClockDateToggle) { mClockDateStyle.setEnabled(false); mClockDateFormat.setEnabled(false); } setHasOptionsMenu(true); mCheckPreferences = true; return prefSet; }
public boolean onPreferenceChange(Preference preference, Object newValue) { if (!mCheckPreferences) { return false; } AlertDialog dialog; if (preference == mClockAmPmStyle) { int val = Integer.parseInt((String) newValue); int index = mClockAmPmStyle.findIndexOfValue((String) newValue); Settings.System.putInt( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_AM_PM_STYLE, val); mClockAmPmStyle.setSummary(mClockAmPmStyle.getEntries()[index]); return true; } else if (preference == mClockStyle) { int val = Integer.parseInt((String) newValue); int index = mClockStyle.findIndexOfValue((String) newValue); Settings.System.putInt( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_STYLE, val); mClockStyle.setSummary(mClockStyle.getEntries()[index]); return true; } else if (preference == mColorPicker) { String hex = ColorPickerPreference.convertToARGB(Integer.valueOf(String.valueOf(newValue))); preference.setSummary(hex); int intHex = ColorPickerPreference.convertToColorInt(hex); Settings.System.putInt( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_COLOR, intHex); return true; } else if (preference == mClockDateDisplay) { int val = Integer.parseInt((String) newValue); int index = mClockDateDisplay.findIndexOfValue((String) newValue); Settings.System.putInt( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_DISPLAY, val); mClockDateDisplay.setSummary(mClockDateDisplay.getEntries()[index]); if (val == 0) { mClockDateStyle.setEnabled(false); mClockDateFormat.setEnabled(false); } else { mClockDateStyle.setEnabled(true); mClockDateFormat.setEnabled(true); } return true; } else if (preference == mClockDateStyle) { int val = Integer.parseInt((String) newValue); int index = mClockDateStyle.findIndexOfValue((String) newValue); Settings.System.putInt( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_STYLE, val); mClockDateStyle.setSummary(mClockDateStyle.getEntries()[index]); parseClockDateFormats(); return true; } else if (preference == mStatusBarClock) { Settings.System.putInt( getActivity().getApplicationContext().getContentResolver(), Settings.System.STATUS_BAR_CLOCK, (Boolean) newValue ? 1 : 0); return true; } else if (preference == mClockDateFormat) { int index = mClockDateFormat.findIndexOfValue((String) newValue); if (index == CUSTOM_CLOCK_DATE_FORMAT_INDEX) { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle(R.string.clock_date_string_edittext_title); alert.setMessage(R.string.clock_date_string_edittext_summary); final EditText input = new EditText(getActivity()); String oldText = Settings.System.getString( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_FORMAT); if (oldText != null) { input.setText(oldText); } alert.setView(input); alert.setPositiveButton( R.string.menu_save, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int whichButton) { String value = input.getText().toString(); if (value.equals("")) { return; } Settings.System.putString( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_FORMAT, value); return; } }); alert.setNegativeButton( R.string.menu_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int which) { return; } }); dialog = alert.create(); dialog.show(); } else { if ((String) newValue != null) { Settings.System.putString( getActivity().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_FORMAT, (String) newValue); } } return true; } return false; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.network_traffic); loadResources(); PreferenceScreen prefSet = getPreferenceScreen(); 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( getContentResolver(), 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(getContentResolver(), Settings.System.NETWORK_TRAFFIC_STATE, 0); int intIndex = mNetTrafficVal & (MASK_UP + MASK_DOWN); intIndex = mNetTrafficState.findIndexOfValue(String.valueOf(intIndex)); updateNetworkTrafficState(intIndex); 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); } }