Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Android conversions #915

Merged
merged 17 commits into from
Feb 26, 2015
Merged
380 changes: 301 additions & 79 deletions android/cpp/jni.cpp

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions android/java/MapboxGLAndroidSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ android {

lintOptions {
checkAllWarnings true
disable 'IconMissingDensityFolder'
warningsAsErrors true
disable 'InvalidPackage'
}

buildTypes {
Expand Down Expand Up @@ -83,8 +84,7 @@ android.libraryVariants.all { variant ->
failOnError = false
destinationDir = new File(destinationDir, variant.baseName)
source = files(variant.javaCompile.source)
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
classpath = files(variant.javaCompile.classpath.files) + files(android.bootClasspath)
options.links("http://docs.oracle.com/javase/7/docs/api/")
options.links("http://d.android.com/reference/")
exclude '**/R.html', '**/R.*.html'
Expand Down Expand Up @@ -234,9 +234,8 @@ afterEvaluate { project ->
}

task androidJavadocs(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath = files(android.bootClasspath)
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
Expand Down
4 changes: 4 additions & 0 deletions android/java/MapboxGLAndroidSDK/lint.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<lint>
<!-- Ignore errors caused by OkHTTP -->
<issue id="InvalidPackage" severity="ignore">
<ignore path="*/okio-1.2.0.jar" />
</issue>
</lint>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mapbox.mapboxgl.lib">
package="com.mapbox.mapboxgl.views">

<uses-feature android:glEsVersion="0x00020000" android:required="true" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mapbox.mapboxgl.lib.constants;
package com.mapbox.mapboxgl.constants;

public interface GeoConstants {
public class GeoConstants {
// http://en.wikipedia.org/wiki/Earth_radius#Equatorial_radius
public static final int RADIUS_EARTH_METERS = 6378137;
public static final double MIN_LATITUDE = -85.05112878;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mapbox.mapboxgl.constants;

public class MathConstants {
public static final double DEG2RAD = (Math.PI / 180.0);
public static final double RAD2DEG = (180.0 / Math.PI);

public static final double PI = Math.PI;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.mapbox.mapboxgl.lib.geometry;
package com.mapbox.mapboxgl.geometry;

import android.os.Parcel;
import android.os.Parcelable;

import java.io.Serializable;
import java.util.List;

Expand All @@ -10,8 +11,6 @@
*/
public final class BoundingBox implements Parcelable, Serializable {

static final long serialVersionUID = 2L;

private final double mLatNorth;
private final double mLatSouth;
private final double mLonEast;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mapbox.mapboxgl.lib.geometry;
package com.mapbox.mapboxgl.geometry;

/**
* Implementation of iOS MKCoordinateRegion
Expand All @@ -7,7 +7,7 @@ public class CoordinateRegion {
private LatLng center;
private CoordinateSpan span;

public CoordinateRegion(LatLng center, CoordinateSpan span) {
public CoordinateRegion(final LatLng center, final CoordinateSpan span) {
this.center = center;
this.span = span;
}
Expand All @@ -16,15 +16,15 @@ public LatLng getCenter() {
return center;
}

public void setCenter(LatLng center) {
public void setCenter(final LatLng center) {
this.center = center;
}

public CoordinateSpan getSpan() {
return span;
}

public void setSpan(CoordinateSpan span) {
public void setSpan(final CoordinateSpan span) {
this.span = span;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.mapbox.mapboxgl.lib.geometry;
package com.mapbox.mapboxgl.geometry;

/**
* Implementation of iOS MKCoordinateSpan
*/
public final class CoordinateSpan {
public class CoordinateSpan {

private double latitudeSpan;
private double longitudeSpan;

public CoordinateSpan(double latitudeSpan, double longitudeSpan) {
public CoordinateSpan(final double latitudeSpan, final double longitudeSpan) {
this.latitudeSpan = latitudeSpan;
this.longitudeSpan = longitudeSpan;
}
Expand All @@ -17,15 +17,15 @@ public double getLatitudeSpan() {
return latitudeSpan;
}

public void setLatitudeSpan(double latitudeSpan) {
public void setLatitudeSpan(final double latitudeSpan) {
this.latitudeSpan = latitudeSpan;
}

public double getLongitudeSpan() {
return longitudeSpan;
}

public void setLongitudeSpan(double longitudeSpan) {
public void setLongitudeSpan(final double longitudeSpan) {
this.longitudeSpan = longitudeSpan;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mapbox.mapboxgl.lib.geometry;
package com.mapbox.mapboxgl.geometry;

/**
* A Latitude, Longitude point.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mapbox.mapboxgl.geometry;

public interface IProjectedMeters {
double getNorthing();

double getEasting();
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.mapbox.mapboxgl.lib.geometry;
package com.mapbox.mapboxgl.geometry;

import android.location.Location;
import android.os.Parcel;
import android.os.Parcelable;
import com.mapbox.mapboxgl.lib.constants.GeoConstants;
import com.mapbox.mapboxgl.lib.constants.MathConstants;

import com.mapbox.mapboxgl.constants.GeoConstants;
import com.mapbox.mapboxgl.constants.MathConstants;

import java.io.Serializable;

public class LatLng implements ILatLng, GeoConstants, MathConstants, Parcelable, Serializable {
public class LatLng implements ILatLng, Parcelable, Serializable {

public static final Parcelable.Creator<LatLng> CREATOR = new Parcelable.Creator<LatLng>() {
public LatLng createFromParcel(Parcel in) {
Expand All @@ -19,14 +21,14 @@ public LatLng[] newArray(int size) {
}
};

private double longitude;
private double latitude;
private double altitude = 0f;
private double longitude;
private double altitude = 0.0;

/**
* Construct a new latitude, longitude point given float arguments
* @param latitude Latitude in degrees
* @param longitude Longitude in degress
* @param longitude Longitude in degrees
*/
public LatLng(double latitude, double longitude) {
this.latitude = latitude;
Expand All @@ -39,7 +41,7 @@ public LatLng(double latitude, double longitude) {
* @param longitude Longitude in degress
* @param altitude Altitude in meters
*/
public LatLng(final double latitude, final double longitude, final double altitude) {
public LatLng(double latitude, double longitude, double altitude) {
this.latitude = latitude;
this.longitude = longitude;
this.altitude = altitude;
Expand All @@ -49,23 +51,23 @@ public LatLng(final double latitude, final double longitude, final double altitu
* Transform a Location into a LatLng point
* @param location Android Location
*/
public LatLng(final Location location) {
public LatLng(Location location) {
this(location.getLatitude(), location.getLongitude(), location.getAltitude());
}

/**
* Clone an existing latitude longitude point
* @param aLatLng LatLng
*/
public LatLng(final LatLng aLatLng) {
public LatLng(LatLng aLatLng) {
this.latitude = aLatLng.latitude;
this.longitude = aLatLng.longitude;
this.altitude = aLatLng.altitude;
}

protected LatLng(Parcel in) {
longitude = in.readDouble();
latitude = in.readDouble();
longitude = in.readDouble();
altitude = in.readDouble();
}

Expand All @@ -85,30 +87,46 @@ public double getAltitude() {
}

@Override
public boolean equals(final Object obj) {
if (obj == null) {
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (obj == this) {
return true;

LatLng latLng = (LatLng) o;

if (Double.compare(latLng.altitude, altitude) != 0) {
return false;
}
if (!obj.getClass().equals(this.getClass())) {

if (Double.compare(latLng.latitude, latitude) != 0) {
return false;
}
final LatLng rhs = (LatLng) obj;
return rhs.latitude == this.latitude
&& rhs.longitude == this.longitude
&& rhs.altitude == this.altitude;
if (Double.compare(latLng.longitude, longitude) != 0) {
return false;
}

return true;
}

@Override
public int hashCode() {
return (int) (37.0 * (17.0 * latitude * 1E6d + longitude * 1E6d) + altitude);
int result;
long temp;
temp = Double.doubleToLongBits(latitude);
result = (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(longitude);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(altitude);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}

@Override
public String toString() {
return "LatLng [longitude=" + longitude + ", latitude=" + latitude + "]";
return "LatLng [longitude=" + longitude + ", latitude=" + latitude + ", altitude=" + altitude + "]";
}

@Override
Expand All @@ -118,8 +136,8 @@ public int describeContents() {

@Override
public void writeToParcel(Parcel out, int flags) {
out.writeDouble(longitude);
out.writeDouble(latitude);
out.writeDouble(longitude);
out.writeDouble(altitude);
}

Expand All @@ -128,12 +146,12 @@ public void writeToParcel(Parcel out, int flags) {
* @param other Other LatLng to compare to
* @return distance in meters
*/
public int distanceTo(final LatLng other) {
public double distanceTo(LatLng other) {

final double a1 = DEG2RAD * this.latitude;
final double a2 = DEG2RAD * this.longitude;
final double b1 = DEG2RAD * other.getLatitude();
final double b2 = DEG2RAD * other.getLongitude();
final double a1 = MathConstants.DEG2RAD * this.latitude;
final double a2 = MathConstants.DEG2RAD * this.longitude;
final double b1 = MathConstants.DEG2RAD * other.getLatitude();
final double b2 = MathConstants.DEG2RAD * other.getLongitude();

final double cosa1 = Math.cos(a1);
final double cosb1 = Math.cos(b1);
Expand All @@ -143,6 +161,6 @@ public int distanceTo(final LatLng other) {
final double t3 = Math.sin(a1) * Math.sin(b1);
final double tt = Math.acos(t1 + t2 + t3);

return (int) (RADIUS_EARTH_METERS * tt);
return GeoConstants.RADIUS_EARTH_METERS * tt;
}
}
Loading