Slide 1

Slide 1 text

ConstraintLayout 2.0 Let’s use the new things! Nicolas Roard @camaelon John Hoford @johnhoford

Slide 2

Slide 2 text

Let’s use the new things! Nicolas Roard @camaelon John Hoford @johnhoford MotionLayout

Slide 3

Slide 3 text

{ 360 | AnDev } 2018 ConstraintLayout 2.0

Slide 4

Slide 4 text

{ 360 | AnDev } 2018 ConstraintLayout 2.0 ★ Layout

Slide 5

Slide 5 text

{ 360 | AnDev } 2018 ConstraintLayout 2.0 ★ Layout ★ Helpers

Slide 6

Slide 6 text

{ 360 | AnDev } 2018 ConstraintLayout 2.0 ★ Layout ★ Helpers ★ Rendering

Slide 7

Slide 7 text

{ 360 | AnDev } 2018 ConstraintLayout 2.0 ★ Layout ★ Helpers ★ Rendering ★ Live Resize

Slide 8

Slide 8 text

{ 360 | AnDev } 2018 ConstraintLayout 2.0 ★ Layout ★ Helpers ★ Rendering ★ Live Resize ★ Motion

Slide 9

Slide 9 text

{ 360 | AnDev } 2018 ConstraintLayout 2.0 ★ Layout ★ Helpers ★ Rendering ★ Live Resize ★ Motion ★ API

Slide 10

Slide 10 text

{ 360 | AnDev } 2018 ConstraintLayout 2.0 ★ Layout ★ Helpers ★ Rendering ★ Live Resize ★ Motion ★ API

Slide 11

Slide 11 text

{ 360 | AnDev } 2018 MotionLayout

Slide 12

Slide 12 text

{ 360 | AnDev } 2018 MotionLayout ConstraintLayout ^

Slide 13

Slide 13 text

{ 360 | AnDev } 2018 MotionLayout: Why ★ Why ★ Audience ★ What can it do

Slide 14

Slide 14 text

{ 360 | AnDev } 2018 Animation Types Animated content Transition Layouts Motion Property Animation

Slide 15

Slide 15 text

{ 360 | AnDev } 2018 Animation Types Animated content Transition Layouts Motion Lottie, Kyrie, Animated Vector Drawable, GIFs, etc. TransitionManager CoordinatorLayout Property Animation Property animation framework (code)

Slide 16

Slide 16 text

{ 360 | AnDev } 2018 MotionLayout Animated content Transition Layouts Motion Lottie, Kyrie, Animated Vector Drawable, GIFs, etc. TransitionManager CoordinatorLayout Property Animation Property animation framework (code)

Slide 17

Slide 17 text

{ 360 | AnDev } 2018 It’s Declarative

Slide 18

Slide 18 text

{ 360 | AnDev } 2018 Declarative Approach ★ Better & Easier model ★ We can build tooling

Slide 19

Slide 19 text

{ 360 | AnDev } 2018 Declarative Approach ★ Better & Easier model ★ We can build tooling

Slide 20

Slide 20 text

{ 360 | AnDev } 2018 Key Concepts ★ Transition ★ Events ★ Keyframes ★ Motion

Slide 21

Slide 21 text

{ 360 | AnDev } 2018 Transitions

Slide 22

Slide 22 text

{ 360 | AnDev } 2018 ConstraintSet ★ Encapsulate all the rules for a layout ★ You can apply ConstraintSet to an existing layout ★ You can switch between multiple ConstraintSets ★ With TransitionManager, basic animation capabilities

Slide 23

Slide 23 text

{ 360 | AnDev } 2018 Start End Seekable Transition Start ConstraintSet End ConstraintSet Interpolation

Slide 24

Slide 24 text

{ 360 | AnDev } 2018

Slide 25

Slide 25 text

{ 360 | AnDev } 2018

Slide 26

Slide 26 text

Slide 27

Slide 27 text

Slide 28

Slide 28 text

Slide 29

