SlideShare a Scribd company logo
Modern Android Development
Computas
24.09.2015
Khiem-Kim Ho Xuan
Agenda
• Code behind
• Material Design
• Pattern recommended to use
Code behind
• Libraries:
• ButterKnife
• Square Otto Event Bus
• Google Play Services
• Support libraries
• Material design
• Retrofit
• Dagger2
• Picasso
24.09.20153
ButterKnife v7.0.1
• Annotate fields with @Bind
• ButterKnife will find the binded ID to the component, layout or resource ids.
• Why?
• Slow reflection. ButterKnife makes sure that the code is generated to perform the view
lookups. Bind delegates to the generated code.
• Resource Binding
• Bind resources. You need to specify the Bind. For example @BindString,
@BindDrawable, @BindColor, @BindDimen
• Non-Activity Binding
• Use @Bind to connect the component or Array. But need to specify @Bind({,….})
• Listener
• Bind listeners for example annotate @OnClick({….}) or @OnItemSelected({…})
• Reset Bind
• Need to clean the bindings when destroying an Activity
or a Fragment using @UnBind.
24.09.20154
Square Otto Event Bus v1.3.8
• Decouple parts of the application for communication.
• Acts as a pub-sub.
• Publish
• Tell Subscribers that an action has occured
• Subscribe
• Receive notification that an event has occured
• Annotate method with @Subscribe
• Register to a bus
• Need to call bus.register(this). In order to receive events
24.09.20155
bus.post(new AnswerAvailableEvent(42));
@Subscribe public void answerAvailable(AnswerAvailableEvent event) { //
TODO: React to the event somehow! }
Retrofit v2.0
• Turns HTTP API into a Java interface
• Uses Annotations to describe HTTP request:
• URL parameter replacement and query parameter support
• Object convertsion to request body (JSON, protocol buffer)
• Multipart request body and file upload
• Request Method
• Request Body
• Multipart
• Header
24.09.20156
@GET("/group/{id}/users") List<User> groupList(@Path("id") int groupId);
@POST("/users/new") Call<User> createUser(@Body User user);
@Multipart @PUT("/user/photo") Call<User> updateUser(@Part("photo")
RequestBody photo, @Part("description") RequestBody description);
@Headers({ "Accept: application/vnd.github.v3.full+json", "User-Agent:
Retrofit-Sample-App" }) @GET("/users/{username}") Call<User>
getUser(@Path("username") String username);
Dagger2
24.09.20157
• Dependency Injection making application loosely coupled.
• Annotations:
• @Module: classes whose methods provide dependencies
• @Provides: methods within module classes
• @Inject: request a dependency (a constructor, field or a method)
• @Component: bridge interface between modules and injection
@Module
public class VehicleModule {
@Provides @Singleton
Motor provideMotor(){
return new Motor();
}
@Provides @Singleton
Vehicle provideVehicle(){
return new Vehicle(new Motor());
}
}
@Inject
public Vehicle(Motor motor){
this.motor = motor;
}
@Singleton
@Component(modules = {VehicleModule.class})
public interface VehicleComponent {
Vehicle provideVehicle();
} // connect @modules with @inject
Dagger2
24.09.20158
• When everything is ready
• Obtain instance of the interface and invoke its method.
• Do it inside onCreate method!
• Why Dagger2?
• No reflection: graph validation, configuration and precondition done at compile time.
• Performance gain
public class MainActivity extends ActionBarActivity {
Vehicle mVehicle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VehicleComponent component = Dagger_VehicleComponent.builder().vehicleModule(new VehicleModule()).build();
mVehicle = component.provideVehicle();
Toast.makeText(this, String.valueOf(vehicle.getSpeed()), Toast.LENGTH_SHORT).show();
}
}
Picasso v2.5.2
24.09.20159
• Load image into a view based on url or from memory
• Picasso handles:
• ImageView recycling and download cancelation in an adapter
• Complex image transformations with minimal memory usage
• Automatic memory and disk caching.
• Has placeholders in case of loading or failed loading image.
Picasso.with(context) .load(url)
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error) .into(imageView);
Material Design
• Make all apps flat as paper,
• responsive animations!
• Right color and shadow depths
• Get inspired!
• http://www.materialup.com/
Material Design
• Use Androids Design library:
• com.android.support.design
• Snackbar!
• Like Toast, but shows a message at the bottom of
the screen
Snackbar.make(mDrawerLayout, "Your message", Snackbar.LENGTH_SHORT)
.setAction(getString(R.string.text_undo), this)
.show();
Shared Element Transition
24.09.201512
• Animate different UI states in an application.
• Built on
• Scene: Defines UI states in an application
• Transition: Defines the animated change between two scenes
• Need to define transition in style.xml and also
<transitionSet
xmlns:android="http://schemas.android.com/apk/res/android">
<changeBounds>
<targets>
<target android:targetId="@id/ivPosterImage" />
<target android:targetId="@id/detailed_image" />
</targets>
</changeBounds>
<changeImageTransform>
<targets>
<target android:targetId="@id/ivPosterImage" />
<target android:targetId="@id/detailed_image" />
</targets>
</changeImageTransform>
</transitionSet>
Shared Element Transition
24.09.201513
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowIsTranslucent">true</item>
<!-- specify enter and exit transitions -->
<item name="android:windowEnterTransition">@transition/fade</item>
<item name="android:windowExitTransition">@transition/fade</item>
<!-- specify shared element transitions -->
<item name="android:windowSharedElementEnterTransition">
@transition/change_image_transform
</item><transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeBounds>
<targets>
<target android:targetId="@id/ivPosterImage" />
<target android:targetId="@id/detailed_image" />
</targets>
</changeBounds>
<changeImageTransform>
<targets>
<target android:targetId="@id/ivPosterImage" />
<target android:targetId="@id/detailed_image" />
</targets>
</changeImageTransform>
</transitionSet>
<item name="android:windowSharedElementExitTransition">
@transition/change_image_transform
</item>
</style>
Floating Action Button
24.09.201514
• fabSize: set the size of the button
• Normal: 56dp
• Mini: 40dp
• backgroundTint: set the background color of this instance
• rippleColor set color of the ripple effect when pressed
• src: set the icon displayed within the FAB
<android.support.design.widget.FloatingActionButton
android:id=”@+id/fab_normal”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:src=”@drawable/ic_plus”
app:fabSize=”normal” />
EditText Floating Labels
• Display floating labels above EditText fields.
• Gives focus or hint of float.
• Useful to use while data is being input
• You can also add Error message
24.09.201515
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edit_text_email"
android:layout_width="match_parent"/>
</android.support.design.widget.TextInputLayout>
setErrorEnabled(true);
setError(getString(R.string.text_error_message));
Navigation View
• Placed within a DrawerLayout
24.09.201516
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/main_content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_header"
app:menu="@menu/drawer" />
</android.support.v4.widget.DrawerLayout>
TabLayout
• tabMode: set the layout to fixed or scrollable
• tabGravity: set gravity of the tab, either filled (distributed to all available space
between individual tabs) or centre (position tabs in the center of the TabLayout)
• setText() and setIcon()
• Listeners:
• OnTabSelectedListener
• TabLayoutOnPageChangeListener
• ViewPagerOnTabSelectedListener
24.09.201517
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill" />
ViewPager pager = (ViewPager)
rootView.findViewById(R.id.viewPager);
pager.setAdapter(new MyPagerAdapter(getActivity().getSupportFragmentManager()));
TabLayout tabLayout = (TabLayout)
rootView.findViewById(R.id.sliding_tabs);tabLayout.addTab(tabLayout.newTab().setText("Tab One"));
tabLayout.addTab(tabLayout.newTab().setText("Tab Two"));
tabLayout.addTab(tabLayout.newTab().setText("Tab Three"));
tabLayout.setupWithViewPager(pager);
Coordinator Layout
• Super FrameLayout
• Adds transition view basedon motion of other components
• Lets us adapt layouts based on scroll events.
• Set the property layout_scrollFlags
• enterAlways – view will become visible when a downward scroll event occurs
• enterAlwaysCollapsed – if view has minHeight, it will only
enter at a that height and expand fully once the scrolling view
reached the top.
24.09.201518
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior=
"@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
/> </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Support Toolbar
• Use
• com.android.support.appcompat-v7:<versionnumber>
• Remember to style the toolbar!
24.09.201519
<android.support.v7.widget.Toolbar
android:id=”@+id/my_awesome_toolbar”
android:layout_height=”wrap_content”
android:layout_width=”match_parent”
android:minHeight=”?attr/actionBarSize”
android:background=”?attr/colorPrimary” />
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.blah);
Toolbar toolbar = (Toolbar)
findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
}
<style name="Theme.MyTheme"
parent="Theme.AppCompat.Light">
<!-- Set AppCompat’s actionBarStyle -->
<item name="actionBarStyle">@style/MyActionBarStyle</item>
<!-- Set AppCompat’s color theming attrs -->
<item name="colorPrimary">@color/my_awesome_red</item>
<item
name="colorPrimaryDark">@color/my_awesome_darker_red</item>
<!-- The rest of your attributes -->
</style>
Pattern recommended to use
• Model-View-Presenter (MVP)
• User interacts with the View.
• There is one-to-one relationship between View and Presenter means one View is mapped to
only one Presenter.
• View has a reference to Presenter but View has not reference to Model.
• Provides two way communication between View and Presenter.
24.09.201520
Firmu – The Cinema Locator App
• Google Play Store
• (Later on Windows Store and IOS).
• Highly inspired by Material Design and modern
mobile development.
• Feedback on the app please 
24.09.201521
Pitch (Beta version)
• Google Play Store
• (Later on Windows Store and IOS).
• Highly inspired by Material Design and modern
mobile development.
• Feedback on the app please 
24.09.201522
23 © Computas AS 24.09.2015
Questions?
Computas AS Tel +47 67 83 10 00
Lysaker Torg 45, pb 482 Fax +47 67 83 10 01
1327 Lysaker Org.nr: NO 986 352 325 MVA
Norway www.computas.com
Khiem-Kim Ho Xuan

