android week 3 - android animations
DESCRIPTION
Join Live Course at http://www.wingnity.com/android Module Goals: In this part we will learn different Android features like ActionBar, Notifications, Playing Media Files etc. Also we will learn how to use Animations in Android to make our Apps more beautiful and interactivie. Options Menu Using Action Bar in Android Notifications Shared Preferences Media Player Video Player Animation in Android Tween Animations Alpha Scale Translate Rotate CrossFading Animations CardFlip AnimationsTRANSCRIPT
Android TechnologyDay Three
Agenda• Options Menu• Notifications• Designing and Creating Notifications• Shared Preferences• Preference Screens• Media Player
Agenda• Animation in Android• Tween Animations• Alpha• Scale• Translate• Rotate• Cross Fading Animations• Card Flip Animations
Options Menu• Above v-2.3 they are shown in Navigation
drawer• Override onCreateOptionsMenu() method to
define your custom menu
Below – V-2.3
Above – V-2.3
Notifications• Notification is a message that you can
display outside your application UI
• User can expand the notification bar and trigger another activity by clicking on notification.
1
3
2
Designing Notifications
Source – developers.android.com
Creating a Notification1. We design our notification with NotificationCompat.Builder
class
2. Defining the action of notification with PendingIntent
3. Firing the notification with NotificationManager
Preferences Screen (Easy Way)• Used to save key-value pairs of primitive data types
SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(getApplicationContext());
String myNameIs = settings.getString("name", "");
Shared Preferences (Default Way)
– Saving SharedPreferences prefs = getSharedPreferences(“details", MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putString(“name", “Whatever”); editor.commit();
– Retreiving SharedPreferences settings = getSharedPreferences("details", MODE_PRIVATE);
String myNameIs = settings.getString(“name", “No name found”);
• You should ask, where should we use this?
Media Player and Sound Pool• MediaPlayer class can be used
to control playback of audio/video files and streams.
• Use SoundPool when you have media files of very small duration.
Animations
Animations• Android’s Animation Framework provides two types of animations.
• Frame animation• Tween animation
Frame Animation• An XML based animation that shows a series of
images in order at regular intervals (like a film)
• Steps:
1. Create an XML file inside drawable folder2. Copy all the images inside the drawable folder
Frame Animation XML 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/jump1" android:duration="120"/> <item android:drawable="@drawable/jump2" android:duration="120"/> <item android:drawable="@drawable/jump3" android:duration="120"/> <item android:drawable="@drawable/jump4" android:duration="120"/> <item android:drawable="@drawable/jump5" android:duration="120"/> <item android:drawable="@drawable/jump6" android:duration="120"/> <item android:drawable="@drawable/jump7" android:duration="120"/> <item android:drawable="@drawable/jump8" android:duration="120"/>
</animation-list>
Tween Animation• An XML based animation that performs transitions such as:
– Rotating– Fading– Moving– Stretching
• Multiple transitions can be performed by using the <set> tag.• <set> is a container of other animations
FadingImportant attributes:
• android:fromAlpha• android:toAlpha
• Here Alpha represents Opacity of the object whose value can lie:
0.0 < alpha <1.0
Scaling• Animations to resize the objects.
android:pivotX -The X coordinate to remain fixed when the object is scaled.android:pivotY - The Y coordinate to remain fixed when the object is scaled.android:fromXScale - Starting X size offset, where 1.0 is no change.android:toXScale - Ending X size offset, where 1.0 is no change.android:fromYScale - Starting Y size offset, where 1.0 is no change.android:toYScale - Ending Y size offset, where 1.0 is no change.
All values are provided in Float.
Moving• A vertical and/or horizontal motion. • Supports the following attributes in any of the following three formats:
– values from -100 to 100 ending with "%", indicating a percentage relative to itself; – values from -100 to 100 ending in "%p", indicating a percentage relative to its parent; – a float value with no suffix, indicating an absolute value.
android:fromXDelta -Starting X Offsetandroid:fromYDelta - Starting Y Offset android:toXDelta - Ending X Offset android:toYDelta - Ending Y Offset
Rotating• Rotating the graphic in clock or anti-clockwise direction
• pivotX and pivotY are the center point of rotation.
android:fromDegrees -Starting Angular Positionandroid:toDegrees - Ending Angular Positionandroid:pivotX -The X coordinate of the center of rotation.android:pivotY - The Y coordinate of the center of rotation.
Set• With <set> you can execute multiple animation simultaneously or in series.
• Nesting of animations<set …> <scale …. /> <set …> <scale …./> <rotate…./> </set></set>
Interpolators• Interpolators allows your existing animation effects to be accelerated, decelerated,
repeated, bounced, etc. by using the android:interpolator attribute.
• Sample:
<set android:interpolator="@android:anim/accelerate_interpolator"> ...</set>
Q&A