Slide 29 text

Slide 30

Slide 30 text

motion:constraintSetStart="@+id/start" motion:constraintSetEnd="@+id/end" motion:duration="1000">

Slide 31

Slide 31 text

motion:constraintSetStart="@+id/start" motion:constraintSetEnd="@+id/end" motion:duration="1000">

Slide 32

Slide 32 text

motion:constraintSetStart="@+id/start" motion:constraintSetEnd="@+id/end" motion:duration="1000">

Slide 33

Slide 33 text

android:layout_marginStart="8dp" motion:layout_constraintBottom_toBottomOf="parent" motion:layout_constraintStart_toStartOf="parent" motion:layout_constraintTop_toTopOf="parent" />

Slide 34

Slide 34 text

android:layout_marginStart="8dp" motion:layout_constraintBottom_toBottomOf="parent" motion:layout_constraintStart_toStartOf="parent" motion:layout_constraintTop_toTopOf="parent" />

Slide 35

Slide 35 text

android:layout_marginStart="8dp" motion:layout_constraintBottom_toBottomOf="parent" motion:layout_constraintStart_toStartOf="parent" motion:layout_constraintTop_toTopOf="parent" />

Slide 36

Slide 36 text

Slide 37

Slide 37 text

android:layout_height="match_parent">

Slide 38

Slide 38 text

android:layout_height="match_parent">

Slide 39

Slide 39 text

class BasicTransitionActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.motion) run.setOnClickListener { motionLayout.transitionToEnd() } } }

Slide 40

Slide 40 text

{ 360 | AnDev } 2018

Slide 41

Slide 41 text

{ 360 | AnDev } 2018

Slide 42

Slide 42 text

Slide 43

Slide 43 text

Slide 44

Slide 44 text

Slide 45

Slide 45 text

xmlns:motion="http://schemas.android.com/apk/res-auto">

Slide 46

Slide 46 text

xmlns:motion="http://schemas.android.com/apk/res-auto">

Slide 47

Slide 47 text

{ 360 | AnDev } 2018

Slide 48

Slide 48 text

{ 360 | AnDev } 2018

Slide 49

Slide 49 text

{ 360 | AnDev } 2018 MotionLayout XML attributes ★ app:layoutDescription=”reference” ★ app:applyMotionScene=”boolean” [ default = true ] ★ app:showPaths=”boolean” [ default = false] ★ app:progress=”float” ★ app:currentState=”reference”

Slide 50

Slide 50 text

{ 360 | AnDev } 2018 Interpolated Attributes ★ Position, Dimensions ★ Visibility & Alpha ★ Translation, Rotation, Scale, Elevation ★ Custom attributes

Slide 51

Slide 51 text

{ 360 | AnDev } 2018 Custom Attributes ★ Extension to ConstraintSet ★ Define values for any attribute ★ Specify the type ★ Specify the setter name string color integer float dimension boolean

Slide 52

Slide 52 text

Slide 53

Slide 53 text

{ 360 | AnDev } 2018 Utilities

Slide 54

Slide 54 text

{ 360 | AnDev } 2018 Utilities ★ MockView

Slide 55

Slide 55 text

{ 360 | AnDev } 2018 Utilities ★ MockView

Slide 56

Slide 56 text

{ 360 | AnDev } 2018 Utilities ★ MockView

Slide 57

Slide 57 text

{ 360 | AnDev } 2018 Utilities ★ MockView ★ ImageFilterView : Contrast, Saturation, Warmth, Crossfade

Slide 58

Slide 58 text

{ 360 | AnDev } 2018

Slide 59

Slide 59 text

{ 360 | AnDev } 2018

Slide 60

Slide 60 text

Slide 61

Slide 61 text

Slide 62

Slide 62 text

motion:touchAnchorSide="right" />

Slide 63

Slide 63 text

motion:touchAnchorSide="right" />

Slide 64

Slide 64 text

Slide 65

Slide 65 text

Slide 66

Slide 66 text

