public class

ShapeView

extends SurfaceView
java.lang.Object
   ↳ android.view.View
     ↳ android.view.SurfaceView
       ↳ sofia.graphics.ShapeView
Known Direct Subclasses

Class Overview

Represents a view containing drawn Shape objects.

Summary

[Expand]
Inherited Constants
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
ShapeView(Context context)
Creates a new ShapeView.
ShapeView(Context context, AttributeSet attrs)
Creates a new ShapeView.
ShapeView(Context context, AttributeSet attrs, int defStyle)
Creates a new ShapeView.
Public Methods
void add(Shape shape)
Adds a shape to the ShapeField currently in use by this view.
void clear()
Removes all shapes from the ShapeField currently in use by this view.
void conditionallyRepaint()
boolean dispatchTouchEvent(MotionEvent e)
void doRepaint()
The real method that performs shape drawing in response to a callback from the repainting thread.
synchronized boolean doesAutoRepaint()
Does this view automatically repaint, or is an explicit call needed?
void enableRotateGestures()
Turn on support for rotation gestures.
void enableScaleGestures()
Turn on support for pinching/zoom gestures.
ShapeAnimationManager getAnimationManager()
Get the animation manager for this view.
Color getBackgroundColor()
Gets the background color of the view.
CoordinateSystem getCoordinateSystem()
PointF getGravity()
Gets the gravity of the physical world represented by this shape view.
<MyShape extends Shape> Set<MyShape> getNeighbors(Shape shape, float distance, boolean diag, Class<MyShape> cls)
Returns the neighbors to the given location.
ShapeField getShapeField()
Gets the ShapeField that the view is currently displaying and simulating.
ShapeFilter<Shape> getShapes()
Gets a filter that can be used to find shapes that match certain criteria.
<MyShape extends Shape> Set<MyShape> getShapesInDirection(float x, float y, float angle, float length, Class<MyShape> cls)
Return all objects that intersect a straight line from the location at a specified angle.
<MyShape extends Shape> Set<MyShape> getShapesInRange(float x, float y, float r, Class<MyShape> cls)
Returns all objects with the logical location within the specified circle.
synchronized void internalSetAutoRepaintForThread(boolean value)
Used internally to temporarily disable repainting.
boolean isInFrontOf(Shape left, Shape right)
Returns true if the left shape is drawn in front of (later than) the shape on the right.
boolean onKeyDown(int keyCode, KeyEvent e)
boolean onTouchEvent(MotionEvent e)
void remove(Shape shape)
Removes a shape from the ShapeField currently in use by this view.
void repaint()
synchronized void setAutoRepaint(boolean value)
Tell this view to automatically repaint when Shapes change (or not).
void setBackgroundColor(Color color)
Sets the background color of the view.
void setGravity(float xGravity, float yGravity)
Sets the gravity of the physical world represented by this shape view.
void setGravity(PointF gravity)
Sets the gravity of the physical world represented by this shape view.
void setShapeField(ShapeField newField)
Sets the ShapeField that the view is currently displaying and simulating.
Protected Methods
void drawContents(Canvas canvas)
Draw all of this view's shapes on the given canvas.
[Expand]
Inherited Methods
From class android.view.SurfaceView
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Public Constructors

public ShapeView (Context context)

Creates a new ShapeView.

Parameters
context This view's context.

public ShapeView (Context context, AttributeSet attrs)

Creates a new ShapeView.

Parameters
context This view's context.
attrs This view's attributes.

public ShapeView (Context context, AttributeSet attrs, int defStyle)

Creates a new ShapeView.

Parameters
context This view's context.
attrs This view's attributes.
defStyle This view's default style.

Public Methods

public void add (Shape shape)

Adds a shape to the ShapeField currently in use by this view. This method is a shortcut for getShapeField().add(shape).

Parameters
shape the shape to add

public void clear ()

Removes all shapes from the ShapeField currently in use by this view. This method is a shortcut for getShapeField().clear().

public void conditionallyRepaint ()

public boolean dispatchTouchEvent (MotionEvent e)

public void doRepaint ()

The real method that performs shape drawing in response to a callback from the repainting thread.

public synchronized boolean doesAutoRepaint ()

Does this view automatically repaint, or is an explicit call needed?

Returns
  • True if this view automatically repaints when contained shapes are modified.

public void enableRotateGestures ()

Turn on support for rotation gestures.

public void enableScaleGestures ()

Turn on support for pinching/zoom gestures.

public ShapeAnimationManager getAnimationManager ()

Get the animation manager for this view.

Returns
  • This view's animation manager.

public Color getBackgroundColor ()

Gets the background color of the view.

Returns
  • the background Color of the view

public CoordinateSystem getCoordinateSystem ()

public PointF getGravity ()

Gets the gravity of the physical world represented by this shape view.

Returns
  • a PointF object whose x and y components are the horizontal and vertical acceleration due to gravity (in units/sec^2) of the physical world represented by this shape view

public Set<MyShape> getNeighbors (Shape shape, float distance, boolean diag, Class<MyShape> cls)

Returns the neighbors to the given location. This method only looks at the logical location and not the extent of objects. Hence it is most useful in scenarios where objects only span one cell.

Parameters
shape The shape whose neighbors will be located.
distance Distance in which to look for other objects.
diag Is the distance also diagonal?
cls Class of objects to look for (null or Object.class will find all classes).
Returns
  • A collection of all neighbors found.

public ShapeField getShapeField ()

Gets the ShapeField that the view is currently displaying and simulating.

Returns
  • the ShapeField currently in use by the view

public ShapeFilter<Shape> getShapes ()

Gets a filter that can be used to find shapes that match certain criteria. This method is a shortcut for getShapeField().getShapes().

Returns
  • a filter that can be used to find shapes that match certain criteria

public Set<MyShape> getShapesInDirection (float x, float y, float angle, float length, Class<MyShape> cls)

Return all objects that intersect a straight line from the location at a specified angle. The angle is clockwise.

Parameters
x x-coordinate.
y y-coordinate.
angle The angle relative to current rotation of the object. (0-359).
length How far we want to look (in cells).
cls Class of objects to look for (null or Object.class will find all classes).
Returns
  • A collection of all objects found.

public Set<MyShape> getShapesInRange (float x, float y, float r, Class<MyShape> cls)

Returns all objects with the logical location within the specified circle. In other words an object A is within the range of an object B if the distance between the center of the two objects is less than r.

Parameters
x Center of the circle.
y Center of the circle.
r Radius of the circle.
cls Class of objects to look for (null or Object.class will find all classes).
Returns
  • A set of shapes that lie within the given circle.

public synchronized void internalSetAutoRepaintForThread (boolean value)

Used internally to temporarily disable repainting.

Parameters
value Says whether the current thread is restoring auto-painting or disabling auto-painting.

public boolean isInFrontOf (Shape left, Shape right)

Returns true if the left shape is drawn in front of (later than) the shape on the right.

Parameters
left The shape to check.
right The shape to check against.
Returns
  • True if left is drawn in front of (later than) right.

public boolean onKeyDown (int keyCode, KeyEvent e)

public boolean onTouchEvent (MotionEvent e)

public void remove (Shape shape)

Removes a shape from the ShapeField currently in use by this view. This method is a shortcut for getShapeField().remove(shape).

Parameters
shape the shape to remove

public void repaint ()

public synchronized void setAutoRepaint (boolean value)

Tell this view to automatically repaint when Shapes change (or not).

Parameters
value Whether or not this view should automatically repaint when shapes change.

public void setBackgroundColor (Color color)

Sets the background color of the view.

Parameters
color the desired background Color

public void setGravity (float xGravity, float yGravity)

Sets the gravity of the physical world represented by this shape view.

Parameters
xGravity the horizontal acceleration due to gravity (in units/sec^2)
yGravity the vertical acceleration due to gravity (in units/sec^2)

public void setGravity (PointF gravity)

Sets the gravity of the physical world represented by this shape view.

Parameters
gravity a PointF whose x and y components are the horizontal and vertical acceleration due to gravity (in units/sec^2) of the physical world represented by this shape view

public void setShapeField (ShapeField newField)

Sets the ShapeField that the view is currently displaying and simulating. When developing games or simulations that involve multiple "levels" or other complex multiple shape layouts, this method can be used to quickly and easily swap out the entire set of shapes used by the view.

Parameters
newField the ShapeField to be used by the view

Protected Methods

protected void drawContents (Canvas canvas)

Draw all of this view's shapes on the given canvas.

Parameters
canvas The canvas to draw on.