@Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     addPreferencesFromResource(R.xml.advanced);
     if (!ShellUtils.isRooted()) {
         PreferenceCategory bypassCategoryPref = (PreferenceCategory) findPreference("Bypass");
         bypassCategoryPref.removePreference(bypassCategoryPref.findPreference("TcpScramblerEnabled"));
     }
 }
  @Override
  public void onResume() {
    super.onResume();

    mSettingsObserver.resume();
    mIm.registerInputDeviceListener(this, null);

    if (!mIsOnlyImeSettings) {
      if (mLanguagePref != null) {
        Configuration conf = getResources().getConfiguration();
        String language = conf.locale.getLanguage();
        String localeString;
        // TODO: This is not an accurate way to display the locale, as it is
        // just working around the fact that we support limited dialects
        // and want to pretend that the language is valid for all locales.
        // We need a way to support languages that aren't tied to a particular
        // locale instead of hiding the locale qualifier.
        if (hasOnlyOneLanguageInstance(language, Resources.getSystem().getAssets().getLocales())) {
          localeString = conf.locale.getDisplayLanguage(conf.locale);
        } else {
          localeString = conf.locale.getDisplayName(conf.locale);
        }
        if (localeString.length() > 1) {
          localeString = Character.toUpperCase(localeString.charAt(0)) + localeString.substring(1);
          mLanguagePref.setSummary(localeString);
        }
      }

      updateUserDictionaryPreference(findPreference(KEY_USER_DICTIONARY_SETTINGS));
      if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) {
        mShowInputMethodSelectorPref.setOnPreferenceChangeListener(this);
      }
    }

    if (mStatusBarImeSwitcher != null) {
      mStatusBarImeSwitcher.setChecked(
          Settings.System.getInt(
                  getActivity().getContentResolver(), Settings.System.STATUS_BAR_IME_SWITCHER, 1)
              != 0);
    }

    // Hard keyboard
    if (!mHardKeyboardPreferenceList.isEmpty()) {
      for (int i = 0; i < sHardKeyboardKeys.length; ++i) {
        CheckBoxPreference chkPref =
            (CheckBoxPreference) mHardKeyboardCategory.findPreference(sHardKeyboardKeys[i]);
        chkPref.setChecked(System.getInt(getContentResolver(), sSystemSettingNames[i], 1) > 0);
      }
    }

    updateInputDevices();

    // IME
    InputMethodAndSubtypeUtil.loadInputMethodSubtypeList(this, getContentResolver(), mImis, null);
    updateActiveInputMethodsSummary();
  }
 @Override
 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
   // Input Method stuff
   if (Utils.isMonkeyRunning()) {
     return false;
   }
   if (preference == mStatusBarImeSwitcher) {
     Settings.System.putInt(
         getActivity().getContentResolver(),
         Settings.System.STATUS_BAR_IME_SWITCHER,
         mStatusBarImeSwitcher.isChecked() ? 1 : 0);
     return true;
   } else if (preference instanceof PreferenceScreen) {
     if (preference.getFragment() != null) {
       // Fragment will be handled correctly by the super class.
     } else if (KEY_CURRENT_INPUT_METHOD.equals(preference.getKey())) {
       final InputMethodManager imm =
           (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
       imm.showInputMethodPicker();
     }
   } else if (preference instanceof CheckBoxPreference) {
     final CheckBoxPreference chkPref = (CheckBoxPreference) preference;
     if (!mHardKeyboardPreferenceList.isEmpty()) {
       for (int i = 0; i < sHardKeyboardKeys.length; ++i) {
         if (chkPref == mHardKeyboardCategory.findPreference(sHardKeyboardKeys[i])) {
           System.putInt(
               getContentResolver(), sSystemSettingNames[i], chkPref.isChecked() ? 1 : 0);
           return true;
         }
       }
     }
     if (chkPref == mGameControllerCategory.findPreference("vibrate_input_devices")) {
       System.putInt(
           getContentResolver(),
           Settings.System.VIBRATE_INPUT_DEVICES,
           chkPref.isChecked() ? 1 : 0);
       return true;
     }
   }
   return super.onPreferenceTreeClick(preferenceScreen, preference);
 }
  private void updateGameControllers() {
    if (haveInputDeviceWithVibrator()) {
      getPreferenceScreen().addPreference(mGameControllerCategory);

      CheckBoxPreference chkPref =
          (CheckBoxPreference) mGameControllerCategory.findPreference("vibrate_input_devices");
      chkPref.setChecked(
          System.getInt(getContentResolver(), Settings.System.VIBRATE_INPUT_DEVICES, 1) > 0);
    } else {
      getPreferenceScreen().removePreference(mGameControllerCategory);
    }
  }
  private void createUI() {
    addPreferencesFromResource(R.xml.navigation_settings);
    PreferenceScreen screen = getPreferenceScreen();
    settings = getMyApplication().getSettings();
    routerServicePreference =
        (ListPreference) screen.findPreference(settings.ROUTER_SERVICE.getId());

    RouteService[] vls = RouteService.getAvailableRouters(getMyApplication());
    String[] entries = new String[vls.length];
    for (int i = 0; i < entries.length; i++) {
      entries[i] = vls[i].getName();
    }
    registerListPreference(settings.ROUTER_SERVICE, screen, entries, vls);

    registerBooleanPreference(settings.SNAP_TO_ROAD, screen);

    Integer[] intValues = new Integer[] {0, 5, 10, 15, 20, 25, 30, 45, 60, 90};
    entries = new String[intValues.length];
    entries[0] = getString(R.string.shared_string_never);
    for (int i = 1; i < intValues.length; i++) {
      entries[i] = (int) intValues[i] + " " + getString(R.string.int_seconds);
    }
    registerListPreference(settings.AUTO_FOLLOW_ROUTE, screen, entries, intValues);

    entries = new String[AutoZoomMap.values().length];
    for (int i = 0; i < entries.length; i++) {
      entries[i] = getString(AutoZoomMap.values()[i].name);
    }
    registerListPreference(settings.AUTO_ZOOM_MAP, screen, entries, AutoZoomMap.values());

    // keep informing option:
    Integer[] keepInformingValues = new Integer[] {0, 1, 2, 3, 5, 7, 10, 15, 20, 25, 30};
    String[] keepInformingNames = new String[keepInformingValues.length];
    keepInformingNames[0] = getString(R.string.keep_informing_never);
    for (int i = 1; i < keepInformingValues.length; i++) {
      keepInformingNames[i] = keepInformingValues[i] + " " + getString(R.string.int_min);
    }
    registerListPreference(
        settings.KEEP_INFORMING, screen, keepInformingNames, keepInformingValues);

    SpeedConstants[] speedValues = SpeedConstants.values();
    String[] speedNamesVls = new String[speedValues.length];
    for (int i = 0; i < speedValues.length; i++) {
      speedNamesVls[i] = speedValues[i].toHumanString(this);
    }
    ;
    registerListPreference(settings.SPEED_SYSTEM, screen, speedNamesVls, speedValues);

    // screen power save option:
    Integer[] screenPowerSaveValues = new Integer[] {0, 5, 10, 15, 20, 30, 45, 60};
    String[] screenPowerSaveNames = new String[screenPowerSaveValues.length];
    screenPowerSaveNames[0] = getString(R.string.shared_string_never);
    for (int i = 1; i < screenPowerSaveValues.length; i++) {
      screenPowerSaveNames[i] = screenPowerSaveValues[i] + " " + getString(R.string.int_seconds);
    }
    registerListPreference(
        settings.WAKE_ON_VOICE_INT, screen, screenPowerSaveNames, screenPowerSaveValues);

    //         registerBooleanPreference(settings.SHOW_ZOOM_BUTTONS_NAVIGATION, screen);

    autoZoomMapPreference = (ListPreference) screen.findPreference(settings.AUTO_ZOOM_MAP.getId());
    autoZoomMapPreference.setOnPreferenceChangeListener(this);

    showAlarms = (Preference) screen.findPreference("show_routing_alarms");
    showAlarms.setOnPreferenceClickListener(this);

    speakAlarms = (Preference) screen.findPreference("speak_routing_alarms");
    speakAlarms.setOnPreferenceClickListener(this);

    Float[] arrivalValues = new Float[] {1.5f, 1f, 0.5f, 0.25f};
    String[] arrivalNames =
        new String[] {
          getString(R.string.arrival_distance_factor_early),
          getString(R.string.arrival_distance_factor_normally),
          getString(R.string.arrival_distance_factor_late),
          getString(R.string.arrival_distance_factor_at_last)
        };
    registerListPreference(settings.ARRIVAL_DISTANCE_FACTOR, screen, arrivalNames, arrivalValues);

    // array size should be equal!
    Float[] speedLimitsKm = new Float[] {0f, 5f, 7f, 10f, 15f, 20f};
    Float[] speedLimitsMiles = new Float[] {0f, 3f, 5f, 7f, 10f, 15f};
    if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
      String[] speedNames = new String[speedLimitsKm.length];
      for (int i = 0; i < speedLimitsKm.length; i++) {
        speedNames[i] = speedLimitsKm[i] + " " + getString(R.string.km_h);
      }
      registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsKm);
    } else {
      String[] speedNames = new String[speedLimitsKm.length];
      for (int i = 0; i < speedNames.length; i++) {
        speedNames[i] = speedLimitsMiles[i] + " " + getString(R.string.mile_per_hour);
      }
      registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsKm);
    }

    PreferenceCategory category =
        (PreferenceCategory) screen.findPreference("guidance_preferences");
    speedLimitExceed = (ListPreference) category.findPreference("speed_limit_exceed");
    ApplicationMode mode = getMyApplication().getSettings().getApplicationMode();
    if (!mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
      category.removePreference(speedLimitExceed);
    }

    // deprecated 2.2
    //		Integer[] delayIntervals = new Integer[] { -1, 3, 5, 7, 10, 15, 20 };
    //		String[] delayIntervalNames = new String[delayIntervals.length];
    //		for (int i = 0; i < delayIntervals.length; i++) {
    //			if (i == 0) {
    //				delayIntervalNames[i] = getString(R.string.auto_follow_route_never);
    //			} else {
    //				delayIntervalNames[i] = delayIntervals[i] + " " + getString(R.string.int_seconds);
    //			}
    //		}
    // registerListPreference(settings.DELAY_TO_START_NAVIGATION, screen, delayIntervalNames,
    // delayIntervals);

    if (getIntent() != null && getIntent().hasExtra(INTENT_SKIP_DIALOG)) {
      setSelectedAppMode(settings.getApplicationMode());
    } else {
      profileDialog();
    }
  }