{ 360 | AnDev } 2018 Transition API ★ transitionToEnd() ★ transitionToStart() ★ transitionToState(int state) ★ setProgress(float value) [0 .. 1]

Slide 67

Slide 67 text

{ 360 | AnDev } 2018 Events

Slide 68

Slide 68 text

{ 360 | AnDev } 2018 Events ★ TransitionListener ★ OnClick ★ OnSwipe

Slide 69

Slide 69 text

{ 360 | AnDev } 2018 TransitionListener

Slide 70

Slide 70 text

public interface TransitionListener { void onTransitionChange(MotionLayout motionLayout, int startId, int endId, float progress); void onTransitionCompleted(MotionLayout motionLayout, int currentId); }

Slide 71

Slide 71 text

{ 360 | AnDev } 2018 OnSwipe

Slide 72

Slide 72 text

Slide 73

Slide 73 text

Slide 74

Slide 74 text

dragDirection dragUp dragDown dragRight dragLeft touchAnchorId touchAnchorSide top bottom left right

Slide 75

Slide 75 text

OnSwipe Create your animation OnSwipe “plays” it

Slide 76

Slide 76 text

OnSwipe Create your animation OnSwipe “plays” it

Slide 77

Slide 77 text

OnSwipe: Top touchAnchorSide : TOP

Slide 78

Slide 78 text

OnSwipe: Top touchAnchorSide : TOP

Slide 79

Slide 79 text

OnSwipe: Right touchAnchorSide : RIGHT

Slide 80

Slide 80 text

OnSwipe: Right touchAnchorSide : RIGHT

Slide 81

Slide 81 text

OnSwipe: Bottom touchAnchorSide : BOTTOM

Slide 82

Slide 82 text

OnSwipe: Bottom touchAnchorSide : BOTTOM

Slide 83

Slide 83 text

OnSwipe: Left touchAnchorSide : LEFT

Slide 84

Slide 84 text

OnSwipe: Left touchAnchorSide : LEFT

Slide 85

Slide 85 text

Touch Up / Release Takes in account velocity Choose a continuous velocity curve to reach the endpoints with a velocity of zero

Slide 86

Slide 86 text

Touch Up / Release Takes in account velocity Choose a continuous velocity curve to reach the endpoints with a velocity of zero

Slide 87

Slide 87 text

{ 360 | AnDev } 2018 OnClick

Slide 88

Slide 88 text

mode • transitionToEnd • toggle • transitionToStart • jumpToEnd • jumpToStart OnClick

Slide 89

Slide 89 text

mode • transitionToEnd • toggle • transitionToStart • jumpToEnd • jumpToStart OnClick

Slide 90

Slide 90 text

{ 360 | AnDev } 2018 Keyframes

Slide 91

Slide 91 text

{ 360 | AnDev } 2018 Keyframe a rendez-vous in time

Slide 92

Slide 92 text

{ 360 | AnDev } 2018 Keyframes ★ Position ★ Attributes ★ Cycles ★ …and more

Slide 93

Slide 93 text

{ 360 | AnDev } 2018 Position

Slide 94

Slide 94 text

KeyFrameSet

Slide 95

Slide 95 text

KeyFrameSet

Slide 96

Slide 96 text

KeyFrameSet

Slide 97

Slide 97 text

KeyFrameSet

Slide 98

Slide 98 text

KeyFrameSet

Slide 99

Slide 99 text

KeyFrameSet

Slide 100

Slide 100 text

KeyFrameSet

Slide 101

Slide 101 text

KeyFrameSet

Slide 102

Slide 102 text

{ 360 | AnDev } 2018 Coordinate Systems

Slide 103

Slide 103 text

{ 360 | AnDev } 2018

Slide 104

Slide 104 text

{ 360 | AnDev } 2018

Slide 105

Slide 105 text

{ 360 | AnDev } 2018 Start End

Slide 106

Slide 106 text

{ 360 | AnDev } 2018 parentRelative 0 X Y

