@Override
 public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
   final Resources res = getResources();
   if (key.equals(Settings.PREF_POPUP_ON)) {
     setPreferenceEnabled(
         Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY,
         Settings.readKeyPreviewPopupEnabled(prefs, res));
   } else if (key.equals(Settings.PREF_SHOW_SETUP_WIZARD_ICON)) {
     LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity());
   }
   updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
   refreshEnablingsOfKeypressSoundAndVibrationSettings();
 }
  @Override
  public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.prefs_screen_advanced);

    final Resources res = getResources();
    final Context context = getActivity();

    // When we are called from the Settings application but we are not already running, some
    // singleton and utility classes may not have been initialized.  We have to call
    // initialization method of these classes here. See {@link LatinIME#onCreate()}.
    AudioAndHapticFeedbackManager.init(context);

    final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();

    if (!Settings.isInternal(prefs)) {
      removePreference(Settings.SCREEN_DEBUG);
    }

    if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
      removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS);
    }

    // TODO: consolidate key preview dismiss delay with the key preview animation parameters.
    if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupOption(res)) {
      removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
    } else {
      // TODO: Cleanup this setup.
      final ListPreference keyPreviewPopupDismissDelay =
          (ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
      final String popupDismissDelayDefaultValue =
          Integer.toString(res.getInteger(R.integer.config_key_preview_linger_timeout));
      keyPreviewPopupDismissDelay.setEntries(
          new String[] {
            res.getString(R.string.key_preview_popup_dismiss_no_delay),
            res.getString(R.string.key_preview_popup_dismiss_default_delay),
          });
      keyPreviewPopupDismissDelay.setEntryValues(new String[] {"0", popupDismissDelayDefaultValue});
      if (null == keyPreviewPopupDismissDelay.getValue()) {
        keyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
      }
      keyPreviewPopupDismissDelay.setEnabled(Settings.readKeyPreviewPopupEnabled(prefs, res));
    }

    if (!res.getBoolean(R.bool.config_setup_wizard_available)) {
      removePreference(Settings.PREF_SHOW_SETUP_WIZARD_ICON);
    }

    if (ProductionFlags.IS_METRICS_LOGGING_SUPPORTED) {
      final Preference enableMetricsLogging = findPreference(Settings.PREF_ENABLE_METRICS_LOGGING);
      if (enableMetricsLogging != null) {
        final int applicationLabelRes = context.getApplicationInfo().labelRes;
        final String applicationName = res.getString(applicationLabelRes);
        final String enableMetricsLoggingTitle =
            res.getString(R.string.enable_metrics_logging, applicationName);
        enableMetricsLogging.setTitle(enableMetricsLoggingTitle);
      }
    } else {
      removePreference(Settings.PREF_ENABLE_METRICS_LOGGING);
    }

    setupKeypressVibrationDurationSettings();
    setupKeypressSoundVolumeSettings();
    refreshEnablingsOfKeypressSoundAndVibrationSettings();
  }