Пример #1
0
 public static String getVersionForTracker(Context ctx) {
   String v = Version.getAppName(ctx);
   if (Version.isProductionVersion(ctx)) {
     v = Version.getFullVersion(ctx);
   } else {
     v += " test";
   }
   return v;
 }
Пример #2
0
 protected void downloadFilesCheckFreeVersion() {
   if (Version.isFreeVersion(this)) {
     int total = settings.NUMBER_OF_FREE_DOWNLOADS.get() + entriesToDownload.size();
     boolean wiki = false;
     for (DownloadEntry es : entriesToDownload.values()) {
       if (es.baseName != null && es.baseName.contains("_wiki")) {
         wiki = true;
         break;
       }
     }
     if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) {
       Builder msg = new AlertDialog.Builder(this);
       msg.setTitle(R.string.free_version_title);
       msg.setMessage(
           getString(
               R.string.free_version_message,
               MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "",
               "( =" + total + ") "));
       msg.setPositiveButton(R.string.default_buttons_ok, null);
       msg.show();
     } else {
       downloadFilesPreCheckSpace();
     }
   } else {
     downloadFilesPreCheckSpace();
   }
 }
Пример #3
0
  public static void installMapLayers(
      final Activity activity, final ResultMatcher<TileSourceTemplate> result) {
    final OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings();
    final Map<String, String> entriesMap = settings.getTileSourceEntries();
    if (!settings.isInternetConnectionAvailable(true)) {
      AccessibleToast.makeText(activity, R.string.internet_not_available, Toast.LENGTH_LONG).show();
      return;
    }
    final List<TileSourceTemplate> downloaded =
        TileSourceManager.downloadTileSourceTemplates(Version.getVersionAsURLParam(activity));
    if (downloaded == null || downloaded.isEmpty()) {
      AccessibleToast.makeText(activity, R.string.error_io_error, Toast.LENGTH_SHORT).show();
      return;
    }
    Builder builder = new AlertDialog.Builder(activity);
    String[] names = new String[downloaded.size()];
    for (int i = 0; i < names.length; i++) {
      names[i] = downloaded.get(i).getName();
    }
    final boolean[] selected = new boolean[downloaded.size()];
    builder.setMultiChoiceItems(
        names,
        selected,
        new DialogInterface.OnMultiChoiceClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            selected[which] = isChecked;
            if (entriesMap.containsKey(downloaded.get(which).getName()) && isChecked) {
              AccessibleToast.makeText(
                      activity, R.string.tile_source_already_installed, Toast.LENGTH_SHORT)
                  .show();
            }
          }
        });
    builder.setNegativeButton(R.string.default_buttons_cancel, null);
    builder.setTitle(R.string.select_tile_source_to_install);
    builder.setPositiveButton(
        R.string.default_buttons_apply,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            List<TileSourceTemplate> toInstall = new ArrayList<TileSourceTemplate>();
            for (int i = 0; i < selected.length; i++) {
              if (selected[i]) {
                toInstall.add(downloaded.get(i));
              }
            }
            for (TileSourceTemplate ts : toInstall) {
              if (settings.installTileSource(ts)) {
                if (result != null) {
                  result.publish(ts);
                }
              }
            }
            // at the end publish null to show end of process
            if (!toInstall.isEmpty() && result != null) {
              result.publish(null);
            }
          }
        });

    builder.show();
  }
Пример #4
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);
        }
      }
    }
  }
