6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin.

Slides:



Advertisements
Similar presentations
Interaction Design: Visio
Advertisements

1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Adobe Flash CS4 – Illustrated Unit E: Optimizing and Publishing a Movie.
Chapter 6 Jam! Implementing Audio in Android Apps.
Chapter 6: Jam! Implementing Audio in Android Apps.
CS378 - Mobile Computing 2D Graphics A Crash Course in Using (Android) 2D Graphics Libraries.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Graphics in Android 1 Fall 2012 CS2302: Programming Principles.
Custom Views, Drawing, Styles, Themes, ViewProperties, Animations, oh my!
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Basic Drawing Techniques
2D Graphics: Part 2.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Chapter 10: Move! Creating Animation
Exploring 2D Graphics: The Sudoku Example Content taken from book: “Hello, Android” by Ed Burnette Third Edition.
BFTAW BDPA Workshop Introduction to GIMP Chris
BFTAW BDPA Workshop Introduction to GIMP Chris
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
Tutorial 6 Working with Bitmaps and Gradients, and Publishing Flash Files.
Tutorial 2 Drawing Text, Adding Shapes, and Creating Symbols.
Doodlz App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Creating a Logo – Lesson 3 1 Creating a Logo Lesson 3.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 7: Reveal! Displaying Pictures in a GridView.
Android Boot Camp for Developers Using Java, 3E
Chapter 7: Reveal! Displaying Pictures in a Gallery.
Java Graphics. Review 3 kinds of elements in components API? Layout managers Events Extend vs. Implement.
Tutorial 2 Drawing Shapes, Adding Text, and Creating Symbols.
Android Graphics Library. Color Android colors are represented with four numbers, one each for alpha, red, green, and blue (ARGB). Each component can.
CS378 - Mobile Computing Responsiveness. An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the.
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.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
CS378 - Mobile Computing User Interface Basics. User Interface Elements View – Control – ViewGroup Layout Widget (Compound Control) Many pre built Views.
Graphics in Android 1 CS7030: Mobile App Development.
Mobile Computing Lecture#12 Graphics & Animation.
Android View Stuff. TextViews Display text Display images???
Flag Quiz Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 10: Move! Creating Animation 1 Android.
By: Eliav Menachi.  Android custom 2D graphics library  OpenGL ES 1.0 for high performance 3D graphics.
Notices Assn 4 posted. Due last day of class. Note that Exercise 10 contains the JavaFX code for three simple GUI programs. Winter 2016CMPE212 - Prof.
Adobe Flash Professional CS5 – Illustrated Unit E: Optimizing and Publishing a Movie.
David Sutton 2D GRAPHICS IN ANDROID. INTRODUCTION AND OUTLINE  In this week’s session we will create a simple Kaleidoscope application. Topics that will.
HTML5 and CSS3 Illustrated Unit F: Inserting and Working with Images.
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.
CS371m - Mobile Computing 2D Graphics A Crash Course in Using (Android) 2D Graphics Libraries.
Lecture 3: Animation & Graphics Topics: Animation, Graphics, Drawing Date: Feb 2, 2016.
Graphics & Animation Radan Ganchev Astea Solutions.
Android Application 2D Graphics cs.
Lecture 3: Animation & Graphics
Lecture 3: Animation & Graphics
Inserting and Working with Images
Lecture 8: Graphics By: Eliav Menachi.
Android Boot Camp for Developers Using Java, 3E
2D Graphics: Part 2.
Android Layouts 24 July 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
2D Graphics A Crash Course in Using (Android) 2D Graphics Libraries
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Graphics with Canvas.
Cannon Game App Android How to Program
Lecture 3: Animation & Graphics
Lecture 8: Graphics By: Eliav Menachi.
Presentation transcript:

6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin

Android Graphics Does not use the Java awt or swing packages Whole set of custom classes Canvas: class that holds code for various "draw" methods Paint: Controls the drawing. A whole host of properties. Similar to Java Graphics object Bitmap: the things drawn on Drawable: the thing to draw. (rectangles, images, lines, etc.) 2

Common Methods for Drawing Two approaches draw graphics or animations into a View object that is part of layout – define graphics that go into View – the simple way Draw graphics directly to a Canvas – the complex way 3

