Android Resources, Animation and Intents

download Android Resources, Animation and Intents

of 33

Transcript of Android Resources, Animation and Intents

  • 8/12/2019 Android Resources, Animation and Intents

    1/33

    Android:

    Resources,Animation and

    Intents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Android: Resources, Animation and Intents

    Tommy MacWilliam

    Harvard University

    February 22, 2011

    http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    2/33

    Android:

    Resources,Animation and

    Intents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Announcements

    Lecture videos available at:

    https://www.cs76.net/Lectures

    New section schedule: https://www.cs76.net/Sections section every week here right after lecture office hours weeks projects are due

    Tuesday/Wednesday nights walkthroughs on Thursdays after project released

    seminars on interesting mobile dev topics onnon-walkthrough weeks

    online labs

    http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    3/33

    Android:

    Resources,Animation and

    Intents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Today

    Resources

    Styles

    Animation

    Intent Filters

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    4/33

    Android:

    Resources,Animation and

    Intents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Section Feedback

    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!

    http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    5/33

    Android:

    Resources,Animation and

    Intents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Resources

    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 yourresources by type

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    6/33

    Android:

    Resources,Animation and

    Intents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Resources

    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 file needed in its raw for (i.e. plaintext)

    xml: configuration XML files

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    7/33

    Android:

    Resources,Animation and

    Intents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Accessing Resources

    resources can be accessed from XML and Java

    XML: @/ Java: R..

    : anim, drawable,etc.

    : filename (without the extension)

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    8/33

    Android:

    Resources,Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Resources

    values: predefined strings, integers, colors, etc.

    filenames are arbitrary, can contain arbitrary XMLelements

    each element must be a child of from Java: R.. from XML: @/

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    9/33

    Android:

    Resources,Animation andIntents

    TommyMacWilliam

    Resources

    StylesAnimations

    Intent Filters

    Alternative Resources

    unlike the iPhone, there are many different types of

    Android devices

    which all have different hardware specs, screen

    resolutions, etc.

    all of the folders in the resdirectory can be

    device-specific

    create a new folder called ---... can have any number of qualifiers, which match devices

    that match all qualifiers

    http://goforward/http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    10/33

    Android:

    Resources,Animation andIntents

    TommyMacWilliam

    Resources

    StylesAnimations

    Intent Filters

    Alternative Resources

    resource qualifiers

    language: en, en-rUS, es, etc. (any valid ISO639-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

    http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    11/33

  • 8/12/2019 Android Resources, Animation and Intents

    12/33

    Android:

    Resources,Animation andIntents

    TommyMacWilliam

    Resources

    StylesAnimations

    Intent Filters

    Picking the Best Resource

    must be specified in the order they were presented here

    4-step process

    eliminate any contradictions (device is en, app hasconfig for es)

    iterate through qualifiers (all possible qualifiers in thepredefined order)

    check if any folder matches the qualifier

    if match, eliminate directories that do not include thequalifier (until only one directory is left)

    http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    13/33

    Android:

    Resources,Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Alternative Resources

    example time!

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    14/33

    Android:

    Resources,Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Styles

    define a custom look and feel for UI elements

    the Android equivalent of CSS makes View XML much less verbose can apply the same style to multiple Views

    stored in XML files located in res/values/

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    15/33

  • 8/12/2019 Android Resources, Animation and Intents

    16/33

    Android:

    Resources,Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Styles

    style can inherit from platform styles and themes via

    theparentattribute a style can also extend an already defined style

    name=MyStyle.Something will automaticallyinherit from the style with name=MyStyle

    http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    17/33

    Android:

    Resources,Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Styles

    example time!

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    18/33

    Android:

    Resources,Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Tween Animations

    despite its name, unrelated to Justin Bieber

    equivalent to CSS3 transitions, can be used to animateany View object

    admittedly a bit more verbose than CSS3, though

    saved in res/anim

    defines properties to be animated concurrently

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    19/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Tween Animations

    transitions

    : fade a Views opacity in/out : resize a View

    : vertical/horizontal motion : rotate a View

    all transitions must be children of a , but a

    can contain s

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    20/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Tween Animations

    attributes in the form android:from

    and android:to

    : fromAlpha, toAlpha : from{X,Y}Scale, to{X,Y}Scale : from{X,Y}, to{X,Y},

    from{X,Y}Delta, to{X,Y}Delta : fromDegrees, toDegrees : duration, startOffset

    http://goforward/http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    21/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Applying Animations

    first, we load a newAnimationvia the

    AnimationUtils.loadAnimation

    recall we can access the animation viaR.anim.

    call startAnimationon the View we want to animate

    AnimationListenerprovides callbacks to detect

    when an animation is complete

    http://goforward/http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    22/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Tween Animations

    example time!

    http://goforward/http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    23/33

  • 8/12/2019 Android Resources, Animation and Intents

    24/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Interpolators

    example time!

    F A i i

    http://goforward/http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    25/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Frame Animation

    used to animate drawableelements

    animation consists of multiple s, each a child of

    an

    eachmust have an android:drawableandandroid:duration

    remember, we can access drawableresources via

    @drawable/

    I t t

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    26/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Intents

    remember, Activities, Broadcast Receivers, and

    Services are triggered via Intents

    last week:Intent i = new Intent(Context

    packageContext, Class cls);

    startActivity(i);

    Intent objects simply contain a description of what

    action is to be performed

    has an action, data, and a category

    we can use Intents to trigger (private) actions within our

    own app and (public) actions within other apps

    http://goforward/http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    27/33

    I t t

  • 8/12/2019 Android Resources, Animation and Intents

    28/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Intents

    contains data for the action (phone number to

    call, etc.) formatted as a URI

    scheme://host/path/segments getScheme(), getHost(), getPathSegments()

    category: additional information about the component

    that should respond

    CATEGORY_BROWSABLE: component can be invokedby the browser to display content

    CATEGORY_LAUNCHER: component can be shown asthe initial activity from the launcher

    manage categories with addCategory()and

    removeCategory()

    Bundles

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    29/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Bundles

    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

    http://goforward/http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    30/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    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

    http://goforward/http://find/http://goback/
  • 8/12/2019 Android Resources, Animation and Intents

    31/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Intent Filters

    must be a child of an

    and can contain , ,

    andelements : action to be performed : format through which data is passed to the

    activity

    accessed viagetIntent().getData()

    : component properties

    Intent Filters

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    32/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    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 a unique android:name

    attribute, we can just pass that to the Intent constructor

    Intent Filters

    http://find/
  • 8/12/2019 Android Resources, Animation and Intents

    33/33

    Android:Resources,

    Animation andIntents

    TommyMacWilliam

    Resources

    Styles

    Animations

    Intent Filters

    Intent Filters

    example time!

    http://find/