Slide 1

Slide 1 text

A Material Design Guide for Android Developers Yash Prabhu @yashvprabhu github.com/yprabhu dramafever.com

Slide 2

Slide 2 text

Why?

Slide 3

Slide 3 text

What is Material Design?

Slide 4

Slide 4 text

Skeuomorphism Flat Material @yashvprabhu

Slide 5

Slide 5 text

Terminology Screen Size - small, normal, large, xlarge Screen density - ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi Orientation - landscape/portrait Resolution - physical pixel Density Independent Pixel - virtual pixel px = dp * (dpi / 160) Example: 240 dp screen, 1 dp = 1.5 px

Slide 6

Slide 6 text

Style Layout Animation Components Patterns

Slide 7

Slide 7 text

Style

Slide 8

Slide 8 text

Color

Slide 9

Slide 9 text

Color Theme

Slide 10

Slide 10 text

Color Theme Typography

Slide 11

Slide 11 text

Color Theme Typography Imagery

Slide 12

Slide 12 text

Color Primary 500 Primary Dark 700 Accent 500 https://material.google.com/style/color .html

Slide 13

Slide 13 text

Material Palette materialpalette.com

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Theme Theme.Holo & Theme.AppCompat

Slide 16

Slide 16 text

How do I apply a theme? <item name="colorPrimary">@color/color_primary</item> <item name="colorPrimaryDark">@color/color_primary_dark</item> <item name="colorAccent">@color/color_accent</item> <item name="android:windowBackground"> @color/window_background </item>

Slide 17

Slide 17 text

Color & Theme Theme.AppCompat compile "com.android.support:appcompat-v7:2 4.2.1" http://developer.android.com/training/ material/theme.html#StatusBar @yashvprabhu

Slide 18

Slide 18 text

Typography Use scaled pixels (sp) Min 12sp

Slide 19

Slide 19 text

Custom Fonts Google Fonts fonts.google.com Chris Jenkins’ Calligraphy Library github.com/chrisjenx/Calligraphy @yashvprabhu

Slide 20

Slide 20 text

Custom Fonts // Programmatically defining typefaces TextView tv= (TextView) findViewById(R.id.custom); Typeface face=Typeface.createFromAsset(getAssets(), "fonts/Verdana.ttf"); tv.setTypeface(face); // Using Chris Jenkins’ Calligraphy library

Slide 21

Slide 21 text

Imagery - Palette API For extracting colors from an image compile "com.android.support:palette-v7:24.2.1" @yashvprabhu

Slide 22

Slide 22 text

Palette API Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.chicago); if (myBitmap != null && !myBitmap.isRecycled()) { Palette.from(myBitmap).generate(paletteListener); }

Slide 23

Slide 23 text

Palette API Palette.PaletteAsyncListener paletteListener = new Palette.PaletteAsyncListener(){ @Override public void onGenerated(Palette palette) { int defColor = 0x000000; int vibrant = palette.getVibrantColor(defColor); int vibrantLight = palette.getLightVibrantColor(defColor); int vibrantDark = palette.getDarkVibrantColor(defColor); int muted = palette.getMutedColor(defaultColor); int mutedLight = palette.getLightMutedColor(defaultColor); int mutedDark = palette.getDarkMutedColor(defaultColor); }}

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Imagery - Raster & Vector Specific number of pixels Uses math to draw shapes using points, lines and curves @yashvprabhu

Slide 26

Slide 26 text

Imagery - Adding Vector assets

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Imagery - Scalable Vector Graphic (svg)

Slide 29

Slide 29 text

Imagery - Adding Vector Assets

Slide 30

Slide 30 text

Layout

Slide 31

Slide 31 text

Keylines & Grids

Slide 32

Slide 32 text

Keylines & Grids Device Metrics

Slide 33

Slide 33 text

Keylines & Grids Device Metrics Responsive UI

Slide 34

Slide 34 text

Keylines & Grids Device Metrics Responsive UI Breakpoints

Slide 35

Slide 35 text

Keylines & Grids 8dp baseline grid 4dp typography grid

Slide 36

Slide 36 text

Design Testing apps Keyline Pushing Material Cue @yashvprabhu

Slide 37

Slide 37 text

Device metrics design.google.com/devices

Slide 38

Slide 38 text

Responsive UI res/layout/main_activity.xml # For handsets res/layout-sw600dp/main_activity.xml # For tablets

Slide 39

Slide 39 text

Responsive UI layout-w1024dp/show_activity.xml

Slide 40

Slide 40 text

Breakpoints @yashvprabhu

Slide 41

Slide 41 text

Animation

Slide 42

Slide 42 text

Surface Reaction

Slide 43

Slide 43 text

Surface Reaction Shadow

Slide 44

Slide 44 text

Surface Reaction Ripples (indicates touch input) ?android:attr/selectableItemBackground ?android:attr/selectableItemBackgroundBor derless android:colorControlHighlight

Slide 45

Slide 45 text

