Android design patterns
Upcoming SlideShare
Loading in...5

Android design patterns



Slides from the guru session about Android Design Patterns and tools held at Appsterdam / Bouncespace at 20/10/2012

Slides from the guru session about Android Design Patterns and tools held at Appsterdam / Bouncespace at 20/10/2012



Total Views
Views on SlideShare
Embed Views



8 Embeds 1,181 607 536 13
http://localhost 11 8 2 2 2



Upload Details

Uploaded via as Adobe PDF

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
  • Very good presentation. I will recommend it to my students. Thank you, Raul!
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Android design patterns Android design patterns Presentation Transcript

  • Android Design Patterns Raul Portales @sla_shalafi Platty Soft @plattysoft
  • Why?Good Design = Happy Users
  • Device Independent DesignSave yourself time and headaches
  • Device Independent Design● Use dips● Prefer Relative Layouts● Qualify dimensions as resources – Best way to move to tablets
  • Fragments Design for phones and tabletsReuse as much code as you can
  • Fragments● A Fragment represents a behavior or a portion of user interface in an Activity.● You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities).
  • Using Fragments● Fragments are only available 3.0+● Gingerbread is still on 50%+ of devices
  • Compat LibraryBrings Fragments back to 1.6
  • Fragments: Detail View
  • Fragments: Detail View
  • The tech side● MasterFragment● DetailFragment● Qualify layouts – xlarge-land → 2 fragments – normal → 1 fragment● MainActivity – If has a detail fragment, use it – Or write 2 different activities
  • Fragments● onCreateView● onViewCreated● getActivity● getArguments
  • Common Pitfalls● Be aware of the Constructor!!● The Activity may not be always there – It may have been destroyed – Or the fragment detached● There is no communication among fragments – Do it through the Activity – Better: Use an interface
  • FragmentManager● findFragmentById● findFragmentByTag● FragmentTransactionFragmentManager fm = getSupportFragmentManager();FragmentTransaction ft = fm.beginTransaction();ft.replace(, MyFragment.newInstance());ft.commitAllowingStateLoss();
  • Fragments: View PagerThe most useful utility of Fragments
  • Fragments: View Pager
  • The tech side● MainActivity● FragmentPagerAdapter – Fragments
  • Show me the Code < android:id="@+id/pager" android:layout_width="fill_parent" android:layout_height="0px" android:layout_weight="1"/> </LinearLayout>ViewPager pager = (ViewPager) findViewById(;pager.setAdapter(adapter);
  • Action BarMain improvement in 3.0 and 4.0 Has been around since 2009
  • Action Bar● Provide a dedicated space for identifying the application brand and user location.● Provide consistent navigation and view refinement across different applications.● Make key actions for the activity (such as "search", "create", "share", etc.) prominent and accessible to the user in a predictable way.
  • Action Bar1.App icon2.View control3.Action buttons4.Action overflow
  • Action Buttons● Frequent● Important● Typical
  • Show me the Codepublic boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(, menu); return true;}<menu xmlns:android="...”> <item android:id="@+id/menu_save" android:icon="@drawable/ic_menu_save" android:title="@string/menu_save" android:showAsAction="ifRoom|withText" /></menu>
  • The Action Bar is NOT part of the Compat Library
  • ActionBarSherlock● Deprecated from Inception – Same class names, different packages● Based on the Compat library● From Android 2.x up
  • Using ABS● Add ABS as library● Use the theme for your App● getActionBar → getSupportActionBar● Activity → SherlockActivity● FragmentActivity → SherlockFragmentActivity● Fragment → SherlockFragment● And so on...
  • ViewPageIndicatorYou have seen it in the screenshots Combined with a ViewPager
  • ViewPageIndicator
  • Show me the Code<com.viewpagerindicator.TitlePageIndicator android:id="@+id/indicator" android:padding="10dip" android:layout_height="wrap_content" android:layout_width="fill_parent" />mIndicator = (TitlePageIndicator)findViewById(;mIndicator.setViewPager(pager);
  • Navigation Styles● Top navigation tabs – For a clear landing page● Dashboard – For a set of important options● Drawer – Combined with a landing page
  • Navigation Styles Vs.
  • Testing on devices
  • Testing on devices
  • Testing on devices
  • Testing on devices
  • Doing more with less● Gingerbread, hdpi, normal → Nexus One● Jelly Bean, xhdpi → Galaxy Nexus● Froyo, mdpi → HTC Magic● ICS, xlarge → Asus Transformer● large → Nexus 7 / Galaxy Tab 7● Honeycomb → Galaxy Tab
  • To know more...● Android Design Site:● Google I/O videos, specially day 3● ActionBarSherlock● ViewPageIndicator
  • Android Design Patterns Raul Portales @sla_shalafi Platty Soft @plattysoft