|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectSurfaceView
org.hermit.android.core.SurfaceRunner
org.hermit.android.instruments.InstrumentSurface
public abstract class InstrumentSurface
Common base for applications which display instruments. This class is
an extension of SurfaceRunner
which provides additional
functions to manage the instruments embedded in it.
When using this class in an app, the app context must call these methods (usually from its corresponding Activity methods):
The surface is enabled once it is created and sized, and
SurfaceRunner.onStart()
and SurfaceRunner.onResume()
have been called. You then
start and stop it by calling SurfaceRunner.surfaceStart()
and
SurfaceRunner.surfaceStop()
.
Field Summary | |
---|---|
static int |
SURFACE_CACHE_BG
Instrument Surface runner option: cache a background bitmap. |
Fields inherited from class org.hermit.android.core.SurfaceRunner |
---|
LOOPED_TICKER, SURFACE_DYNAMIC |
Constructor Summary | |
---|---|
InstrumentSurface(Activity app)
Create a SurfaceRunner instance. |
|
InstrumentSurface(Activity app,
int options)
Create a SurfaceRunner instance. |
Method Summary | |
---|---|
void |
addGauge(Gauge i)
Add a gauge to this surface. |
void |
addInstrument(Instrument i)
Add an instrument to the system, associated with this surface. |
protected void |
animStart()
We are starting the animation loop. |
protected void |
animStop()
We are stopping the animation loop, for example to pause the app. |
protected void |
appSize(int width,
int height,
Bitmap.Config config)
Set the screen size. |
protected void |
appStart()
The application is starting. |
protected void |
appStop()
The application is closing down. |
protected void |
doDraw(Canvas canvas,
long now)
Draw the current frame of the application. |
protected void |
doUpdate(long now)
Update the state of the application for the current frame. |
protected abstract void |
layout(int width,
int height)
Lay out the display for a given screen size. |
Methods inherited from class org.hermit.android.core.SurfaceRunner |
---|
getBitmap, getBitmap, getRes, onPause, onResume, onStart, onStop, onSurfaceThread, onWindowFocusChanged, optionSet, postUpdate, setDebugPerf, setDebugPos, setDelay, statsCount, statsCreate, statsTime, surfaceChanged, surfaceCreated, surfaceDestroyed, surfaceStart, surfaceStop |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SURFACE_CACHE_BG
Constructor Detail |
---|
public InstrumentSurface(Activity app)
app
- The application context we're running in.public InstrumentSurface(Activity app, int options)
app
- The application context we're running in.options
- Options for this SurfaceRunner. A bitwise OR of
SURFACE_XXX constants.Method Detail |
---|
public void addInstrument(Instrument i)
Gauge
s
for this instrument and add them to the surface with
addGauge(Gauge)
.
All instruments added here will be started and stopped when the
application starts and stops, and will have their measurement turned
on when the app is visible and running. Their
Instrument.doUpdate(long)
method will be called each
time round the main animation loop.
All instruments must be added before the application starts running.
i
- The instrument to add.public void addGauge(Gauge i)
Instrument
, it should be attached to the surface with
addInstrument(Instrument)
.
All gauges added here will have their
Gauge.draw(Canvas, long, boolean)
method called each
time round the main animation loop.
All gauges must be added before the application starts running.
i
- The gauge to add.protected abstract void layout(int width, int height)
width
- The new width of the surface.height
- The new height of the surface.protected void appStart()
If subclasses override this, they must call through to this method.
appStart
in class SurfaceRunner
protected void appSize(int width, int height, Bitmap.Config config)
We call the layout() method here, so subclasses generally don't need to override this. If subclasses do override this, they must call through to this method.
appSize
in class SurfaceRunner
width
- The new width of the surface.height
- The new height of the surface.config
- The pixel format of the surface.protected void animStart()
doUpdate() and doDraw() may be called from this point on.
If subclasses override this, they must call through to this method.
animStart
in class SurfaceRunner
protected void animStop()
doUpdate() and doDraw() will not be called from this point on.
If subclasses override this, they must call through to this method.
animStop
in class SurfaceRunner
protected void appStop()
appStop
in class SurfaceRunner
protected void doUpdate(long now)
Applications must override this, and can use it to update for example the physics of a game. This may be a no-op in some cases.
doDraw() will always be called after this method is called; however, the converse is not true, as we sometimes need to draw just to update the screen. Hence this method is useful for updates which are dependent on time rather than frames.
doUpdate
in class SurfaceRunner
now
- Nominal time of the current frame in ms.protected void doDraw(Canvas canvas, long now)
Applications must override this, and are expected to draw the entire screen into the provided canvas.
This method will always be called after a call to doUpdate(), and also when the screen needs to be re-drawn.
doDraw
in class SurfaceRunner
canvas
- The Canvas to draw into.now
- Nominal time of the current frame in ms.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |