示例#1
0
  public void showDialogInitializingCommandPlayer(
      final Activity uiContext, boolean warningNoneProvider, Runnable run) {
    String voiceProvider = osmandSettings.VOICE_PROVIDER.get();
    if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
      if (warningNoneProvider && voiceProvider == null) {
        Builder builder = new AlertDialog.Builder(uiContext);
        builder.setCancelable(true);
        builder.setNegativeButton(R.string.default_buttons_cancel, null);
        builder.setPositiveButton(
            R.string.default_buttons_ok,
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(uiContext, SettingsActivity.class);
                intent.putExtra(
                    SettingsActivity.INTENT_KEY_SETTINGS_SCREEN,
                    SettingsActivity.SCREEN_NAVIGATION_SETTINGS);
                uiContext.startActivity(intent);
              }
            });
        builder.setTitle(R.string.voice_is_not_available_title);
        builder.setMessage(R.string.voice_is_not_available_msg);
        builder.show();
      }

    } else {
      if (player == null || !Algorithms.objectEquals(voiceProvider, player.getCurrentVoice())) {
        initVoiceDataInDifferentThread(uiContext, voiceProvider, run);
      }
    }
  }
示例#2
0
  public void showDialogInitializingCommandPlayer(
      final Activity uiContext, boolean warningNoneProvider, Runnable run, boolean showDialog) {
    String voiceProvider = osmandSettings.VOICE_PROVIDER.get();
    if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
      if (warningNoneProvider && voiceProvider == null) {
        Builder builder = new AccessibleAlertBuilder(uiContext);
        LinearLayout ll = new LinearLayout(uiContext);
        ll.setOrientation(LinearLayout.VERTICAL);
        final TextView tv = new TextView(uiContext);
        tv.setPadding(7, 3, 7, 0);
        tv.setText(R.string.voice_is_not_available_msg);
        tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 19);
        ll.addView(tv);

        final CheckBox cb = new CheckBox(uiContext);
        cb.setText(R.string.shared_string_remember_my_choice);
        LinearLayout.LayoutParams lp =
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        lp.setMargins(7, 10, 7, 0);
        cb.setLayoutParams(lp);
        ll.addView(cb);

        builder.setCancelable(true);
        builder.setNegativeButton(
            R.string.shared_string_cancel,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                if (cb.isChecked()) {
                  osmandSettings.VOICE_PROVIDER.set(OsmandSettings.VOICE_PROVIDER_NOT_USE);
                }
              }
            });
        builder.setPositiveButton(
            R.string.shared_string_ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(uiContext, SettingsActivity.class);
                intent.putExtra(
                    SettingsActivity.INTENT_KEY_SETTINGS_SCREEN,
                    SettingsActivity.SCREEN_GENERAL_SETTINGS);
                uiContext.startActivity(intent);
              }
            });

        builder.setTitle(R.string.voice_is_not_available_title);
        builder.setView(ll);
        // builder.setMessage(R.string.voice_is_not_available_msg);
        builder.show();
      }

    } else {
      if (player == null || !Algorithms.objectEquals(voiceProvider, player.getCurrentVoice())) {
        appInitializer.initVoiceDataInDifferentThread(uiContext, voiceProvider, run, showDialog);
      }
    }
  }
示例#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.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;
  }
示例#4
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;
  }