Пример #5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    settings = ((OsmandApplication) getApplication()).getSettings();
    if (downloadListIndexThread == null) {
      downloadListIndexThread = new DownloadIndexListThread(this);
    }
    // recreation upon rotation is prevented in manifest file
    CustomTitleBar titleBar =
        new CustomTitleBar(
            this, R.string.local_index_download, R.drawable.tab_download_screen_icon);
    setContentView(R.layout.download_index);
    titleBar.afterSetContentView();

    downloadFileHelper = new DownloadFileHelper(this);
    findViewById(R.id.DownloadButton)
        .setOnClickListener(
            new View.OnClickListener() {

              @Override
              public void onClick(View v) {
                downloadFilesCheckFreeVersion();
              }
            });

    updateLoadedFiles();

    filterText = (EditText) findViewById(R.id.search_box);
    textWatcher =
        new TextWatcher() {
          @Override
          public void afterTextChanged(Editable s) {}

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            DownloadIndexAdapter adapter = ((DownloadIndexAdapter) getExpandableListAdapter());
            if (adapter != null) {
              adapter.getFilter().filter(s);
            }
          }
        };
    filterText.addTextChangedListener(textWatcher);
    final Intent intent = getIntent();
    if (intent != null && intent.getExtras() != null) {
      final String filter = intent.getExtras().getString(FILTER_KEY);
      if (filter != null) {
        filterText.setText(filter);
      }
    }

    if (downloadListIndexThread.getCachedIndexFiles() != null) {
      setListAdapter(new DownloadIndexAdapter(downloadListIndexThread.getCachedIndexFiles()));
    } else {
      downloadIndexList();
    }
    if (Version.isFreeVersion(this) && settings.checkFreeDownloadsNumberZero()) {
      Builder msg = new AlertDialog.Builder(this);
      msg.setTitle(R.string.free_version_title);
      msg.setMessage(
          getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "", ""));
      msg.show();
    }
  }
Пример #6
0
  public static String writeGpxFile(File fout, GPXFile file, Context ctx) {
    try {
      SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT);
      format.setTimeZone(TimeZone.getTimeZone("UTC"));
      FileOutputStream output = new FileOutputStream(fout);
      XmlSerializer serializer = Xml.newSerializer();
      serializer.setOutput(output, "UTF-8"); // $NON-NLS-1$
      serializer.setFeature(
          "http://xmlpull.org/v1/doc/features.html#indent-output", true); // $NON-NLS-1$
      serializer.startDocument("UTF-8", true); // $NON-NLS-1$
      serializer.startTag(null, "gpx"); // $NON-NLS-1$
      serializer.attribute(null, "version", "1.1"); // $NON-NLS-1$ //$NON-NLS-2$
      if (file.author == null) {
        serializer.attribute(null, "creator", Version.getAppName(ctx)); // $NON-NLS-1$
      } else {
        serializer.attribute(null, "creator", file.author); // $NON-NLS-1$
      }
      serializer.attribute(
          null, "xmlns", "http://www.topografix.com/GPX/1/1"); // $NON-NLS-1$ //$NON-NLS-2$
      serializer.attribute(null, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
      serializer.attribute(
          null,
          "xsi:schemaLocation",
          "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd");

      for (Track track : file.tracks) {
        serializer.startTag(null, "trk"); // $NON-NLS-1$
        writeNotNullText(serializer, "name", track.name);
        writeNotNullText(serializer, "desc", track.desc);
        for (TrkSegment segment : track.segments) {
          serializer.startTag(null, "trkseg"); // $NON-NLS-1$
          for (WptPt p : segment.points) {
            serializer.startTag(null, "trkpt"); // $NON-NLS-1$
            writeWpt(format, serializer, p);
            serializer.endTag(null, "trkpt"); // $NON-NLS-1$
          }
          serializer.endTag(null, "trkseg"); // $NON-NLS-1$
        }
        writeExtensions(serializer, track);
        serializer.endTag(null, "trk"); // $NON-NLS-1$
      }

      for (Route track : file.routes) {
        serializer.startTag(null, "rte"); // $NON-NLS-1$
        writeNotNullText(serializer, "name", track.name);
        writeNotNullText(serializer, "desc", track.desc);

        for (WptPt p : track.points) {
          serializer.startTag(null, "rtept"); // $NON-NLS-1$
          writeWpt(format, serializer, p);
          serializer.endTag(null, "rtept"); // $NON-NLS-1$
        }
        writeExtensions(serializer, track);
        serializer.endTag(null, "rte"); // $NON-NLS-1$
      }

      for (WptPt l : file.points) {
        serializer.startTag(null, "wpt"); // $NON-NLS-1$
        writeWpt(format, serializer, l);
        serializer.endTag(null, "wpt"); // $NON-NLS-1$
      }

      serializer.endTag(null, "gpx"); // $NON-NLS-1$
      serializer.flush();
      serializer.endDocument();
    } catch (RuntimeException e) {
      log.error("Error saving gpx", e); // $NON-NLS-1$
      return ctx.getString(R.string.error_occurred_saving_gpx);
    } catch (IOException e) {
      log.error("Error saving gpx", e); // $NON-NLS-1$
      return ctx.getString(R.string.error_occurred_saving_gpx);
    }
    return null;
  }