SlideShare a Scribd company logo
Milos Marinkovic "Modular Android UI"
A visual introduction
What does it mean to have a Modular UI?
Responsive layouts
Adjust padding and View positions on larger screens
Different item lists on different devices
List presented as Grid on larger screens
Runtime-configurable layouts
Different list arrangement on larger screens
Displaying the same content in different containers
Compress layout vertically
in split-screen scenario
Different navigation on different devices
Architecture & Layering
Android SDK helps.. with some stuff
● Screen sizes: small, normal, large, xlarge
● Screen aspect ratio: long, notlong
● Device orientation: land, port
● Screen densities: ldpi, mdpi, hdpi, xhdpi,
xxhdpi, xxxhdpi
● Density pixels (dp) instead of pixels (px)
● Precise screen sizes: w__dp, h__dp, sw__dp
Phones
Small Tablets (7”, 8”)
Large Tablets
Android layouts
● Less layouts; more styles
● Print and slice UI on paper
● Sub-layouts belong to static containers
● Use phone UI in tablet containers
MVC
Model:View:Controller
● Model - SQLite,
Shared prefs
● View - main_activity.xml,
ListFragment.java
● Controller - MyController.java,
MainActivity.java (don’t)
MVVM
Model:View:ViewModel
● Model - SQLite,
Shared prefs
● View - main_activity.xml,
ViewGroup or View,
AccountListFragment.java
● ViewModel - AccountListFragmentUiModel.java
MVP
Model:View:Presenter
● Model - SQLite,
Shared prefs
● View - main_activity.xml,
ViewGroup or View
● Presenter - MainActivity.java
ListFragment.java
MVP - Variations
Passive View
● View not aware of the Model
● Presenter does the hard work
Supervising Controller
● View interacts directly with the Model
● Presenter handles extreme cases
Components for Android
How we divided
Android components
Lifecycle
● Service, Activity, Fragment, Dialog,
Application - all different
● Create a custom UI entity? I do it anyway
● Unreliability, bugs, appcompat, gotchas
● API levels…
● Fragment caching mechanism…
Solution: Move away from Android APIs?
Fragment lifecycle...
Android Lists with RecyclerView
● Decouple!
● Android: Recycler View, Adapter, Layout
Manager, Item Animator, Item Decorator,
Recycled Pool, Cache, Item Decoration
Advice: Split “adapter” component
(1) data provider and (2) recycler adapter
Recycler overview
Asynchronous work
● UI events must go to a UI thread
● Long operations go on a background thread
● Thread or AsyncTask or RxJava
● Events? Otto or GreenRobot or others
● A swarm of events
Advice: Keep it minimal for your needs
Self-contained UI parts (Pages)
● Keep pages focused on the UI
● Presenters prepare data for pages
● Pages handle dialogs internally
● Complex dialogs? Contain pages inside them
● Persistent presenters or Presenter pool?
Advice: Instantiate in one place
Android Activity
● Context is everywhere
● Difficult to decouple
● Components: LoaderManager, Cursor,
FragmentManager, Fragment backstack,
Fragment caching, Content Providers,
Intents, Menus, etc.
Advice: It’s worth decoupling, try to do it
Intents
● Handle all intents in one place
● Allow the IntentHandler to navigate
● Use an ActivityResolver
● Allow easy Activity switching
Advice: React in onResume() method if possible
Connecting the dots
Rules for a ‘happy’ UI
● Enumerate pages somehow (enum optimized?)
● Pages need a common navigation API
● Framework creates (and caches) pages
● Follow the Activity lifecycle
Example of a ‘happy’ UI code:
navigate().with(myBundle).to(Pages.LOGIN);
Show and hide pages (Page Manager)
● Static containers or dynamic containers
● Watch out: component lifecycles
● Decoupled mechanism for show/hide
● The dark pit of FragmentManager
Advice: Small app - use FragmentManager
Big app - build your own PageManager
Layout and navigation (The Coordinator)
● Decoupled navigation & layout component
● Uses the PageManager to show/hide
● Handles back and “up”
● Holds the IntentHandler component
Advice: Make Coordinator also a page, a
‘super-page’ that holds all other pages
Visible UI on Phones Actual layers on Phones
The Coordinator
Content Page
Navigation drawer page
The Coordinator
Branding bar
List page
Details page
FAB
List Page
Toolbar & menu
List
- Item photo
- Item name
Details Page
Toolbar & menu
Large title
Content
Actual layers on Tablets
Page Modularity
External configuration causes trouble
● A lot of if-else branches in pages
● Custom Views rule the app (learning curve)
Solution: Have a distinct page for each UI
Advice: Create a PageResolver component
Drawbacks
● A lot of decoupling and cosmetic work
● A lot of method references
● Difficult to switch to
● Makes sense only for complex UIs
● Team education
● Limited support (open-source?)
To recap...
● Self-maintained UI components (pages)
● Data is always prepared (presenters)
● Intent handling happens in one place
● Page Resolver helps with modular UIs
● Separate navigation mechanism
● Wrap it all up in a Coordinator
● Have a Coordinator for each screen variant
Finally done.
Modular Android UI
GitHub / Twitter / LinkedIn
@ milosmns
Blog
www.angrybyte.me
Questions?

