[android] - remove deprecation notices and code

This commit is contained in:
Tobrun
2018-10-31 15:50:11 +01:00
committed by Tobrun
parent 37a4967149
commit 7882ce1274
21 changed files with 234 additions and 681 deletions

View File

@@ -50,6 +50,15 @@ public class CameraAnimationTypeActivity extends AppCompatActivity implements On
private MapView mapView;
private boolean cameraState;
private MapboxMap.OnCameraIdleListener cameraIdleListener = new MapboxMap.OnCameraIdleListener() {
@Override
public void onCameraIdle() {
if (mapboxMap != null) {
Timber.w(mapboxMap.getCameraPosition().toString());
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -66,7 +75,7 @@ public class CameraAnimationTypeActivity extends AppCompatActivity implements On
mapboxMap = map;
mapboxMap.getUiSettings().setAttributionEnabled(false);
mapboxMap.getUiSettings().setLogoEnabled(false);
mapboxMap.setOnCameraChangeListener(position -> Timber.w(position.toString()));
mapboxMap.addOnCameraIdleListener(cameraIdleListener);
// handle move button clicks
View moveButton = findViewById(R.id.cameraMoveButton);
@@ -149,6 +158,9 @@ public class CameraAnimationTypeActivity extends AppCompatActivity implements On
@Override
protected void onDestroy() {
super.onDestroy();
if (mapboxMap != null) {
mapboxMap.removeOnCameraIdleListener(cameraIdleListener);
}
mapView.onDestroy();
}

View File

@@ -60,7 +60,7 @@ public class CameraPositionActivity extends FragmentActivity implements OnMapRea
fab.setOnClickListener(this);
// listen to long click events to toggle logging camera changes
mapboxMap.setOnMapLongClickListener(this);
mapboxMap.addOnMapLongClickListener(this);
}
@Override
@@ -124,6 +124,9 @@ public class CameraPositionActivity extends FragmentActivity implements OnMapRea
@Override
protected void onDestroy() {
super.onDestroy();
if (mapboxMap != null) {
mapboxMap.removeOnMapLongClickListener(this);
}
mapView.onDestroy();
}

View File

@@ -1,9 +1,11 @@
package com.mapbox.mapboxsdk.testapp.activity.camera;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
@@ -19,13 +21,22 @@ public class MaxMinZoomActivity extends AppCompatActivity implements OnMapReadyC
private MapView mapView;
private MapboxMap mapboxMap;
@Override
private MapboxMap.OnMapClickListener clickListener = new MapboxMap.OnMapClickListener() {
@Override
public boolean onMapClick(@NonNull LatLng point) {
if (mapboxMap != null) {
mapboxMap.setStyle(Style.OUTDOORS, style -> Timber.d("Style Loaded %s", style));
}
return true;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maxmin_zoom);
mapView = (MapView) findViewById(R.id.mapView);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
@@ -35,10 +46,7 @@ public class MaxMinZoomActivity extends AppCompatActivity implements OnMapReadyC
mapboxMap = map;
mapboxMap.setMinZoomPreference(3);
mapboxMap.setMaxZoomPreference(5);
mapboxMap.setOnMapClickListener(point -> {
map.setStyle(Style.OUTDOORS, style -> Timber.d("Style Loaded %s", style));
return false;
});
mapboxMap.addOnMapClickListener(clickListener);
}
@Override
@@ -74,6 +82,9 @@ public class MaxMinZoomActivity extends AppCompatActivity implements OnMapReadyC
@Override
protected void onDestroy() {
super.onDestroy();
if (mapboxMap != null) {
mapboxMap.removeOnMapClickListener(clickListener);
}
mapView.onDestroy();
}

View File

@@ -15,6 +15,7 @@ import com.google.gson.JsonElement;
import com.mapbox.geojson.Feature;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
@@ -34,12 +35,37 @@ public class QueryRenderedFeaturesPropertiesActivity extends AppCompatActivity {
private MapboxMap mapboxMap;
private Marker marker;
private MapboxMap.OnMapClickListener mapClickListener = new MapboxMap.OnMapClickListener() {
@Override
public boolean onMapClick(@NonNull LatLng point) {
final float density = getResources().getDisplayMetrics().density;
final PointF pixel = mapboxMap.getProjection().toScreenLocation(point);
Timber.i(
"Requesting features for %sx%s (%sx%s adjusted for density)",
pixel.x, pixel.y, pixel.x / density, pixel.y / density
);
List<Feature> features = mapboxMap.queryRenderedFeatures(pixel);
// Debug output
debugOutput(features);
// Remove any previous markers
if (marker != null) {
mapboxMap.removeMarker(marker);
}
// Add a marker on the clicked point
marker = mapboxMap.addMarker(new CustomMarkerOptions().position(point).features(features));
mapboxMap.selectMarker(marker);
return true;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_query_features_point);
final float density = getResources().getDisplayMetrics().density;
// Initialize map as normal
mapView = (MapView) findViewById(R.id.mapView);
@@ -51,31 +77,8 @@ public class QueryRenderedFeaturesPropertiesActivity extends AppCompatActivity {
addCustomInfoWindowAdapter(mapboxMap);
// Add a click listener
mapboxMap.setOnMapClickListener(point -> {
// Query
final PointF pixel = mapboxMap.getProjection().toScreenLocation(point);
Timber.i(
"Requesting features for %sx%s (%sx%s adjusted for density)",
pixel.x, pixel.y, pixel.x / density, pixel.y / density
);
List<Feature> features = mapboxMap.queryRenderedFeatures(pixel);
// Debug output
debugOutput(features);
// Remove any previous markers
if (marker != null) {
mapboxMap.removeMarker(marker);
}
// Add a marker on the clicked point
marker = mapboxMap.addMarker(new CustomMarkerOptions().position(point).features(features));
mapboxMap.selectMarker(marker);
return false;
});
mapboxMap.addOnMapClickListener(mapClickListener);
});
}
private void debugOutput(List<Feature> features) {
@@ -166,6 +169,9 @@ public class QueryRenderedFeaturesPropertiesActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
super.onDestroy();
if (mapboxMap != null) {
mapboxMap.removeOnMapClickListener(mapClickListener);
}
mapView.onDestroy();
}

View File

@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp.activity.infowindow;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
@@ -28,13 +29,39 @@ public class DynamicInfoWindowAdapterActivity extends AppCompatActivity implemen
private MapboxMap mapboxMap;
private MapView mapView;
private MarkerView marker;
private MapboxMap.OnMapClickListener mapClickListener = new MapboxMap.OnMapClickListener() {
@Override
public boolean onMapClick(@NonNull LatLng point) {
if (marker == null) {
return false;
}
// Distance from click to marker
double distanceKm = marker.getPosition().distanceTo(point) / 1000;
// Get the info window
final InfoWindow infoWindow = marker.getInfoWindow();
// Get the view from the info window
if (infoWindow != null && infoWindow.getView() != null) {
// Set the new text on the text view in the info window
TextView textView = (TextView) infoWindow.getView();
textView.setText(String.format(Locale.getDefault(), "%.2fkm", distanceKm));
// Update the info window position (as the text length changes)
textView.post(infoWindow::update);
}
return true;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_infowindow_adapter);
mapView = (MapView) findViewById(R.id.mapView);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
@@ -50,30 +77,11 @@ public class DynamicInfoWindowAdapterActivity extends AppCompatActivity implemen
mapboxMap.getUiSettings().setDeselectMarkersOnTap(false);
// Add a marker
final MarkerView marker = addMarker(mapboxMap);
marker = addMarker(mapboxMap);
mapboxMap.selectMarker(marker);
// On map click, change the info window contents
mapboxMap.setOnMapClickListener(point -> {
// Distance from click to marker
double distanceKm = marker.getPosition().distanceTo(point) / 1000;
// Get the info window
final InfoWindow infoWindow = marker.getInfoWindow();
// Get the view from the info window
if (infoWindow != null && infoWindow.getView() != null) {
// Set the new text on the text view in the info window
TextView textView = (TextView) infoWindow.getView();
textView.setText(String.format(Locale.getDefault(), "%.2fkm", distanceKm));
textView.post(() -> {
// Update the info window position (as the text length changes)
infoWindow.update();
});
}
return false;
});
mapboxMap.addOnMapClickListener(mapClickListener);
// Focus on Paris
mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(PARIS));
@@ -133,6 +141,9 @@ public class DynamicInfoWindowAdapterActivity extends AppCompatActivity implemen
@Override
protected void onDestroy() {
super.onDestroy();
if (mapboxMap != null) {
mapboxMap.removeOnMapClickListener(mapClickListener);
}
mapView.onDestroy();
}

View File

@@ -24,13 +24,32 @@ import java.text.DecimalFormat;
* </p>
*/
public class InfoWindowActivity extends AppCompatActivity
implements OnMapReadyCallback, MapboxMap.OnInfoWindowCloseListener, MapboxMap.OnMapLongClickListener,
MapboxMap.OnInfoWindowClickListener, MapboxMap.OnInfoWindowLongClickListener {
implements OnMapReadyCallback, MapboxMap.OnInfoWindowCloseListener, MapboxMap.OnInfoWindowClickListener,
MapboxMap.OnInfoWindowLongClickListener {
private MapboxMap mapboxMap;
private MapView mapView;
private Marker customMarker;
private MapboxMap.OnMapLongClickListener mapLongClickListener = new MapboxMap.OnMapLongClickListener() {
@Override
public boolean onMapLongClick(@NonNull LatLng point) {
if (customMarker != null) {
// Remove previous added marker
mapboxMap.removeAnnotation(customMarker);
customMarker = null;
}
// Add marker on long click location with default marker image
customMarker = mapboxMap.addMarker(new MarkerOptions()
.title("Custom Marker")
.snippet(new DecimalFormat("#.#####").format(point.getLatitude()) + ", "
+ new DecimalFormat("#.#####").format(point.getLongitude()))
.position(point));
return true;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -77,7 +96,7 @@ public class InfoWindowActivity extends AppCompatActivity
private void addInfoWindowListeners() {
mapboxMap.setOnInfoWindowCloseListener(this);
mapboxMap.setOnMapLongClickListener(this);
mapboxMap.addOnMapLongClickListener(mapLongClickListener);
mapboxMap.setOnInfoWindowClickListener(this);
mapboxMap.setOnInfoWindowLongClickListener(this);
}
@@ -108,24 +127,6 @@ public class InfoWindowActivity extends AppCompatActivity
Toast.makeText(getApplicationContext(), "OnLongClick: " + marker.getTitle(), Toast.LENGTH_LONG).show();
}
@Override
public boolean onMapLongClick(@NonNull LatLng point) {
if (customMarker != null) {
// Remove previous added marker
mapboxMap.removeAnnotation(customMarker);
customMarker = null;
}
// Add marker on long click location with default marker image
customMarker = mapboxMap.addMarker(new MarkerOptions()
.title("Custom Marker")
.snippet(new DecimalFormat("#.#####").format(point.getLatitude()) + ", "
+ new DecimalFormat("#.#####").format(point.getLongitude()))
.position(point));
return false;
}
@Override
protected void onStart() {
super.onStart();
@@ -159,6 +160,9 @@ public class InfoWindowActivity extends AppCompatActivity
@Override
protected void onDestroy() {
super.onDestroy();
if (mapboxMap != null) {
mapboxMap.removeOnMapLongClickListener(mapLongClickListener);
}
mapView.onDestroy();
}

View File

@@ -26,6 +26,7 @@ import com.mapbox.mapboxsdk.testapp.R;
import java.util.List;
import java.util.Locale;
import com.mapbox.mapboxsdk.testapp.utils.IdleZoomListener;
import timber.log.Timber;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
@@ -38,7 +39,8 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
private MapView mapView;
private MapboxMap mapboxMap;
private ActionBarDrawerToggle actionBarDrawerToggle;
private int currentStyleIndex = 0;
private int currentStyleIndex;
private IdleZoomListener idleZoomListener;
private static final String[] STYLES = new String[] {
Style.MAPBOX_STREETS,
@@ -66,8 +68,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
if (actionBar != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
actionBarDrawerToggle = new ActionBarDrawerToggle(this,
drawerLayout,
R.string.navigation_drawer_open,
@@ -79,7 +80,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
}
private void setupMapView(Bundle savedInstanceState) {
mapView = (MapView) findViewById(R.id.mapView);
mapView = findViewById(R.id.mapView);
mapView.addOnDidFinishLoadingStyleListener(() -> {
if (mapboxMap != null) {
@@ -105,7 +106,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
}
private void setFpsView() {
final TextView fpsView = (TextView) findViewById(R.id.fpsView);
final TextView fpsView = findViewById(R.id.fpsView);
mapboxMap.setOnFpsChangedListener(fps ->
fpsView.setText(String.format(Locale.US, "FPS: %4.2f", fps))
);
@@ -114,7 +115,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
private void setupNavigationView(List<Layer> layerList) {
Timber.v("New style loaded with JSON: %s", mapboxMap.getStyleJson());
final LayerListAdapter adapter = new LayerListAdapter(this, layerList);
ListView listView = (ListView) findViewById(R.id.listView);
ListView listView = findViewById(R.id.listView);
listView.setAdapter(adapter);
listView.setOnItemClickListener((parent, view, position, id) -> {
Layer clickedLayer = adapter.getItem(position);
@@ -133,19 +134,17 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
}
private void closeNavigationView() {
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
drawerLayout.closeDrawers();
}
private void setupZoomView() {
final TextView textView = (TextView) findViewById(R.id.textZoom);
mapboxMap.setOnCameraChangeListener(position ->
textView.setText(String.format(getString(R.string.debug_zoom), position.zoom))
);
final TextView textView = findViewById(R.id.textZoom);
mapboxMap.addOnCameraIdleListener(idleZoomListener = new IdleZoomListener(mapboxMap, textView));
}
private void setupDebugChangeView() {
FloatingActionButton fabDebug = (FloatingActionButton) findViewById(R.id.fabDebug);
FloatingActionButton fabDebug = findViewById(R.id.fabDebug);
fabDebug.setOnClickListener(view -> {
if (mapboxMap != null) {
Timber.d("Debug FAB: isDebug Active? %s", mapboxMap.isDebugActive());
@@ -155,7 +154,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
}
private void setupStyleChangeView() {
FloatingActionButton fabStyles = (FloatingActionButton) findViewById(R.id.fabStyles);
FloatingActionButton fabStyles = findViewById(R.id.fabStyles);
fabStyles.setOnClickListener(view -> {
if (mapboxMap != null) {
currentStyleIndex++;
@@ -205,6 +204,9 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
@Override
protected void onDestroy() {
super.onDestroy();
if (mapboxMap != null && idleZoomListener != null) {
mapboxMap.removeOnCameraIdleListener(idleZoomListener);
}
mapView.onDestroy();
}
@@ -246,8 +248,8 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
if (view == null) {
view = layoutInflater.inflate(android.R.layout.simple_list_item_2, parent, false);
ViewHolder holder = new ViewHolder(
(TextView) view.findViewById(android.R.id.text1),
(TextView) view.findViewById(android.R.id.text2)
view.findViewById(android.R.id.text1),
view.findViewById(android.R.id.text2)
);
view.setTag(holder);
}

View File

@@ -8,7 +8,6 @@ import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
@@ -17,6 +16,7 @@ import com.mapbox.mapboxsdk.style.layers.FillLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.utils.IdleZoomListener;
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
import java.io.IOException;
@@ -48,6 +48,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
public static final String AMSTERDAM_PARKS_LAYER = "amsterdam-parks-layer";
private MapView mapView;
private MapboxMap mapboxMap;
private IdleZoomListener idleListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -55,7 +56,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
setContentView(R.layout.activity_data_driven_style);
// Initialize map as normal
mapView = (MapView) findViewById(R.id.mapView);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(map -> {
@@ -75,15 +76,9 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
private void setupDebugZoomView() {
final TextView textView = (TextView) findViewById(R.id.textZoom);
mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition position) {
textView.setText(String.format(getString(R.string.debug_zoom), position.zoom));
}
});
mapboxMap.addOnCameraIdleListener(idleListener = new IdleZoomListener(mapboxMap, textView));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_data_driven_style, menu);
@@ -123,6 +118,9 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
super.onDestroy();
if (mapboxMap != null && idleListener != null) {
mapboxMap.removeOnCameraIdleListener(idleListener);
}
mapView.onDestroy();
}

View File

@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp.activity.style;
import android.graphics.PointF;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
@@ -9,6 +10,7 @@ import com.google.gson.JsonObject;
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.FeatureCollection;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.style.layers.Property;
@@ -51,6 +53,23 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
private boolean isSelected = false;
private boolean isShowingSymbolLayer = true;
private MapboxMap.OnMapClickListener mapClickListener = new MapboxMap.OnMapClickListener() {
@Override
public boolean onMapClick(@NonNull LatLng point) {
PointF screenPoint = mapboxMap.getProjection().toScreenLocation(point);
List<Feature> featureList = mapboxMap.queryRenderedFeatures(screenPoint, LAYER_ID);
if (!featureList.isEmpty()) {
Feature feature = featureList.get(0);
boolean selectedNow = feature.getBooleanProperty(KEY_PROPERTY_SELECTED);
isSelected = !selectedNow;
updateSource();
} else {
Timber.e("No features found");
}
return true;
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -62,7 +81,7 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
mapboxMap = map;
updateSource();
addLayer();
addMapClickListener();
map.addOnMapClickListener(mapClickListener);
});
}
@@ -113,23 +132,6 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
mapboxMap.addLayer(layer);
}
private void addMapClickListener() {
mapboxMap.setOnMapClickListener(point -> {
PointF screenPoint = mapboxMap.getProjection().toScreenLocation(point);
List<Feature> featureList = mapboxMap.queryRenderedFeatures(screenPoint, LAYER_ID);
if (!featureList.isEmpty()) {
Feature feature = featureList.get(0);
boolean selectedNow = feature.getBooleanProperty(KEY_PROPERTY_SELECTED);
isSelected = !selectedNow;
updateSource();
} else {
Timber.e("No features found");
}
return false;
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_symbols, menu);

View File

@@ -15,6 +15,7 @@ import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
@@ -39,6 +40,7 @@ public class TextureViewDebugModeActivity extends AppCompatActivity implements O
private MapboxMap mapboxMap;
private ActionBarDrawerToggle actionBarDrawerToggle;
private int currentStyleIndex = 0;
private IdleListener idleListener;
private static final String[] STYLES = new String[] {
Style.MAPBOX_STREETS,
@@ -67,7 +69,7 @@ public class TextureViewDebugModeActivity extends AppCompatActivity implements O
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
actionBarDrawerToggle = new ActionBarDrawerToggle(this,
drawerLayout,
R.string.navigation_drawer_open,
@@ -103,14 +105,14 @@ public class TextureViewDebugModeActivity extends AppCompatActivity implements O
}
private void setFpsView() {
final TextView fpsView = (TextView) findViewById(R.id.fpsView);
final TextView fpsView = findViewById(R.id.fpsView);
mapboxMap.setOnFpsChangedListener(fps -> fpsView.setText(String.format(Locale.US, "FPS: %4.2f", fps)));
}
private void setupNavigationView(List<Layer> layerList) {
Timber.v("New style loaded with JSON: %s", mapboxMap.getStyleJson());
final LayerListAdapter adapter = new LayerListAdapter(this, layerList);
ListView listView = (ListView) findViewById(R.id.listView);
ListView listView = findViewById(R.id.listView);
listView.setAdapter(adapter);
listView.setOnItemClickListener((parent, view, position, id) -> {
Layer clickedLayer = adapter.getItem(position);
@@ -129,18 +131,17 @@ public class TextureViewDebugModeActivity extends AppCompatActivity implements O
}
private void closeNavigationView() {
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
drawerLayout.closeDrawers();
}
private void setupZoomView() {
final TextView textView = (TextView) findViewById(R.id.textZoom);
mapboxMap.setOnCameraChangeListener(position ->
textView.setText(String.format(getString(R.string.debug_zoom), position.zoom)));
final TextView textView = findViewById(R.id.textZoom);
mapboxMap.addOnCameraIdleListener(idleListener = new IdleListener(mapboxMap, textView));
}
private void setupDebugChangeView() {
FloatingActionButton fabDebug = (FloatingActionButton) findViewById(R.id.fabDebug);
FloatingActionButton fabDebug = findViewById(R.id.fabDebug);
fabDebug.setOnClickListener(view -> {
if (mapboxMap != null) {
Timber.d("Debug FAB: isDebug Active? %s", mapboxMap.isDebugActive());
@@ -150,7 +151,7 @@ public class TextureViewDebugModeActivity extends AppCompatActivity implements O
}
private void setupStyleChangeView() {
FloatingActionButton fabStyles = (FloatingActionButton) findViewById(R.id.fabStyles);
FloatingActionButton fabStyles = findViewById(R.id.fabStyles);
fabStyles.setOnClickListener(view -> {
if (mapboxMap != null) {
currentStyleIndex++;
@@ -200,6 +201,9 @@ public class TextureViewDebugModeActivity extends AppCompatActivity implements O
@Override
protected void onDestroy() {
super.onDestroy();
if (mapboxMap != null && idleListener != null) {
mapboxMap.removeOnCameraIdleListener(idleListener);
}
mapView.onDestroy();
}
@@ -241,8 +245,8 @@ public class TextureViewDebugModeActivity extends AppCompatActivity implements O
if (view == null) {
view = layoutInflater.inflate(android.R.layout.simple_list_item_2, parent, false);
ViewHolder holder = new ViewHolder(
(TextView) view.findViewById(android.R.id.text1),
(TextView) view.findViewById(android.R.id.text2)
view.findViewById(android.R.id.text1),
view.findViewById(android.R.id.text2)
);
view.setTag(holder);
}
@@ -262,4 +266,22 @@ public class TextureViewDebugModeActivity extends AppCompatActivity implements O
}
}
}
private static class IdleListener implements MapboxMap.OnCameraIdleListener {
private MapboxMap mapboxMap;
private TextView textView;
IdleListener(MapboxMap mapboxMap, TextView textView) {
this.mapboxMap = mapboxMap;
this.textView = textView;
}
@Override
public void onCameraIdle() {
Context context = textView.getContext();
CameraPosition position = mapboxMap.getCameraPosition();
textView.setText(String.format(context.getString(R.string.debug_zoom), position.zoom));
}
}
}

View File

@@ -0,0 +1,25 @@
package com.mapbox.mapboxsdk.testapp.utils;
import android.content.Context;
import android.widget.TextView;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
public class IdleZoomListener implements MapboxMap.OnCameraIdleListener {
private MapboxMap mapboxMap;
private TextView textView;
public IdleZoomListener(MapboxMap mapboxMap, TextView textView) {
this.mapboxMap = mapboxMap;
this.textView = textView;
}
@Override
public void onCameraIdle() {
Context context = textView.getContext();
CameraPosition position = mapboxMap.getCameraPosition();
textView.setText(String.format(context.getString(R.string.debug_zoom), position.zoom));
}
}