android develpment vol. 3, mff uk, 2015

121
Android Development vol. 3 Tomáš Kypta @TomasKypta

Upload: tomas-kypta

Post on 15-Apr-2017

338 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Android Develpment vol. 3, MFF UK, 2015

Android Development vol. 3Tomáš Kypta

@TomasKypta

Page 2: Android Develpment vol. 3, MFF UK, 2015

Agenda• Dialogs

• Material Design

• UX Design Patterns

• Dependency Injection

• Useful Android Libraries

Page 3: Android Develpment vol. 3, MFF UK, 2015

Database

Page 4: Android Develpment vol. 3, MFF UK, 2015

Database

• SQLiteDatabase

• SQLiteOpenHelper

• can be used with/without content provider

Page 5: Android Develpment vol. 3, MFF UK, 2015

Exercise

1. Check the code of the DB access.

Page 6: Android Develpment vol. 3, MFF UK, 2015

Dialogs

Page 7: Android Develpment vol. 3, MFF UK, 2015

Dialogs

• handled via DialogFragment

• styling problems

Page 8: Android Develpment vol. 3, MFF UK, 2015

Dialogs

Page 9: Android Develpment vol. 3, MFF UK, 2015

Dialogs• android-styled-dialogs

• https://github.com/avast/android-styled-dialogs

Page 10: Android Develpment vol. 3, MFF UK, 2015

Dialogs

