[android] added user dot customization example

Fixes #4896
This commit is contained in:
Cameron Mace
2016-04-28 17:10:44 -04:00
committed by Tobrun
parent 89afbc648e
commit 90cd425c5a
5 changed files with 212 additions and 0 deletions

View File

@@ -147,6 +147,14 @@
android:name="@string/category"
android:value="@string/category_userlocation" />
</activity>
<activity
android:name=".activity.userlocation.MyLocationDotColor"
android:description="@string/description_user_location_dot_color"
android:label="@string/activity_user_dot_color">
<meta-data
android:name="@string/category"
android:value="@string/category_userlocation" />
</activity>
<activity
android:name=".activity.userlocation.MyLocationToggleActivity"
android:description="@string/description_user_location_toggle"

View File

@@ -0,0 +1,145 @@
package com.mapbox.mapboxsdk.testapp.activity.userlocation;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.Nullable;
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.location.LocationListener;
import com.mapbox.mapboxsdk.location.LocationServices;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.R;
public class MyLocationDotColor extends AppCompatActivity implements LocationListener {
private MapView mapView;
private MapboxMap map;
private Location location;
private boolean firstRun;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_location_dot_color);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
location = LocationServices.getLocationServices(this).getLastLocation();
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 mapboxMap) {
map = mapboxMap;
mapboxMap.setMyLocationEnabled(true);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom((location != null ? new LatLng(location) : new LatLng(0, 0)), 15));
}
});
// handle default button clicks
findViewById(R.id.defaultUserDotColoringButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
map.getMyLocationViewSettings().setAccuracyTintColor(ContextCompat.getColor(MyLocationDotColor.this, R.color.my_location_ring));
map.getMyLocationViewSettings().setForegroundTintColor(ContextCompat.getColor(MyLocationDotColor.this, R.color.primaryDark));
}
});
// handle tint user dot button clicks
findViewById(R.id.tintUserDotButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
map.getMyLocationViewSettings().setAccuracyTintColor(ContextCompat.getColor(MyLocationDotColor.this, R.color.mapbox_green));
map.getMyLocationViewSettings().setForegroundTintColor(ContextCompat.getColor(MyLocationDotColor.this, R.color.mapbox_green));
}
});
// handle tint accuracy ring button clicks
findViewById(R.id.UserAccuracyRingTintButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
map.getMyLocationViewSettings().setAccuracyTintColor(ContextCompat.getColor(MyLocationDotColor.this, R.color.accent));
map.getMyLocationViewSettings().setForegroundTintColor(ContextCompat.getColor(MyLocationDotColor.this, R.color.mapbox_blue));
}
});
LocationServices.getLocationServices(this).addLocationListener(this);
}
@Override
public void onLocationChanged(Location location) {
if (map != null && firstRun) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location), 15));
firstRun = false;
}
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -0,0 +1,53 @@
<?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: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" />
<com.mapbox.mapboxsdk.maps.MapView
android:id="@id/mapView"
android:layout_below="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:style_url="@string/style_mapbox_streets"
app:scroll_enabled="false" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="@+id/defaultUserDotColoringButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_user_dot_default" />
<Button
android:id="@+id/tintUserDotButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_user_dot_tint" />
<Button
android:id="@+id/UserAccuracyRingTintButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_user_accuracy_ring_tint" />
</LinearLayout>
</RelativeLayout>

View File

@@ -4,4 +4,5 @@
<color name="primaryDark">#166B83</color>
<color name="accent">#E55E5E</color>
<color name="white">#F9F9F9</color>
<color name="mapbox_green">#56B881</color>
</resources>

View File

@@ -37,6 +37,7 @@
<string name="activity_snapshot">Snapshot Activity</string>
<string name="activity_user_tracking_mode">User tracking mode</string>
<string name="activity_user_tracking_customization">User location customization</string>
<string name="activity_user_dot_color">User location dot color</string>
<string name="activity_user_location_toggle">User location toggle</string>
<string name="activity_custom_layer">Custom Layer</string>
<string name="activity_map_padding">Map Padding</string>
@@ -47,6 +48,7 @@
<!-- Description -->
<string name="description_user_location_tracking">Tracks the location of the user</string>
<string name="description_user_location_customization">Customize the location of the user</string>
<string name="description_user_location_dot_color">Customize the user dot color</string>
<string name="description_user_location_toggle">Toggle location of the user on and off</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>
@@ -98,6 +100,9 @@
<string name="button_camera_ease">Ease</string>
<string name="button_camera_animate">Animate</string>
<string name="button_make_snapshot">Snapshot</string>
<string name="button_user_dot_default">Default</string>
<string name="button_user_dot_tint">Tint dot</string>
<string name="button_user_accuracy_ring_tint">Tint ring</string>
<string name="label_fps">FPS:</string>