From 93af937d8939b29a9676cf625361e2f601a9c4c7 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 24 Jan 2012 00:14:25 +0100 Subject: [PATCH] Change version track mechanism. Split mapcreator and osmand. --- .../{Version.java => MapCreatorVersion.java} | 19 ++----- .../net/osmand/data/MapTileDownloader.java | 9 +--- .../osmand/data/index/IndexBatchCreator.java | 4 +- .../net/osmand/data/index/WikiIndexer.java | 4 +- .../src/net/osmand/map/TileSourceManager.java | 5 +- .../src/net/osmand/swing/MapPanel.java | 6 +-- .../src/net/osmand/swing/OsmExtractionUI.java | 4 +- .../swing/TileBundleDownloadDialog.java | 4 +- OsmAnd/res/values/no_translate.xml | 2 +- OsmAnd/src/net/osmand/GPXUtilities.java | 2 +- OsmAnd/src/net/osmand/Version.java | 50 +++++++++++++++++++ .../net/osmand/plus/AsyncLoadingThread.java | 20 ++++---- .../plus/DownloadOsmandIndexesHelper.java | 5 +- .../net/osmand/plus/NavigationService.java | 2 +- .../src/net/osmand/plus/OsmandSettings.java | 3 +- .../src/net/osmand/plus/ResourceManager.java | 17 +++++-- .../plus/activities/DownloadFileHelper.java | 6 +-- .../activities/DownloadIndexActivity.java | 31 +++++++----- .../plus/activities/DownloadTilesDialog.java | 3 +- .../plus/activities/EditingPOIActivity.java | 6 +-- .../plus/activities/MainMenuActivity.java | 10 ++-- .../osmand/plus/activities/MapActivity.java | 7 ++- .../activities/NavigatePointActivity.java | 2 - .../plus/activities/OsmandApplication.java | 2 - .../plus/activities/SettingsActivity.java | 3 +- .../search/SearchAddressOnlineActivity.java | 2 +- .../osmand/plus/views/OsmandMapTileView.java | 5 +- 27 files changed, 136 insertions(+), 97 deletions(-) rename DataExtractionOSM/src/net/osmand/{Version.java => MapCreatorVersion.java} (58%) create mode 100644 OsmAnd/src/net/osmand/Version.java diff --git a/DataExtractionOSM/src/net/osmand/Version.java b/DataExtractionOSM/src/net/osmand/MapCreatorVersion.java similarity index 58% rename from DataExtractionOSM/src/net/osmand/Version.java rename to DataExtractionOSM/src/net/osmand/MapCreatorVersion.java index 4e0f39a50b..3232f082de 100644 --- a/DataExtractionOSM/src/net/osmand/Version.java +++ b/DataExtractionOSM/src/net/osmand/MapCreatorVersion.java @@ -3,28 +3,15 @@ package net.osmand; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -public class Version { +public class MapCreatorVersion { + public static String APP_VERSION = "0.7.1"; //$NON-NLS-1$ public static final String APP_DESCRIPTION = "alpha"; //$NON-NLS-1$ - + public static final String APP_MAP_CREATOR_NAME = "OsmAndMapCreator"; //$NON-NLS-1$ public static final String APP_MAP_CREATOR_VERSION = APP_MAP_CREATOR_NAME + " " + APP_VERSION; //$NON-NLS-1$ public static final String APP_MAP_CREATOR_FULL_NAME = APP_MAP_CREATOR_NAME + " " + APP_VERSION + " " +APP_DESCRIPTION; //$NON-NLS-1$ //$NON-NLS-2$ - public static String APP_NAME = "OsmAnd"; //$NON-NLS-1$ - public static String APP_NAME_VERSION = APP_NAME + " " + APP_VERSION; //$NON-NLS-1$ - public static String APP_FULL_NAME = APP_NAME + " " + APP_VERSION + " " +APP_DESCRIPTION; //$NON-NLS-1$ //$NON-NLS-2$ - - public static void setAppVersionAndName(String appName, String appVersion){ - APP_VERSION = appVersion; - APP_NAME = appName; - APP_NAME_VERSION = APP_NAME + " " + APP_VERSION; //$NON-NLS-1$ - APP_FULL_NAME = APP_NAME + " " + APP_VERSION + " " +APP_DESCRIPTION; //$NON-NLS-1$ //$NON-NLS-2$ - } - - - - public static String getVersionAsURLParam() { try { return "osmandver=" + URLEncoder.encode(APP_VERSION + " " + APP_DESCRIPTION, "UTF-8"); diff --git a/DataExtractionOSM/src/net/osmand/data/MapTileDownloader.java b/DataExtractionOSM/src/net/osmand/data/MapTileDownloader.java index dda0b4a8a7..ce8f45a47b 100644 --- a/DataExtractionOSM/src/net/osmand/data/MapTileDownloader.java +++ b/DataExtractionOSM/src/net/osmand/data/MapTileDownloader.java @@ -17,7 +17,6 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import net.osmand.Algoritms; -import net.osmand.Version; import net.osmand.LogUtil; import org.apache.commons.logging.Log; @@ -32,7 +31,7 @@ public class MapTileDownloader { private static MapTileDownloader downloader = null; private static Log log = LogUtil.getLog(MapTileDownloader.class); - public static String USER_AGENT = Version.APP_NAME_VERSION; + public static String USER_AGENT = "Osmand~"; private ThreadPoolExecutor threadPoolExecutor; @@ -43,12 +42,6 @@ public class MapTileDownloader { private int currentErrors = 0; - - - public static MapTileDownloader getInstance(){ - return getInstance(Version.APP_NAME_VERSION); - } - public static MapTileDownloader getInstance(String userAgent){ if(downloader == null){ downloader = new MapTileDownloader(TILE_DOWNLOAD_THREADS); diff --git a/DataExtractionOSM/src/net/osmand/data/index/IndexBatchCreator.java b/DataExtractionOSM/src/net/osmand/data/index/IndexBatchCreator.java index feedd212a9..bfe71a8b2a 100644 --- a/DataExtractionOSM/src/net/osmand/data/index/IndexBatchCreator.java +++ b/DataExtractionOSM/src/net/osmand/data/index/IndexBatchCreator.java @@ -31,7 +31,7 @@ import javax.xml.parsers.ParserConfigurationException; import net.osmand.Algoritms; import net.osmand.LogUtil; -import net.osmand.Version; +import net.osmand.MapCreatorVersion; import net.osmand.data.IndexConstants; import net.osmand.data.preparation.DBDialect; import net.osmand.data.preparation.IndexCreator; @@ -455,7 +455,7 @@ public class IndexBatchCreator { FileOutputStream fout = new FileOutputStream(logFileName); fout.write((new Date() + "\n").getBytes()); - fout.write((Version.APP_MAP_CREATOR_FULL_NAME + "\n").getBytes()); + fout.write((MapCreatorVersion.APP_MAP_CREATOR_FULL_NAME + "\n").getBytes()); fout.close(); fh = new FileHandler(logFileName.getAbsolutePath(), 5000000, 1, true); fh.setFormatter(new SimpleFormatter()); diff --git a/DataExtractionOSM/src/net/osmand/data/index/WikiIndexer.java b/DataExtractionOSM/src/net/osmand/data/index/WikiIndexer.java index e8b0e9d809..04e0a9b666 100644 --- a/DataExtractionOSM/src/net/osmand/data/index/WikiIndexer.java +++ b/DataExtractionOSM/src/net/osmand/data/index/WikiIndexer.java @@ -29,7 +29,7 @@ import org.xml.sax.helpers.DefaultHandler; import net.osmand.Algoritms; import net.osmand.LogUtil; -import net.osmand.Version; +import net.osmand.MapCreatorVersion; import net.osmand.data.preparation.IndexCreator; import net.osmand.impl.ConsoleProgressImplementation; @@ -251,7 +251,7 @@ public class WikiIndexer { streamWriter.writeCharacters("\n"); streamWriter.writeStartElement("osm"); streamWriter.writeAttribute("version", "0.6"); - streamWriter.writeAttribute("generator", Version.APP_MAP_CREATOR_VERSION); + streamWriter.writeAttribute("generator", MapCreatorVersion.APP_MAP_CREATOR_VERSION); progress.startTask("Parse wiki xml", progIS.available()); } diff --git a/DataExtractionOSM/src/net/osmand/map/TileSourceManager.java b/DataExtractionOSM/src/net/osmand/map/TileSourceManager.java index f6e9a1ea23..eec1ac5512 100644 --- a/DataExtractionOSM/src/net/osmand/map/TileSourceManager.java +++ b/DataExtractionOSM/src/net/osmand/map/TileSourceManager.java @@ -23,7 +23,6 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import net.osmand.LogUtil; -import net.osmand.Version; import org.apache.commons.logging.Log; import org.xml.sax.Attributes; @@ -320,10 +319,10 @@ public class TileSourceManager { } - public static List downloadTileSourceTemplates() { + public static List downloadTileSourceTemplates(String versionAsUrl) { final List templates = new ArrayList(); try { - URLConnection connection = new URL("http://download.osmand.net//tile_sources.php?" + Version.getVersionAsURLParam()).openConnection(); + URLConnection connection = new URL("http://download.osmand.net//tile_sources.php?" + versionAsUrl).openConnection(); final SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); saxParser.parse(connection.getInputStream(), new DefaultHandler(){ @Override diff --git a/DataExtractionOSM/src/net/osmand/swing/MapPanel.java b/DataExtractionOSM/src/net/osmand/swing/MapPanel.java index 655aac3992..feaff4e555 100644 --- a/DataExtractionOSM/src/net/osmand/swing/MapPanel.java +++ b/DataExtractionOSM/src/net/osmand/swing/MapPanel.java @@ -41,7 +41,7 @@ import javax.swing.UIManager; import net.osmand.Algoritms; import net.osmand.LogUtil; -import net.osmand.Version; +import net.osmand.MapCreatorVersion; import net.osmand.data.DataTileManager; import net.osmand.data.MapTileDownloader; import net.osmand.data.MapTileDownloader.DownloadRequest; @@ -99,7 +99,7 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback { final JMenu downloadedMenu = new JMenu("Additional"); //$NON-NLS-1$ final File tilesDirectory = DataExtractionSettings.getSettings().getTilesDirectory(); Map udf = getCommonTemplates(tilesDirectory); - final List downloaded = TileSourceManager.downloadTileSourceTemplates(); + final List downloaded = TileSourceManager.downloadTileSourceTemplates(MapCreatorVersion.APP_VERSION); final Map items = new IdentityHashMap(); tiles.add(downloadedMenu); @@ -251,7 +251,7 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback { private int xStartingImage = 0; private int yStartingImage = 0; - private MapTileDownloader downloader = MapTileDownloader.getInstance(Version.APP_MAP_CREATOR_VERSION); + private MapTileDownloader downloader = MapTileDownloader.getInstance(MapCreatorVersion.APP_MAP_CREATOR_VERSION); Map cache = new HashMap(); private JPopupMenu popupMenu; diff --git a/DataExtractionOSM/src/net/osmand/swing/OsmExtractionUI.java b/DataExtractionOSM/src/net/osmand/swing/OsmExtractionUI.java index 64acf48731..6058aed138 100644 --- a/DataExtractionOSM/src/net/osmand/swing/OsmExtractionUI.java +++ b/DataExtractionOSM/src/net/osmand/swing/OsmExtractionUI.java @@ -39,7 +39,7 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.xml.stream.XMLStreamException; -import net.osmand.Version; +import net.osmand.MapCreatorVersion; import net.osmand.data.preparation.IndexCreator; import net.osmand.map.IMapLocationListener; import net.osmand.map.ITileSource; @@ -252,7 +252,7 @@ public class OsmExtractionUI implements IMapLocationListener { aboutApplication.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - JOptionPane.showMessageDialog(frame, Version.APP_MAP_CREATOR_FULL_NAME); + JOptionPane.showMessageDialog(frame, MapCreatorVersion.APP_MAP_CREATOR_FULL_NAME); } }); diff --git a/DataExtractionOSM/src/net/osmand/swing/TileBundleDownloadDialog.java b/DataExtractionOSM/src/net/osmand/swing/TileBundleDownloadDialog.java index 0bcc065035..5555160b77 100644 --- a/DataExtractionOSM/src/net/osmand/swing/TileBundleDownloadDialog.java +++ b/DataExtractionOSM/src/net/osmand/swing/TileBundleDownloadDialog.java @@ -24,7 +24,7 @@ import javax.swing.SpinnerNumberModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import net.osmand.Version; +import net.osmand.MapCreatorVersion; import net.osmand.data.MapTileDownloader; import net.osmand.data.MapTileDownloader.DownloadRequest; import net.osmand.data.MapTileDownloader.IMapDownloaderCallback; @@ -185,7 +185,7 @@ public class TileBundleDownloadDialog extends JDialog { numberTiles += (x2 - x1 + 1) * (y2 - y1 + 1); } final int number = numberTiles; - final MapTileDownloader instance = MapTileDownloader.getInstance(Version.APP_MAP_CREATOR_VERSION); + final MapTileDownloader instance = MapTileDownloader.getInstance(MapCreatorVersion.APP_MAP_CREATOR_VERSION); progressDialog.setRunnable(new Runnable(){ @Override diff --git a/OsmAnd/res/values/no_translate.xml b/OsmAnd/res/values/no_translate.xml index dc2679bae1..36787c8477 100644 --- a/OsmAnd/res/values/no_translate.xml +++ b/OsmAnd/res/values/no_translate.xml @@ -1,7 +1,7 @@ Osmand+ - 0.7.0 beta + 0.7.0 alpha UA-28342846-2 10 diff --git a/OsmAnd/src/net/osmand/GPXUtilities.java b/OsmAnd/src/net/osmand/GPXUtilities.java index 34d58ca42a..87bb1be6f6 100644 --- a/OsmAnd/src/net/osmand/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/GPXUtilities.java @@ -137,7 +137,7 @@ public class GPXUtilities { 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.APP_NAME_VERSION); //$NON-NLS-1$ + serializer.attribute(null, "creator", Version.getAppName(ctx)); //$NON-NLS-1$ } else { serializer.attribute(null, "creator", file.author); //$NON-NLS-1$ } diff --git a/OsmAnd/src/net/osmand/Version.java b/OsmAnd/src/net/osmand/Version.java new file mode 100644 index 0000000000..04ff0fa139 --- /dev/null +++ b/OsmAnd/src/net/osmand/Version.java @@ -0,0 +1,50 @@ +package net.osmand; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +import net.osmand.plus.R; + +import android.content.Context; + +public class Version { + + private final String appVersion; + private final String appName; + + private Version(Context ctx) { + appVersion = ctx.getString(R.string.app_version); + appName = ctx.getString(R.string.app_name); + } + + private static Version ver = null; + private static Version getVersion(Context ctx){ + if(ver == null){ + ver = new Version(ctx); + } + return ver; + } + + public static String getFullVersion(Context ctx){ + Version v = getVersion(ctx); + return v.appName + " " + v.appVersion; + } + + public static String getAppName(Context ctx){ + Version v = getVersion(ctx); + return v.appName; + } + + public static boolean isProductionVersion(Context ctx){ + Version v = getVersion(ctx); + return !v.appVersion.startsWith("#"); + } + + public static String getVersionAsURLParam(Context ctx) { + try { + return "osmandver=" + URLEncoder.encode(getFullVersion(ctx), "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java b/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java index 0e1b2486f5..399555e687 100644 --- a/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java +++ b/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java @@ -12,7 +12,6 @@ import net.osmand.Algoritms; import net.osmand.LogUtil; import net.osmand.ResultMatcher; import net.osmand.data.Amenity; -import net.osmand.data.MapTileDownloader; import net.osmand.data.TransportStop; import net.osmand.data.MapTileDownloader.DownloadRequest; import net.osmand.data.MapTileDownloader.IMapDownloaderCallback; @@ -34,7 +33,6 @@ public class AsyncLoadingThread extends Thread { AmenityLoadRequest poiLoadRequest = null; TransportLoadRequest transportLoadRequest = null; - private static final MapTileDownloader downloader = MapTileDownloader.getInstance(); private final ResourceManager resourceManger; @@ -57,7 +55,7 @@ public class AsyncLoadingThread extends Thread { private int calculateProgressStatus(){ int progress = 0; - if (downloader.isSomethingBeingDownloaded()) { + if (resourceManger.getMapTileDownloader().isSomethingBeingDownloaded()) { progress = BusyIndicator.STATUS_GREEN; } else if (resourceManger.getContext().getRoutingHelper().isRouteBeingCalculated()) { progress = BusyIndicator.STATUS_BLUE; @@ -118,14 +116,14 @@ public class AsyncLoadingThread extends Thread { } else if (req instanceof MapLoadRequest) { if (!mapLoaded) { MapLoadRequest r = (MapLoadRequest) req; - resourceManger.getRenderer().loadMap(r.tileBox, downloader.getDownloaderCallbacks()); + resourceManger.getRenderer().loadMap(r.tileBox, resourceManger.getMapTileDownloader().getDownloaderCallbacks()); mapLoaded = true; } } } if (tileLoaded || amenityLoaded || transportLoaded || mapLoaded) { // use downloader callback - for (IMapDownloaderCallback c : downloader.getDownloaderCallbacks()) { + for (IMapDownloaderCallback c : resourceManger.getMapTileDownloader().getDownloaderCallbacks()) { c.tileDownloaded(null); } } @@ -163,11 +161,11 @@ public class AsyncLoadingThread extends Thread { } public boolean isFileCurrentlyDownloaded(File fileToSave) { - return downloader.isFileCurrentlyDownloaded(fileToSave); + return resourceManger.getMapTileDownloader().isFileCurrentlyDownloaded(fileToSave); } public void requestToDownload(TileLoadDownloadRequest req) { - downloader.requestToDownload(req); + resourceManger.getMapTileDownloader().requestToDownload(req); } protected static class TileLoadDownloadRequest extends DownloadRequest { @@ -185,7 +183,7 @@ public class AsyncLoadingThread extends Thread { } } - protected static class MapObjectLoadRequest implements ResultMatcher { + protected class MapObjectLoadRequest implements ResultMatcher { protected double topLatitude; protected double bottomLatitude; protected double leftLongitude; @@ -217,7 +215,7 @@ public class AsyncLoadingThread extends Thread { public void finish() { running = false; // use downloader callback - for (IMapDownloaderCallback c : downloader.getDownloaderCallbacks()) { + for (IMapDownloaderCallback c : resourceManger.getMapTileDownloader().getDownloaderCallbacks()) { c.tileDownloaded(null); } } @@ -234,7 +232,7 @@ public class AsyncLoadingThread extends Thread { } - protected static class AmenityLoadRequest extends MapObjectLoadRequest { + protected class AmenityLoadRequest extends MapObjectLoadRequest { private final List res; private final PoiFilter filter; private final int zoom; @@ -277,7 +275,7 @@ public class AsyncLoadingThread extends Thread { } - protected static class TransportLoadRequest extends MapObjectLoadRequest { + protected class TransportLoadRequest extends MapObjectLoadRequest { private final List repos; private int zoom; diff --git a/OsmAnd/src/net/osmand/plus/DownloadOsmandIndexesHelper.java b/OsmAnd/src/net/osmand/plus/DownloadOsmandIndexesHelper.java index c1a69f4690..256fdcfbb9 100644 --- a/OsmAnd/src/net/osmand/plus/DownloadOsmandIndexesHelper.java +++ b/OsmAnd/src/net/osmand/plus/DownloadOsmandIndexesHelper.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.net.URL; import net.osmand.LogUtil; -import net.osmand.Version; import net.osmand.data.IndexConstants; import org.apache.commons.logging.Log; @@ -17,12 +16,12 @@ import android.content.Context; public class DownloadOsmandIndexesHelper { private final static Log log = LogUtil.getLog(DownloadOsmandIndexesHelper.class); - public static IndexFileList downloadIndexesListFromInternet(){ + public static IndexFileList downloadIndexesListFromInternet(String versionAsUrl){ try { log.debug("Start loading list of index files"); //$NON-NLS-1$ IndexFileList result = new IndexFileList(); try { - URL url = new URL("http://download.osmand.net/get_indexes?" + Version.getVersionAsURLParam()); //$NON-NLS-1$ + URL url = new URL("http://download.osmand.net/get_indexes?" + versionAsUrl ); //$NON-NLS-1$ XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); parser.setInput(url.openStream(), "UTF-8"); //$NON-NLS-1$ int next; diff --git a/OsmAnd/src/net/osmand/plus/NavigationService.java b/OsmAnd/src/net/osmand/plus/NavigationService.java index c3cfb7ce29..209792b21f 100644 --- a/OsmAnd/src/net/osmand/plus/NavigationService.java +++ b/OsmAnd/src/net/osmand/plus/NavigationService.java @@ -122,7 +122,7 @@ public class NavigationService extends Service implements LocationListener { Notification notification = new Notification(R.drawable.icon, "", //$NON-NLS-1$ System.currentTimeMillis()); notification.flags = Notification.FLAG_NO_CLEAR; - notification.setLatestEventInfo(this, Version.APP_NAME, + notification.setLatestEventInfo(this, Version.getAppName(this), getString(R.string.service_stop_background_service), PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index f64d44a839..c108fed1f8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -8,6 +8,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import net.osmand.Version; import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager; import net.osmand.map.TileSourceManager.TileSourceTemplate; @@ -590,7 +591,7 @@ public class OsmandSettings { public List getInternetAvailableSourceTemplates(){ if(internetAvailableSourceTemplates == null && isInternetConnectionAvailable()){ - internetAvailableSourceTemplates = TileSourceManager.downloadTileSourceTemplates(); + internetAvailableSourceTemplates = TileSourceManager.downloadTileSourceTemplates(Version.getVersionAsURLParam(ctx)); } return internetAvailableSourceTemplates; } diff --git a/OsmAnd/src/net/osmand/plus/ResourceManager.java b/OsmAnd/src/net/osmand/plus/ResourceManager.java index 562dc29e74..401bc6ffbd 100644 --- a/OsmAnd/src/net/osmand/plus/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/ResourceManager.java @@ -26,6 +26,7 @@ import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.Amenity; import net.osmand.data.AmenityType; import net.osmand.data.IndexConstants; +import net.osmand.data.MapTileDownloader; import net.osmand.data.MapTileDownloader.DownloadRequest; import net.osmand.data.TransportStop; import net.osmand.map.ITileSource; @@ -107,6 +108,8 @@ public class ResourceManager { protected final MapRenderRepositories renderer; + protected final MapTileDownloader tileDownloader; + public final AsyncLoadingThread asyncLoadingThread = new AsyncLoadingThread(this); protected boolean internetIsNotAccessible = false; @@ -118,6 +121,8 @@ public class ResourceManager { this.renderer = new MapRenderRepositories(context); asyncLoadingThread.start(); + tileDownloader = MapTileDownloader.getInstance(Version.getFullVersion(context)); + resetStoreDirectory(); WindowManager mgr = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); @@ -128,6 +133,10 @@ public class ResourceManager { log.info("Tiles to load in memory : " + tiles); maxImgCacheSize = (int) (tiles) ; } + + public MapTileDownloader getMapTileDownloader() { + return tileDownloader; + } public void resetStoreDirectory() { @@ -370,7 +379,7 @@ public class ResourceManager { } private List checkAssets(IProgress progress) { - if (!Version.APP_VERSION.equalsIgnoreCase(context.getSettings().PREVIOUS_INSTALLED_VERSION.get())) { + if (!Version.getFullVersion(context).equalsIgnoreCase(context.getSettings().PREVIOUS_INSTALLED_VERSION.get())) { File file = context.getSettings().extendOsmandPath(APP_DIR); file.mkdirs(); if(file.canWrite()){ @@ -378,7 +387,7 @@ public class ResourceManager { progress.startTask(context.getString(R.string.installing_new_resources), -1); AssetManager assetManager = context.getAssets(); copyingAssets(assetManager, "", file, progress); - context.getSettings().PREVIOUS_INSTALLED_VERSION.set(Version.APP_VERSION); + context.getSettings().PREVIOUS_INSTALLED_VERSION.set(Version.getFullVersion(context)); } catch (IOException e) { log.error(e.getMessage(), e); } catch (XmlPullParserException e) { @@ -661,7 +670,7 @@ public class ResourceManager { } } if(!repos.isEmpty()){ - AmenityLoadRequest req = new AmenityLoadRequest(repos, zoom, filter); + AmenityLoadRequest req = asyncLoadingThread.new AmenityLoadRequest(repos, zoom, filter); req.setBoundaries(topLatitude, leftLongitude, bottomLatitude, rightLongitude); asyncLoadingThread.requestToLoadAmenities(req); } @@ -700,7 +709,7 @@ public class ResourceManager { } } if(!repos.isEmpty()){ - TransportLoadRequest req = new TransportLoadRequest(repos, zoom); + TransportLoadRequest req = asyncLoadingThread.new TransportLoadRequest(repos, zoom); req.setBoundaries(topLatitude, leftLongitude, bottomLatitude, rightLongitude); asyncLoadingThread.requestToLoadTransport(req); } diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java b/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java index 7172d59d5b..3910ea0037 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java @@ -64,7 +64,7 @@ public class DownloadFileHelper { } } HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setRequestProperty("User-Agent", Version.APP_NAME); //$NON-NLS-1$ + conn.setRequestProperty("User-Agent", Version.getFullVersion(ctx)); //$NON-NLS-1$ conn.setReadTimeout(30000); if (fileread > 0) { String range = "bytes="+fileread + "-" + (length -1); //$NON-NLS-1$ //$NON-NLS-2$ @@ -137,11 +137,11 @@ public class DownloadFileHelper { out = new FileOutputStream(fileToDownload); try { if(parts == 1){ - URL url = new URL("http://download.osmand.net/download?file="+fileName + "&" + Version.getVersionAsURLParam()); //$NON-NLS-1$ + URL url = new URL("http://download.osmand.net/download?file="+fileName + "&" + Version.getVersionAsURLParam(ctx)); //$NON-NLS-1$ downloadFile(fileName, out, url, null, indexOfAllFiles, progress, forceWifi); } else { for(int i=1; i<=parts; i++){ - URL url = new URL("http://download.osmand.net/download?file="+fileName+"-"+i + "&" + Version.getVersionAsURLParam()); //$NON-NLS-1$ + URL url = new URL("http://download.osmand.net/download?file="+fileName+"-"+i + "&" + Version.getVersionAsURLParam(ctx)); //$NON-NLS-1$ downloadFile(fileName, out, url, " ["+i+"/"+parts+"]", indexOfAllFiles, progress, forceWifi); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java index 39b58b339a..6992db6e0a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java @@ -90,7 +90,7 @@ public class DownloadIndexActivity extends ExpandableListActivity { private static final int MB = 1 << 20; public static final String FILTER_KEY = "filter"; - private static DownloadIndexListThread downloadListIndexThread = new DownloadIndexListThread(); + private static DownloadIndexListThread downloadListIndexThread; private ProgressDialog progressFileDlg = null; private Map indexFileNames = null; @@ -108,7 +108,7 @@ public class DownloadIndexActivity extends ExpandableListActivity { private void setCustomVarsToTracker(){ - tracker.setCustomVar(1, "App", Version.APP_NAME_VERSION); + tracker.setCustomVar(1, "App", Version.getFullVersion(this)); tracker.setCustomVar(2, "Device", Build.DEVICE); tracker.setCustomVar(3, "Brand", Build.BRAND); tracker.setCustomVar(4, "Model", Build.MODEL); @@ -127,13 +127,16 @@ public class DownloadIndexActivity extends ExpandableListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if(downloadListIndexThread == null) { + downloadListIndexThread = new DownloadIndexListThread(Version.getVersionAsURLParam(this)); + } // recreation upon rotation is prevented in manifest file setContentView(R.layout.download_index); tracker = GoogleAnalyticsTracker.getInstance(); // Start the tracker in manual dispatch mode... tracker.startNewSession(getString(R.string.ga_api_key), 60, this); setCustomVarsToTracker(); - tracker.trackPageView("/download.activity?" +Version.getVersionAsURLParam()); + tracker.trackPageView("/download.activity?" +Version.getVersionAsURLParam(this)); downloadFileHelper = new DownloadFileHelper(this); findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){ @@ -213,7 +216,7 @@ public class DownloadIndexActivity extends ExpandableListActivity { public boolean onOptionsItemSelected(MenuItem item) { if(item.getItemId() == RELOAD_ID){ //re-create the thread - downloadListIndexThread = new DownloadIndexListThread(); + downloadListIndexThread = new DownloadIndexListThread(Version.getVersionAsURLParam(this)); downloadIndexList(); } else { final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter)getExpandableListAdapter(); @@ -254,10 +257,12 @@ public class DownloadIndexActivity extends ExpandableListActivity { private static class DownloadIndexListThread extends Thread { private DownloadIndexActivity uiActivity = null; - private IndexFileList indexFiles = null; + private IndexFileList indexFiles = null; + private final String versionUrlParam; - public DownloadIndexListThread(){ + public DownloadIndexListThread(String versionUrlParam){ super("DownloadIndexes"); //$NON-NLS-1$ + this.versionUrlParam = versionUrlParam; } public void setUiActivity(DownloadIndexActivity uiActivity) { this.uiActivity = uiActivity; @@ -269,7 +274,7 @@ public class DownloadIndexActivity extends ExpandableListActivity { @Override public void run() { - indexFiles = DownloadOsmandIndexesHelper.downloadIndexesListFromInternet(); + indexFiles = DownloadOsmandIndexesHelper.downloadIndexesListFromInternet(versionUrlParam); if(uiActivity != null) { uiActivity.removeDialog(DIALOG_PROGRESS_LIST); uiActivity.runOnUiThread(new Runnable() { @@ -342,14 +347,14 @@ public class DownloadIndexActivity extends ExpandableListActivity { case DIALOG_PROGRESS_FILE: DownloadIndexesAsyncTask task = new DownloadIndexesAsyncTask(new ProgressDialogImplementation(progressFileDlg,true)); String[] indexes = entriesToDownload.keySet().toArray(new String[0]); - String v = Version.APP_NAME_VERSION; - if(Version.APP_DESCRIPTION.equals("beta")){ - v +="beta"; + String v = Version.getAppName(this); + if(Version.isProductionVersion(this)){ + v = Version.getFullVersion(this); } else { - v +="test"; + v +=" test"; } for(String index : indexes) { - tracker.trackEvent(v, Version.APP_NAME, index, 1); + tracker.trackEvent(v, Version.getAppName(this), index, 1); } task.execute(indexes); break; @@ -359,7 +364,7 @@ public class DownloadIndexActivity extends ExpandableListActivity { downloadListIndexThread.start(); } else if(downloadListIndexThread.getState() == Thread.State.TERMINATED){ // possibly exception occurred we don't have cache of files - downloadListIndexThread = new DownloadIndexListThread(); + downloadListIndexThread = new DownloadIndexListThread(Version.getVersionAsURLParam(this)); downloadListIndexThread.setUiActivity(this); downloadListIndexThread.start(); } diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadTilesDialog.java b/OsmAnd/src/net/osmand/plus/activities/DownloadTilesDialog.java index 4eb64f54f1..833193cd91 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadTilesDialog.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadTilesDialog.java @@ -4,6 +4,7 @@ import java.text.MessageFormat; import java.util.ArrayList; import net.osmand.LogUtil; +import net.osmand.Version; import net.osmand.data.MapTileDownloader; import net.osmand.data.MapTileDownloader.DownloadRequest; import net.osmand.data.MapTileDownloader.IMapDownloaderCallback; @@ -144,7 +145,7 @@ public class DownloadTilesDialog { } }); - final MapTileDownloader instance = MapTileDownloader.getInstance(); + final MapTileDownloader instance = MapTileDownloader.getInstance(Version.getFullVersion(ctx)); final ArrayList previousCallbacks = new ArrayList(instance.getDownloaderCallbacks()); diff --git a/OsmAnd/src/net/osmand/plus/activities/EditingPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/EditingPOIActivity.java index 21256c56cc..050333864d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditingPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditingPOIActivity.java @@ -567,7 +567,7 @@ public class EditingPOIActivity implements DialogProvider { ser.startTag(null, "tag"); //$NON-NLS-1$ ser.attribute(null, "k", "created_by"); //$NON-NLS-1$ //$NON-NLS-2$ - ser.attribute(null, "v", Version.APP_NAME_VERSION); //$NON-NLS-1$ + ser.attribute(null, "v", Version.getFullVersion(ctx)); //$NON-NLS-1$ ser.endTag(null, "tag"); //$NON-NLS-1$ ser.endTag(null, "changeset"); //$NON-NLS-1$ ser.endTag(null, "osm"); //$NON-NLS-1$ @@ -699,10 +699,10 @@ public class EditingPOIActivity implements DialogProvider { ser.startDocument("UTF-8", true); //$NON-NLS-1$ ser.startTag(null, "osmChange"); //$NON-NLS-1$ ser.attribute(null, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$ - ser.attribute(null, "generator", Version.APP_NAME); //$NON-NLS-1$ + ser.attribute(null, "generator", Version.getFullVersion(ctx)); //$NON-NLS-1$ ser.startTag(null, action); ser.attribute(null, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$ - ser.attribute(null, "generator", Version.APP_NAME); //$NON-NLS-1$ + ser.attribute(null, "generator", Version.getFullVersion(ctx)); //$NON-NLS-1$ writeNode(n, info, ser, changeSetId, OsmandSettings.getOsmandSettings(ctx).USER_NAME.get()); ser.endTag(null, action); ser.endTag(null, "osmChange"); //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java index 1b872a2f11..9ce79a2b36 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java @@ -77,7 +77,7 @@ public class MainMenuActivity extends TrackedActivity { text.append("\nProduct : ").append(Build.PRODUCT); //$NON-NLS-1$ text.append("\nBuild : ").append(Build.DISPLAY); //$NON-NLS-1$ text.append("\nVersion : ").append(Build.VERSION.RELEASE); //$NON-NLS-1$ - text.append("\nApp Version : ").append(Version.APP_NAME_VERSION); //$NON-NLS-1$ + text.append("\nApp Version : ").append(Version.getAppName(MainMenuActivity.this)); //$NON-NLS-1$ try { PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0); if (info != null) { @@ -130,7 +130,7 @@ public class MainMenuActivity extends TrackedActivity { rightview = (View) window.findViewById(R.id.SearchButton); rightview.startAnimation(getAnimation(1, 0)); - String textVersion = Version.APP_VERSION + " " + Version.APP_DESCRIPTION; + String textVersion = Version.getFullVersion(activity); final TextView textVersionView = (TextView) window.findViewById(R.id.TextVersion); textVersionView.setText(textVersion); SharedPreferences prefs = activity.getApplicationContext().getSharedPreferences("net.osmand.settings", MODE_WORLD_READABLE); @@ -245,7 +245,7 @@ public class MainMenuActivity extends TrackedActivity { if(!pref.contains(FIRST_TIME_APP_RUN)){ firstTime = true; pref.edit().putBoolean(FIRST_TIME_APP_RUN, true).commit(); - pref.edit().putString(VERSION_INSTALLED, Version.APP_VERSION).commit(); + pref.edit().putString(VERSION_INSTALLED, Version.getFullVersion(activity)).commit(); applicationInstalledFirstTime(); } else { @@ -254,8 +254,8 @@ public class MainMenuActivity extends TrackedActivity { pref.edit().putInt(TIPS_SHOW, ++i).commit(); } boolean appVersionChanged = false; - if(!Version.APP_VERSION.equals(pref.getString(VERSION_INSTALLED, ""))){ - pref.edit().putString(VERSION_INSTALLED, Version.APP_VERSION).commit(); + if(!Version.getFullVersion(activity).equals(pref.getString(VERSION_INSTALLED, ""))){ + pref.edit().putString(VERSION_INSTALLED, Version.getFullVersion(activity)).commit(); appVersionChanged = true; } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index ac721c8d57..17d62b7255 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -11,7 +11,6 @@ import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.LogUtil; import net.osmand.Version; -import net.osmand.data.MapTileDownloader; import net.osmand.data.MapTileDownloader.DownloadRequest; import net.osmand.data.MapTileDownloader.IMapDownloaderCallback; import net.osmand.map.IMapLocationListener; @@ -135,7 +134,7 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener notificationIndent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Notification notification = new Notification(R.drawable.icon, "", //$NON-NLS-1$ System.currentTimeMillis()); - notification.setLatestEventInfo(this, Version.APP_NAME, + notification.setLatestEventInfo(this, Version.getAppName(this), getString(R.string.go_back_to_osmand), PendingIntent.getActivity( this, 0, notificationIndent, PendingIntent.FLAG_UPDATE_CURRENT)); @@ -175,7 +174,7 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener }); poiActions = new EditingPOIActivity(this); - MapTileDownloader.getInstance().addDownloaderCallback(new IMapDownloaderCallback(){ + getMyApplication().getResourceManager().getMapTileDownloader().addDownloaderCallback(new IMapDownloaderCallback(){ @Override public void tileDownloaded(DownloadRequest request) { if(request != null && !request.error && request.fileToSave != null){ @@ -583,7 +582,7 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener if(mNotificationManager != null){ mNotificationManager.cancel(APP_NOTIFICATION_ID); } - MapTileDownloader.getInstance().removeDownloaderCallback(mapView); + getMyApplication().getResourceManager().getMapTileDownloader().removeDownloaderCallback(mapView); } diff --git a/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java b/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java index 58b06b548f..b919111f97 100644 --- a/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java @@ -6,7 +6,6 @@ import java.util.Locale; import java.util.StringTokenizer; import com.google.android.apps.analytics.easytracking.TrackedActivity; -import com.google.android.apps.analytics.easytracking.TrackedListActivity; import net.osmand.LogUtil; import net.osmand.osm.LatLon; @@ -16,7 +15,6 @@ import net.osmand.plus.R; import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild; import net.osmand.plus.views.OsmandMapTileView; -import android.app.Activity; import android.app.Dialog; import android.content.Intent; import android.location.Location; diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java index be1e886492..1ebb5edb0b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java @@ -14,7 +14,6 @@ import net.osmand.Algoritms; import net.osmand.FavouritePoint; import net.osmand.GPXUtilities; import net.osmand.LogUtil; -import net.osmand.Version; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; import net.osmand.plus.FavouritesDbHelper; @@ -75,7 +74,6 @@ public class OsmandApplication extends Application { super.onCreate(); long timeToStart = System.currentTimeMillis(); osmandSettings = OsmandSettings.getOsmandSettings(this); - Version.setAppVersionAndName(getString(R.string.app_name), getString(R.string.app_version)); routingHelper = new RoutingHelper(osmandSettings, OsmandApplication.this, player); manager = new ResourceManager(this); daynightHelper = new DayNightHelper(this); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java index 8a4565f938..2a045a8d63 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java @@ -11,6 +11,7 @@ import java.util.Map.Entry; import java.util.Set; import net.osmand.ResultMatcher; +import net.osmand.Version; import net.osmand.map.TileSourceManager; import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.plus.NavigationService; @@ -806,7 +807,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference Toast.makeText(activity, R.string.internet_not_available, Toast.LENGTH_LONG).show(); return; } - final List downloaded = TileSourceManager.downloadTileSourceTemplates(); + final List downloaded = TileSourceManager.downloadTileSourceTemplates(Version.getVersionAsURLParam(activity)); if(downloaded == null || downloaded.isEmpty()){ Toast.makeText(activity, R.string.error_io_error, Toast.LENGTH_SHORT).show(); return; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java index 6dc5875255..3dc75f3cba 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java @@ -138,7 +138,7 @@ public class SearchAddressOnlineActivity extends ListActivity implements SearchA URL url = new URL(b.toString()); URLConnection conn = url.openConnection(); conn.setDoInput(true); - conn.setRequestProperty("User-Agent", Version.APP_NAME_VERSION); //$NON-NLS-1$ + conn.setRequestProperty("User-Agent", Version.getFullVersion(SearchAddressOnlineActivity.this)); //$NON-NLS-1$ conn.connect(); InputStream is = conn.getInputStream(); XmlPullParser parser = Xml.newPullParser(); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 0dabb1e934..2451987930 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.Map; import net.osmand.LogUtil; -import net.osmand.data.MapTileDownloader; import net.osmand.data.MapTileDownloader.DownloadRequest; import net.osmand.data.MapTileDownloader.IMapDownloaderCallback; import net.osmand.map.IMapLocationListener; @@ -427,7 +426,9 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall boolean useInternet = getSettings().USE_INTERNET_TO_DOWNLOAD_TILES.get(); if (useInternet) { - MapTileDownloader.getInstance().refuseAllPreviousRequests(); + if(application != null) { + application.getResourceManager().getMapTileDownloader().refuseAllPreviousRequests(); + } }