Skip to content

Commit 78b298d

Browse files
author
Jeremy Woods
committed
Update the Fragment integration app
Move the Activities to Fragments Replaced Animations with Animators Enabled Gestureback Test: this updated the test app Change-Id: I7270c71bfc23b36d729ccd3841833589c0ffa144
1 parent 251cbde commit 78b298d

File tree

10 files changed

+198
-38
lines changed

10 files changed

+198
-38
lines changed

fragment/integration-tests/testapp/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ android {
2525
main {
2626
res.srcDirs = ["src/main/res",
2727
"src/main/res/layouts/doubleTransitionBug",
28-
"src/main/res/layouts/kittenFragmentTransitions"
28+
"src/main/res/layouts/kittenFragmentTransitions",
29+
"src/main/res/layouts/basicAnimators",
2930
]
3031
}
3132
}

fragment/integration-tests/testapp/src/main/AndroidManifest.xml

+1-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
android:allowBackup="true"
2222
android:label="@string/app_name"
2323
android:supportsRtl="true"
24+
android:enableOnBackInvokedCallback="true"
2425
tools:ignore="AllowBackup,GoogleAppIndexingWarning,MissingApplicationIcon">
2526
<activity
2627
android:name=".MainFragmentActivity"
@@ -32,12 +33,6 @@
3233
<category android:name="android.intent.category.LAUNCHER" />
3334
</intent-filter>
3435
</activity>
35-
<activity
36-
android:name=".doubleTransitionBug.DoubleTransitionBugActivity"
37-
android:exported="false" />
38-
<activity
39-
android:name=".kittenfragmenttransitions.KittenTransitionMainActivity"
40-
android:exported="false" />
4136
</application>
4237

4338
</manifest>

fragment/integration-tests/testapp/src/main/java/androidx/fragment/testapp/AnimationTestsFragment.kt fragment/integration-tests/testapp/src/main/java/androidx/fragment/testapp/AnimatorTestsFragment.kt

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 The Android Open Source Project
2+
* Copyright 2023 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,13 @@
1616

1717
package androidx.fragment.testapp
1818

19+
import android.os.Bundle
20+
import android.view.View
1921
import androidx.fragment.app.Fragment
22+
import androidx.fragment.testapp.basicAnimators.BasicFragmentAnimatorFragment
2023

21-
class AnimationTestsFragment : Fragment(R.layout.animation_fragment)
24+
class AnimatorTestsFragment : Fragment(R.layout.animation_fragment) {
25+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
26+
addButton("Basic Fragment Animators", BasicFragmentAnimatorFragment())
27+
}
28+
}

fragment/integration-tests/testapp/src/main/java/androidx/fragment/testapp/TestTypeSelectFragment.kt

+15-15
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@ class TestTypeSelectFragment : Fragment(R.layout.test_type_select) {
2828
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
2929
super.onViewCreated(view, savedInstanceState)
3030

31-
addButton("Fragment Animation Test", AnimationTestsFragment())
31+
addButton("Fragment Animator Test", AnimatorTestsFragment())
3232
addButton("Fragment Transition Test", TransitionTestsFragment())
3333
}
34+
}
3435

