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

Cherry pick for v5.3.1 #10887

Merged
merged 8 commits into from
Jan 10, 2018
11 changes: 11 additions & 0 deletions platform/android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

Mapbox welcomes participation and contributions from everyone. If you'd like to do so please see the [`Contributing Guide`](https://github.com/mapbox/mapbox-gl-native/blob/master/CONTRIBUTING.md) first to get started.

## 5.3.1 - January 10, 2018
- Blacklist binary program loading for Vivante GC4000 GPUs [#10862](https://github.com/mapbox/mapbox-gl-native/pull/10862)
- Support Genymotion [#10841](https://github.com/mapbox/mapbox-gl-native/pull/10841)
- Getting bitmap from drawable fix [#10763](https://github.com/mapbox/mapbox-gl-native/pull/10763)
- Use US locale when converting between int color and RGBA string [#10810](https://github.com/mapbox/mapbox-gl-native/pull/10810)
- Harden map destruction [#10811](https://github.com/mapbox/mapbox-gl-native/pull/10811)
- RTL support [#10828](https://github.com/mapbox/mapbox-gl-native/pull/10828)
- Allow configuring Http url logging when a request fails [#10830](https://github.com/mapbox/mapbox-gl-native/pull/10830)
- Don't send double tap event multiple times for telemetry [#10854](https://github.com/mapbox/mapbox-gl-native/pull/10854)
- Use the correct cancelable callback after posting cancel [#10871](https://github.com/mapbox/mapbox-gl-native/pull/10871)

## 5.3.0 - December 20, 2017
- Add support for TinySDF [#10706](https://github.com/mapbox/mapbox-gl-native/pull/10706)
- Save restore MyLocationViewSettings [#10746](https://github.com/mapbox/mapbox-gl-native/pull/10746)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@
import okhttp3.internal.Util;
import timber.log.Timber;

import static android.util.Log.DEBUG;
import static android.util.Log.INFO;
import static android.util.Log.WARN;

class HTTPRequest implements Callback {

private static OkHttpClient mClient = new OkHttpClient.Builder().dispatcher(getDispatcher()).build();
private static boolean logEnabled = true;
private static boolean logRequestUrl = false;

private String USER_AGENT_STRING = null;

private static final int CONNECTION_ERROR = 0;
Expand Down Expand Up @@ -97,7 +103,7 @@ private HTTPRequest(long nativePtr, String resourceUrl, String etag, String modi
mCall = mClient.newCall(mRequest);
mCall.enqueue(this);
} catch (Exception exception) {
onFailure(exception);
handleFailure(mCall, exception);
}
}

Expand Down Expand Up @@ -134,7 +140,7 @@ public void onResponse(Call call, Response response) throws IOException {
try {
body = response.body().bytes();
} catch (IOException ioException) {
onFailure(ioException);
onFailure(call, ioException);
// throw ioException;
return;
} finally {
Expand All @@ -157,29 +163,16 @@ public void onResponse(Call call, Response response) throws IOException {

@Override
public void onFailure(Call call, IOException e) {
onFailure(e);
handleFailure(call, e);
}

private void onFailure(Exception e) {
int type = PERMANENT_ERROR;
if ((e instanceof NoRouteToHostException) || (e instanceof UnknownHostException) || (e instanceof SocketException)
|| (e instanceof ProtocolException) || (e instanceof SSLException)) {
type = CONNECTION_ERROR;
} else if ((e instanceof InterruptedIOException)) {
type = TEMPORARY_ERROR;
}

private void handleFailure(Call call, Exception e) {
String errorMessage = e.getMessage() != null ? e.getMessage() : "Error processing the request";
int type = getFailureType(e);

if (logEnabled) {
if (type == TEMPORARY_ERROR) {
Timber.d("Request failed due to a temporary error: %s", errorMessage);
} else if (type == CONNECTION_ERROR) {
Timber.i("Request failed due to a connection error: %s", errorMessage);
} else {
// PERMANENT_ERROR
Timber.w("Request failed due to a permanent error: %s", errorMessage);
}
String requestUrl = call.request().url().toString();
logFailure(type, errorMessage, requestUrl);
}

mLock.lock();
Expand All @@ -189,6 +182,26 @@ private void onFailure(Exception e) {
mLock.unlock();
}

private int getFailureType(Exception e) {
if ((e instanceof NoRouteToHostException) || (e instanceof UnknownHostException) || (e instanceof SocketException)
|| (e instanceof ProtocolException) || (e instanceof SSLException)) {
return CONNECTION_ERROR;
} else if ((e instanceof InterruptedIOException)) {
return TEMPORARY_ERROR;
}
return PERMANENT_ERROR;
}

private void logFailure(int type, String errorMessage, String requestUrl) {
Timber.log(
type == TEMPORARY_ERROR ? DEBUG : type == CONNECTION_ERROR ? INFO : WARN,
"Request failed due to a %s error: %s %s",
type == TEMPORARY_ERROR ? "temporary" : type == CONNECTION_ERROR ? "connection" : "permanent",
errorMessage,
logRequestUrl ? requestUrl : ""
);
}

private String getUserAgent() {
if (USER_AGENT_STRING == null) {
return USER_AGENT_STRING = Util.toHumanReadableAscii(
Expand Down Expand Up @@ -217,4 +230,8 @@ private String getApplicationIdentifier() {
static void enableLog(boolean enabled) {
logEnabled = enabled;
}

static void enablePrintRequestUrlOnFailure(boolean enabled) {
logRequestUrl = enabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class HttpRequestUtil {

/**
* Set the log state of HttpRequest.
* Set the log state of HttpRequest. Default value is true.
* <p>
* This configuration will outlast the lifecycle of the Map.
* </p>
Expand All @@ -16,4 +16,20 @@ public class HttpRequestUtil {
public static void setLogEnabled(boolean enabled) {
HTTPRequest.enableLog(enabled);
}

/**
* Enable printing of the request url when an error occurred. Default value is false.
* <p>
* Requires {@link #setLogEnabled(boolean)} to be activated.
* </p>
* <p>
* This configuration will outlast the lifecycle of the Map.
* </p>
*
* @param enabled True will print urls, false will disable
*/
public static void setPrintRequestUrlOnFaillure(boolean enabled) {
HTTPRequest.enablePrintRequestUrlOnFailure(enabled);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -296,51 +296,43 @@ private void initialiseDrawingSurface(MapboxMapOptions options) {
mapRenderer = new TextureViewMapRenderer(getContext(), textureView, options.getLocalIdeographFontFamily()) {
@Override
protected void onSurfaceCreated(GL10 gl, EGLConfig config) {
MapView.this.post(new Runnable() {
@Override
public void run() {
// Initialise only once
if (mapboxMap == null) {
initialiseMap();
mapboxMap.onStart();
}
}
});

initRenderSurface();
super.onSurfaceCreated(gl, config);
}
};

addView(textureView, 0);
} else {
GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView);
glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());

mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView, options.getLocalIdeographFontFamily()) {
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
MapView.this.post(new Runnable() {
@Override
public void run() {
// Initialise only once
if (mapboxMap == null) {
initialiseMap();
mapboxMap.onStart();
}
}
});

initRenderSurface();
super.onSurfaceCreated(gl, config);
}
};

glSurfaceView.setVisibility(View.VISIBLE);

}

nativeMapView = new NativeMapView(this, mapRenderer);
nativeMapView.resizeView(getMeasuredWidth(), getMeasuredHeight());
}

private void initRenderSurface() {
post(new Runnable() {
@Override
public void run() {
// Initialise only when not destroyed and only once
if (!destroyed && mapboxMap == null) {
initialiseMap();
mapboxMap.onStart();
}
}
});
}

/**
* You must call this method from the parent's Activity#onSaveInstanceState(Bundle)
* or Fragment#onSaveInstanceState(Bundle).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.graphics.RectF;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.FloatRange;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -713,20 +712,6 @@ public final void moveCamera(CameraUpdate update) {
*/
public final void moveCamera(final CameraUpdate update, final MapboxMap.CancelableCallback callback) {
transform.moveCamera(MapboxMap.this, update, callback);
// MapChange.REGION_DID_CHANGE_ANIMATED is not called for `jumpTo`
// invalidate camera position to provide OnCameraChange event.
invalidateCameraPosition();

if (callback != null) {
new Handler().post(new Runnable() {
@Override
public void run() {
if (callback != null) {
callback.onFinish();
}
}
});
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class MapboxMapOptions implements Parcelable {
@ColorInt
private int attributionTintColor = UNDEFINED_COLOR;
private boolean attributionEnabled = true;
private int attributionGravity = Gravity.BOTTOM;
private int attributionGravity = Gravity.BOTTOM | Gravity.START;
private int[] attributionMargins;

private double minZoom = MapboxConstants.MINIMUM_ZOOM;
Expand Down Expand Up @@ -234,7 +234,7 @@ public static MapboxMapOptions createFromAttributes(@NonNull Context context, @N
mapboxMapOptions.attributionEnabled(typedArray.getBoolean(
R.styleable.mapbox_MapView_mapbox_uiAttribution, true));
mapboxMapOptions.attributionGravity(typedArray.getInt(
R.styleable.mapbox_MapView_mapbox_uiAttributionGravity, Gravity.BOTTOM));
R.styleable.mapbox_MapView_mapbox_uiAttributionGravity, Gravity.BOTTOM | Gravity.START));
mapboxMapOptions.attributionMargins(new int[] {
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginLeft,
NINETY_TWO_DP * pxlRatio)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class Transform implements MapView.OnMapChangedListener {
private final MarkerViewManager markerViewManager;
private final TrackingSettings trackingSettings;
private final MyLocationView myLocationView;
private final Handler handler = new Handler();

private CameraPosition cameraPosition;
private MapboxMap.CancelableCallback cameraCancelableCallback;
Expand Down Expand Up @@ -83,7 +84,7 @@ public void onMapChanged(@MapView.MapChange int change) {
if (change == REGION_DID_CHANGE_ANIMATED) {
updateCameraPosition(invalidateCameraPosition());
if (cameraCancelableCallback != null) {
new Handler().post(new Runnable() {
handler.post(new Runnable() {
@Override
public void run() {
if (cameraCancelableCallback != null) {
Expand All @@ -99,14 +100,23 @@ public void run() {
}

@UiThread
final void moveCamera(MapboxMap mapboxMap, CameraUpdate update, MapboxMap.CancelableCallback callback) {
final void moveCamera(MapboxMap mapboxMap, CameraUpdate update, final MapboxMap.CancelableCallback callback) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
if (isValidCameraPosition(cameraPosition)) {
trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, false);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
mapView.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
cameraChangeDispatcher.onCameraIdle();
invalidateCameraPosition();
handler.post(new Runnable() {
@Override
public void run() {
if (callback != null) {
callback.onFinish();
}
}
});
}
}

Expand Down Expand Up @@ -182,16 +192,15 @@ void cancelTransitions() {

// notify animateCamera and easeCamera about cancelling
if (cameraCancelableCallback != null) {
final MapboxMap.CancelableCallback callback = cameraCancelableCallback;
cameraChangeDispatcher.onCameraIdle();
new Handler().post(new Runnable() {
handler.post(new Runnable() {
@Override
public void run() {
if (cameraCancelableCallback != null) {
cameraCancelableCallback.onCancel();
cameraCancelableCallback = null;
}
callback.onCancel();
}
});
cameraCancelableCallback = null;
}

// cancel ongoing transitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -925,14 +926,21 @@ private void setWidgetMargins(@NonNull final View view, int[] initMargins, int l
initMargins[2] = right;
initMargins[3] = bottom;

// convert inital margins with padding
// convert initial margins with padding
int[] contentPadding = projection.getContentPadding();
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
left += contentPadding[0];
top += contentPadding[1];
right += contentPadding[2];
bottom += contentPadding[3];
layoutParams.setMargins(left, top, right, bottom);

// support RTL
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
layoutParams.setMarginStart(left);
layoutParams.setMarginEnd(right);
}

view.setLayoutParams(layoutParams);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.maps.renderer.egl;

import android.opengl.GLSurfaceView;
import android.os.Build;
import android.support.annotation.NonNull;

import java.util.ArrayList;
Expand Down Expand Up @@ -261,9 +262,8 @@ private int getConfigAttr(EGL10 egl, EGLDisplay display, EGLConfig config, int a
return attributevalue[0];
}


private int[] getConfigAttributes() {
boolean emulator = inEmulator();
boolean emulator = inEmulator() || inGenymotion();
Timber.i("In emulator: %s", emulator);

// Get all configs at least RGB 565 with 16 depth and 8 stencil
Expand All @@ -290,4 +290,12 @@ private int[] getConfigAttributes() {
private boolean inEmulator() {
return System.getProperty("ro.kernel.qemu") != null;
}

/**
* Detect if we are in genymotion
*/
private boolean inGenymotion() {
return Build.MANUFACTURER.contains("Genymotion");
}

}
Loading