private void startApplicationBackground() {
    List<String> warnings = new ArrayList<String>();
    try {
      if (!Version.isBlackberry(this)) {
        if (osmandSettings.NATIVE_RENDERING_FAILED.get()) {
          osmandSettings.SAFE_MODE.set(true);
          osmandSettings.NATIVE_RENDERING_FAILED.set(false);
          warnings.add(getString(R.string.native_library_not_supported));
        } else if (!osmandSettings.SAFE_MODE.get()) {
          osmandSettings.NATIVE_RENDERING_FAILED.set(true);
          startDialog.startTask(getString(R.string.init_native_library), -1);
          RenderingRulesStorage storage = rendererRegistry.getCurrentSelectedRenderer();
          boolean initialized = NativeOsmandLibrary.getLibrary(storage, this) != null;
          osmandSettings.NATIVE_RENDERING_FAILED.set(false);
          if (!initialized) {
            LOG.info("Native library could not be loaded!");
          }
        } else {
          warnings.add(getString(R.string.native_library_not_running));
        }
      }
      warnings.addAll(manager.reloadIndexes(startDialog));
      player = null;
      if (savingTrackHelper.hasDataToSave()) {
        startDialog.startTask(getString(R.string.saving_gpx_tracks), -1);
        warnings.addAll(savingTrackHelper.saveDataToGpx());
      }

      // restore backuped favorites to normal file
      final File appDir = getAppPath(null);
      File save = new File(appDir, FavouritesDbHelper.FILE_TO_SAVE);
      File bak = new File(appDir, FavouritesDbHelper.FILE_TO_BACKUP);
      if (bak.exists() && (!save.exists() || bak.lastModified() > save.lastModified())) {
        if (save.exists()) {
          save.delete();
        }
        bak.renameTo(save);
      }
    } finally {
      synchronized (OsmandApplication.this) {
        final ProgressDialog toDismiss;
        if (startDialog != null) {
          toDismiss = startDialog.getDialog();
        } else {
          toDismiss = null;
        }
        startDialog = null;

        if (toDismiss != null) {
          uiHandler.post(
              new Runnable() {
                @Override
                public void run() {
                  if (toDismiss != null) {
                    // TODO handling this dialog is bad, we need a better standard way
                    toDismiss.dismiss();
                    // toDismiss.getOwnerActivity().dismissDialog(PROGRESS_DIALOG);
                  }
                }
              });
          showWarnings(warnings, toDismiss.getContext());
        } else {
          startingWarnings = warnings;
        }
      }
    }
  }
Beispiel #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;
  }