Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit ce21b2b

Browse files
committed
Adds "FormattedAddress" to ReverseGeocode methods.
Adds new street types to ForwardGeocode methods. Upgrades to AndroidX. Built with SDK 29.
1 parent d441577 commit ce21b2b

45 files changed

Lines changed: 282 additions & 159 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CedarMapsSDK/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ apply plugin: 'signing'
33
apply plugin: 'com.github.dcendents.android-maven'
44

55
group = "com.cedarmaps"
6-
version = "4.1.0"
6+
version = "4.2.0"
77
def siteUrl = 'http://cedarmaps.com'
88
def gitUrl = 'http://cedarmaps.com/git'
99

1010
android {
11-
compileSdkVersion 28
11+
compileSdkVersion 29
1212

1313
defaultConfig {
1414
minSdkVersion 15 //IceCream Sandwich 4.0.3
15-
targetSdkVersion 28 //Pie
15+
targetSdkVersion 29 //10
1616
}
1717
}
1818

1919
dependencies {
2020
api 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.3.0'
21-
implementation 'com.squareup.okhttp3:okhttp:3.14.1'
21+
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
2222
implementation 'com.google.code.gson:gson:2.8.5'
2323
}
2424

CedarMapsSDK/src/main/java/com/cedarstudios/cedarmapssdk/AuthenticationManager.java

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import android.content.SharedPreferences;
66
import android.os.Handler;
77
import android.os.Looper;
8-
import android.support.annotation.NonNull;
9-
import android.support.annotation.Nullable;
8+
import androidx.annotation.NonNull;
9+
import androidx.annotation.Nullable;
1010
import android.text.TextUtils;
1111

1212
import com.cedarstudios.cedarmapssdk.listeners.AccessTokenListener;
1313
import com.mapbox.mapboxsdk.Mapbox;
1414

15+
import org.jetbrains.annotations.NotNull;
1516
import org.json.JSONObject;
1617

1718
import java.io.IOException;
@@ -109,8 +110,14 @@ public void run() {
109110
handler.post(new Runnable() {
110111
@Override
111112
public void run() {
112-
completionHandler.onFailure(e.getMessage());
113-
113+
String message = e.getLocalizedMessage();
114+
if (message == null) {
115+
message = e.getMessage();
116+
}
117+
if (message == null) {
118+
message = "Unknown error in getting access token occurred.";
119+
}
120+
completionHandler.onFailure(message);
114121
}
115122
});
116123
}
@@ -240,20 +247,9 @@ private void fetchAccessTokenFromServer(final AccessTokenListener completionHand
240247
.build();
241248

242249
client.newCall(request).enqueue(new Callback() {
243-
@Override
244-
public void onFailure(Call call, final IOException e) {
245-
handler.post(new Runnable() {
246-
@Override
247-
public void run() {
248-
if (completionHandler != null) {
249-
completionHandler.onFailure(e.getMessage());
250-
}
251-
}
252-
});
253-
}
254250

255251
@Override
256-
public void onResponse(Call call, final Response response) {
252+
public void onResponse(@NotNull Call call, @NotNull final Response response) {
257253
ResponseBody body = response.body();
258254
if (body == null) {
259255
handler.post(new Runnable() {
@@ -285,7 +281,14 @@ public void run() {
285281
@Override
286282
public void run() {
287283
if (completionHandler != null) {
288-
completionHandler.onFailure(e.getMessage());
284+
String message = e.getLocalizedMessage();
285+
if (message == null) {
286+
message = e.getMessage();
287+
}
288+
if (message == null) {
289+
message = "Unknown encoding error occurred.";
290+
}
291+
completionHandler.onFailure(message);
289292
}
290293
}
291294
});
@@ -318,13 +321,42 @@ public void run() {
318321
@Override
319322
public void run() {
320323
if (completionHandler != null) {
321-
completionHandler.onFailure(e.getMessage());
324+
String message = e.getLocalizedMessage();
325+
if (message == null) {
326+
message = e.getMessage();
327+
}
328+
if (message == null) {
329+
message = "Unknown network error occurred.";
330+
}
331+
completionHandler.onFailure(message);
322332
}
323333
}
324334
});
325335
}
326336
}
337+
327338
}
339+
340+
@Override
341+
public void onFailure(@NotNull Call call, @NotNull final IOException e) {
342+
handler.post(new Runnable() {
343+
@Override
344+
public void run() {
345+
if (completionHandler != null) {
346+
String message = e.getLocalizedMessage();
347+
if (message == null) {
348+
message = e.getMessage();
349+
}
350+
if (message == null) {
351+
message = "Unknown network error occurred.";
352+
}
353+
completionHandler.onFailure(message);
354+
}
355+
}
356+
});
357+
}
358+
359+
328360
});
329361
}
330362
}

