-
-
Notifications
You must be signed in to change notification settings - Fork 980
/
Version.java
112 lines (87 loc) · 2.98 KB
/
Version.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package net.osmand.plus;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class Version {
private final String appVersion;
private final String appName;
private final static String FREE_VERSION_NAME = "net.osmand";
private final static String SHERPAFY_VERSION_NAME = "net.osmand.sherpafy";
public static boolean isGpsStatusEnabled(OsmandApplication ctx) {
return isGooglePlayEnabled(ctx) && !isBlackberry(ctx);
}
public static boolean isBlackberry(OsmandApplication ctx) {
return ctx.getString(R.string.versionFeatures).contains("+blackberry");
}
public static boolean isMarketEnabled(OsmandApplication ctx) {
return isGooglePlayEnabled(ctx) || isAmazonEnabled(ctx);
}
public static String marketPrefix(OsmandApplication ctx) {
if (isAmazonEnabled(ctx)) {
return "amzn://apps/android?p=";
} else if (isGooglePlayEnabled(ctx)) {
return "market://search?q=pname:";
}
return "http://osmand.net/apps?";
}
private static boolean isAmazonEnabled(OsmandApplication ctx) {
return ctx.getString(R.string.versionFeatures).contains("+amazon");
}
private static boolean isGooglePlayEnabled(OsmandApplication ctx) {
return ctx.getString(R.string.versionFeatures).contains("+play_market");
}
public static boolean isSherpafy(OsmandApplication ctx) {
return ctx.getPackageName().equals(SHERPAFY_VERSION_NAME);
}
private Version(OsmandApplication ctx) {
appVersion = ctx.getString(R.string.app_version);
appName = ctx.getString(R.string.app_name);
}
private static Version ver = null;
private static Version getVersion(OsmandApplication ctx){
if(ver == null){
ver = new Version(ctx);
}
return ver;
}
public static String getFullVersion(OsmandApplication ctx){
Version v = getVersion(ctx);
return v.appName + " " + v.appVersion;
}
public static String getAppVersion(OsmandApplication ctx){
Version v = getVersion(ctx);
return v.appVersion;
}
public static String getBuildAppEdition(OsmandApplication ctx){
return ctx.getString(R.string.app_edition);
}
public static String getAppName(OsmandApplication ctx){
Version v = getVersion(ctx);
return v.appName;
}
public static boolean isProductionVersion(OsmandApplication ctx){
Version v = getVersion(ctx);
return !v.appVersion.contains("#");
}
public static String getVersionAsURLParam(OsmandApplication ctx) {
try {
return "osmandver=" + URLEncoder.encode(getVersionForTracker(ctx), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
public static boolean isFreeVersion(OsmandApplication ctx){
return ctx.getPackageName().equals(FREE_VERSION_NAME);
}
public static boolean isDeveloperVersion(OsmandApplication ctx){
return getAppName(ctx).contains("~");
}
public static String getVersionForTracker(OsmandApplication ctx) {
String v = Version.getAppName(ctx);
if(Version.isProductionVersion(ctx)){
v = Version.getFullVersion(ctx);
} else {
v +=" test";
}
return v;
}
}