diff options
author | Brad Leege <bleege@gmail.com> | 2016-04-06 12:54:22 -0500 |
---|---|---|
committer | Brad Leege <bleege@gmail.com> | 2016-04-06 14:44:52 -0500 |
commit | 9a3e8ae571017071e09e6efdb60292c8d62b8bdd (patch) | |
tree | 0d27dc4c209026664bac020e4aca37905dfc1878 /platform | |
parent | 8814463380c248d5163745ac12433beeae3ff051 (diff) | |
download | qtlocation-mapboxgl-9a3e8ae571017071e09e6efdb60292c8d62b8bdd.tar.gz |
[android] #4619 - Creating standalone CustomLayerActivity example
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml | 7 | ||||
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java | 124 | ||||
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/customlayer/ExampleCustomLayer.java (renamed from platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/other/CustomLayer.java) | 4 | ||||
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_layers_24dp.xml | 9 | ||||
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_layers_clear_24dp.xml | 9 | ||||
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_custom_layer.xml | 47 | ||||
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml | 5 | ||||
-rw-r--r-- | platform/android/src/example_custom_layer.cpp | 2 |
8 files changed, 202 insertions, 5 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 93f66819c2..54199f9b90 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -121,6 +121,13 @@ android:name="@string/category" android:value="@string/category_camera" /> </activity> + <activity android:name=".activity.customlayer.CustomLayerActivity" + android:description="@string/description_custom_layer" + android:label="@string/activity_custom_layer"> + <meta-data + android:name="@string/category" + android:value="@string/category_custom_layer" /> + </activity> <activity android:name=".activity.userlocation.MyLocationTrackingModeActivity" android:description="@string/description_user_location_tracking" diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java new file mode 100644 index 0000000000..04d427344f --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.java @@ -0,0 +1,124 @@ +package com.mapbox.mapboxsdk.testapp.activity.customlayer; + +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.MenuItem; +import android.view.View; +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.layers.CustomLayer; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.testapp.model.customlayer.ExampleCustomLayer; + +public class CustomLayerActivity extends AppCompatActivity { + + private MapboxMap mapboxMap; + private MapView mapView; + + private boolean isShowingCustomLayer = false; + private FloatingActionButton fab; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_custom_layer); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + final ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setDisplayShowHomeEnabled(true); + } + + mapView = (MapView) findViewById(R.id.mapView); + mapView.setAccessToken(getString(R.string.mapbox_access_token)); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.91448, -243.60947), 10)); + + } + }); + + fab = (FloatingActionButton) findViewById(R.id.fab); + fab.setColorFilter(ContextCompat.getColor(this, R.color.primary)); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mapboxMap != null) { + swapCustomLayer(); + } + } + }); + } + + private void swapCustomLayer() { + + if (isShowingCustomLayer) { + mapboxMap.removeCustomLayer("custom"); + fab.setImageResource(R.drawable.ic_layers_24dp); + } else { + mapboxMap.addCustomLayer(new CustomLayer("custom", + ExampleCustomLayer.createContext(), + ExampleCustomLayer.InitializeFunction, + ExampleCustomLayer.RenderFunction, + ExampleCustomLayer.DeinitializeFunction), null); + fab.setImageResource(R.drawable.ic_layers_clear_24dp); + } + + isShowingCustomLayer = !isShowingCustomLayer; + } + + @Override + public void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/other/CustomLayer.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/customlayer/ExampleCustomLayer.java index cecaac05b3..2901060459 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/other/CustomLayer.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/customlayer/ExampleCustomLayer.java @@ -1,6 +1,6 @@ -package com.mapbox.mapboxsdk.testapp.model.other; +package com.mapbox.mapboxsdk.testapp.model.customlayer; -public class CustomLayer { +public class ExampleCustomLayer { static { System.loadLibrary("example-custom-layer"); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_layers_24dp.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_layers_24dp.xml new file mode 100644 index 0000000000..944b526c5c --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_layers_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="#FFFFFF" + android:pathData="M11.99,18.54l-7.37,-5.73L3,14.07l9,7 9,-7 -1.63,-1.27 -7.38,5.74zM12,16l7.36,-5.73L21,9l-9,-7 -9,7 1.63,1.27L12,16z"/> +</vector> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_layers_clear_24dp.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_layers_clear_24dp.xml new file mode 100644 index 0000000000..249f57fc65 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_layers_clear_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="#FFFFFF" + android:pathData="M19.81,14.99l1.19,-0.92 -1.43,-1.43 -1.19,0.92 1.43,1.43zM19.36,10.27L21,9l-9,-7 -2.91,2.27 7.87,7.88 2.4,-1.88zM3.27,1L2,2.27l4.22,4.22L3,9l1.63,1.27L12,16l2.1,-1.63 1.43,1.43L12,18.54l-7.37,-5.73L3,14.07l9,7 4.95,-3.85L20.73,21 22,19.73 3.27,1z"/> +</vector> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_custom_layer.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_custom_layer.xml new file mode 100644 index 0000000000..2b52f7d8fd --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_custom_layer.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <android.support.v7.widget.Toolbar + android:id="@+id/toolbar" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + android:background="@color/primary" + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> + + </android.support.v7.widget.Toolbar> + + <FrameLayout + android:id="@+id/content_frame" + android:layout_width="match_parent" + android:layout_height="match_parent" + > + + <android.support.design.widget.CoordinatorLayout + android:id="@+id/coordinator_layout" + 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.design.widget.FloatingActionButton + android:id="@+id/fab" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="end|bottom" + android:layout_margin="@dimen/fab_margin" + android:src="@drawable/ic_layers_24dp" + app:backgroundTint="@android:color/white" + /> + + </android.support.design.widget.CoordinatorLayout> + + </FrameLayout> + +</LinearLayout> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index c7aabc96d7..3ada24d880 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -35,14 +35,14 @@ <!-- Other --> <string name="activity_snapshot">Snapshot Activity</string> <string name="activity_user_tracking_mode">User tracking mode</string> - <string name="activity_custom_layer">Custom Layer (experimental)</string> + <string name="activity_custom_layer">Custom Layer</string> <string name="activity_map_padding">Map Padding</string> <string name="activity_offline">Offline Map</string> <string name="activity_minmax_zoom">Min/Max Zoom</string> <!-- Description --> <string name="description_user_location_tracking">Tracks the location of the user</string> - <string name="description_custom_layer">Experimental feature</string> + <string name="description_custom_layer">Overlay a custom native layer on the map</string> <string name="description_info_window_adapter">Learn how to create a custom InfoWindow</string> <string name="description_cameraposition">CameraPosition capabilities</string> <string name="description_map_fragment">Showcase MapFragment</string> @@ -72,6 +72,7 @@ <string name="category">category</string> <string name="category_annotation">Annotation</string> <string name="category_camera">Camera</string> + <string name="category_custom_layer">Custom Layer</string> <string name="category_directions">Directions</string> <string name="category_fragment">Fragment</string> <string name="category_geocoding">Geocoding</string> diff --git a/platform/android/src/example_custom_layer.cpp b/platform/android/src/example_custom_layer.cpp index 439f9aff1a..a513b7faf6 100644 --- a/platform/android/src/example_custom_layer.cpp +++ b/platform/android/src/example_custom_layer.cpp @@ -76,7 +76,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { JNIEnv *env = nullptr; vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6); - jclass customLayerClass = env->FindClass("com/mapbox/mapboxsdk/testapp/layers/ExampleCustomLayer"); + jclass customLayerClass = env->FindClass("com/mapbox/mapboxsdk/testapp/model/customlayer/ExampleCustomLayer"); JNINativeMethod methods[] = { {"createContext", "()J", reinterpret_cast<void *>(&nativeCreateContext)} |