コード例 #1
0
  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);
  }
  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;
  }
コード例 #3
0
  @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);
    }
  }