SlideShare a Scribd company logo
1 of 37
Android Effective UI
Tips, Tricks and Patterns
Adham Enaya
adhamenaya.com 1
Topics
• Introduction
• Resources and qualifiers
• Using ButterKnife Library
• Model View Presenter (MVP)
• Some advices
adhamenaya.com 2
Motivation
• Provide and enjoyable user experience.
• Change the UI depending on the device.
• Improve layout performance.
• Create Customized widgets.
• Make the UI code maintainable and testable.
adhamenaya.com 3
Android Devices
• Almost 19,000 devices(60% growth yearly)
adhamenaya.com 4
Motivation (2)
How can we change the UI
depending on the device ?
By using Android Resources
adhamenaya.com 5
Android Recourses
• Color: declares the app
color pallet
• Drawable: images
assets
• Layout: xml file declares
the app layout.
• Menu: xml file declares
the UI menu
• Integer: integer values
in xml and java codes.
adhamenaya.com 6
Resources & Qualifiers
• Screen Density: hdpi, mdpi … etc
• Screen Size: large, small .. etc
• Language: ar, en, ar-JO
• Min Width: sw600dp, sw720dp
• Screen Orientation: port and land
• Android API level: v7, v8, v9 …etc
adhamenaya.com 7
Resources & Qualifiers/Screen Destiny
• Screen Destiny: quantity pixels(dots) per inch
– ldpi: ~120dpi
– mdpi: ~160dpi
– hdpi: ~240dpi
– xhdpi: ~360dpi
– xxhdpi:480dpi
– xxxhdpi: ~640dpi
adhamenaya.com 8
Resources & Qualifiers/Screen Density
adhamenaya.com 9
Resources & Qualifiers/Screen Destiny
adhamenaya.com 10
Resources & Qualifiers/Screen Size
• xlarge screens are at least 960dp x 720dp > 7 inch
• large screens are at least 640dp x 480dp 5-7 inch
• normal screens are at least 470dp x 320dp 3.0-4.7 inch
• small screens are at least 426dp x 320dp 2.2-2.7 inch
adhamenaya.com 11
Resources & Qualifiers/Screen Size
• Android screen resolution distribution in China. (Umeng data)
adhamenaya.com 12
How to use Qualifiers?
• Create new directory in res/ folder
• The name of the folder in this format:
– <resources_name>-<qualifier>
– Resource name: such drawable, layout …
– Qualifier: such as hdpi, mdpi, land, port…
adhamenaya.com 13
Android resources example
• drawable/: for every thing
• drawable-en/ : for English locale
• drawable-en-port/ : for English and in portrait
orientation
• drawable-en-notouch-12key/ : For English
and in notouch devices and 12key as primary
input
• drawable-port-ldpi/ : for low density screen
and in portrait orientation
adhamenaya.com 14
Android resources example(2)
• layout-v4: API level (android 1.6)
• layout- h720dp: Available height 720
• Layout-sw600dp: Smallest width 600
Same application with different layouts for each device.
adhamenaya.com 15
Using Butter Knife Library (1)
• Inject Views and view events in activities and
fragments.
• Notation –based. By : Jake Wharton (Square).
adhamenaya.com 16
Using Butter Knife Library (2)
• Using findViewById
adhamenaya.com 17
Using the Butter Knife Library (3)
• Add dependency to build.gradle:
– compile 'com.jakewharton:butterknife:6.1.0‘
• In the onCreate() method of the
activity, before using any the views,
call inject on the Butterknife object:
– ButterKnife.inject(this);
adhamenaya.com 18
ButterKnife / Insatiate the view (4)
• Use:
– @InjectView(R.id.sample_textview);
– TextView textview;
• Rather than:
– TextView textview;
– textview =
(TextView)findViewById(R.id.sample_textview);
adhamenaya.com 19
Butter Knife / View Events(5)
• Use:
@OnClick(R.id.sample_textview)
public void showToastMessage(){
// DO SOTHING ….
}
adhamenaya.com 20
Android Design Pattern
Model-View-Presenter (MVP)
adhamenaya.com 21
What is MVP?
• The MVP pattern allows separate the
presentation layer(UI) from the business logic
adhamenaya.com 22
Why use MVP?
• Android activities are closely coupled to both
interface and data.
– Such as: CursorAdapter (View)+Cursor(data)
• Application to be easily extensible and
maintainable.
– Such as: changing the data access (from local
database to web service).
• Easier to test each interface alone.
adhamenaya.com 23
How to implement MVP ?
• MVP architecture consists of 3 layers:
– View
– Presenter
– Model
View Presenter Model
User Event Update Model
Update view State Changed
event
adhamenaya.com 24
MVP: VIEW
• Activity, Fragment, View …
• Has a reference to the Presenter
• Propagates evens from UI to the Presenter.
(such as onClick)
• Exposes methods that controls the
presentation objects. (Such as Show/Hide
progress bar)
adhamenaya.com 25
MVP: PRESENTER
• Middle-man Between the View and Presenter
• Has reference to View and Model.
• Introduce a level of abstraction to the data
coming from the model, and formats it before
sending it to the view (this makes the View
and Model independent).
• Updates the UI, the difference to the MVC.
adhamenaya.com 26
MVP: Model (Interactor)
• Gateway towards the business logic.
• Contains methods to for data retrival.
adhamenaya.com 27
MVP Conventions
• MVP
– Views: ExampleView
– Listeners: ExampleListener
– Presenters: ExamplePresenter
• > impl: ExamplePresenterImpl
– Interactors: ExampleInteractor
• > impl: ExmpleInteractorImpl
adhamenaya.com 28
MVP Example
Activity Presenter
Network
Interactor
Press Login Button valiadteAccount()
loginSuccess() networkSuccess()
loginFailue() networkFailure()
adhamenaya.com 29
MVP Example: Login
adhamenaya.com 30
Login Sequence
LoginActivity PresenterImpl
(onLoginFinsishedListener)
InteractorImpl
attempLogin(..)
validateCredentials(..)
onSuccess()
navigateToMainActivity()
onError()
loginFaild()
loginTapped()
Web
Service
adhamenaya.com 31
MVP vs. MVC
• MVP Pattern
– View is more loosely coupled to the model. The
presenter is responsible for binding the model to
the view.
– Easier to unit test because interaction with the
view is through an interface
– Usually view to presenter map one to one.
Complex views may have multi presenters.
adhamenaya.com 32
MVP architecture
adhamenaya.com 33
MVP vs. MVC
• MVC Pattern
– Controller are based on behaviors and can be
shared across views
– Can be responsible for determining which view to
display
34adhamenaya.com
MVC architecture
adhamenaya.com 35
Some Advices
• Avoid expensive tasks on the UI thread.
• Avoid code duplicity
• Use themes, styles and colors properly.
• Think in UI layer as isolated domain.
• Write testable code and test it.
• Measure the UI performance using the
performance measure tools.
adhamenaya.com 36
Any Questions?
Contact me: a.it@hotmail.com
adhamenaya.com 37