35-
private fun Fragment.addButton(text: String, fragment: Fragment) {
36-
(requireView() as LinearLayout).addView(
37-
Button(context).apply {
38-
this.text = text
36+
internal fun Fragment.addButton(text: String, fragment: Fragment) {
37+
(requireView() as LinearLayout).addView(
38+
Button(context).apply {
39+
this.text = text
3940

40-
setOnClickListener {
41-
parentFragmentManager.commit {
42-
replace(R.id.fragment_container, fragment)
43-
addToBackStack(null)
44-
}
45-
}
46-
layoutParams = LinearLayout.LayoutParams(-1, 0).apply {
47-
weight = 1f
41+
setOnClickListener {
42+
parentFragmentManager.commit {
43+
replace(R.id.fragment_container, fragment)
44+
addToBackStack(null)
4845
}
4946
}
50-
)
51-
}
47+
layoutParams = LinearLayout.LayoutParams(-1, 0).apply {
48+
weight = 1f
49+
}
50+
}
51+
)
5252
}

fragment/integration-tests/testapp/src/main/java/androidx/fragment/testapp/TransitionTestsFragment.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import android.widget.Button
2323
import android.widget.LinearLayout
2424
import androidx.fragment.app.Fragment
2525
import androidx.fragment.app.FragmentActivity
26-
import androidx.fragment.testapp.doubleTransitionBug.DoubleTransitionBugActivity
27-
import androidx.fragment.testapp.kittenfragmenttransitions.KittenTransitionMainActivity
26+
import androidx.fragment.testapp.doubleTransitionBug.DoubleTransitionBugFragment
27+
import androidx.fragment.testapp.kittenfragmenttransitions.KittenTransitionMainFragment
2828

2929
class TransitionTestsFragment : Fragment(R.layout.transition_fragment) {
3030
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
3131

32-
addButton("Double Transition Bug", DoubleTransitionBugActivity::class.java)
33-
addButton("Kitten Transition", KittenTransitionMainActivity::class.java)
32+
addButton("Double Transition Bug", DoubleTransitionBugFragment())
33+
addButton("Kitten Transition", KittenTransitionMainFragment())
3434
}
3535
}
3636

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2023 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package androidx.fragment.testapp.basicAnimators
18+
19+
import android.graphics.Color
20+
import android.os.Bundle
21+
import android.view.LayoutInflater
22+
import android.view.View
23+
import android.view.ViewGroup
24+
import android.widget.Button
25+
import androidx.annotation.ColorInt
26+
import androidx.core.os.bundleOf
27+
import androidx.fragment.app.Fragment
28+
import androidx.fragment.app.commit
29+
import androidx.fragment.testapp.R
30+
31+
class BasicFragmentAnimatorFragment : Fragment(R.layout.basic_animators_main) {
32+
private var count = 0
33+
34+
override fun onCreateView(
35+
inflater: LayoutInflater,
36+
container: ViewGroup?,
37+
savedInstanceState: Bundle?
38+
): View? {
39+
if (savedInstanceState == null) {
40+
parentFragmentManager.beginTransaction()
41+
.setPrimaryNavigationFragment(this)
42+
.commit()
43+
childFragmentManager.commit {
44+
add(R.id.content, Fragment(R.layout.basic_animator_fragment))
45+
}
46+
}
47+
48+
return super.onCreateView(inflater, container, savedInstanceState)
49+
}
50+
51+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
52+
super.onViewCreated(view, savedInstanceState)
53+
54+
view.findViewById<Button>(R.id.next_button).setOnClickListener {
55+
switchFragment()
56+
}
57+
}
58+
59+
private fun switchFragment() {
60+
val fragment = MainFragment()
61+
fragment.arguments = bundleOf("myarg" to when (count % 6) {
62+
1 -> { Color.GREEN }
63+
2 -> { Color.RED }
64+
3 -> { Color.YELLOW }
65+
4 -> { Color.GRAY }
66+
5 -> { Color.MAGENTA }
67+
else -> {
68+
Color.BLUE
69+
}
70+
})
71+
72+
count++
73+
74+
childFragmentManager.beginTransaction()
75+
.setCustomAnimations(
76+
androidx.fragment.R.animator.fragment_close_enter,
77+
androidx.fragment.R.animator.fragment_close_exit,
78+
androidx.fragment.R.animator.fragment_close_enter,
79+
androidx.fragment.R.animator.fragment_close_exit,
80+
)
81+
.setReorderingAllowed(true)
82+
.replace(R.id.content, fragment)
83+
.addToBackStack(null)
84+
.commit()
85+
}
86+
87+
class MainFragment : Fragment(R.layout.basic_animator_fragment) {
88+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
89+
super.onViewCreated(view, savedInstanceState)
90+
@ColorInt val myarg = arguments?.getInt("myarg") ?: Color.RED
91+
92+
view.setBackgroundColor(myarg)
93+
}
94+
}
95+
}
+8-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 The Android Open Source Project
2+
* Copyright 2023 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,28 +20,29 @@ import android.os.Bundle
2020
import android.view.Gravity
2121
import android.widget.Button
2222
import androidx.fragment.app.Fragment
23-
import androidx.fragment.app.FragmentActivity
2423
import androidx.fragment.app.commit
2524
import androidx.fragment.testapp.R
2625
import androidx.transition.Fade
2726
import androidx.transition.Slide
2827

29-
class DoubleTransitionBugActivity : FragmentActivity(R.layout.double_transition_bug_activity_main) {
28+
class DoubleTransitionBugFragment : Fragment(R.layout.double_transition_bug_activity_main) {
3029

3130
override fun onCreate(savedInstanceState: Bundle?) {
3231
super.onCreate(savedInstanceState)
3332

3433
if (savedInstanceState == null) {
35-
supportFragmentManager.commit {
34+
childFragmentManager.commit {
3635
add(R.id.content, Fragment(R.layout.double_transition_bug_fragment_second))
3736
}
3837
}
3938

40-
findViewById<Button>(R.id.important_button).setOnClickListener { switchFragment() }
39+
requireActivity().findViewById<Button>(R.id.important_button).setOnClickListener {
40+
switchFragment()
41+
}
4142
}
4243

4344
private fun switchFragment() {
44-
val currentFragment = supportFragmentManager.findFragmentById(R.id.content)
45+
val currentFragment = childFragmentManager.findFragmentById(R.id.content)
4546

4647
currentFragment!!.exitTransition = Fade()
4748

@@ -51,7 +52,7 @@ class DoubleTransitionBugActivity : FragmentActivity(R.layout.double_transition_
5152
val first = Fragment(R.layout.double_transition_bug_fragment_first)
5253
first.enterTransition = Fade().setDuration(5000)
5354

54-
supportFragmentManager.beginTransaction()
55+
childFragmentManager.beginTransaction()
5556
.setReorderingAllowed(true)
5657
.add(R.id.content, first)
5758
.add(R.id.content, second)
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 The Android Open Source Project
2+
* Copyright 2023 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,10 +15,10 @@
1515
*/
1616
package androidx.fragment.testapp.kittenfragmenttransitions
1717

18-
import androidx.fragment.app.FragmentActivity
18+
import androidx.fragment.app.Fragment
1919
import androidx.fragment.testapp.R
2020

2121
/**
2222
* Main activity that holds our fragments
2323
*/
24-
class KittenTransitionMainActivity : FragmentActivity(R.layout.kitten_activity_main)
24+
class KittenTransitionMainFragment : Fragment(R.layout.kitten_activity_main)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2023 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
19+
android:layout_width="match_parent"
20+
android:layout_height="match_parent">
21+
22+
<FrameLayout
23+
android:id="@+id/content"
24+
android:layout_width="match_parent"
25+
android:layout_height="match_parent"/>
26+
27+
</FrameLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2023 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
19+
android:layout_width="match_parent"
20+
android:layout_height="match_parent">
21+
22+
<FrameLayout
23+
android:id="@+id/content"
24+
android:layout_width="match_parent"
25+
android:layout_height="match_parent"/>
26+
27+
<Button
28+
android:id="@+id/next_button"
29+
android:layout_gravity="center"
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:text="Next" />
33+
34+
</FrameLayout>

0 commit comments

Comments
 (0)