Lecture 8: Graphics By: Eliav Menachi.

Slides:



Advertisements
Similar presentations
Threads, Surface Views and Real-Time Games. Background Most of the Android apps we’ve covered so far have been single threaded – And Event driven – An.
Advertisements

CS378 - Mobile Computing 2D Graphics A Crash Course in Using (Android) 2D Graphics Libraries.
Graphics & Animation in Android. Android rendering options The Canvas API Renderscript OpenGL wrappers NDK OpenGL
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Development of mobile applications using PhoneGap and HTML 5
Android Fragments A very brief introduction Android Fragments1.
Written by Liron Blecher
Basic Drawing Techniques
Java Beans.
Foundation Flash CS Introduction Welcome to Flash CS3 Professional. You have seen a lot of the great stuff Flash can do and it is now time for.
6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin.
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
Mobile Application Development using Android Lecture 2.
Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 lcdui Rob Pooley
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 13 lcdui and OXO Rob Pooley
Introduction to Flash Animation CS 318. Topics Introduction to Flash and animation The Flash development environment Creating Flash animations  Layers.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Announcements Homework #2 will be posted after class due Thursday Feb 7, 1:30pm you may work with one other person No office hours tonight (sorry!) I will.
SurfaceView.
Basic Animation. Animation 4 options – Animated.gif – Frame by Frame animation – Tweened animation This is our focus – OpenGL ES Graphics API for more.
Mobile Computing Lecture#12 Graphics & Animation.
Object-Oriented Programming: Inheritance and Polymorphism.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
By: Eliav Menachi.  Android custom 2D graphics library  OpenGL ES 1.0 for high performance 3D graphics.
CHAPTER 4 Fragments ActionBar Menus. Explore how to build applications that use an ActionBar and Fragments Understand the Fragment lifecycle Learn to.
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
CHAPTER 5 Graphics Drawing Audio. Chapter objectives: Learn to draw to a canvas Examine the process of adding drawn elements and UI controls to a layout.
Lecture 3: Animation & Graphics Topics: Animation, Graphics, Drawing Date: Feb 2, 2016.
Graphics & Animation Radan Ganchev Astea Solutions.
Computer System Structures
X3DOM : Integrating 3D content seamlessly into webpage
Microsoft Foundation Classes MFC
Drawing And Animations
Android Mobile Application Development
Android Application 2D Graphics cs.
Lecture 3: Animation & Graphics
Graphical Output Basic Images.
Working in the Forms Developer Environment
Lecture 3: Animation & Graphics
Instructor: Mazhar Hussain
Lecture 8: Graphics By: Eliav Menachi.
Chapter 4: Scalable Vector Graphics (SVG)
Android.
Cross Platform Development using Software Matrix
Java Look-and-Feel Design Guidelines
3.02 Computer Animation Software and Design Guidelines
Technologies Overview Media files, such as the sounds, are placed in the app’s resource folder res/raw. When an Activity is shut down, its Fragment.
Activities and Intents
Android Layouts 24 July 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
CSC461 Lecture 8: Input Devices
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Introduction to Operating System (OS)
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
Understand Windows Forms Applications and Console-based Applications
Mobile Computing With Android ACST 4550 Android Animation
EE 422C Java FX.
Android Programming Lecture 6
Game Loop Frame Rate.
Animate Workspace. Objective % Utilize appropriate tools and methods to produce digital animation.
.NET and .NET Core 7. XAML Pan Wuming 2017.
Cannon Game App Android How to Program
Game Loop Update & Draw.
Object-Oriented Programming: Inheritance and Polymorphism
Lecture 3: Animation & Graphics
Model, View, Controller design pattern
ANIMATE WORKSPACE Stage Timeline Properties Panel Library Panel
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Mobile Computing With Android ACST 4550 Android Animation
Adobe Flash CS3 Revealed
Presentation transcript:

Lecture 8: Graphics By: Eliav Menachi

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

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

Drawing into a view 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

Simple Graphics Inside a View Android offers a custom 2D graphics library for drawing and animating shapes and images: android.graphics.drawable android.view.animation

Drawables A Drawable is a general abstraction for "something that can be drawn" 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

ShapeDrawable ShapeDrawable is used to dynamically draw some two-dimensional graphics A ShapeDrawable is an extension of 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

Drawing directly to a Canvas 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.. In a separate thread, by managing a SurfaceView and performing draws to the Canvas as fast as your thread is capable.

Draw with a Canvas 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. Using the canvas: On a View On a SurfaceView

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

Programmatic Animation 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

On a SurfaceView The SurfaceView is a special subclass of View that offers a dedicated drawing surface within the View hierarchy 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

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

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

The Drawing Thread Pass the SurfaceHandler to the thread Retrieve the Canvas with lockCanvas() Do the drawing Call unlockCanvasAndPost(), passing it your Canvas object The Surface will now draw the Canvas as you left it

Tween Animation 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

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

Frame Animation 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 <animation-list> element as the root node and a series of child <item> nodes that each define a frame The frame is a drawable resource for the frame and the frame duration. See simple animation example

OpenGL ES (Embedded Systems) 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

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