Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit a0bf21e

Browse files
authored
Update to MotionLayout alpha3 (#43)
* Update to MotionLayout alpha3 - Replace MotionLayout#setShowPaths with #setDebugMode - Changed Activities comfor to new listeners - Use PropertySet for views which only alpha changes in MotionScene
1 parent 9fa6a85 commit a0bf21e

File tree

9 files changed

+107
-100
lines changed

9 files changed

+107
-100
lines changed

motionlayout/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ apply plugin: 'kotlin-android'
2121
apply plugin: 'kotlin-android-extensions'
2222

2323
android {
24-
compileSdkVersion 27
24+
compileSdkVersion 28
2525
defaultConfig {
2626
applicationId "com.google.androidstudio.motionlayoutexample"
2727
minSdkVersion 18
28-
targetSdkVersion 27
28+
targetSdkVersion 28
2929
versionCode 1
3030
versionName "1.0"
3131
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -41,11 +41,11 @@ android {
4141
dependencies {
4242
implementation fileTree(dir: 'libs', include: ['*.jar'])
4343
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
44-
implementation 'com.android.support:appcompat-v7:27.1.1'
44+
implementation 'com.android.support:appcompat-v7:28.0.0'
4545

46-
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha2'
46+
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha3'
4747
implementation 'android.arch.lifecycle:extensions:1.1.1'
48-
implementation 'com.android.support:design:27.1.1'
48+
implementation 'com.android.support:design:28.0.0'
4949
implementation 'com.airbnb.android:lottie:2.5.1'
5050
implementation 'com.github.bumptech.glide:glide:4.8.0'
5151
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample/DemoActivity.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import android.widget.ImageView
2626

2727
@RequiresApi(Build.VERSION_CODES.LOLLIPOP) // for View#clipToOutline
2828
class DemoActivity : AppCompatActivity() {
29+
2930
private lateinit var container: View
3031

3132
override fun onCreate(savedInstanceState: Bundle?) {
@@ -39,8 +40,12 @@ class DemoActivity : AppCompatActivity() {
3940
icon?.clipToOutline = true
4041
}
4142

42-
val doShowPaths = intent.getBooleanExtra("showPaths", false)
43-
(container as? MotionLayout)?.setShowPaths(doShowPaths)
43+
val debugMode = if (intent.getBooleanExtra("showPaths", false)) {
44+
MotionLayout.DEBUG_SHOW_PATH
45+
} else {
46+
MotionLayout.DEBUG_SHOW_NONE
47+
}
48+
(container as? MotionLayout)?.setDebugMode(debugMode)
4449
}
4550

4651
fun changeState(v: View?) {

motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample/MainActivity.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.google.androidstudio.motionlayoutexample
22

33
import android.content.Intent
4-
import android.support.v7.app.AppCompatActivity
54
import android.os.Bundle
5+
import android.support.v7.app.AppCompatActivity
66
import android.support.v7.widget.LinearLayoutManager
77
import android.support.v7.widget.RecyclerView
88
import android.widget.CompoundButton
@@ -52,7 +52,6 @@ class MainActivity : AppCompatActivity(), CompoundButton.OnCheckedChangeListener
5252
setContentView(R.layout.activity_main)
5353
viewManager = LinearLayoutManager(this)
5454
viewAdapter = DemosAdapter(dataset)
55-
5655
recyclerView = findViewById<RecyclerView>(R.id.recyclerview).apply {
5756
setHasFixedSize(true)
5857
layoutManager = viewManager

motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample/fragmentsdemo/FragmentExample2Activity.kt

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,61 @@ import com.google.androidstudio.motionlayoutexample.R
2525
import kotlinx.android.synthetic.main.main_activity.*
2626

2727
class FragmentExample2Activity : AppCompatActivity(), View.OnClickListener, MotionLayout.TransitionListener {
28-
override fun onTransitionChange(p0: MotionLayout?, p1: Int, p2: Int, progress: Float) {
29-
if (progress - lastProgress > 0) {
28+
29+
// TODO: Extract the common code with FragmentExampleActivity
30+
private var lastProgress = 0f
31+
private var fragment : Fragment? = null
32+
private var last : Float = 0f
33+
34+
override fun onTransitionChange(p0: MotionLayout?, p1: Int, p2: Int, p3: Float) {
35+
if (p3 - lastProgress > 0) {
3036
// from start to end
31-
val atEnd = Math.abs(progress - 1f) < 0.1f
37+
val atEnd = Math.abs(p3 - 1f) < 0.1f
3238
if (atEnd && fragment is MainFragment) {
3339
val transaction = supportFragmentManager.beginTransaction()
3440
transaction
3541
.setCustomAnimations(R.animator.show, 0)
36-
fragment = ListFragment.newInstance()
37-
transaction
38-
.replace(R.id.container, fragment)
42+
fragment = ListFragment.newInstance().also {
43+
transaction
44+
.replace(R.id.container, it)
3945
.commitNow()
46+
}
4047
}
4148
} else {
4249
// from end to start
43-
val atStart = progress < 0.9f
50+
val atStart = p3 < 0.9f
4451
if (atStart && fragment is ListFragment) {
4552
val transaction = supportFragmentManager.beginTransaction()
4653
transaction
4754
.setCustomAnimations(0, R.animator.hide)
48-
fragment = MainFragment.newInstance()
49-
transaction
50-
.replace(R.id.container, fragment)
55+
fragment = MainFragment.newInstance().also {
56+
transaction
57+
.replace(R.id.container, it)
5158
.commitNow()
59+
}
5260
}
5361
}
54-
lastProgress = progress
62+
lastProgress = p3
5563
}
5664

57-
override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) {
65+
override fun onTransitionTrigger(p0: MotionLayout?, p1: Int, p2: Boolean, p3: Float) {
5866
}
5967

60-
private var lastProgress = 0f
68+
override fun onTransitionStarted(p0: MotionLayout?, p1: Int, p2: Int) {
69+
}
6170

62-
private var fragment : Fragment? = null
63-
private var last : Float = 0f
71+
override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) {
72+
}
6473

6574
override fun onCreate(savedInstanceState: Bundle?) {
6675
super.onCreate(savedInstanceState)
6776
setContentView(R.layout.main_activity)
6877
if (savedInstanceState == null) {
69-
fragment = MainFragment.newInstance()
70-
supportFragmentManager.beginTransaction()
71-
.replace(R.id.container, fragment)
78+
fragment = MainFragment.newInstance().also {
79+
supportFragmentManager.beginTransaction()
80+
.replace(R.id.container, it)
7281
.commitNow()
82+
}
7383
}
7484
//toggle.setOnClickListener(this)
7585
//toggleAnimation.setOnClickListener(this)
@@ -88,10 +98,11 @@ class FragmentExample2Activity : AppCompatActivity(), View.OnClickListener, Moti
8898
transaction
8999
.setCustomAnimations(0, R.animator.hide)
90100
MainFragment.newInstance()
91-
}
92-
transaction
93-
.replace(R.id.container, fragment)
101+
}.also {
102+
transaction
103+
.replace(R.id.container, it)
94104
.commitNow()
105+
}
95106
}
96107
}
97108
}

motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample/fragmentsdemo/FragmentExampleActivity.kt

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,55 +25,62 @@ import com.google.androidstudio.motionlayoutexample.R
2525
import kotlinx.android.synthetic.main.main_activity.*
2626

2727
class FragmentExampleActivity : AppCompatActivity(), View.OnClickListener, MotionLayout.TransitionListener {
28-
override fun onTransitionChange(p0: MotionLayout?, p1: Int, p2: Int, progress: Float) {
29-
if (progress - lastProgress > 0) {
28+
29+
private var lastProgress = 0f
30+
private var fragment : Fragment? = null
31+
private var last : Float = 0f
32+
33+
override fun onTransitionChange(p0: MotionLayout?, p1: Int, p2: Int, p3: Float) {
34+
if (p3 - lastProgress > 0) {
3035
// from start to end
31-
val atEnd = Math.abs(progress - 1f) < 0.1f
36+
val atEnd = Math.abs(p3 - 1f) < 0.1f
3237
if (atEnd && fragment is MainFragment) {
3338
val transaction = supportFragmentManager.beginTransaction()
3439
transaction
3540
.setCustomAnimations(R.animator.show, 0)
36-
fragment = SecondFragment.newInstance()
37-
transaction
41+
fragment = SecondFragment.newInstance().also {
42+
transaction
3843
.setCustomAnimations(R.animator.show, 0)
39-
.replace(R.id.container, fragment)
44+
.replace(R.id.container, it)
4045
.commitNow()
46+
}
4147
}
4248
} else {
4349
// from end to start
44-
val atStart = progress < 0.9f
50+
val atStart = p3 < 0.9f
4551
if (atStart && fragment is SecondFragment) {
4652
val transaction = supportFragmentManager.beginTransaction()
4753
transaction
4854
.setCustomAnimations(0, R.animator.hide)
49-
fragment = MainFragment.newInstance()
50-
transaction
51-
.replace(R.id.container, fragment)
55+
fragment = MainFragment.newInstance().also {
56+
transaction
57+
.replace(R.id.container, it)
5258
.commitNow()
59+
}
5360
}
5461
}
55-
lastProgress = progress
62+
lastProgress = p3
5663
}
5764

58-
override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) {
65+
override fun onTransitionTrigger(p0: MotionLayout?, p1: Int, p2: Boolean, p3: Float) {
5966
}
6067

61-
private var lastProgress = 0f
68+
override fun onTransitionStarted(p0: MotionLayout?, p1: Int, p2: Int) {
69+
}
6270

63-
private var fragment : Fragment? = null
64-
private var last : Float = 0f
71+
override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) {
72+
}
6573

6674
override fun onCreate(savedInstanceState: Bundle?) {
6775
super.onCreate(savedInstanceState)
6876
setContentView(R.layout.main_activity)
6977
if (savedInstanceState == null) {
70-
fragment = MainFragment.newInstance()
71-
supportFragmentManager.beginTransaction()
72-
.replace(R.id.container, fragment)
78+
fragment = MainFragment.newInstance().also {
79+
supportFragmentManager.beginTransaction()
80+
.replace(R.id.container, it)
7381
.commitNow()
82+
}
7483
}
75-
//toggle.setOnClickListener(this)
76-
//toggleAnimation.setOnClickListener(this)
7784
motionLayout.setTransitionListener(this)
7885
}
7986

@@ -89,10 +96,11 @@ class FragmentExampleActivity : AppCompatActivity(), View.OnClickListener, Motio
8996
transaction
9097
.setCustomAnimations(0, R.animator.hide)
9198
MainFragment.newInstance()
92-
}
93-
transaction
94-
.replace(R.id.container, fragment)
99+
}.also {
100+
transaction
101+
.replace(R.id.container, it)
95102
.commitNow()
103+
}
96104
}
97105
}
98106
}

motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample/viewpagerdemo/ViewPagerActivity.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ class ViewPagerActivity : AppCompatActivity() {
4141
pager.addOnPageChangeListener(motionLayout as ViewPager.OnPageChangeListener)
4242
}
4343

44-
val doShowPaths = intent.getBooleanExtra("showPaths", false)
45-
motionLayout.setShowPaths(doShowPaths)
44+
val debugMode = if (intent.getBooleanExtra("showPaths", false)) {
45+
MotionLayout.DEBUG_SHOW_PATH
46+
} else {
47+
MotionLayout.DEBUG_SHOW_NONE
48+
}
49+
motionLayout.setDebugMode(debugMode)
4650
}
4751
}

motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample/viewpagerdemo/ViewPagerActivity2.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import android.os.Bundle
2020
import android.support.constraint.motion.MotionLayout
2121
import android.support.v4.view.ViewPager
2222
import android.support.v7.app.AppCompatActivity
23-
import android.view.View
2423
import com.google.androidstudio.motionlayoutexample.R
2524
import kotlinx.android.synthetic.main.motion_16_viewpager.*
2625

@@ -42,7 +41,11 @@ class ViewPagerActivity2 : AppCompatActivity() {
4241
pager.addOnPageChangeListener(motionLayout as ViewPager.OnPageChangeListener)
4342
}
4443

45-
val doShowPaths = intent.getBooleanExtra("showPaths", false)
46-
motionLayout.setShowPaths(doShowPaths)
44+
val debugMode = if (intent.getBooleanExtra("showPaths", false)) {
45+
MotionLayout.DEBUG_SHOW_PATH
46+
} else {
47+
MotionLayout.DEBUG_SHOW_NONE
48+
}
49+
motionLayout.setDebugMode(debugMode)
4750
}
4851
}

motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample/youtubedemo/YouTubeDemoActivity.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ class YouTubeDemoActivity : AppCompatActivity() {
3636
isNestedScrollingEnabled = false
3737
layoutManager = LinearLayoutManager(this@YouTubeDemoActivity)
3838
}
39-
val doShowPaths = intent.getBooleanExtra("showPaths", false)
40-
motionLayout.setShowPaths(doShowPaths)
39+
val debugMode = if (intent.getBooleanExtra("showPaths", false)) {
40+
MotionLayout.DEBUG_SHOW_PATH
41+
} else {
42+
MotionLayout.DEBUG_SHOW_NONE
43+
}
44+
motionLayout.setDebugMode(debugMode)
4145
}
4246
}

motionlayout/src/main/res/xml/scene_24.xml

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,13 @@
6565
motion:layout_constraintEnd_toEndOf="parent"
6666
motion:layout_constraintStart_toStartOf="parent"/>
6767

68-
<Constraint
69-
android:id="@id/image_play"
70-
android:layout_width="wrap_content"
71-
android:layout_height="wrap_content"
72-
android:layout_marginEnd="16dp"
73-
android:alpha="0"
74-
motion:layout_constraintEnd_toStartOf="@id/image_clear"
75-
motion:layout_constraintTop_toTopOf="@id/top_image_container"
76-
motion:layout_constraintBottom_toBottomOf="@id/top_image_container"
77-
/>
68+
<Constraint android:id="@id/image_play" >
69+
<PropertySet motion:alpha="0" />
70+
</Constraint>
7871

