diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 96631c91f..06f487acb 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -576,7 +576,7 @@ public class MapView extends FrameLayout { // double getDirection() { - if(mDestroyed){ + if (mDestroyed) { return 0; } @@ -1270,7 +1270,7 @@ public class MapView extends FrameLayout { // Must handle window resizing here. @Override public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { - if(mDestroyed){ + if (mDestroyed) { return; } @@ -1281,7 +1281,7 @@ public class MapView extends FrameLayout { // Must sync with UI here @Override public void onSurfaceTextureUpdated(SurfaceTexture surface) { - if(mDestroyed){ + if (mDestroyed) { return; } @@ -2456,27 +2456,16 @@ public class MapView extends FrameLayout { void snapshot(@NonNull final MapboxMap.SnapshotReadyCallback callback, @Nullable final Bitmap bitmap) { final TextureView textureView = (TextureView) findViewById(R.id.textureView); final boolean canUseBitmap = bitmap != null && textureView.getWidth() == bitmap.getWidth() && textureView.getHeight() == bitmap.getHeight(); - - new AsyncTask() { - @Override - protected Bitmap doInBackground(Void... params) { - if (canUseBitmap) { - return textureView.getBitmap(bitmap); - } else { - return textureView.getBitmap(); - } - } - - @Override - protected void onPostExecute(Bitmap bitmap) { - callback.onSnapshotReady(bitmap); - } - }.execute(); + if (canUseBitmap) { + callback.onSnapshotReady(textureView.getBitmap(bitmap)); + } else { + callback.onSnapshotReady(textureView.getBitmap()); + } } - // - // View utility methods - // +// +// View utility methods +// private void setWidgetGravity(@NonNull final View view, int gravity) { LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); @@ -2494,295 +2483,295 @@ public class MapView extends FrameLayout { view.setLayoutParams(layoutParams); } - private static class AttributionOnClickListener implements View.OnClickListener, DialogInterface.OnClickListener { +private static class AttributionOnClickListener implements View.OnClickListener, DialogInterface.OnClickListener { - private static final int ATTRIBUTION_INDEX_IMPROVE_THIS_MAP = 2; - private static final int ATTRIBUTION_INDEX_TELEMETRY_SETTINGS = 3; - private MapView mMapView; + private static final int ATTRIBUTION_INDEX_IMPROVE_THIS_MAP = 2; + private static final int ATTRIBUTION_INDEX_TELEMETRY_SETTINGS = 3; + private MapView mMapView; - public AttributionOnClickListener(MapView mapView) { - super(); - mMapView = mapView; - } + public AttributionOnClickListener(MapView mapView) { + super(); + mMapView = mapView; + } - // Called when someone presses the attribution icon - @Override - public void onClick(View v) { - Context context = v.getContext(); - String[] items = context.getResources().getStringArray(R.array.attribution_names); + // Called when someone presses the attribution icon + @Override + public void onClick(View v) { + Context context = v.getContext(); + String[] items = context.getResources().getStringArray(R.array.attribution_names); + AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AttributionAlertDialogStyle); + builder.setTitle(R.string.attributionsDialogTitle); + builder.setAdapter(new ArrayAdapter<>(context, R.layout.attribution_list_item, items), this); + builder.show(); + } + + // Called when someone selects an attribution, 'Improve this map' adds location data to the url + @Override + public void onClick(DialogInterface dialog, int which) { + final Context context = ((Dialog) dialog).getContext(); + if (which == ATTRIBUTION_INDEX_TELEMETRY_SETTINGS) { + + int array = R.array.attribution_telemetry_options; + if (MapboxEventManager.getMapboxEventManager().isTelemetryEnabled()) { + array = R.array.attribution_telemetry_options_already_participating; + } + String[] items = context.getResources().getStringArray(array); AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AttributionAlertDialogStyle); - builder.setTitle(R.string.attributionsDialogTitle); - builder.setAdapter(new ArrayAdapter<>(context, R.layout.attribution_list_item, items), this); - builder.show(); - } + builder.setTitle(R.string.attributionTelemetryTitle); + LayoutInflater factory = LayoutInflater.from(context); + View content = factory.inflate(R.layout.attribution_telemetry_view, null); - // Called when someone selects an attribution, 'Improve this map' adds location data to the url - @Override - public void onClick(DialogInterface dialog, int which) { - final Context context = ((Dialog) dialog).getContext(); - if (which == ATTRIBUTION_INDEX_TELEMETRY_SETTINGS) { + ListView lv = (ListView) content.findViewById(R.id.telemetryOptionsList); + lv.setAdapter(new ArrayAdapter(context, R.layout.attribution_list_item, items)); + lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - int array = R.array.attribution_telemetry_options; - if (MapboxEventManager.getMapboxEventManager().isTelemetryEnabled()) { - array = R.array.attribution_telemetry_options_already_participating; - } - String[] items = context.getResources().getStringArray(array); - AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AttributionAlertDialogStyle); - builder.setTitle(R.string.attributionTelemetryTitle); - LayoutInflater factory = LayoutInflater.from(context); - View content = factory.inflate(R.layout.attribution_telemetry_view, null); - - ListView lv = (ListView) content.findViewById(R.id.telemetryOptionsList); - lv.setAdapter(new ArrayAdapter(context, R.layout.attribution_list_item, items)); - lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - - builder.setView(content); - final AlertDialog telemDialog = builder.show(); - lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - switch (position) { - case 0: - String url = context.getResources().getStringArray(R.array.attribution_links)[3]; - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(url)); - context.startActivity(intent); - telemDialog.cancel(); - return; - case 1: - MapboxEventManager.getMapboxEventManager().setTelemetryEnabled(false); - telemDialog.cancel(); - return; - case 2: - MapboxEventManager.getMapboxEventManager().setTelemetryEnabled(true); - telemDialog.cancel(); - return; - } + builder.setView(content); + final AlertDialog telemDialog = builder.show(); + lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + switch (position) { + case 0: + String url = context.getResources().getStringArray(R.array.attribution_links)[3]; + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(url)); + context.startActivity(intent); + telemDialog.cancel(); + return; + case 1: + MapboxEventManager.getMapboxEventManager().setTelemetryEnabled(false); + telemDialog.cancel(); + return; + case 2: + MapboxEventManager.getMapboxEventManager().setTelemetryEnabled(true); + telemDialog.cancel(); + return; } - }); - return; - } - String url = context.getResources().getStringArray(R.array.attribution_links)[which]; - if (which == ATTRIBUTION_INDEX_IMPROVE_THIS_MAP) { - LatLng latLng = mMapView.getMapboxMap().getCameraPosition().target; - url = String.format(url, latLng.getLongitude(), latLng.getLatitude(), (int) mMapView.getZoom()); - } - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(url)); - context.startActivity(intent); + } + }); + return; } - } - - private static class ZoomInvalidator implements Runnable { - - private MapboxMap mapboxMap; - - public ZoomInvalidator(MapboxMap mapboxMap) { - this.mapboxMap = mapboxMap; + String url = context.getResources().getStringArray(R.array.attribution_links)[which]; + if (which == ATTRIBUTION_INDEX_IMPROVE_THIS_MAP) { + LatLng latLng = mMapView.getMapboxMap().getCameraPosition().target; + url = String.format(url, latLng.getLongitude(), latLng.getLatitude(), (int) mMapView.getZoom()); } + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(url)); + context.startActivity(intent); + } +} - @Override - public void run() { - // invalidate camera position - mapboxMap.getCameraPosition(); - } +private static class ZoomInvalidator implements Runnable { + + private MapboxMap mapboxMap; + + public ZoomInvalidator(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; } - /** - * Definition of a map change event. - * - * @see MapView.OnMapChangedListener#onMapChanged(int) - */ - @IntDef({REGION_WILL_CHANGE, - REGION_WILL_CHANGE_ANIMATED, - REGION_IS_CHANGING, - REGION_DID_CHANGE, - REGION_DID_CHANGE_ANIMATED, - WILL_START_LOADING_MAP, - DID_FINISH_LOADING_MAP, - DID_FAIL_LOADING_MAP, - WILL_START_RENDERING_FRAME, - DID_FINISH_RENDERING_FRAME, - DID_FINISH_RENDERING_FRAME_FULLY_RENDERED, - WILL_START_RENDERING_MAP, - DID_FINISH_RENDERING_MAP, - DID_FINISH_RENDERING_MAP_FULLY_RENDERED - }) - @Retention(RetentionPolicy.SOURCE) - public @interface MapChange { + @Override + public void run() { + // invalidate camera position + mapboxMap.getCameraPosition(); } +} - /** - *

- * This {@link MapChange} is triggered whenever the currently displayed map region is about to changing - * without an animation. - *

- *

- * This event is followed by a series of {@link MapView#REGION_IS_CHANGING} and ends - * with {@link MapView#REGION_DID_CHANGE}. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int REGION_WILL_CHANGE = 0; +/** + * Definition of a map change event. + * + * @see MapView.OnMapChangedListener#onMapChanged(int) + */ +@IntDef({REGION_WILL_CHANGE, + REGION_WILL_CHANGE_ANIMATED, + REGION_IS_CHANGING, + REGION_DID_CHANGE, + REGION_DID_CHANGE_ANIMATED, + WILL_START_LOADING_MAP, + DID_FINISH_LOADING_MAP, + DID_FAIL_LOADING_MAP, + WILL_START_RENDERING_FRAME, + DID_FINISH_RENDERING_FRAME, + DID_FINISH_RENDERING_FRAME_FULLY_RENDERED, + WILL_START_RENDERING_MAP, + DID_FINISH_RENDERING_MAP, + DID_FINISH_RENDERING_MAP_FULLY_RENDERED +}) +@Retention(RetentionPolicy.SOURCE) +public @interface MapChange { +} - /** - *

- * This {@link MapChange} is triggered whenever the currently displayed map region is about to changing - * with an animation. - *

- *

- * This event is followed by a series of {@link MapView#REGION_IS_CHANGING} and ends - * with {@link MapView#REGION_DID_CHANGE_ANIMATED}. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int REGION_WILL_CHANGE_ANIMATED = 1; +/** + *

+ * This {@link MapChange} is triggered whenever the currently displayed map region is about to changing + * without an animation. + *

+ *

+ * This event is followed by a series of {@link MapView#REGION_IS_CHANGING} and ends + * with {@link MapView#REGION_DID_CHANGE}. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int REGION_WILL_CHANGE = 0; - /** - *

- * This {@link MapChange} is triggered whenever the currently displayed map region is changing. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int REGION_IS_CHANGING = 2; +/** + *

+ * This {@link MapChange} is triggered whenever the currently displayed map region is about to changing + * with an animation. + *

+ *

+ * This event is followed by a series of {@link MapView#REGION_IS_CHANGING} and ends + * with {@link MapView#REGION_DID_CHANGE_ANIMATED}. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int REGION_WILL_CHANGE_ANIMATED = 1; - /** - *

- * This {@link MapChange} is triggered whenever the currently displayed map region finished changing - * without an animation. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int REGION_DID_CHANGE = 3; +/** + *

+ * This {@link MapChange} is triggered whenever the currently displayed map region is changing. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int REGION_IS_CHANGING = 2; - /** - *

- * This {@link MapChange} is triggered whenever the currently displayed map region finished changing - * with an animation. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int REGION_DID_CHANGE_ANIMATED = 4; +/** + *

+ * This {@link MapChange} is triggered whenever the currently displayed map region finished changing + * without an animation. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int REGION_DID_CHANGE = 3; - /** - *

- * This {@link MapChange} is triggered when the map is about to start loading a new map style. - *

- *

- * This event is followed by {@link MapView#DID_FINISH_LOADING_MAP} or - * {@link MapView#DID_FAIL_LOADING_MAP}. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int WILL_START_LOADING_MAP = 5; +/** + *

+ * This {@link MapChange} is triggered whenever the currently displayed map region finished changing + * with an animation. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int REGION_DID_CHANGE_ANIMATED = 4; - /** - *

- * This {@link MapChange} is triggered when the map has successfully loaded a new map style. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int DID_FINISH_LOADING_MAP = 6; +/** + *

+ * This {@link MapChange} is triggered when the map is about to start loading a new map style. + *

+ *

+ * This event is followed by {@link MapView#DID_FINISH_LOADING_MAP} or + * {@link MapView#DID_FAIL_LOADING_MAP}. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int WILL_START_LOADING_MAP = 5; - /** - *

- * This {@link MapChange} is currently not implemented. - *

- *

- * This event is triggered when the map has failed to load a new map style. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int DID_FAIL_LOADING_MAP = 7; +/** + *

+ * This {@link MapChange} is triggered when the map has successfully loaded a new map style. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int DID_FINISH_LOADING_MAP = 6; - /** - *

- * This {@link MapChange} is currently not implemented. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int WILL_START_RENDERING_FRAME = 8; +/** + *

+ * This {@link MapChange} is currently not implemented. + *

+ *

+ * This event is triggered when the map has failed to load a new map style. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int DID_FAIL_LOADING_MAP = 7; - /** - *

- * This {@link MapChange} is currently not implemented. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int DID_FINISH_RENDERING_FRAME = 9; +/** + *

+ * This {@link MapChange} is currently not implemented. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int WILL_START_RENDERING_FRAME = 8; - /** - *

- * This {@link MapChange} is currently not implemented. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int DID_FINISH_RENDERING_FRAME_FULLY_RENDERED = 10; +/** + *

+ * This {@link MapChange} is currently not implemented. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int DID_FINISH_RENDERING_FRAME = 9; - /** - *

- * This {@link MapChange} is currently not implemented. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int WILL_START_RENDERING_MAP = 11; +/** + *

+ * This {@link MapChange} is currently not implemented. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int DID_FINISH_RENDERING_FRAME_FULLY_RENDERED = 10; - /** - *

- * This {@link MapChange} is currently not implemented. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int DID_FINISH_RENDERING_MAP = 12; +/** + *

+ * This {@link MapChange} is currently not implemented. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int WILL_START_RENDERING_MAP = 11; - /** - *

- * This {@link MapChange} is currently not implemented. - *

- * - * @see MapView.OnMapChangedListener - */ - public static final int DID_FINISH_RENDERING_MAP_FULLY_RENDERED = 13; +/** + *

+ * This {@link MapChange} is currently not implemented. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int DID_FINISH_RENDERING_MAP = 12; +/** + *

+ * This {@link MapChange} is currently not implemented. + *

+ * + * @see MapView.OnMapChangedListener + */ +public static final int DID_FINISH_RENDERING_MAP_FULLY_RENDERED = 13; + +/** + * Interface definition for a callback to be invoked when the displayed map view changes. + * + * @see MapView#addOnMapChangedListener(OnMapChangedListener) + * @see MapView.MapChange + */ +public interface OnMapChangedListener { /** - * Interface definition for a callback to be invoked when the displayed map view changes. + * Called when the displayed map view changes. * - * @see MapView#addOnMapChangedListener(OnMapChangedListener) - * @see MapView.MapChange + * @param change Type of map change event, one of {@link #REGION_WILL_CHANGE}, + * {@link #REGION_WILL_CHANGE_ANIMATED}, + * {@link #REGION_IS_CHANGING}, + * {@link #REGION_DID_CHANGE}, + * {@link #REGION_DID_CHANGE_ANIMATED}, + * {@link #WILL_START_LOADING_MAP}, + * {@link #DID_FAIL_LOADING_MAP}, + * {@link #DID_FINISH_LOADING_MAP}, + * {@link #WILL_START_RENDERING_FRAME}, + * {@link #DID_FINISH_RENDERING_FRAME}, + * {@link #DID_FINISH_RENDERING_FRAME_FULLY_RENDERED}, + * {@link #WILL_START_RENDERING_MAP}, + * {@link #DID_FINISH_RENDERING_MAP}, + * {@link #DID_FINISH_RENDERING_MAP_FULLY_RENDERED}. */ - public interface OnMapChangedListener { - /** - * Called when the displayed map view changes. - * - * @param change Type of map change event, one of {@link #REGION_WILL_CHANGE}, - * {@link #REGION_WILL_CHANGE_ANIMATED}, - * {@link #REGION_IS_CHANGING}, - * {@link #REGION_DID_CHANGE}, - * {@link #REGION_DID_CHANGE_ANIMATED}, - * {@link #WILL_START_LOADING_MAP}, - * {@link #DID_FAIL_LOADING_MAP}, - * {@link #DID_FINISH_LOADING_MAP}, - * {@link #WILL_START_RENDERING_FRAME}, - * {@link #DID_FINISH_RENDERING_FRAME}, - * {@link #DID_FINISH_RENDERING_FRAME_FULLY_RENDERED}, - * {@link #WILL_START_RENDERING_MAP}, - * {@link #DID_FINISH_RENDERING_MAP}, - * {@link #DID_FINISH_RENDERING_MAP_FULLY_RENDERED}. - */ - void onMapChanged(@MapChange int change); - } + void onMapChanged(@MapChange int change); +} }