Example #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    CustomTitleBar titleBar =
        new CustomTitleBar(this, R.string.settings_activity, R.drawable.tab_settings_screen_icon);
    setTheme(R.style.CustomTitleTheme_Preference);
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings_pref);
    titleBar.afterSetContentView();

    String[] entries;
    String[] entrieValues;
    PreferenceScreen screen = getPreferenceScreen();
    osmandSettings = getMyApplication().getSettings();

    PreferenceCategory cat = (PreferenceCategory) screen.findPreference("global_app_settings");
    if (!Version.isBlackberry(this)) {
      CheckBoxPreference nativeCheckbox =
          createCheckBoxPreference(
              osmandSettings.SAFE_MODE, R.string.safe_mode, R.string.safe_mode_description);
      // disable the checkbox if the library cannot be used
      if ((NativeOsmandLibrary.isLoaded() && !NativeOsmandLibrary.isSupported())
          || osmandSettings.NATIVE_RENDERING_FAILED.get()) {
        nativeCheckbox.setEnabled(false);
        nativeCheckbox.setChecked(true);
      }
      cat.addPreference(nativeCheckbox);

      applicationDir = new EditTextPreference(this);
      applicationDir.setTitle(R.string.application_dir);
      applicationDir.setKey("external_storage_dir");
      applicationDir.setDialogTitle(R.string.application_dir);
      applicationDir.setOnPreferenceChangeListener(this);
      cat.addPreference(applicationDir);
    }

    //		BidForFixHelper bidForFixHelper = getMyApplication().getBidForFix();
    //		bidForFixHelper.generatePreferenceList(screen, getString(R.string.support_new_features),
    // this);
    OsmandPlugin.onSettingsActivityCreate(this, screen);

    registerBooleanPreference(osmandSettings.USE_ENGLISH_NAMES, screen);
    registerBooleanPreference(osmandSettings.AUTO_ZOOM_MAP, screen);
    registerBooleanPreference(osmandSettings.FAST_ROUTE_MODE, screen);
    registerBooleanPreference(osmandSettings.SNAP_TO_ROAD, screen);
    registerBooleanPreference(osmandSettings.USE_COMPASS_IN_NAVIGATION, screen);
    registerBooleanPreference(osmandSettings.LEFT_SIDE_NAVIGATION, screen);

    // List preferences
    //		registerListPreference(osmandSettings.ROTATE_MAP, screen,
    //				new String[]{getString(R.string.rotate_map_none_opt),
    // getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)},
    //				new Integer[]{OsmandSettings.ROTATE_MAP_NONE, OsmandSettings.ROTATE_MAP_BEARING,
    // OsmandSettings.ROTATE_MAP_COMPASS});

    registerListPreference(
        osmandSettings.MAP_SCREEN_ORIENTATION,
        screen,
        new String[] {
          getString(R.string.map_orientation_portrait),
          getString(R.string.map_orientation_landscape),
          getString(R.string.map_orientation_default)
        },
        new Integer[] {
          ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
          ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
          ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
        });

    MetricsConstants[] mvls =
        new MetricsConstants[] {
          MetricsConstants.KILOMETERS_AND_METERS,
          MetricsConstants.MILES_AND_FOOTS,
          MetricsConstants.MILES_AND_YARDS
        }; // MetricsConstants.values();
    entries = new String[mvls.length];
    for (int i = 0; i < entries.length; i++) {
      entries[i] = mvls[i].toHumanString(this);
    }
    registerListPreference(osmandSettings.METRIC_SYSTEM, screen, entries, mvls);

    // getResources().getAssets().getLocales();
    entrieValues =
        new String[] {
          "", "en", "af", "hy", "eu", "bs", "bg", "ca", "cs", "nl", "fi", "fr", "ka", "de", "el",
          "he", "hi", "hu", "id", "it", "ja", "ko", "lv", "lt", "mr", "no", "pl", "pt", "ro", "ru",
          "sk", "sl", "es", "sv", "uk", "vi"
        };
    entries =
        new String[] {
          getString(R.string.system_locale),
          "English",
          "Afrikaans",
          "Armenian",
          "Basque",
          "Bosnian",
          "Bulgarian",
          "Catalan",
          "Czech",
          "Dutch",
          "Finnish",
          "French",
          "Georgian",
          "German",
          "Greek",
          "Hebrew",
          "Hindi",
          "Hungarian",
          "Indonesian",
          "Italian",
          "Japanese",
          "Korean",
          "Latvian",
          "Lithuanian",
          "Marathi",
          "Norwegian",
          "Polish",
          "Portuguese",
          "Romanian",
          "Russian",
          "Slovak",
          "Slovenian",
          "Spanish",
          "Swedish",
          "Ukrainian",
          "Vietnamese"
        };
    registerListPreference(osmandSettings.PREFERRED_LOCALE, screen, entries, entrieValues);

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

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

    //		entries = new String[ApplicationMode.values().length];
    //		for(int i=0; i<entries.length; i++){
    //			entries[i] = ApplicationMode.values()[i].toHumanString(this);
    //		}
    //		registerListPreference(osmandSettings.APPLICATION_MODE, screen, entries,
    // ApplicationMode.values());
    //
    //		applicationModePreference = (ListPreference)
    // screen.findPreference(osmandSettings.APPLICATION_MODE.getId());
    //		applicationModePreference.setOnPreferenceChangeListener(this);

    routerServicePreference =
        (ListPreference) screen.findPreference(osmandSettings.ROUTER_SERVICE.getId());
    routerServicePreference.setOnPreferenceChangeListener(this);

    Preference localIndexes = (Preference) screen.findPreference(OsmandSettings.LOCAL_INDEXES);
    localIndexes.setOnPreferenceClickListener(this);
    bidforfix = (Preference) screen.findPreference("bidforfix");
    bidforfix.setOnPreferenceClickListener(this);
    plugins = (Preference) screen.findPreference("plugins");
    plugins.setOnPreferenceClickListener(this);
    avoidRouting = (Preference) screen.findPreference("avoid_in_routing");
    avoidRouting.setOnPreferenceClickListener(this);
    showAlarms = (Preference) screen.findPreference("show_routing_alarms");
    showAlarms.setOnPreferenceClickListener(this);

    Intent intent = getIntent();
    if (intent != null && intent.getIntExtra(INTENT_KEY_SETTINGS_SCREEN, 0) != 0) {
      int s = intent.getIntExtra(INTENT_KEY_SETTINGS_SCREEN, 0);
      String pref = null;
      if (s == SCREEN_GENERAL_SETTINGS) {
        pref = SCREEN_ID_GENERAL_SETTINGS;
      } else if (s == SCREEN_NAVIGATION_SETTINGS) {
        pref = SCREEN_ID_NAVIGATION_SETTINGS;
      }
      if (pref != null) {
        Preference toOpen = screen.findPreference(pref);
        if (toOpen instanceof PreferenceScreen) {
          setPreferenceScreen((PreferenceScreen) toOpen);
        }
      }
    }
  }
  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();
    }
  }