Android Application 2D Graphics cs.

Slides:



Advertisements
Similar presentations
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Advertisements

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.
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.
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.
Chapter 10: Move! Creating Animation
6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin.
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.
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 Hello World 1. Click on Start and type eclipse into the textbox 2.
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.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
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???
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.
Resources. Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type anim/XML files that define tween.
Graphics & Animation Radan Ganchev Astea Solutions.
Lecture 3: Animation & Graphics
David Meredith Aalborg University
Lecture 3: Animation & Graphics
Inserting and Working with Images
Lecture 8: Graphics By: Eliav Menachi.
Android Boot Camp for Developers Using Java, 3E
Flash Interface, Commands and Functions
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.
Chapter 15, Images …a few points
Graphics in Android Fall 2012 CS2302: Programming Principles.
Graphics with Canvas.
Cannon Game App Android How to Program
Lecture 3: Animation & Graphics
Lecture 8: Graphics By: Eliav Menachi.
Presentation transcript:

Android Application 2D Graphics cs

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.)

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

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

Simple Graphics Change background to an image previously used background colors

Top Ten With Image Background

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

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

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

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

Simple Example - Graphics View

GraphicsView - onDraw

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

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

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

Anti Aliasing

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

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

Linear Gradient

LinearGradient

RadialGradient

RadialGradient

SweepGradient

SweepGradient

SweepGradient

SweepGradient

SweepGradient

GuessFour

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

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

res/anim shake up down shake left right

More Tweened Examples hyperspace example from android dev site rotate and change alpha animation types: alpha scale translate rotate http://developer.android.com/guide/topics/resources/animation-resource.html

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

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

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

Implement SurfaceHolder.Callback methods

Prevent Runaway Threads!

Inner Class for Thread

Run Method in StaticThread 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

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

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

Separate Bitmap StaticThread has a Bitmap instance var Initialize in constructor

Updates to Bitmap 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

Animations Frame based vs. Time based Frame based: Time 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

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

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