com.ls.widgets.map.model
Class MapObject

java.lang.Object
  extended by com.ls.widgets.map.model.MapObject
Direct Known Subclasses:
PositionMarker

public class MapObject
extends java.lang.Object


Constructor Summary
MapObject(java.lang.Object id)
           
MapObject(java.lang.Object id, Drawable drawable, int x, int y)
          Creates new MapObject.
MapObject(java.lang.Object id, Drawable drawable, int x, int y, boolean isTouchable)
          Creates new MapObject.
MapObject(java.lang.Object id, Drawable drawable, int x, int y, boolean isTouchable, boolean isScalable)
          Creates new MapObject.
MapObject(java.lang.Object id, Drawable drawable, int x, int y, int pivotX, int pivotY)
          Creates new MapObject.
MapObject(java.lang.Object id, Drawable drawable, int x, int y, int pivotX, int pivotY, boolean isTouchable, boolean isScalable)
          Creates new MapObject.
MapObject(java.lang.Object id, Drawable drawable, Point position)
          Creates new MapObject.
MapObject(java.lang.Object id, Drawable drawable, Point position, boolean isTouchable)
          Creates new MapObject.
MapObject(java.lang.Object id, Drawable drawable, Point position, boolean isTouchable, boolean isScalable)
          Creates new MapObject.
MapObject(java.lang.Object id, Drawable drawable, Point position, Point pivotPoint)
          Creates new MapObject.
MapObject(java.lang.Object id, Drawable drawable, Point position, Point pivotPoint, boolean isTouchable)
          Creates new MapObject.
MapObject(java.lang.Object id, Drawable drawable, Point position, Point pivotPoint, boolean isTouchable, boolean isScalable)
          Creates new MapObject.
 
Method Summary
 void draw(Canvas canvas)
          Draws the map object on the canvas
 boolean equals(java.lang.Object o)
           
 Rect getBounds()
          Returns bounds of the image that represents the map object.
 Drawable getDrawable()
          Returns image that was passed to the constructor.
 java.lang.Object getId()
          Returns id of this object
 Point getPosition()
          Returns position of the map object in map coordinates in pixels of the original image.
 int getX()
          Returns X coordinate of the map object in map coordinates.
 int getXScaled()
          Returns X coordinate of the map object in map coordinates.
 int getY()
          Returns Y coordinate of the map object in map coordinates.
 int getYScaled()
          Returns Y coordinate of the map object in map coordinates.
 int hashCode()
           
 boolean isTouchable()
          Shows whether this object is touchable.
 boolean isTouched(Rect touchRect)
          Determines whether touch rectangle intersects the bounds of this object.
 void moveTo(int x, int y)
          Moves object to another position on the map that is defined in pixels.
 void moveTo(Location location)
          Moves object to another position on the map that is defined in pixels.
 void setDrawable(Drawable drawable)
          Sets object's image.
 void setPivotPoint(int x, int y)
          Set's pivot point within the drawable
 void setPivotPoint(Point pivotPoint)
          Set's pivot point within the drawable
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapObject

public MapObject(java.lang.Object id)

MapObject

public MapObject(java.lang.Object id,
                 Drawable drawable,
                 int x,
                 int y)
Creates new MapObject.

Parameters:
id - - id of the object.
drawable - - image.
x - - x coordinate of the object in map coordinates.
y - - y coordinate of the object in map coordinates.

MapObject

public MapObject(java.lang.Object id,
                 Drawable drawable,
                 Point position)
Creates new MapObject.

Parameters:
id - - id of the object.
drawable - - image
position - - coordinate of the object in map coordinates.

MapObject

public MapObject(java.lang.Object id,
                 Drawable drawable,
                 int x,
                 int y,
                 int pivotX,
                 int pivotY)
Creates new MapObject.

Parameters:
id - - id of the object.
drawable - - image.
x - - x coordinate of the object in map coordinates.
y - - y coordinate of the object in map coordinates.
pivotX - - x coordinate of pivot point in image coordinates.
pivotY - - y coordinate of pivot point in image coordinates.

MapObject

public MapObject(java.lang.Object id,
                 Drawable drawable,
                 Point position,
                 Point pivotPoint)
Creates new MapObject.

Parameters:
id - - id of the object.
drawable - - image.
position - - coordinate of the object in map coordinates.
pivotPoint - - coordinate of the pivot point in image coordinates.

MapObject

public MapObject(java.lang.Object id,
                 Drawable drawable,
                 int x,
                 int y,
                 boolean isTouchable)
Creates new MapObject.

Parameters:
id - - id of the object.
drawable - - image.
x - - x coordinate of the object in map coordinates.
y - - y coordinate of the object in map coordinates.
isTouchable - - true if the object should respond to touch events, false otherwise.

MapObject

public MapObject(java.lang.Object id,
                 Drawable drawable,
                 Point position,
                 boolean isTouchable)
Creates new MapObject.

Parameters:
id - - id of the object.
drawable - - image.
position - - coordinate of the object in map coordinates.
isTouchable - - true if the object should respond to touch events, false otherwise.

MapObject

public MapObject(java.lang.Object id,
                 Drawable drawable,
                 Point position,
                 Point pivotPoint,
                 boolean isTouchable)
Creates new MapObject.

