-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[markerview] - add initial markerview plugin
- Loading branch information
Showing
13 changed files
with
356 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...ain/java/com/mapbox/mapboxsdk/plugins/testapp/activity/markerview/MarkerViewActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"/> |
50 changes: 50 additions & 0 deletions
50
plugin-markerview/src/main/java/com/mapbox/mapboxsdk/plugins/markerview/MarkerView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.