Slide 107

Slide 107 text

{ 360 | AnDev } 2018 deltaRelative Y X

Slide 108

Slide 108 text

{ 360 | AnDev } 2018 pathRelative X Y

Slide 109

Slide 109 text

{ 360 | AnDev } 2018 Attributes

Slide 110

Slide 110 text

KeyFrameSet

Slide 111

Slide 111 text

KeyFrameSet

Slide 112

Slide 112 text

KeyFrameSet

Slide 113

Slide 113 text

KeyFrameSet

Slide 114

Slide 114 text

KeyAttributes support motion:transitionEasing motion:curveFit android:visibility android:alpha android:elevation android:rotation android:rotationX android:rotationY android:scaleX android:scaleY android:translationX android:translationY android:translationZ motion:transitionPathRotate motion:progress + Custom Attributes

Slide 115

Slide 115 text

{ 360 | AnDev } 2018 Cycles

Slide 116

Slide 116 text

KeyCycle

Slide 117

Slide 117 text

KeyCycle

Slide 118

Slide 118 text

{ 360 | AnDev } 2018 Code KeyCycle Value (attributes)

Slide 119

Slide 119 text

{ 360 | AnDev } 2018 Code KeyCycle Period

Slide 120

Slide 120 text

KeyCycle

Slide 121

Slide 121 text

KeyCycle

Slide 122

Slide 122 text

{ 360 | AnDev } 2018 Motion

Slide 123

Slide 123 text

{ 360 | AnDev } 2018 Motion ★ CoordinatorLayout ★ DrawerLayout ★ ViewPager ★ MotionLayout

Slide 124

Slide 124 text

{ 360 | AnDev } 2018 motion:progress

Slide 125

Slide 125 text

{ 360 | AnDev } 2018 Collapsible Toolbar (CoordinatorLayout)

Slide 126

Slide 126 text

{ 360 | AnDev } 2018

Slide 127

Slide 127 text

{ 360 | AnDev } 2018

Slide 128

Slide 128 text

{ 360 | AnDev } 2018 Create CollapsibleToolbar 0

Slide 129

Slide 129 text

class CollapsibleToolbar @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : MotionLayout(context, attrs, defStyleAttr), AppBarLayout.OnOffsetChangedListener { override fun onOffsetChanged(appBarLayout: AppBarLayout?, verticalOffset: Int) { progress = -verticalOffset / appBarLayout?.totalScrollRange?.toFloat()!! } override fun onAttachedToWindow() { super.onAttachedToWindow() (parent as? AppBarLayout)?.addOnOffsetChangedListener(this) } }

Slide 130

Slide 130 text

class CollapsibleToolbar @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : MotionLayout(context, attrs, defStyleAttr), AppBarLayout.OnOffsetChangedListener { override fun onOffsetChanged(appBarLayout: AppBarLayout?, verticalOffset: Int) { progress = -verticalOffset / appBarLayout?.totalScrollRange?.toFloat()!! } override fun onAttachedToWindow() { super.onAttachedToWindow() (parent as? AppBarLayout)?.addOnOffsetChangedListener(this) } }

Slide 131

Slide 131 text

{ 360 | AnDev } 2018 Replace CollapsingToolbarLayout 1

Slide 132

Slide 132 text

Slide 133

Slide 133 text

Slide 134

Slide 134 text

{ 360 | AnDev } 2018 Create a layout for the header 2

Slide 135

Slide 135 text

Slide 136

Slide 136 text

Slide 137

Slide 137 text

{ 360 | AnDev } 2018 Create a MotionScene 3

Slide 138

Slide 138 text

Slide 139

Slide 139 text

Slide 140

Slide 140 text

Slide 141

Slide 141 text

No content

Slide 142

Slide 142 text

No content

Slide 143

Slide 143 text

{ 360 | AnDev } 2018 DrawerLayout

Slide 144

Slide 144 text

{ 360 | AnDev } 2018

Slide 145

