Search in sources :

Example 1 with LocationRequestFragment

use of de.westnordost.streetcomplete.location.LocationRequestFragment 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;
}
Also used : ImageButton(android.widget.ImageButton) LocationState(de.westnordost.streetcomplete.location.LocationState) SingleLocationRequest(de.westnordost.streetcomplete.location.SingleLocationRequest) Handler(android.os.Handler) CompassView(de.westnordost.streetcomplete.view.CompassView) View(android.view.View) LocationRequestFragment(de.westnordost.streetcomplete.location.LocationRequestFragment)

Aggregations

Handler (android.os.Handler)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 LocationRequestFragment (de.westnordost.streetcomplete.location.LocationRequestFragment)1 LocationState (de.westnordost.streetcomplete.location.LocationState)1 SingleLocationRequest (de.westnordost.streetcomplete.location.SingleLocationRequest)1 CompassView (de.westnordost.streetcomplete.view.CompassView)1