Package com.kernelcrew.moodapp.ui
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 -
Method Summary
Modifier and TypeMethodDescriptiononCreateView
(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
setLocation
(Double lat, Double lon) 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
-
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 classandroidx.fragment.app.Fragment
- Parameters:
inflater
- The LayoutInflater to inflate viewscontainer
- The parent view containersavedInstanceState
- Previously saved state- Returns:
- The inflated and configured fragment view
-
onViewCreated
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 classandroidx.fragment.app.Fragment
- Parameters:
view
- The view that was createdsavedInstanceState
- State bundle provided by the fragment manager
-
saveMoodEventWithoutLocation
public void saveMoodEventWithoutLocation()Saves a mood event without location data using a default message. -
setUpdateListener
Listener for location updates. -
setLocation
-
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
- Parameters:
latitude
- The latitude coordinate to display on the maplongitude
- The longitude coordinate to display on the map- Throws:
NullPointerException
- if getView() returns null or if map initialization failsIllegalStateException
- if the fragment is not attached to an activity
-