Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Added traffic plugin example #385

Merged
merged 9 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MapboxAndroidDemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ dependencies {
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.0-beta.5@aar') {
transitive = true
}

// Mapbox traffic plugin
compile 'com.mapbox.mapboxsdk:mapbox-android-plugin-traffic:0.1.0'

// Mapbox Android UI
compile 'com.mapbox.mapboxsdk:mapbox-android-ui:2.1.2'

Expand Down
7 changes: 7 additions & 0 deletions MapboxAndroidDemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity"/>
</activity>
<activity
android:name=".examples.plugins.TrafficPluginActivity"
android:label="@string/activity_plugins_traffic_plugin_title">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity"/>
</activity>
<activity
android:name=".examples.camera.BoundingBoxCameraActivity"
android:label="@string/activity_camera_bounding_box_title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.mapbox.mapboxandroiddemo.examples.mas.StaticImageActivity;
import com.mapbox.mapboxandroiddemo.examples.offline.OfflineManagerActivity;
import com.mapbox.mapboxandroiddemo.examples.offline.SimpleOfflineMapActivity;
import com.mapbox.mapboxandroiddemo.examples.plugins.TrafficPluginActivity;
import com.mapbox.mapboxandroiddemo.examples.query.FeatureCountActivity;
import com.mapbox.mapboxandroiddemo.examples.query.QueryFeatureActivity;
import com.mapbox.mapboxandroiddemo.examples.query.SelectBuildingActivity;
Expand Down Expand Up @@ -343,6 +344,16 @@ private void listItems(int id) {
currentCategory = R.id.nav_extrusions;
break;

case R.id.nav_plugins:
exampleItemModel.add(new ExampleItemModel(
R.string.activity_plugins_traffic_plugin_title,
R.string.activity_plugins_traffic_plugin_description,
new Intent(MainActivity.this, TrafficPluginActivity.class),
R.string.activity_plugins_traffic_plugin_url
));
currentCategory = R.id.nav_plugins;
break;

case R.id.nav_annotations:
exampleItemModel.add(new ExampleItemModel(
R.string.activity_annotation_marker_title,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.mapbox.mapboxandroiddemo.examples.plugins;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.mapbox.mapboxandroiddemo.R;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.plugins.traffic.TrafficPlugin;

/**
* Toggle the Mapbox Traffic plugin to display real-time traffic data on top
* of your map (not all regions supported at the moment).
*/
public class TrafficPluginActivity extends AppCompatActivity {

private MapView mapView;
private MapboxMap map;
private TrafficPlugin trafficPlugin;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview.
Mapbox.getInstance(this, getString(R.string.access_token));

// This contains the MapView in XML and needs to be called after the access token is configured.
setContentView(R.layout.activity_traffic_plugin);

mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
map = mapboxMap;
trafficPlugin = new TrafficPlugin(mapView, mapboxMap);
TrafficPluginActivity.this.trafficPlugin.toggle(); // Enable the traffic view by default
}
});

findViewById(R.id.traffic_toggle_fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (map != null) {
trafficPlugin.toggle();
}
}
});
}

@Override
public void onResume() {
super.onResume();
mapView.onResume();
}

@Override
protected void onStart() {
super.onStart();
mapView.onStart();
}

@Override
protected void onStop() {
super.onStop();
mapView.onStop();
}

@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);
}
}
Original file line number Diff line number Diff line change
@@ -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="M18.92,6.01C18.72,5.42 18.16,5 17.5,5h-11c-0.66,0 -1.21,0.42 -1.42,1.01L3,12v8c0,0.55 0.45,1 1,1h1c0.55,0 1,-0.45 1,-1v-1h12v1c0,0.55 0.45,1 1,1h1c0.55,0 1,-0.45 1,-1v-8l-2.08,-5.99zM6.5,16c-0.83,0 -1.5,-0.67 -1.5,-1.5S5.67,13 6.5,13s1.5,0.67 1.5,1.5S7.33,16 6.5,16zM17.5,16c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5zM5,11l1.5,-4.5h11L19,11L5,11z"/>
</vector>
39 changes: 39 additions & 0 deletions MapboxAndroidDemo/src/main/res/layout/activity_traffic_plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintLeft_toLeftOf="parent"
mapbox:layout_constraintRight_toRightOf="parent"
mapbox:layout_constraintTop_toTopOf="parent"
mapbox:mapbox_cameraTargetLat="1.352506"
mapbox:mapbox_cameraTargetLng="103.842874"
mapbox:mapbox_cameraZoom="9.579712"
mapbox:mapbox_styleUrl="@string/mapbox_style_dark"/>

