Lecture 3: Animation & Graphics

Slides:



Advertisements
Similar presentations
CS378 - Mobile Computing 2D Graphics A Crash Course in Using (Android) 2D Graphics Libraries.
Advertisements

Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Graphics & Animation in Android. Android rendering options The Canvas API Renderscript OpenGL wrappers NDK OpenGL
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
2D Graphics: Part 1. Android Graphics Libraries 2D Graphics –custom 2D graphics library in packages android.graphics android.graphics.drawable android.graphics.drawable.shapes.
Basic Animation. Animation 4 options – Animated.gif – Frame by Frame animation – Tweened animation This is our focus – OpenGL ES Graphics API for more.
Custom Views, Drawing, Styles, Themes, ViewProperties, Animations, oh my!
Basic Drawing Techniques
2D Graphics: Part 2.
CHAPTER 4 Images XNA Game Studio 4.0. Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures.
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.
Flag Quiz App 1 CS7030: Mobile App Development. assets Folder 2 CS7030: Mobile App Development  drawable folder – Image contents at the root level 
CE Applied Communications Technology Android lecture 2 - Structures Android File structure Resources Drawables Layout Values R Class Manifest Running.
Animation.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
SpotOn Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Android Boot Camp for Developers Using Java, 3E
Android Graphics Library. Color Android colors are represented with four numbers, one each for alpha, red, green, and blue (ARGB). Each component can.
Animations 1 Fall 2012 CS2302: Programming Principles.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
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.
Mobile Programming Lecture 11 Animation and TraceView.
Android Threads. Threads Android will show an “ANR” error if a View does not return from handling an event within 5 seconds Or, if some code running in.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Basic Animation. Animation 4 options – Animated.gif – Frame by Frame animation – Tweened animation This is our focus – OpenGL ES Graphics API for more.
© 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.
Mobile Computing Lecture#12 Graphics & Animation.
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
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.
David Sutton 2D GRAPHICS IN ANDROID. INTRODUCTION AND OUTLINE  In this week’s session we will create a simple Kaleidoscope application. Topics that will.
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.
Android.
Chapter 2: Simplify! The Android User Interface
Android Application 2D Graphics cs.
Graphics & Animation in Android
GUI Programming Fundamentals
滑動版面 建國科技大學 資管系 饒瑞佶 2013/7 V1.
CS499 – Mobile Application Development
Lecture 3: Animation & Graphics
Lecture 8: Graphics By: Eliav Menachi.
Android Boot Camp for Developers Using Java, 3E
2D Graphics: Part 2.
S.RENUKADEVI/AP/SCD/ANDROID - Notifications
Android Layouts 24 July 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
Android Introduction Camera.
Android SDK & App Development
Image Asset Vector Asset
Mobile Computing With Android ACST 4550 Android Animation
2D Graphics A Crash Course in Using (Android) 2D Graphics Libraries
Android Programming Lecture 6
Android Layout Basics Topics
Many thanks to Jun Bum Lim for his help with this tutorial.
Graphics with Canvas.
Android: Shapes.
Lecture 3: Animation & Graphics
Android SDK & App Development
Lecture 8: Graphics By: Eliav Menachi.
Android Project Structure, App Resources and Event Handling
CS 240 – Advanced Programming Concepts
Android: Shapes.
Mobile Computing With Android ACST 4550 Android Animation
Presentation transcript:

Lecture 3: Animation & Graphics Topics: Animation, Graphics, Drawing Date: Jan 31, 2016

References (study these) http://developer.android.com/guide/topics/graphics/overview.html http://developer.android.com/guide/topics/graphics/prop-animation.html http://developer.android.com/guide/topics/graphics/view-animation.html http://developer.android.com/guide/topics/graphics/drawable-animation.html http://developer.android.com/guide/topics/graphics/2d-graphics.html

High Five! https://youtu.be/uFpoXq73HHY

Animation Overview Property Animation View Animation Drawable Animation

1. Property Animation (Value) Changing value of a variable over a period: Use setInterpolator() to change behavior. ValueAnimator anim = ValueAnimator.ofFloat(0f, 40f); anim.setDuration(40); anim.start(); Limitation?

