aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-prod (mdb) <android-build-team-robot@google.com>2020-04-07 21:38:03 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-04-07 21:38:03 +0000
commit71ec73234213ed1ea6a4697884e5f8f29b8f1804 (patch)
tree055d7dc7c8f4e9aec80c3e190c0e1155cc71028b
parent927b02e2bbf0fa6eca80b8c91e6b6a4748e2be80 (diff)
parentdad28a8eb34f7f9aad66758017a41840118d1822 (diff)
downloadsupport-snap-temp-L62100000674737214.tar.gz
Merge "Merge cherrypicks of [1280289, 1280290, 1280291, 1281232, 1281233, 1280216, 1281234, 1281235] into androidx-preference-release" into androidx-preference-releasesnap-temp-L95400000731027645snap-temp-L86600000600203557snap-temp-L73900000674721054snap-temp-L62100000674737214snap-temp-L56500000675461586snap-temp-L13100000674277159
-rw-r--r--buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt2
-rw-r--r--preference/preference-ktx/build.gradle6
-rw-r--r--preference/preference/build.gradle3
-rw-r--r--preference/preference/src/androidTest/java/androidx/preference/tests/PreferenceDialogFragmentCompatTest.kt120
-rw-r--r--preference/preference/src/androidTest/res/layout/inflated_fragment_container_view.xml29
-rw-r--r--preference/preference/src/androidTest/res/layout/inflated_fragment_tag.xml27
-rw-r--r--preference/preference/src/androidTest/res/layout/simple_layout.xml22
-rw-r--r--preference/preference/src/androidTest/res/xml/test_fragment_container_dialog_preference.xml21
-rw-r--r--preference/preference/src/androidTest/res/xml/test_fragment_tag_dialog_preference.xml21
-rw-r--r--preference/preference/src/main/java/androidx/preference/PreferenceDialogFragmentCompat.java4
-rw-r--r--preference/preference/src/main/java/androidx/preference/PreferenceFragmentCompat.java4
11 files changed, 252 insertions, 7 deletions
diff --git a/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt b/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
index f5adde45732..4358776259d 100644
--- a/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
@@ -82,7 +82,7 @@ object LibraryVersions {
val PRINT = Version("1.1.0-alpha01")
val PERCENTLAYOUT = Version("1.1.0-alpha01")
val PERSISTENCE = Version("2.0.1")
- val PREFERENCE = Version("1.1.0")
+ val PREFERENCE = Version("1.1.1")
val RECOMMENDATION = Version("1.1.0-alpha01")
val RECYCLERVIEW = Version("1.1.0-alpha07")
val REMOTECALLBACK = Version("1.0.0-alpha02")
diff --git a/preference/preference-ktx/build.gradle b/preference/preference-ktx/build.gradle
index 57fdce284d8..f66d8924e46 100644
--- a/preference/preference-ktx/build.gradle
+++ b/preference/preference-ktx/build.gradle
@@ -41,6 +41,12 @@ android {
dependencies {
api(project(":preference:preference"))
+ api("androidx.core:core-ktx:1.1.0") {
+ because 'Mirror preference dependency graph for -ktx artifacts'
+ }
+ api("androidx.fragment:fragment-ktx:1.2.4") {
+ because 'Mirror preference dependency graph for -ktx artifacts'
+ }
api(KOTLIN_STDLIB)
androidTestImplementation(JUNIT)
diff --git a/preference/preference/build.gradle b/preference/preference/build.gradle
index eb7d29e8704..72ae0ec488c 100644
--- a/preference/preference/build.gradle
+++ b/preference/preference/build.gradle
@@ -30,7 +30,7 @@ dependencies {
api("androidx.appcompat:appcompat:1.1.0")
api("androidx.core:core:1.1.0")
implementation("androidx.collection:collection:1.0.0")
- api("androidx.fragment:fragment:1.1.0")
+ api("androidx.fragment:fragment:1.2.4")
api("androidx.recyclerview:recyclerview:1.0.0")
androidTestImplementation(ANDROIDX_TEST_EXT_JUNIT)
@@ -41,6 +41,7 @@ dependencies {
androidTestImplementation(MOCKITO_CORE, libs.exclude_bytebuddy) // DexMaker has it"s own MockMaker
androidTestImplementation(DEXMAKER_MOCKITO, libs.exclude_bytebuddy) // DexMaker has it"s own MockMaker
androidTestImplementation(KOTLIN_STDLIB)
+ androidTestImplementation(TRUTH)
}
android {
diff --git a/preference/preference/src/androidTest/java/androidx/preference/tests/PreferenceDialogFragmentCompatTest.kt b/preference/preference/src/androidTest/java/androidx/preference/tests/PreferenceDialogFragmentCompatTest.kt
new file mode 100644
index 00000000000..258681aefbb
--- /dev/null
+++ b/preference/preference/src/androidTest/java/androidx/preference/tests/PreferenceDialogFragmentCompatTest.kt
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.preference.tests
+
+import android.content.Context
+import android.os.Bundle
+import android.util.AttributeSet
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.DialogFragment
+import androidx.fragment.app.Fragment
+import androidx.preference.DialogPreference
+import androidx.preference.Preference
+import androidx.preference.PreferenceDialogFragmentCompat
+import androidx.preference.PreferenceFragmentCompat
+import androidx.preference.test.R
+import androidx.preference.tests.helpers.PreferenceTestHelperActivity
+import androidx.test.filters.LargeTest
+import androidx.test.rule.ActivityTestRule
+import com.google.common.truth.Truth.assertWithMessage
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+
+@LargeTest
+@RunWith(Parameterized::class)
+class PreferenceDialogFragmentCompatTest(private val xmlLayoutId: Int) {
+
+ companion object {
+ @JvmStatic
+ @Parameterized.Parameters(name = "xmlLayoutId={0}")
+ fun data(): Array<Int> {
+ return arrayOf(
+ R.xml.test_fragment_container_dialog_preference,
+ R.xml.test_fragment_tag_dialog_preference
+ )
+ }
+ }
+
+ @get:Rule
+ val activityTestRule = ActivityTestRule(PreferenceTestHelperActivity::class.java)
+
+ @Test
+ fun testInflatedChildDialogFragment() {
+ val fm = activityTestRule.activity.supportFragmentManager
+ lateinit var fragment: InflatedFragment
+
+ activityTestRule.runOnUiThread {
+ fragment = InflatedFragment(xmlLayoutId)
+
+ fm.beginTransaction()
+ .add(fragment, null)
+ .commitNow()
+ }
+
+ // Show the dialog
+ fragment.preferenceManager.showDialog(fragment.preferenceManager.findPreference("key"))
+
+ // Assert on UI thread so we wait for the dialog to show
+ activityTestRule.runOnUiThread {
+ assertWithMessage("The inflated child fragment should not be null")
+ .that(fragment.dialogFragment.childFragmentManager.findFragmentByTag("fragment1"))
+ .isNotNull()
+ }
+ }
+}
+
+class InflatedFragment(val xmlLayoutId: Int) : PreferenceFragmentCompat() {
+
+ lateinit var dialogFragment: DialogFragment
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ setPreferencesFromResource(xmlLayoutId, rootKey)
+ }
+
+ override fun onDisplayPreferenceDialog(preference: Preference) {
+ dialogFragment = DialogFragment(preference.key)
+ .also { it.setTargetFragment(this, 0) }
+ .also { it.show(parentFragmentManager, null) }
+ }
+}
+
+class NestedFragment : Fragment(R.layout.simple_layout)
+
+class TestFragmentContainerViewDialogPreference(context: Context?, attrs: AttributeSet?) :
+ DialogPreference(context, attrs) {
+ init { dialogLayoutResource = R.layout.inflated_fragment_container_view }
+}
+
+class TestFragmentTagDialogPreference(context: Context?, attrs: AttributeSet?) :
+ DialogPreference(context, attrs) {
+ init { dialogLayoutResource = R.layout.inflated_fragment_tag }
+}
+
+class DialogFragment(val key: String) : PreferenceDialogFragmentCompat() {
+ init { arguments = Bundle(1).apply { putString(ARG_KEY, key) } }
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ return inflater.inflate(R.layout.simple_layout, container, false)
+ }
+ override fun onDialogClosed(positiveResult: Boolean) {}
+} \ No newline at end of file
diff --git a/preference/preference/src/androidTest/res/layout/inflated_fragment_container_view.xml b/preference/preference/src/androidTest/res/layout/inflated_fragment_container_view.xml
new file mode 100644
index 00000000000..391deda3f99
--- /dev/null
+++ b/preference/preference/src/androidTest/res/layout/inflated_fragment_container_view.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/inflated_container_parent"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <androidx.fragment.app.FragmentContainerView
+ android:id="@+id/fragment_container_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:name="androidx.preference.tests.NestedFragment"
+ android:tag="fragment1"/>
+</FrameLayout>
diff --git a/preference/preference/src/androidTest/res/layout/inflated_fragment_tag.xml b/preference/preference/src/androidTest/res/layout/inflated_fragment_tag.xml
new file mode 100644
index 00000000000..09bc8d82539
--- /dev/null
+++ b/preference/preference/src/androidTest/res/layout/inflated_fragment_tag.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ <fragment android:name="androidx.preference.tests.NestedFragment"
+ android:id="@+id/child_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:tag="fragment1"/>
+</FrameLayout> \ No newline at end of file
diff --git a/preference/preference/src/androidTest/res/layout/simple_layout.xml b/preference/preference/src/androidTest/res/layout/simple_layout.xml
new file mode 100644
index 00000000000..08b334d72be
--- /dev/null
+++ b/preference/preference/src/androidTest/res/layout/simple_layout.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical" android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+</FrameLayout> \ No newline at end of file
diff --git a/preference/preference/src/androidTest/res/xml/test_fragment_container_dialog_preference.xml b/preference/preference/src/androidTest/res/xml/test_fragment_container_dialog_preference.xml
new file mode 100644
index 00000000000..2bc7c5e7a8f
--- /dev/null
+++ b/preference/preference/src/androidTest/res/xml/test_fragment_container_dialog_preference.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+ <androidx.preference.tests.TestFragmentContainerViewDialogPreference
+ android:key="key"
+ android:title="launch a preference"/>
+</androidx.preference.PreferenceScreen>
diff --git a/preference/preference/src/androidTest/res/xml/test_fragment_tag_dialog_preference.xml b/preference/preference/src/androidTest/res/xml/test_fragment_tag_dialog_preference.xml
new file mode 100644
index 00000000000..b0c40f27ced
--- /dev/null
+++ b/preference/preference/src/androidTest/res/xml/test_fragment_tag_dialog_preference.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+ <androidx.preference.tests.TestFragmentTagDialogPreference
+ android:key="key"
+ android:title="launch a preference"/>
+</androidx.preference.PreferenceScreen>
diff --git a/preference/preference/src/main/java/androidx/preference/PreferenceDialogFragmentCompat.java b/preference/preference/src/main/java/androidx/preference/PreferenceDialogFragmentCompat.java
index 8877f1be101..850cd0ebab0 100644
--- a/preference/preference/src/main/java/androidx/preference/PreferenceDialogFragmentCompat.java
+++ b/preference/preference/src/main/java/androidx/preference/PreferenceDialogFragmentCompat.java
@@ -27,7 +27,6 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
-import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
@@ -224,8 +223,7 @@ public abstract class PreferenceDialogFragmentCompat extends DialogFragment impl
return null;
}
- LayoutInflater inflater = LayoutInflater.from(context);
- return inflater.inflate(resId, null);
+ return getLayoutInflater().inflate(resId, null);
}
/**
diff --git a/preference/preference/src/main/java/androidx/preference/PreferenceFragmentCompat.java b/preference/preference/src/main/java/androidx/preference/PreferenceFragmentCompat.java
index 36420d6ae1e..9e982cdfabe 100644
--- a/preference/preference/src/main/java/androidx/preference/PreferenceFragmentCompat.java
+++ b/preference/preference/src/main/java/androidx/preference/PreferenceFragmentCompat.java
@@ -592,7 +592,7 @@ public abstract class PreferenceFragmentCompat extends Fragment implements
}
// check if dialog is already showing
- if (getFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) {
+ if (getParentFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) {
return;
}
@@ -611,7 +611,7 @@ public abstract class PreferenceFragmentCompat extends Fragment implements
+ "displaying a custom dialog for this Preference.");
}
f.setTargetFragment(this, 0);
- f.show(getFragmentManager(), DIALOG_FRAGMENT_TAG);
+ f.show(getParentFragmentManager(), DIALOG_FRAGMENT_TAG);
}
/**