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

Commit

Permalink
[android] - hold off handling hover events untill map has been created
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Oct 10, 2017
1 parent 24bd336 commit 7722cdf
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import android.content.Context;
import android.graphics.PointF;
import android.os.Build;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.IntDef;
Expand Down Expand Up @@ -47,9 +47,9 @@

import timber.log.Timber;

import static android.opengl.GLSurfaceView.RENDERMODE_WHEN_DIRTY;
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION;
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE;
import static android.opengl.GLSurfaceView.RENDERMODE_WHEN_DIRTY;

/**
* <p>
Expand Down Expand Up @@ -382,7 +382,7 @@ public void onDestroy() {

@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isMapInitialized()) {
if (!isMapInitialized() || !isZoomButtonControllerInitialized()) {
return super.onTouchEvent(event);
}

Expand Down Expand Up @@ -419,6 +419,10 @@ public boolean onGenericMotionEvent(MotionEvent event) {

@Override
public boolean onHoverEvent(MotionEvent event) {
if (!isZoomButtonControllerInitialized()) {
return super.onHoverEvent(event);
}

switch (event.getActionMasked()) {
case MotionEvent.ACTION_HOVER_ENTER:
case MotionEvent.ACTION_HOVER_MOVE:
Expand Down Expand Up @@ -506,7 +510,9 @@ protected void onSizeChanged(int width, int height, int oldw, int oldh) {
@CallSuper
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mapZoomButtonController.setVisible(false);
if (isZoomButtonControllerInitialized()) {
mapZoomButtonController.setVisible(false);
}
}

// Called when view is hidden and shown
Expand All @@ -516,7 +522,7 @@ protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
return;
}

if (mapZoomButtonController != null) {
if (isZoomButtonControllerInitialized()) {
mapZoomButtonController.setVisible(visibility == View.VISIBLE);
}
}
Expand Down Expand Up @@ -582,6 +588,10 @@ private boolean isMapInitialized() {
return nativeMapView != null;
}

private boolean isZoomButtonControllerInitialized() {
return mapZoomButtonController != null;
}

MapboxMap getMapboxMap() {
return mapboxMap;
}
Expand Down

0 comments on commit 7722cdf

Please sign in to comment.