Slide 1

Slide 1 text

Transitions without Activities or Fragments @chris_h_codes

Slide 2

Slide 2 text

Transitions are slick

Slide 3

Slide 3 text

Transitions are slick

Slide 4

Slide 4 text

Transitions are slick

Slide 5

Slide 5 text

Not like this

Slide 6

Slide 6 text

Teleportation sucks

Slide 7

Slide 7 text

Teleportation sucks

Slide 8

Slide 8 text

Avoiding an ‘event boundary’

Slide 9

Slide 9 text

Avoiding an ‘event boundary’ ?

Slide 10

Slide 10 text

Walking through doorways causes forgetting: Situation models and experienced space ? * https://doi.org/10.3758/BF03193261

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

My Animator code works! Animator animator = ObjectAnimator.ofFloat(0f, 10f); button.animate() .alpha(0) .translationY(200);

Slide 14

Slide 14 text

Transitions are powerful • Easier to compose than traditional Animator code • Allow for shared elements

Slide 15

Slide 15 text

Learning about Transitions Developers Generate Scenes from Layouts Apply a Transition without Scenes

Slide 16

Slide 16 text

Transitions - Google IO YouTube Now you call Activity.makeSceneTransitionAnimation() Learning about Transitions

Slide 17

Slide 17 text

YouTube Square - Avoiding Fragments Use #fragnums, lol Learning about Transitions

Slide 18

Slide 18 text

This is not a Fragment bashing talk • Conductor • Flow • Pancakes • PancakesOnPlates • Scoop • Cicerone • BackStack • Magellan • Simple Stack • Triad • Okuki • Navi

Slide 19

Slide 19 text

This talk is about two scenarios ViewGroup

Slide 20

Slide 20 text

This talk is about two scenarios ViewGroup View1

Slide 21

Slide 21 text

This talk is about two scenarios View1 View2

Slide 22

Slide 22 text

This talk is about two scenarios View2 View1

Slide 23

Slide 23 text

This talk is about two scenarios TransitionManager.beginDelayedTransition()

Slide 24

Slide 24 text

This talk is about two scenarios TransitionManager.beginDelayedTransition()

Slide 25

Slide 25 text

Simple layout changes

Slide 26

Slide 26 text

blueView.setVisibility(View.VISIBLE);

Slide 27

Slide 27 text

The forgotten Honeycomb API

Slide 28

Slide 28 text

Oreo changes things

Slide 29

Slide 29 text

LayoutTransition layoutTransition = container .getLayoutTransition(); layoutTransition .enableTransitionType(LayoutTransition.CHANGING); Jelly Bean tricks

Slide 30

Slide 30 text

Using TransitionManager

Slide 31

Slide 31 text

TransitionManager.beginDelayedTransition(container); View view = findViewById(R.id.blueView); view.setVisibility(View.VISIBLE);

Slide 32

Slide 32 text

Complex example

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Make a simple version

Slide 38

Slide 38 text

Slide 39

Slide 39 text

Slide 40

Slide 40 text

Slide 41

Slide 41 text

Slide 42

Slide 42 text

helpButton.setOnClickListener(v -> { TransitionManager.beginDelayedTransition(linearContainer); LayoutParams containerParams = linearContainer.getLayoutParams(); containerParams.height = LayoutParams.WRAP_CONTENT; });

Slide 43

Slide 43 text

helpButton.setOnClickListener(v -> { TransitionManager.beginDelayedTransition(linearContainer); LayoutParams containerParams = linearContainer.getLayoutParams(); containerParams.height = LayoutParams.WRAP_CONTENT; title.setVisibility(View.GONE); instructions.setVisibility(View.GONE); helpButton.setVisibility(View.GONE); okButton.setVisibility(View.VISIBLE); });

Slide 44

Slide 44 text

