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

Commit 462b3d3

Browse files
committed
[android] - add style inspecatable in debug mode activity
1 parent 830bf15 commit 462b3d3

File tree

3 files changed

+231
-60
lines changed

3 files changed

+231
-60
lines changed

platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml

+3-5
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,12 @@
305305
</activity>
306306
<activity
307307
android:name=".activity.maplayout.DebugModeActivity"
308+
android:configChanges="orientation|keyboardHidden|screenSize"
308309
android:description="@string/description_debug_mode"
309310
android:label="@string/activity_debug_mode">
310311
<meta-data
311312
android:name="@string/category"
312-
android:value="@string/category_maplayout"/>
313-
<meta-data
314-
android:name="android.support.PARENT_ACTIVITY"
315-
android:value=".activity.FeatureOverviewActivity"/>
313+
android:value="@string/category_basic"/>
316314
</activity>
317315
<activity
318316
android:name=".activity.offline.OfflineActivity"
@@ -717,4 +715,4 @@
717715
<!-- android:value="true" /> -->
718716
</application>
719717

720-
</manifest>
718+
</manifest>

platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.java

+152-17
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
11
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
22

3+
import android.content.Context;
34
import android.os.Bundle;
4-
import android.support.annotation.NonNull;
55
import android.support.design.widget.FloatingActionButton;
6+
import android.support.v4.widget.DrawerLayout;
7+
import android.support.v7.app.ActionBar;
8+
import android.support.v7.app.ActionBarDrawerToggle;
69
import android.support.v7.app.AppCompatActivity;
10+
import android.view.LayoutInflater;
11+
import android.view.MenuItem;
712
import android.view.View;
13+
import android.view.ViewGroup;
14+
import android.widget.AdapterView;
15+
import android.widget.BaseAdapter;
16+
import android.widget.ListView;
817
import android.widget.TextView;
918

1019
import com.mapbox.mapboxsdk.camera.CameraPosition;
1120
import com.mapbox.mapboxsdk.constants.Style;
1221
import com.mapbox.mapboxsdk.maps.MapView;
1322
import com.mapbox.mapboxsdk.maps.MapboxMap;
1423
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
24+
import com.mapbox.mapboxsdk.style.layers.Layer;
25+
import com.mapbox.mapboxsdk.style.layers.Property;
1526
import com.mapbox.mapboxsdk.testapp.R;
1627

28+
import java.util.List;
29+
1730
import timber.log.Timber;
1831

32+
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
33+
1934
/**
2035
* Test Activity showcasing the different debug modes and allows to cycle between the default map styles.
2136
*/
22-
public class DebugModeActivity extends AppCompatActivity {
37+
public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCallback {
2338

2439
private MapView mapView;
2540
private MapboxMap mapboxMap;
26-
41+
private ActionBarDrawerToggle actionBarDrawerToggle;
2742
private int currentStyleIndex = 0;
2843

2944
private static final String[] STYLES = new String[] {
@@ -32,45 +47,104 @@ public class DebugModeActivity extends AppCompatActivity {
3247
Style.LIGHT,
3348
Style.DARK,
3449
Style.SATELLITE,
35-
Style.SATELLITE_STREETS
50+
Style.SATELLITE_STREETS,
51+
Style.TRAFFIC_DAY,
52+
Style.TRAFFIC_NIGHT
3653
};
3754

3855
@Override
3956
protected void onCreate(Bundle savedInstanceState) {
4057
super.onCreate(savedInstanceState);
4158
setContentView(R.layout.activity_debug_mode);
59+
setupToolbar();
60+
setupMapView(savedInstanceState);
61+
setupDebugChangeView();
62+
setupStyleChangeView();
63+
}
64+
65+
private void setupToolbar() {
66+
ActionBar actionBar = getSupportActionBar();
67+
if (actionBar != null) {
68+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
69+
getSupportActionBar().setHomeButtonEnabled(true);
4270

71+
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
72+
actionBarDrawerToggle = new ActionBarDrawerToggle(this,
73+
drawerLayout,
74+
R.string.navigation_drawer_open,
75+
R.string.navigation_drawer_close
76+
);
77+
actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
78+
actionBarDrawerToggle.syncState();
79+
}
80+
}
81+
82+
private void setupMapView(Bundle savedInstanceState) {
4383
mapView = (MapView) findViewById(R.id.mapView);
4484
mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
4585
@Override
4686
public void onMapChanged(int change) {
4787
if (change == MapView.DID_FINISH_LOADING_STYLE && mapboxMap != null) {
48-
Timber.e("New loaded style = %s", mapboxMap.getStyleJson());
88+
Timber.v("New style loaded with JSON: %s", mapboxMap.getStyleJson());
89+
setupNavigationView(mapboxMap.getLayers());
4990
}
5091
}
5192
});
5293

5394
mapView.setTag(true);
5495
mapView.setStyleUrl(STYLES[currentStyleIndex]);
5596
mapView.onCreate(savedInstanceState);
56-
mapView.getMapAsync(new OnMapReadyCallback() {
97+
mapView.getMapAsync(this);
98+
}
99+
100+
@Override
101+
public void onMapReady(MapboxMap map) {
102+
mapboxMap = map;
103+
mapboxMap.getUiSettings().setZoomControlsEnabled(true);
104+
105+
setupNavigationView(mapboxMap.getLayers());
106+
setupZoomView();
107+
}
108+
109+
private void setupNavigationView(List<Layer> layerList) {
110+
final LayerListAdapter adapter = new LayerListAdapter(this, layerList);
111+
ListView listView = (ListView) findViewById(R.id.listView);
112+
listView.setAdapter(adapter);
113+
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
57114
@Override
58-
public void onMapReady(@NonNull MapboxMap map) {
59-
mapboxMap = map;
115+
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
116+
Layer clickedLayer = adapter.getItem(position);
117+
toggleLayerVisibility(clickedLayer);
118+
closeNavigationView();
119+
}
120+
});
121+
}
60122

61-
mapboxMap.getUiSettings().setZoomControlsEnabled(true);
123+
private void toggleLayerVisibility(Layer layer) {
124+
boolean isVisible = layer.getVisibility().getValue().equals(Property.VISIBLE);
125+
layer.setProperties(
126+
visibility(
127+
isVisible ? Property.NONE : Property.VISIBLE
128+
)
129+
);
130+
}
62131

63-
// show current zoom level on screen
64-
final TextView textView = (TextView) findViewById(R.id.textZoom);
65-
mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
66-
@Override
67-
public void onCameraChange(CameraPosition position) {
68-
textView.setText(String.format(getString(R.string.debug_zoom), position.zoom));
69-
}
70-
});
132+
private void closeNavigationView() {
133+
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
134+
drawerLayout.closeDrawers();
135+
}
136+
137+
private void setupZoomView() {
138+
final TextView textView = (TextView) findViewById(R.id.textZoom);
139+
mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
140+
@Override
141+
public void onCameraChange(CameraPosition position) {
142+
textView.setText(String.format(getString(R.string.debug_zoom), position.zoom));
71143
}
72144
});
145+
}
73146