More Related Content

What's hot (20)

PPTX
Angular2 and TypeScript
David Giard
 
PDF
Building Universal Web Apps with React ForwardJS 2017
Elyse Kolker Gordon
 
PPTX
Angular Workshop_Sarajevo2
Christoffer Noring
 
PDF
Creating lightweight JS Apps w/ Web Components and lit-html
Ilia Idakiev
 
PPTX
Angular js
Behind D Walls
 
PPTX
Angular 9
Raja Vishnu
 
PPT
GWT Training - Session 1/3
Faiz Bashir
 
PPTX
Intoduction to Angularjs
Gaurav Agrawal
 
PDF
Angular Best Practices - Perfomatix
Perfomatix Solutions
 
PDF
Angular js
Knoldus Inc.
 
PPT
GWT Training - Session 2/3
Faiz Bashir
 
PPTX
Working with AngularJS
André Vala
 
PDF
Vaadin Components @ Angular U
Joonas Lehtinen
 
PDF
Understanding router state in angular 7 passing data through angular router s...
Katy Slemon
 
PPTX
Angular introduction students
Christian John Felix
 
PDF
Start Developing Apps for Magnolia CMS
Magnolia
 
PPTX
Angular2 + rxjs
Christoffer Noring
 
PDF
Building maintainable app
Kristijan Jurković
 