helpButton.setOnClickListener(v -> { TransitionManager.beginDelayedTransition(linearContainer); LayoutParams containerParams = linearContainer.getLayoutParams(); containerParams.height = LayoutParams.WRAP_CONTENT; title.setVisibility(View.GONE); instructions.setVisibility(View.GONE); helpButton.setVisibility(View.GONE); okButton.setVisibility(View.VISIBLE); });

Slide 45

Slide 45 text

TransitionManager .beginDelayedTransition(linearContainer);

Slide 46

Slide 46 text

TransitionManager .beginDelayedTransition(linearContainer, transition); Customise the Transition

Slide 47

Slide 47 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(title) .addTarget(instructions) .addTarget(helpButton) .addTarget(okButton)) .addTransition(new ChangeBounds() .addTarget(linearContainer)); TransitionManager .beginDelayedTransition(linearContainer, transition); Customise the Transition

Slide 48

Slide 48 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(title) .addTarget(instructions) .addTarget(helpButton) .addTarget(okButton)) .addTransition(new ChangeBounds() .addTarget(linearContainer)); TransitionManager .beginDelayedTransition(linearContainer, transition);

Slide 49

Slide 49 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(title) .addTarget(instructions) .addTarget(helpButton) .addTarget(okButton)) .addTransition(new ChangeBounds() .addTarget(linearContainer)); TransitionManager .beginDelayedTransition(linearContainer, transition);

Slide 50

Slide 50 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(title) .addTarget(instructions) .addTarget(helpButton) .addTarget(okButton)) .addTransition(new ChangeBounds() .addTarget(linearContainer)); TransitionManager .beginDelayedTransition(linearContainer, transition);

Slide 51

Slide 51 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(title) .addTarget(instructions) .addTarget(helpButton) .addTarget(okButton)) .addTransition(new ChangeBounds() .addTarget(linearContainer) .addTarget(callButton)); TransitionManager .beginDelayedTransition(linearContainer, transition);

Slide 52

Slide 52 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(title) .addTarget(instructions) .addTarget(helpButton) .addTarget(okButton)) .addTransition(new ChangeBounds() .addTarget(linearContainer) .addTarget(callButton) .addTarget(okButton) .addTarget(helpButton)); TransitionManager .beginDelayedTransition(linearContainer, transition);

Slide 53

Slide 53 text

Slide 54

Slide 54 text

Slide 55

Slide 55 text

Slide 56

Slide 56 text

Slide 57

Slide 57 text

Slide 58

Slide 58 text

Slide 59

Slide 59 text

ConstraintLayout container = findViewById(R.id.container); ConstraintSet idleSet = new ConstraintSet(); ConstraintSet triggeredSet = new ConstraintSet(); idleSet.clone(container); triggeredSet.clone(container); Take advantage of ConstraintSet

Slide 60

Slide 60 text

ConstraintLayout container = findViewById(R.id.container); ConstraintSet idleSet = new ConstraintSet(); ConstraintSet triggeredSet = new ConstraintSet(); idleSet.clone(container); triggeredSet.clone(container); triggeredSet.setVisibility(R.id.title, View.GONE); triggeredSet.setVisibility(R.id.instructions, View.GONE); triggeredSet.setVisibility(R.id.helpButton, View.GONE); triggeredSet.setVisibility(R.id.okButton, View.VISIBLE); triggeredSet.connect(R.id.whiteBackground, ConstraintSet.TOP, R.id.guideline, ConstraintSet.TOP); Take advantage of ConstraintSet

Slide 61

Slide 61 text

ConstraintLayout container = findViewById(R.id.container); ConstraintSet idleSet = new ConstraintSet(); ConstraintSet triggeredSet = new ConstraintSet(); idleSet.clone(container); triggeredSet.clone(container); triggeredSet.setVisibility(R.id.title, View.GONE); triggeredSet.setVisibility(R.id.instructions, View.GONE); triggeredSet.setVisibility(R.id.helpButton, View.GONE); triggeredSet.setVisibility(R.id.okButton, View.VISIBLE); triggeredSet.connect(R.id.whiteBackground, ConstraintSet.TOP, R.id.guideline, ConstraintSet.TOP); helpButton.setOnClickListener(v -> { TransitionManager.beginDelayedTransition(container); triggeredSet.applyTo(container); }); Take advantage of ConstraintSet

