com.esri.android.map
Class LayerView<V extends LayerModel>

java.lang.Object
  extended by android.view.View
      extended by com.esri.android.map.LayerView<V>
All Implemented Interfaces:
android.graphics.drawable.Drawable.Callback, android.view.accessibility.AccessibilityEventSource, android.view.KeyEvent.Callback
Direct Known Subclasses:
DynamicLayer, GraphicsLayer, LocationService.LocationServiceInner, TiledLayer

public abstract class LayerView<V extends LayerModel>
extends android.view.View

The LayerView class is the base class for all layers that can be added to a MapView.

In a Model-View-Controller architecture, this class represents the View. It handles the image rendering related functions of this architecture. Each View has an associated model class, in this case LayerModel, which handles fetching map images, calculating map extent, and so on.

You will typically work with one of the sub-classes of this abstract class. For example,

You can also extend the LayerView class to add support for additional types of services. However, it is preferred that you extend directly from a DynamicLayer or a TiledLayer class instead of directly from the LayerView if your service type can be classified as dynamic or cached. If your service type extends outside these two types, then you must extend directly from the LayerView class.

Note: The LayerView class, as a base class, extends Android's View class and inherits all of Android's View methods and attributes. This makes working with this View similar to working with a regular Android View.


Nested Class Summary
 
Nested classes/interfaces inherited from class android.view.View
android.view.View.BaseSavedState, android.view.View.MeasureSpec, android.view.View.OnClickListener, android.view.View.OnCreateContextMenuListener, android.view.View.OnFocusChangeListener, android.view.View.OnKeyListener, android.view.View.OnLongClickListener, android.view.View.OnTouchListener
 
Field Summary
protected  float canvasOffsetX
          The default screen origin of the canvas in the LayerView is at the following screen point: (0, 0).
protected  float canvasOffsetY
          The default screen origin of the canvas in the LayerView is at the following screen point: (0, 0).
protected  MapView mapView
          The MapView object that contains this LayerView.
protected  V model
          The LayerModel object that is associated with this LayerView.
 
Fields inherited from class android.view.View
DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, INVISIBLE, KEEP_SCREEN_ON, NO_ID, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET
 
Constructor Summary
LayerView(android.content.Context context, android.util.AttributeSet attrs)
          Inflate the LayerView object from XML.
LayerView(android.content.Context context, android.util.AttributeSet attrs, int defStyle)
          Inflate the LayerView object from XML and apply a class-specific base style.
 
Method Summary
protected  void cancelPendingTasks()
          Cancels all the pending worker threads held by the LayerView object.
protected  void clearCache()
          Clears all the cache used for animation and drawing.
 Point getCenter()
          Returns the center of the map as it is being displayed on the device with the MapView's spatial coordinate system.
 SpatialReference getDefaultSpatialReference()
          If the LayerView is associated with a LayerModel, then the default spatial coordinate system of the layer model is returned.
 Envelope getExtent()
          Returns an extent representing the maximum extent of data, which is currently visible on the device that is showing the map.
 Envelope getFullExtent()
          Gets the full MapView extent based on the default spatial reference as defined by the map service the layer belongs to.
protected  V getModel()
          Returns the LayerModel object associated with this LayerView.
 float[] getOffset()
          Returns the offset of the canvas for the current View.
 OnStatusChangedListener getOnStatusChangedListener()
          Gets the onStatusChangedListener of the LayerView.
 double getResolution()
          Gets the current map resolution based on the map view extent and screen size of the view.
 SpatialReference getSpatialReference()
          Returns the current spatial coordinate system used by the LayerModel that is associated with this LayerView.
 String getUrl()
          Gets the URL of the map service associated with the LayerView.
 int getUrlHashCode()
          A convenience method that returns the hash code of the map service URL.
protected  void initLayer()
          Used to initialize the LayerView and LayerModel objects synchronously.
protected abstract  V initModel()
          This method will instantiate the LayerModel object.
 boolean isInitialized()
          Determines if the LayerView has been initialized.
 boolean isLongLifeCache()
          Determines when to destroy the background of animations that occurs when zooming the MapView.