<android.support.design.widget.FloatingActionButton
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the vector icons black, lets tint it to white instead so it matches the UI a bit more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

android:id="@+id/traffic_toggle_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/ic_directions_car_white_24dp"
mapbox:fabSize="normal"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintRight_toRightOf="parent"/>

</android.support.constraint.ConstraintLayout>
3 changes: 3 additions & 0 deletions MapboxAndroidDemo/src/main/res/menu/menu_activity_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<item
android:id="@+id/nav_extrusions"
android:title="@string/extrusions_category"/>
<item
android:id="@+id/nav_plugins"
android:title="@string/plugins_category"/>
<item
android:id="@+id/nav_camera"
android:title="@string/camera_category"/>
Expand Down
6 changes: 5 additions & 1 deletion MapboxAndroidDemo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<string name="activity_mas_directions_title">Show directions on map</string>
<string name="activity_mas_geocoding_title">Geocoding autocomplete widget</string>
<string name="activity_mas_static_image_title">Download a static map</string>
<string name="activity_plugins_traffic_plugin_title">Display real-time traffic</string>
<string name="activity_mas_simplify_polyline_title">Simplify a polyline</string>
<string name="activity_mas_map_matching_title">Map Matching</string>
<string name="activity_lab_location_picker_title">Location picker</string>
Expand Down Expand Up @@ -150,8 +151,9 @@
<string name="activity_location_animated_icon_description">Use a marker view to mark the users location and add a pulsing animation to it.</string>
<string name="activity_location_customize_user_description">"Adjust the user location icon's colors and padding so it appears lower on the screen."</string>
<string name="activity_mas_directions_description">Use Mapbox Android Services to request directions.</string>
<string name="activity_mas_geocoding_description">"Use Mapbox Android Service's geocoder to convert location text into geographic coordinates."</string>
<string name="activity_mas_geocoding_description">Use Mapbox Android Service\'s geocoder to convert location text into geographic coordinates.</string>
<string name="activity_mas_static_image_description">Use Mapbox Android Services to build a url and download a static map.</string>
<string name="activity_plugins_traffic_plugin_description">Use Mapbox\'s traffic plugin to display live car congestion data on top of a map.</string>
<string name="activity_mas_simplify_polyline_description">Using the polylines utility, simplify a polyline which reduces the amount of coordinates making up the polyline depending on tolerance.</string>
<string name="activity_mas_map_matching_description">Match raw GPS points to the map so they aligns with the roads/pathways.</string>
<string name="activity_lab_location_picker_description">Drop a marker at a specific location and then perform reverse geocoding.</string>
Expand Down Expand Up @@ -214,6 +216,7 @@
<string name="activity_mas_directions_url" translatable="false">http://i.imgur.com/DhQltqB.jpg</string>
<string name="activity_mas_geocoding_url" translatable="false">http://i.imgur.com/mBJGh3P.png</string>
<string name="activity_mas_static_image_url" translatable="false">http://i.imgur.com/COdES0F.png</string>
<string name="activity_plugins_traffic_plugin_url" translatable="false">http://i.imgur.com/HRriOVR.png</string>
<string name="activity_mas_simplify_polyline_url" translatable="false">http://i.imgur.com/uATgul1.png</string>
<string name="activity_mas_map_matching_url" translatable="false">http://i.imgur.com/bWvVbwC.png</string>
<string name="activity_lab_location_picker_url" translatable="false">http://i.imgur.com/0JTVwaa.png</string>
Expand Down Expand Up @@ -361,6 +364,7 @@
<string name="minneapolis">Minneapolis</string>
<string name="miami">Miami</string>
<string name="extrusions_category">3D Extrusions</string>
<string name="plugins_category">Plugins</string>

<!--Landing activity-->
<string name="tv_create_account_button">Create account</string>
Expand Down
2 changes: 1 addition & 1 deletion bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ workflows:

echo "Run tests on firebase:"
gcloud auth activate-service-account --key-file secret.json --project mapbox-android-demo
gcloud beta test android run --type robo --app MapboxAndroidDemo/build/outputs/apk/MapboxAndroidDemo-gpservices-debug.apk --device-ids shamu --os-version-ids 22 --locales en --orientations portrait --timeout 10m
gcloud firebase test android run --type robo --app MapboxAndroidDemo/build/outputs/apk/MapboxAndroidDemo-gpservices-debug.apk --device-ids shamu --os-version-ids 22 --locales en --orientations portrait --timeout 10m
- deploy-to-bitrise-io:
inputs:
- notify_user_groups: none
Expand Down