Replace Apache URL validation with OkHTTP
Also add some missing MapView constructors.
This commit is contained in:
@@ -28,7 +28,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'commons-validator:commons-validator:1.4.1'
|
||||
compile 'com.android.support:support-annotations:22.2.1'
|
||||
compile 'com.android.support:support-v4:22.2.1'
|
||||
compile 'com.squareup.okhttp:okhttp:2.4.0'
|
||||
|
||||
@@ -55,9 +55,11 @@ import com.mapzen.android.lost.api.LocationListener;
|
||||
import com.mapzen.android.lost.api.LocationRequest;
|
||||
import com.mapzen.android.lost.api.LocationServices;
|
||||
import com.mapzen.android.lost.api.LostApiClient;
|
||||
import org.apache.commons.validator.routines.UrlValidator;
|
||||
import com.squareup.okhttp.HttpUrl;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -174,6 +176,19 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
initialize(context, null);
|
||||
}
|
||||
|
||||
public MapView(Context context, @NonNull String accessToken) {
|
||||
super(context);
|
||||
setAccessToken(accessToken);
|
||||
initialize(context, null);
|
||||
}
|
||||
|
||||
public MapView(Context context, @NonNull String accessToken, String styleUrl) {
|
||||
super(context);
|
||||
setAccessToken(accessToken);
|
||||
setStyleUrl(styleUrl);
|
||||
initialize(context, null);
|
||||
}
|
||||
|
||||
// Called when properties are being set from XML
|
||||
public MapView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
@@ -514,14 +529,16 @@ public class MapView extends FrameLayout implements LocationListener {
|
||||
}
|
||||
|
||||
private void validateStyleUrl(String url) {
|
||||
String[] schemes = {"http", "https", "file", "asset"};
|
||||
UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS | UrlValidator.ALLOW_LOCAL_URLS);
|
||||
if (!urlValidator.isValid(url)) {
|
||||
throw new RuntimeException("Style URL is not a valid http, https, file or asset URL.");
|
||||
String[] schemes = {"http", "https", "asset"};
|
||||
url = url.replaceFirst("asset://", "http://");
|
||||
HttpUrl parsedUrl = HttpUrl.parse(url);
|
||||
if (parsedUrl == null) {
|
||||
throw new RuntimeException("Style URL is not a valid http, https or asset URL.");
|
||||
}
|
||||
}
|
||||
|
||||
public void setStyleUrl(String url) {
|
||||
validateStyleUrl(url);
|
||||
mStyleUrl = url;
|
||||
mNativeMapView.setStyleUrl(url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user