@Override
  public void onWindowFocusChanged(boolean hasFocus) {
    if (!hasFocus) return;

    mPreferencesList = new ArrayList<String>();
    mPreferenceScreen = getPreferenceScreen();
    initGroups(mPreferenceScreen);
    initValues();
  }
  private void initGroups(PreferenceGroup preferences) {
    final int count = preferences.getPreferenceCount();
    for (int i = 0; i < count; i++) {
      Preference pref = preferences.getPreference(i);
      if (pref instanceof PreferenceGroup) initGroups((PreferenceGroup) pref);
      else {
        pref.setOnPreferenceChangeListener(this);

        // Some Preference UI elements are not actually preferences,
        // but they require a key to work correctly. For example,
        // "Clear private data" requires a key for its state to be
        // saved when the orientation changes. It uses the
        // "android.not_a_preference.privacy.clear" key - which doesn't
        // exist in Gecko - to satisfy this requirement.
        String key = pref.getKey();
        if (key != null && !key.startsWith(NON_PREF_PREFIX)) {
          mPreferencesList.add(pref.getKey());
        }
      }
    }
  }