1. Property Animation (Object) Changing a property of an object. Hello World Hello World Hello World ObjectAnimator anim = ObjectAnimator.ofFloat(myTextView, “textSize”, 10f, 30f); anim.setDuration(5000); anim.start(); Object Variable

2. View Animation You can animate a View e.g., by scaling, rotating, translating an ImageView.

2. View Animation Define the Animation in XML: res/anim Use Animation to fetch it, then apply it to a View. <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="360" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset=“1000" android:duration="10000" /> Animation x = AnimationUtils.loadAnimation( getApplicationContext(), R.anim.abovexmlfile ); someView.startAnimation(x);

3. Drawable Animation We can load and display a series of Drawable resources (e.g. images) one after another.

3. Drawable Animation Define animation-list in XML: res/drawable Use AnimationDrawable inside your code <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot=“false"> <item android:drawable="@drawable/pic1" android:duration=“1000" /> <item android:drawable="@drawable/pic2" android:duration=“1000" /> <item android:drawable="@drawable/pic1" android:duration=“1000" /> <item android:drawable="@drawable/pic2" android:duration=“1000" /> </animation-list> someImgView.setBackgroundResource(R.drawable.abovexml); ((AnimationDrawable)someImgView.getBackground()).start();

Code Practice: Get a few images and copy: res/drawable/ Create an XML file: res/drawable/my_anim_list Add an ImageView and set Background Use AnimationDrawable to start animation

Graphics Overview Canvas and Drawables Hardware Acceleration (think GPU) OpenGL (framework API and NDK) drawRect() drawCircle() … Bitmap Canvas

2D Drawing Drawable: Canvas: Put Drawables (into a View) Less work, less control, less efficiency Canvas: Draw on the Canvas (of a View) More work, more control, more efficiency

1. Using Drawables Putting Drawables into a View Four ButtonViews res/drawable/Queen.png Four ButtonViews res/drawable/tfade.xml

1. Using Drawables android.graphics.drawable BitmapDrawable, Transition Drawable, Animation Drawable, ShapeDrawable, etc. Two ways to add Drawables: Image from Project Resource XML file defining Drawable properties

1(a) Image from Project Resource Copy images into res/drawable/ Use it inside the layout xml You can also do the same by writing code: <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/img1" android:src="@drawable/my_image"/> ImageView i = new ImageView(this); i.setImageResource(R.drawable.my_image); LinearLayout ll = new LinearLayout(this); ll.addView(i); setContentView(ll); //instead of setContentView(R.layout.somexmllayoutfile)

1(b) XML with drawable properties e.g. Transition Drawable: res/drawable/something.xml Now, take an ImageView to show it (them): <transition xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/image1"> <item android:drawable="@drawable/image2"> </transition> TransitionDrawable td; td = (TransitionDrawable) getResources().getDrawable(R.drawable.something); td.setCrossFadeEnabled(true); ImageView img; img = (ImageView) findViewById(R.id.img1); img.setImageDrawable(td); td.startTransition(5000);

Nine Patch Image Regular .png images + defining stretchable regions From a terminal: Run the draw9patch command from your SDK sdk/tools directory to launch the tool.

2. Using Canvas Canvas holds all of your draw*() calls. Drawing is performed upon an underlying Bitmap. Two ways to use the Canvas of a View: Custom View Surface View Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); Paint p = new Paint(); p.setColor(Color.GREEN); c.drawRect(10, 10, 90, 90, p);

2(a) Canvas of a Custom View Good for low frame-rate applications (e.g. chess or snake game). You define a new View and add it in the layout XML file (like you do for a TextView, ImageView etc.) Android provides you the Canvas as you extend a View and override its onDraw() method. To request a redraw, use: invalidate(). Outside main Activity’s thread, use postInvalidate().

2(a) Canvas of a Custom View Create your own View Class (CustomView.java) Use the View in the layout xml To force a redraw: invalidate() public class CustomView extends View { //Declare all four types of constructors here. @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //Use canvas.draw*() } } <edu.unc.nirjon.projectname.CustomView android:id="@+id/mycustomview" android:layout_width="match_parent" android:layout_height="match_parent" />

Code Practice: Create 2 Buttons: Up and Down Create a Custom View Draw a circle at location (X, Y) Every time the buttons are clicked, the point will move. (Hint: use invalidate() to force redraw).