Sofia API Reference

  • Package Index
  • Class Index
  • Packages
  • sofia.app
  • sofia.content
  • sofia.data
  • sofia.graphics
    • Interfaces
    • Joint
    • PropertyTransformer
    • Classes
    • AbstractJoint
    • Anchor
    • Color
    • CoordinateSystem
    • DirectionalPad
    • DistanceJoint
    • ElasticInInterpolator
    • ElasticInOutInterpolator
    • ElasticOutInterpolator
    • FillableShape
    • FillableShape.Animator
    • Geometry
    • Image
    • LineShape
    • MotionStep
    • OvalShape
    • PointAndAnchor
    • Polygon
    • PolygonShape
    • Predicate
    • RectangleShape
    • RevoluteJoint
    • Shape
    • Shape.Animator
    • Shape.Filter
    • ShapeField
    • ShapeFilter
    • ShapeSet
    • ShapeView
    • SizeF
    • StrokedShape
    • StrokedShape.Animator
    • TextShape
    • TextShape.Animator
    • Timings
    • ViewEdges
    • ZIndexComparator
    • Enums
    • RepeatMode
    • ShapeMotion
  • sofia.util
  • sofia.view
  • sofia.widget

public class
ShapeView

extends SurfaceView

Inheritance

  • java.lang.Object
    • SurfaceView
      • sofia.graphics.ShapeView

Class Overview

Represents a view containing drawn Shape objects.


Summary

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(RectF bounds)
void conditionallyRepaint()
boolean dispatchTouchEvent(MotionEvent e)
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()
void repaint(RectF bounds)
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, RectF repaintBounds)
Draw all of this view's shapes on the given canvas.
Methods inherited from class java.lang.Object
Object clone()
boolean equals(Object arg0)
void finalize()
final Class<?> getClass()
int hashCode()
final void notify()
final void notifyAll()
String toString()
final void wait()
final void wait(long arg0, int arg1)
final void wait(long arg0)

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 (RectF bounds)

public void conditionallyRepaint ()

public boolean dispatchTouchEvent (MotionEvent e)

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.

See Also
  • setAutoRepaint(boolean)
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 void repaint (RectF bounds)

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, RectF repaintBounds)

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

Parameters
canvas
The canvas to draw on.