Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - show error message when no browser is installed on the de…
Browse files Browse the repository at this point in the history
…vice of the user. (#8901)
  • Loading branch information
tobrun authored May 8, 2017
1 parent dd353a6 commit 45545e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mapbox.mapboxsdk.maps;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
Expand All @@ -12,6 +13,7 @@
import android.text.style.URLSpan;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Toast;

import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.camera.CameraPosition;
Expand Down Expand Up @@ -66,7 +68,7 @@ public void onClick(DialogInterface dialog, int which) {
if (isLatestEntry(which)) {
showTelemetryDialog();
} else {
showAttributionWebPage(which);
showMapFeedbackWebPage(which);
}
}

Expand All @@ -88,10 +90,7 @@ public void onClick(DialogInterface dialog, int which) {
builder.setNeutralButton(R.string.mapbox_attributionTelemetryNeutral, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String url = context.getResources().getString(R.string.mapbox_telemetryLink);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
context.startActivity(intent);
showWebPage(context.getResources().getString(R.string.mapbox_telemetryLink));
dialog.cancel();
}
});
Expand All @@ -105,14 +104,12 @@ public void onClick(DialogInterface dialog, int which) {
builder.show();
}

private void showAttributionWebPage(int which) {
Intent intent = new Intent(Intent.ACTION_VIEW);
private void showMapFeedbackWebPage(int which) {
String url = attributionMap.get(attributionKeys[which]);
if (url.contains(MAP_FEEDBACK_URL)) {
url = buildMapFeedbackMapUrl(mapboxMap.getCameraPosition());
}
intent.setData(Uri.parse(url));
context.startActivity(intent);
showWebPage(url);
}

private String buildMapFeedbackMapUrl(CameraPosition cameraPosition) {
Expand All @@ -122,6 +119,17 @@ private String buildMapFeedbackMapUrl(CameraPosition cameraPosition) {
(int) cameraPosition.zoom) : MAP_FEEDBACK_URL;
}

private void showWebPage(@NonNull String url) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
context.startActivity(intent);
} catch (ActivityNotFoundException exception) {
// explicitly handling if the device hasn't have a web browser installed. #8899
Toast.makeText(context, R.string.mapbox_attributionErrorNoBrowser, Toast.LENGTH_LONG).show();
}
}

private static class AttributionBuilder {

private final HashMap<String, String> map = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<string name="mapbox_attributionTelemetryPositive">Agree</string>
<string name="mapbox_attributionTelemetryNegative">Disagree</string>
<string name="mapbox_attributionTelemetryNeutral">More info</string>
<string name="mapbox_attributionErrorNoBrowser">No web browser installed on device, can\'t open web page.</string>
<string name="mapbox_offline_error_region_definition_invalid">Provided OfflineRegionDefinition doesn\'t fit the world bounds: %s</string>
<string name="mapbox_telemetrySettings">Telemetry Settings</string>
<string name="mapbox_telemetryLink" translatable="false">https://www.mapbox.com/telemetry/</string>
Expand Down

0 comments on commit 45545e1

Please sign in to comment.