More Related Content

PDF
Nicholas Gustilo "Clean Android: building great mobile apps"
PDF
Android application architecture
PPTX
[Android] DI in multimodule application
PPTX
Gradle and Android Studio : Best of Friends
PDF
Designing a json/rest api for your mobile app
PDF
Dagger2 Intro
PDF
Gradle & Android Studio - Introduction
PPT
Google Web Toolkit
Nicholas Gustilo "Clean Android: building great mobile apps"
Android application architecture
[Android] DI in multimodule application
Gradle and Android Studio : Best of Friends
Designing a json/rest api for your mobile app
Dagger2 Intro
Gradle & Android Studio - Introduction
Google Web Toolkit

What's hot (20)

PDF
Django: Beyond Basics
PDF
Using TypeScript with Angular
PDF
Introduction to django framework
PDF
Building Better AngularJS 1.X Apps With TypeScript
PDF
Introduction to React Native
PDF
Clean Architecture
PPTX
React native introduction (Mobile Warsaw)
PPTX
[DevDay2018] React Native – Hello World - By: Trung Pham & React Native team ...
PDF
GWT - Building Rich Internet Applications Using OO Tools
PDF
Intro to Gradle + How to get up to speed
PDF
Gradle enabled android project
PDF
Headless Drupal: A modern approach to (micro)services and APIs
PDF
Building End-to-End Apps Using Typescript
PDF
Counterclockwise past present future
PDF
JHipster, modern web application development made easy
PPTX
Say hello to react js - Day 1
PPTX
Presentation on octobercms
PDF
A/B test your Android build setup with ASPoet
PDF
Intro to Flutter
PDF
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
Django: Beyond Basics
Using TypeScript with Angular
Introduction to django framework
Building Better AngularJS 1.X Apps With TypeScript
Introduction to React Native
Clean Architecture
React native introduction (Mobile Warsaw)
[DevDay2018] React Native – Hello World - By: Trung Pham & React Native team ...
GWT - Building Rich Internet Applications Using OO Tools
Intro to Gradle + How to get up to speed
Gradle enabled android project
Headless Drupal: A modern approach to (micro)services and APIs
Building End-to-End Apps Using Typescript
Counterclockwise past present future
JHipster, modern web application development made easy
Say hello to react js - Day 1
Presentation on octobercms
A/B test your Android build setup with ASPoet
Intro to Flutter
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
Ad

Viewers also liked (15)

PDF
Firefox OS in the development process of a HTML5 app with Cordova
PDF
16 Web & Graphic Design Trends to Watch in 2016
PPSX
Cbc p2 saldaña
PDF
Curriculum meeting 2014
PPTX
Отчет за первое полугодие 2013 года. Департамент науки, промышленной политики...
PPTX
20 steps to build an awesome personal brand
PDF
Horario de las eucaristia
PPT
Distributech 2015 - Mobile Work management
PDF
「Sympathy」 Phantasy Star Online 2の プロシージャルBGMシステム by セガ
PPT
Dulguun wwwii
PDF
презентацияна 01.06.13г. (рус.яз)
DOCX
olproject
PPTX
Launch 3 22-38-1
PDF
BBC foaf talk
PDF
Как построить энергоэффективный дом?
Firefox OS in the development process of a HTML5 app with Cordova
16 Web & Graphic Design Trends to Watch in 2016
Cbc p2 saldaña
Curriculum meeting 2014
Отчет за первое полугодие 2013 года. Департамент науки, промышленной политики...
20 steps to build an awesome personal brand
Horario de las eucaristia
Distributech 2015 - Mobile Work management
「Sympathy」 Phantasy Star Online 2の プロシージャルBGMシステム by セガ
Dulguun wwwii
презентацияна 01.06.13г. (рус.яз)
olproject
Launch 3 22-38-1
BBC foaf talk
Как построить энергоэффективный дом?
Ad

Similar to Milos Marinkovic "Modular Android UI" (20)

