Skip to content

Instantly share code, notes, and snippets.

@klemenzarn
Created June 1, 2017 07:43
Show Gist options
  • Save klemenzarn/db3b7b08a4de2448f3675f67fc1b3ee4 to your computer and use it in GitHub Desktop.
Save klemenzarn/db3b7b08a4de2448f3675f67fc1b3ee4 to your computer and use it in GitHub Desktop.
GoogleMapView inside HorizontalView
//horizontalScrollView initialization needed
public void initGoogleMap(){
//google map view init
TouchableMapFragment mapFragment = (TouchableMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_view);
mapFragment.setListener(new TouchableMapFragment.OnWrapperTouchListener() {
@Override
public void onTouchUp() {
horizontalScrollView.requestDisallowInterceptTouchEvent(false);
}
@Override
public void onTouchDown() {
horizontalScrollView.requestDisallowInterceptTouchEvent(true);
}
});
mapFragment.getMapAsync(this);
}
public class TouchableMapFragment extends SupportMapFragment {
public OnWrapperTouchListener listener;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = super.onCreateView(inflater, container, savedInstanceState);
TouchableWrapper wrapper = new TouchableWrapper(getActivity());
wrapper.setBackgroundColor(Color.TRANSPARENT);
ViewGroup rootViewGroup = (ViewGroup) root;
if (rootViewGroup != null) {
rootViewGroup.addView(wrapper, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
return root;
}
public void setListener(OnWrapperTouchListener listener) {
this.listener = listener;
}
class TouchableWrapper extends FrameLayout {
public TouchableWrapper(@NonNull Context context) {
super(context);
}
public TouchableWrapper(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public TouchableWrapper(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean dispatchTouchEvent(MotionEvent e) {
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
if (listener != null)
listener.onTouchDown();
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
if (listener != null)
listener.onTouchUp();
break;
}
return super.dispatchTouchEvent(e);
}
}
public interface OnWrapperTouchListener {
void onTouchUp();
void onTouchDown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment