Lecture 3: Animation & Graphics
Lecture 3: Animation & Graphics
https://youtu.be/uFpoXq73HHY
Concepts
What is Animation?
• To create an illusion of motion or change.
• By rapid succession of sequential, minimally
different images.
A 2D graphic (tree) is
synthesized by using basic
shapes (circles and a rectangle)
What is Computer Vision?
• To understand images using computers.
• e.g., identifying objects in images
• Tools/API: OpenCV, OpenVX
https://www.youtube.com/watch?v=xVwsr9p3irA
What is a GPU?
• Specialized HW for graphics processing.
• Large number of cores and threads.
• Limited features (instruction types, OS interactions)
ALU ALU
Control ALU Control ALU
ALU ALU
Cache Cache
Cache
RAM RAM
CPU GPU
Android: Source and Resource
• Source: e.g. .java
• Resources: e.g. layout, string, bitmap, animation.
• Benefits: multiple languages, multiple screens, easy to manage.
aapt Packed
Resource R.java
tool Resources
Libraries
Bitmap Shape
9-Patch State
Transition
Animation
Android Animation
Types of Animation
1. Drawable Animation
2. View Animation
3. Property Animation
((AnimationDrawable)someImgView.getBackground()).start();
We’ll try this today:
• Get some images and put into: res/drawable/
• Create an XML file: res/drawable/my_anim_list
• Add an ImageView and set Background
• Use AnimationDrawable to start animation
2. View Animation
• You can animate a View e.g., by scaling, rotating,
and translating an ImageView.
2. View Animation
• Define the Animation in XML: res/anim
XML:
<?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"
/>
someView.startAnimation(x);
3. Property Animation (Value)
• Changing value of a variable over a period:
Limitation?
3. Property Animation (Object)
• Changing a property of an object.
ObjectAnimator anim =
ObjectAnimator.ofFloat(myTextView, “textSize”, 10f, 30f);
anim.setDuration(5000);
anim.start();
Object Variable
Summary of Android Animation
• List of XML tags and Java Classes:
Animation Type XML Tag Java Class
Drawable Animation animation-list AnimationDrawable
View Animation rotate Animation
translate
scale
set
Property Animation ValueAnimator
ObjectAnimator
Android Graphics
Graphics Approches
• Canvas and Drawables
• OpenGL (framework API and NDK)
S2E9
2D Drawing
1. Drawable:
• Put Drawables (in a View)
• Less work, less control, less efficiency
2. Canvas:
• Draw on the Canvas (of a View)
• More work, more control, more efficiency
1. Using Drawables
• Two ways of putting Drawables into a View
Four
ButtonViews
res/drawable/queen.png
res/drawable/tfade.xml
1(a) Image from Project Resource
• Copy images into res/drawable/
• Use it inside the layout xml
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/img1"
android:src="@drawable/my_image"/>
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.
drawRect()
drawRect()
drawCircle()
…