Slide 62

Slide 62 text

helpButton.setOnClickListener(v -> { TransitionManager .beginDelayedTransition(container, new AutoTransition()); triggeredSet.applyTo(container); }); Take advantage of ConstraintSet

Slide 63

Slide 63 text

public class AutoTransition extends TransitionSet { private void init() { setOrdering(ORDERING_SEQUENTIAL); addTransition(new Fade(Fade.OUT)); addTransition(new ChangeBounds()); addTransition(new Fade(Fade.IN)); } }

Slide 64

Slide 64 text

Transition transition = new TransitionSet() .addTransition(new Fade()) .addTransition(new ChangeBounds()); TransitionManager .beginDelayedTransition(container, transition);

Slide 65

Slide 65 text

Transition transition = new TransitionSet() .addTransition(new Fade()) .addTransition(new ChangeBounds()); TransitionManager .beginDelayedTransition(container, transition);

Slide 66

Slide 66 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(title) .addTarget(instructions) .setDuration(100)) .addTransition(new Fade() .addTarget(helpButton) .addTarget(okButton) .setDuration(400)) .addTransition(new ChangeBounds() .setDuration(400) .setInterpolator(new FastOutSlowInInterpolator()); TransitionManager .beginDelayedTransition(container, transition);

Slide 67

Slide 67 text

Switching screens

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

Make a simple version

Slide 72

Slide 72 text

ViewGroup

Slide 73

Slide 73 text

ViewGroup

Slide 74

Slide 74 text

ViewGroup

Slide 75

Slide 75 text

ViewGroup

Slide 76

Slide 76 text

ViewGroup TransitionManager.beginDelayedTransition(viewGroup); viewGroup.remove(homeView); viewGroup.add(alarmView);

Slide 77

Slide 77 text

ViewGroup What if we use Fade? TransitionManager .beginDelayedTransition(viewGroup, new Fade()); viewGroup.remove(homeView); viewGroup.add(alarmView);

Slide 78

Slide 78 text

ViewGroup TransitionManager .beginDelayedTransition(viewGroup, new Slide()); viewGroup.remove(homeView); viewGroup.add(alarmView); What if we use Slide?

Slide 79

Slide 79 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.START) .addTarget(homeView) .setInterpolator(new FastOutSlowInInterpolator()) .addTransition(new Slide(Gravity.END) .addTarget(alarmView) .setInterpolator(new FastOutSlowInInterpolator()); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.remove(homeView); viewGroup.add(alarmView); A nicer Slide

Slide 80

Slide 80 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.START) .addTarget(alarmView) .setInterpolator(new FastOutSlowInInterpolator()); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.remove(homeView); viewGroup.add(alarmView);

Slide 81

Slide 81 text

ViewGroup Sliding over Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView) .setInterpolator(new LinearOutSlowInInterpolator()); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.remove(homeView); viewGroup.add(alarmView);

Slide 82

Slide 82 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(homeView) .setStartDelay(300) .setDuration(0)) .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView) .setInterpolator(new LinearOutSlowInInterpolator()); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.remove(homeView); viewGroup.add(alarmView); Sliding over

Slide 83

Slide 83 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(homeView) .setStartDelay(300) .setDuration(0)) .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView) .setInterpolator(new LinearOutSlowInInterpolator()); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.remove(homeView); viewGroup.add(alarmView); Sliding over

Slide 84

Slide 84 text

ViewGroup

Slide 85

Slide 85 text

ViewGroup

Slide 86

Slide 86 text

ViewGroup

Slide 87

Slide 87 text

ViewGroup

Slide 88

Slide 88 text