PPTX
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson
 
PPTX
Angular tutorial
Rohit Gupta
 
Angular2 and TypeScript
David Giard
 
Building Universal Web Apps with React ForwardJS 2017
Elyse Kolker Gordon
 
Angular Workshop_Sarajevo2
Christoffer Noring
 
Creating lightweight JS Apps w/ Web Components and lit-html
Ilia Idakiev
 
Angular js
Behind D Walls
 
Angular 9
Raja Vishnu
 
GWT Training - Session 1/3
Faiz Bashir
 
Intoduction to Angularjs
Gaurav Agrawal
 
Angular Best Practices - Perfomatix
Perfomatix Solutions
 
Angular js
Knoldus Inc.
 
GWT Training - Session 2/3
Faiz Bashir
 
Working with AngularJS
André Vala
 
Vaadin Components @ Angular U
Joonas Lehtinen
 
Understanding router state in angular 7 passing data through angular router s...
Katy Slemon
 
Angular introduction students
Christian John Felix
 
Start Developing Apps for Magnolia CMS
Magnolia
 
Angular2 + rxjs
Christoffer Noring
 
Building maintainable app
Kristijan Jurković
 
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson
 
Angular tutorial
Rohit Gupta
 

Viewers also liked (12)

PDF
Poteri di autentica dell'avvocato - Cittadella 18.03.16
Edoardo Ferraro
 
