Your SlideShare is downloading. ×
0
Busy Android Developer's Guide to UI Ted Neward Neward & Associates http://www.tedneward.com | ted@tedneward.com
Credentials <ul><li>Who is this guy? </li></ul><ul><ul><li>Architectural Consultant, Neudesic Software </li></ul></ul><ul>...
Objectives <ul><li>Our goal here today is... </li></ul><ul><ul><li>... to get familiar with the various Android UI element...
Activities and Tasks <ul><li>Activity </li></ul><ul><ul><li>somewhat akin to a web page or screen </li></ul></ul><ul><ul><...
Activities and Tasks <ul><li>Tasks </li></ul><ul><ul><li>Tasks are the logical thread of use through Activities </li></ul>...
Viewables <ul><li>View and ViewGroups </li></ul><ul><ul><li>View is the base class for &quot;widgets&quot; </li></ul></ul>...
Viewables <ul><li>Widgets (android.widget) </li></ul><ul><ul><li>&quot;Push Me&quot;: Button, CompoundButton, CheckBox, Im...
Viewables <ul><li>Layouts (android.widget) </li></ul><ul><ul><li>LinearLayout </li></ul></ul><ul><ul><li>RelativeLayout </...
Viewables <ul><li>Dialogs (android.app) are a special case of Activity </li></ul><ul><ul><li>AlertDialog (OK/Cancel/Help, ...
Creation <ul><li>Two ways of creating UIs in Android </li></ul><ul><ul><li>either create UI &quot;by hand&quot; in Java </...
Layout Resources <ul><li>Layout resources are in res/layout directory </li></ul><ul><ul><li>XML file name corresponds to R...
Layout Resources <LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; android:orientation=&q...
Layout Resources <ul><li>Layout resources can be &quot;tuned&quot; </li></ul><ul><ul><li>like all resources, layouts can b...
Menus <ul><li>Menus </li></ul><ul><ul><li>Activities can also have menubar items associated with them </li></ul></ul><ul><...
Menus <menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;> <item android:id=&quot;@+id/new_game&quo...
Menus <ul><li>ActionBar (3.0+) </li></ul><ul><ul><li>A set of menus/menuitems appearing at the top </li></ul></ul><ul><ul>...
Event-handling <ul><li>Most Views/ViewGroups offer events for code to subscribe to </li></ul><ul><ul><li>These are called ...
Intents <ul><li>Moving from one Activity to another requires an Intent </li></ul><ul><ul><li>Intent = Action (verb) + Cont...
Threading <ul><li>Good Thread hygiene is critical here </li></ul><ul><ul><li>This is a phone--you don't own the machine! <...
Wrapping up <ul><li>&quot;What do you know?&quot; </li></ul>
Summary <ul><li>Android is a Java-based mobile device framework </li></ul><ul><ul><li>... but it's not Java </li></ul></ul...
Resources <ul><li>Busy Coder’s Guide to Android </li></ul><ul><ul><li>Mark Murphy, http://www.commonsware.com </li></ul></...
Upcoming SlideShare
Loading in...5
×

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

3,064

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,064
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
87
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

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

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

    Clipping is a handy way to collect important slides you want to go back to later.

×