Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add map type selector #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,9 +34,12 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -161,6 +164,8 @@ public class MapFragment extends BaseFragment implements OnMapReadyCallback, Map
private ArrayList<FavoriteItem> favList;
private CompositePermissionListener locationPermissionListener;
private MultiplePermissionsListener cameraPermissionListener;
protected List mapTypeValuesList;
private Spinner mapTypeSpinner;

private Location userLocation;
LocationListener locationListener = new LocationListener() {
Expand Down Expand Up @@ -310,9 +315,42 @@ private void setUpClusterer() {
map.setOnMarkerClickListener(clusterManager);
}

private void setUpMapTypeMenu(final GoogleMap googleMap) {
mapTypeSpinner = (Spinner) getActivity().findViewById(R.id.mapTypeSpinner);
String[] mapTypeValues = getContext().getResources().getStringArray(R.array.map_type_values);
mapTypeValuesList = Arrays.asList(mapTypeValues);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
getContext(),
android.R.layout.simple_spinner_dropdown_item,
mapTypeValuesList);
mapTypeSpinner.setAdapter(arrayAdapter);

mapTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
switch (position) {
case 0:
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
break;
case 1:
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
break;
case 2:
googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
break;
}
}

@Override
public void onNothingSelected(AdapterView<?> parent) {}
});
}

@Override
public void onMapReady(GoogleMap googleMap) {
this.map = googleMap;
setUpMapTypeMenu(this.map);
map.setInfoWindowAdapter(new BubbleAdapter(getActivity()));
map.setOnInfoWindowClickListener(this);
map.getUiSettings().setMapToolbarEnabled(false);
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/res/layout/fragment_map.xml
Expand Up @@ -125,4 +125,15 @@
android:layout_height="wrap_content"
android:visibility="gone"/>

</RelativeLayout>
<Spinner
android:id="@+id/mapTypeSpinner"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:background="@drawable/button_map"
android:spinnerMode="dropdown"
android:layout_alignTop="@+id/reloadButton"
android:layout_toRightOf="@+id/reloadButton"
android:layout_toEndOf="@+id/reloadButton"
android:elevation="6dp"/>

</RelativeLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/values-es/arrays.xml
Expand Up @@ -21,4 +21,9 @@
<item>Bicis</item>
<item>No Activas</item>
</string-array>
<string-array name="map_type_values">
<item>Normal</item>
<item>Híbrido</item>
<item>Terreno</item>
</string-array>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/arrays.xml
Expand Up @@ -21,4 +21,9 @@
<item>Bikes</item>
<item>Not Active</item>
</string-array>
<string-array name="map_type_values">
<item>Normal</item>
<item>Hybrid</item>
<item>Terrain</item>
</string-array>
</resources>