Skip to content

Commit

Permalink
Building plugin (#26)
Browse files Browse the repository at this point in the history
* # This is a combination of 5 commits.
# This is the 1st commit message:
add Building plugin

# The commit message #2 will be skipped:

#	fixed issues reviewed by me

# The commit message #3 will be skipped:

#	fixed bitrise script

# The commit message #4 will be skipped:

#	added DDS for building height

# The commit message #5 will be skipped:

#	removed commented out code

* cleaned up gradle file

* updated Makefile

* added optional constructor param to place buildings below layer

* added comment with more information
  • Loading branch information
tobrun authored and Cameron Mace committed Jul 18, 2017
1 parent 95a74c5 commit c39ff12
Show file tree
Hide file tree
Showing 18 changed files with 596 additions and 88 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@ checkstyle:
test:
cd plugins; ./gradlew :traffic:test
cd plugins; ./gradlew :locationlayer:test
cd plugins; ./gradlew :building:test

build-release:
cd plugins; ./gradlew :traffic:assembleRelease
cd plugins; ./gradlew :locationlayer:assembleRelease
cd plugins; ./gradlew :building:assembleRelease

javadoc:
# Android modules
# Output is ./mapbox/*/build/docs/javadoc/release
cd plugins; ./gradlew :traffic:javadocrelease
cd plugins; ./gradlew :locationlayer:javadocrelease
cd plugins; ./gradlew :building:javadocrelease

publish:
cd plugins; export IS_LOCAL_DEVELOPMENT=false; ./gradlew :traffic:uploadArchives
cd plugins; export IS_LOCAL_DEVELOPMENT=false; ./gradlew :locationlayer:uploadArchives
cd plugins; export IS_LOCAL_DEVELOPMENT=false; ./gradlew :building:uploadArchives

publish-local:
# This publishes to ~/.m2/repository/com/mapbox/mapboxsdk
cd plugins; export IS_LOCAL_DEVELOPMENT=true; ./gradlew :traffic:uploadArchives
cd plugins; export IS_LOCAL_DEVELOPMENT=true; ./gradlew :locationlayer:uploadArchives
cd plugins; export IS_LOCAL_DEVELOPMENT=true; ./gradlew :building:uploadArchives
107 changes: 54 additions & 53 deletions plugins/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,71 +1,72 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
applicationId "com.mapbox.mapboxsdk.plugins.testapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
defaultConfig {
applicationId "com.mapbox.mapboxsdk.plugins.testapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
debug {
testCoverageEnabled true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
buildTypes {
debug {
testCoverageEnabled true
}

dexOptions {
maxProcessCount 8
javaMaxHeapSize "2g"
preDexLibraries true
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

dexOptions {
maxProcessCount 8
javaMaxHeapSize "2g"
preDexLibraries true
}
}

dependencies {
// Support libraries
compile rootProject.ext.dep.supportAnnotations
compile rootProject.ext.dep.supportAppcompatV7
compile rootProject.ext.dep.supportDesign
compile rootProject.ext.dep.supportRecyclerView
compile rootProject.ext.dep.supportConstraintLayout
// Support libraries
compile rootProject.ext.dep.supportAnnotations
compile rootProject.ext.dep.supportAppcompatV7
compile rootProject.ext.dep.supportDesign
compile rootProject.ext.dep.supportRecyclerView
compile rootProject.ext.dep.supportConstraintLayout

// Unit testing
testCompile rootProject.ext.dep.junit
testCompile rootProject.ext.dep.mockito
// Unit testing
testCompile rootProject.ext.dep.junit
testCompile rootProject.ext.dep.mockito

// Instrumentation testing
androidTestCompile(rootProject.ext.dep.testRunner, {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile(rootProject.ext.dep.testRules, {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile(rootProject.ext.dep.testEspressoCore, {
exclude group: 'com.android.support', module: 'support-annotations'
})
// Instrumentation testing
androidTestCompile(rootProject.ext.dep.testRunner, {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile(rootProject.ext.dep.testRules, {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile(rootProject.ext.dep.testEspressoCore, {
exclude group: 'com.android.support', module: 'support-annotations'
})

// Square crew
compile rootProject.ext.dep.timber
compile rootProject.ext.dep.butterKnife
annotationProcessor rootProject.ext.dep.butterKnifeProcessor
// Square crew
compile rootProject.ext.dep.timber
compile rootProject.ext.dep.butterKnife
annotationProcessor rootProject.ext.dep.butterKnifeProcessor

// Leak canary
debugCompile rootProject.ext.dep.leakCanaryDebug
releaseCompile rootProject.ext.dep.leakCanaryRelease
testCompile rootProject.ext.dep.leakCanaryTest
// Leak canary
debugCompile rootProject.ext.dep.leakCanaryDebug
releaseCompile rootProject.ext.dep.leakCanaryRelease
testCompile rootProject.ext.dep.leakCanaryTest

// Plugin modules
compile project(':traffic')
compile project(':locationlayer')
// Plugin modules
compile project(':traffic')
compile project(':locationlayer')
compile project(':building')
}

apply from: '../checkstyle.gradle'
Expand Down
13 changes: 12 additions & 1 deletion plugins/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@
android:label="@string/title_traffic">
<meta-data
android:name="@string/category"
android:value="@string/category_runtime_styling"/>
android:value="@string/category_navigation"/>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
<activity
android:name=".activity.BuildingActivity"
android:description="@string/description_building"
android:label="@string/title_building">
<meta-data
android:name="@string/category"
android:value="@string/category_extrusions"/>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public void onCreate() {
LeakCanary.install(this);
initializeLogger();
Mapbox.getInstance(this, getString(R.string.mapbox_access_token));
Timber.plant(new Timber.DebugTree());
}

private void initializeLogger() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
package com.mapbox.mapboxsdk.plugins.testapp.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.SeekBar;

import com.mapbox.androidsdk.plugins.building.BuildingPlugin;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.plugins.testapp.R;
import com.mapbox.mapboxsdk.style.light.Light;
import com.mapbox.mapboxsdk.style.light.Position;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import timber.log.Timber;

/**
* Activity showcasing building plugin integration
*/
public class BuildingActivity extends AppCompatActivity implements OnMapReadyCallback {

@BindView(R.id.mapView)
MapView mapView;

@BindView(R.id.fabBuilding)
View fab;

@BindView(R.id.seekbarLightRadialCoordinate)
SeekBar seekbarRadialCoordinate;

@BindView(R.id.seekbarLightAzimuthalAngle)
SeekBar seekbarAzimuthalAngle;

@BindView(R.id.seekbarLightPolarAngle)
SeekBar seekbarPolarAngle;

private MapboxMap mapboxMap;
private BuildingPlugin buildingPlugin;
private boolean isEnabled;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_building);
ButterKnife.bind(this);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}

@Override
public void onMapReady(MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
buildingPlugin = new BuildingPlugin(mapView, mapboxMap);
buildingPlugin.setMinZoomLevel(15);
fab.setVisibility(View.VISIBLE);
initLightSeekbar();
}

// See https://en.wikipedia.org/wiki/Spherical_coordinate_system for more information on these values
private void initLightSeekbar() {
seekbarRadialCoordinate.setMax(24); // unknown?
seekbarAzimuthalAngle.setMax(180); // unknown?
seekbarPolarAngle.setMax(180); // polar angle ranges from 0 to 180 degrees

PositionChangeListener positionChangeListener = new PositionChangeListener();
seekbarRadialCoordinate.setOnSeekBarChangeListener(positionChangeListener);
seekbarAzimuthalAngle.setOnSeekBarChangeListener(positionChangeListener);
seekbarPolarAngle.setOnSeekBarChangeListener(positionChangeListener);
}

@OnClick(R.id.fabBuilding)
public void onBuildingFabClicked() {
if (mapboxMap != null) {
isEnabled = !isEnabled;
buildingPlugin.setVisibility(isEnabled);
Timber.e("Building plugin is enabled :%s", isEnabled);
}
}

private class PositionChangeListener implements SeekBar.OnSeekBarChangeListener {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
invalidateLightPosition();
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Only listening to positionChange for onProgress.
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Only listening to positionChange for onProgress.
}
}

private void invalidateLightPosition() {
Light light = mapboxMap.getLight();
float radialCoordinate = (float) seekbarRadialCoordinate.getProgress() / 20;
float azimuthalAngle = seekbarAzimuthalAngle.getProgress();
float polarAngle = seekbarPolarAngle.getProgress();
light.setPosition(new Position(radialCoordinate, azimuthalAngle, polarAngle));
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_building_min_zoom:
buildingPlugin.setMinZoomLevel(14);
return true;
case R.id.menu_building_opacity:
buildingPlugin.setOpacity(1.0f);
return true;
case R.id.menu_building_color:
buildingPlugin.setColor(Color.RED);
return true;
case R.id.menu_building_style:
mapboxMap.setStyle(Style.DARK);
return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_building, menu);
return super.onCreateOptionsMenu(menu);
}

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

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

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

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

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}

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

@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}
9 changes: 9 additions & 0 deletions plugins/app/src/main/res/drawable/ic_business.xml
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="#FF000000"
android:pathData="M12,7L12,3L2,3v18h20L22,7L12,7zM6,19L4,19v-2h2v2zM6,15L4,15v-2h2v2zM6,11L4,11L4,9h2v2zM6,7L4,7L4,5h2v2zM10,19L8,19v-2h2v2zM10,15L8,15v-2h2v2zM10,11L8,11L8,9h2v2zM10,7L8,7L8,5h2v2zM20,19h-8v-2h2v-2h-2v-2h2v-2h-2L12,9h8v10zM18,11h-2v2h2v-2zM18,15h-2v2h2v-2z"/>
</vector>
Loading

0 comments on commit c39ff12

Please sign in to comment.