use of de.westnordost.streetcomplete.location.LocationState in project StreetComplete by westnordost.
the class MapControlsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_map_controls, container, false);
compassNeedle = view.findViewById(R.id.compassNeedle);
view.findViewById(R.id.compass).setOnClickListener(v -> {
boolean isFollowing = mapFragment.isFollowingPosition();
boolean isCompassMode = mapFragment.isCompassMode();
boolean isNorthUp = mapFragment.getRotation() == 0;
if (!isNorthUp) {
mapFragment.setMapOrientation(0, 0);
}
if (isFollowing) {
setIsCompassMode(!isCompassMode);
}
});
trackingButton = view.findViewById(R.id.gps_tracking);
trackingButton.setOnClickListener(v -> {
LocationState state = trackingButton.getState();
if (state.isEnabled()) {
if (!mapFragment.isFollowingPosition()) {
setIsFollowingPosition(true);
} else {
setIsFollowingPosition(false);
}
} else {
String tag = LocationRequestFragment.class.getSimpleName();
LocationRequestFragment locationRequestFragment = (LocationRequestFragment) getActivity().getSupportFragmentManager().findFragmentByTag(tag);
if (locationRequestFragment != null) {
locationRequestFragment.startRequest();
}
}
});
ImageButton zoomInButton = view.findViewById(R.id.zoom_in);
zoomInButton.setOnClickListener(v -> mapFragment.zoomIn());
ImageButton zoomOutButton = view.findViewById(R.id.zoom_out);
zoomOutButton.setOnClickListener(v -> mapFragment.zoomOut());
ImageButton createNoteButton = view.findViewById(R.id.create_note);
createNoteButton.setOnClickListener(v -> {
v.setEnabled(false);
new Handler(Looper.getMainLooper()).postDelayed(() -> v.setEnabled(true), 200);
listener.onClickCreateNote();
});
singleLocationRequest = new SingleLocationRequest(getActivity());
return view;
}
Aggregations