79-
<Constraint
80-
android:id="@id/image_clear"
81-
android:layout_width="wrap_content"
82-
android:layout_height="wrap_content"
83-
android:layout_marginEnd="16dp"
84-
android:alpha="0"
85-
motion:layout_constraintEnd_toEndOf="@id/top_image_container"
86-
motion:layout_constraintTop_toTopOf="@id/top_image_container"
87-
motion:layout_constraintBottom_toBottomOf="@id/top_image_container"
88-
/>
72+
<Constraint android:id="@id/image_clear" >
73+
<PropertySet motion:alpha="0" />
74+
</Constraint>
8975

9076
<Constraint
9177
android:id="@id/bottom_nav"
@@ -144,27 +130,14 @@
144130
motion:layout_constraintStart_toStartOf="@id/top_image_container"
145131
/>
146132

147-
<Constraint
148-
android:id="@id/image_play"
149-
android:layout_width="wrap_content"
150-
android:layout_height="wrap_content"
151-
android:layout_marginEnd="16dp"
152-
android:alpha="1"
153-
motion:layout_constraintEnd_toStartOf="@id/image_clear"
154-
motion:layout_constraintTop_toTopOf="@id/top_image_container"
155-
motion:layout_constraintBottom_toBottomOf="@id/top_image_container"
156-
/>
133+
<Constraint android:id="@id/image_play" >
134+
<PropertySet motion:alpha="1" />
135+
</Constraint>
136+
137+
<Constraint android:id="@id/image_clear" >
138+
<PropertySet motion:alpha="1" />
139+
</Constraint>
157140

158-
<Constraint
159-
android:id="@id/image_clear"
160-
android:layout_width="wrap_content"
161-
android:layout_height="wrap_content"
162-
android:layout_marginEnd="16dp"
163-
android:alpha="1"
164-
motion:layout_constraintEnd_toEndOf="@id/top_image_container"
165-
motion:layout_constraintTop_toTopOf="@id/top_image_container"
166-
motion:layout_constraintBottom_toBottomOf="@id/top_image_container"
167-
/>
168141

169142
<Constraint
170143
android:id="@id/bottom_nav"

0 commit comments

Comments
 (0)