CedarMapsSDK/src/main/java/com/cedarstudios/cedarmapssdk/CedarMaps.java

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import android.os.AsyncTask;
88
import android.os.Handler;
99
import android.os.Looper;
10-
import android.support.annotation.NonNull;
11-
import android.support.annotation.Nullable;
12-
import android.support.v4.util.Pair;
10+
import androidx.annotation.NonNull;
11+
import androidx.annotation.Nullable;
12+
import androidx.core.util.Pair;
1313
import android.text.TextUtils;
1414
import android.util.DisplayMetrics;
1515

@@ -22,6 +22,7 @@
2222
import com.cedarstudios.cedarmapssdk.model.MapID;
2323
import com.cedarstudios.cedarmapssdk.model.StaticMarker;
2424
import com.cedarstudios.cedarmapssdk.model.geocoder.forward.ForwardGeocodeResponse;
25+
import com.cedarstudios.cedarmapssdk.model.geocoder.reverse.FormattedAddressPrefixLength;
2526
import com.cedarstudios.cedarmapssdk.model.geocoder.reverse.ReverseGeocodeResponse;
2627
import com.cedarstudios.cedarmapssdk.model.routing.GeoRoutingResponse;
2728
import com.mapbox.mapboxsdk.geometry.LatLng;
@@ -442,6 +443,7 @@ public void onFailure(String errorMessage) {
442443
});
443444
}
444445

446+
445447
/**
446448
* Gives an address based on a provided coordinate.
447449
* This method works asynchronously and returns immediately.
@@ -451,10 +453,52 @@ public void onFailure(String errorMessage) {
451453
* The handler methods are called on UIThread.
452454
*/
453455
public void reverseGeocode(LatLng coordinate, final ReverseGeocodeResultListener completionHandler) {
456+
reverseGeocode(coordinate,
457+
null,
458+
FormattedAddressPrefixLength.SHORT,
459+
null,
460+
false,
461+
completionHandler);
462+
}
463+
464+
/**
465+
* @param coordinate The coordinate to get the address from.
466+
* @param addressFormat Format string for generated formatted address.
467+
* e.g. "{country}{province}{sep}{city}{sep}{locality}{sep}{district}{sep}{address}{sep}{place}"
468+
* @param formattedAddressPrefixLength Length of streets prefix in generated formatted address.
469+
* Default is short.
470+
* @param formattedAddressSeparator The separator used in generated formatted address.
471+
* Default is "، "
472+
* @param shouldOutputVerboseFormattedAddress A boolean indicating if extra information
473+
* should be included in generated formatted address
474+
* such as نرسیده به and بعد از.
475+
* @param completionHandler The handler to notify when Reverse Geocode results are ready with success or error.
476+
* The handler methods are called on UIThread.
477+
*/
478+
public void reverseGeocode(LatLng coordinate,
479+
@Nullable String addressFormat,
480+
@NonNull FormattedAddressPrefixLength formattedAddressPrefixLength,
481+
@Nullable String formattedAddressSeparator,
482+
boolean shouldOutputVerboseFormattedAddress,
483+
final ReverseGeocodeResultListener completionHandler) {
454484
String url = String.format(Locale.ENGLISH,
455-
authManager.getAPIBaseURL() + "geocode/%1$s/%2$s,%3$s.json",
485+
authManager.getAPIBaseURL() + "geocode/%1$s/%2$s,%3$s.json?prefix=%4$s",
456486
mapID.toString(),
457-
coordinate.getLatitude(), coordinate.getLongitude());
487+
coordinate.getLatitude(),
488+
coordinate.getLongitude(),
489+
formattedAddressPrefixLength.toString());
490+
491+
if (addressFormat != null && addressFormat.length() > 0) {
492+
url += String.format(Locale.ENGLISH, "&format=%1$s", addressFormat);
493+
}
494+
495+
if (formattedAddressSeparator != null) {
496+
url += String.format(Locale.ENGLISH, "&separator=%1$s", formattedAddressSeparator);
497+
}
498+
499+
if (shouldOutputVerboseFormattedAddress) {
500+
url += String.format(Locale.ENGLISH, "&verbosity=%1$s", "true");
501+
}
458502

