@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);

    menuPref = (MultiSelectListPreference) findPreference("menu_list");
    sitePref = (ListPreference) findPreference("site_list");

    menuPref.setOnPreferenceChangeListener(this);
  }
  @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);
  }
  @SuppressWarnings("deprecation")
  @SuppressLint("WorldReadableFiles")
  @Override
  protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
    addPreferencesFromResource(R.xml.pref_general);

    getViews();

    mPrefs = getSharedPreferences(Common.PREFS, Context.MODE_WORLD_READABLE);

    /* Workaround: since we now do the changes automatically as this activity
     * follows our XML now (overriden getSharedPreferences), emitting an intent
     * to update settings won't work since the changes are committed after the return.
     * We can workaround that in two ways: either delay the intent using a handler,
     * but that may cause some multiple intents to be fired for no reason, or
     * saving the changes manually then firing the intent. We do the latter here.
     */
    OnPreferenceChangeListener listener =
        new OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            preferenceChanged(preference, newValue);
            return true;
          }
        };

    mEnableTagLostCheckBox.setChecked(mPrefs.getBoolean(Common.PREF_TAGLOST, true));
    mEnableTagLostCheckBox.setOnPreferenceChangeListener(listener);

    mSoundsToPlay.setValues(
        mPrefs.getStringSet(
            Common.PREF_SOUNDS_TO_PLAY,
            new HashSet<String>(
                Arrays.asList(
                    getResources().getStringArray(R.array.pref_default_sounds_to_play)))));
    mSoundsToPlay.setOnPreferenceChangeListener(listener);

    mEnableNfcForStatesList.setSummary("   "); // required or will not update
    mEnableNfcForStatesList.setSummary("%s");
    mEnableNfcForStatesList.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            preferenceChanged(preference, newValue);
            mEnableNfcForStatesList.setSummary("   "); // required or will not update
            mEnableNfcForStatesList.setSummary("%s");
            return true;
          }
        });

    mCopyrightPreference.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            Resources resources = getResources();
            String[] contributors = resources.getStringArray(R.array.contributors);
            String[] methodsOfContribution = resources.getStringArray(R.array.contributors_how);
            String[] translators = resources.getStringArray(R.array.translators);
            String translatorsTitle = getString(R.string.translators_title);

            String contributorString = "";

            for (int i = 0; i < contributors.length; i++) {
              if (i != 0) contributorString += "\n";
              String contributor = "* %s (%s)";
              contributorString +=
                  String.format(contributor, contributors[i], methodsOfContribution[i]);
            }

            if (translators.length != 0) {
              contributorString += "\n\n";
              contributorString += translatorsTitle + ":" + "\n";

              for (int i = 0; i < translators.length; i++) {
                if (i != 0) contributorString += "\n";
                contributorString += "* " + translators[i];
              }
            }

            AlertDialog.Builder alertDialog =
                new AlertDialog.Builder(NFCLockScreenOffEnablerActivity.this)
                    .setTitle(R.string.contributors_title)
                    .setMessage(contributorString);

            alertDialog.show();
            return true;
          }
        });

    /*
    if (mPrefs.contains(Common.PREF_PRESENCE_CHECK_TIMEOUT)) {
    	mPresenceCheckTimeoutPreference.setSummary(getString(R.string.pref_summary_presence_check)
    			+ " " + mPrefs.getString(Common.PREF_PRESENCE_CHECK_TIMEOUT, "2000"));
    }
    mPresenceCheckTimeoutPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
    	@Override
    	public boolean onPreferenceChange(Preference preference, Object newValue) {
    		preferenceChanged(preference, newValue);
    		mPresenceCheckTimeoutPreference.setSummary(" ");
    		mPresenceCheckTimeoutPreference.setSummary(getString(R.string.pref_summary_presence_check)
    				+ " " + newValue);
    		return true;
    	}
    });

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
    	mPresenceCheckTimeoutPreference.setSummary(R.string.not_supported_yet_kitkat);
    	mPresenceCheckTimeoutPreference.setEnabled(false);
    }
    */

    findPreference(Common.PREF_DEBUG_MODE).setOnPreferenceChangeListener(listener);

    findPreference("show_in_launcher")
        .setOnPreferenceChangeListener(
            new OnPreferenceChangeListener() {
              @Override
              public boolean onPreferenceChange(Preference preference, Object newValue) {
                // Thanks to Chainfire for this
                // http://www.chainfire.eu/articles/133/_TUT_Supporting_multiple_icons_in_your_app/
                PackageManager pm = getPackageManager();
                pm.setComponentEnabledSetting(
                    new ComponentName(
                        getApplicationContext(), Common.MOD_PACKAGE_NAME + ".Activity-Launcher"),
                    (Boolean) newValue
                        ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                        : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
                return true;
              }
            });
  }