[android] #3276 - WIP Android View Annotations, showing an Android SDK view on the screen
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 745 B |
Binary file not shown.
|
After Width: | Height: | Size: 168 B |
Binary file not shown.
|
After Width: | Height: | Size: 323 B |
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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" />
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user