public class MapFragment
extends android.app.Fragment
Map
and handles map UI interactions such as
panning and zooming. MapFragment
extends the Android Fragment
class and retains
its lifecycle behaviors.
Upon the initialization of MapFragment
, a Map
object is automatically created and
bound to the fragment. This Map
object is then persisted throughout the
MapFragment
's lifetime. Since MapFragment
internally calls
Fragment.setRetainInstance(true)
, the Map
will retain any properties applied to
it during an application's lifetime.
MapFragment
objects have their own lifecycle, state, and back stack, thus it is unsafe to
assume objects returned by a MapFragment
instance (with the exception of Map
)
will be available throughout the lifetime of its attached activity.
A MapFragment
is defined in an Android layout XML file. For example:
<fragment class="com.here.android.mpa.mapping.MapFragment" android:id="@+id/map_fragment" android:layout_width="fill_parent" android:layout_height="fill_parent" />
Note: MapFragment
automatically handles MapEngine
pausing and resuming during
activity state changes, thus it is not necessary for the activity that owns MapFragment
instances to manually call MapEngine.onPause()
or MapEngine.onResume()
during the
activity's onPause()
and onResume()
. However, considerations should be made in
how much processing is done during the onResume()
method. Performing significant amounts
of processing may delay view rendering in cases such as device orientation changes. In these
cases, it is recommended to use a specifically designated handler to organize the amount of
processing to be done.
Constructor and Description |
---|
MapFragment()
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addOnMapRenderListener(OnMapRenderListener listener)
Adds a
OnMapRenderListener to listen for map render events. |
android.graphics.Rect |
getCopyrightBoundaryRect()
Gets the current HERE copyright logo's boundary rectangle.
|
int |
getCopyrightLogoHeight()
Returns the height of the copyright logo.
|
CopyrightLogoPosition |
getCopyrightLogoPosition()
Returns the on-screen position of the HERE copyright logo as a
CopyrightLogoPosition value. |
int |
getCopyrightLogoWidth()
Returns the width of the copyright logo.
|
int |
getCopyrightMargin()
Returns the current margin for the HERE copyright logo, in number of pixels, as an offset
from the edge of the visible map area to the edge of the logo.
|
Map |
getMap()
Returns the instance of
Map associated with this map fragment |
MapGesture |
getMapGesture()
Returns the
MapGesture object representing the current gesture handler for the
MapFragment . |
void |
init(android.content.Context context,
OnEngineInitListener listener)
Initializes the
MapEngine and displays a map that occupies the entire
MapFragment 's view rectangle. |
void |
init(OnEngineInitListener listener)
Initializes the
MapEngine and displays a map that occupies the entire
MapFragment 's view rectangle. |
android.view.View |
onCreateView(android.view.LayoutInflater inflater,
android.view.ViewGroup container,
android.os.Bundle savedInstanceState)
Called when this fragment is first attached to its
Activity . |
void |
onDestroyView()
Called when the view previously created by
onCreateView(LayoutInflater, ViewGroup, Bundle) has been detached from this
fragment. |
void |
onInflate(android.app.Activity activity,
android.util.AttributeSet attrs,
android.os.Bundle savedInstanceState)
Deprecated.
Deprecated as of release 3.5. Use
#onInflate(Context,
android.util.AttributeSet, android.os.Bundle) instead. |
void |
onInflate(android.content.Context context,
android.util.AttributeSet attrs,
android.os.Bundle savedInstanceState)
Called when this fragment is being created as part of a view layout inflation, typically from
setting the content view of an activity.
|
void |
onPause()
Called when this fragment is no longer resumed.
|
void |
onResume()
Called when this fragment is visible to the user and actively running.
|
void |
onSaveInstanceState(android.os.Bundle outState)
Called when this fragment has been asked to save its current dynamic state.
|
void |
removeOnMapRenderListener(OnMapRenderListener listener)
Removes an existing
OnMapRenderListener . |
void |
setCopyrightBoundaryRect(android.graphics.Rect rect)
Sets a rectangle, in pixels, relative to the top left corner of the
MapFragment 's
boundary, for the placement of the HERE copyright logo. |
void |
setCopyrightLogoPosition(CopyrightLogoPosition position)
Sets a position for the HERE copyright logo.
|
void |
setCopyrightMargin(int margin)
Sets a margin for the HERE copyright logo, in number of pixels, as an offset from the edge of
the visible map area to the edge of the logo (depending on the placement).
|
void |
setMapMarkerDragListener(MapMarker.OnDragListener listener)
Sets a
MapMarker.OnDragListener to be invoked whenever any MapMarker on a
Map that is attached to this fragment is dragged. |
void |
setOnTouchListener(android.view.View.OnTouchListener listener)
Sets an
View.OnTouchListener to be invoked whenever a touch event is sent to the
MapFragment . |
dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLoaderManager, getParentFragment, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, hashCode, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isRemoving, isResumed, isStateSaved, isVisible, onActivityCreated, onActivityResult, onAttach, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreate, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onDestroy, onDestroyOptionsMenu, onDetach, onGetLayoutInflater, onHiddenChanged, onInflate, onLowMemory, onMultiWindowModeChanged, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPictureInPictureModeChanged, onPrepareOptionsMenu, onRequestPermissionsResult, onStart, onStop, onTrimMemory, onViewCreated, onViewStateRestored, postponeEnterTransition, registerForContextMenu, requestPermissions, 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
public void init(OnEngineInitListener listener)
MapEngine
and displays a map that occupies the entire
MapFragment
's view rectangle. Users of MapFragment
should call this method or
init(Context, OnEngineInitListener)
after the fragment is first attached
to its activity. This method should only be used for fragments declared in a layout XML. Do
not use this method when MapFragment
is created programmatically.listener
- A OnEngineInitListener
object that will be called when MapFragment
initialization is finished. A null object can be supplied if the caller does not
expect any notification when initialization completes.OnEngineInitListener
,
MapEngine.init(Context, OnEngineInitListener)
,
init(Context, OnEngineInitListener)
public void init(android.content.Context context, OnEngineInitListener listener)
MapEngine
and displays a map that occupies the entire
MapFragment
's view rectangle. Users of MapFragment
should call this method
after the fragment is first attached to its activity.
This method can be used for MapFragment
objects that are created programatically or
declared in a layout XML file.
context
- The application context of this fragment.listener
- A OnEngineInitListener
object that will be called when MapFragment
initialization is finished. A null object can be supplied if the caller does not
require any notification when initialization completes.OnEngineInitListener
,
MapEngine.init(Context, OnEngineInitListener)
,
init(OnEngineInitListener)
public android.view.View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)
Activity
. Automatically starts to
initialize the MapEngine
for later use.onCreateView
in class android.app.Fragment
MapView
object.Fragment.onAttach(android.app.Activity)
@Deprecated public void onInflate(android.app.Activity activity, android.util.AttributeSet attrs, android.os.Bundle savedInstanceState)
#onInflate(Context,
android.util.AttributeSet, android.os.Bundle)
instead.onInflate
in class android.app.Fragment
Fragment.onInflate(android.app.Activity, android.util.AttributeSet,
android.os.Bundle)
public void onInflate(android.content.Context context, android.util.AttributeSet attrs, android.os.Bundle savedInstanceState)
onInflate
in class android.app.Fragment
Fragment.onInflate(Context, android.util.AttributeSet, android.os.Bundle)
public void onResume()
MapEngine
activities will be resumed automatically.onResume
in class android.app.Fragment
Fragment.onResume()
public void onPause()
MapEngine
activities will be
paused automatically.onPause
in class android.app.Fragment
Fragment.onPause()
public void onDestroyView()
onCreateView(LayoutInflater, ViewGroup, Bundle)
has been detached from this
fragment. The MapView
object created earlier will detach itself of its associated
Map
instance.onDestroyView
in class android.app.Fragment
Fragment.onDestroyView()
public void onSaveInstanceState(android.os.Bundle outState)
onSaveInstanceState
in class android.app.Fragment
Fragment.onSaveInstanceState(android.os.Bundle)
public Map getMap()
Map
associated with this map fragmentMap
object currently displayed in this fragment.public android.graphics.Rect getCopyrightBoundaryRect()
null
if a boundary
rect has not been set previously.null
if a boundary rect has not been set
previously.setCopyrightBoundaryRect(Rect)
public void setCopyrightBoundaryRect(android.graphics.Rect rect)
MapFragment
's
boundary, for the placement of the HERE copyright logo.
If the specified rectangle is not contained completely within the current visible map area, their area of intersection will be used instead of the specified rectangle's area. The copyright logo and copyright margin must fit into the rectangle, otherwise specified rectangle will be ignored.
The rectangle is reset upon screen rotation or upon screen re-creation, or it can be done by
setting a null
-Rect
.
rect
- A Rect
representing the desired rectangular container to be used for
positioning the copyright logo. Use null
Rect
to reset the
boundary container.java.lang.IllegalArgumentException
- If the supplied Rect
is invalid.public int getCopyrightMargin()
This method only returns a valid value once fragment initialization has taken place.
MapFragment
, in number of pixelspublic int getCopyrightLogoWidth()
This method only returns a valid value once fragment initialization has completed.
public int getCopyrightLogoHeight()
This method only returns a valid value once fragment initialization has taken completed.
public void setCopyrightMargin(int margin)
margin
- Desired offset from the edge of the MapFragment
public CopyrightLogoPosition getCopyrightLogoPosition()
CopyrightLogoPosition
value.public void setCopyrightLogoPosition(CopyrightLogoPosition position)
After the logo's position is set, the position stays effective even when the screen is rotated or re-created.
position
- A CopyrightLogoPosition
value representing the desired placement of the HERE copyright logo with respect
to the visible map view areapublic MapGesture getMapGesture()
MapGesture
object representing the current gesture handler for the
MapFragment
. Applications can intercept this object and override the default event
behaviors.MapGesture
public void addOnMapRenderListener(OnMapRenderListener listener)
OnMapRenderListener
to listen for map render events.listener
- A OnMapRenderListener
to add to the MapFragment
removeOnMapRenderListener(OnMapRenderListener)
public void removeOnMapRenderListener(OnMapRenderListener listener)
OnMapRenderListener
.listener
- A OnMapRenderListener
to remove from the MapFragment
public void setOnTouchListener(android.view.View.OnTouchListener listener)
View.OnTouchListener
to be invoked whenever a touch event is sent to the
MapFragment
.listener
- An View.OnTouchListener
to set for the MapFragment
public void setMapMarkerDragListener(MapMarker.OnDragListener listener)
MapMarker.OnDragListener
to be invoked whenever any MapMarker
on a
Map
that is attached to this fragment is dragged.listener
- An MapMarker.OnDragListener
to set for this MapFragment