diff --git a/MapboxAndroidDemo/build.gradle b/MapboxAndroidDemo/build.gradle index bdcd1e239..94b474834 100644 --- a/MapboxAndroidDemo/build.gradle +++ b/MapboxAndroidDemo/build.gradle @@ -111,6 +111,7 @@ dependencies { implementation dependenciesList.mapboxPluginGeoJson implementation dependenciesList.mapboxPluginMarkerCluster implementation dependenciesList.mapboxPluginPlaces + implementation dependenciesList.mapboxPluginLocalization // Firebase implementation dependenciesList.firebaseCrash diff --git a/MapboxAndroidDemo/src/main/AndroidManifest.xml b/MapboxAndroidDemo/src/main/AndroidManifest.xml index 472ed3011..a57576a21 100644 --- a/MapboxAndroidDemo/src/main/AndroidManifest.xml +++ b/MapboxAndroidDemo/src/main/AndroidManifest.xml @@ -138,6 +138,13 @@ android:name="android.support.PARENT_ACTIVITY" android:value="com.mapbox.mapboxandroiddemo.MainActivity" /> + + + diff --git a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java index ac0850253..53373691c 100644 --- a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java +++ b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java @@ -64,6 +64,7 @@ import com.mapbox.mapboxandroiddemo.examples.offline.SimpleOfflineMapActivity; import com.mapbox.mapboxandroiddemo.examples.plugins.BuildingPluginActivity; import com.mapbox.mapboxandroiddemo.examples.plugins.GeoJsonPluginActivity; +import com.mapbox.mapboxandroiddemo.examples.plugins.LocalizationPluginActivity; import com.mapbox.mapboxandroiddemo.examples.plugins.LocationPluginActivity; import com.mapbox.mapboxandroiddemo.examples.plugins.MarkerClustersPluginActivity; import com.mapbox.mapboxandroiddemo.examples.plugins.PlacesPluginActivity; @@ -418,8 +419,14 @@ private void listItems(int id) { R.string.activity_plugins_marker_clusters_plugin_title, R.string.activity_plugins_geojson_marker_clusters_description, new Intent(MainActivity.this, MarkerClustersPluginActivity.class), - R.string.activity_plugins_markers_clusters_plugin_url, true, BuildConfig.MIN_SDK_VERSION)); - + R.string.activity_plugins_markers_clusters_plugin_url, true, BuildConfig.MIN_SDK_VERSION) + ); + exampleItemModels.add(new ExampleItemModel( + R.string.activity_plugins_localization_plugin_title, + R.string.activity_plugins_localization_plugin_description, + new Intent(MainActivity.this, LocalizationPluginActivity.class), + R.string.activity_plugins_localization_plugin_url, true, BuildConfig.MIN_SDK_VERSION) + ); currentCategory = R.id.nav_plugins; break; diff --git a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/plugins/LocalizationPluginActivity.java b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/plugins/LocalizationPluginActivity.java new file mode 100644 index 000000000..3c8a77b14 --- /dev/null +++ b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/plugins/LocalizationPluginActivity.java @@ -0,0 +1,127 @@ +package com.mapbox.mapboxandroiddemo.examples.plugins; + +import android.os.Bundle; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.view.View; + +import com.mapbox.mapboxandroiddemo.R; +import com.mapbox.mapboxsdk.Mapbox; +import com.mapbox.mapboxsdk.camera.CameraPosition; +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.plugins.localization.LocalizationPlugin; +import com.mapbox.mapboxsdk.plugins.localization.MapLocale; + +/** + * Use the localization plugin to retrieve the device's language and set all map text labels to that language. + */ +public class LocalizationPluginActivity extends AppCompatActivity implements OnMapReadyCallback { + + private MapView mapView; + private LocalizationPlugin localizationPlugin; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Mapbox access token is configured here. This needs to be called either in your application + // object or in the same activity which contains the mapview. + Mapbox.getInstance(this, getString(R.string.access_token)); + + // This contains the MapView in XML and needs to be called after the access token is configured. + setContentView(R.layout.activity_localization_plugin); + mapView = findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(this); + } + + @Override + public void onMapReady(final MapboxMap mapboxMap) { + + localizationPlugin = new LocalizationPlugin(mapView, mapboxMap); + + findViewById(R.id.language_one_cardview).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + localizationPlugin.setMapLanguage(MapLocale.ARABIC); + } + }); + findViewById(R.id.language_two_cardview).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + localizationPlugin.setMapLanguage(MapLocale.RUSSIAN); + } + }); + findViewById(R.id.language_three_cardview).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + localizationPlugin.setMapLanguage(MapLocale.SIMPLIFIED_CHINESE); + } + }); + findViewById(R.id.match_map_to_device_language).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Snackbar.make(view, R.string.change_device_language_instruction, Snackbar.LENGTH_LONG).show(); + try { + localizationPlugin.matchMapLanguageWithDeviceDefault(); + CameraPosition position = new CameraPosition.Builder() + .target(new LatLng(34.032666, -80.363160)) + .zoom(2.038777) + .build(); + + mapboxMap.animateCamera(CameraUpdateFactory + .newCameraPosition(position), 1000); + } catch (RuntimeException exception) { + Snackbar.make(view, exception.toString(), Snackbar.LENGTH_LONG).show(); + } + } + }); + } + + // Add the mapView lifecycle to the activity's lifecycle methods + @Override + public void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + protected void onStart() { + super.onStart(); + mapView.onStart(); + } + + @Override + protected void onStop() { + super.onStop(); + mapView.onStop(); + } + + @Override + public void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } +} \ No newline at end of file diff --git a/MapboxAndroidDemo/src/main/res/drawable/ic_swap_horiz_white_24dp.xml b/MapboxAndroidDemo/src/main/res/drawable/ic_swap_horiz_white_24dp.xml new file mode 100644 index 000000000..5a1d789ac --- /dev/null +++ b/MapboxAndroidDemo/src/main/res/drawable/ic_swap_horiz_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/MapboxAndroidDemo/src/main/res/layout/activity_localization_plugin.xml b/MapboxAndroidDemo/src/main/res/layout/activity_localization_plugin.xml new file mode 100644 index 000000000..667591850 --- /dev/null +++ b/MapboxAndroidDemo/src/main/res/layout/activity_localization_plugin.xml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MapboxAndroidDemo/src/main/res/values/activity_strings.xml b/MapboxAndroidDemo/src/main/res/values/activity_strings.xml index 76b38f8f4..c876e886b 100644 --- a/MapboxAndroidDemo/src/main/res/values/activity_strings.xml +++ b/MapboxAndroidDemo/src/main/res/values/activity_strings.xml @@ -205,6 +205,19 @@ Load custom raster style Load local style + + Map not localized to device language and now set to French + Map localized to device language + Camera bounds for country associated with language tag: %1$s + Make sure that the device\'s default language is not English + Mandarin + Russian + Arabic + Change the device\'s language to German and then tap this button. Already in German? Try French + Try setting your phone to a different language. German or French perhaps? + Uh-oh! You\'re lost in NYC. Tap the buttons below to + switch the map\'s language so that you can ask for help with directions. + Oh no! The call to the Directions Matrix API failed! %1$s miles diff --git a/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml b/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml index 54c250e87..a35719e2f 100644 --- a/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml +++ b/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml @@ -63,6 +63,7 @@ Easily retrieve GeoJSON data from a url, asset, or path Add location search ("geocoding") functionality and UI to search for any place in the world Use the plugin to automatically add marker clusters to the map. This example shows bike share stations in Paris. + Use the plugin to automatically change map label text to the language set on the device. Using the polylines utility, simplify a polyline which reduces the amount of coordinates making up the polyline depending on tolerance. Match raw GPS points to the map so they aligns with the roads/pathways. Send and share a map snapshot image. diff --git a/MapboxAndroidDemo/src/main/res/values/titles_strings.xml b/MapboxAndroidDemo/src/main/res/values/titles_strings.xml index 238caf1ea..a35ad0328 100644 --- a/MapboxAndroidDemo/src/main/res/values/titles_strings.xml +++ b/MapboxAndroidDemo/src/main/res/values/titles_strings.xml @@ -58,6 +58,7 @@ Display real-time traffic Display buildings in 3D Show a user\'s location + Change map text to device language Load GeoJSON data Location search Add marker clusters diff --git a/MapboxAndroidDemo/src/main/res/values/urls_strings.xml b/MapboxAndroidDemo/src/main/res/values/urls_strings.xml index 6ca29d7a0..cb225aae0 100644 --- a/MapboxAndroidDemo/src/main/res/values/urls_strings.xml +++ b/MapboxAndroidDemo/src/main/res/values/urls_strings.xml @@ -64,6 +64,7 @@ https://i.imgur.com/oKHx3bv.png http://i.imgur.com/kju0sKw.jpg https://i.imgur.com/P6wsuea.jpg + https://i.imgur.com/vi3D3qf.png http://i.imgur.com/uATgul1.png http://i.imgur.com/bWvVbwC.png https://i.imgur.com/OiveDFG.png diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 9afd52f15..fb05fd650 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -8,7 +8,7 @@ ext { ] version = [ - // mapbox + // Mapbox mapboxMapSdk : '5.5.0', mapboxTurf : '3.0.0-beta.3', mapboGeoJson : '3.0.0-beta.3', @@ -19,11 +19,11 @@ ext { mapboxPluginTraffic : '0.4.0-SNAPSHOT', mapboxPluginMarkerCluster: '0.1.0', mapboxPluginPlaces : '0.2.1', + mapboxPluginLocalization : '0.1.0', // Support supportLib : '26.1.0', constraintLayout : '1.0.2', - firebase : '11.0.4', // Square @@ -33,7 +33,7 @@ ext { picasso : '2.5.2', retrofit : '2.2.0', - //other + // Other gson : '2.8', segmentAnalytics : '2.0.0' ] @@ -51,19 +51,21 @@ ext { ] dependenciesList = [ - // mapbox + // Mapbox mapboxMapSdk : "com.mapbox.mapboxsdk:mapbox-android-sdk:${version.mapboxMapSdk}", mapboxTurf : "com.mapbox.mapboxsdk:mapbox-sdk-turf:${version.mapboxTurf}", mapboGeoJson : "com.mapbox.mapboxsdk:mapbox-sdk-geojson:${version.mapboGeoJson}", + // Mapbox plugins mapboxPluginLocationLayer: "com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:${version.mapboxPluginLocationLayer}", mapboxPluginBuilding : "com.mapbox.mapboxsdk:mapbox-android-plugin-building:${version.mapboxPluginBuilding}", mapboxPluginTraffic : "com.mapbox.mapboxsdk:mapbox-android-plugin-traffic:${version.mapboxPluginTraffic}", mapboxPluginGeoJson : "com.mapbox.mapboxsdk:mapbox-android-plugin-geojson:${version.mapboxPluginGeoJson}", mapboxPluginMarkerCluster: "com.mapbox.mapboxsdk:mapbox-android-plugin-cluster-utils:${version.mapboxPluginMarkerCluster}", mapboxPluginPlaces : "com.mapbox.mapboxsdk:mapbox-android-plugin-places:${version.mapboxPluginPlaces}", + mapboxPluginLocalization : "com.mapbox.mapboxsdk:mapbox-android-plugin-localization:${version.mapboxPluginLocalization}", - // support + // Support supportV4 : "com.android.support:support-v4:${version.supportLib}", supportAppcompatV7 : "com.android.support:appcompat-v7:${version.supportLib}", supportDesign : "com.android.support:design:${version.supportLib}", @@ -74,7 +76,7 @@ ext { supportConstraintLayout : "com.android.support.constraint:constraint-layout:${version.constraintLayout}", supportAnnotations : "com.android.support:support-annotations:${version.supportLib}", - // square crew + // Square timber : "com.jakewharton.timber:timber:${version.timber}", okhttp3 : "com.squareup.okhttp3:okhttp:${version.okthttp3}", picasso : "com.squareup.picasso:picasso:${version.picasso}", @@ -83,7 +85,7 @@ ext { leakCanaryDebug : "com.squareup.leakcanary:leakcanary-android:${version.leakCanary}", leakCanaryRelease : "com.squareup.leakcanary:leakcanary-android-no-op:${version.leakCanary}", - // firebase + // Firebase firebaseCrash : "com.google.firebase:firebase-crash:${version.firebase}", firebasePerf : "com.google.firebase:firebase-perf:${version.firebase}",