diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-02-14 16:04:34 +0100 |
---|---|---|
committer | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-02-18 11:45:53 +0100 |
commit | 4a8b91f67442c155ebd0a4885f8f0b0eb7e220ec (patch) | |
tree | c99b8834fb0b25e5d258d5256f51aaf1c7631efe | |
parent | ceea900578d8f31497810ef19aa7c17669e40722 (diff) |
wip
6 files changed, 196 insertions, 38 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapboxPresenter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapboxPresenter.java new file mode 100644 index 000000000..37580bbfe --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapboxPresenter.java @@ -0,0 +1,5 @@ +package com.mapbox.mapboxsdk; + + +public interface MapboxPresenter<V> { +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapboxView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapboxView.java new file mode 100644 index 000000000..05c853ed0 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapboxView.java @@ -0,0 +1,4 @@ +package com.mapbox.mapboxsdk; + +public interface MapboxView { +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapPresenter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapPresenter.java new file mode 100644 index 000000000..483e0a7e6 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapPresenter.java @@ -0,0 +1,7 @@ +package com.mapbox.mapboxsdk.maps; + +import com.mapbox.mapboxsdk.MapboxPresenter; + +interface MapPresenter extends MapboxPresenter<MapView> { + +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapPresenterImpl.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapPresenterImpl.java new file mode 100644 index 000000000..319522f23 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapPresenterImpl.java @@ -0,0 +1,31 @@ +package com.mapbox.mapboxsdk.maps; + +import android.content.Context; +import android.support.annotation.NonNull; + +import com.mapbox.mapboxsdk.maps.renderer.MapRenderer; + +class MapPresenterImpl implements MapPresenter { + private final MapView mapView; + private final MapboxMapOptions mapboxMapOptions; + private MapRenderer renderer; + + MapPresenterImpl(@NonNull MapView mapView, @NonNull Context context, @NonNull MapboxMapOptions mapboxMapOptions) { + this.mapView = mapView; + this.mapboxMapOptions = mapboxMapOptions; + initialize(); + } + + private void initialize() { + mapView.setForegroundColor(mapboxMapOptions.getForegroundLoadColor()); + mapView.inflateInternalViews(); + mapView.setViewOptions(); + + String localFontFamily = mapboxMapOptions.getLocalIdeographFontFamily(); + if (mapboxMapOptions.getTextureMode()) { + renderer = mapView.initializeTextureView(localFontFamily, mapboxMapOptions.getTranslucentTextureSurface()); + } else { + renderer = mapView.initializeSurfaceView(localFontFamily); + } + } +} 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 9d8dbce28..b1f00b2b7 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 @@ -61,6 +61,8 @@ import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE; */ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { + private MapPresenter mapPresenter; + private final MapChangeReceiver mapChangeReceiver = new MapChangeReceiver(); private final MapCallback mapCallback = new MapCallback(); private final InitialRenderCallback initialRenderCallback = new InitialRenderCallback(); @@ -120,20 +122,9 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { return; } - // hide surface until map is fully loaded #10990 - setForeground(new ColorDrawable(options.getForegroundLoadColor())); - mapboxMapOptions = options; - // inflate view - View view = LayoutInflater.from(context).inflate(R.layout.mapbox_mapview_internal, this); - compassView = view.findViewById(R.id.compassView); - attrView = view.findViewById(R.id.attributionView); - logoView = view.findViewById(R.id.logoView); - - // add accessibility support - setContentDescription(context.getString(R.string.mapbox_mapActionDescription)); - setWillNotDraw(false); + mapPresenter = new MapPresenterImpl(this, context, options); initialiseDrawingSurface(options); } @@ -276,30 +267,9 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { private void initialiseDrawingSurface(MapboxMapOptions options) { String localFontFamily = options.getLocalIdeographFontFamily(); if (options.getTextureMode()) { - TextureView textureView = new TextureView(getContext()); - boolean translucentSurface = options.getTranslucentTextureSurface(); - mapRenderer = new TextureViewMapRenderer(getContext(), - textureView, localFontFamily, translucentSurface) { - @Override - protected void onSurfaceCreated(GL10 gl, EGLConfig config) { - MapView.this.onSurfaceCreated(); - super.onSurfaceCreated(gl, config); - } - }; - addView(textureView, 0); } else { - GLSurfaceView glSurfaceView = new GLSurfaceView(getContext()); - glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop()); - mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView, localFontFamily) { - @Override - public void onSurfaceCreated(GL10 gl, EGLConfig config) { - MapView.this.onSurfaceCreated(); - super.onSurfaceCreated(gl, config); - } - }; - addView(glSurfaceView, 0); } boolean crossSourceCollisions = mapboxMapOptions.getCrossSourceCollisions(); @@ -432,10 +402,10 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { } /** - * The maximum frame rate at which the map view is rendered, - * but it can't excess the ability of device hardware. + * The maximum frame rate at which the map view is rendered, + * but it can't excess the ability of device hardware. * - * @param maximumFps Can be set to arbitrary integer values. + * @param maximumFps Can be set to arbitrary integer values. */ public void setMaximumFps(int maximumFps) { if (mapRenderer != null) { @@ -740,8 +710,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { } /** - - /** + * /** * Set a callback that's invoked when the style has finished loading. * * @param listener The callback that's invoked when the style has finished loading @@ -777,6 +746,59 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { mapChangeReceiver.removeOnSourceChangedListener(listener); } + + /// + /// View Implementation + /// + + void setForegroundColor(int foregroundLoadColor) { + // hide surface until map is fully loaded #10990 + setForeground(new ColorDrawable(foregroundLoadColor)); + } + + void inflateInternalViews() { + View view = LayoutInflater.from(getContext()).inflate(R.layout.mapbox_mapview_internal, this); + compassView = view.findViewById(R.id.compassView); + attrView = view.findViewById(R.id.attributionView); + logoView = view.findViewById(R.id.logoView); + } + + void setViewOptions() { + // add accessibility support + setContentDescription(getContext().getString(R.string.mapbox_mapActionDescription)); + setWillNotDraw(false); + } + + MapRenderer initializeTextureView(@Nullable String localFontFamily, boolean translucent) { + TextureView textureView = new TextureView(getContext()); + mapRenderer = new TextureViewMapRenderer(getContext(), + textureView, localFontFamily, translucent) { + @Override + protected void onSurfaceCreated(GL10 gl, EGLConfig config) { + MapView.this.onSurfaceCreated(); + super.onSurfaceCreated(gl, config); + } + }; + + addView(textureView, 0); + return mapRenderer; + } + + MapRenderer initializeSurfaceView(@Nullable String localFontFamily) { + GLSurfaceView glSurfaceView = new GLSurfaceView(getContext()); + glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop()); + mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView, localFontFamily) { + @Override + public void onSurfaceCreated(GL10 gl, EGLConfig config) { + MapView.this.onSurfaceCreated(); + super.onSurfaceCreated(gl, config); + } + }; + + addView(glSurfaceView, 0); + return mapRenderer; + } + /** * Interface definition for a callback to be invoked when the camera will change. * <p> diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapPresenterTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapPresenterTest.kt new file mode 100644 index 000000000..612e8c399 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapPresenterTest.kt @@ -0,0 +1,89 @@ +package com.mapbox.mapboxsdk.maps + +import android.content.Context +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mockito +import org.mockito.Mockito.* +import org.mockito.junit.MockitoJUnitRunner + +@RunWith(MockitoJUnitRunner::class) +class MapPresenterTest { + private lateinit var mapPresenter: MapPresenter + private lateinit var mapView: MapView + private lateinit var context: Context + private lateinit var mapboxMapOptions: MapboxMapOptions + + @Before + fun setup() { + mapView = mock(MapView::class.java) + context = mock(Context::class.java) + + mapboxMapOptions = mock(MapboxMapOptions::class.java) + doReturn(0xFFF0E9E1.toInt()).`when`(mapboxMapOptions).foregroundLoadColor + doReturn(false).`when`(mapboxMapOptions).textureMode + doReturn(null).`when`(mapboxMapOptions).localIdeographFontFamily + + mapPresenter = MapPresenterImpl(mapView, context, mapboxMapOptions) + } + + @Test + fun init_foregroundColorSet() { + verify(mapView).setForegroundColor(0xFFF0E9E1.toInt()) + } + + @Test + fun init_inflateInternalViews() { + verify(mapView).inflateInternalViews() + } + + @Test + fun init_setViewOptions() { + verify(mapView).setViewOptions() + } + + @Test + fun init_initializeTextureView() { + doReturn(true).`when`(mapboxMapOptions).textureMode + doReturn(false).`when`(mapboxMapOptions).translucentTextureSurface + doReturn(null).`when`(mapboxMapOptions).localIdeographFontFamily + mapPresenter = MapPresenterImpl(mapView, context, mapboxMapOptions) + verify(mapView).initializeTextureView(null, false) + } + + @Test + fun init_initializeTranslucentTextureView() { + doReturn(true).`when`(mapboxMapOptions).textureMode + doReturn(true).`when`(mapboxMapOptions).translucentTextureSurface + doReturn(null).`when`(mapboxMapOptions).localIdeographFontFamily + mapPresenter = MapPresenterImpl(mapView, context, mapboxMapOptions) + verify(mapView).initializeTextureView(null, true) + } + + @Test + fun init_initializeTextureViewWithLocalFonts() { + doReturn(true).`when`(mapboxMapOptions).textureMode + doReturn(true).`when`(mapboxMapOptions).translucentTextureSurface + doReturn("comic-sans").`when`(mapboxMapOptions).localIdeographFontFamily + mapPresenter = MapPresenterImpl(mapView, context, mapboxMapOptions) + verify(mapView).initializeTextureView("comic-sans", true) + } + + @Test + fun init_initializeSurfaceView() { + doReturn(false).`when`(mapboxMapOptions).textureMode + doReturn(null).`when`(mapboxMapOptions).localIdeographFontFamily + mapPresenter = MapPresenterImpl(mapView, context, mapboxMapOptions) + verify(mapView).initializeSurfaceView(null) + } + + @Test + fun init_initializeSurfaceViewWithLocalFonts() { + doReturn(false).`when`(mapboxMapOptions).textureMode + doReturn("comic-sans").`when`(mapboxMapOptions).localIdeographFontFamily +// mapPresenter = MapPresenterImpl(mapView, context, mapboxMapOptions) +// verify(mapView).initializeSurfaceView("comic-sans") + } +}
\ No newline at end of file |