best practices for ui

Upload: mohit-jain

Post on 02-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Best Practices for UI

    1/55

  • 8/11/2019 Best Practices for UI

    2/55

    Few of the recommended ways of playing with UI:

    Designing for multiple screens Designing for TV Creating Custom Views Creating Backward-Compatible UIs Implementing Accessibility Managing the System UI

  • 8/11/2019 Best Practices for UI

    3/55

    Designing for multiple screens

    Supporting Different Screen Sizes Supporting Different Screen Densities Implementing Adaptive UI Flows

  • 8/11/2019 Best Practices for UI

    4/55

    RESOLUTION VS PIXEL DENSITY

  • 8/11/2019 Best Practices for UI

    5/55

    Few basic technical terms:Pixel is the smallest element that can be displayed

    on screen.Display size is the diagonal measurement of thescreen in centimeters or inches.Resolution is the number of pixels on the displayPixel Density is calculated based on the resolutioand size of the display.

    Pixel Density= Root((Horizontal Number of Pixel^2) + (Vertical Number ofPixel^2))/Screen Size

  • 8/11/2019 Best Practices for UI

    6/55Display Monitor Size and Resolution

  • 8/11/2019 Best Practices for UI

    7/55Pixel Density Comparison of Displays with Different Resolution

  • 8/11/2019 Best Practices for UI

    8/55

    High Pixel Density Vs Low Pixel Density

  • 8/11/2019 Best Practices for UI

    9/55

    RESOLUTION OR DISPLAY SIZE

    WHICH IS IMPORTANT?

  • 8/11/2019 Best Practices for UI

    10/55

    Pixel Density for Full-HD TVFull-HD TV -> 32 inches -> resolution 1080p (19201080pixels).

    Pixel Density = Root((1920^2)+(1080^2))/32=68.84 ppi

    Pixel Density for Nexus 5(Full HD Display)Nexus 5 -> 4.95 inch.Pixel density = 445 ppi .

    Conclusion: Nexus 5 has better pixel density(more than 6 times of 32 inTV).

  • 8/11/2019 Best Practices for UI

    11/55

    What makes the smartphones to be built with higher pixeldensity than TVs or monitors?

  • 8/11/2019 Best Practices for UI

    12/55

    Designing for multiple screens: Supporting Different Screen Size

    Layout Screen size Layout Screen configuration Correct layout Correct screen Images Scaling

  • 8/11/2019 Best Practices for UI

    13/55

    Designing for multiple screens: Supporting Different Screen Sizes: U wrap_content and match_parent

    A common Newsreader layout in portrait and landscape mode.

  • 8/11/2019 Best Practices for UI

    14/55

    Designing for multiple screens: Supporting Different Screen Sizes: URelativeLayout

    A sample layout appearing on aQVGA screen.(small screen)

    The same sample layout appearing on a Wscreen.(large screen)

  • 8/11/2019 Best Practices for UI

    15/55

    Designing for multiple screens: Supporting Different Screen Sizes: USize Qualifiers

    res/layout/main.xml , single-pane (default) layout:

    This layout (without qualifiers) will be selected for smaller devices.

  • 8/11/2019 Best Practices for UI

    16/55

    Designing for multiple screens: Supporting Different Screen Sizes: USize Qualifiers

    res/layout-large/main.xml , two-pane layout:

    This layout with large qualifier will be selected on devices with screens classified as large (foexample, 7" tablets and above)

  • 8/11/2019 Best Practices for UI

    17/55

  • 8/11/2019 Best Practices for UI

    18/55

    Designing for multiple screens: Supporting Different Screen Sizes: Ulayout aliases

    To avoid the duplication of the same file for tablets and TVs, we can use alias fileFor example, we can define the following layouts: res/layout/main.xml , single-pane layout res/layout/main_twopanes.xml , two-pane layout

    And add these two files: res/values-large/layout.xml :

    @layout/main_twopanes

  • 8/11/2019 Best Practices for UI

    19/55

    Designing for multiple screens: Supporting Different Densities

    Use Density-independent Pixels Provide Alternative Bitmaps

  • 8/11/2019 Best Practices for UI

    20/55

    Designing for multiple screens: Supporting Different Densities: UDensity-independent Pixels

    For example, when we specify spacing between two views, use dp ra

    When specifying text size, always use sp :

  • 8/11/2019 Best Practices for UI

    21/55

    Designing for multiple screens: Supporting Different Densities: ProvAlternative Bitmaps

    Start with the raw resource in vector format and generate the images for each density using the following sscale:

    xhdpi : 2.0 hdpi : 1.5 mdpi : 1.0 (baseline) ldpi : 0.75

    Then, place the generated image files in the appropriate subdirectory under res/ and the syscorrect one automatically based on the screen density of the device our application is running on:MyProject/

    res/drawable-xhdpi/

    awesomeimage.pngdrawable-hdpi/

    awesomeimage.pngdrawable-mdpi/

    awesomeimage.pngdrawable-ldpi/

    awesomeimage.png

  • 8/11/2019 Best Practices for UI

    22/55

    Designing for multiple screens: Implementing Adaptive UI flow

    Determine the current layout React according to current layout Reuse Fragments in other activities Handle Screen Configuration changes

  • 8/11/2019 Best Practices for UI

    23/55

    Designing for multiple screens: Implementing Adaptive UI flowsDetermine the current layout

    public class NewsReaderActivity extends FragmentActivity { boolean mIsDualPane ;

    @Override public void onCreate ( Bundle savedInstanceState ) {

    super . onCreate ( savedInstanceState ); setContentView ( R. layout . main_layout );

    View articleView = findViewById ( R. id . article );

    mIsDualPane = articleView != null && articleView . getVisibility () == View . V

    } }

    Determine what layout the user is currently viewing.

  • 8/11/2019 Best Practices for UI

    24/55

    Designing for multiple screens: Implementing Adaptive UI flowsDetermine the current layout

    Button catButton = ( Button ) findViewById ( R. id . categorybuttonOnClickListener listener = /* create listener here */ ; if ( catButton != null ) {

    catButton . setOnClickListener ( listener );

    }

    Adapting to the existence of different components is to check whether they aravailable before performing an operation on them.

  • 8/11/2019 Best Practices for UI

    25/55

    Designing for multiple screens: Implementing Adaptive UI flows: RAccording to Current Layout

    @Override public void onHeadlineSelected ( int index ) {

    mArtIndex = index ; if ( mIsDualPane ) {

    /* display article on the right pane */ mArticleFragment . displayArticle ( mCurrentCat . getArticle ( ind

    } else { /* start a separate activity */ Intent intent = new Intent ( this , ArticleActivity . class ); intent . putExtra ( "catIndex" , mCatIndex );

    intent . putExtra ( "artIndex" , index ); startActivity ( intent ); }

    }

  • 8/11/2019 Best Practices for UI

    26/55

    Designing for multiple screens: Implementing Adaptive UI flows: RAccording to Current Layout

    final String CATEGORIES [] = { "Top Stories" , "Politics" , "Economy" , "Technology" };

    public void onCreate ( Bundle savedInstanceState ) {

    .... if ( mIsDualPane ) { /* use tabs for navigation */ actionBar . setNavigationMode ( android . app . ActionBar . NAVIGATION_MODE_TABS ); int i ; for ( i = 0 ; i < CATEGORIES . length ; i ++) {

    actionBar . addTab ( actionBar . newTab (). setText ( CATEGORIES [ i ]). setTabListener ( handler ));

    } actionBar . setSelectedNavigationItem ( selTab );

    } else { /* use list navigation (spinner) */ actionBar . setNavigationMode ( android . app . ActionBar . NAVIGATION_MODE_LIST ); SpinnerAdapter adap = new ArrayAdapter ( this ,

    R. layout . headline_item , CATEGORIES ); actionBar . setListNavigationCallbacks ( adap , handler );

    } }

  • 8/11/2019 Best Practices for UI

    27/55

    Designing for multiple screens: Implementing Adaptive UI flowsReuse Fragments in Other Activities

    ArticleFragment used in the dual-pane layout.

  • 8/11/2019 Best Practices for UI

    28/55

    Designing for multiple screens: Implementing Adaptive UI flowsReuse Fragments in Other Activities

    ArticleFragment reused (without a layout) in the activity layout for smaller screens(ArticleActivity)

    ArticleFragment frag = new ArticleFragment (); getSupportFragmentManager (). beginTransaction (). add ( android . R.

    frag ). commit ();

  • 8/11/2019 Best Practices for UI

    29/55

    Designing for multiple screens: Implementing Adaptive UI flowsReuse Fragments in Other Activities

    public class HeadlinesFragment extends ListFragment { ...

    OnHeadlineSelectedListener mHeadlineSelectedListener = null ;

    /* Must be implemented by host activity */ public interface OnHeadlineSelectedListener {

    public void onHeadlineSelected ( int index ); } ...

    public void setOnHeadlineSelectedListener ( OnHeadlineSelectedListener liste

    mHeadlineSelectedListener = listener ; }

    }

    Define an interface that abstracts all the ways in which the fragment needs to interwith its host activity, and then the host activity implements that interface.

  • 8/11/2019 Best Practices for UI

    30/55

    Designing for multiple screens: Implementing Adaptive UI flowsReuse Fragments in Other Activities

    public class HeadlinesFragment extends ListFragment { ...

    @Override public void onItemClick ( AdapterView parent , View view , int position , long id )

    if ( null != mHeadlineSelectedListener ) { mHeadlineSelectedListener . onHeadlineSelected ( position

    } }

    ... }

    When the user selects a headline, the fragment notifies the listener specified by the activity (as opposed to notifying a specific hard-coded activity)

  • 8/11/2019 Best Practices for UI

    31/55

    Designing for multiple screens: Implementing Adaptive UI flowsHandle Screen Configuration Changes

    public class ArticleActivity extends FragmentActivity { int mCatIndex , mArtIndex ;

    @Override protected void onCreate ( Bundle savedInstanceState ) {

    super . onCreate ( savedInstanceState ); mCatIndex = getIntent (). getExtras (). getInt ( "catIndex" , 0 ); mArtIndex = getIntent (). getExtras (). getInt ( "artIndex" , 0 );

    // If should be in two-pane mode, finish to return to main activity if ( getResources (). getBoolean ( R. bool . has_two_panes )) {

    finish (); return ;

    } ...

    }

    When the user is in portrait mode and the activity for viewing an article is onscreen, we need to detethe orientation changed to landscape and react appropriately by ending the activity and return to the

    activity so the content can display in the two-pane layout.

  • 8/11/2019 Best Practices for UI

    32/55

    Designing for TV

    Optimizing Layouts for TV permanent "landscape" mode, high-resolution displays, "10 foot UI" environment Optimizing Navigation for TVhandling D-pad navigation, providing navigational feedback, providing easily-accessible controls on the scre

    Handling features not supported on TV

  • 8/11/2019 Best Practices for UI

    33/55

    Designing for TV: Optimizing Layouts for TV

    Layout resources Landscape mode Texts & controls Visible from distance High Resolution bitmaps & icons HD TV

    screens

  • 8/11/2019 Best Practices for UI

    34/55

    Designing for TVs: Optimizing Layouts for TV: Design LandscaLayouts

    TV screens are always in landscape orientation .Follow these tips to build landscape layouts optimized for TV screens:

    Put on-screen navigational controls on the left or right side of the screenthe vertical space for content.

    Create UIs that are divided into sections , by using Fragments and uselike GridView instead of ListView to make better use of the horizonta

    space . Use view groups such as RelativeLayout or LinearLayout to arrange view

    allows the Android system to adjust the position of the views to the size,alignment, aspect ratio, and pixel density of the TV screen.

    Add sufficient margins between layout controls to avoid a cluttered UI.

  • 8/11/2019 Best Practices for UI

    35/55

  • 8/11/2019 Best Practices for UI

    36/55

    Designing for TVs: Optimizing Layouts for TV: Design LandscaLayouts

    res/layout-land-large/photogrid_tv.xml

  • 8/11/2019 Best Practices for UI

    37/55

    Designing for TVs: Optimizing Layouts for TV: Design LandscaLayouts

    LeftNavBar bar = ( LeftNavBarService . instance ()). getLeftNavBar

    Include the Left Navigation Bar Library in our application to set up action bar items on the lefside of the screen, instead of creating a custom Fragment to add controls.

  • 8/11/2019 Best Practices for UI

    38/55

    Designing for TVs: Optimizing Layouts for TV: Make Text and ConEasy to See

    The text and controls in a TV application's UI should be easily visible and navigable frFollow these tips to make them easier to see from a distance : Break text into small chunks that users can quickly scan . Use light text on a dark background . This style is easier to read on a TV. Avoid lightweight fonts or fonts that have both very narrow and very broad stroke

    sans-serif fonts and use anti-aliasing to increase readability. Use Android's standard font sizes : Ensure that all our view widgets are large enough to be clearly visible to someone

    away from the screen (this distance is greater for very large screens). The best way to douse layout-relative sizing rather than absolute sizing, and density-independentof absolute pixel units. For example, to set the width of a widget, use wrap_content instepixel measurement, and to set the margin for a widget, use dip instead of px values.

    android:textAppearance ="?android:attr/textAppearanc

    f f f h

  • 8/11/2019 Best Practices for UI

    39/55

    Designing for TVs: Optimizing Layouts for TV: Design for High-DLarge Screens

    The common HDTV display resolutions are 720p, 1080i, and 1080p.

    A small tip is to design our UI for 1080p, and then allow the Androidsystem to downscale our UI to 720p if necessary.

    D i i f TV O i i i L f TV D i H dl L

  • 8/11/2019 Best Practices for UI

    40/55

    Designing for TVs: Optimizing Layouts for TV: Design to Handle LBitmaps

    The Android system has a limited amount of memory, so downloading and storing highresolution images can often cause out-of-memory errors in our app.To avoid this, follow these tips: Load images only when they're displayed on the screen. For example, when di

    multiple images in a GridView or Gallery, only load an image when getView() is cathe View's Adapter.

    Call recycle() on Bitmap views that are no longer needed. Use WeakReference for storing references to Bitmap objects in an in-memory If we fetch images from the network , use AsyncTask to fetch them and store th

    SD card for faster access. Never do network transactions on the application's UI thre Scale down really large images to a more appropriate size as we download

    otherwise, downloading the image itself may cause an "Out of Memory" exception.

    D i i f TV O i i i N i i f TV

  • 8/11/2019 Best Practices for UI

    41/55

    Designing for TV: Optimizing Navigation for TV

    Ensuring all layout controls are D-pad navigab Providing highly obvious feedback for UI

    navigation. Placing layout controls for easy access.

  • 8/11/2019 Best Practices for UI

    42/55

    TV remote D pad

    D ig i g f TV O ti i i g N ig ti f TV H dl D

  • 8/11/2019 Best Practices for UI

    43/55

    Designing for TVs: Optimizing Navigation for TV: Handle D-paNavigation

    Follow these tips to design for D-pad: Ensure that the D-pad can navigate to all the visible controls on the scree For scrolling lists with focus , D-pad up/down keys scroll the list and Enter key

    item in the list. Ensure that users can select an element in the list and that the list stiscrolls when an element is selected.

    Ensure that movement between controls is straightforward and predicta

    Android usually handles navigation order between layout elements automatically, so we

    don't need to do anything extra. If the screen layout makes navigation difficult, or if wewant users to move through the layout in a specific way, we can set up explicit navigationfor our controls.For example,

  • 8/11/2019 Best Practices for UI

    44/55

    Designing for TVs: Optimizing Navigation for TV: Provide Clear VIndication for Focus and Selection

    1. Use appropriate color highlights for all navigable and selectable elethe UI. This makes it easy for users to know whether the control isfocused or selected when they navigate with a D-pad.

    2. Use uniform highlight scheme across our application.

    3. Android provides Drawable State List Resources to implement hselected and focused controls.

    Designing for TVs: Optimizing Navigation for TV: Provide Clear V

  • 8/11/2019 Best Practices for UI

    45/55

    Designing for TVs: Optimizing Navigation for TV: Provide Clear VIndication for Focus and Selection

    For example:

    res/drawable/button.xml:

    This layout XML applies the above state list drawable to a Button :

    Designing for TVs: Optimizing Navigation for TV: Design for E

  • 8/11/2019 Best Practices for UI

    46/55

    Designing for TVs: Optimizing Navigation for TV: Design for ENavigation

    1. Users should be able to navigate to any UI control with a coupl

    clicks.

    2. Navigation should be easy and intuitive to understand.

    3. For any non-intuitive actions, provide users with written help

    triggered by a help button or action bar icon.

  • 8/11/2019 Best Practices for UI

    47/55

    Designing for TVs: Optimizing Navigation for TV: Design for E

  • 8/11/2019 Best Practices for UI

    48/55

    Designing for TVs: Optimizing Navigation for TV: Design for ENavigation

    Such multi-pane UIs make D-pad navigation easier and make good use of thehorizontal screen space for TVs.

    res/layout/cool_places.xml

  • 8/11/2019 Best Practices for UI

    49/55

    Designing for TV: Handling Features Not Supported on TV

    Providing workarounds for some non-supportedfeatures.

    Checking for available features at runtime andconditionally activating/deactivating certain codepaths based on availability of those features.

    Designing for TV: Handling Features Not Supported on TV

  • 8/11/2019 Best Practices for UI

    50/55

    Designing for TV: Handling Features Not Supported on TV

    The Android system does not support the following features for a TVdevice:

    Hardware Android feature descriptor

    Camera android.hardware.camera

    GPS android.hardware.location.gps

    Microphone android.hardware.microphone

    Near Field Communications (NFC) android.hardware.nfc

    Telephony android.hardware.telephony

    Touchscreen android.hardware.touchscreen

    Designing for TVs: Handling Features Not Supported on TV: Wo

  • 8/11/2019 Best Practices for UI

    51/55

    Designing for TVs: Handling Features Not Supported on TV: WoAround Features Not Supported on TV

    1. Ensure that every control in our app can be accessed with the D-pad.

    Explicitly disable the touchscreen requirement in our manifest file

    2. Disable apps picture -taking functionality for TVs and allow usersand edit photos.

    3. Mobile app for voice control that takes voice input can be used as control for a TV.

  • 8/11/2019 Best Practices for UI

    52/55

    es g g o Vs: a d g eatu es ot Suppo ted o V: C ecAvailable Features at Runtime

    // Check if android.hardware.telephony feature is available. if ( getPackageManager (). hasSystemFeature ( "android.hardware.telephony"

    Log . d ( "Mobile Test" , "Running on phone" ); // Check if android.hardware.touchscreen feature is available. } else if ( getPackageManager (). hasSystemFeature ( "android.hardware.touchscree{

    Log . d ( "Tablet Test" , "Running on devices that don't support telphony but havea touchscreen." ); } else {

    Log . d ( "TV Test" , "Running on a TV!" );

    }

    Detect device type at runtime based on supported features.

  • 8/11/2019 Best Practices for UI

    53/55

    References

    http://developer.android.com/training/best-ui.html http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-

    know/ http://www.youtube.com/watch?v=zsRnRLh-O34

    http://developer.android.com/training/best-ui.htmlhttp://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://www.youtube.com/watch?v=zsRnRLh-O34http://www.youtube.com/watch?v=zsRnRLh-O34http://www.youtube.com/watch?v=zsRnRLh-O34http://www.youtube.com/watch?v=zsRnRLh-O34http://www.youtube.com/watch?v=zsRnRLh-O34http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://teknosrc.com/resolution-vs-pixel-density-in-displays-all-you-need-to-know/http://developer.android.com/training/best-ui.htmlhttp://developer.android.com/training/best-ui.htmlhttp://developer.android.com/training/best-ui.htmlhttp://developer.android.com/training/best-ui.htmlhttp://developer.android.com/training/best-ui.html
  • 8/11/2019 Best Practices for UI

    54/55

    Questions???

  • 8/11/2019 Best Practices for UI

    55/55