Class LocationFragment

java.lang.Object
androidx.fragment.app.Fragment
com.kernelcrew.moodapp.ui.LocationFragment
All Implemented Interfaces:
ComponentCallbacks, View.OnCreateContextMenuListener, androidx.activity.result.ActivityResultCaller, androidx.lifecycle.HasDefaultViewModelProviderFactory, androidx.lifecycle.LifecycleOwner, androidx.lifecycle.ViewModelStoreOwner, androidx.savedstate.SavedStateRegistryOwner

public class LocationFragment extends androidx.fragment.app.Fragment
  • Nested Class Summary

    Nested classes/interfaces inherited from class androidx.fragment.app.Fragment

    androidx.fragment.app.Fragment.InstantiationException, androidx.fragment.app.Fragment.SavedState
  • Field Summary

    Fields inherited from class androidx.fragment.app.Fragment

    mPreviousWho
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    Creates the fragment view and initializes location services.
    void
    onViewCreated(View view, Bundle savedInstanceState)
    Called after this view has been created.
    void
    populateMapFromExistingLocation(double latitude, double longitude)
    Populates the map with an existing location coordinate pair.
    void
    Saves a mood event without location data using a default message.
    void
     
    void
    Listener for location updates.

    Methods inherited from class androidx.fragment.app.Fragment

    dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getDefaultViewModelCreationExtras, getDefaultViewModelProviderFactory, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, getParentFragmentManager, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSavedStateRegistry, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, getViewLifecycleOwner, getViewLifecycleOwnerLiveData, getViewModelStore, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isStateSaved, isVisible, onActivityCreated, onActivityResult, onAttach, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreate, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onDestroy, onDestroyOptionsMenu, onDestroyView, onDetach, onGetLayoutInflater, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPause, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onRequestPermissionsResult, onResume, onSaveInstanceState, onStart, onStop, onViewStateRestored, postponeEnterTransition, postponeEnterTransition, registerForActivityResult, registerForActivityResult, registerForContextMenu, requestPermissions, requireActivity, requireArguments, requireContext, requireFragmentManager, requireHost, requireParentFragment, requireView, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, startPostponedEnterTransition, toString, unregisterForContextMenu

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • LocationFragment

      public LocationFragment()
  • Method Details

    • onCreateView

      @Nullable public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
      Creates the fragment view and initializes location services. Sets up the location button and location client.
      Overrides:
      onCreateView in class androidx.fragment.app.Fragment
      Parameters:
      inflater - The LayoutInflater to inflate views
      container - The parent view container
      savedInstanceState - Previously saved state
      Returns:
      The inflated and configured fragment view
    • onViewCreated

      public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
      Called after this view has been created. Initializes the permission request launcher. We do this here since the map should be initialized first.
      Overrides:
      onViewCreated in class androidx.fragment.app.Fragment
      Parameters:
      view - The view that was created
      savedInstanceState - State bundle provided by the fragment manager
    • saveMoodEventWithoutLocation

      public void saveMoodEventWithoutLocation()
      Saves a mood event without location data using a default message.
    • setUpdateListener

      public void setUpdateListener(LocationUpdateListener form)
      Listener for location updates.
    • setLocation

      public void setLocation(Double lat, Double lon)
    • populateMapFromExistingLocation

      public void populateMapFromExistingLocation(double latitude, double longitude)
      Populates the map with an existing location coordinate pair. This method is used when editing a mood event that already has location data, or when restoring a previously saved location. The method performs the following actions:
      • Updates the internal latitude and longitude properties
      • Shows the map card and hides the add location button
      • Shows the remove location button
      • Initializes the map with a marker at the specified coordinates
      • Sets up a click listener to allow the user to change the location by tapping elsewhere on the map
      Note that this method uses getView() which may return null if the fragment is not attached to its activity. Callers should ensure the fragment is in the proper lifecycle state before calling this method.
      Parameters:
      latitude - The latitude coordinate to display on the map
      longitude - The longitude coordinate to display on the map
      Throws:
      NullPointerException - if getView() returns null or if map initialization fails
      IllegalStateException - if the fragment is not attached to an activity