147+
private void setupDebugChangeView() {
74148
FloatingActionButton fabDebug = (FloatingActionButton) findViewById(R.id.fabDebug);
75149
fabDebug.setOnClickListener(new View.OnClickListener() {
76150
@Override
@@ -81,7 +155,9 @@ public void onClick(View view) {
81155
}
82156
}
83157
});
158+
}
84159

160+
private void setupStyleChangeView() {
85161
FloatingActionButton fabStyles = (FloatingActionButton) findViewById(R.id.fabStyles);
86162
fabStyles.setOnClickListener(new View.OnClickListener() {
87163
@Override
@@ -102,6 +178,11 @@ public void onStyleLoaded(String style) {
102178
});
103179
}
104180

181+
@Override
182+
public boolean onOptionsItemSelected(MenuItem item) {
183+
return actionBarDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
184+
}
185+
105186
@Override
106187
protected void onStart() {
107188
super.onStart();
@@ -143,4 +224,58 @@ public void onLowMemory() {
143224
super.onLowMemory();
144225
mapView.onLowMemory();
145226
}
227+
228+
private static class LayerListAdapter extends BaseAdapter {
229+
230+
private LayoutInflater layoutInflater;
231+
private List<Layer> layers;
232+
233+
LayerListAdapter(Context context, List<Layer> layers) {
234+
this.layoutInflater = LayoutInflater.from(context);
235+
this.layers = layers;
236+
}
237+
238+
@Override
239+
public int getCount() {
240+
return layers.size();
241+
}
242+
243+
@Override
244+
public Layer getItem(int position) {
245+
return layers.get(position);
246+
}
247+
248+
@Override
249+
public long getItemId(int position) {
250+
return position;
251+
}
252+
253+
@Override
254+
public View getView(int position, View convertView, ViewGroup parent) {
255+
Layer layer = layers.get(position);
256+
View view = convertView;
257+
if (view == null) {
258+
view = layoutInflater.inflate(android.R.layout.simple_list_item_2, parent, false);
259+
ViewHolder holder = new ViewHolder(
260+
(TextView) view.findViewById(android.R.id.text1),
261+
(TextView) view.findViewById(android.R.id.text2)
262+
);
263+
view.setTag(holder);
264+
}
265+
ViewHolder holder = (ViewHolder) view.getTag();
266+
holder.text.setText(layer.getClass().getSimpleName());
267+
holder.subText.setText(layer.getId());
268+
return view;
269+
}
270+
271+
private static class ViewHolder {
272+
final TextView text;
273+
final TextView subText;
274+
275+
ViewHolder(TextView text, TextView subText) {
276+
this.text = text;
277+
this.subText = subText;
278+
}
279+
}
280+
}
146281
}
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,86 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.design.widget.CoordinatorLayout
2+
<android.support.v4.widget.DrawerLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
4-
xmlns:app="http://schemas.android.com/apk/res-auto"
5-
android:id="@+id/coordinator_layout"
4+
android:id="@+id/drawer_layout"
65
android:layout_width="match_parent"
76
android:layout_height="match_parent"
8-
android:orientation="vertical">
7+
android:clickable="true"
8+
android:focusable="true"
9+
android:focusableInTouchMode="true">
910

10-
<com.mapbox.mapboxsdk.maps.MapView
11-
android:id="@+id/mapView"
11+
<android.support.design.widget.CoordinatorLayout
12+
xmlns:android="http://schemas.android.com/apk/res/android"
13+
xmlns:app="http://schemas.android.com/apk/res-auto"
14+
android:id="@+id/coordinator_layout"
1215
android:layout_width="match_parent"
1316
android:layout_height="match_parent"
14-
app:mapbox_uiAttribution="false"
15-
app:mapbox_uiCompass="false"
16-
app:mapbox_uiLogo="false"/>
17+
android:orientation="vertical">
1718

18-
<TextView
19-
android:id="@+id/textZoom"
20-
android:layout_width="wrap_content"
21-
android:layout_height="wrap_content"
22-
android:layout_gravity="bottom|start"
23-
android:layout_margin="8dp"
24-
android:textIsSelectable="false"
25-
android:textSize="14sp"/>
26-
27-
<android.support.design.widget.FloatingActionButton
28-
android:id="@+id/fabDebug"
29-
android:layout_width="wrap_content"
30-
android:layout_height="wrap_content"
31-
android:layout_gravity="end|bottom"
32-
android:layout_marginBottom="82dp"
33-
android:layout_marginEnd="@dimen/fab_margin"
34-
android:layout_marginRight="@dimen/fab_margin"
35-
android:src="@drawable/ic_refresh"
36-
app:backgroundTint="@color/accent"
37-
app:layout_anchorGravity="top"/>
38-
39-
<android.support.design.widget.FloatingActionButton
40-
android:id="@+id/fabStyles"
19+
<com.mapbox.mapboxsdk.maps.MapView
20+
android:id="@+id/mapView"
21+
android:layout_width="match_parent"
22+
android:layout_height="match_parent"
23+
app:mapbox_uiAttribution="false"
24+
app:mapbox_uiCompass="false"
25+
app:mapbox_uiLogo="false"/>
26+
27+
<TextView
28+
android:id="@+id/textZoom"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:layout_gravity="bottom|start"
32+
android:layout_margin="8dp"
33+
android:textIsSelectable="true"
34+
android:textSize="14sp"
35+
app:layout_anchor="@id/bottom_sheet"
36+
app:layout_anchorGravity="bottom|start"/>
37+
38+
<android.support.v4.widget.NestedScrollView
39+
android:id="@+id/bottom_sheet"
40+
android:layout_width="match_parent"
41+
android:layout_height="250dp"
42+
android:background="@color/white"
43+
android:visibility="invisible"
44+
app:behavior_hideable="true"
45+
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"/>
46+
47+
<android.support.design.widget.FloatingActionButton
48+
android:id="@+id/fabDebug"
49+
android:layout_width="wrap_content"
50+
android:layout_height="wrap_content"
51+
android:layout_gravity="top|end"
52+
android:layout_marginBottom="82dp"
53+
android:layout_marginEnd="@dimen/fab_margin"
54+
android:layout_marginRight="@dimen/fab_margin"
55+
android:src="@drawable/ic_refresh"
56+
app:backgroundTint="@color/accent"
57+
app:layout_anchor="@+id/fabStyles"
58+
app:layout_anchorGravity="top"/>
59+
60+
<android.support.design.widget.FloatingActionButton
61+
android:id="@id/fabStyles"
62+
android:layout_width="wrap_content"
63+
android:layout_height="wrap_content"
64+
android:layout_gravity="end|bottom"
65+
android:layout_margin="@dimen/fab_margin"
66+
android:src="@drawable/ic_layers"
67+
app:backgroundTint="@color/primary"
68+
app:layout_anchor="@id/bottom_sheet"
69+
app:layout_anchorGravity="bottom|end"/>
70+
71+
</android.support.design.widget.CoordinatorLayout>
72+
73+
<android.support.design.widget.NavigationView
4174
android:layout_width="wrap_content"
42-
android:layout_height="wrap_content"
43-
android:layout_gravity="end|bottom"
44-
android:layout_margin="@dimen/fab_margin"
45-
android:src="@drawable/ic_layers"
46-
app:backgroundTint="@color/primary"/>
75+
android:layout_height="match_parent"
76+
android:layout_gravity="start"
77+
android:background="@android:color/white">
78+
79+
<ListView
80+
android:id="@+id/listView"
81+
android:layout_width="match_parent"
82+
android:layout_height="match_parent"/>
83+
84+
</android.support.design.widget.NavigationView>
4785

48-
</android.support.design.widget.CoordinatorLayout>
86+
</android.support.v4.widget.DrawerLayout>

0 commit comments

Comments
 (0)