Commit 3c9262b2 authored by Mohsen Taleb's avatar Mohsen Taleb

Added support for custom API urls and updated to mapbox-0.7.3

parent 2d853272
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
version = "0.7.1"
version = "0.7.3"
def siteUrl = 'http://cedarmaps.com'
def gitUrl = 'http://cedarmaps.com/git'
group = "com.cedarmaps"
android {
compileSdkVersion 21
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
versionCode 2
versionName "0.7.1"
targetSdkVersion 22
versionCode 3
versionName "0.7.3"
}
buildTypes {
}
......@@ -22,7 +22,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.1@aar') {
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.3@aar') {
transitive = true
}
}
......
......@@ -3,9 +3,6 @@ package com.cedarstudios.cedarmapssdk;
import com.squareup.okhttp.Response;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
public class CedarMapsException extends Exception {
......
......@@ -62,7 +62,7 @@ class CedarMapsImpl extends CedarMapsBaseImpl implements CedarMaps {
throw new CedarMapsException(e);
}
String url = String
.format(Locale.ENGLISH, conf.getRestBaseURL() + "geocode/%s/%s.json",
.format(Locale.ENGLISH, conf.getAPIBaseURL() + "geocode/%s/%s.json",
conf.getMapId(), term);
url += String.format(Locale.ENGLISH, "?limit=%s", limit);
......@@ -88,7 +88,7 @@ class CedarMapsImpl extends CedarMapsBaseImpl implements CedarMaps {
@Override
public JSONObject geocode(double lat, double lng) throws CedarMapsException {
String url = String.format(Locale.ENGLISH,
conf.getRestBaseURL() + "geocode/%1$s/%2$s,%3$s.json", conf.getMapId(), lat, lng);
conf.getAPIBaseURL() + "geocode/%1$s/%2$s,%3$s.json", conf.getMapId(), lat, lng);
if (TextUtils.isEmpty(conf.getMapId())) {
throw new CedarMapsException(new NullPointerException(
......
package com.cedarstudios.cedarmapssdk.config;
class CedarMapsConstants {
public final static String CEDARMAPS_BASE_URL_V1 = "http://api.cedarmaps.com/v1/";
}
......@@ -12,7 +12,7 @@ public interface Configuration extends AuthorizationConfiguration, Serializable
String getOAuth2AccessToken();
String getRestBaseURL();
String getAPIBaseURL();
String getOAuth2Scope();
......
package com.cedarstudios.cedarmapssdk.config;
import com.cedarstudios.cedarmapssdk.CedarMapsConstants;
import java.io.ObjectStreamException;
import java.io.Serializable;
......@@ -22,10 +21,10 @@ class ConfigurationBase implements Configuration, Serializable {
private String mapId;
private String oAuth2TokenURL = CedarMapsConstants.CEDARMAPS_BASE_URL_V1 + "token";
private String restBaseURL = CedarMapsConstants.CEDARMAPS_BASE_URL_V1;
private String oAuth2TokenURL = restBaseURL + "token";
public void setOAuthClientId(String oAuthClientId) {
this.oAuthClientId = oAuthClientId;
......@@ -39,8 +38,13 @@ class ConfigurationBase implements Configuration, Serializable {
this.mapId = mapId;
}
public void setAPIBaseUrl(String baseUrl) {
restBaseURL = baseUrl;
setOAuth2TokenURL(restBaseURL + "token");
}
@Override
public String getRestBaseURL() {
public String getAPIBaseURL() {
return restBaseURL;
}
......
......@@ -4,6 +4,12 @@ public final class ConfigurationBuilder {
private ConfigurationBase configurationBase = new ConfigurationBase();
public ConfigurationBuilder setAPIBaseURL(String baseURL) {
checkNotBuilt();
configurationBase.setAPIBaseUrl(baseURL);
return this;
}
public ConfigurationBuilder setClientId(String clientId) {
checkNotBuilt();
......
package com.cedarstudios.cedarmapssdk.tileprovider;
import com.cedarstudios.cedarmapssdk.CedarMaps;
import com.cedarstudios.cedarmapssdk.CedarMapsConstants;
import com.cedarstudios.cedarmapssdk.CedarMapsException;
import com.cedarstudios.cedarmapssdk.CedarMapsFactory;
import com.cedarstudios.cedarmapssdk.CedarMapsTileLayerListener;
......@@ -202,7 +201,7 @@ public class CedarMapsTileLayer extends WebSourceTileLayer {
private String getBrandedJSONURL() {
String url = String
.format(Locale.ENGLISH, CedarMapsConstants.CEDARMAPS_BASE_URL_V1
.format(Locale.ENGLISH, mConfiguration.getAPIBaseURL()
+ "tiles/%s.json?access_token=%s&secure=1", mId,
CedarMapsUtils.getAccessToken());
if (!mEnableSSL) {
......@@ -263,7 +262,7 @@ public class CedarMapsTileLayer extends WebSourceTileLayer {
if (!TextUtils.isEmpty(aUrl) && !aUrl.toLowerCase(Locale.US).contains("http://") && !aUrl
.toLowerCase(Locale.US).contains("https://")) {
super.setURL(
CedarMapsConstants.CEDARMAPS_BASE_URL_V1 + "tiles/" + aUrl
mConfiguration.getAPIBaseURL() + "tiles/" + aUrl
+ "/{z}/{x}/{y}.png?access_token="
+ CedarMapsUtils.getAccessToken());
} else {
......
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.cedarstudios.cedarmaps.sample"
minSdkVersion 9
targetSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
......@@ -21,6 +21,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:appcompat-v7:22.1.1'
compile(project(':CedarMapsSDK'))
}
......@@ -16,7 +16,7 @@ repositories {
}
dependencies {
compile('com.cedarmaps:CedarMapsSDK:0.7.1@aar') {
compile('com.cedarmaps:CedarMapsSDK:0.7.3@aar') {
transitive = true
}
}
......@@ -112,6 +112,19 @@ Configuration configuration = new ConfigurationBuilder()
Currently you can use `cedarmaps.streets` as default mapId
#### Changing API Base Url
You can change API Base Url by setting it on configuration object:
```java
MapView mapView = new MapView(context);
Configuration configuration = new ConfigurationBuilder()
.setAPIBaseURL(CUSTOM_API_URL)
.setClientId(Constants.CLIENT_ID)
.setClientSecret(Constants.CLIENT_SECRET)
.setMapId(Constants.MAPID_CEDARMAPS_STREETS)
.build();
```
### Attention
......
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
// NOTE: Do not place your application dependencies here; they belong
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment