summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2018-11-21 11:25:23 +0100
committerTobrun <tobrun@mapbox.com>2018-11-21 13:25:48 +0100
commit66c91667f4b38a07ffc56908f21b01c969f9a1b6 (patch)
tree1660356d5c958d4d821872bb3ac6692da8a67b2e /platform/android
parentf30429832e78600b8100a812fb50bcf1b949d567 (diff)
downloadqtlocation-mapboxgl-66c91667f4b38a07ffc56908f21b01c969f9a1b6.tar.gz
[android] - add overlay example with custom drawing using paint and canvas
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml11
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/OverlayMapActivity.kt82
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_overlay.xml13
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml1
5 files changed, 108 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index d30265f18a..22ae7f9824 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -740,6 +740,17 @@
android:value=".activity.FeatureOverviewActivity" />
</activity>
<activity
+ android:name=".activity.maplayout.OverlayMapActivity"
+ android:description="@string/description_overlay"
+ android:label="@string/activity_overlay">
+ <meta-data
+ android:name="@string/category"
+ android:value="@string/category_maplayout" />
+ <meta-data
+ android:name="android.support.PARENT_ACTIVITY"
+ android:value=".activity.FeatureOverviewActivity" />
+ </activity>
+ <activity
android:name=".activity.maplayout.LocalGlyphActivity"
android:description="@string/description_local_glyph"
android:label="@string/activity_local_glyph">
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/OverlayMapActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/OverlayMapActivity.kt
new file mode 100644
index 0000000000..8549ab8a60
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/OverlayMapActivity.kt
@@ -0,0 +1,82 @@
+package com.mapbox.mapboxsdk.testapp.activity.maplayout
+
+import android.annotation.SuppressLint
+import android.content.Context
+import android.graphics.*
+import android.os.Bundle
+import android.support.v7.app.AppCompatActivity
+import android.view.View
+import com.mapbox.mapboxsdk.testapp.R
+import kotlinx.android.synthetic.main.activity_overlay.*
+
+/**
+ * Test overlaying a Map with a View that uses a radial gradient shader.
+ */
+class OverlayMapActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_overlay)
+ mapView.onCreate(savedInstanceState)
+ parentView.addView(OverlayView(this))
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView.onStop()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView.onLowMemory()
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView.onDestroy()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle?) {
+ super.onSaveInstanceState(outState)
+ outState?.let {
+ mapView.onSaveInstanceState(it)
+ }
+ }
+
+ class OverlayView(context: Context) : View(context) {
+
+ private lateinit var paint: Paint
+
+ @SuppressLint("DrawAllocation") // only happens once
+ override fun onDraw(canvas: Canvas?) {
+ super.onDraw(canvas)
+
+ canvas?.let {
+ if (!::paint.isInitialized) {
+ paint = Paint()
+ paint.color = Color.BLACK
+ paint.strokeWidth = 1.0f
+ paint.style = Paint.Style.FILL_AND_STROKE
+ paint.shader = RadialGradient(width / 2.0f, height / 2.0f,
+ height / 3.0f, Color.TRANSPARENT, Color.BLACK, Shader.TileMode.CLAMP)
+ }
+ it.drawRect(0.0f, 0.0f, width.toFloat(), height.toFloat(), paint)
+ }
+ }
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_overlay.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_overlay.xml
new file mode 100644
index 0000000000..915b0a2c5b
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_overlay.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/parentView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <com.mapbox.mapboxsdk.maps.MapView
+ android:id="@+id/mapView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+</android.support.constraint.ConstraintLayout> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
index ca54c954d4..7fdc4c1bea 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
@@ -63,6 +63,7 @@
<string name="description_textureview_resize">Resize a map rendered on a TextureView</string>
<string name="description_textureview_animate">Animate a map rendered on a TextureView</string>
<string name="description_textureview_transparent">Enable a transparent surface on TextureView</string>
+ <string name="description_overlay">Blend an overlay on a map</string>
<string name="description_grid_source">Example Custom Geometry Source</string>
<string name="description_local_glyph">Suzhou using Droid Sans for Chinese glyphs</string>
<string name="description_hillshade">Example raster-dem source and hillshade layer</string>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
index f73bcc147d..3345c8db4e 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
@@ -63,6 +63,7 @@
<string name="activity_textureview_resize">TextureView resize</string>
<string name="activity_textureview_animate">TextureView animation</string>
<string name="activity_textureview_transparent">TextureView transparent background</string>
+ <string name="activity_overlay">Map overlay</string>
<string name="activity_grid_source">Grid Source</string>
<string name="activity_local_glyph">Local CJK glyph generation</string>
<string name="activity_hillshade">Hillshade</string>