More Related Content

What's hot

Building Scalable JavaScript Apps
Building Scalable JavaScript AppsBuilding Scalable JavaScript Apps
Building Scalable JavaScript AppsGil Fink
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_contentNAVEENSAGGAM1
 
Android Lollipop and Material Design
Android Lollipop and Material DesignAndroid Lollipop and Material Design
Android Lollipop and Material DesignJames Montemagno
 
angular-formly presentation
angular-formly presentationangular-formly presentation
angular-formly presentationAnnia Martinez
 
Modules in AngularJs
Modules in AngularJsModules in AngularJs
Modules in AngularJsK Arunkumar
 
Beyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreBeyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreAri Lerner
 
Model View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In AspnetModel View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In Aspnetrainynovember12
 
Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Max Klymyshyn
 
Angular EE - Special Workshop by Nir Kaufman
Angular EE - Special Workshop by Nir KaufmanAngular EE - Special Workshop by Nir Kaufman
Angular EE - Special Workshop by Nir KaufmanNir Kaufman
 
Tdd in android (mvp)
Tdd in android (mvp)Tdd in android (mvp)
Tdd in android (mvp)Prateek Jain
 
Angular 6 - The Complete Guide
Angular 6 - The Complete GuideAngular 6 - The Complete Guide
Angular 6 - The Complete GuideSam Dias
 
Introduction To Model View Presenter
Introduction To Model View PresenterIntroduction To Model View Presenter
Introduction To Model View Presentersaeed shargi ghazani
 

What's hot (20)

Building Scalable JavaScript Apps
Building Scalable JavaScript AppsBuilding Scalable JavaScript Apps
Building Scalable JavaScript Apps
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_content
 
