Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 71f4e21

Browse files
committed
Motion: Replace deprecated APIs
Change-Id: Ia2aefc3e2aa5ba57222a3424b6a94cca8c1756ca
1 parent b4aef2a commit 71f4e21

24 files changed

+91
-88
lines changed

Motion/.idea/misc.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

Motion/app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ apply plugin: 'kotlin-android'
1919
apply plugin: "androidx.navigation.safeargs.kotlin"
2020

2121
android {
22-
compileSdkVersion 30
22+
compileSdkVersion 31
2323

2424
defaultConfig {
2525
applicationId 'com.example.android.motion'
2626
minSdkVersion 14
27-
targetSdkVersion 30
27+
targetSdkVersion 31
2828
versionCode 1
2929
versionName '1.0'
3030
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
@@ -51,16 +51,16 @@ android {
5151
dependencies {
5252
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
5353

54-
implementation 'androidx.core:core-ktx:1.6.0'
54+
implementation 'androidx.core:core-ktx:1.7.0'
5555
implementation 'androidx.fragment:fragment-ktx:1.3.6'
5656
implementation 'androidx.appcompat:appcompat:1.3.1'
5757
implementation 'androidx.transition:transition:1.4.1'
5858
implementation 'androidx.dynamicanimation:dynamicanimation:1.1.0-alpha03'
5959
implementation 'androidx.recyclerview:recyclerview:1.2.1'
6060

61-
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
61+
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
6262

63-
def lifecycle_version = '2.3.1'
63+
def lifecycle_version = '2.4.0'
6464
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
6565
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
6666

Motion/app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
<activity
3838
android:name=".MainActivity"
39+
android:exported="true"
3940
android:theme="@style/Theme.Motion.CardUi">
4041
<intent-filter>
4142
<action android:name="android.intent.action.MAIN" />
@@ -45,6 +46,7 @@
4546

4647
<activity
4748
android:name=".demo.dissolve.DissolveActivity"
49+
android:exported="true"
4850
android:label="@string/dissolve_label">
4951
<intent-filter>
5052
<action android:name="android.intent.action.MAIN" />
@@ -61,6 +63,7 @@
6163

6264
<activity
6365
android:name=".demo.fadethrough.FadeThroughActivity"
66+
android:exported="true"
6467
android:label="@string/fade_through_label">
6568
<intent-filter>
6669
<action android:name="android.intent.action.MAIN" />
@@ -77,6 +80,7 @@
7780

7881
<activity
7982
android:name=".demo.fabtransformation.FabTransformationActivity"
83+
android:exported="true"
8084
android:label="@string/fab_transformation_label">
8185
<intent-filter>
8286
<action android:name="android.intent.action.MAIN" />
@@ -93,6 +97,7 @@
9397

9498
<activity
9599
android:name=".demo.reorder.ReorderActivity"
100+
android:exported="true"
96101
android:label="@string/reorder_label">
97102
<intent-filter>
98103
<action android:name="android.intent.action.MAIN" />
@@ -109,6 +114,7 @@
109114

110115
<activity
111116
android:name=".demo.stagger.StaggerActivity"
117+
android:exported="true"
112118
android:label="@string/stagger_label">
113119
<intent-filter>
114120
<action android:name="android.intent.action.MAIN" />
@@ -125,6 +131,7 @@
125131

126132
<activity
127133
android:name=".demo.loading.LoadingActivity"
134+
android:exported="true"
128135
android:label="@string/loading_label">
129136
<intent-filter>
130137
<action android:name="android.intent.action.MAIN" />
@@ -141,6 +148,7 @@
141148

142149
<activity
143150
android:name=".demo.oscillation.OscillationActivity"
151+
android:exported="true"
144152
android:label="@string/oscillation_label"
145153
android:theme="@style/Theme.Motion.CardUi">
146154
<intent-filter>
@@ -158,6 +166,7 @@
158166

159167
<activity
160168
android:name=".demo.sharedelement.SharedElementActivity"
169+
android:exported="true"
161170
android:label="@string/shared_element_label"
162171
android:theme="@style/Theme.Motion.Translucent">
163172
<intent-filter>
@@ -175,6 +184,7 @@
175184

176185
<activity
177186
android:name=".demo.containertransform.ContainerTransformActivity"
187+
android:exported="true"
178188
android:label="@string/container_transform_label"
179189
android:theme="@style/Theme.Motion.Translucent">
180190
<intent-filter>

Motion/app/src/main/java/com/example/android/motion/MainActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.example.android.motion
1919
import androidx.appcompat.app.AppCompatActivity
2020
import android.os.Bundle
2121
import androidx.appcompat.widget.Toolbar
22+
import androidx.core.view.WindowCompat
2223
import androidx.fragment.app.commitNow
2324
import com.example.android.motion.ui.EdgeToEdge
2425
import com.example.android.motion.ui.demolist.DemoListFragment
@@ -32,7 +33,7 @@ class MainActivity : AppCompatActivity() {
3233
setSupportActionBar(toolbar)
3334

3435
// Configure edge-to-edge display.
35-
EdgeToEdge.setUpRoot(findViewById(R.id.main))
36+
WindowCompat.setDecorFitsSystemWindows(window, false)
3637
EdgeToEdge.setUpAppBar(findViewById(R.id.app_bar), toolbar)
3738

3839
// Set up the fragment.

Motion/app/src/main/java/com/example/android/motion/demo/containertransform/CheeseArticleFragment.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import androidx.appcompat.widget.Toolbar
2828
import androidx.coordinatorlayout.widget.CoordinatorLayout
2929
import androidx.core.view.ViewCompat
3030
import androidx.core.view.ViewGroupCompat
31+
import androidx.core.view.WindowInsetsCompat
3132
import androidx.core.view.updateLayoutParams
3233
import androidx.core.view.updatePadding
3334
import androidx.core.widget.NestedScrollView
@@ -82,19 +83,20 @@ class CheeseArticleFragment : Fragment() {
8283

8384
// Adjust the edge-to-edge display.
8485
ViewCompat.setOnApplyWindowInsetsListener(view) { _, insets ->
86+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
8587
toolbar.updateLayoutParams<CollapsingToolbarLayout.LayoutParams> {
86-
topMargin = insets.systemWindowInsetTop
88+
topMargin = systemBars.top
8789
}
8890
// The collapsed app bar gets taller by the toolbar's top margin. The CoordinatorLayout
8991
// has to have a bottom margin of the same amount so that the scrolling content is
9092
// completely visible.
9193
scroll.updateLayoutParams<CoordinatorLayout.LayoutParams> {
92-
bottomMargin = insets.systemWindowInsetTop
94+
bottomMargin = systemBars.top
9395
}
9496
content.updatePadding(
95-
left = insets.systemWindowInsetLeft,
96-
right = insets.systemWindowInsetRight,
97-
bottom = insets.systemWindowInsetBottom
97+
left = systemBars.left,
98+
right = systemBars.right,
99+
bottom = systemBars.bottom
98100
)
99101
insets
100102
}

Motion/app/src/main/java/com/example/android/motion/demo/containertransform/CheeseCardFragment.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import androidx.appcompat.widget.Toolbar
2727
import androidx.constraintlayout.widget.ConstraintLayout
2828
import androidx.core.view.ViewCompat
2929
import androidx.core.view.ViewGroupCompat
30+
import androidx.core.view.WindowInsetsCompat
3031
import androidx.core.view.updateLayoutParams
3132
import androidx.core.view.updatePadding
3233
import androidx.fragment.app.Fragment
@@ -76,13 +77,14 @@ class CheeseCardFragment : Fragment() {
7677
val name: TextView = view.findViewById(R.id.name)
7778

7879
ViewCompat.setOnApplyWindowInsetsListener(view.parent as View) { _, insets ->
80+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
7981
toolbar.updateLayoutParams<AppBarLayout.LayoutParams> {
80-
topMargin = insets.systemWindowInsetTop
82+
topMargin = systemBars.top
8183
}
8284
content.updatePadding(
83-
left = insets.systemWindowInsetLeft,
84-
right = insets.systemWindowInsetRight,
85-
bottom = insets.systemWindowInsetBottom
85+
left = systemBars.left,
86+
right = systemBars.right,
87+
bottom = systemBars.bottom
8688
)
8789
insets
8890
}

Motion/app/src/main/java/com/example/android/motion/demo/containertransform/ContainerTransformActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ package com.example.android.motion.demo.containertransform
1818

1919
import android.os.Bundle
2020
import androidx.appcompat.app.AppCompatActivity
21+
import androidx.core.view.WindowCompat
2122
import com.example.android.motion.R
22-
import com.example.android.motion.ui.EdgeToEdge
2323

2424
class ContainerTransformActivity : AppCompatActivity() {
2525

2626
override fun onCreate(savedInstanceState: Bundle?) {
2727
super.onCreate(savedInstanceState)
2828
setContentView(R.layout.container_transform_activity)
29-
EdgeToEdge.setUpRoot(findViewById(R.id.nav_host))
29+
WindowCompat.setDecorFitsSystemWindows(window, false)
3030
}
3131
}

Motion/app/src/main/java/com/example/android/motion/demo/dissolve/DissolveActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.widget.ImageView
2121
import androidx.activity.viewModels
2222
import androidx.appcompat.app.AppCompatActivity
2323
import androidx.appcompat.widget.Toolbar
24+
import androidx.core.view.WindowCompat
2425
import androidx.transition.TransitionManager
2526
import com.example.android.motion.R
2627
import com.example.android.motion.demo.FAST_OUT_SLOW_IN
@@ -42,7 +43,7 @@ class DissolveActivity : AppCompatActivity() {
4243
val next: MaterialButton = findViewById(R.id.next)
4344

4445
setSupportActionBar(toolbar)
45-
EdgeToEdge.setUpRoot(findViewById(R.id.root))
46+
WindowCompat.setDecorFitsSystemWindows(window, false)
4647
EdgeToEdge.setUpAppBar(findViewById(R.id.app_bar), toolbar)
4748
EdgeToEdge.setUpScrollingContent(findViewById(R.id.content))
4849

Motion/app/src/main/java/com/example/android/motion/demo/fabtransformation/FabTransformationActivity.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import androidx.appcompat.app.AppCompatActivity
2626
import androidx.appcompat.widget.Toolbar
2727
import androidx.coordinatorlayout.widget.CoordinatorLayout
2828
import androidx.core.view.ViewCompat
29+
import androidx.core.view.WindowCompat
30+
import androidx.core.view.WindowInsetsCompat
2931
import androidx.core.view.isVisible
3032
import androidx.core.view.updateLayoutParams
3133
import com.bumptech.glide.Glide
@@ -81,19 +83,20 @@ class FabTransformationActivity : AppCompatActivity() {
8183
setSupportActionBar(toolbar)
8284

8385
// Set up edge-to-edge display.
84-
EdgeToEdge.setUpRoot(root)
86+
WindowCompat.setDecorFitsSystemWindows(window, false)
8587
EdgeToEdge.setUpAppBar(findViewById(R.id.app_bar), toolbar)
8688
val fabMargin = resources.getDimensionPixelSize(R.dimen.spacing_medium)
8789
ViewCompat.setOnApplyWindowInsetsListener(root) { _, insets ->
90+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
8891
fab.updateLayoutParams<CoordinatorLayout.LayoutParams> {
89-
leftMargin = fabMargin + insets.systemWindowInsetLeft
90-
rightMargin = fabMargin + insets.systemWindowInsetRight
91-
bottomMargin = fabMargin + insets.systemWindowInsetBottom
92+
leftMargin = fabMargin + systemBars.left
93+
rightMargin = fabMargin + systemBars.right
94+
bottomMargin = fabMargin + systemBars.bottom
9295
}
9396
sheet.updateLayoutParams<CoordinatorLayout.LayoutParams> {
94-
leftMargin = fabMargin + insets.systemWindowInsetLeft
95-
rightMargin = fabMargin + insets.systemWindowInsetRight
96-
bottomMargin = fabMargin + insets.systemWindowInsetBottom
97+
leftMargin = fabMargin + systemBars.left
98+
rightMargin = fabMargin + systemBars.right
99+
bottomMargin = fabMargin + systemBars.bottom
97100
}
98101
insets
99102
}

Motion/app/src/main/java/com/example/android/motion/demo/fadethrough/FadeThroughActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.widget.ImageView
2121
import androidx.appcompat.app.AppCompatActivity
2222
import androidx.appcompat.widget.Toolbar
2323
import androidx.constraintlayout.widget.ConstraintLayout
24+
import androidx.core.view.WindowCompat
2425
import androidx.core.view.isVisible
2526
import androidx.transition.TransitionManager
2627
import com.bumptech.glide.Glide
@@ -48,7 +49,7 @@ class FadeThroughActivity : AppCompatActivity() {
4849

4950
// Set up the layout.
5051
setSupportActionBar(toolbar)
51-
EdgeToEdge.setUpRoot(findViewById(R.id.root))
52+
WindowCompat.setDecorFitsSystemWindows(window, false)
5253
EdgeToEdge.setUpAppBar(findViewById(R.id.app_bar), toolbar)
5354
EdgeToEdge.setUpScrollingContent(findViewById(R.id.content))
5455
Glide.with(icon).load(R.drawable.cheese_2).transform(CircleCrop()).into(icon)

0 commit comments

Comments
 (0)