Created
June 1, 2017 07:43
-
-
Save klemenzarn/db3b7b08a4de2448f3675f67fc1b3ee4 to your computer and use it in GitHub Desktop.
GoogleMapView inside HorizontalView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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