Android Lollipop and Material Design
Android Lollipop and Material DesignAndroid Lollipop and Material Design
Android Lollipop and Material Design
 
Material Design Android
Material Design AndroidMaterial Design Android
Material Design Android
 
Angular Js
Angular JsAngular Js
Angular Js
 
Angular material
Angular materialAngular material
Angular material
 
JAX 08 - Agile RCP
JAX 08 - Agile RCPJAX 08 - Agile RCP
JAX 08 - Agile RCP
 
angular-formly presentation
angular-formly presentationangular-formly presentation
angular-formly presentation
 
Modules in AngularJs
Modules in AngularJsModules in AngularJs
Modules in AngularJs
 
Beyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreBeyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and more
 
Drawing Tool
Drawing ToolDrawing Tool
Drawing Tool
 
Model View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In AspnetModel View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In Aspnet
 
iOS UI best practices
iOS UI best practicesiOS UI best practices
iOS UI best practices
 
Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013Angular.js - JS Camp UKraine 2013
Angular.js - JS Camp UKraine 2013
 
Angular EE - Special Workshop by Nir Kaufman
Angular EE - Special Workshop by Nir KaufmanAngular EE - Special Workshop by Nir Kaufman
Angular EE - Special Workshop by Nir Kaufman
 
Angular 9
Angular 9 Angular 9
Angular 9
 
Tdd in android (mvp)
Tdd in android (mvp)Tdd in android (mvp)
Tdd in android (mvp)
 
Type of angular 2
Type of angular 2Type of angular 2
Type of angular 2
 
Angular 6 - The Complete Guide
Angular 6 - The Complete GuideAngular 6 - The Complete Guide
Angular 6 - The Complete Guide
 
Introduction To Model View Presenter
Introduction To Model View PresenterIntroduction To Model View Presenter
Introduction To Model View Presenter
 

Viewers also liked

Android Architecture MVP Pattern
Android Architecture MVP Pattern Android Architecture MVP Pattern
Android Architecture MVP Pattern Jeff Potter
 
Clean architecture
Clean architectureClean architecture
Clean architectureandbed
 
Mvp in practice
Mvp in practiceMvp in practice
Mvp in practice彥彬 洪
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsAleksandar Ilić
 
Skroutz Android MVP and Adapter Delegates presentation
Skroutz Android MVP and Adapter Delegates  presentationSkroutz Android MVP and Adapter Delegates  presentation
Skroutz Android MVP and Adapter Delegates presentationgmetal
 
Infinum Android Talks #12 - MVP design pattern for Android Apps
Infinum Android Talks #12 - MVP design pattern for Android AppsInfinum Android Talks #12 - MVP design pattern for Android Apps
Infinum Android Talks #12 - MVP design pattern for Android AppsInfinum
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean ArchitectureBadoo
 
Rendra Toro - Model View Presenter
Rendra Toro - Model View PresenterRendra Toro - Model View Presenter
Rendra Toro - Model View PresenterDicoding
 
Yoza Aprilio - We must design
Yoza Aprilio - We must designYoza Aprilio - We must design
Yoza Aprilio - We must designDicoding
 
Mobility Beyond Imagination (MBI)
Mobility Beyond Imagination (MBI)Mobility Beyond Imagination (MBI)
Mobility Beyond Imagination (MBI)Alex Ureta Jr.
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMMudasir Qazi
 
The Future Of Work & The Work Of The Future
The Future Of Work & The Work Of The FutureThe Future Of Work & The Work Of The Future
The Future Of Work & The Work Of The FutureArturo Pelayo
 

Viewers also liked (18)

Android Architecture MVP Pattern
Android Architecture MVP Pattern Android Architecture MVP Pattern
Android Architecture MVP Pattern
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Mvp in practice
Mvp in practiceMvp in practice
Mvp in practice
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App Components
 
Skroutz Android MVP and Adapter Delegates presentation
Skroutz Android MVP and Adapter Delegates  presentationSkroutz Android MVP and Adapter Delegates  presentation
Skroutz Android MVP and Adapter Delegates presentation
 
Core Android
Core AndroidCore Android
Core Android
 
Karumi Dojo: Kata Maxibon
Karumi Dojo: Kata MaxibonKarumi Dojo: Kata Maxibon
Karumi Dojo: Kata Maxibon
 
Infinum Android Talks #12 - MVP design pattern for Android Apps
Infinum Android Talks #12 - MVP design pattern for Android AppsInfinum Android Talks #12 - MVP design pattern for Android Apps
Infinum Android Talks #12 - MVP design pattern for Android Apps
 
