Add free version support

This commit is contained in:
Victor Shcherb 2012-01-15 14:20:33 +01:00
parent 47ca60940f
commit 0eee93e4af
7 changed files with 64 additions and 9 deletions

View file

@ -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() {

View file

@ -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){

View file

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="free_version_message">Free OsmAnd version is limited to %1$s downloads %2$s and doesn\'t support offline wikipedia articles.</string>
<string name="free_version_title">Free version</string>
<string name="poi_context_menu_showdescription">Show POI description</string>
<string name="index_name_us">North America - United States</string>

View file

@ -1077,7 +1077,17 @@ public class OsmandSettings {
public final CommonPreference<Boolean> SHOW_ZOOM_LEVEL =
new BooleanPreference("show_zoom_level", false, false, true);
public final OsmandPreference<Integer> 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),

View file

@ -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$

View file

@ -97,6 +97,9 @@ public class DownloadIndexActivity extends ExpandableListActivity {
private ProgressDialog progressFileDlg = null;
private Map<String, String> indexFileNames = null;
private TreeMap<String, DownloadEntry> entriesToDownload = new TreeMap<String, DownloadEntry>();
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()){

View file

@ -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);