Presentation is loading. Please wait.

Presentation is loading. Please wait.

By: Eliav Menachi.  Android custom 2D graphics library  OpenGL ES 1.0 for high performance 3D graphics.

Similar presentations


Presentation on theme: "By: Eliav Menachi.  Android custom 2D graphics library  OpenGL ES 1.0 for high performance 3D graphics."— Presentation transcript:

1 By: Eliav Menachi

2  Android custom 2D graphics library  OpenGL ES 1.0 for high performance 3D graphics

3  When drawing 2D graphics, you'll typically do so in one of two ways 1. Draw your graphics or animations into a View object from your layout. 2. Draw directly to a Canvas

4  Best choice when drawing simple graphics  Where is no need to change dynamically  Its not part of a performance-intensive game  The drawing and animation is handled by the system's normal View hierarchy drawing process  You simply define the graphics to go inside the View

5  Android offers a custom 2D graphics library for drawing and animating shapes and images :  android.graphics.drawable android.graphics.drawable  android.view.animation android.view.animation

6  A Drawable is a general abstraction for "something that can be drawn"Drawable  There are three ways to define and instantiate a Drawable:  using an image saved in your project resouces  using an XML file that defines the Drawable properties  using the normal class constructors

7  ShapeDrawable is used to dynamically draw some two-dimensional graphics ShapeDrawable  A ShapeDrawable is an extension of Drawable Drawable  ShapeDrawable has its own draw() method  you can create a subclass of View that draws the ShapeDrawable during the View.onDraw() method  See Simple Shape example

8  When you're application needs to regularly re-draw itself (like games)  There's more than one way to do this:  In the same thread as your UI Activity, using a custom View in your layout, call invalidate() and then handle the onDraw() callback..invalidate()onDraw()  In a separate thread, by managing a SurfaceView and performing draws to the Canvas as fast as your thread is capable.SurfaceView

9  A Canvas works for you as a pretense, or interface, to the actual surface upon which your graphics will be drawn  The Canvas holds all of your "draw" calls  Via the Canvas, your drawing is actually performed upon an underlying Bitmap, which is placed into the window.Bitmap  Using the canvas:  On a View  On a SurfaceView

10  Create a custom View component  Override the onDraw() callback methodonDraw()  This method will be called by the Android framework to request that the View draw itself  Use the given Canvas for drawingCanvas  The View is drawn by Android only when invalidated  Use Invalidate() to invalidate the View  See SimpleShape Example

11  Create an animated View  Create a Drawable to hold our animated image  Override the onDraw method which draw the view  Setting bounds defines the position and size of the image inside the View  Display the view in your activity and update the view periodically

12  The SurfaceView is a special subclass of View that offers a dedicated drawing surface within the View hierarchySurfaceView  The aim is to offer this drawing surface to an application's secondary thread  The application isn't required to wait until the system's View hierarchy is ready to draw  Secondary thread can draw to its own Canvas at its own pace using a reference to the SurfaceView

13 1. Create a new class that extends SurfaceViewSurfaceView  The class should also implement SurfaceHolder.Callback SurfaceHolder.Callback ▪ an interface that will notify you with information about the underlying Surface (created, changed, or destroyed)Surface 2. Define your secondary Thread class  The thread will perform all the drawing procedures to your Canvas

14 3. When your SurfaceView is initialized, get the SurfaceHolder by calling getHolder()getHolder()  Instead of handling the Surface object directly, you should handle it via a SurfaceHolderSurfaceHolder 4. Notify the SurfaceHolder that you'd like to receive SurfaceHolder callbacks by calling addCallback() addCallback() 5. Override each of the SurfaceHolder.Callback methods inside your SurfaceView class.SurfaceHolder.Callback

15 1. Pass the SurfaceHandler to the thread 2. Retrieve the Canvas with lockCanvas()lockCanvas() 3. Do the drawing 4. Call unlockCanvasAndPost(), passing it your Canvas objectunlockCanvasAndPost()  The Surface will now draw the Canvas as you left it

16  A tween animation can perform a series of simple transformations (position, size, rotation, and transparency) on the contents of a View object  A sequence of animation instructions defines the tween animation  The instructions are defined by either XML or Android code

17  The animation instructions defines:  The transformations  when the transformation will occur  How long they should take to apply  Transformations can be sequential or simultaneous

18  Created a sequence of different images, played in order, like a roll of film  The XML file that lists the frames that compose the animation  The XML file consists of an element as the root node and a series of child nodes that each define a frame  The frame is a drawable resource for the frame and the frame duration.  See simple animation example

19  OpenGL defines a cross-platform and cross- language API for computer graphics  OpenGL ES is a limited version of OpenGL costumed for mobile phones, PDAs, video game consoles, and other embedded systems  OpenGL ES standard: http://www.khronos.org/opengles/ http://www.zeuscmd.com/tutorials/opengles/index.php

20 1. Create a custom View subclass. 2. Get a handle to an OpenGLContext, which provides access to Android’s OpenGL ES functionality. 3. In the View’s onDraw() method, use the handle to the GL object and then use its methods to perform any GL functions.


Download ppt "By: Eliav Menachi.  Android custom 2D graphics library  OpenGL ES 1.0 for high performance 3D graphics."

Similar presentations


Ads by Google