Skip to content

Commit

Permalink
[mapview] avoid throwing null pointer exception on slow initialisation (
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun authored and emerson233 committed Jul 20, 2021
1 parent bfd4a2e commit 0f0c46b
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -530,21 +530,33 @@ public boolean onTouchEvent(MotionEvent event) {

@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
if (!isKeyDetectorInitialized()) {
return super.onKeyDown(keyCode, event);
}
return mapKeyListener.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
}

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (!isKeyDetectorInitialized()) {
return super.onKeyLongPress(keyCode, event);
}
return mapKeyListener.onKeyLongPress(keyCode, event) || super.onKeyLongPress(keyCode, event);
}

@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
if (!isKeyDetectorInitialized()) {
return super.onKeyUp(keyCode, event);
}
return mapKeyListener.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event);
}

@Override
public boolean onTrackballEvent(@NonNull MotionEvent event) {
if (!isKeyDetectorInitialized()) {
return super.onTrackballEvent(event);
}
return mapKeyListener.onTrackballEvent(event) || super.onTrackballEvent(event);
}

Expand Down Expand Up @@ -1126,6 +1138,10 @@ private boolean isGestureDetectorInitialized() {
return mapGestureDetector != null;
}

private boolean isKeyDetectorInitialized() {
return mapKeyListener != null;
}

@Nullable
MapboxMap getMapboxMap() {
return mapboxMap;
Expand Down

0 comments on commit 0f0c46b

Please sign in to comment.