Mvc, mvp, mvvm...
Mvc, mvp, mvvm...Mvc, mvp, mvvm...
Mvc, mvp, mvvm...
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Rendra Toro - Model View Presenter
Rendra Toro - Model View PresenterRendra Toro - Model View Presenter
Rendra Toro - Model View Presenter
 
Yoza Aprilio - We must design
Yoza Aprilio - We must designYoza Aprilio - We must design
Yoza Aprilio - We must design
 
MVP Clean Architecture
MVP Clean  Architecture MVP Clean  Architecture
MVP Clean Architecture
 
Mobility Beyond Imagination (MBI)
Mobility Beyond Imagination (MBI)Mobility Beyond Imagination (MBI)
Mobility Beyond Imagination (MBI)
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVM
 
Effective Android UI - English
Effective Android UI - EnglishEffective Android UI - English
Effective Android UI - English
 
Building maintainable app
Building maintainable appBuilding maintainable app
Building maintainable app
 
The Future Of Work & The Work Of The Future
The Future Of Work & The Work Of The FutureThe Future Of Work & The Work Of The Future
The Future Of Work & The Work Of The Future
 

Similar to Android Effective UI: Tips, Tricks and Patterns

Evolution of the SAP User Experience and Technology Stack
Evolution of the SAP User Experience and Technology StackEvolution of the SAP User Experience and Technology Stack
Evolution of the SAP User Experience and Technology StackVictor Ionescu
 
Device Independent API design
Device Independent API designDevice Independent API design
Device Independent API designAmrita jain
 
Droidcon 2013 automotive quality dunca_czol_garmin
Droidcon 2013 automotive quality dunca_czol_garminDroidcon 2013 automotive quality dunca_czol_garmin
Droidcon 2013 automotive quality dunca_czol_garminDroidcon Berlin
 
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speechVue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speechDivante
 
Good bye Massive View Controller!
Good bye Massive View Controller!Good bye Massive View Controller!
Good bye Massive View Controller!Supercharge
 
Forge - DevCon 2016: Implementing Rich Applications in the Browser
Forge - DevCon 2016: Implementing Rich Applications in the BrowserForge - DevCon 2016: Implementing Rich Applications in the Browser
Forge - DevCon 2016: Implementing Rich Applications in the BrowserAutodesk
 
Win j svsphonegap-damyan-petev-mihail-mateev
Win j svsphonegap-damyan-petev-mihail-mateevWin j svsphonegap-damyan-petev-mihail-mateev
Win j svsphonegap-damyan-petev-mihail-mateevMihail Mateev
 
How to become a Rational Developer for IBM i Power User
How to become a Rational Developer for IBM i Power UserHow to become a Rational Developer for IBM i Power User
How to become a Rational Developer for IBM i Power UserStrongback Consulting
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Ganesh Kondal
 
Android Training in Chandigarh
Android Training in ChandigarhAndroid Training in Chandigarh
Android Training in ChandigarhArcadian Learning
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...Mark Leusink
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...Mark Roden
 
Introduction to interactive data visualisation using R Shiny
Introduction to interactive data visualisation using R ShinyIntroduction to interactive data visualisation using R Shiny
Introduction to interactive data visualisation using R Shinyanamarisaguedes
 
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentationvue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentationDivante
 
Mobile Vue.js – From PWA to Native
Mobile Vue.js – From PWA to NativeMobile Vue.js – From PWA to Native
Mobile Vue.js – From PWA to NativeMartinSotirov
 
PLAT-20 Building Alfresco Prototypes in a Few Hours
PLAT-20 Building Alfresco Prototypes in a Few HoursPLAT-20 Building Alfresco Prototypes in a Few Hours
PLAT-20 Building Alfresco Prototypes in a Few HoursAlfresco Software
 

Similar to Android Effective UI: Tips, Tricks and Patterns (20)

Evolution of the SAP User Experience and Technology Stack
Evolution of the SAP User Experience and Technology StackEvolution of the SAP User Experience and Technology Stack
Evolution of the SAP User Experience and Technology Stack
 
Android development first steps
Android development   first stepsAndroid development   first steps
Android development first steps
 
Device Independent API design
Device Independent API designDevice Independent API design
Device Independent API design
 
