Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add java formatting #863

Merged
merged 2 commits into from
Jan 18, 2022
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
13 changes: 13 additions & 0 deletions .github/workflows/flutter_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,20 @@ jobs:
- run: chmod +x swiftformat_linux
- name: Check Swift formatting
run: ./swiftformat_linux --swiftversion 4.2 --maxwidth 100 --lint ios

check-java-formatting:
name: "Check Java formatting"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: get google-java-format
run: wget https://github.com/google/google-java-format/releases/download/v1.13.0/google-java-format-1.13.0-all-deps.jar
- run: java --version
- name: Check Java formatting
run: java -jar google-java-format-1.13.0-all-deps.jar --set-exit-if-changed -n $(find . -type f -name "*.java")


build-android:
environment: ANDROID_CI_DOWNLOADS_TOKEN
name: "Build Android apk"
Expand Down
48 changes: 22 additions & 26 deletions android/src/main/java/com/mapbox/mapboxgl/Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,23 @@
import android.content.Context;
import android.graphics.Point;
import android.util.DisplayMetrics;

import com.mapbox.geojson.Polygon;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.log.Logger;
import com.mapbox.mapboxsdk.maps.MapboxMap;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Conversions between JSON-like values and MapboxMaps data types.
*/
/** Conversions between JSON-like values and MapboxMaps data types. */
class Convert {

private final static String TAG = "Convert";
private static final String TAG = "Convert";

static boolean toBoolean(Object o) {
return (Boolean) o;
Expand Down Expand Up @@ -57,15 +51,17 @@ static CameraUpdate toCameraUpdate(Object o, MapboxMap mapboxMap, float density)
case "newLatLng":
return CameraUpdateFactory.newLatLng(toLatLng(data.get(1)));
case "newLatLngBounds":
return CameraUpdateFactory.newLatLngBounds(toLatLngBounds(data.get(1)), toPixels(data.get(2), density),
toPixels(data.get(3), density), toPixels(data.get(4), density), toPixels(data.get(5), density));
return CameraUpdateFactory.newLatLngBounds(
toLatLngBounds(data.get(1)),
toPixels(data.get(2), density),
toPixels(data.get(3), density),
toPixels(data.get(4), density),
toPixels(data.get(5), density));
case "newLatLngZoom":
return CameraUpdateFactory.newLatLngZoom(toLatLng(data.get(1)), toFloat(data.get(2)));
case "scrollBy":
mapboxMap.scrollBy(
toFractionalPixels(data.get(1), density),
toFractionalPixels(data.get(2), density)
);
toFractionalPixels(data.get(1), density), toFractionalPixels(data.get(2), density));
return null;
case "zoomBy":
if (data.size() == 2) {
Expand Down Expand Up @@ -143,12 +139,11 @@ static List<LatLng> toLatLngList(Object o, boolean flippedOrder) {
}
final List<?> data = toList(o);
List<LatLng> latLngList = new ArrayList<>();
for (int i=0; i<data.size(); i++) {
for (int i = 0; i < data.size(); i++) {
final List<?> coords = toList(data.get(i));
if(flippedOrder){
if (flippedOrder) {
latLngList.add(new LatLng(toDouble(coords.get(1)), toDouble(coords.get(0))));
}
else{
} else {
latLngList.add(new LatLng(toDouble(coords.get(0)), toDouble(coords.get(1))));
}
}
Expand All @@ -173,7 +168,8 @@ static Polygon interpretListLatLng(List<List<LatLng>> geometry) {
for (List<LatLng> innerGeometry : geometry) {
List<com.mapbox.geojson.Point> innerPoints = new ArrayList<>(innerGeometry.size());
for (LatLng latLng : innerGeometry) {
innerPoints.add(com.mapbox.geojson.Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
innerPoints.add(
com.mapbox.geojson.Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
}
points.add(innerPoints);
}
Expand Down Expand Up @@ -229,8 +225,8 @@ static void interpretMapboxMapOptions(Object o, MapboxMapOptionsSink sink, Conte
if (minMaxZoomPreference != null) {
final List<?> zoomPreferenceData = toList(minMaxZoomPreference);
sink.setMinMaxZoomPreference( //
toFloatWrapper(zoomPreferenceData.get(0)), //
toFloatWrapper(zoomPreferenceData.get(1)));
toFloatWrapper(zoomPreferenceData.get(0)), //
toFloatWrapper(zoomPreferenceData.get(1)));
}
final Object rotateGesturesEnabled = data.get("rotateGesturesEnabled");
if (rotateGesturesEnabled != null) {
Expand Down Expand Up @@ -265,30 +261,30 @@ static void interpretMapboxMapOptions(Object o, MapboxMapOptionsSink sink, Conte
sink.setMyLocationRenderMode(toInt(myLocationRenderMode));
}
final Object logoViewMargins = data.get("logoViewMargins");
if(logoViewMargins != null){
if (logoViewMargins != null) {
final List logoViewMarginsData = toList(logoViewMargins);
final Point point = toPoint(logoViewMarginsData, metrics.density);
sink.setLogoViewMargins(point.x, point.y);
}
final Object compassGravity = data.get("compassViewPosition");
if(compassGravity != null){
if (compassGravity != null) {
sink.setCompassGravity(toInt(compassGravity));
}
final Object compassViewMargins = data.get("compassViewMargins");
if(compassViewMargins != null){
if (compassViewMargins != null) {
final List compassViewMarginsData = toList(compassViewMargins);
final Point point = toPoint(compassViewMarginsData, metrics.density);
sink.setCompassViewMargins(point.x, point.y);
}
final Object attributionButtonGravity = data.get("attributionButtonPosition");
if(attributionButtonGravity != null){
if (attributionButtonGravity != null) {
sink.setAttributionButtonGravity(toInt(attributionButtonGravity));
}
final Object attributionButtonMargins = data.get("attributionButtonMargins");
if(attributionButtonMargins != null){
if (attributionButtonMargins != null) {
final List attributionButtonMarginsData = toList(attributionButtonMargins);
final Point point = toPoint(attributionButtonMarginsData, metrics.density);
sink.setAttributionButtonMargins(point.x, point.y);
}
}
}
}
Loading