summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewContainer.java
blob: d590582f09e18235631dc69537d124ec5b1188cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.mapbox.mapboxsdk.annotations;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.widget.FrameLayout;

/**
 * ViewGroup that dispatches TouchEvents to the parent ViewGroup.
 * <p>
 * This allows to dispatch touch events that occur on MarkerView to MapView.
 * https://github.com/mapbox/mapbox-gl-native/issues/5388
 * </p>
 */
public class MarkerViewContainer extends FrameLayout {

  public MarkerViewContainer(Context context, AttributeSet attrs) {
    super(context, attrs);
    setTag(false);
  }

  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    super.dispatchTouchEvent(ev);
    boolean actionUp = (boolean) getTag();
    if (!actionUp) {
      ((ViewGroup) getParent()).onTouchEvent(ev);
    } else {
      setTag(false);
    }
    return true;
  }
}