Simple Graphics Use Drawables in Views Create a folder res/drawable Add images – png (preferred) – jpg (acceptable) – gif (discouraged) Images can be added as background for Views 4

Simple Graphics Change background to an image – previously used background colors 5

Top Ten With Image Background 6

Add ImageView to Layout In the main.xml for top ten 7

ImageView Attributes scaleType: how image should be moved or resized in the ImageView tint: affects color of image more to position image in ImageView 8

Changing ImageView Programmatically Randomly set the alpha (transparency of the image) Or pick an image randomly Or set image based on month (Season) 9

Using a Canvas Simple way -> Create a custom View and override the onDraw method The Canvas is sent as a parameter Create a class that extends View – override the 2 parameter constructor – override the onDraw method – perform custom drawing in the onDraw method – add the View to the proper layout 10

Simple Example - Graphics View 11

GraphicsView - onDraw 12

Add CustomView to XML in main.xml add custom View as last element in LinearLayout 13

Canvas Class methods to draw – lines – arcs – paths – images – circles – ovals – points – text – and a few I missed 14

Paint typically create Paint with anti aliasing Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); 15

Anti Aliasing 16

Paint Object many, many attributes and properties including: – current color to draw with – whether to fill or outline shapes – size of stroke when drawing – text attributes including size, style (e.g. underline, bold), alignment, – gradients 17

Gradients 3 kinds of gradients LinearGradeint RadialGradeint SweepGradient at least 2 color, but possibly more flows from one color to another 18

Linear Gradient 19

LinearGradient 20

RadialGradient 21

RadialGradient 22

SweepGradient 23

SweepGradient 24

SweepGradient 25

SweepGradient 26

SweepGradient 27

GuessFour 28

Simple Animations Tweened Animations provide a way to perform simple animations on Views, Bitmaps, TextViews, Drawables provide start point, end point, size, rotation, transparency, other properties Can set up tweened animation in XML or programmatically 29

GuessFour Example On error board shakes back and forth On win board shakes up and down From BoardView in GuessFour 30

res/anim shake up down shake left right 31

More Tweened Examples hyperspace example from android dev site rotate and change alpha animation types: – alpha – scale – translate – rotate 32

More Complex Graphics Don't want apps to become unresponsive If complex graphics or animation use SurfaceView class Main view not waiting on onDraw to finish secondary thread with reference to SurfaceView SrufaceView draws and when done display result 33

Using a SurfaceView extend SurfaceView implement SurfaceHolder.Callback – methods to notify main View when SurfaceView is created, changed or destroyed 34

Simple Example Static Screen continuously draw several hundred small rectangles (points, with stroke = 10) – slowly fill screen and then keep changing 35

Implement SurfaceHolder.Callback methods 36

Prevent Runaway Threads! 37

Inner Class for Thread 38

Run Method in StaticThread 39 Standard Approach for Drawing on SurfaceView

Demo run() Pronounced flicker and jitter Double buffer under the hood We are drawing on two different Bitmaps Canvas does drawing onto Bitmap 40

Remove Flicker / Jitter If we draw background each "frame" then we don't redraw previous rectangles How about "saving" all the data? – points, colors 41

Alternative Recall two approaches: – draw on UI thread by overriding onDraw create custom View (tutorial 4) okay if not a lot of drawing – must keep UI thread responsive complex drawing or animations using SurfaceView Third approach, possible variation on the above two approaches – maintain a separate Bitmap 42

Separate Bitmap StaticThread has a Bitmap instance var Initialize in constructor 43

Updates to Bitmap 44 Create a Canvas to draw on the Bitmap we are saving When done drawing to Bitmap use SurfaceView Canvas to draw

Demo Alt Version of run() Flicker and jitter? Also possible to save Bitmap to file for later use 45

Animations Frame based vs. Time based Frame based: – update every frame – simple, but difference in frame rates Time based – update every frame but based on time elapsed since last frame – more work, more accurate – sdk example lunar lander 46

Checking Frame Rate From StaticView Emulator 6-7 fps, dev phone fps 47

Controlling Frame Rate Sleep after completing work in loop of run More complex than shown, use previous time and current time 48