Android Resources, Animation and Intents
Android Resources, Animation and Intents
Announcements
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
Today
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
Section Feedback
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
http://tommymacwilliam.com/e76/feedback
let me know how Im doing!
I dont like long surveys either, so give me feedback via an anonymous (I promise) 140-character tweet!
Resources
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
remember, resources are anything in our project that isnt code all resources will be placed in a special directory called res
this directory contains subfolders to organize your resources by type
Resources
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
anim: animations (which well take a look at later) color: colors used for different states of UI elements drawable: PNG, JPG, GIF, etc. layout: layouts for activities (which we saw last week) menu: app menus (i.e. Options, Context, etc.) raw: any le needed in its raw for (i.e. plaintext) xml: conguration XML les
Accessing Resources
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
<type>:
Resources
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
Alternative Resources
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
unlike the iPhone, there are many different types of Android devices
which all have different hardware specs, screen resolutions, etc.
Alternative Resources
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
resource qualiers
language: en, en-rUS, es, etc. (any valid ISO 639-1 code)
http://www.loc.gov/standards/iso639-2/php/code_list.php
screen size: small, normal, large, xlarge screen aspect ratio: long, notlong screen orientation: port, land
Alternative Resources
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
resource qualiers
pixel density: ldpi, mdpi, hdpi, xhdpi, nodpi text input: nokeys, qwerty, 12key navigation: nonav, dpad, trackball, wheel
must be specied in the order they were presented here 4-step process
eliminate any contradictions (device is en, app has cong for es) iterate through qualiers (all possible qualiers in the predened order) check if any folder matches the qualier if match, eliminate directories that do not include the qualier (until only one directory is left)
Alternative Resources
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
example time!
Styles
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
Styles
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
<style> denes multiple <item>s <item>s name attribute is equivalent to the View attribute
value equivalent to the value of the View attribute
Styles
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
style can inherit from platform styles and themes via the parent attribute a style can also extend an already dened style
name=MyStyle.Something will automatically inherit from the style with name=MyStyle
Styles
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
example time!
Tween Animations
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
despite its name, unrelated to Justin Bieber equivalent to CSS3 transitions, can be used to animate any View object
admittedly a bit more verbose than CSS3, though
Tween Animations
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
transitions
<alpha>: fade a Views opacity in/out <scale>: resize a View <translate>: vertical/horizontal motion <rotate>: rotate a View
all transitions must be children of a <set>, but a <set> can contain <set>s
Tween Animations
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
Applying Animations
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
call startAnimation on the View we want to animate AnimationListener provides callbacks to detect when an animation is complete
Tween Animations
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
example time!
Interpolators
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
just like in CSS3, the interpolator determines how the animation is applied
built-in interpolators given by @android:anim/<interpolator> accelerate_decelerate_interpolator, bounce_interpolator, linear_interpolator, overshoot_interpolator
Interpolators
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
example time!
Frame Animation
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
used to animate drawable elements animation consists of multiple <item>s, each a child of an <animation-list>
each <item> must have an android:drawable and android:duration remember, we can access drawable resources via @drawable/<name>
Intents
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
remember, Activities, Broadcast Receivers, and Services are triggered via Intents
last week: Intent i = new Intent(Context packageContext, Class<?> cls); startActivity(i);
we can use Intents to trigger (private) actions within our own app and (public) actions within other apps
Intents
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
Intents
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
<URI> contains data for the action (phone number to call, etc.) formatted as a URI
scheme://host/path/segments getScheme(), getHost(), getPathSegments()
Bundles
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
we can pass additional data to Activities with bundles sending data: intent.putExtra(key, value); retrieving passed data: Bundle bundle = getIntent().getExtras(); bundle.getString(key);
Intent Filters
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
we can also allow other apps to open Activities within our app via Intent Filters we register these in AndroidManifest.xml
generally not created using Java also where we tell Android what Activities exist in our app
Intent Filters
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
<intent-filter> must be a child of an <activity> and can contain <action>, <data>, and <category> elements
<action>: action to be performed <data>: format through which data is passed to the activity
accessed via getIntent().getData()
Intent Filters
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
we can also use Intent Filters to open our apps Activities from within our app
the other syntax is kinda ugly
if we give our <action> a unique android:name attribute, we can just pass that to the Intent constructor
Intent Filters
Android: Resources, Animation and Intents Tommy MacWilliam Resources Styles Animations Intent Filters
example time!