protected  void onAnimationEnd()
           
protected  void onAnimationStart()
           
protected  void onDraw(android.graphics.Canvas canvas)
           
protected  void onSizeChanged(int w, int h, int oldw, int oldh)
           
 void setLongLifeCache(boolean longLifeCache)
          Determines when to destroy the background of animations that occurs when zooming the MapView.
 void setOffset(float offsetX, float offsetY)
          Updates the offset of the canvas for the current View.
 void setOnStatusChangedListener(OnStatusChangedListener onStatusChangedListener)
          Sets the onStatusChangedListener of the LayerView.
protected  void setUrl(String url)
          Sets the URL of the map service associated with the LayerView.
 Point toMapPoint(float x, float y)
          A convenience method that will convert coordinates specified in screen pixels to an ArcGIS geometry Point with the current MapView's coordinate system.
 Point toMapPoint(Point pt)
          A convenience method that will convert an ArcGIS geometry Point that contains screen coordinates to the current MapView coordinates.
 Point toScreenPoint(float x, float y)
          A convenience method that will convert the coordinates specified in coordinate system units to an ArcGIS geometry Point.
 Point toScreenPoint(Point pt)
          A convenience method that will convert an ArcGIS geometry Point given in the MapView's spatial coordinate system to the device's screen coordinates.
protected abstract  void update()
          Updates the MapView with images that are retrieved from the LayerView's associated LayerModel object.
 
Methods inherited from class android.view.View
addFocusables, addFocusables, addTouchables, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, cancelLongPress, checkInputConnectionProxy, clearAnimation, clearFocus, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createContextMenu, destroyDrawingCache, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDraw, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetPressed, dispatchSetSelected, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, draw, drawableStateChanged, findFocus, findViewById, findViewWithTag, fitSystemWindows, focusSearch, forceLayout, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getId, getKeepScreenOn, getKeyDispatcherState, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMeasuredHeight, getMeasuredWidth, getNextFocusDownId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getResources, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getTag, getTag, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getVerticalFadingEdgeLength, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, hasFocus, hasFocusable, hasWindowFocus, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, invalidateDrawable, isClickable, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isInEditMode, isInTouchMode, isLayoutRequested, isLongClickable, isOpaque, isPaddingOffsetRequired, isPressed, isSaveEnabled, isScrollbarFadingEnabled, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, layout, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onAttachedToWindow, onCheckIsTextEditor, onConfigurationChanged, onCreateContextMenu, onCreateDrawableState, onCreateInputConnection, onDetachedFromWindow, onDisplayHint, onDrawScrollBars, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onLayout, onMeasure, onRestoreInstanceState, onSaveInstanceState, onScrollChanged, onSetAlpha, onStartTemporaryDetach, onTouchEvent, onTrackballEvent, onVisibilityChanged, onWindowFocusChanged, onWindowVisibilityChanged, performClick, performHapticFeedback, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, refreshDrawableState, removeCallbacks, requestFocus, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAnimation, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setClickable, setContentDescription, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFocusable, setFocusableInTouchMode, setHapticFeedbackEnabled, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setId, setKeepScreenOn, setLayoutParams, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnFocusChangeListener, setOnKeyListener, setOnLongClickListener, setOnTouchListener, setPadding, setPressed, setSaveEnabled, setScrollbarFadingEnabled, setScrollBarStyle, setScrollContainer, setSelected, setSoundEffectsEnabled, setTag, setTag, setTouchDelegate, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVisibility, setWillNotCacheDrawing, setWillNotDraw, showContextMenu, startAnimation, unscheduleDrawable, unscheduleDrawable, verifyDrawable, willNotCacheDrawing, willNotDraw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

protected V extends LayerModel model
The LayerModel object that is associated with this LayerView.


canvasOffsetX

protected volatile float canvasOffsetX
The default screen origin of the canvas in the LayerView is at the following screen point: (0, 0).

To begin the process of moving the origin of the canvas for the current LayerView, you can set the canvasOffsetX's field value in screen pixels.


