Transcript
Page 1: Android week 3 - Android Animations

Android TechnologyDay Three

Page 2: Android week 3 - Android Animations

Agenda• Options Menu• Notifications• Designing and Creating Notifications• Shared Preferences• Preference Screens• Media Player

Page 3: Android week 3 - Android Animations

Agenda• Animation in Android• Tween Animations• Alpha• Scale• Translate• Rotate• Cross Fading Animations• Card Flip Animations

Page 4: Android week 3 - Android 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

Page 5: Android week 3 - Android Animations

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

Page 6: Android week 3 - Android Animations

Designing Notifications

Source – developers.android.com

Page 7: Android week 3 - Android Animations

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

Page 8: Android week 3 - Android Animations

Preferences Screen (Easy Way)• Used to save key-value pairs of primitive data types

SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(getApplicationContext());

String myNameIs = settings.getString("name", "");

Page 9: Android week 3 - Android Animations

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?

Page 10: Android week 3 - Android Animations

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.

Page 11: Android week 3 - Android Animations

Animations

Page 12: Android week 3 - Android Animations

Animations• Android’s Animation Framework provides two types of animations.

• Frame animation• Tween animation

Page 13: Android week 3 - Android Animations

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

Page 14: Android week 3 - Android Animations

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>

Page 15: Android week 3 - Android Animations

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

Page 16: Android week 3 - Android Animations

FadingImportant attributes:

• android:fromAlpha• android:toAlpha

• Here Alpha represents Opacity of the object whose value can lie:

0.0 < alpha <1.0

Page 17: Android week 3 - Android Animations

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.

Page 18: Android week 3 - Android Animations

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

Page 19: Android week 3 - Android Animations

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.

Page 20: Android week 3 - Android Animations

Set• With <set> you can execute multiple animation simultaneously or in series.

• Nesting of animations<set …> <scale …. /> <set …> <scale …./> <rotate…./> </set></set>

Page 21: Android week 3 - Android Animations

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>

Page 22: Android week 3 - Android Animations

Q&A

Page 23: Android week 3 - Android Animations

Thank You….!!http://www.wingnity.com/android

+91 999 755 8888