Parameters:
id - - id of the object.
drawable - - image.
position - - coordinate of the object in map coordinates.
pivotPoint - - coordinate of the pivot point in image coordinates.
isTouchable - - true if the object should respond to touch events, false otherwise.

MapObject

public MapObject(java.lang.Object id,
                 Drawable drawable,
                 int x,
                 int y,
                 boolean isTouchable,
                 boolean isScalable)
Creates new MapObject.

Parameters:
id - - id of the object.
drawable - - image.
x - - x coordinate of the object in map coordinates.
y - - y coordinate of the object in map coordinates.
isTouchable - - true if the object should respond to touch events, false otherwise.
isScalable - - true, if map object should be scaled on map zoom, false otherwise.

MapObject

public MapObject(java.lang.Object id,
                 Drawable drawable,
                 Point position,
                 boolean isTouchable,
                 boolean isScalable)
Creates new MapObject.

Parameters:
id - - id of the object.
drawable - - image.
position - - coordinate of the object in map coordinates.
isTouchable - - true if the object should respond to touch events, false otherwise.
isScalable - - true, if map object should be scaled on map zoom, false otherwise.

MapObject

public MapObject(java.lang.Object id,
                 Drawable drawable,
                 Point position,
                 Point pivotPoint,
                 boolean isTouchable,
                 boolean isScalable)
Creates new MapObject.

Parameters:
id - - id of the object.
drawable - - image.
position - - coordinate of the object in map coordinates.
pivotPoint - - coordinate of the pivot point in image coordinates.
isTouchable - - true if the object should respond to touch events, false otherwise.
isScalable - - true, if map object should be scaled on map zoom, false otherwise.

MapObject

public MapObject(java.lang.Object id,
                 Drawable drawable,
                 int x,
                 int y,
                 int pivotX,
                 int pivotY,
                 boolean isTouchable,
                 boolean isScalable)
Creates new MapObject.

Parameters:
id - - id of the object.
drawable - - image.
x - - x coordinate of the object in map coordinates.
y - - y coordinate of the object in map coordinates.
pivotX - - x coordinate of pivot point in image coordinates.
pivotY - - y coordinate of pivot point in image coordinates.
isTouchable - - true if the object should respond to touch events, false otherwise.
isScalable - - true, if map object should be scaled on map zoom, false otherwise.
Method Detail

getDrawable

public Drawable getDrawable()
Returns image that was passed to the constructor.

Returns:
instance of Drawable.

setDrawable

public void setDrawable(Drawable drawable)
Sets object's image.

Parameters:
drawable - instance of Drawable.
Throws:
java.lang.IllegalArgumentException - when null is set.

draw

public void draw(Canvas canvas)
Draws the map object on the canvas

Parameters:
canvas - - Canvas

getId

public java.lang.Object getId()
Returns id of this object

Returns:
Object that was passed as an id to the constructor.

isTouched

public boolean isTouched(Rect touchRect)
Determines whether touch rectangle intersects the bounds of this object. Coordinates that are passed in touchRect are the screen coordinates + scroll offset.

Parameters:
touchRect - - area inside of the map.
Returns:
- true if touchRect intersects the map object's touch area, false otherwise.

getXScaled

public int getXScaled()
Returns X coordinate of the map object in map coordinates.

Returns:
X coordinate taking the map scale into account.

getYScaled

public int getYScaled()
Returns Y coordinate of the map object in map coordinates.

Returns:
Y coordinate taking the map scale into account.

getX

public int getX()
Returns X coordinate of the map object in map coordinates.

Returns:
X coordinate of the object.

getY

public int getY()
Returns Y coordinate of the map object in map coordinates.

Returns:
Y coordinate of the object.

getPosition

public Point getPosition()
Returns position of the map object in map coordinates in pixels of the original image.

Returns:
instance of android.graphics.Point.

isTouchable

public boolean isTouchable()
Shows whether this object is touchable.

Returns:
true if this object should respond to touch events, false otherwise.

setPivotPoint

public void setPivotPoint(int x,
                          int y)
Set's pivot point within the drawable

Parameters:
x - - x coordinate in pixels
y - - y coordinate in pixels

setPivotPoint

public void setPivotPoint(Point pivotPoint)
Set's pivot point within the drawable

Parameters:
pivotPoint - position of pivot point within the drawable.
Throws:
java.lang.IllegalArgumentException - if null is passed

getBounds

public Rect getBounds()
Returns bounds of the image that represents the map object. Note: for efficiency, the returned object may be the same object stored in the drawable (though this is not guaranteed), so if a persistent copy of the bounds is needed, call copyBounds(rect) instead. You should also not change the object returned by this method as it may be the same object stored in the drawable.

Returns:
instance of Rect with size of the image in pixels taking the scale of the map into account.

moveTo

public void moveTo(int x,
                   int y)
Moves object to another position on the map that is defined in pixels.

Parameters:
x - - horizontal coordinate of the object within the map in pixels.
y - - vertical coordinate of the object within the map in pixels.

moveTo

public void moveTo(Location location)
Moves object to another position on the map that is defined in pixels. In order for this method to work you should ensure that geo area is configured in /assets/map/map.xml file.

Parameters:
location - - location of the object.
Throws:
java.lang.IllegalStateException - if geo area is not configured in map.xml file.
See Also:
android.location.Location

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object