ODS
Trabajos de mates
idasou
 
PPSX
Rodriguez ruiz
Leonardo Rodriguez Ruiz
 
PDF
Energia solar 01
Lucelio Santos
 
PPTX
4.Evaluación de Proyectos y Aplicaciones Computarizadas
Selene Orozco
 
PDF
Mtaylor Get Acquainted Presentation 1 Safe One!
morgan_taylor
 
PDF
Đèn LED chiếu sáng khu vực mua bán chung trong siêu thị, trung tâm thương mại
RANGDONG LIGHT SOURCE & VACUUM FLASK JOINT STOCK COMPANY
 
RTF
Defolu Spot Buzdolabı Alanlar İstanbul
Eskici eşya alanlar
 
PPTX
Phobias A Presentation by Mr Allah Dad Khan Former DG Agri Extension /Visiti...
Mr.Allah Dad Khan
 
PDF
Sentenza su ammissione gratuito patrocinio per procedimenti mediazione
GRATUITO PATROCINIO e ART 24. - Associazione per la Tutela del Diritto di Difesa
 
Poteri di autentica dell'avvocato - Cittadella 18.03.16
Edoardo Ferraro
 
Trabajos de mates
idasou
 
Rodriguez ruiz
Leonardo Rodriguez Ruiz
 
Energia solar 01
Lucelio Santos
 
4.Evaluación de Proyectos y Aplicaciones Computarizadas
Selene Orozco
 
Mtaylor Get Acquainted Presentation 1 Safe One!
morgan_taylor
 
Đèn LED chiếu sáng khu vực mua bán chung trong siêu thị, trung tâm thương mại
RANGDONG LIGHT SOURCE & VACUUM FLASK JOINT STOCK COMPANY
 
Defolu Spot Buzdolabı Alanlar İstanbul
Eskici eşya alanlar
 
Phobias A Presentation by Mr Allah Dad Khan Former DG Agri Extension /Visiti...
Mr.Allah Dad Khan
 
Sentenza su ammissione gratuito patrocinio per procedimenti mediazione
GRATUITO PATROCINIO e ART 24. - Associazione per la Tutela del Diritto di Difesa
 
Ad

Similar to Modern android development (20)

PPTX
Android architecture
Trong-An Bui
 
PDF
Modern Android app library stack
Tomáš Kypta
 
PPTX
Lecture android best practices
eleksdev
 
PDF
Android application architecture
Romain Rochegude
 
PDF
RIBs - Fragments which work
Dmitry Zaytsev
 
PDF
Droidcon Paris 2015
Renaud Boulard
 
PPTX
Applico Android Info Session at Columbia University
Applico
 
PPTX
Android 3
Robert Cooper
 
PDF
Building maintainable app #droidconzg
Kristijan Jurković
 
PPTX
What's New in Android
Robert Cooper
 
PDF
Introducing Honeycomb
CommonsWare
 
PDF
Di code steps
Brian Kiptoo
 
PDF
Overview of Android Infrastructure
C.T.Co
 
PDF
Overview of Android Infrastructure
Alexey Buzdin
 
PDF
Stmik bandung
farid savarudin
 
PDF
Innovation Generation - The Mobile Meetup: Android Best Practices
Solstice Mobile Argentina
 
PDF
Mobile Software Engineering Crash Course - C04 Android Cont.
Mohammad Shaker
 
PPTX
Google I/O 2019 - what's new in Android Q and Jetpack
Sunita Singh
 
PDF
Mattbrenner
Droidcon Berlin
 
PPTX
Dagger 2 - Injeção de Dependência
Edson Menegatti
 
Android architecture
Trong-An Bui
 
Modern Android app library stack
Tomáš Kypta
 
Lecture android best practices
eleksdev
 
Android application architecture
Romain Rochegude
 
RIBs - Fragments which work
Dmitry Zaytsev
 
Droidcon Paris 2015
Renaud Boulard
 
Applico Android Info Session at Columbia University
Applico
 
Android 3
Robert Cooper
 
Building maintainable app #droidconzg
Kristijan Jurković
 
What's New in Android
Robert Cooper
 
Introducing Honeycomb
CommonsWare
 
Di code steps
Brian Kiptoo
 
