@SuppressWarnings("unchecked")
  @Override
  public boolean onPreferenceClick(Preference preference) {
    if (preference == avoidRouting || preference == preferRouting) {
      List<RoutingParameter> prms = preference == avoidRouting ? avoidParameters : preferParameters;
      String[] vals = new String[prms.size()];
      OsmandPreference[] bls = new OsmandPreference[prms.size()];
      for (int i = 0; i < prms.size(); i++) {
        RoutingParameter p = prms.get(i);
        vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName());
        bls[i] = settings.getCustomRoutingBooleanProperty(p.getId());
      }
      showBooleanSettings(vals, bls, preference.getTitle());
      return true;
    } else if (preference == showAlarms) {
      showBooleanSettings(
          new String[] {
            getString(R.string.show_traffic_warnings),
            getString(R.string.show_pedestrian_warnings),
            getString(R.string.show_cameras),
            getString(R.string.show_lanes)
          },
          new OsmandPreference[] {
            settings.SHOW_TRAFFIC_WARNINGS,
            settings.SHOW_PEDESTRIAN,
            settings.SHOW_CAMERAS,
            settings.SHOW_LANES
          },
          preference.getTitle());
      return true;
    } else if (preference == speakAlarms) {
      AlertDialog dlg =
          showBooleanSettings(
              new String[] {
                getString(R.string.speak_street_names),
                getString(R.string.speak_traffic_warnings),
                getString(R.string.speak_pedestrian),
                getString(R.string.speak_speed_limit),
                getString(R.string.speak_cameras),
                getString(R.string.announce_gpx_waypoints),
                getString(R.string.speak_favorites),
                getString(R.string.speak_poi)
              },
              new OsmandPreference[] {
                settings.SPEAK_STREET_NAMES,
                settings.SPEAK_TRAFFIC_WARNINGS,
                settings.SPEAK_PEDESTRIAN,
                settings.SPEAK_SPEED_LIMIT,
                settings.SPEAK_SPEED_CAMERA,
                settings.ANNOUNCE_WPT,
                settings.ANNOUNCE_NEARBY_FAVORITES,
                settings.ANNOUNCE_NEARBY_POI
              },
              preference.getTitle());
      if (!settings.SPEAK_SPEED_CAMERA.get()) {
        dlg.setOnDismissListener(
            new DialogInterface.OnDismissListener() {

              @Override
              public void onDismiss(DialogInterface dialog) {
                if (settings.SPEAK_SPEED_CAMERA.get()) {
                  settings.SPEAK_SPEED_CAMERA.set(false);
                  confirmSpeedCamerasDlg();
                }
              }
            });
      }
      return true;
    }
    return false;
  }
 private void prepareRoutingPrefs(PreferenceScreen screen) {
   PreferenceCategory cat = (PreferenceCategory) screen.findPreference("routing_preferences");
   cat.removeAll();
   CheckBoxPreference fastRoute =
       createCheckBoxPreference(
           settings.FAST_ROUTE_MODE, R.string.fast_route_mode, R.string.fast_route_mode_descr);
   if (settings.ROUTER_SERVICE.get() != RouteService.OSMAND) {
     cat.addPreference(fastRoute);
   } else {
     ApplicationMode am = settings.getApplicationMode();
     GeneralRouter router = getRouter(getMyApplication().getDefaultRoutingConfig(), am);
     clearParameters();
     if (router != null) {
       Map<String, RoutingParameter> parameters = router.getParameters();
       if (parameters.containsKey("short_way")) {
         cat.addPreference(fastRoute);
       }
       List<RoutingParameter> others = new ArrayList<GeneralRouter.RoutingParameter>();
       for (Map.Entry<String, RoutingParameter> e : parameters.entrySet()) {
         String param = e.getKey();
         if (param.startsWith("avoid_")) {
           avoidParameters.add(e.getValue());
         } else if (param.startsWith("prefer_")) {
           preferParameters.add(e.getValue());
         } else if (!param.equals("short_way")) {
           others.add(e.getValue());
         }
       }
       if (avoidParameters.size() > 0) {
         avoidRouting = new Preference(this);
         avoidRouting.setTitle(R.string.avoid_in_routing_title);
         avoidRouting.setSummary(R.string.avoid_in_routing_descr);
         avoidRouting.setOnPreferenceClickListener(this);
         cat.addPreference(avoidRouting);
       }
       if (preferParameters.size() > 0) {
         preferRouting = new Preference(this);
         preferRouting.setTitle(R.string.prefer_in_routing_title);
         preferRouting.setSummary(R.string.prefer_in_routing_descr);
         preferRouting.setOnPreferenceClickListener(this);
         cat.addPreference(preferRouting);
       }
       for (RoutingParameter p : others) {
         Preference basePref;
         if (p.getType() == RoutingParameterType.BOOLEAN) {
           basePref =
               createCheckBoxPreference(settings.getCustomRoutingBooleanProperty(p.getId()));
         } else {
           Object[] vls = p.getPossibleValues();
           String[] svlss = new String[vls.length];
           int i = 0;
           for (Object o : vls) {
             svlss[i++] = o.toString();
           }
           basePref =
               createListPreference(
                   settings.getCustomRoutingProperty(
                       p.getId(), p.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-"),
                   p.getPossibleValueDescriptions(),
                   svlss,
                   SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()),
                   SettingsBaseActivity.getRoutingStringPropertyDescription(
                       this, p.getId(), p.getDescription()));
         }
         basePref.setTitle(
             SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()));
         basePref.setSummary(
             SettingsBaseActivity.getRoutingStringPropertyDescription(
                 this, p.getId(), p.getDescription()));
         cat.addPreference(basePref);
       }
     }
     ApplicationMode mode = getMyApplication().getSettings().getApplicationMode();
     if (mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
       PreferenceCategory category =
           (PreferenceCategory) screen.findPreference("guidance_preferences");
       category.addPreference(speedLimitExceed);
     } else {
       PreferenceCategory category =
           (PreferenceCategory) screen.findPreference("guidance_preferences");
       category.removePreference(speedLimitExceed);
     }
   }
 }