• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Android | Busy Java Developers Guide to Android: UI | Ted Neward

Android | Busy Java Developers Guide to Android: UI | Ted Neward






Total Views
Views on SlideShare
Embed Views



2 Embeds 16

http://lanyrd.com 15
https://www.linkedin.com 1



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Android | Busy Java Developers Guide to Android: UI | Ted Neward Android | Busy Java Developers Guide to Android: UI | Ted Neward Presentation Transcript

    • Busy Android Developer's Guide to UI Ted Neward Neward & Associates http://www.tedneward.com | ted@tedneward.com
    • Credentials
      • Who is this guy?
        • Architectural Consultant, Neudesic Software
        • Principal, Architect, Consultant and Mentor
          • ask me how I can help your project or your team
        • Microsoft MVP (F#, C#, Architect)
        • JSR 175, 277 Expert Group Member
        • Author
          • Professional F# 2.0 (w/Erickson, et al; Wrox, 2010)
          • Effective Enterprise Java (Addison-Wesley, 2004)
          • C# In a Nutshell (w/Drayton, et all; OReilly, 2003)
          • SSCLI Essentials (w/Stutz, et al; OReilly, 2003)
          • Server-Based Java Programming (Manning, 2000)
        • Blog: http://blogs.tedneward.com
        • Papers: http://www.tedneward.com/writings
        • Twitter: @tedneward
    • Objectives
      • Our goal here today is...
        • ... to get familiar with the various Android UI elements
        • ... to come to understand XML layouts
        • ... to learn how to handle events within Android UIs
    • Activities and Tasks
      • Activity
        • somewhat akin to a web page or screen
        • public class that extends android.app.Activity
        • activities have event methods for override
          • onCreate: activity "constructor"
          • onDestroy: activity "finalizer"
          • onStart/onResume/onPause/onStop/onRestart flow
          • remember to always call up the inheritance chain
    • Activities and Tasks
      • Tasks
        • Tasks are the logical thread of use through Activities
          • usually starting from the Home screen
        • Tasks form a "back stack" of Activity instances
          • "back" button removes the top card, destroys that activity
        • Tasks are distinct from one another
          • a new task creates a new stack of cards
          • this means more than one Activity instance of the same type is possible
        • Tasks cross applications and processes
          • in this respect, Activities are like web pages
    • Viewables
      • View and ViewGroups
        • View is the base class for "widgets"
        • ViewGroup is the base for Composite-patterned containers of other View objects (including other ViewGroup instances)
        • Each Activity can hold one content View
          • most often, this is a ViewGroup, forming a hierarchy
        • Custom Views and ViewGroups
          • you can do them, but it's pretty rare
    • Viewables
      • Widgets (android.widget)
        • "Push Me": Button, CompoundButton, CheckBox, ImageButton, RadioButton
        • Text: EditText, TextView, NumberPicker, TextSwitcher
        • Graphics: Gallery, ImageSwitcher, ImageView
        • Selectors: RatingBar, SeekBar, Spinner, Switch
        • Time: AnalogClock, DigitalClock, Chronometer, CalendarView, DatePicker, TimePicker
        • Composite: ListView, SlidingDrawer, TabHost
        • Media: MediaController
        • Space (literally, just that--empty space!)
        • ... and a few more
    • Viewables
      • Layouts (android.widget)
        • LinearLayout
        • RelativeLayout
        • TableLayout
        • GridLayout
        • AbsoluteLayout (bad!)
        • FrameLayout (mostly useless!)
    • Viewables
      • Dialogs (android.app) are a special case of Activity
        • AlertDialog (OK/Cancel/Help, etc)
        • ProgressDialog (56 of 100...)
        • DatePickerDialog
        • TimePickerDialog
      • But Dialogs are not Activities
        • Dialogs are always created and displayed as part of (and are "owned" by) an Activity; as such, they are intimately wrapped up in their host Activity's code
        • AlertDialog is the workhorse here
    • Creation
      • Two ways of creating UIs in Android
        • either create UI "by hand" in Java
        • or using XML-based layout (resource) file
          • layout resources are not tied to an Activity; they are just a group of Views laid out in an XML file
          • layout resources can be "inflated" from XML into UI objects (via a system service)
          • Activity.setContentView() is a shortcut way to do this
    • Layout Resources
      • Layout resources are in res/layout directory
        • XML file name corresponds to R.layout.{filename}
        • Root element is (usually) a ViewGroup (Layout class)
        • android: namespace is mandatory
        • element attributes describe "setter" values
        • android:id is critical for manipulation
          • "@+{prefix}/{name}" defines new R.{prefix}.{name} id
          • {prefix} is most often "id" but isn't required
          • IDs don't have to be unique across the entire tree (but usually are)
    • Layout Resources <LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; android:orientation=&quot;vertical&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot;> <ListView android:id=&quot;@+my_team_ids/lstInvitees&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;wrap_content&quot; android:padding=&quot;6dip&quot; /> <LinearLayout android:orientation=&quot;horizontal&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot; android:gravity=&quot;bottom&quot;> <TextView android:text=&quot;Add:&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; /> <EditText android:id=&quot;@+my_team_ids/txtNewTeamMember&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:hint=&quot;(Email address)&quot; android:maxLines=&quot;1&quot; /> <ImageButton android:id=&quot;@+my_team_ids/btnInvite&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:src=&quot;@android:drawable/sym_action_chat&quot; /> </LinearLayout> </LinearLayout>
    • Layout Resources
      • Layout resources can be &quot;tuned&quot;
        • like all resources, layouts can be spceialized to particular scenarios
          • screen size: &quot;small&quot;, &quot;normal&quot;, &quot;large&quot;, &quot;xlarge&quot;
          • orientation: &quot;port&quot;, &quot;land&quot;
          • pixel density: &quot;ldpi&quot;, &quot;mdpi&quot;, &quot;hdpi&quot;, &quot;xhdpi&quot;, &quot;nodpi&quot;, &quot;tvdpi&quot;
          • platform version: &quot;v3&quot;, &quot;v4&quot;, &quot;v7&quot;, ...
        • this is one way to customize UI to different device profiles
          • the above qualifiers MUST be in that order
          • see ${SDK}/docs/guide/topics/resources/providing-resources.html
    • Menus
      • Menus
        • Activities can also have menubar items associated with them
          • best used for actions that aren't common or frequent
        • Menus are often defined in layout (res/menu)
          • menu: define a menu, a container for menu items
          • item: define a menuitem, with id, icon and title (text)
          • group: convenience grouping of item elements (invisible)
    • Menus <menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;> <item android:id=&quot;@+id/new_game&quot; android:icon=&quot;@drawable/ic_new_game&quot; android:title=&quot;@string/new_game&quot; /> <item android:id=&quot;@+id/help&quot; android:icon=&quot;@drawable/ic_help&quot; android:title=&quot;@string/help&quot; /> </menu>
    • Menus
      • ActionBar (3.0+)
        • A set of menus/menuitems appearing at the top
          • generally only useful for tablets
    • Event-handling
      • Most Views/ViewGroups offer events for code to subscribe to
        • These are called &quot;InputEvents&quot;
        • Most of the time, this is the classic &quot;Listener&quot; idiom
          • View.OnClickListeners can be wired up in the XML layout
        • Most of the time, these are wired up in onCreate()
    • Intents
      • Moving from one Activity to another requires an Intent
        • Intent = Action (verb) + Context (target)
        • easiest Intent is the &quot;launch the Activity&quot; Intent
          • Intent next = new Intent(this, NextActivity.class);
          • startActivity(next);
    • Threading
      • Good Thread hygiene is critical here
        • This is a phone--you don't own the machine!
        • Android isn't quite like Java, and has a slightly different &quot;take&quot; on the threads-and-UI position
          • no blocking behaviors (in general)
          • NO UI modifications from non-UI thread
          • If the UI thread is inactive for more than 5 seconds, bye!
        • Android provides Handlers, which can be sent Messages that will then be processed on the Activity's UI thread
        • Java5 provides a few other constructs as well
    • Wrapping up
      • &quot;What do you know?&quot;
    • Summary
      • Android is a Java-based mobile device framework
        • ... but it's not Java
        • ... and it's not a web app technology
        • ... and it's definitely not Swing or SWT
    • Resources
      • Busy Coder’s Guide to Android
        • Mark Murphy, http://www.commonsware.com
      • Android website
        • http://developer.android.com
      • Presentations by this guy
        • Busy Android Dev's Guide to Persistence
        • Busy Android Dev's Guide to Communication
        • ... and more