Animated TriangleActivityjava

The AnimatedTriangleActivity.java activity resembles the activity in Listing 13-4 that tests a simple triangle drawing, so you should be able to understand it easily. The goal of this activity is to provide a surface to draw on and then show it on the Android screen (see Listing 13-8).

The key line of code in this activity is highlighted in bold font. We basically took the previous activity that we used for a simple drawing (see Listing 13-4) and commented out the rendering mode. This lets the GLSurfaceView default to continuous-rendering mode, which accommodates repeated calls to the onDraw method of the renderer, in this case AnimatedSimpleTriangleRenderer.

Listing 13-8. AnimatedTriangleActivity Source Code

//filename: AnimatedTriangleActivity.java public class AnimatedTriangleActivity extends Activity { private GLSurfaceView mTestHarness; ^Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

mTestHarness = new GLSurfaceView(this); mTestHarness.setEGLConfigChooser(false);

mTestHarness.setRenderer(new AnimatedSimpleTriangleRenderer(this)); //mTestHarness.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

setContentView(mTestHarness);

^Override protected void onResume() { super.onResume(); mTestHarness.onResume();

^Override protected void onPause() { super.onPause(); mTestHarness.onPause();

Now let's look into the AnimatedSimpleTriangleRenderer class, which appears in Listing 13-8. It's responsible for drawing the rectangle at frequent intervals to simulate animation.

0 0

Post a comment