-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic map localization support added
- Loading branch information
Cameron Mace
committed
Feb 21, 2018
1 parent
4cb4a74
commit a65da9c
Showing
20 changed files
with
1,030 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/LocalizationActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package com.mapbox.mapboxsdk.plugins.testapp.activity; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.widget.Toast; | ||
|
||
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; | ||
import com.mapbox.mapboxsdk.plugins.testapp.R; | ||
import com.mapbox.mapboxsdk.plugins.testapp.Utils; | ||
|
||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
import butterknife.OnClick; | ||
|
||
public class LocalizationActivity extends AppCompatActivity implements OnMapReadyCallback { | ||
|
||
@BindView(R.id.mapView) | ||
MapView mapView; | ||
|
||
private LocalizationPlugin localizationPlugin; | ||
private MapboxMap mapboxMap; | ||
private boolean mapIsLocalized; | ||
|
||
private static final MapLocale[] LOCALES = new MapLocale[] { | ||
MapLocale.CANADA, | ||
MapLocale.GERMANY, | ||
MapLocale.CHINA, | ||
MapLocale.US, | ||
MapLocale.CANADA_FRENCH, | ||
MapLocale.ITALY, | ||
MapLocale.JAPAN, | ||
MapLocale.KOREA, | ||
MapLocale.FRANCE | ||
}; | ||
|
||
private static int index; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_localization); | ||
ButterKnife.bind(this); | ||
mapIsLocalized = true; | ||
Toast.makeText(this, R.string.change_language_instruction, Toast.LENGTH_LONG).show(); | ||
mapView.onCreate(savedInstanceState); | ||
mapView.getMapAsync(this); | ||
} | ||
|
||
@Override | ||
public void onMapReady(MapboxMap mapboxMap) { | ||
this.mapboxMap = mapboxMap; | ||
localizationPlugin = new LocalizationPlugin(mapView, mapboxMap); | ||
localizationPlugin.matchMapLanguageWithDeviceDefault(); | ||
} | ||
|
||
@OnClick(R.id.localize_fab) | ||
public void localizeToggleFab() { | ||
if (mapIsLocalized) { | ||
localizationPlugin.setMapLanguage(new MapLocale(MapLocale.FRENCH)); | ||
Toast.makeText(this, R.string.map_not_localized, Toast.LENGTH_SHORT).show(); | ||
mapIsLocalized = false; | ||
} else { | ||
localizationPlugin.matchMapLanguageWithDeviceDefault(); | ||
Toast.makeText(this, R.string.map_localized, Toast.LENGTH_SHORT).show(); | ||
mapIsLocalized = true; | ||
} | ||
} | ||
|
||
@OnClick(R.id.camera_localization) | ||
public void localizeCameraFab() { | ||
MapLocale locale = getNextMapLocale(); | ||
localizationPlugin.setMapLanguage(locale); | ||
localizationPlugin.setCameraToLocaleCountry(locale); | ||
} | ||
|
||
@OnClick(R.id.change_map_style) | ||
public void changeMapStyleFab() { | ||
if (mapboxMap != null) { | ||
mapboxMap.setStyleUrl(Utils.getNextStyle()); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
mapView.onStart(); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
mapView.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
mapView.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
mapView.onStop(); | ||
} | ||
|
||
@Override | ||
protected void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
mapView.onSaveInstanceState(outState); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
mapView.onDestroy(); | ||
} | ||
|
||
@Override | ||
public void onLowMemory() { | ||
super.onLowMemory(); | ||
mapView.onLowMemory(); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.menu_languages, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
switch (item.getItemId()) { | ||
case R.id.english: | ||
localizationPlugin.setMapLanguage(MapLocale.ENGLISH); | ||
return true; | ||
case R.id.spanish: | ||
localizationPlugin.setMapLanguage(MapLocale.SPANISH); | ||
return true; | ||
case R.id.french: | ||
localizationPlugin.setMapLanguage(MapLocale.FRENCH); | ||
return true; | ||
case R.id.german: | ||
localizationPlugin.setMapLanguage(MapLocale.GERMAN); | ||
return true; | ||
case R.id.russian: | ||
localizationPlugin.setMapLanguage(MapLocale.RUSSIAN); | ||
return true; | ||
case R.id.chinese: | ||
localizationPlugin.setMapLanguage(MapLocale.CHINESE); | ||
return true; | ||
case R.id.simplified_chinese: | ||
localizationPlugin.setMapLanguage(MapLocale.SIMPLIFIED_CHINESE); | ||
return true; | ||
case R.id.portuguese: | ||
localizationPlugin.setMapLanguage(MapLocale.PORTUGUESE); | ||
return true; | ||
case R.id.arabic: | ||
localizationPlugin.setMapLanguage(MapLocale.ARABIC); | ||
return true; | ||
case android.R.id.home: | ||
finish(); | ||
return true; | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
public static MapLocale getNextMapLocale() { | ||
index++; | ||
if (index == LOCALES.length) { | ||
index = 0; | ||
} | ||
return LOCALES[index]; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:pathData="M12.87,15.07l-2.54,-2.51 0.03,-0.03c1.74,-1.94 2.98,-4.17 3.71,-6.53L17,6L17,4h-7L10,2L8,2v2L1,4v1.99h11.17C11.5,7.92 10.44,9.75 9,11.35 8.07,10.32 7.3,9.19 6.69,8h-2c0.73,1.63 1.73,3.17 2.98,4.56l-5.09,5.02L4,19l5,-5 3.11,3.11 0.76,-2.04zM18.5,10h-2L12,22h2l1.12,-3h4.75L21,22h2l-4.5,-12zM15.88,17l1.62,-4.33L19.12,17h-3.24z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<com.mapbox.mapboxsdk.maps.MapView | ||
android:id="@+id/mapView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:mapbox_cameraTargetLat="51.505300" | ||
app:mapbox_cameraTargetLng="-0.075073" | ||
app:mapbox_cameraTilt="20" | ||
app:mapbox_cameraZoom="2.5" | ||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"> | ||
|
||
</com.mapbox.mapboxsdk.maps.MapView> | ||
|
||
<android.support.design.widget.FloatingActionButton | ||
android:id="@+id/localize_fab" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="16dp" | ||
android:layout_marginEnd="16dp" | ||
android:layout_marginRight="16dp" | ||
android:src="@drawable/ic_translate_white_24dp" | ||
app:backgroundTint="@color/colorPrimary" | ||
app:fabSize="normal" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent"/> | ||
|
||
<android.support.design.widget.FloatingActionButton | ||
android:id="@+id/change_map_style" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="8dp" | ||
android:layout_marginEnd="16dp" | ||
android:layout_marginRight="16dp" | ||
android:src="@drawable/ic_layers" | ||
android:tint="@android:color/white" | ||
app:backgroundTint="@color/colorAccent" | ||
app:fabSize="normal" | ||
app:layout_constraintBottom_toTopOf="@+id/camera_localization" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintRight_toRightOf="parent"/> | ||
|
||
<android.support.design.widget.FloatingActionButton | ||
android:id="@+id/camera_localization" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="8dp" | ||
android:layout_marginEnd="16dp" | ||
android:layout_marginRight="16dp" | ||
android:src="@drawable/ic_camera" | ||
android:tint="@android:color/white" | ||
app:backgroundTint="@color/colorAccent" | ||
app:fabSize="normal" | ||
app:layout_constraintBottom_toTopOf="@+id/localize_fab" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintRight_toRightOf="parent"/> | ||
|
||
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<item | ||
android:id="@+id/english" | ||
android:title="English" | ||
app:showAsAction="never"/> | ||
|
||
<item | ||
android:id="@+id/spanish" | ||
android:title="Spanish" | ||
app:showAsAction="never"/> | ||
|
||
<item | ||
android:id="@+id/french" | ||
android:title="French" | ||
app:showAsAction="never"/> | ||
|
||
<item | ||
android:id="@+id/german" | ||
android:title="German" | ||
app:showAsAction="never"/> | ||
|
||
<item | ||
android:id="@+id/russian" | ||
android:title="Russian" | ||
app:showAsAction="never"/> | ||
|
||
<item | ||
android:id="@+id/chinese" | ||
android:title="Chinese" | ||
app:showAsAction="never"/> | ||
|
||
<item | ||
android:id="@+id/simplified_chinese" | ||
android:title="Simplified Chinese" | ||
app:showAsAction="never"/> | ||
|
||
|
||
<item | ||
android:id="@+id/portuguese" | ||
android:title="Portuguese" | ||
app:showAsAction="never"/> | ||
|
||
<item | ||
android:id="@+id/arabic" | ||
android:title="Arabic" | ||
app:showAsAction="never"/> | ||
|
||
|
||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.