Example #1
0
 public void checkPrefferedLocale() {
   Configuration config = getBaseContext().getResources().getConfiguration();
   String lang = osmandSettings.PREFERRED_LOCALE.get();
   if (!"".equals(lang) && !config.locale.getLanguage().equals(lang)) {
     prefferedLocale = new Locale(lang);
     Locale.setDefault(prefferedLocale);
     config.locale = prefferedLocale;
     getBaseContext()
         .getResources()
         .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
   }
 }
Example #2
0
  @SuppressWarnings("unchecked")
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    // handle boolean prefences
    OsmandPreference<Boolean> boolPref = booleanPreferences.get(preference.getKey());
    OsmandPreference<Integer> seekPref = seekBarPreferences.get(preference.getKey());
    OsmandPreference<Object> listPref =
        (OsmandPreference<Object>) listPreferences.get(preference.getKey());
    OsmandPreference<String> editPref = editTextPreferences.get(preference.getKey());
    if (boolPref != null) {
      boolPref.set((Boolean) newValue);
      if (boolPref.getId().equals(osmandSettings.SAFE_MODE.getId())) {
        if (((Boolean) newValue).booleanValue()) {
          loadNativeLibrary();
        }
      }
    } else if (seekPref != null) {
      seekPref.set((Integer) newValue);
    } else if (editPref != null) {
      editPref.set((String) newValue);
    } else if (listPref != null) {
      int ind = ((ListPreference) preference).findIndexOfValue((String) newValue);
      CharSequence entry = ((ListPreference) preference).getEntries()[ind];
      Map<String, ?> map = listPrefValues.get(preference.getKey());
      Object obj = map.get(entry);
      final Object oldValue = listPref.get();
      boolean changed = listPref.set(obj);

      // Specific actions after list preference changed
      if (changed) {
        if (listPref.getId().equals(osmandSettings.VOICE_PROVIDER.getId())) {
          if (MORE_VALUE.equals(newValue)) {
            listPref.set(oldValue); // revert the change..
            final Intent intent = new Intent(this, DownloadIndexActivity.class);
            intent.putExtra(DownloadIndexActivity.FILTER_KEY, "voice");
            startActivity(intent);
          } else {
            getMyApplication().showDialogInitializingCommandPlayer(this, false);
          }
        } else if (listPref.getId().equals(osmandSettings.ROUTER_SERVICE.getId())) {
          routerServicePreference.setSummary(
              getString(R.string.router_service_descr)
                  + "  ["
                  + osmandSettings.ROUTER_SERVICE.get()
                  + "]");
        } else if (listPref.getId().equals(osmandSettings.APPLICATION_MODE.getId())) {
          updateAllSettings();
        } else if (listPref.getId().equals(osmandSettings.PREFERRED_LOCALE.getId())) {
          // restart application to update locale
          getMyApplication().checkPrefferedLocale();
          Intent intent = getIntent();
          finish();
          startActivity(intent);
        }
      }
    } else if (preference == applicationDir) {
      warnAboutChangingStorage((String) newValue);
      return false;
    }
    return true;
  }
Example #3
0
  @SuppressWarnings("unchecked")
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    // handle boolean prefences
    OsmandPreference<Boolean> boolPref = booleanPreferences.get(preference.getKey());
    OsmandPreference<Integer> seekPref = seekBarPreferences.get(preference.getKey());
    OsmandPreference<Object> listPref =
        (OsmandPreference<Object>) listPreferences.get(preference.getKey());
    OsmandPreference<String> editPref = editTextPreferences.get(preference.getKey());
    if (boolPref != null) {
      boolPref.set((Boolean) newValue);
      if (boolPref.getId().equals(osmandSettings.MAP_VECTOR_DATA.getId())) {
        MapRenderRepositories r =
            ((OsmandApplication) getApplication()).getResourceManager().getRenderer();
        if (r.isEmpty()) {
          Toast.makeText(this, getString(R.string.no_vector_map_loaded), Toast.LENGTH_LONG).show();
          return false;
        }
      }
    } else if (seekPref != null) {
      seekPref.set((Integer) newValue);
    } else if (editPref != null) {
      editPref.set((String) newValue);
    } else if (listPref != null) {
      int ind = ((ListPreference) preference).findIndexOfValue((String) newValue);
      CharSequence entry = ((ListPreference) preference).getEntries()[ind];
      Map<String, ?> map = listPrefValues.get(preference.getKey());
      Object obj = map.get(entry);
      final Object oldValue = listPref.get();
      boolean changed = listPref.set(obj);

      // Specific actions after list preference changed
      if (changed) {
        if (listPref.getId().equals(osmandSettings.VOICE_PROVIDER.getId())) {
          if (MORE_VALUE.equals(newValue)) {
            listPref.set(oldValue); // revert the change..
            final Intent intent = new Intent(this, DownloadIndexActivity.class);
            intent.putExtra(DownloadIndexActivity.FILTER_KEY, "voice");
            startActivity(intent);
          } else {
            getMyApplication().showDialogInitializingCommandPlayer(this, false);
          }
        } else if (listPref.getId().equals(osmandSettings.APPLICATION_MODE.getId())) {
          updateAllSettings();
        } else if (listPref.getId().equals(osmandSettings.PREFERRED_LOCALE.getId())) {
          // restart application to update locale
          getMyApplication().checkPrefferedLocale();
          Intent intent = getIntent();
          finish();
          startActivity(intent);
        }
      }
      if (listPref.getId().equals(osmandSettings.RENDERER.getId())) {
        if (changed) {
          Toast.makeText(this, R.string.renderer_load_sucess, Toast.LENGTH_SHORT).show();
        } else {
          Toast.makeText(this, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
        }
      }
    } else if (preference == applicationDir) {
      warnAboutChangingStorage((String) newValue);
      return false;
    } else if (preference == routeServiceEnabled) {
      Intent serviceIntent = new Intent(this, NavigationService.class);
      if ((Boolean) newValue) {
        ComponentName name = startService(serviceIntent);
        if (name == null) {
          routeServiceEnabled.setChecked(getMyApplication().getNavigationService() != null);
        }
      } else {
        if (!stopService(serviceIntent)) {
          routeServiceEnabled.setChecked(getMyApplication().getNavigationService() != null);
        }
      }
    } else if (preference == tileSourcePreference
        || preference == overlayPreference
        || preference == underlayPreference) {
      if (MORE_VALUE.equals(newValue)) {
        SettingsActivity.installMapLayers(
            this,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                updateTileSourceSummary();
              }
            });
      } else if (preference == tileSourcePreference) {
        osmandSettings.MAP_TILE_SOURCES.set((String) newValue);
        updateTileSourceSummary();
      } else {
        if (((String) newValue).length() == 0) {
          newValue = null;
        }
        if (preference == underlayPreference) {
          osmandSettings.MAP_UNDERLAY.set(((String) newValue));
        } else if (preference == overlayPreference) {
          osmandSettings.MAP_OVERLAY.set(((String) newValue));
        }
      }
    }
    return true;
  }