Read your library of choice’s documentation carefully! ViewGroup

Slide 89

Slide 89 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView) .setInterpolator(new LinearOutSlowInInterpolator()); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.remove(homeView); viewGroup.add(alarmView);

Slide 90

Slide 90 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView) .setInterpolator(new LinearOutSlowInInterpolator()); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.remove(homeView); viewGroup.add(alarmView);

Slide 91

Slide 91 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView) .setInterpolator(new LinearOutSlowInInterpolator()); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.add(alarmView);

Slide 92

Slide 92 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView) .setInterpolator(new LinearOutSlowInInterpolator()) .addListener(new Transition.TransitionListener() { @Override onTransitionEnd(Transition transition) { container.removeView(homeView); } }); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.add(alarmView);

Slide 93

Slide 93 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView) .setInterpolator(new LinearOutSlowInInterpolator()) .addListener(new Transition.TransitionListener() { @Override onTransitionEnd(Transition transition) { container.removeView(homeView); } }); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.add(alarmView);

Slide 94

Slide 94 text

ViewGroup Sharing elements

Slide 95

Slide 95 text

ViewGroup Sharing elements Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView) .setInterpolator(new LinearOutSlowInInterpolator());

Slide 96

Slide 96 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView) .setInterpolator(new LinearOutSlowInInterpolator()) .addTransition(new ChangeBounds() .addTarget(homeView.fab) .addTarget(alarmView.fab)); Sharing elements

Slide 97

Slide 97 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView) .setInterpolator(new LinearOutSlowInInterpolator()) .addTransition(new ChangeBounds() .addTarget(homeView.fab) .addTarget(alarmView.fab)); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.add(alarmView); Sharing elements

Slide 98

Slide 98 text

ViewGroup Breaking up views

Slide 99

Slide 99 text

ViewGroup Breaking up views

Slide 100

Slide 100 text

ViewGroup Breaking up views

Slide 101

Slide 101 text

ViewGroup Breaking up views

Slide 102

Slide 102 text

ViewGroup Breaking up views

Slide 103

Slide 103 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView) .setInterpolator(new LinearOutSlowInInterpolator()) .addTransition(new ChangeBounds() .addTarget(homeView.fab) .addTarget(alarmView.fab)); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.add(alarmView);

Slide 104

Slide 104 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView.contentContainer) .setInterpolator(new LinearOutSlowInInterpolator()) .addTransition(new ChangeBounds() .addTarget(homeView.fab) .addTarget(alarmView.fab)); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.add(alarmView);

Slide 105

Slide 105 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView.contentContainer) .setInterpolator(new LinearOutSlowInInterpolator()) .addTransition(new ChangeBounds() .addTarget(homeView.fab) .addTarget(alarmView.fab)); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.add(alarmView);

Slide 106

Slide 106 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView.contentContainer) .setInterpolator(new LinearOutSlowInInterpolator()) .addTransition(new ChangeBounds() .addTarget(homeView.fab) .addTarget(alarmView.fab)); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.add(alarmView);

Slide 107

Slide 107 text

ViewGroup Transition transition = new TransitionSet() .addTransition(new Slide(Gravity.BOTTOM) .addTarget(alarmView.contentContainer) .setInterpolator(new LinearOutSlowInInterpolator()) .addTransition(new ChangeBounds() .addTarget(homeView.fab) .addTarget(alarmView.fab)); TransitionManager .beginDelayedTransition(viewGroup, transition); viewGroup.add(alarmView); homeView.removeView(homeView.fab);

Slide 108

Slide 108 text

ViewGroup 


Slide 109

Slide 109 text

ViewGroup 


Slide 110

Slide 110 text

ViewGroup 


Slide 111

Slide 111 text

Same but different

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

Slide 115

Slide 115 text

Slide 116

Slide 116 text

Slide 117

Slide 117 text


 
 
 
 
 


Slide 118

Slide 118 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(searchView.scrim)) .addTransition(new ChangeBounds() .addTarget(homeView.card) .addTarget(searchView.card)); 
 
 
 
 
 


