diff options
author | Tobrun <tobrun@mapbox.com> | 2016-04-21 10:50:01 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2016-05-20 12:00:01 +0200 |
commit | 028ef7a32356ffce8ba66b203016445e02637644 (patch) | |
tree | b04e8d8e228c29125533a18919335fb7df232f7f /platform/android/MapboxGLAndroidSDKTestApp | |
parent | ef257c257d8ba681005c3b7ce4618b09caaa0f37 (diff) | |
download | qtlocation-mapboxgl-028ef7a32356ffce8ba66b203016445e02637644.tar.gz |
[android] #3276 - WIP Android View Annotations, showing an Android SDK view on the screen
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp')
11 files changed, 250 insertions, 1 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 5411643842..d31915f217 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -253,6 +253,16 @@ android:value="@string/category_maplayout" /> </activity> + <activity + android:name=".activity.annotation.ViewMarkerActivity" + android:description="@string/description_view_marker" + android:label="@string/activity_view_marker"> + <meta-data + android:name="@string/category" + android:value="@string/category_annotation" /> + </activity> + + <!-- Configuration Settings --> <meta-data android:name="com.mapbox.TestEventsServer" diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/ViewMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/ViewMarkerActivity.java new file mode 100644 index 0000000000..27615da5dd --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/ViewMarkerActivity.java @@ -0,0 +1,123 @@ +package com.mapbox.mapboxsdk.testapp.activity.annotation; + +import android.os.Bundle; +import android.support.annotation.DrawableRes; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +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.annotations.Marker; +import com.mapbox.mapboxsdk.annotations.MarkerOptions; +import com.mapbox.mapboxsdk.annotations.MarkerView; +import com.mapbox.mapboxsdk.geometry.LatLng; +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.view.CustomMarkerView; + +public class ViewMarkerActivity extends AppCompatActivity implements OnMapReadyCallback { + + private MapView mMapView; + private Marker brazil, germany, china, us; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_marker_view); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setDisplayShowHomeEnabled(true); + } + + mMapView = (MapView) findViewById(R.id.mapView); + mMapView.onCreate(savedInstanceState); + mMapView.getMapAsync(this); + } + + @Override + public void onMapReady(MapboxMap mapboxMap) { + + // adapt GL-marker to View-marker + mapboxMap.setMarkerViewAdapter(new MapboxMap.MarkerViewAdapter() { + @Nullable + @Override + public MarkerView getView(@NonNull Marker marker) { + if (marker.equals(brazil)) { + return createMarkerView("br", R.drawable.ic_brazil); + } else if (marker.equals(germany)) { + return createMarkerView("de", R.drawable.ic_germany); + } else if (marker.equals(china)) { + return createMarkerView("ch", R.drawable.ic_china); + } else if (marker.equals(us)) { + return createMarkerView("us", R.drawable.ic_us); + } + return null; + } + }); + + // add markers + china = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(31.230416, 121.473701))); + brazil = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(-15.798200, -47.922363))); + us = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(38.907192, -77.036871))); + germany = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(52.520007, 13.404954))); + } + + private MarkerView createMarkerView(String countryAbbrev, @DrawableRes int countryIconRes) { + CustomMarkerView customMarkerView = new CustomMarkerView(this); + customMarkerView.setText(countryAbbrev); + customMarkerView.setImage(countryIconRes); + return customMarkerView; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + @Override + public void onResume() { + super.onResume(); + mMapView.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + mMapView.onPause(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mMapView.onSaveInstanceState(outState); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mMapView.onDestroy(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mMapView.onLowMemory(); + } + +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/view/CustomMarkerView.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/view/CustomMarkerView.java new file mode 100644 index 0000000000..761500aa43 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/view/CustomMarkerView.java @@ -0,0 +1,36 @@ +package com.mapbox.mapboxsdk.testapp.view; + +import android.content.Context; +import android.support.annotation.DrawableRes; +import android.support.annotation.NonNull; +import android.view.LayoutInflater; +import android.widget.ImageView; +import android.widget.TextView; + +import com.mapbox.mapboxsdk.annotations.MarkerView; +import com.mapbox.mapboxsdk.testapp.R; + +public class CustomMarkerView extends MarkerView { + + private TextView textView; + private ImageView imageView; + + public CustomMarkerView(Context context) { + super(context); + init(context); + } + + private void init(Context context) { + LayoutInflater.from(context).inflate(R.layout.view_custom_marker, this); + textView = (TextView) findViewById(R.id.textView); + imageView = (ImageView) findViewById(R.id.imageView); + } + + public void setText(@NonNull String text) { + textView.setText(text); + } + + public void setImage(@DrawableRes int drawableRes) { + imageView.setImageResource(drawableRes); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_brazil.png b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_brazil.png Binary files differnew file mode 100644 index 0000000000..13bce838ff --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_brazil.png diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_china.png b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_china.png Binary files differnew file mode 100644 index 0000000000..d75026aac0 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_china.png diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_germany.png b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_germany.png Binary files differnew file mode 100644 index 0000000000..07707aa0ff --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_germany.png diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_us.png b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_us.png Binary files differnew file mode 100644 index 0000000000..57f3cbe654 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_us.png diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_view.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_view.xml new file mode 100644 index 0000000000..687592502f --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_view.xml @@ -0,0 +1,58 @@ +<?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/container" + 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" + app:access_token="@string/mapbox_access_token" + app:style_url="@string/style_light" + 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_marginBottom="82dp"--> + <!--android:layout_marginRight="@dimen/fab_margin"--> + <!--android:src="@drawable/ic_refresh_24dp"--> + <!--app:backgroundTint="@color/accent"--> + <!--app:layout_anchorGravity="top" />--> + + <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="@color/primary" /> + + </android.support.design.widget.CoordinatorLayout> + + </FrameLayout> + +</LinearLayout> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/view_custom_marker.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/view_custom_marker.xml new file mode 100644 index 0000000000..08caf1df66 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/view_custom_marker.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + + <ImageView + android:id="@id/imageView" + android:layout_width="64dp" + android:layout_height="64dp"/> + + <TextView + android:id="@id/textView" + android:layout_width="wrap_content" + android:textColor="@android:color/white" + android:layout_height="wrap_content" + android:textStyle="bold" + android:layout_centerInParent="true" /> + +</RelativeLayout>
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/ids.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/ids.xml index 9b316d0c31..120bf49fca 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/ids.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/ids.xml @@ -4,6 +4,7 @@ <item name="fab" type="id" /> <item name="progress" type="id" /> <item name="imageView" type="id" /> + <item name="textView" type="id" /> <item name="toolbar" type="id" /> <item name="container" type="id" /> <item name="item_click_support" type="id" /> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index 835b1479f1..840427af09 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -17,7 +17,8 @@ <string name="activity_polyline">Polyline</string> <string name="activity_polygon">Polygon</string> <string name="activity_press_for_marker">Press Map For Marker</string> - + <string name="activity_view_marker">x</string> + <!-- InfoWindow--> <string name="activity_info_window">Standard InfoWindow example</string> <string name="activity_infowindow_adapter">Custom InfoWindow Adapter</string> @@ -76,6 +77,7 @@ <string name="description_scroll_by">Scroll with pixels in x,y direction</string> <string name="description_snapshot">Example to make a snapshot of the map</string> <string name="description_doublemap">2 maps in a view hierarchy</string> + <string name="description_view_marker">x</string> <string name="menuitem_title_concurrent_infowindow">Concurrent Open InfoWindows</string>r <string name="menuitem_title_tracking_mode_dismiss_on_gesture">Dismiss location tracking on gesture</string> |