canvasOffsetY

protected volatile float canvasOffsetY
The default screen origin of the canvas in the LayerView is at the following screen point: (0, 0).

To begin the process of moving the origin of the canvas for the current LayerView, you can set the canvasOffsetY's field value in screen pixels.


mapView

protected MapView mapView
The MapView object that contains this LayerView.

Constructor Detail

LayerView

public LayerView(android.content.Context context,
                 android.util.AttributeSet attrs,
                 int defStyle)
Inflate the LayerView object from XML and apply a class-specific base style. This constructor of LayerView allows instances to use their own base style when being inflated.

Parameters:
context - The Context this View is running in. This Context provides access to the current theme, resources, and so on.
attrs - The attributes of the XML used to inflate this View.
defStyle - the style to apply to this View. If a value of 0 is supplied, then no style will be applied (beyond what is included in the theme). This value may either specified as an attribute resource whose value will be retrieved from the current theme, or as an explicit style resource.

LayerView

public LayerView(android.content.Context context,
                 android.util.AttributeSet attrs)
Inflate the LayerView object from XML. This constructor is called when the View is being constructed from XML, but no class-specific base style is specified. The constructor will use a default style of value 0. Therefore, the only attribute values applied are those in the Context's theme and given AttributeSet. The method, onFinishInflate(), will be called after all children have been added.

Parameters:
context - The Context this View is running in. This Context provides access to the current theme, resources, and so on.
attrs - The attributes of the XML used to inflate this View.
Method Detail

initModel

protected abstract V initModel()
                                           throws Exception
This method will instantiate the LayerModel object.

In a Model-View-Controller architecture, the LayerView represents the View and handles the image rendering related functionality. Each View has an associated Model object that handles fetching map images, calculating map bounds, and so on.

Any class that extends the LayerView class should provide an implementation of a LayerModel class and instantiate that model in this method.

Returns:
the LayerModel instance associated with this LayerView.
Throws:
Exception

initLayer

protected final void initLayer()
                        throws Exception
Used to initialize the LayerView and LayerModel objects synchronously.

Throws:
Exception

isInitialized

public boolean isInitialized()
Determines if the LayerView has been initialized.

Returns:
Returns true if the LayerView has been initialized; false otherwise.

setUrl

protected void setUrl(String url)
Sets the URL of the map service associated with the LayerView.

Parameters:
url - the URL pointing to your map service.

getUrl

public String getUrl()
Gets the URL of the map service associated with the LayerView.

Returns:
the URL as a string.

isLongLifeCache

public boolean isLongLifeCache()
Determines when to destroy the background of animations that occurs when zooming the MapView. If true is returned, then the animation background will be destroyed once all the requested images are drawn. However, if false is returned, then once the first map image request is received the background will be destroyed releasing the memory. To set the value reported by this method, use the setLongLifeCache(boolean) method.


setLongLifeCache

public void setLongLifeCache(boolean longLifeCache)
Determines when to destroy the background of animations that occurs when zooming the MapView.

Set to true to destroy the animation background when all requested images are drawn. If you want to release the memory as soon as the first map image request comes back, set it to false.

Parameters:
longLifeCache - set to true for long life animation background; false otherwise.

onSizeChanged

protected void onSizeChanged(int w,
                             int h,
                             int oldw,
                             int oldh)
Overrides:
onSizeChanged in class android.view.View

getDefaultSpatialReference

public SpatialReference getDefaultSpatialReference()
If the LayerView is associated with a LayerModel, then the default spatial coordinate system of the layer model is returned.


getSpatialReference

public SpatialReference getSpatialReference()
Returns the current spatial coordinate system used by the LayerModel that is associated with this LayerView. The LayerView is drawn based on this coordinate system.


toScreenPoint

public Point toScreenPoint(Point pt)
A convenience method that will convert an ArcGIS geometry Point given in the MapView's spatial coordinate system to the device's screen coordinates.

Parameters:
pt - an ArcGIS geometry Point that represents a location on the map.
Returns:
the screen (x, y) as an ArcGIS geometry Point, but without a spatial coordinate system defined.