Overview of Android Infrastructure
C.T.Co
 
Overview of Android Infrastructure
Alexey Buzdin
 
Stmik bandung
farid savarudin
 
Innovation Generation - The Mobile Meetup: Android Best Practices
Solstice Mobile Argentina
 
Mobile Software Engineering Crash Course - C04 Android Cont.
Mohammad Shaker
 
Google I/O 2019 - what's new in Android Q and Jetpack
Sunita Singh
 
Mattbrenner
Droidcon Berlin
 
Dagger 2 - Injeção de Dependência
Edson Menegatti
 
Ad

Recently uploaded (20)

PPTX
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
PPTX
Precedence and Associativity in C prog. language
Mahendra Dheer
 
PPTX
quantum computing transition from classical mechanics.pptx
gvlbcy
 
PPTX
filteration _ pre.pptx 11111110001.pptx
awasthivaibhav825
 
PDF
SG1-ALM-MS-EL-30-0008 (00) MS - Isolators and disconnecting switches.pdf
djiceramil
 
PDF
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
PDF
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
PPTX
ENSA_Module_7.pptx_wide_area_network_concepts
RanaMukherjee24
 
PPTX
Online Cab Booking and Management System.pptx
diptipaneri80
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
PPTX
Water resources Engineering GIS KRT.pptx
Krunal Thanki
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPTX
ETP Presentation(1000m3 Small ETP For Power Plant and industry
MD Azharul Islam
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PDF
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
PPTX
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
Precedence and Associativity in C prog. language
Mahendra Dheer
 
quantum computing transition from classical mechanics.pptx
gvlbcy
 
filteration _ pre.pptx 11111110001.pptx
awasthivaibhav825
 
SG1-ALM-MS-EL-30-0008 (00) MS - Isolators and disconnecting switches.pdf
djiceramil
 
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
ENSA_Module_7.pptx_wide_area_network_concepts
RanaMukherjee24
 
Online Cab Booking and Management System.pptx
diptipaneri80
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
Water resources Engineering GIS KRT.pptx
Krunal Thanki
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
ETP Presentation(1000m3 Small ETP For Power Plant and industry
MD Azharul Islam
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 

Modern android development

  • 2. Agenda • Code behind • Material Design • Pattern recommended to use
  • 3. Code behind • Libraries: • ButterKnife • Square Otto Event Bus • Google Play Services • Support libraries • Material design • Retrofit • Dagger2 • Picasso 24.09.20153
  • 4. ButterKnife v7.0.1 • Annotate fields with @Bind • ButterKnife will find the binded ID to the component, layout or resource ids. • Why? • Slow reflection. ButterKnife makes sure that the code is generated to perform the view lookups. Bind delegates to the generated code. • Resource Binding • Bind resources. You need to specify the Bind. For example @BindString, @BindDrawable, @BindColor, @BindDimen • Non-Activity Binding • Use @Bind to connect the component or Array. But need to specify @Bind({,….}) • Listener • Bind listeners for example annotate @OnClick({….}) or @OnItemSelected({…}) • Reset Bind • Need to clean the bindings when destroying an Activity or a Fragment using @UnBind. 24.09.20154
  • 5. Square Otto Event Bus v1.3.8 • Decouple parts of the application for communication. • Acts as a pub-sub. • Publish • Tell Subscribers that an action has occured • Subscribe • Receive notification that an event has occured • Annotate method with @Subscribe • Register to a bus • Need to call bus.register(this). In order to receive events 24.09.20155 bus.post(new AnswerAvailableEvent(42)); @Subscribe public void answerAvailable(AnswerAvailableEvent event) { // TODO: React to the event somehow! }
  • 6. Retrofit v2.0 • Turns HTTP API into a Java interface • Uses Annotations to describe HTTP request: • URL parameter replacement and query parameter support • Object convertsion to request body (JSON, protocol buffer) • Multipart request body and file upload • Request Method • Request Body • Multipart • Header 24.09.20156 @GET("/group/{id}/users") List<User> groupList(@Path("id") int groupId); @POST("/users/new") Call<User> createUser(@Body User user); @Multipart @PUT("/user/photo") Call<User> updateUser(@Part("photo") RequestBody photo, @Part("description") RequestBody description); @Headers({ "Accept: application/vnd.github.v3.full+json", "User-Agent: Retrofit-Sample-App" }) @GET("/users/{username}") Call<User> getUser(@Path("username") String username);
  • 7. Dagger2 24.09.20157 • Dependency Injection making application loosely coupled. • Annotations: • @Module: classes whose methods provide dependencies • @Provides: methods within module classes • @Inject: request a dependency (a constructor, field or a method) • @Component: bridge interface between modules and injection @Module public class VehicleModule { @Provides @Singleton Motor provideMotor(){ return new Motor(); } @Provides @Singleton Vehicle provideVehicle(){ return new Vehicle(new Motor()); } } @Inject public Vehicle(Motor motor){ this.motor = motor; } @Singleton @Component(modules = {VehicleModule.class}) public interface VehicleComponent { Vehicle provideVehicle(); } // connect @modules with @inject
  • 8. Dagger2 24.09.20158 • When everything is ready • Obtain instance of the interface and invoke its method. • Do it inside onCreate method! • Why Dagger2? • No reflection: graph validation, configuration and precondition done at compile time. • Performance gain public class MainActivity extends ActionBarActivity { Vehicle mVehicle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); VehicleComponent component = Dagger_VehicleComponent.builder().vehicleModule(new VehicleModule()).build(); mVehicle = component.provideVehicle(); Toast.makeText(this, String.valueOf(vehicle.getSpeed()), Toast.LENGTH_SHORT).show(); } }
  • 9. Picasso v2.5.2 24.09.20159 • Load image into a view based on url or from memory • Picasso handles: • ImageView recycling and download cancelation in an adapter • Complex image transformations with minimal memory usage • Automatic memory and disk caching. • Has placeholders in case of loading or failed loading image. Picasso.with(context) .load(url) .placeholder(R.drawable.user_placeholder) .error(R.drawable.user_placeholder_error) .into(imageView);
  • 10. Material Design • Make all apps flat as paper, • responsive animations! • Right color and shadow depths • Get inspired! • http://www.materialup.com/
  • 11. Material Design • Use Androids Design library: • com.android.support.design • Snackbar! • Like Toast, but shows a message at the bottom of the screen Snackbar.make(mDrawerLayout, "Your message", Snackbar.LENGTH_SHORT) .setAction(getString(R.string.text_undo), this) .show();
  • 12. Shared Element Transition 24.09.201512 • Animate different UI states in an application. • Built on • Scene: Defines UI states in an application • Transition: Defines the animated change between two scenes • Need to define transition in style.xml and also <transitionSet xmlns:android="http://schemas.android.com/apk/res/android"> <changeBounds> <targets> <target android:targetId="@id/ivPosterImage" /> <target android:targetId="@id/detailed_image" /> </targets> </changeBounds> <changeImageTransform> <targets> <target android:targetId="@id/ivPosterImage" /> <target android:targetId="@id/detailed_image" /> </targets> </changeImageTransform> </transitionSet>
  • 13. Shared Element Transition 24.09.201513 <style name="AppTheme" parent="AppTheme.Base"> <item name="android:windowContentTransitions">true</item> <item name="android:windowAllowEnterTransitionOverlap">true</item> <item name="android:windowAllowReturnTransitionOverlap">true</item> <item name="android:windowIsTranslucent">true</item> <!-- specify enter and exit transitions --> <item name="android:windowEnterTransition">@transition/fade</item> <item name="android:windowExitTransition">@transition/fade</item> <!-- specify shared element transitions --> <item name="android:windowSharedElementEnterTransition"> @transition/change_image_transform </item><transitionSet xmlns:android="http://schemas.android.com/apk/res/android"> <changeBounds> <targets> <target android:targetId="@id/ivPosterImage" /> <target android:targetId="@id/detailed_image" /> </targets> </changeBounds> <changeImageTransform> <targets> <target android:targetId="@id/ivPosterImage" /> <target android:targetId="@id/detailed_image" /> </targets> </changeImageTransform> </transitionSet> <item name="android:windowSharedElementExitTransition"> @transition/change_image_transform </item> </style>
  • 14. Floating Action Button 24.09.201514 • fabSize: set the size of the button • Normal: 56dp • Mini: 40dp • backgroundTint: set the background color of this instance • rippleColor set color of the ripple effect when pressed • src: set the icon displayed within the FAB <android.support.design.widget.FloatingActionButton android:id=”@+id/fab_normal” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:src=”@drawable/ic_plus” app:fabSize=”normal” />
  • 15. EditText Floating Labels • Display floating labels above EditText fields. • Gives focus or hint of float. • Useful to use while data is being input • You can also add Error message 24.09.201515 <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/edit_text_email" android:layout_width="match_parent"/> </android.support.design.widget.TextInputLayout> setErrorEnabled(true); setError(getString(R.string.text_error_message));
  • 16. Navigation View • Placed within a DrawerLayout 24.09.201516 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <FrameLayout android:id="@+id/main_content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <android.support.design.widget.NavigationView android:id="@+id/navigation_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:headerLayout="@layout/navigation_header" app:menu="@menu/drawer" /> </android.support.v4.widget.DrawerLayout>
  • 17. TabLayout • tabMode: set the layout to fixed or scrollable • tabGravity: set gravity of the tab, either filled (distributed to all available space between individual tabs) or centre (position tabs in the center of the TabLayout) • setText() and setIcon() • Listeners: • OnTabSelectedListener • TabLayoutOnPageChangeListener • ViewPagerOnTabSelectedListener 24.09.201517 <android.support.design.widget.TabLayout android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabMode="fixed" app:tabGravity="fill" /> ViewPager pager = (ViewPager) rootView.findViewById(R.id.viewPager); pager.setAdapter(new MyPagerAdapter(getActivity().getSupportFragmentManager())); TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.sliding_tabs);tabLayout.addTab(tabLayout.newTab().setText("Tab One")); tabLayout.addTab(tabLayout.newTab().setText("Tab Two")); tabLayout.addTab(tabLayout.newTab().setText("Tab Three")); tabLayout.setupWithViewPager(pager);
  • 18. Coordinator Layout • Super FrameLayout • Adds transition view basedon motion of other components • Lets us adapt layouts based on scroll events. • Set the property layout_scrollFlags • enterAlways – view will become visible when a downward scroll event occurs • enterAlwaysCollapsed – if view has minHeight, it will only enter at a that height and expand fully once the scrolling view reached the top. 24.09.201518 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior= "@string/appbar_scrolling_view_behavior" /> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar app:layout_scrollFlags="scroll|enterAlways" /> <android.support.design.widget.TabLayout /> </android.support.design.widget.AppBarLayout> </android.support.design.widget.CoordinatorLayout>
  • 19. Support Toolbar • Use • com.android.support.appcompat-v7:<versionnumber> • Remember to style the toolbar! 24.09.201519 <android.support.v7.widget.Toolbar android:id=”@+id/my_awesome_toolbar” android:layout_height=”wrap_content” android:layout_width=”match_parent” android:minHeight=”?attr/actionBarSize” android:background=”?attr/colorPrimary” /> @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.blah); Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar); setSupportActionBar(toolbar); } <style name="Theme.MyTheme" parent="Theme.AppCompat.Light"> <!-- Set AppCompat’s actionBarStyle --> <item name="actionBarStyle">@style/MyActionBarStyle</item> <!-- Set AppCompat’s color theming attrs --> <item name="colorPrimary">@color/my_awesome_red</item> <item name="colorPrimaryDark">@color/my_awesome_darker_red</item> <!-- The rest of your attributes --> </style>
  • 20. Pattern recommended to use • Model-View-Presenter (MVP) • User interacts with the View. • There is one-to-one relationship between View and Presenter means one View is mapped to only one Presenter. • View has a reference to Presenter but View has not reference to Model. • Provides two way communication between View and Presenter. 24.09.201520
  • 21. Firmu – The Cinema Locator App • Google Play Store • (Later on Windows Store and IOS). • Highly inspired by Material Design and modern mobile development. • Feedback on the app please  24.09.201521
  • 22. Pitch (Beta version) • Google Play Store • (Later on Windows Store and IOS). • Highly inspired by Material Design and modern mobile development. • Feedback on the app please  24.09.201522
  • 23. 23 © Computas AS 24.09.2015 Questions? Computas AS Tel +47 67 83 10 00 Lysaker Torg 45, pb 482 Fax +47 67 83 10 01 1327 Lysaker Org.nr: NO 986 352 325 MVA Norway www.computas.com Khiem-Kim Ho Xuan