Skip to content

Commit

Permalink
[markerview] - add initial markerview plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Sep 6, 2018
1 parent 0ecff07 commit 20b35b4
Show file tree
Hide file tree
Showing 13 changed files with 356 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ dependencies {
implementation project(':plugin-offline')
implementation project(':plugin-localization')
implementation project(':plugin-annotation')
implementation project(':plugin-markerview')
}

apply from: "${rootDir}/gradle/checkstyle.gradle"
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity>
<activity
android:name=".activity.markerview.MarkerViewActivity"
android:description="@string/description_markerview"
android:label="@string/title_markerview">
<meta-data
android:name="@string/category"
android:value="@string/category_markerview" />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity>

<service
android:name="com.mapbox.mapboxsdk.plugins.offline.offline.OfflineDownloadService"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.mapbox.mapboxsdk.plugins.testapp.activity.markerview;

import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.plugins.markerview.MarkerView;
import com.mapbox.mapboxsdk.plugins.markerview.MarkerViewManager;
import com.mapbox.mapboxsdk.plugins.testapp.R;

import java.util.Random;

public class MarkerViewActivity extends AppCompatActivity {

private final Random random = new Random();
private MapView mapView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_annotation);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(mapboxMap -> {
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(2));

// create markerview manager
MarkerViewManager markerViewManager = new MarkerViewManager(mapView, mapboxMap);

// create a custom animation marker view
View customView = createCustomAnimationView();
MarkerView animMarkerView = new MarkerView(new LatLng(), customView);
markerViewManager.addMarker(animMarkerView);

// random add marker views across the globe
for (int i = 0; i < 20; i++) {
ImageView imageView = new ImageView(MarkerViewActivity.this);
imageView.setImageResource(R.drawable.ic_car);
imageView.setLayoutParams(new FrameLayout.LayoutParams(56,56));

MarkerView markerView = new MarkerView(createRandomLatLng(), imageView);
markerViewManager.addMarker(markerView);
}
});
}

private View createCustomAnimationView(){
View customView = LayoutInflater.from(this).inflate(R.layout.marker_view, null);
customView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
View icon = customView.findViewById(R.id.imageview);
View animationView = customView.findViewById(R.id.animation_layout);
icon.setOnClickListener(v -> {
ValueAnimator anim = ValueAnimator.ofInt(animationView.getMeasuredWidth(), 350);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.addUpdateListener(valueAnimator -> {
int val = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = animationView.getLayoutParams();
layoutParams.width = val;
animationView.setLayoutParams(layoutParams);
});
anim.setDuration(1250);
anim.start();
});
return customView;
}

private LatLng createRandomLatLng() {
return new LatLng((random.nextDouble() * -180.0) + 90.0,
(random.nextDouble() * -360.0) + 180.0);
}

@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
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);
}
}
26 changes: 26 additions & 0 deletions app/src/main/res/layout/marker_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:background="@color/cardview_dark_background"
app:cardCornerRadius="10dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true"
android:layout_height="32dp">

<ImageView
android:id="@+id/imageview"
app:srcCompat="@drawable/ic_car"
android:layout_width="32dp"
android:layout_alignParentLeft="true"
android:layout_height="32dp"
android:padding="4dp"/>

<FrameLayout
android:id="@+id/animation_layout"
android:layout_width="0dp"
android:layout_toRightOf="@id/imageview"
android:layout_height="32dp"/>

</android.support.v7.widget.CardView>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<string name="category_offline">Offline</string>
<string name="category_localization">Localization</string>
<string name="category_annotation">Annotations</string>
<string name="category_markerview">View synchronisation</string>

<!-- Titles -->
<string name="title_traffic">Traffic Plugin</string>
Expand All @@ -28,6 +29,7 @@
<string name="title_offline_ui_components">Offline Ui Components</string>
<string name="title_location_fragment">Location Fragment</string>
<string name="title_marker">Symbol plugin</string>
<string name="title_markerview">MarkerView plugin</string>

<!-- Descriptions -->
<string name="description_traffic">Add Traffic layers to any Mapbox basemap.</string>
Expand All @@ -45,6 +47,7 @@
<string name="description_offline_ui_components">Shows off the UI components included in the offline plugin.</string>
<string name="description_location_fragment">Show current location in the Fragment</string>
<string name="description_marker">Show symbols on a map</string>
<string name="description_markerview">Synchronise a view on a map</string>

<!-- Buttons -->
<string name="button_location_mode_none">None</string>
Expand Down
1 change: 1 addition & 0 deletions plugin-markerview/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
47 changes: 47 additions & 0 deletions plugin-markerview/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion androidVersions.compileSdkVersion
buildToolsVersion androidVersions.buildToolsVersion

defaultConfig {
minSdkVersion androidVersions.minSdkVersion
targetSdkVersion androidVersions.targetSdkVersion
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

configurations {
javadocDeps
}

lintOptions {
abortOnError false
}

testOptions {
unitTests.returnDefaultValues true
unitTests.all {
jacoco {
includeNoLocationClasses true
}
}
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}

dependencies {
implementation dependenciesList.supportAppcompatV7
implementation dependenciesList.mapboxMapSdk
javadocDeps dependenciesList.mapboxMapSdk
testImplementation dependenciesList.junit
testImplementation dependenciesList.mockito
}

apply from: "${rootDir}/gradle/javadoc.gradle"
apply from: "${rootDir}/gradle/publish.gradle"
apply from: "${rootDir}/gradle/checkstyle.gradle"
apply from: "${rootDir}/gradle/jacoco.gradle"
5 changes: 5 additions & 0 deletions plugin-markerview/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VERSION_NAME=0.1.0-SNAPSHOT
POM_ARTIFACT_ID=mapbox-android-plugin-markerview
POM_NAME=Mapbox Android MarkerView Plugin
POM_DESCRIPTION=Mapbox Android MarkerView Plugin
POM_PACKAGING=aar
21 changes: 21 additions & 0 deletions plugin-markerview/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
2 changes: 2 additions & 0 deletions plugin-markerview/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mapbox.mapboxsdk.plugins.markerview"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.mapbox.mapboxsdk.plugins.markerview;

import android.graphics.PointF;
import android.support.annotation.NonNull;
import android.view.View;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.Projection;

public class MarkerView {

private final View view;
private LatLng latLng;
private Projection projection;
private OnPositionUpdateListener onPositionUpdateListener;

public MarkerView(@NonNull LatLng latLng, @NonNull View view) {
this.latLng = latLng;
this.view = view;
}

public void setLatLng(@NonNull LatLng latLng) {
this.latLng = latLng;
update();
}

public void setOnPositionUpdateListener(OnPositionUpdateListener onPositionUpdateListener) {
this.onPositionUpdateListener = onPositionUpdateListener;
}

void setProjection(Projection projection) {
this.projection = projection;
}

View getView() {
return view;
}

void update() {
PointF point = projection.toScreenLocation(latLng);
if (onPositionUpdateListener != null) {
point = onPositionUpdateListener.onUpdate(point);
}
view.setX(point.x);
view.setY(point.y);
}

public interface OnPositionUpdateListener {
PointF onUpdate(PointF pointF);
}
}
Loading

0 comments on commit 20b35b4

Please sign in to comment.