diff --git a/DataExtractionOSM/src/net/osmand/Version.java b/DataExtractionOSM/src/net/osmand/Version.java index 587171c940..58697438ac 100644 --- a/DataExtractionOSM/src/net/osmand/Version.java +++ b/DataExtractionOSM/src/net/osmand/Version.java @@ -4,17 +4,25 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Version { - - public static String APP_NAME = "OsmAnd"; //$NON-NLS-1$ public static String APP_VERSION = "0.7.0"; //$NON-NLS-1$ - public static final String APP_MAP_CREATOR_NAME = "OsmAndMapCreator"; //$NON-NLS-1$ public static final String APP_DESCRIPTION = "alpha"; //$NON-NLS-1$ - public static final String APP_NAME_VERSION = APP_NAME + " " + APP_VERSION; //$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_FULL_NAME = APP_NAME + " " + APP_VERSION + " " +APP_DESCRIPTION; //$NON-NLS-1$ //$NON-NLS-2$ 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() { diff --git a/DataExtractionOSM/src/net/osmand/data/MapTileDownloader.java b/DataExtractionOSM/src/net/osmand/data/MapTileDownloader.java index 06f6299b0c..dda0b4a8a7 100644 --- a/DataExtractionOSM/src/net/osmand/data/MapTileDownloader.java +++ b/DataExtractionOSM/src/net/osmand/data/MapTileDownloader.java @@ -46,7 +46,7 @@ public class MapTileDownloader { public static MapTileDownloader getInstance(){ - return getInstance(null); + return getInstance(Version.APP_NAME_VERSION); } public static MapTileDownloader getInstance(String userAgent){ diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 93256b7f15..5676bc40ec 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,8 @@ + + Free OsmAnd version is limited to %1$s downloads %2$s and doesn\'t support offline wikipedia articles. + Free version Show POI description North America - United States diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index aa090bcb25..f64d44a839 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1077,7 +1077,17 @@ public class OsmandSettings { public final CommonPreference SHOW_ZOOM_LEVEL = new BooleanPreference("show_zoom_level", false, false, true); + + public final OsmandPreference NUMBER_OF_FREE_DOWNLOADS = + new IntPreference("free_downloads", 0, true); + public boolean checkFreeDownloadsNumberZero(){ + if(!globalPreferences.contains(NUMBER_OF_FREE_DOWNLOADS.getId())){ + NUMBER_OF_FREE_DOWNLOADS.set(0); + return true; + } + return false; + } public enum DayNightMode { AUTO(R.string.daynight_mode_auto), diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java b/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java index 01ab89d4af..d4e544dcf0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java @@ -35,6 +35,7 @@ public class DownloadFileHelper { private final Activity ctx; private boolean interruptDownloading = false; + public DownloadFileHelper(Activity ctx){ this.ctx = ctx; } @@ -65,6 +66,7 @@ public class DownloadFileHelper { } } HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestProperty("User-Agent", Version.APP_NAME); //$NON-NLS-1$ conn.setReadTimeout(30000); if (fileread > 0) { String range = "bytes="+fileread + "-" + (length -1); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java index a995192ac0..eafb96f18e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java @@ -97,6 +97,9 @@ public class DownloadIndexActivity extends ExpandableListActivity { private ProgressDialog progressFileDlg = null; private Map indexFileNames = null; private TreeMap entriesToDownload = new TreeMap(); + + private String FREE_VERSION_NAME = "net.osmand"; + private int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 5; private TextWatcher textWatcher ; @@ -139,7 +142,7 @@ public class DownloadIndexActivity extends ExpandableListActivity { @Override public void onClick(View v) { - downloadFilesPreCheckSpace(); + downloadFilesCheckFreeVersion(); } }); @@ -180,6 +183,12 @@ public class DownloadIndexActivity extends ExpandableListActivity { } else { downloadIndexList(); } + if(getPackageName().equals(FREE_VERSION_NAME) && OsmandSettings.getOsmandSettings(this).checkFreeDownloadsNumberZero()){ + Builder msg = new AlertDialog.Builder(this); + msg.setTitle(R.string.free_version_message); + msg.setMessage(getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS+"", "")); + msg.show(); + } } @@ -526,6 +535,30 @@ public class DownloadIndexActivity extends ExpandableListActivity { return entry; } + + protected void downloadFilesCheckFreeVersion() { + if (getPackageName().equals(FREE_VERSION_NAME)) { + int total = OsmandSettings.getOsmandSettings(this).NUMBER_OF_FREE_DOWNLOADS.get() + entriesToDownload.size(); + boolean wiki = false; + for (DownloadEntry es : entriesToDownload.values()) { + if (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_message); + msg.setMessage(getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "", "( > " + total + ") ")); + msg.show(); + } else { + downloadFilesPreCheckSpace(); + } + } else { + downloadFilesPreCheckSpace(); + } + } + protected void downloadFilesPreCheckSpace() { double sz = 0; for(DownloadEntry es : entriesToDownload.values()){ diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java index 0a63535d8a..be1e886492 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java @@ -75,8 +75,7 @@ public class OsmandApplication extends Application { super.onCreate(); long timeToStart = System.currentTimeMillis(); osmandSettings = OsmandSettings.getOsmandSettings(this); - Version.APP_NAME = getString(R.string.app_name); - Version.APP_VERSION = getString(R.string.app_version); + 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);