PDF
Android UI Fundamentals part 1
PPTX
Android apps development
PDF
Android development first steps
PDF
The Good, the Bad and the Ugly things to do with android
PPTX
Android app development
PDF
Ch4 creating user interfaces
PDF
Mobile Application Development -Lecture 07 & 08.pdf
PPTX
Material design
PPTX
Android apps development
PDF
Designing and implementing_android_uis_for_phones_and_tablets
PPT
Android application development for TresmaxAsia
PPTX
(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016
PPTX
Android crash course
PPTX
Android Apps Development Basic
PDF
Effective Android UI - English
PDF
Android Lesson 2
PPTX
creating User interface in mobile and app dev
PPTX
Exploring Layouts and Providers
PPTX
Workshop Android for Java Developers
PDF
Designing and implementing_android_uis_for_phones_and_tablets
Android UI Fundamentals part 1
Android apps development
Android development first steps
The Good, the Bad and the Ugly things to do with android
Android app development
Ch4 creating user interfaces
Mobile Application Development -Lecture 07 & 08.pdf
Material design
Android apps development
Designing and implementing_android_uis_for_phones_and_tablets
Android application development for TresmaxAsia
(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016
Android crash course
Android Apps Development Basic
Effective Android UI - English
Android Lesson 2
creating User interface in mobile and app dev
Exploring Layouts and Providers
Workshop Android for Java Developers
Designing and implementing_android_uis_for_phones_and_tablets

More from IT Event (20)

PDF
Denis Radin - "Applying NASA coding guidelines to JavaScript or airspace is c...
PDF
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
PDF
Max Voloshin - "Organization of frontend development for products with micros...
PDF
Roman Romanovsky, Sergey Rak - "JavaScript в IoT "
PDF
Konstantin Krivlenia - "Continuous integration for frontend"
PPTX
Illya Klymov - "Vue.JS: What did I swap React for in 2017 and why?"
PDF
Evgeny Gusev - "A circular firing squad: How technologies drag frontend down"
PDF
Vladimir Grinenko - "Dependencies in component web done right"
PDF
Dmitry Bartalevich - "How to train your WebVR"
PDF
Aleksey Bogachuk - "Offline Second"
PDF
James Allardice - "Building a better login with the credential management API"
PDF
Fedor Skuratov "Dark Social: as messengers change the market of social media ...
PPTX
Андрей Зайчиков "Архитектура распределенных кластеров NoSQL на AWS"
PPTX
Алексей Рагозин "Java и linux борьба за микросекунды"
PPTX
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
PDF
Наш ответ Uber’у
PDF
Александр Крашенинников "Hadoop High Availability: опыт Badoo"
PDF
Leonid Vasilyev "Building, deploying and running production code at Dropbox"
PDF
Анатолий Пласковский "Миллионы карточных платежей за месяц, или как потерять ...
PDF
Mete Atamel "Resilient microservices with kubernetes"
Denis Radin - "Applying NASA coding guidelines to JavaScript or airspace is c...
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
Max Voloshin - "Organization of frontend development for products with micros...
Roman Romanovsky, Sergey Rak - "JavaScript в IoT "
Konstantin Krivlenia - "Continuous integration for frontend"
Illya Klymov - "Vue.JS: What did I swap React for in 2017 and why?"
Evgeny Gusev - "A circular firing squad: How technologies drag frontend down"
Vladimir Grinenko - "Dependencies in component web done right"
Dmitry Bartalevich - "How to train your WebVR"
Aleksey Bogachuk - "Offline Second"
James Allardice - "Building a better login with the credential management API"
Fedor Skuratov "Dark Social: as messengers change the market of social media ...
Андрей Зайчиков "Архитектура распределенных кластеров NoSQL на AWS"
Алексей Рагозин "Java и linux борьба за микросекунды"
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
Наш ответ Uber’у
Александр Крашенинников "Hadoop High Availability: опыт Badoo"
Leonid Vasilyev "Building, deploying and running production code at Dropbox"
Анатолий Пласковский "Миллионы карточных платежей за месяц, или как потерять ...
Mete Atamel "Resilient microservices with kubernetes"

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
master seminar digital applications in india
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Open folder Downloads.pdf yes yes ges yes
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Pre independence Education in Inndia.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
human mycosis Human fungal infections are called human mycosis..pptx
master seminar digital applications in india
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Open Quiz Monsoon Mind Game Prelims.pptx
Cardiovascular Pharmacology for pharmacy students.pptx
TR - Agricultural Crops Production NC III.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
GDM (1) (1).pptx small presentation for students
STATICS OF THE RIGID BODIES Hibbelers.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
2.FourierTransform-ShortQuestionswithAnswers.pdf
Open folder Downloads.pdf yes yes ges yes
Week 4 Term 3 Study Techniques revisited.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Pre independence Education in Inndia.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf

Milos Marinkovic "Modular Android UI"

  • 2. A visual introduction What does it mean to have a Modular UI?
  • 4. Adjust padding and View positions on larger screens
  • 5. Different item lists on different devices
  • 6. List presented as Grid on larger screens
  • 8. Different list arrangement on larger screens
  • 9. Displaying the same content in different containers
  • 10. Compress layout vertically in split-screen scenario
  • 11. Different navigation on different devices
  • 13. Android SDK helps.. with some stuff ● Screen sizes: small, normal, large, xlarge ● Screen aspect ratio: long, notlong ● Device orientation: land, port ● Screen densities: ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi ● Density pixels (dp) instead of pixels (px) ● Precise screen sizes: w__dp, h__dp, sw__dp
  • 17. Android layouts ● Less layouts; more styles ● Print and slice UI on paper ● Sub-layouts belong to static containers ● Use phone UI in tablet containers
  • 18. MVC Model:View:Controller ● Model - SQLite, Shared prefs ● View - main_activity.xml, ListFragment.java ● Controller - MyController.java, MainActivity.java (don’t)
  • 19. MVVM Model:View:ViewModel ● Model - SQLite, Shared prefs ● View - main_activity.xml, ViewGroup or View, AccountListFragment.java ● ViewModel - AccountListFragmentUiModel.java
  • 20. MVP Model:View:Presenter ● Model - SQLite, Shared prefs ● View - main_activity.xml, ViewGroup or View ● Presenter - MainActivity.java ListFragment.java
  • 21. MVP - Variations Passive View ● View not aware of the Model ● Presenter does the hard work Supervising Controller ● View interacts directly with the Model ● Presenter handles extreme cases
  • 24. Lifecycle ● Service, Activity, Fragment, Dialog, Application - all different ● Create a custom UI entity? I do it anyway ● Unreliability, bugs, appcompat, gotchas ● API levels… ● Fragment caching mechanism… Solution: Move away from Android APIs?
  • 26. Android Lists with RecyclerView ● Decouple! ● Android: Recycler View, Adapter, Layout Manager, Item Animator, Item Decorator, Recycled Pool, Cache, Item Decoration Advice: Split “adapter” component (1) data provider and (2) recycler adapter
  • 28. Asynchronous work ● UI events must go to a UI thread ● Long operations go on a background thread ● Thread or AsyncTask or RxJava ● Events? Otto or GreenRobot or others ● A swarm of events Advice: Keep it minimal for your needs
  • 29. Self-contained UI parts (Pages) ● Keep pages focused on the UI ● Presenters prepare data for pages ● Pages handle dialogs internally ● Complex dialogs? Contain pages inside them ● Persistent presenters or Presenter pool? Advice: Instantiate in one place
  • 30. Android Activity ● Context is everywhere ● Difficult to decouple ● Components: LoaderManager, Cursor, FragmentManager, Fragment backstack, Fragment caching, Content Providers, Intents, Menus, etc. Advice: It’s worth decoupling, try to do it
  • 31. Intents ● Handle all intents in one place ● Allow the IntentHandler to navigate ● Use an ActivityResolver ● Allow easy Activity switching Advice: React in onResume() method if possible
  • 33. Rules for a ‘happy’ UI ● Enumerate pages somehow (enum optimized?) ● Pages need a common navigation API ● Framework creates (and caches) pages ● Follow the Activity lifecycle Example of a ‘happy’ UI code: navigate().with(myBundle).to(Pages.LOGIN);
  • 34. Show and hide pages (Page Manager) ● Static containers or dynamic containers ● Watch out: component lifecycles ● Decoupled mechanism for show/hide ● The dark pit of FragmentManager Advice: Small app - use FragmentManager Big app - build your own PageManager
  • 35. Layout and navigation (The Coordinator) ● Decoupled navigation & layout component ● Uses the PageManager to show/hide ● Handles back and “up” ● Holds the IntentHandler component Advice: Make Coordinator also a page, a ‘super-page’ that holds all other pages
  • 36. Visible UI on Phones Actual layers on Phones The Coordinator Content Page Navigation drawer page
  • 37. The Coordinator Branding bar List page Details page FAB List Page Toolbar & menu List - Item photo - Item name Details Page Toolbar & menu Large title Content Actual layers on Tablets
  • 38. Page Modularity External configuration causes trouble ● A lot of if-else branches in pages ● Custom Views rule the app (learning curve) Solution: Have a distinct page for each UI Advice: Create a PageResolver component
  • 39. Drawbacks ● A lot of decoupling and cosmetic work ● A lot of method references ● Difficult to switch to ● Makes sense only for complex UIs ● Team education ● Limited support (open-source?)
  • 40. To recap... ● Self-maintained UI components (pages) ● Data is always prepared (presenters) ● Intent handling happens in one place ● Page Resolver helps with modular UIs ● Separate navigation mechanism ● Wrap it all up in a Coordinator ● Have a Coordinator for each screen variant
  • 41. Finally done. Modular Android UI GitHub / Twitter / LinkedIn @ milosmns Blog www.angrybyte.me Questions?