toMapPoint

public Point toMapPoint(Point pt)
A convenience method that will convert an ArcGIS geometry Point that contains screen coordinates to the current MapView coordinates.

Parameters:
pt - the ArcGIS geometry Point given in screen coordinates.
Returns:
the ArcGIS geometry Point in the MapView's coordinate system.

toMapPoint

public Point toMapPoint(float x,
                        float y)
A convenience method that will convert coordinates specified in screen pixels to an ArcGIS geometry Point with the current MapView's coordinate system.

Parameters:
x - the x coordinate of the screen point in pixels.
y - the y coordinate of the screen point in pixels.
Returns:
the ArcGIS geometry Point in the MapView's coordinate system.

toScreenPoint

public Point toScreenPoint(float x,
                           float y)
A convenience method that will convert the coordinates specified in coordinate system units to an ArcGIS geometry Point.

Parameters:
x - the x coordinate of the MapView point.
y - the y coordinate of the MapView point.
Returns:
the ArcGIS geometry Point converted to screen coordinates.

onDraw

protected void onDraw(android.graphics.Canvas canvas)
Overrides:
onDraw in class android.view.View

onAnimationEnd

protected void onAnimationEnd()
Overrides:
onAnimationEnd in class android.view.View

onAnimationStart

protected void onAnimationStart()
Overrides:
onAnimationStart in class android.view.View

getOffset

public float[] getOffset()
Returns the offset of the canvas for the current View. By default the origin of the canvas in a View is at the following screen point: (0, 0). To change the origin of the canvas for the current View, you can call the setOffset method and pass in your new origin in screen pixels.

Returns:
the offset of the canvas for the current View in pixels as a float array.

setOffset

public void setOffset(float offsetX,
                      float offsetY)
Updates the offset of the canvas for the current View. By default the origin of the canvas in a View is at the following screen point: (0, 0). Use this method to pass in the new (x, y) coordinate in screen pixels.

Parameters:
offsetX - the x screen offset in pixels.
offsetY - the y screen offset in pixels.

getModel

protected V getModel()
Returns the LayerModel object associated with this LayerView.


getCenter

public Point getCenter()
Returns the center of the map as it is being displayed on the device with the MapView's spatial coordinate system.


getResolution

public double getResolution()
Gets the current map resolution based on the map view extent and screen size of the view.


getExtent

public Envelope getExtent()
Returns an extent representing the maximum extent of data, which is currently visible on the device that is showing the map.


getFullExtent

public Envelope getFullExtent()
Gets the full MapView extent based on the default spatial reference as defined by the map service the layer belongs to.


clearCache

protected void clearCache()
Clears all the cache used for animation and drawing. This method is only necessary if you extend the LayerView class and should never be called programmatically for the layer types that are supported by the ArcGIS API for Android.


getUrlHashCode

public int getUrlHashCode()
A convenience method that returns the hash code of the map service URL. The hash codes for map service URLs are cached and this method spares the effort of the developer programmatically calculating the hash code.


cancelPendingTasks

protected void cancelPendingTasks()
Cancels all the pending worker threads held by the LayerView object.


update

protected abstract void update()
Updates the MapView with images that are retrieved from the LayerView's associated LayerModel object. This method is called when the MapView's extent is changed.

Any class that extends the LayerView class should provide an implementation of this method to retrieve updated an updated map from the map service. The TiledLayer and DynamicLayer subclasses provide default implementation for cached and dynamic map services. If you DO NOT need to support other types of map services, then you should not override this default functionality (it will save you a lot of unnecessary development effort).


getOnStatusChangedListener

public OnStatusChangedListener getOnStatusChangedListener()
Gets the onStatusChangedListener of the LayerView.

Returns:
Returns the onStatusChangedListener.

setOnStatusChangedListener

public void setOnStatusChangedListener(OnStatusChangedListener onStatusChangedListener)
Sets the onStatusChangedListener of the LayerView.

Parameters:
onStatusChangedListener - The onStatusChangedListener to set.


Copyright © 2010. All Rights Reserved.