459503
getResponseBodyFromURL(url, new NetworkResponseBodyCompletionHandler() {
460504
@Override

CedarMapsSDK/src/main/java/com/cedarstudios/cedarmapssdk/CedarMapsStyle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.cedarstudios.cedarmapssdk;
22

3-
import android.support.annotation.NonNull;
3+
import androidx.annotation.NonNull;
44

55
public enum CedarMapsStyle {
66
VECTOR_LIGHT {

CedarMapsSDK/src/main/java/com/cedarstudios/cedarmapssdk/CedarMapsStyleConfigurator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import android.os.Handler;
44
import android.os.Looper;
5-
import android.support.annotation.NonNull;
5+
import androidx.annotation.NonNull;
66

77
import com.cedarstudios.cedarmapssdk.listeners.AccessTokenListener;
88
import com.cedarstudios.cedarmapssdk.listeners.OnStyleConfigurationListener;
@@ -20,7 +20,7 @@ public void onSuccess(@NonNull final String accessToken) {
2020
@Override
2121
public void run() {
2222
String url = style.urlString() + "?access_token=" + accessToken;
23-
Style.Builder builder = new Style.Builder().fromUrl(url);
23+
Style.Builder builder = new Style.Builder().fromUri(url);
2424
completionHandler.onSuccess(builder);
2525
}
2626
});

CedarMapsSDK/src/main/java/com/cedarstudios/cedarmapssdk/CedarOkHttpClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import android.content.Context;
44
import android.content.pm.PackageManager;
55
import android.os.Build;
6-
import android.support.v4.os.ConfigurationCompat;
6+
import androidx.core.os.ConfigurationCompat;
7+
8+
import org.jetbrains.annotations.NotNull;
79

810
import java.io.IOException;
911
import java.util.Locale;
@@ -25,8 +27,9 @@ static OkHttpClient getSharedInstance(final Context applicationContext) {
2527
.connectTimeout(30, TimeUnit.SECONDS)
2628
.readTimeout(30, TimeUnit.SECONDS)
2729
.addNetworkInterceptor(new Interceptor() {
30+
@NotNull
2831
@Override
29-
public Response intercept(Chain chain) throws IOException {
32+
public Response intercept(@NotNull Chain chain) throws IOException {
3033
String userAgent;
3134
if (userAgent(applicationContext) != null) {
3235
userAgent = userAgent(applicationContext);

CedarMapsSDK/src/main/java/com/cedarstudios/cedarmapssdk/MapView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.cedarstudios.cedarmapssdk;
22

33
import android.content.Context;
4-
import android.support.annotation.NonNull;
5-
import android.support.annotation.Nullable;
4+
import androidx.annotation.NonNull;
5+
import androidx.annotation.Nullable;
66
import android.util.AttributeSet;
77
import android.widget.ImageView;
88
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;

CedarMapsSDK/src/main/java/com/cedarstudios/cedarmapssdk/listeners/AccessTokenListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.cedarstudios.cedarmapssdk.listeners;
22

3-
import android.support.annotation.NonNull;
3+
import androidx.annotation.NonNull;
44
/**
55
* The listener for obtaining the Access Token needed in using CedarMaps API.
66
*/

CedarMapsSDK/src/main/java/com/cedarstudios/cedarmapssdk/listeners/ForwardGeocodeResultsListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.cedarstudios.cedarmapssdk.listeners;
22

3-
import android.support.annotation.NonNull;
3+
import androidx.annotation.NonNull;
44
import com.cedarstudios.cedarmapssdk.model.geocoder.forward.ForwardGeocode;
55
import java.util.List;
66

CedarMapsSDK/src/main/java/com/cedarstudios/cedarmapssdk/listeners/GeoRoutingResultListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.cedarstudios.cedarmapssdk.listeners;
22

3-
import android.support.annotation.NonNull;
3+
import androidx.annotation.NonNull;
44
import com.cedarstudios.cedarmapssdk.model.routing.GeoRouting;
55

66
/**

0 commit comments

Comments
 (0)