Slide 145 text

{ 360 | AnDev } 2018

Slide 146

Slide 146 text

class DrawerContent @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : MotionLayout(context, attrs, defStyleAttr), DrawerLayout.DrawerListener { override fun onDrawerStateChanged(newState: Int) { } override fun onDrawerSlide(drawerView: View, slideOffset: Float) { progress = slideOffset } override fun onDrawerClosed(drawerView: View) { } override fun onDrawerOpened(drawerView: View) { } override fun onAttachedToWindow() { super.onAttachedToWindow() (parent as? DrawerLayout)?.addDrawerListener(this) } }

Slide 147

Slide 147 text

class DrawerContent @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : MotionLayout(context, attrs, defStyleAttr), DrawerLayout.DrawerListener { override fun onDrawerStateChanged(newState: Int) { } override fun onDrawerSlide(drawerView: View, slideOffset: Float) { progress = slideOffset } override fun onDrawerClosed(drawerView: View) { } override fun onDrawerOpened(drawerView: View) { } override fun onAttachedToWindow() { super.onAttachedToWindow() (parent as? DrawerLayout)?.addDrawerListener(this) } }

Slide 148

Slide 148 text

class DrawerContent @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : MotionLayout(context, attrs, defStyleAttr), DrawerLayout.DrawerListener { override fun onDrawerStateChanged(newState: Int) { } override fun onDrawerSlide(drawerView: View, slideOffset: Float) { progress = slideOffset } override fun onDrawerClosed(drawerView: View) { } override fun onDrawerOpened(drawerView: View) { } override fun onAttachedToWindow() { super.onAttachedToWindow() (parent as? DrawerLayout)?.addDrawerListener(this) } }

Slide 149

Slide 149 text

{ 360 | AnDev } 2018 ViewPager

Slide 150

Slide 150 text

{ 360 | AnDev } 2018

Slide 151

Slide 151 text

{ 360 | AnDev } 2018

Slide 152

Slide 152 text

class ViewpagerHeader @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : MotionLayout(context, attrs, defStyleAttr), ViewPager.OnPageChangeListener { override fun onPageScrollStateChanged(state: Int) {} override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { var numPages = 3 progress = (position + positionOffset) / (numPages - 1) } override fun onPageSelected(position: Int) {} }

Slide 153

Slide 153 text

{ 360 | AnDev } 2018 MotionLayout

Slide 154

Slide 154 text

{ 360 | AnDev } 2018

Slide 155

Slide 155 text

{ 360 | AnDev } 2018

Slide 156

Slide 156 text

{ 360 | AnDev } 2018

Slide 157

Slide 157 text

{ 360 | AnDev } 2018

Slide 158

Slide 158 text

{ 360 | AnDev } 2018

Slide 159

Slide 159 text

Slide 160

Slide 160 text

Slide 161

Slide 161 text

motion:touchAnchorSide="bottom" motion:dragDirection="dragUp" />

Slide 162

Slide 162 text

Slide 163

Slide 163 text

Slide 164

Slide 164 text

Slide 165

Slide 165 text

Slide 166

Slide 166 text

Slide 167

Slide 167 text

Slide 168

Slide 168 text

Slide 169

Slide 169 text

{ 360 | AnDev } 2018

Slide 170

Slide 170 text

{ 360 | AnDev } 2018

Slide 171

Slide 171 text

{ 360 | AnDev } 2018 Documentation ★ Online Documentation: https://developer.android.com/reference/android/ support/constraint/motion/package-summary ★ Medium Articles: ★ Introduction to MotionLayout - Part I : http://bit.ly/2O4AmIz ★ Introduction to MotionLayout - Part II : http://bit.ly/2uPuWbw ★ Introduction to MotionLayout - Part III : http://bit.ly/2zRjCSj ★ https://github.com/googlesamples/android-ConstraintLayoutExamples

Slide 172

Slide 172 text

Thanks! Nicolas Roard @camaelon John Hoford @johnhoford