Shadow Elevation (lifts to your touch) ● Resting 2dp ● Raised 8dp

Slide 46

Slide 46 text

Components

Slide 47

Slide 47 text

Button

Slide 48

Slide 48 text

Button Card

Slide 49

Slide 49 text

Button Card Grid & List

Slide 50

Slide 50 text

Button Card Grid & List Snackbar

Slide 51

Slide 51 text

Demo github.com/yprabhu/materialworld Forked from github.com/chrisbanes/cheesesquare @yashvprabhu

Slide 52

Slide 52 text

app/build.gradle compile "com.android.support:palette-v7:24.2.1" compile "com.android.support:design:24.2.1" compile "com.android.support:appcompat-v7:24.2.1" compile "com.android.support:recyclerview-v7:24.2.1" compile "com.android.support:cardview-v7:24.2.1"

Slide 53

Slide 53 text

Buttons Flat Raised FAB

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Post-21 (Lollipop)

Slide 56

Slide 56 text

Pre-21 (Lollipop) workaround

Slide 57

Slide 57 text

FloatingActionButton (FAB) Default Elevation: 6 dp Normal size: 56 dp, Mini size: 40 dp

Slide 58

Slide 58 text

FAB Widget

Slide 59

Slide 59 text

Card compile 'com.android.support:cardview-v7:24.2.1' Resting elevation: 2dp Raised elevation: 8dp

Slide 60

Slide 60 text

CardView

Slide 61

Slide 61 text

Lists & Grids compile 'com.android.support:recyclerview-v7:24.2.1'

Slide 62

Slide 62 text

RecyclerView - Under the hood Recycler View Layout Manager Adapter Dataset Item Animator @yashvprabhu

Slide 63

Slide 63 text

Add RecyclerView to your layout

Slide 64

Slide 64 text

Add RecyclerView item

Slide 65

Slide 65 text

Set LayoutManager & Adapter // Set either of these layout managers recyclerView.setLayoutManager(new LinearLayoutManager(context)); recyclerView.setLayoutManager(new GridLayoutManager(context, GRID_SPAN)); recyclerView.setLayoutManager(new StaggeredGridLayoutManager(STAGGERED_GRID_SPAN, StaggeredGridLayoutManager.VERTICAL)); // Set adapter on recycler view recyclerView.setAdapter(new GridRecyclerViewAdapter(activity);

Slide 66

Slide 66 text

Snackbar ● Swipeable, can have actions ● Single-line snackbar height: 48dp ● Multi-line snackbar height: 80dp ● Text: Roboto Regular 14sp ● Action button: Roboto Med 14sp, all-caps ● Default background fill: #323232 100%

Slide 67

Slide 67 text

Snackbar Snackbar.make(view, "Archived", Snackbar.LENGTH_SHORT) .setAction(R.string.undo_string, new UndoListener()); .show();

Slide 68

Slide 68 text

Patterns

Slide 69

Slide 69 text

@yashvprabhu

Slide 70

Slide 70 text

Appbar, Toolbar, ActionBar? @yashvprabhu

Slide 71

Slide 71 text

Appbar, Toolbar, ActionBar? @yashvprabhu

Slide 72

Slide 72 text

Common Pattern: Tabs @yashvprabhu

Slide 73

Slide 73 text

CoordinatorLayout AppBarLayout ToolBarLayout TabLayout ViewPager FloatingActionButton @yashvprabhu

Slide 74

Slide 74 text

Scrolling Behaviors CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto" Toolbar app:layout_scrollFlags="scroll|enterAlways|snap" ViewPager app:layout_behavior="@string/appbar_scrolling_view_behavior" @yashvprabhu

Slide 75

Slide 75 text

Common Pattern: Flexible space with image @yashvprabhu

Slide 76

Slide 76 text

Coordinator Layout AppBarLayout CollapsingToolbarLayout NestedScrollView FloatingActionButton ImageView Toolbar LinearLayout CardView Button @yashvprabhu

Slide 77

Slide 77 text

Scrolling Behaviors CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto" CollapsingToolbarLayout app:layout_scrollFlags="scroll|exitUntilCollapsed" NestedScrollView app:layout_behavior="@string/appbar_scrolling_view_behavior" @yashvprabhu

Slide 78

Slide 78 text

Style Layout Animation Components Patterns

Slide 79

Slide 79 text

Image Credit Windows Phone - Flat design iOS Phone - Skeuomorphic design Android - Material Design Android Design Docs Android Developer docs City images @yashvprabhu

Slide 80

Slide 80 text

Resources Udacity - Material Design for Android Developers Android Developer Docs - Material Design Google Material Design Guidelines Plaid app by Nick Butcher MaterialWorld (Cheesesquare by Chris Banes) Tutorials: Material Doc, Codepath, Google IO 2016 Codelabs @yashvprabhu

Slide 81

Slide 81 text

A Practical Guide to Material Design Implementation Yash Prabhu @yashvprabhu github.com/yprabhu dramafever.com We’re hiring! www.jsco.re/8ns9