Unit 6
Working with Graphics and Animation
2D Graphics in Android
Android offers a custom 2D graphics library for drawing and
animating shapes and images.
The android.graphics.drawable and android.view.animation
packages are where you'll find the common classes used for
drawing and animating in two-dimensions.
A simple way to add graphics to your application is by
referencing an image file from your project resources.
Supported file types are PNG (preferred), JPG (acceptable) and
GIF (discouraged).
This technique would obviously be preferred for application
icons, logos, or other graphics such as those used in a game.
2D Graphics in Android
To use an image resource, just add your file to
the res/drawable/ directory of your project. From there, you
can reference it from your code or your XML layout. Either
way, it is referred using a resource ID, which is the file name
without the file type extension (E.g., my_image.png is
referenced as my_image).
Canvas API in Android is a drawing framework which helps us
to draw custom design like line, circle or even a
rectangle. Using these we can make any shape whichever we
want according to design.
In Android Studio, click on
View > Tool Windows > Resource Manager in the menus or
click on the Resource Manager tab to the left of the Project
window.
Click the + below Resource Manager, and select Import
Drawables.
Android graphics provides low level graphics tools such as
canvases, color, filters, points and rectangles which handle
drawing to the screen directly.
For implementation of graphics in android visit the link below:
https://www.javatpoint.com/android-simple-graphics-example
Applications of 2D Graphics
It can be used to create and edit logos, and other graphical
elements.
It can be used to create website layouts and design elements.
It can be used to create illustrations, visual presentations, and
digital art.
It can be used to edit and enhance photos, images, and
animation.
It can be used to create and edit website designs, presentation
slides, and marketing materials.
Bitmap in android
In Android, a Bitmap is a representation of an image that consists of pixels
with a specified width, height, and color format. A Bitmap from a View is a
Bitmap that is created from a View in your Android application.
In effect, a bitmap is an array of binary data representing the values of
pixels in an image or display. A GIF is an example of a graphics image file
that has a bitmap. When the GIF is displayed on a computer monitor, the
computer reads the bitmap to determine which colours to use to “paint” the
screen.
To display a raster image (bitmap) on the screen, you need an Image object
and a Graphics object. Pass the name of a file (or a pointer to a stream) to
an Image constructor. After you have created an Image object, pass the
address of that Image object to the DrawImage method of a Graphics
object.
Animations in Android
Animation in android apps is the process of creating motion
and shape change.
The basic ways of animation are as follows:
Fade In Animation
Fade Out Animation
Cross Fading Animation
Blink Animation
Zoom In Animation
Zoom Out Animation
Rotate Animation
Move Animation
Slide Up Animation
Slide Down Animation
Bounce Animation
Sequential Animation
Together Animation
Frame Animation in android
In Android Frame Animation, you will be swapping frames
repeatedly, so that it appears continuous to the human eye and
we feel that it is animated.
Frame is referred to an image. So to implement frame by frame
animation in android, one needs to have set of images, which
describes a motion.
For implementation of frame animation visit the following
link:
https://www.edureka.co/blog/frame-animation-in-android/#:~:t
ext=In%20Android%20Frame%20Animation%2C%20you,ima
ges%2C%20which%20describes%20a%20motion
.
Tween Animation in android
A tween animation can perform a series of simple
transformations (position, size, rotation, and transparency) on
the contents of a View object.
So, if you have a TextView object, you can move, rotate, grow,
or shrink the text.
If it has a background image, the background image will be
transformed along with the text.
We have four kinds tween animations:
Alpha, Rotate, Translate, Scale.
Tween Animation in android
Tween animation could be set in both code and xml.
By AnimationSet, we could mix these animations together.
By AnimationUtils.loadAnimation, we could load these
animations defined in xml.
By Animation.AnimationListener, we could add listener to
listen to changes of animations.
For implementation of Tween animation visit the following
link:
https://dongchuan.github.io/android/2015/06/21/Tween-Animat
ion.html#:~:text=We%20have%20four%20kinds%20tween,%2
C%20Rotate%2C%20Translate%2C%20Scale
.
View Animation in android
You can use the view animation system to perform tweened animation
on Views.
Tween animation calculates the animation with information such as the
start point, end point, size, rotation, and other common aspects of an
animation.
A tween animation can perform a series of simple transformations
(position, size, rotation, and transparency) on the contents of a View
object.
So, if you have a TextView object, you can move, rotate, grow, or shrink
the text. If it has a background image, the background image will be
transformed along with the text.
The animation package provides all the classes used in a tween
animation.
The drawback of this mechanism is that it can only be applied to Views.
Google Map API
References
https://developers.google.com/maps/documentation/androi
d-sdk/start#create-project
https://developers.google.com/maps/documentation/androi
d-sdk/map