Droidcon 2013 automotive quality dunca_czol_garmin
Droidcon 2013 automotive quality dunca_czol_garminDroidcon 2013 automotive quality dunca_czol_garmin
Droidcon 2013 automotive quality dunca_czol_garmin
 
Mini training- Scenario Driven Design
Mini training- Scenario Driven DesignMini training- Scenario Driven Design
Mini training- Scenario Driven Design
 
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speechVue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
 
Good bye Massive View Controller!
Good bye Massive View Controller!Good bye Massive View Controller!
Good bye Massive View Controller!
 
Forge - DevCon 2016: Implementing Rich Applications in the Browser
Forge - DevCon 2016: Implementing Rich Applications in the BrowserForge - DevCon 2016: Implementing Rich Applications in the Browser
Forge - DevCon 2016: Implementing Rich Applications in the Browser
 
Win j svsphonegap-damyan-petev-mihail-mateev
Win j svsphonegap-damyan-petev-mihail-mateevWin j svsphonegap-damyan-petev-mihail-mateev
Win j svsphonegap-damyan-petev-mihail-mateev
 
How to become a Rational Developer for IBM i Power User
How to become a Rational Developer for IBM i Power UserHow to become a Rational Developer for IBM i Power User
How to become a Rational Developer for IBM i Power User
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
 
Android Training in Chandigarh
Android Training in ChandigarhAndroid Training in Chandigarh
Android Training in Chandigarh
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...
 
Introduction to interactive data visualisation using R Shiny
Introduction to interactive data visualisation using R ShinyIntroduction to interactive data visualisation using R Shiny
Introduction to interactive data visualisation using R Shiny
 
Project
ProjectProject
Project
 
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentationvue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
 
The Decoupled CMS in Financial Services
The Decoupled CMS in Financial ServicesThe Decoupled CMS in Financial Services
The Decoupled CMS in Financial Services
 
Mobile Vue.js – From PWA to Native
Mobile Vue.js – From PWA to NativeMobile Vue.js – From PWA to Native
Mobile Vue.js – From PWA to Native
 
PLAT-20 Building Alfresco Prototypes in a Few Hours
PLAT-20 Building Alfresco Prototypes in a Few HoursPLAT-20 Building Alfresco Prototypes in a Few Hours
PLAT-20 Building Alfresco Prototypes in a Few Hours
 

