Commit e970a16d authored by Deployer's avatar Deployer

Updated to Mapbox SDK version 6.8.0

parent 184b6f25
......@@ -3,7 +3,7 @@ apply plugin: 'signing'
apply plugin: 'com.github.dcendents.android-maven'
group = "com.cedarmaps"
version = "3.1.2"
version = "3.2.0"
def siteUrl = 'http://cedarmaps.com'
def gitUrl = 'http://cedarmaps.com/git'
......@@ -17,7 +17,7 @@ android {
}
dependencies {
api 'com.cedarmaps:mapbox-android-sdk:6.5.0'
api 'com.cedarmaps:mapbox-android-sdk:6.8.0'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.google.code.gson:gson:2.8.5'
}
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cedarstudios.cedarmapssdk">
<application android:allowBackup="true">
<application>
</application>
</manifest>
package com.cedarstudios.cedarmapssdk;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
......@@ -24,6 +25,7 @@ import java.net.URLDecoder;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
......@@ -38,6 +40,7 @@ final class AuthenticationManager {
private static final String defaultBaseURL = "https://api.cedarmaps.com/v1/";
private static final String SAVED_ACCESS_TOKEN_KEY = "com.cedarstudios.cedarmapssdk.saved_access_token";
@SuppressLint("StaticFieldLeak")
private static AuthenticationManager instance;
private String mClientID;
......@@ -52,7 +55,11 @@ final class AuthenticationManager {
private BroadcastReceiver mapViewError401BroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
regenerateAccessToken();
} catch (CedarMapsException e) {
e.printStackTrace();
}
}
};
......@@ -149,19 +156,21 @@ final class AuthenticationManager {
}
}
void regenerateAccessToken() {
void regenerateAccessToken() throws CedarMapsException {
if (isFetchingNewAccessToken) {
return;
}
isFetchingNewAccessToken = true;
invalidateCredentials();
Mapbox.getInstance(getContext(), Constants.INITIAL_TOKEN);
fetchAccessTokenFromServer(new AccessTokenListener() {
@Override
public void onSuccess(@NonNull String accessToken) {
isFetchingNewAccessToken = false;
if (!TextUtils.isEmpty(accessToken)) {
Mapbox.getInstance(getContext(), accessToken);
Mapbox.setAccessToken("pk." + accessToken);
Intent intent = new Intent(ACCESS_TOKEN_READY_INTENT);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
......@@ -175,7 +184,7 @@ final class AuthenticationManager {
});
}
private boolean saveAccessToken() throws CedarMapsException {
private void saveAccessToken() throws CedarMapsException {
if (TextUtils.isEmpty(mAccessToken)) {
throw new CedarMapsException("AccessToken is not available to save. Try calling 'getAccessToken' first.");
}
......@@ -186,7 +195,6 @@ final class AuthenticationManager {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(SAVED_ACCESS_TOKEN_KEY, mAccessToken);
editor.apply();
return true;
}
@Nullable
......@@ -215,9 +223,13 @@ final class AuthenticationManager {
}
}
private void fetchAccessTokenFromServer(final AccessTokenListener completionHandler) {
private void fetchAccessTokenFromServer(final AccessTokenListener completionHandler) throws CedarMapsException {
if (mContext == null) {
throw new CedarMapsException("Context is not set. Please call 'setContext' method on CedarMaps.getInstance()");
}
CedarOkHttpClient client = CedarOkHttpClient.getInstance();
OkHttpClient client = CedarOkHttpClient.getSharedInstance(mContext);
final Handler handler = new Handler(Looper.getMainLooper());
String url = mBaseURL + "token";
......
......@@ -34,6 +34,7 @@ import java.util.Locale;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
......@@ -49,6 +50,7 @@ public class CedarMaps {
private String mMapID;
private String mDirectionID;
private static CedarMaps instance;
private AuthenticationManager authManager = AuthenticationManager.getInstance();
//endregion
//region Initializers
......@@ -95,7 +97,7 @@ public class CedarMaps {
* @return AuthenticationManager singleton object; You could use this to continue setting the other parameters such as clientSecret and context.
*/
public CedarMaps setClientID(@NonNull String clientID) {
AuthenticationManager.getInstance().setClientID(clientID);
authManager.setClientID(clientID);
return CedarMaps.getInstance();
}
......@@ -106,7 +108,7 @@ public class CedarMaps {
* @return AuthenticationManager singleton object; You could use this to continue setting the other parameters such as context.
*/
public CedarMaps setClientSecret(@NonNull String clientSecret) {
AuthenticationManager.getInstance().setClientSecret(clientSecret);
authManager.setClientSecret(clientSecret);
return CedarMaps.getInstance();
}
......@@ -119,7 +121,7 @@ public class CedarMaps {
* @return AuthenticationManager singleton object.
*/
public CedarMaps setContext(@NonNull Context context) {
AuthenticationManager.getInstance().setContext(context);
authManager.setContext(context);
return CedarMaps.getInstance();
}
......@@ -131,13 +133,13 @@ public class CedarMaps {
* @return AuthenticationManager singleton object.
*/
public CedarMaps setAPIBaseURL(@Nullable String url) {
AuthenticationManager.getInstance().setAPIBaseURL(url);
authManager.setAPIBaseURL(url);
return CedarMaps.getInstance();
}
//endregion
public String getSavedAccessToken() throws CedarMapsException {
return AuthenticationManager.getInstance().getSavedAccessToken();
return authManager.getSavedAccessToken();
}
/**
......@@ -247,7 +249,7 @@ public class CedarMaps {
return;
}
String url = String.format(Locale.ENGLISH,
AuthenticationManager.getInstance().getAPIBaseURL() + "geocode/%s/%s.json",
authManager.getAPIBaseURL() + "geocode/%s/%s.json",
mMapID,
term);
......@@ -304,7 +306,7 @@ public class CedarMaps {
*/
public void reverseGeocode(LatLng coordinate, final ReverseGeocodeResultListener completionHandler) {
String url = String.format(Locale.ENGLISH,
AuthenticationManager.getInstance().getAPIBaseURL() + "geocode/%1$s/%2$s,%3$s.json",
authManager.getAPIBaseURL() + "geocode/%1$s/%2$s,%3$s.json",
mMapID,
coordinate.getLatitude(), coordinate.getLongitude());
......@@ -347,7 +349,7 @@ public class CedarMaps {
public void distance(LatLng start, LatLng end, final GeoRoutingResultListener completionHandler) {
String url = String.format(Locale.ENGLISH,
AuthenticationManager.getInstance().getAPIBaseURL() + "distance/%1$s/%2$s,%3$s;%4$s,%5$s",
authManager.getAPIBaseURL() + "distance/%1$s/%2$s,%3$s;%4$s,%5$s",
mDirectionID,
start.getLatitude(), start.getLongitude(), end.getLatitude(), end.getLongitude());
......@@ -398,7 +400,7 @@ public class CedarMaps {
}
String url = String.format(Locale.ENGLISH,
AuthenticationManager.getInstance().getAPIBaseURL() + "distance/%1$s/%2$s",
authManager.getAPIBaseURL() + "distance/%1$s/%2$s",
mDirectionID, pairs.toString());
getResponseBodyFromURL(url, new NetworkResponseBodyCompletionHandler() {
......@@ -497,7 +499,7 @@ public class CedarMaps {
}
String url = String.format(Locale.ENGLISH,
AuthenticationManager.getInstance().getAPIBaseURL() + "direction/%1$s/%2$s?instructions=%3$s&locale=%4$s",
authManager.getAPIBaseURL() + "direction/%1$s/%2$s?instructions=%3$s&locale=%4$s",
mDirectionID,
pairs.toString(),
shouldShowInstructions ? "true" : "false",
......@@ -568,7 +570,7 @@ public class CedarMaps {
}
String url = String.format(Locale.ENGLISH,
AuthenticationManager.getInstance().getAPIBaseURL() + "static/light/%s/%s%s%s", paramPosition, paramDimension, paramScale, paramMarkers);
authManager.getAPIBaseURL() + "static/light/%s/%s%s%s", paramPosition, paramDimension, paramScale, paramMarkers);
getResponseBodyFromURL(url, new NetworkResponseBodyCompletionHandler() {
@Override
......@@ -627,10 +629,10 @@ public class CedarMaps {
private void getResponseBodyFromURL(final String url, final NetworkResponseBodyCompletionHandler completionHandler) {
AuthenticationManager.getInstance().getAccessToken(new AccessTokenListener() {
authManager.getAccessToken(new AccessTokenListener() {
@Override
public void onSuccess(@NonNull String accessToken) {
CedarOkHttpClient client = CedarOkHttpClient.getInstance();
OkHttpClient client = CedarOkHttpClient.getSharedInstance(authManager.getContext());
Request request = new Request.Builder()
.url(url)
.tag(url)
......@@ -646,7 +648,11 @@ public class CedarMaps {
if (response.code() == 400) {
completionHandler.onFailure(new CedarMapsException("Invalid Request. Missing Parameters.", response).getMessage());
} else if (response.code() == 401) {
AuthenticationManager.getInstance().regenerateAccessToken();
try {
authManager.regenerateAccessToken();
} catch (CedarMapsException e) {
e.printStackTrace();
}
completionHandler.onFailure(new CedarMapsException("Obtaining Bearer Token Failed.", response).getMessage());
} else if (response.code() == 500) {
completionHandler.onFailure(new CedarMapsException("Internal Server Error.", response).getMessage());
......
package com.cedarstudios.cedarmapssdk;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.os.ConfigurationCompat;
import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Response;
final class CedarOkHttpClient {
final class CedarOkHttpClient extends OkHttpClient {
private static OkHttpClient sharedInstance;
static OkHttpClient getSharedInstance(final Context applicationContext) {
if (sharedInstance != null) {
return sharedInstance;
}
sharedInstance = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.addNetworkInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
String userAgent;
if (userAgent(applicationContext) != null) {
userAgent = userAgent(applicationContext);
} else {
userAgent = "CedarMaps SDK";
}
assert userAgent != null;
return chain.proceed(
chain.request().newBuilder().header(
"User-Agent",
userAgent
).build()
);
}
})
.build();
return sharedInstance;
}
private static CedarOkHttpClient client = new CedarOkHttpClient();
private static String userAgent(Context applicationContext) {
String abi;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
abi = Build.SUPPORTED_ABIS[0];
} else {
abi = Build.CPU_ABI;
}
public static CedarOkHttpClient getInstance() {
return client;
try {
return String.format(
Locale.US, "%s/%s (%d) %s Android/%s %s-%s (%s)",
applicationContext.getPackageName(),
applicationContext.getPackageManager().getPackageInfo(
applicationContext.getPackageName(),
0
).versionName,
applicationContext.getPackageManager().getPackageInfo(
applicationContext.getPackageName(),
0
).versionCode,
ConfigurationCompat
.getLocales(applicationContext.getResources().getConfiguration()).get(0),
Build.VERSION.RELEASE,
Build.MANUFACTURER,
Build.MODEL,
abi
);
} catch (PackageManager.NameNotFoundException e) {
return null;
}
}
}
package com.cedarstudios.cedarmapssdk;
class Constants {
static final String INITIAL_TOKEN = "pk.spamradecrofnekotxobpamekafasisiht";
}
......@@ -10,11 +10,9 @@ import android.support.v4.content.LocalBroadcastManager;
import android.util.AttributeSet;
import com.cedarstudios.cedarmapssdk.listeners.AccessTokenListener;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import java.util.Locale;
import java.util.Map;
public class MapView extends com.mapbox.mapboxsdk.maps.MapView {
......@@ -58,7 +56,7 @@ public class MapView extends com.mapbox.mapboxsdk.maps.MapView {
}
};
LocalBroadcastManager.getInstance(Mapbox.getApplicationContext())
LocalBroadcastManager.getInstance(getContext().getApplicationContext())
.registerReceiver(mBroadcastReceiver, new IntentFilter(AuthenticationManager.ACCESS_TOKEN_READY_INTENT));
}
}
......@@ -107,7 +105,7 @@ public class MapView extends com.mapbox.mapboxsdk.maps.MapView {
@Override
public void onDestroy() {
LocalBroadcastManager.getInstance(Mapbox.getApplicationContext()).unregisterReceiver(mBroadcastReceiver);
LocalBroadcastManager.getInstance(getContext().getApplicationContext()).unregisterReceiver(mBroadcastReceiver);
super.onDestroy();
}
}
......@@ -26,10 +26,12 @@ final class TileConfigurator {
});
}
} else {
Mapbox.getInstance(context, Constants.INITIAL_TOKEN);
AuthenticationManager.getInstance().getAccessToken(new AccessTokenListener() {
@Override
public void onSuccess(@NonNull String accessToken) {
Mapbox.getInstance(context, accessToken);
Mapbox.setAccessToken("pk." + accessToken);
if (completionHandler != null) {
completionHandler.onSuccess();
}
......
package com.cedarstudios.cedarmapssdk.listeners;
import android.support.annotation.NonNull;
/**
* The listener for obtaining the Access Token needed in using CedarMaps API.
*/
......
......@@ -4,7 +4,6 @@ package com.cedarstudios.cedarmapssdk.model.geocoder.forward;
import android.support.annotation.Nullable;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
......
......@@ -7,8 +7,8 @@ android {
applicationId "com.cedarmaps.sdksampleapp"
minSdkVersion 15
targetSdkVersion 28
versionCode 97071210
versionName "1.2.1"
versionCode 97100410
versionName "1.4.0"
vectorDrawables.useSupportLibrary = true
}
......@@ -21,6 +21,7 @@ android {
}
lintOptions {
disable 'MissingTranslation'
abortOnError false
}
......@@ -33,7 +34,7 @@ android {
abi {
enable true
reset()
// include "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
include "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
universalApk true
}
}
......@@ -44,14 +45,14 @@ android {
def STRING = "String"
def MARKET = "MARKET"
def GOOGLE_PLAY = '"GooglePlay"'
def CAFE_BAZAAR = '"CafeBazaar"'
def GOOGLE_PLAY = '"googleplay"'
def CAFE_BAZAAR = '"cafebazaar"'
googlePlay {
buildConfigField STRING, MARKET, GOOGLE_PLAY
dimension "dimension"
ndk {
abiFilters "armeabi-v7a","arm64-v8a","x86","x86_64"
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
}
......@@ -59,13 +60,13 @@ android {
buildConfigField STRING, MARKET, CAFE_BAZAAR
dimension "dimension"
ndk {
abiFilters "armeabi-v7a","arm64-v8a"
abiFilters "armeabi-v7a", "arm64-v8a"
}
}
}
}
ext.abiCodes = ['armeabi-v7a':1, 'arm64-v8a':2, 'x86':3, 'x86_64':4]
ext.abiCodes = ['x86':1, 'x86_64':2, 'armeabi-v7a':3, 'arm64-v8a':4]
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def baseAbiVersionCode =
......@@ -78,10 +79,6 @@ android.applicationVariants.all { variant ->
dependencies {
implementation (project(':CedarMapsSDK'))
implementation("com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:0.8.2") {
exclude group: 'com.mapbox.mapboxsdk'
}
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-vector-drawable:28.0.0'
......
......@@ -9,8 +9,7 @@
<application
android:allowClearUserData="true"
android:appCategory="maps"
android:fullBackupContent="true"
android:allowBackup="true"
android:allowBackup="false"
android:name=".SampleApp"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
......@@ -27,7 +26,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="android.max_aspect" android:value="2.1" />
</application>
</manifest>
\ No newline at end of file
......@@ -6,8 +6,9 @@ public class Constants {
public static final int PERMISSION_LOCATION_REQUEST_CODE = 100;
static final String CLIENT_ID = "CLIENT_ID";
static final String CLIENT_SECRET = "CLIENT_SECRET";
// TODO: Add your clientID and clientSecret here.
static final String CLIENT_ID = "YOUR_CLIENT_ID";
static final String CLIENT_SECRET = "YOUR_CLIENT_SECRET";
public static final LatLng VANAK_SQUARE = new LatLng(35.7572, 51.4099);
}
......@@ -2,11 +2,13 @@ package com.cedarmaps.sdksampleapp;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;
import com.cedarmaps.sdksampleapp.fragments.DirectionFragment;
import com.cedarmaps.sdksampleapp.fragments.ForwardGeocodeFragment;
......@@ -16,11 +18,32 @@ import com.cedarmaps.sdksampleapp.fragments.StaticMapFragment;
import com.cedarstudios.cedarmapssdk.CedarMaps;
import com.cedarstudios.cedarmapssdk.listeners.OnTilesConfigured;
public class MainActivity extends AppCompatActivity {
import java.util.Locale;
public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CedarMaps.getInstance().prepareTiles(new OnTilesConfigured() {
@Override
public void onSuccess() {
BottomNavigationView navigation = findViewById(R.id.navigationView);
navigation.setOnNavigationItemSelectedListener(MainActivity.this);
navigation.setSelectedItemId(R.id.navigation_map);
}
@Override
public void onFailure(@NonNull String error) {
Toast.makeText(MainActivity.this, R.string.error_preparing_tiles, Toast.LENGTH_LONG).show();
}
});
}
private Integer currentlySelectedMenuID = null;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= item -> {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment fragment = null;
switch (item.getItemId()) {
case R.id.navigation_map:
......@@ -45,35 +68,17 @@ public class MainActivity extends AppCompatActivity {
break;
}
if (fragment != null && (currentlySelectedMenuID == null || currentlySelectedMenuID != item.getItemId())) {
invalidateOptionsMenu();
if (fragment != null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
currentlySelectedMenuID = item.getItemId();
transaction.add(R.id.content, fragment).commit();
if (getSupportFragmentManager().getFragments().isEmpty()) {
transaction.add(R.id.content, fragment, String.format(Locale.US, "item: %d", item.getItemId())).commit();
} else {
transaction.replace(R.id.content, fragment, String.format(Locale.US, "item: %d", item.getItemId())).commit();
invalidateOptionsMenu();
}
return true;
}
return false;
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CedarMaps.getInstance().prepareTiles(new OnTilesConfigured() {
@Override
public void onSuccess() {
BottomNavigationView navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
navigation.setSelectedItemId(R.id.navigation_map);
currentlySelectedMenuID = navigation.getSelectedItemId();
}
@Override
public void onFailure(@NonNull String error) {
Log.e("MainActivity", error);
}
});
}
}
package com.cedarmaps.sdksampleapp;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
......@@ -30,10 +31,10 @@ public class SearchViewAdapter extends RecyclerView.Adapter<SearchViewAdapter.Se
SearchViewHolder(View v) {
super(v);
mNameTextView = (TextView) v.findViewById(R.id.search_view_list_item_name);
mTypeTextView = (TextView) v.findViewById(R.id.search_view_list_item_type);
mCityTextView = (TextView) v.findViewById(R.id.search_view_list_city);
mLocalityTextView = (TextView) v.findViewById(R.id.search_view_list_item_locality);
mNameTextView = v.findViewById(R.id.search_view_list_item_name);
mTypeTextView = v.findViewById(R.id.search_view_list_item_type);
mCityTextView = v.findViewById(R.id.search_view_list_city);
mLocalityTextView = v.findViewById(R.id.search_view_list_item_locality);
v.setOnClickListener(this);
}
......
......@@ -215,8 +215,8 @@ public class DirectionFragment extends Fragment {
}
@Override
public void onDestroy() {
super.onDestroy();
public void onDestroyView() {
super.onDestroyView();
mMapView.onDestroy();
}
......
......@@ -251,8 +251,8 @@ public class ForwardGeocodeFragment extends Fragment {
}
@Override
public void onDestroy() {
super.onDestroy();
public void onDestroyView() {
super.onDestroyView();
mMapView.onDestroy();
}
......
......@@ -8,17 +8,14 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.cedarmaps.sdksampleapp.Constants;
import com.cedarmaps.sdksampleapp.R;
import com.cedarstudios.cedarmapssdk.MapView;
import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.android.core.location.LocationEngineListener;
......@@ -29,9 +26,8 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin;
import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode;
import static android.support.v4.content.PermissionChecker.PERMISSION_GRANTED;
......@@ -40,7 +36,6 @@ public class MapFragment extends Fragment implements LocationEngineListener {
private MapView mMapView;
private MapboxMap mMapboxMap;
private LocationEngine mLocationEngine = null;
private LocationLayerPlugin mLocationLayerPlugin = null;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
......@@ -61,14 +56,16 @@ public class MapFragment extends Fragment implements LocationEngineListener {
mMapboxMap.setMaxZoomPreference(17);
mMapboxMap.setMinZoomPreference(6);
mMapboxMap.setCameraPosition(
new CameraPosition.Builder()
.target(Constants.VANAK_SQUARE)
.zoom(15)
.build());
if (hasLocationPermissions()) {
enableLocationPlugin();
if (PermissionsManager.areLocationPermissionsGranted(getActivity())) {
enableLocationComponent();
}
//Move map to a certain position
animateToCoordinate(Constants.VANAK_SQUARE, 15);
//Add marker to map
addMarkerToMapViewAtPosition(Constants.VANAK_SQUARE);
......@@ -106,39 +103,37 @@ public class MapFragment extends Fragment implements LocationEngineListener {
private void setupCurrentLocationButton() {
FloatingActionButton fb = getView().findViewById(R.id.showCurrentLocationButton);
fb.setOnClickListener(v -> {
if (!hasLocationPermissions()) {
enableLocationPlugin();
return;
}
enableLocationComponent();
toggleCurrentLocationButton();
});
}
@SuppressLint("MissingPermission")
private void toggleCurrentLocationButton() {
if (mLocationLayerPlugin == null) {
if (!mMapboxMap.getLocationComponent().isLocationComponentEnabled()) {
return;
}
Location location = mLocationLayerPlugin.getLastKnownLocation();
Location location = mMapboxMap.getLocationComponent().getLastKnownLocation();
if (location != null) {
animateToCoordinate(new LatLng(location.getLatitude(),location.getLongitude()), 16);
}
switch (mLocationLayerPlugin.getRenderMode()) {
switch (mMapboxMap.getLocationComponent().getRenderMode()) {
case RenderMode.NORMAL:
mLocationLayerPlugin.setRenderMode(RenderMode.COMPASS);
mMapboxMap.getLocationComponent().setRenderMode(RenderMode.COMPASS);
break;
case RenderMode.GPS:
mLocationLayerPlugin.setRenderMode(RenderMode.NORMAL);
mMapboxMap.getLocationComponent().setRenderMode(RenderMode.NORMAL);
break;
case RenderMode.COMPASS:
mLocationLayerPlugin.setRenderMode(RenderMode.NORMAL);
mMapboxMap.getLocationComponent().setRenderMode(RenderMode.NORMAL);
break;
}
}
@SuppressWarnings( {"MissingPermission"})
private void enableLocationPlugin() {
private void enableLocationComponent() {
if (getActivity() == null) {
return;
}
......@@ -147,8 +142,8 @@ public class MapFragment extends Fragment implements LocationEngineListener {
// Create a location engine instance
initializeLocationEngine();
mLocationLayerPlugin = new LocationLayerPlugin(mMapView, mMapboxMap, mLocationEngine);
mLocationLayerPlugin.setLocationLayerEnabled(true);
mMapboxMap.getLocationComponent().activateLocationComponent(getActivity());
mMapboxMap.getLocationComponent().setLocationComponentEnabled(true);
} else {
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, Constants.PERMISSION_LOCATION_REQUEST_CODE);
}
......@@ -160,16 +155,8 @@ public class MapFragment extends Fragment implements LocationEngineListener {
mLocationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
mLocationEngine.activate();
Location lastLocation = mLocationEngine.getLastLocation();
if (lastLocation == null) {
mLocationEngine.addLocationEngineListener(this);
}
}
private boolean hasLocationPermissions() {
//Request Location Permission
return getActivity() != null && ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) == PERMISSION_GRANTED;
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
......@@ -181,8 +168,10 @@ public class MapFragment extends Fragment implements LocationEngineListener {
@SuppressWarnings( {"MissingPermission"})
public void onStart() {
super.onStart();
if (mLocationLayerPlugin != null) {
mLocationLayerPlugin.onStart();
if (PermissionsManager.areLocationPermissionsGranted(getActivity())) {
if (mLocationEngine != null) {
mLocationEngine.activate();
}
}
mMapView.onStart();
}
......@@ -192,11 +181,8 @@ public class MapFragment extends Fragment implements LocationEngineListener {
super.onStop();
if (mLocationEngine != null) {
mLocationEngine.removeLocationUpdates();
mLocationEngine.removeLocationEngineListener(this);
}
if (mLocationLayerPlugin != null) {
mLocationLayerPlugin.onStop();
}
mMapView.onStop();
}
......@@ -219,8 +205,8 @@ public class MapFragment extends Fragment implements LocationEngineListener {
}
@Override
public void onDestroy() {
super.onDestroy();
public void onDestroyView() {
super.onDestroyView();
mMapView.onDestroy();
if (mLocationEngine != null) {
mLocationEngine.deactivate();
......@@ -241,7 +227,7 @@ public class MapFragment extends Fragment implements LocationEngineListener {
if (!(grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED)) {
Toast.makeText(getActivity(), R.string.location_is_needed_to_function, Toast.LENGTH_LONG).show();
} else {
enableLocationPlugin();
enableLocationComponent();
toggleCurrentLocationButton();
}
break;
......@@ -253,7 +239,7 @@ public class MapFragment extends Fragment implements LocationEngineListener {
@SuppressLint("MissingPermission")
@Override
public void onConnected() {
if (mLocationEngine != null && hasLocationPermissions()) {
if (mLocationEngine != null && PermissionsManager.areLocationPermissionsGranted(getActivity())) {
mLocationEngine.requestLocationUpdates();
}
}
......
......@@ -3,6 +3,7 @@ package com.cedarmaps.sdksampleapp.fragments;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
......@@ -20,7 +21,6 @@ import com.cedarstudios.cedarmapssdk.listeners.ReverseGeocodeResultListener;
import com.cedarstudios.cedarmapssdk.model.geocoder.reverse.ReverseGeocode;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
public class ReverseGeocodeFragment extends Fragment {
......@@ -174,8 +174,8 @@ public class ReverseGeocodeFragment extends Fragment {
}
@Override
public void onDestroy() {
super.onDestroy();
public void onDestroyView() {
super.onDestroyView();
mMapView.onDestroy();
}
......
......@@ -30,7 +30,6 @@ import java.util.ArrayList;
public class StaticMapFragment extends Fragment {
private Button createMapButton;
private ImageView mapImageView;
private ProgressBar progressBar;
private TextView howToTextView;
......@@ -53,7 +52,7 @@ public class StaticMapFragment extends Fragment {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
createMapButton = view.findViewById(R.id.static_map_create_button);
Button createMapButton = view.findViewById(R.id.static_map_create_button);
mapImageView = view.findViewById(R.id.static_map_image_view);
progressBar = view.findViewById(R.id.static_map_progress_bar);
howToTextView = view.findViewById(R.id.static_map_hint);
......
......@@ -17,7 +17,7 @@
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:id="@+id/navigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
......
......@@ -29,4 +29,5 @@
<string name="province">استان</string>
<string name="comma">،</string>
<string name="location_is_needed_to_function">نرم‌افزار برای عملکرد این ویژگی به موقعیت مکانی نیاز دارد</string>
<string name="error_preparing_tiles">خطا در آماده‌سازی نقشه</string>
</resources>
......@@ -32,4 +32,5 @@
<string name="longitude_example" translatable="false">51.3572</string>
<string name="zoom_example" translatable="false">13</string>
<string name="location_is_needed_to_function">App needs location to function</string>
<string name="error_preparing_tiles">Error in preparing map tiles</string>
</resources>
......@@ -2,7 +2,7 @@
This guide will take you through the process of integrating CedarMaps into your Android application.
All the mentioned methods and tools in this document are tested on Android Studio v3.2.0.
All the mentioned methods and tools in this document are tested on Android Studio v3.2.1.
## Table of Contents
- [Installation](#installation)
......@@ -38,7 +38,7 @@ Then, add this to the `build.gradle` of your **app** module:
```groovy
dependencies {
implementation 'com.cedarmaps:CedarMapsSDK:3.1.2'
implementation 'com.cedarmaps:CedarMapsSDK:3.2.0'
}
```
......@@ -97,7 +97,7 @@ CedarMaps.getInstance()
### Mapbox
CedarMaps SDK is based on [Mapbox GL Android SDK v6.3.0](https://github.com/mapbox/mapbox-gl-native) and provides extra API methods over Mapbox.
CedarMaps SDK is based on [Mapbox GL Android SDK v6.8.0](https://github.com/mapbox/mapbox-gl-native) and provides extra API methods over Mapbox.
For more information about how to use MapView and other components such as **Adding Markers**, **Showing Current Location**, etc., please see [Mapbox Getting Started](https://www.mapbox.com/help/first-steps-android-sdk/).
#### MapView
......@@ -174,21 +174,6 @@ mMapView.setStyleUrl("STYLE_URL");
```
Make sure to use your base URL if you have one.
#### Plugins
Mapbox uses [Plugins](https://github.com/mapbox/mapbox-plugins-android) to add extra functionality to the base SDK.
Each plugin is added as a new dependency in `build.gradle`.
```groovy
dependencies {
implementation ('com.mapbox.mapboxsdk:PLUGIN_NAME:PLUGIN_VERSION_NUMBER') {
exclude group: 'com.mapbox.mapboxsdk'
}
}
```
**Note:** Since CedarMaps uses a forked version of Mapbox SDK, make sure to exclude `group: 'com.mapbox.mapboxsdk'` when adding a new plugin.
### APK Size
......
......@@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
......@@ -18,9 +18,9 @@ allprojects {
repositories {
jcenter()
mavenCentral()
google()
maven {
url "https://repo.cedarmaps.com/android/"
}
google()
}
}
GROUP=com.cedarmaps
VERSION_NAME=3.1.0
VERSION_NAME=3.2.0
# Project-wide Gradle settings.
......
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