SimpleDialogFragment.createBuilder(c, getSupportFragmentManager()) .setTitle(“Backport of material dialogs") .setMessage(“Lorem ipsum dolor sit amet…”) .setPositiveButtonText("OK") .setNegativeButtonText("Cancel") .setNeutralButtonText("Help") .setRequestCode(REQUEST_SIMPLE_DIALOG) .show();

Page 11: Android Develpment vol. 3, MFF UK, 2015

Dialogs

SimpleDialogFragment.createBuilder(c, getSupportFragmentManager()) .setTitle(“Backport of material dialogs") .setMessage(“Lorem ipsum dolor sit amet…”) .setPositiveButtonText("OK") .setNegativeButtonText("Cancel") .setNeutralButtonText("Help") .setRequestCode(REQUEST_SIMPLE_DIALOG) .show();

Page 12: Android Develpment vol. 3, MFF UK, 2015

Dialogs

SimpleDialogFragment.createBuilder(c, getSupportFragmentManager()) .setTitle(“Backport of material dialogs") .setMessage(“Lorem ipsum dolor sit amet…”) .setPositiveButtonText("OK") .setNegativeButtonText("Cancel") .setNeutralButtonText("Help") .setRequestCode(REQUEST_SIMPLE_DIALOG) .show();

Page 13: Android Develpment vol. 3, MFF UK, 2015

Dialogs

SimpleDialogFragment.createBuilder(c, getSupportFragmentManager()) .setTitle(“Backport of material dialogs") .setMessage(“Lorem ipsum dolor sit amet…”) .setPositiveButtonText("OK") .setNegativeButtonText("Cancel") .setNeutralButtonText("Help") .setRequestCode(REQUEST_SIMPLE_DIALOG) .show();

Page 14: Android Develpment vol. 3, MFF UK, 2015

Dialogs

SimpleDialogFragment.createBuilder(c, getSupportFragmentManager()) .setTitle(“Backport of material dialogs") .setMessage(“Lorem ipsum dolor sit amet…”) .setPositiveButtonText("OK") .setNegativeButtonText("Cancel") .setNeutralButtonText("Help") .setRequestCode(REQUEST_SIMPLE_DIALOG) .show();

Page 15: Android Develpment vol. 3, MFF UK, 2015

Dialogs

•implement listener in activity/fragment to receive callback •ISimpleDialogListener

•IPositiveButtonDialogListener

•INegativeButtonDialogListener

•INeutralButtonDialogListener

Page 16: Android Develpment vol. 3, MFF UK, 2015

Dialogs

@Overridepublic void onPositiveButtonClicked(int requestCode) { if (requestCode == REQUEST_SIMPLE_DIALOG) { Toast.makeText(c, "Positive button clicked", Toast.LENGTH_SHORT) .show(); }}

Page 17: Android Develpment vol. 3, MFF UK, 2015

Dialogs

@Overridepublic void onPositiveButtonClicked(int requestCode) { if (requestCode == REQUEST_SIMPLE_DIALOG) { Toast.makeText(c, "Positive button clicked", Toast.LENGTH_SHORT) .show(); }}

Page 18: Android Develpment vol. 3, MFF UK, 2015

Dialogs

@Overridepublic void onPositiveButtonClicked(int requestCode) { if (requestCode == REQUEST_SIMPLE_DIALOG) { Toast.makeText(c, "Positive button clicked", Toast.LENGTH_SHORT) .show(); }}

Page 19: Android Develpment vol. 3, MFF UK, 2015

Exercise

2. Display alert dialog when we click on an account item.

3. Check the code of add dialog.

Page 20: Android Develpment vol. 3, MFF UK, 2015

Material Design

Page 21: Android Develpment vol. 3, MFF UK, 2015

Android Design

Evolution

long time ago …

Page 22: Android Develpment vol. 3, MFF UK, 2015

Android Design Evolution

Holo Design

Material Design

Page 23: Android Develpment vol. 3, MFF UK, 2015

Material Design

Page 24: Android Develpment vol. 3, MFF UK, 2015

Material Design

• tangible surfaces and edges

• shadows

• elevation

• motion

Page 25: Android Develpment vol. 3, MFF UK, 2015

Material Design

• themes since API level 21

• @android:style/Theme.Material (dark version)

• @android:style/Theme.Material.Light (light version)

• @android:style/Theme.Material.Light.DarkActionBar

• …

Page 26: Android Develpment vol. 3, MFF UK, 2015

Material Design

• compatibility themes

• @style/Theme.AppCompat (dark version)

• @style/Theme.AppCompat.Light (light version)

• @style/Theme.AppCompat.Light.DarkActionBar

• …

Page 27: Android Develpment vol. 3, MFF UK, 2015

The Color Palette• three color hues from the primary palette

• one accent color from the secondary palette

Page 28: Android Develpment vol. 3, MFF UK, 2015

The Color Palette

• http://www.google.com/design/spec/style/color.html

Page 29: Android Develpment vol. 3, MFF UK, 2015

The Color Palette<!-- inherit from the material theme --><style name="AppTheme" parent=“android:Theme.Material"> <!-- Main theme colors --> <!-- your app branding color for the app bar --> <item name=“android:colorPrimary">@color/primary</item> <!-- darker variant for the status bar and contextual app bars --> <item name=“android:colorPrimaryDark">@color/primary_dark</item> <!-- theme UI controls like checkboxes and text fields --> <item name="android:colorAccent">@color/accent</item> </style>

Page 30: Android Develpment vol. 3, MFF UK, 2015

The Color Palette<!-- inherit from the material theme --><style name="AppTheme" parent=“android:Theme.Material"> <!-- Main theme colors --> <!-- your app branding color for the app bar --> <item name=“android:colorPrimary">@color/primary</item> <!-- darker variant for the status bar and contextual app bars --> <item name=“android:colorPrimaryDark">@color/primary_dark</item> <!-- theme UI controls like checkboxes and text fields --> <item name="android:colorAccent">@color/accent</item> </style>

Page 31: Android Develpment vol. 3, MFF UK, 2015

The Color Palette<!-- inherit from the material theme --><style name="AppTheme" parent=“android:Theme.Material"> <!-- Main theme colors --> <!-- your app branding color for the app bar --> <item name=“android:colorPrimary">@color/primary</item> <!-- darker variant for the status bar and contextual app bars --> <item name=“android:colorPrimaryDark">@color/primary_dark</item> <!-- theme UI controls like checkboxes and text fields --> <item name="android:colorAccent">@color/accent</item> </style>

Page 32: Android Develpment vol. 3, MFF UK, 2015

The Color Palette<!-- inherit from the material theme --><style name="AppTheme" parent=“android:Theme.Material"> <!-- Main theme colors --> <!-- your app branding color for the app bar --> <item name=“android:colorPrimary">@color/primary</item> <!-- darker variant for the status bar and contextual app bars --> <item name=“android:colorPrimaryDark">@color/primary_dark</item> <!-- theme UI controls like checkboxes and text fields --> <item name="android:colorAccent">@color/accent</item> </style>

Page 33: Android Develpment vol. 3, MFF UK, 2015

The Color Palette with AppCompat

<!-- AppCompat variant --><style name="AppTheme" parent=“Theme.AppCompat"> <!-- your app branding color for the app bar --> <item name=“colorPrimary">@color/primary</item> <!-- darker variant for the status bar and contextual app bars --> <item name=“colorPrimaryDark">@color/primary_dark</item> <!-- theme UI controls like checkboxes and text fields --> <item name="colorAccent">@color/accent</item> </style>

Page 34: Android Develpment vol. 3, MFF UK, 2015

The Color Palette with AppCompat

<!-- AppCompat variant --><style name="AppTheme" parent=“Theme.AppCompat"> <!-- your app branding color for the app bar --> <item name=“colorPrimary">@color/primary</item> <!-- darker variant for the status bar and contextual app bars --> <item name=“colorPrimaryDark">@color/primary_dark</item> <!-- theme UI controls like checkboxes and text fields --> <item name="colorAccent">@color/accent</item> </style>

Page 35: Android Develpment vol. 3, MFF UK, 2015

The Color Palette with AppCompat

<!-- AppCompat variant --><style name="AppTheme" parent=“Theme.AppCompat"> <!-- your app branding color for the app bar --> <item name=“colorPrimary">@color/primary</item> <!-- darker variant for the status bar and contextual app bars --> <item name=“colorPrimaryDark">@color/primary_dark</item> <!-- theme UI controls like checkboxes and text fields --> <item name="colorAccent">@color/accent</item> </style>

Page 36: Android Develpment vol. 3, MFF UK, 2015

The Color Palette with AppCompat

<!-- AppCompat variant --><style name="AppTheme" parent=“Theme.AppCompat"> <!-- your app branding color for the app bar --> <item name=“colorPrimary">@color/primary</item> <!-- darker variant for the status bar and contextual app bars --> <item name=“colorPrimaryDark">@color/primary_dark</item> <!-- theme UI controls like checkboxes and text fields --> <item name="colorAccent">@color/accent</item> </style>

Page 37: Android Develpment vol. 3, MFF UK, 2015

The Color Palette

Page 38: Android Develpment vol. 3, MFF UK, 2015

Toolbar

Page 39: Android Develpment vol. 3, MFF UK, 2015

Toolbar

• generalization of action bar

• main Android navigation element

Page 40: Android Develpment vol. 3, MFF UK, 2015

Toolbar

• AppCompatActivity

compile 'com.android.support:appcompat-v7:22.0.0'

• inherit styles from Theme.AppCompat

• for inflating views for action bar use getSupportActionBar().getThemedContext()

Page 41: Android Develpment vol. 3, MFF UK, 2015

Toolbar

<android.support.v7.widget.Toolbar android:id="@+id/my_toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize" android:background="?attr/colorPrimary" />

Page 42: Android Develpment vol. 3, MFF UK, 2015

Toolbar

@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(toolbar);}

Page 43: Android Develpment vol. 3, MFF UK, 2015

Toolbar• standalone mode

• setSupportActionBar(toolbar);

Page 44: Android Develpment vol. 3, MFF UK, 2015

CardView

Page 45: Android Develpment vol. 3, MFF UK, 2015

CardView

• showing information inside cards with consistent look

compile 'com.android.support:cardview-v7:22.0.0'

Page 46: Android Develpment vol. 3, MFF UK, 2015

CardView

Page 47: Android Develpment vol. 3, MFF UK, 2015

CardView<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/card_view" android:layout_gravity="center" android:layout_width="200dp" android:layout_height="200dp" card_view:cardCornerRadius="16dp"> … </android.support.v7.widget.CardView>

Page 48: Android Develpment vol. 3, MFF UK, 2015

Elevation

Page 49: Android Develpment vol. 3, MFF UK, 2015

Elevation

Page 50: Android Develpment vol. 3, MFF UK, 2015

Elevation

android:elevation=“4dp”

view.setElevation(elevation);

Page 51: Android Develpment vol. 3, MFF UK, 2015

Transition

Page 52: Android Develpment vol. 3, MFF UK, 2015

Transition Animation

• since API level 21

• in styles.xml

<item name=“android:windowEnterTransition"> @android:transition/explode</item> <item name=“android:windowExitTransition"> @android:transition/explode</item>

Page 53: Android Develpment vol. 3, MFF UK, 2015

Transition

public class MyActivity1 extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { // enable transitions before content is added getWindow().requestFeature( Window.FEATURE_CONTENT_TRANSITIONS); super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_1); … }}

Page 54: Android Develpment vol. 3, MFF UK, 2015

Transition

btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getWindow().setExitTransition(new Explode()); Intent intent = new Intent(MyActivity1.this, MyActivity2.class); startActivity(intent, ActivityOptions .makeSceneTransitionAnimation(MyActivity1.this) .toBundle()); } });

Page 55: Android Develpment vol. 3, MFF UK, 2015

Shared Element Transition

• enable window content transitions

• transition for shared element

• define shared element with android:transitionName

• in both layouts

• ActivityOptions.makeSceneTransitionAnimation()

Page 56: Android Develpment vol. 3, MFF UK, 2015

Shared Element

Transition

Page 57: Android Develpment vol. 3, MFF UK, 2015

Ripple

Page 58: Android Develpment vol. 3, MFF UK, 2015

Ripple

• RippleDrawable

• set as view background

Page 59: Android Develpment vol. 3, MFF UK, 2015

Ripple

Page 60: Android Develpment vol. 3, MFF UK, 2015

Ripple

<ripple android:color="#ffff0000" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@android:color/white" /></ripple>

Page 61: Android Develpment vol. 3, MFF UK, 2015

Dynamic color

Page 62: Android Develpment vol. 3, MFF UK, 2015

State List Animator

Page 63: Android Develpment vol. 3, MFF UK, 2015

State List Animator

• materials raise up to meet your finger

• android:stateListAnimator="@anim/raise"

Page 64: Android Develpment vol. 3, MFF UK, 2015

State List Animator

… and ripple

Page 65: Android Develpment vol. 3, MFF UK, 2015

State List Animator<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true" android:state_pressed="true"> <objectAnimator android:duration="@android:integer/config_shortAnimTime" android:propertyName="translationZ" android:valueTo="10dp" android:valueType="floatType" /> </item> <item> <objectAnimator android:duration="@android:integer/config_shortAnimTime" android:propertyName="translationZ" android:valueTo="0dp" android:valueType="floatType" /> </item> </selector>

Page 66: Android Develpment vol. 3, MFF UK, 2015

State List Animator<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true" android:state_pressed="true"> <objectAnimator android:duration="@android:integer/config_shortAnimTime" android:propertyName="translationZ" android:valueTo="10dp" android:valueType="floatType" /> </item> <item> <objectAnimator android:duration="@android:integer/config_shortAnimTime" android:propertyName="translationZ" android:valueTo="0dp" android:valueType="floatType" /> </item> </selector>

Page 67: Android Develpment vol. 3, MFF UK, 2015

State List Animator<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true" android:state_pressed="true"> <objectAnimator android:duration="@android:integer/config_shortAnimTime" android:propertyName="translationZ" android:valueTo="10dp" android:valueType="floatType" /> </item> <item> <objectAnimator android:duration="@android:integer/config_shortAnimTime" android:propertyName="translationZ" android:valueTo="0dp" android:valueType="floatType" /> </item> </selector>

Page 68: Android Develpment vol. 3, MFF UK, 2015

Floating Action Button

Page 69: Android Develpment vol. 3, MFF UK, 2015

Exercise

4. Check the code of FAB in project.

Page 70: Android Develpment vol. 3, MFF UK, 2015

UX Design Patterns

Page 71: Android Develpment vol. 3, MFF UK, 2015

Pull-to-Refresh

Page 72: Android Develpment vol. 3, MFF UK, 2015

Pull-to-Refresh<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swipeContainer" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/lvItems" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop=“true" /> </android.support.v4.widget.SwipeRefreshLayout>

Page 73: Android Develpment vol. 3, MFF UK, 2015

Pull-to-Refresh<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swipeContainer" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/lvItems" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop=“true" /> </android.support.v4.widget.SwipeRefreshLayout>

Page 74: Android Develpment vol. 3, MFF UK, 2015

Pull-to-Refresh

Page 75: Android Develpment vol. 3, MFF UK, 2015

Exercise

5. Add Pull-to-Refresh for account list.

Page 76: Android Develpment vol. 3, MFF UK, 2015

Swipe-to-dismiss

Page 77: Android Develpment vol. 3, MFF UK, 2015

Swipe-to-dismiss• dismiss list item by swiping left or right

Page 78: Android Develpment vol. 3, MFF UK, 2015

Swipe-to-dismiss with Undo

Page 79: Android Develpment vol. 3, MFF UK, 2015

Snackbar

Page 80: Android Develpment vol. 3, MFF UK, 2015

Snackbar

• Toast-like message

• they provide action

Page 81: Android Develpment vol. 3, MFF UK, 2015

Snackbar

Snackbar snackbar = Snackbar.make(coordinatorLayout, “This is a Snackbar", Snackbar.LENGTH_LONG);

snackbar.show();

Page 82: Android Develpment vol. 3, MFF UK, 2015

SnackbarSnackbar snackbar = Snackbar .make(coordinatorLayout, "Message was deleted”, Snackbar.LENGTH_LONG) .setAction("UNDO", new View.OnClickListener() { @Override public void onClick(View view) { // do something } }); snackbar.show();

Page 83: Android Develpment vol. 3, MFF UK, 2015

Exercise

6. Show a snackbar when we display account detail.

Page 84: Android Develpment vol. 3, MFF UK, 2015

Software Design Patterns

Page 85: Android Develpment vol. 3, MFF UK, 2015

Dependency Injection

Page 86: Android Develpment vol. 3, MFF UK, 2015

Service Locator

Page 87: Android Develpment vol. 3, MFF UK, 2015

Service Locator

• via Context

Object context.getSystemService(String)

Page 88: Android Develpment vol. 3, MFF UK, 2015

Service Locatorpublic class MyApplication extends Application { private MyManager mMyManager; @Override public Object getSystemService(String name) { if (MyManager.class.getName().equals(name)) { if (mMyManager == null) { mMyManager = new MyManager(); } return mMyManager; } return super.getSystemService(name); } }

Page 89: Android Develpment vol. 3, MFF UK, 2015

Service Locatorpublic class MyApplication extends Application { private MyManager mMyManager; @Override public Object getSystemService(String name) { if (MyManager.class.getName().equals(name)) { if (mMyManager == null) { mMyManager = new MyManager(); } return mMyManager; } return super.getSystemService(name); }}

Page 90: Android Develpment vol. 3, MFF UK, 2015

Service Locatorpublic class MyApplication extends Application { private MyManager mMyManager; @Override public Object getSystemService(String name) { if (MyManager.class.getName().equals(name)) { if (mMyManager == null) { mMyManager = new MyManager(); } return mMyManager; } return super.getSystemService(name); }}

Page 91: Android Develpment vol. 3, MFF UK, 2015

Service Locator

MyManager myManager = (MyManager) context

.getApplicationContext()

.getSystemService(MyManager.class.getName());

Page 92: Android Develpment vol. 3, MFF UK, 2015

Service Locator

• always use application context

• can’t be used in libraries

• you usually don’t control the application object

Page 93: Android Develpment vol. 3, MFF UK, 2015

Exercise

7. Use service locator to access API.

Page 94: Android Develpment vol. 3, MFF UK, 2015

Dagger 2

Page 95: Android Develpment vol. 3, MFF UK, 2015

Dagger 2• by Google

• evolution of Dagger 1 (by Square)

• no reflection

• generated code in compile time

• constructor and field injection

Page 96: Android Develpment vol. 3, MFF UK, 2015

Dagger 2

• Constructor injection

private ProviderC mProviderC; private ProviderD mProviderD; @Inject public ProviderA(ProviderC providerC, ProviderD providerD) { mProviderC = providerC; mProviderD = providerD; }

Page 97: Android Develpment vol. 3, MFF UK, 2015

Dagger 2• Field injection

public class MainActivity extends AppCompatActivity { @Inject ProviderA mProviderA; @Inject ProviderB mProviderB;

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((MyApp) getApplication()).getAppComponent() .injectMainActivity(this); }}

Page 98: Android Develpment vol. 3, MFF UK, 2015

Dagger 2

• prefer constructor injection wherever possible

• you can test the unit in isolation

• providing mocks is a piece of cake

Page 99: Android Develpment vol. 3, MFF UK, 2015

Dagger 2• Some catches when using field injection

• Construct the whole component

• Implicit provisions doesn’t support overrides!!

public class ProviderA { … @Inject public ProviderA(ProviderC providerC) { mProviderC = providerC; }}

Page 100: Android Develpment vol. 3, MFF UK, 2015

Dagger 2• Some catches when using field injection

• Make explicit provisions @Module public class AppModule { @Provides @Singleton ProviderB provideProvider2(ProviderC providerC) { return new ProviderB(providerC); } @Provides ProviderD provideProvider4() { return new ProviderD(); } }

• Beware marking constructors with @Inject when providing explicitly

• may create unwanted double provision

Page 101: Android Develpment vol. 3, MFF UK, 2015

Exercise

8. Use Dagger 2 to access server API.

Page 102: Android Develpment vol. 3, MFF UK, 2015

View Holder

Page 103: Android Develpment vol. 3, MFF UK, 2015

View Holderstatic class ViewHolder { TextView txtName; TextView txtDescription; public ViewHolder(View view) { txtName = (TextView) view.findViewById(R.id.txt_name); txtDesc = (TextView) view.findViewById(R.id.txt_desc); }}

view.setTag(holder);

ViewHolder holder = (ViewHolder) view.getTag();

Page 104: Android Develpment vol. 3, MFF UK, 2015

View Holderstatic class ViewHolder { TextView txtName; TextView txtDescription; public ViewHolder(View view) { txtName = (TextView) view.findViewById(R.id.txt_name); txtDesc = (TextView) view.findViewById(R.id.txt_desc); }}

view.setTag(holder);

ViewHolder holder = (ViewHolder) view.getTag();

Page 105: Android Develpment vol. 3, MFF UK, 2015

View Holderstatic class ViewHolder { TextView txtName; TextView txtDescription; public ViewHolder(View view) { txtName = (TextView) view.findViewById(R.id.txt_name); txtDesc = (TextView) view.findViewById(R.id.txt_desc); }}

view.setTag(holder);

ViewHolder holder = (ViewHolder) view.getTag();

Page 106: Android Develpment vol. 3, MFF UK, 2015

Exercise

9. Check code of RecyclerView.Adapter. And finish RecyclerView.Adapter for repositories in RepoFragment.

Page 107: Android Develpment vol. 3, MFF UK, 2015

Useful Android Libraries

Page 108: Android Develpment vol. 3, MFF UK, 2015

Event Bus

Page 109: Android Develpment vol. 3, MFF UK, 2015

Event Bus

• no direct support

• library or custom implementation

• alternative to local broadcasts

Page 110: Android Develpment vol. 3, MFF UK, 2015

Event Bus

• Otto (http://square.github.io/otto)

Bus bus = new Bus(); bus.register(this);

bus.unregister(this);

@Subscribe public void wasLoggedOut(LogoutEvent event) { // do some logout action }

Page 111: Android Develpment vol. 3, MFF UK, 2015

Event Bus

bus.post(new LogoutEvent(LogoutEvent.LogoutType.MANUAL));

@Produce public LogoutEvent produceLogoutEvent() { return new LogoutEvent(LogoutEvent.LogoutType.MANUAL); }

Page 112: Android Develpment vol. 3, MFF UK, 2015

Exercise

10.Notify AccountFragment about DB changes.

Page 113: Android Develpment vol. 3, MFF UK, 2015

Image Loaders

Page 114: Android Develpment vol. 3, MFF UK, 2015

Image Loaders

• For loading images from and URL into ImageView

Page 115: Android Develpment vol. 3, MFF UK, 2015

Image Loaders

• Picasso

• http://square.github.io/picasso/

Picasso.with(context) .load(URL) .into(imageView);

Page 116: Android Develpment vol. 3, MFF UK, 2015

Image Loaders

• Glide

• https://github.com/bumptech/glide

• Android-Universal-Image-Loader

• https://github.com/nostra13/Android-Universal-Image-Loader

Page 117: Android Develpment vol. 3, MFF UK, 2015

Exercise

11.Load avatar image of an account.

Page 118: Android Develpment vol. 3, MFF UK, 2015

Other Useful Libraries

• ButterKnife

• RxJava / RxAndroid

• Mortar

Page 119: Android Develpment vol. 3, MFF UK, 2015

Exercise

12.Use ButterKnife in RepoFragment.

Page 120: Android Develpment vol. 3, MFF UK, 2015

Useful Libraries - for unit testing

Page 121: Android Develpment vol. 3, MFF UK, 2015

Thank You