Android Effective UI: Tips, Tricks and Patterns

  • 1. Android Effective UI Tips, Tricks and Patterns Adham Enaya adhamenaya.com 1
  • 2. Topics • Introduction • Resources and qualifiers • Using ButterKnife Library • Model View Presenter (MVP) • Some advices adhamenaya.com 2
  • 3. Motivation • Provide and enjoyable user experience. • Change the UI depending on the device. • Improve layout performance. • Create Customized widgets. • Make the UI code maintainable and testable. adhamenaya.com 3
  • 4. Android Devices • Almost 19,000 devices(60% growth yearly) adhamenaya.com 4
  • 5. Motivation (2) How can we change the UI depending on the device ? By using Android Resources adhamenaya.com 5
  • 6. Android Recourses • Color: declares the app color pallet • Drawable: images assets • Layout: xml file declares the app layout. • Menu: xml file declares the UI menu • Integer: integer values in xml and java codes. adhamenaya.com 6
  • 7. Resources & Qualifiers • Screen Density: hdpi, mdpi … etc • Screen Size: large, small .. etc • Language: ar, en, ar-JO • Min Width: sw600dp, sw720dp • Screen Orientation: port and land • Android API level: v7, v8, v9 …etc adhamenaya.com 7
  • 8. Resources & Qualifiers/Screen Destiny • Screen Destiny: quantity pixels(dots) per inch – ldpi: ~120dpi – mdpi: ~160dpi – hdpi: ~240dpi – xhdpi: ~360dpi – xxhdpi:480dpi – xxxhdpi: ~640dpi adhamenaya.com 8
  • 9. Resources & Qualifiers/Screen Density adhamenaya.com 9
  • 10. Resources & Qualifiers/Screen Destiny adhamenaya.com 10
  • 11. Resources & Qualifiers/Screen Size • xlarge screens are at least 960dp x 720dp > 7 inch • large screens are at least 640dp x 480dp 5-7 inch • normal screens are at least 470dp x 320dp 3.0-4.7 inch • small screens are at least 426dp x 320dp 2.2-2.7 inch adhamenaya.com 11
  • 12. Resources & Qualifiers/Screen Size • Android screen resolution distribution in China. (Umeng data) adhamenaya.com 12
  • 13. How to use Qualifiers? • Create new directory in res/ folder • The name of the folder in this format: – <resources_name>-<qualifier> – Resource name: such drawable, layout … – Qualifier: such as hdpi, mdpi, land, port… adhamenaya.com 13
  • 14. Android resources example • drawable/: for every thing • drawable-en/ : for English locale • drawable-en-port/ : for English and in portrait orientation • drawable-en-notouch-12key/ : For English and in notouch devices and 12key as primary input • drawable-port-ldpi/ : for low density screen and in portrait orientation adhamenaya.com 14
  • 15. Android resources example(2) • layout-v4: API level (android 1.6) • layout- h720dp: Available height 720 • Layout-sw600dp: Smallest width 600 Same application with different layouts for each device. adhamenaya.com 15
  • 16. Using Butter Knife Library (1) • Inject Views and view events in activities and fragments. • Notation –based. By : Jake Wharton (Square). adhamenaya.com 16
  • 17. Using Butter Knife Library (2) • Using findViewById adhamenaya.com 17
  • 18. Using the Butter Knife Library (3) • Add dependency to build.gradle: – compile 'com.jakewharton:butterknife:6.1.0‘ • In the onCreate() method of the activity, before using any the views, call inject on the Butterknife object: – ButterKnife.inject(this); adhamenaya.com 18
  • 19. ButterKnife / Insatiate the view (4) • Use: – @InjectView(R.id.sample_textview); – TextView textview; • Rather than: – TextView textview; – textview = (TextView)findViewById(R.id.sample_textview); adhamenaya.com 19
  • 20. Butter Knife / View Events(5) • Use: @OnClick(R.id.sample_textview) public void showToastMessage(){ // DO SOTHING …. } adhamenaya.com 20
  • 22. What is MVP? • The MVP pattern allows separate the presentation layer(UI) from the business logic adhamenaya.com 22
  • 23. Why use MVP? • Android activities are closely coupled to both interface and data. – Such as: CursorAdapter (View)+Cursor(data) • Application to be easily extensible and maintainable. – Such as: changing the data access (from local database to web service). • Easier to test each interface alone. adhamenaya.com 23
  • 24. How to implement MVP ? • MVP architecture consists of 3 layers: – View – Presenter – Model View Presenter Model User Event Update Model Update view State Changed event adhamenaya.com 24
  • 25. MVP: VIEW • Activity, Fragment, View … • Has a reference to the Presenter • Propagates evens from UI to the Presenter. (such as onClick) • Exposes methods that controls the presentation objects. (Such as Show/Hide progress bar) adhamenaya.com 25
  • 26. MVP: PRESENTER • Middle-man Between the View and Presenter • Has reference to View and Model. • Introduce a level of abstraction to the data coming from the model, and formats it before sending it to the view (this makes the View and Model independent). • Updates the UI, the difference to the MVC. adhamenaya.com 26
  • 27. MVP: Model (Interactor) • Gateway towards the business logic. • Contains methods to for data retrival. adhamenaya.com 27
  • 28. MVP Conventions • MVP – Views: ExampleView – Listeners: ExampleListener – Presenters: ExamplePresenter • > impl: ExamplePresenterImpl – Interactors: ExampleInteractor • > impl: ExmpleInteractorImpl adhamenaya.com 28
  • 29. MVP Example Activity Presenter Network Interactor Press Login Button valiadteAccount() loginSuccess() networkSuccess() loginFailue() networkFailure() adhamenaya.com 29
  • 32. MVP vs. MVC • MVP Pattern – View is more loosely coupled to the model. The presenter is responsible for binding the model to the view. – Easier to unit test because interaction with the view is through an interface – Usually view to presenter map one to one. Complex views may have multi presenters. adhamenaya.com 32
  • 34. MVP vs. MVC • MVC Pattern – Controller are based on behaviors and can be shared across views – Can be responsible for determining which view to display 34adhamenaya.com
  • 36. Some Advices • Avoid expensive tasks on the UI thread. • Avoid code duplicity • Use themes, styles and colors properly. • Think in UI layer as isolated domain. • Write testable code and test it. • Measure the UI performance using the performance measure tools. adhamenaya.com 36
  • 37. Any Questions? Contact me: a.it@hotmail.com adhamenaya.com 37