[android] Add scaling marker activity to TestApp using the View Marker API

Fixes #5409
This commit is contained in:
Antonio Zugaldia
2016-06-19 16:55:43 -04:00
parent b2ce41375c
commit 7fb5c097bf
4 changed files with 212 additions and 0 deletions

View File

@@ -269,6 +269,14 @@
android:name="@string/category"
android:value="@string/category_annotation" />
</activity>
<activity
android:name=".activity.annotation.MarkerViewScaleActivity"
android:description="@string/description_view_marker_scale"
android:label="@string/activity_view_marker_scale">
<meta-data
android:name="@string/category"
android:value="@string/category_annotation" />
</activity>
<activity android:name=".activity.navigation.LocationPickerActivity"
android:description="@string/description_location_picker"

View File

@@ -0,0 +1,141 @@
package com.mapbox.mapboxsdk.testapp.activity.annotation;
import android.os.Bundle;
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 android.widget.SeekBar;
import android.widget.TextView;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.MarkerView;
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
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 java.util.Locale;
public class MarkerViewScaleActivity extends AppCompatActivity {
private MapView mMapView;
private View mMarkerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_marker_view_scale);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
final SeekBar xBar = (SeekBar) findViewById(R.id.seekbar_factor);
TextView xText = (TextView) findViewById(R.id.textview_factor);
xBar.setOnSeekBarChangeListener(new FactorChangeListener(xText));
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
Icon icon = IconFactory.getInstance(MarkerViewScaleActivity.this)
.fromResource(R.drawable.ic_circle);
MarkerView mMarker = mapboxMap.addMarker(new MarkerViewOptions()
.position(new LatLng(38.907192, -77.036871))
.icon(icon)
.flat(true));
mMarkerView = mapboxMap.getMarkerViewManager().getView(mMarker);
}
});
}
@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();
}
private class FactorChangeListener implements SeekBar.OnSeekBarChangeListener {
private TextView xText;
public FactorChangeListener(TextView xText) {
this.xText = xText;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float newScale = getScale(progress);
xText.setText(String.format(Locale.US, "Scale: %.1f", newScale));
if (MarkerViewScaleActivity.this.mMarkerView != null) {
mMarkerView.setScaleX(newScale);
mMarkerView.setScaleY(newScale);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Not used
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Not used
}
private float getScale(int progress) {
float scale = 1.0f * progress / 25;
return scale < 1.0 ? 1.0f : scale;
}
}
}

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.support.v7.widget.Toolbar
android:id="@id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingBottom="8dp"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:text="Scaling in the View Marker API" />
<TextView
android:id="@+id/textview_factor"
android:layout_alignBottom="@+id/seekbar_factor"
android:layout_below="@id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Scale: 1" />
<SeekBar
android:id="@+id/seekbar_factor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:layout_marginLeft="56dp"
android:progress="0" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<com.mapbox.mapboxsdk.maps.MapView
android:id="@id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
app:center_latitude="38.907192"
app:center_longitude="-77.036871"
app:style_url="@string/style_mapbox_streets"
app:zoom="12" />
</RelativeLayout>

View File

@@ -18,6 +18,7 @@
<string name="activity_polygon">Polygon</string>
<string name="activity_press_for_marker">Press Map For Marker</string>
<string name="activity_view_marker">View Marker API</string>
<string name="activity_view_marker_scale">Scaling in the View Marker API</string>
<!-- InfoWindow-->
<string name="activity_info_window">Standard InfoWindow example</string>
@@ -84,8 +85,10 @@
<string name="description_doublemap">2 maps in a view hierarchy</string>
<string name="description_back_to_map">Restart map view after temporarily leaving to another activity</string>
<string name="description_view_marker">Use an Android SDK View as marker</string>
<string name="description_view_marker_scale">Scale a View Marker</string>
<string name="description_dynamic_info_window_adapter">Learn how to create a dynamic custom InfoWindow</string>
<string name="description_location_picker">Use a fixed Marker to select your location</string>
<string name="menuitem_title_concurrent_infowindow">Concurrent Open InfoWindows</string>
<string name="menuitem_title_deselect_markers_on_tap">Deselect Markers On Tap</string>
<string name="menuitem_title_tracking_mode_dismiss_on_gesture">Dismiss location tracking on gesture</string>