Slide 119

Slide 119 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(searchView.scrim)) .addTransition(new ChangeBounds() .addTarget(homeView.card) .addTarget(searchView.card)); TransitionManager .beginDelayedTransition(viewGroup, transition); container.addView(searchView); 
 
 
 
 


Slide 120

Slide 120 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(searchView.scrim)) .addTransition(new ChangeBounds() .addTarget(homeView.card) .addTarget(searchView.card)); TransitionManager .beginDelayedTransition(viewGroup, transition); container.addView(searchView);

Slide 121

Slide 121 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(searchView.scrim)) .addTransition(new ChangeBounds() .addTarget(homeView.card) .addTarget(searchView.card)); TransitionManager .beginDelayedTransition(viewGroup, transition); container.addView(searchView); homeView.removeView(homeView.card);

Slide 122

Slide 122 text

Slide 123

Slide 123 text

Slide 124

Slide 124 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(searchView.scrim)) .addTransition(new ChangeBounds() .addTarget(homeView.card) .addTarget(searchView.card)); TransitionManager .beginDelayedTransition(viewGroup, transition); homeView.removeView(homeView.card);

Slide 125

Slide 125 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(searchView.scrim)) .addTransition(new ChangeBounds() .addTarget(homeView.card) .addTarget(searchView.card)); TransitionManager .beginDelayedTransition(viewGroup, transition); homeView.removeView(homeView.card);

Slide 126

Slide 126 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(searchView.scrim)) .addTransition(new TransitionSet() .addTransition(new ChangeBounds()) .addTransition(new ChangeTransform()) .addTarget(homeView.card) .addTarget(searchView.card)); TransitionManager .beginDelayedTransition(viewGroup, transition); homeView.removeView(homeView.card);

Slide 127

Slide 127 text

What about going back?

Slide 128

Slide 128 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(searchView.scrim)) .addTransition(new TransitionSet() .addTransition(new ChangeBounds()) .addTransition(new ChangeTransform()) .addTarget(homeView.card) .addTarget(searchView.card)); TransitionManager .beginDelayedTransition(viewGroup, transition); homeView.addView(homeView.card); container.removeView(searchView); What about going back?

Slide 129

Slide 129 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(searchView.scrim)) .addTransition(new TransitionSet() .addTransition(new ChangeBounds()) .addTransition(new ChangeTransform()) .addTarget(homeView.card) .addTarget(searchView.card)); TransitionManager .beginDelayedTransition(viewGroup, transition); homeView.addView(homeView.card); container.removeView(searchView);

Slide 130

Slide 130 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(searchView.scrim)) .addTransition(new TransitionSet() .addTransition(new ChangeBounds()) .addTransition(new ChangeTransform()) .addTarget(homeView.card) .addTarget(searchView.card)); TransitionManager .beginDelayedTransition(viewGroup, transition); homeView.addView(homeView.card); container.removeView(searchView);

Slide 131

Slide 131 text

Transition transition = new TransitionSet() .addTransition(new Fade() .addTarget(searchView.scrim)) .addTransition(new TransitionSet() .addTransition(new ChangeBounds()) .addTransition(new ChangeTransform()) .addTarget(R.id.homeCard) .addTarget(searchView.card)); TransitionManager .beginDelayedTransition(viewGroup, transition); homeView.addView(homeView.card); container.removeView(searchView);

Slide 132

Slide 132 text

Transitions aren’t perfect

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

Debugging tips • Know your layout hierarchy • ChangeBounds() is a good place to start investigating • Try starting with simplified versions of your screens

Slide 135

Slide 135 text

Things to remember • Transitions are powerful; don’t ignore them • Choose your view-based navigation library carefully • Use them to enhance UX, not show off

Slide 136

Slide 136 text

Transitions without Activities or Fragments chris_h_codes chris-horner chrishorner.codes