コード例 #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SettingsActivityComponent cmp = DaggerService.getDaggerComponent(getActivity());
    cmp.inject(this);

    mSettings.setCached(true);

    addPreferencesFromResource(R.xml.prefs_service);

    runWhen = (ListPreference) findPreference(ServiceSettings.RUN_WHEN);
    runWhen.setPersistent(false);
    runWhen.setValue(mSettings.runWhen());
    runWhen.setOnPreferenceChangeListener(this);

    onlyOnWifi = (CheckBoxPreference) findPreference(ServiceSettings.ONLY_WIFI);
    onlyOnWifi.setPersistent(false);
    onlyOnWifi.setChecked(mSettings.onlyOnWifi());
    onlyOnWifi.setOnPreferenceChangeListener(this);

    wifiNetwork = (MultiSelectListPreference) findPreference(ServiceSettings.WIFI_NETWORKS);
    wifiNetwork.setPersistent(false);
    String[] ssids = getWifiNetworks();
    wifiNetwork.setEntries(ssids);
    wifiNetwork.setEntryValues(ssids);
    wifiNetwork.setValues(mSettings.allowedWifiNetworks());
    wifiNetwork.setOnPreferenceChangeListener(this);

    onlyCharging = (CheckBoxPreference) findPreference(ServiceSettings.ONLY_CHARGING);
    onlyCharging.setPersistent(false);
    onlyCharging.setChecked(mSettings.onlyWhenCharging());
    onlyCharging.setOnPreferenceChangeListener(this);

    catBetween = (PreferenceCategory) findPreference("cat_between");
    hideShowRunWhenCategories(mSettings.runWhen());

    scheduleStart = (TimePreference) findPreference(ServiceSettings.RANGE_START);
    scheduleStart.setPersistent(false);
    scheduleStart.setValue(mSettings.getScheduledStartTime());
    scheduleStart.setOnPreferenceChangeListener(this);

    scheduleEnd = (TimePreference) findPreference(ServiceSettings.RANGE_END);
    scheduleEnd.setPersistent(false);
    scheduleEnd.setValue(mSettings.getScheduledEndTime());
    scheduleEnd.setOnPreferenceChangeListener(this);

    exportConfig = findPreference("export");
    exportConfig.setOnPreferenceClickListener(this);
    importConfig = findPreference("import");
    importConfig.setOnPreferenceClickListener(this);
  }
 @Override
 public void setEntries(CharSequence[] entries) {
   super.setEntries(entries);
   if (mDialog != null) mDialog.setItems(entries);
 }