Merge "Update KSP to 1.4.10-dev-experimental-20201110" into androidx-master-dev
diff --git a/androidx-plugin/gradle-plugin/build.gradle b/androidx-plugin/gradle-plugin/build.gradle
index 1c56a16..3e45bc0 100644
--- a/androidx-plugin/gradle-plugin/build.gradle
+++ b/androidx-plugin/gradle-plugin/build.gradle
@@ -59,5 +59,9 @@
id = "AndroidXPlugin"
implementationClass = "androidx.build.AndroidXPlugin"
}
+ AndroidXUiPlugin {
+ id = "AndroidXUiPlugin"
+ implementationClass = "androidx.build.AndroidXUiPlugin"
+ }
}
}
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AnnotationProcessorTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AnnotationProcessorTest.java
index 04ae3f3..885811f 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AnnotationProcessorTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AnnotationProcessorTest.java
@@ -18,9 +18,9 @@
import static androidx.appsearch.app.AppSearchSchema.PropertyConfig.INDEXING_TYPE_PREFIXES;
import static androidx.appsearch.app.AppSearchSchema.PropertyConfig.TOKENIZER_TYPE_PLAIN;
-import static androidx.appsearch.app.AppSearchTestUtils.checkIsBatchResultSuccess;
-import static androidx.appsearch.app.AppSearchTestUtils.checkIsResultSuccess;
-import static androidx.appsearch.app.AppSearchTestUtils.convertSearchResultsToDocuments;
+import static androidx.appsearch.app.util.AppSearchTestUtils.checkIsBatchResultSuccess;
+import static androidx.appsearch.app.util.AppSearchTestUtils.checkIsResultSuccess;
+import static androidx.appsearch.app.util.AppSearchTestUtils.convertSearchResultsToDocuments;
import static com.google.common.truth.Truth.assertThat;
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/SearchSpecTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/SearchSpecTest.java
index 0d2dae4..7dbc7b9 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/SearchSpecTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/SearchSpecTest.java
@@ -18,49 +18,12 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
-
import android.os.Bundle;
import org.junit.Test;
public class SearchSpecTest {
@Test
- public void buildSearchSpecWithoutTermMatchType() {
- assertThrows(RuntimeException.class, () -> new SearchSpec.Builder()
- .addSchemaType("testSchemaType")
- .build());
- }
-
- @Test
- public void testBuildSearchSpec() {
- SearchSpec searchSpec = new SearchSpec.Builder()
- .setTermMatch(SearchSpec.TERM_MATCH_PREFIX)
- .addNamespace("namespace1", "namespace2")
- .addSchemaType("schemaTypes1", "schemaTypes2")
- .setSnippetCount(5)
- .setSnippetCountPerProperty(10)
- .setMaxSnippetSize(15)
- .setNumPerPage(42)
- .setOrder(SearchSpec.ORDER_ASCENDING)
- .setRankingStrategy(SearchSpec.RANKING_STRATEGY_DOCUMENT_SCORE)
- .build();
-
- assertThat(searchSpec.getTermMatch()).isEqualTo(SearchSpec.TERM_MATCH_PREFIX);
- assertThat(searchSpec.getNamespaces())
- .containsExactly("namespace1", "namespace2").inOrder();
- assertThat(searchSpec.getSchemaTypes())
- .containsExactly("schemaTypes1", "schemaTypes2").inOrder();
- assertThat(searchSpec.getSnippetCount()).isEqualTo(5);
- assertThat(searchSpec.getSnippetCountPerProperty()).isEqualTo(10);
- assertThat(searchSpec.getMaxSnippetSize()).isEqualTo(15);
- assertThat(searchSpec.getNumPerPage()).isEqualTo(42);
- assertThat(searchSpec.getOrder()).isEqualTo(SearchSpec.ORDER_ASCENDING);
- assertThat(searchSpec.getRankingStrategy())
- .isEqualTo(SearchSpec.RANKING_STRATEGY_DOCUMENT_SCORE);
- }
-
- @Test
public void testGetBundle() {
SearchSpec searchSpec = new SearchSpec.Builder()
.setTermMatch(SearchSpec.TERM_MATCH_PREFIX)
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AppSearchResultTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/AppSearchResultCtsTest.java
similarity index 95%
rename from appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AppSearchResultTest.java
rename to appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/AppSearchResultCtsTest.java
index 11264e5..740208f 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AppSearchResultTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/AppSearchResultCtsTest.java
@@ -14,13 +14,15 @@
* limitations under the License.
*/
-package androidx.appsearch.app;
+package androidx.appsearch.app.cts;
import static com.google.common.truth.Truth.assertThat;
+import androidx.appsearch.app.AppSearchResult;
+
import org.junit.Test;
-public class AppSearchResultTest {
+public class AppSearchResultCtsTest {
@Test
public void testResultEquals_Identical() {
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AppSearchSchemaTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/AppSearchSchemaCtsTest.java
similarity index 95%
rename from appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AppSearchSchemaTest.java
rename to appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/AppSearchSchemaCtsTest.java
index f8e6c94..ba04b58 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AppSearchSchemaTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/AppSearchSchemaCtsTest.java
@@ -14,19 +14,20 @@
* limitations under the License.
*/
-package androidx.appsearch.app;
+package androidx.appsearch.app.cts;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
+import androidx.appsearch.app.AppSearchSchema;
import androidx.appsearch.app.AppSearchSchema.PropertyConfig;
import androidx.appsearch.exceptions.IllegalSchemaException;
import org.junit.Test;
-public class AppSearchSchemaTest {
+public class AppSearchSchemaCtsTest {
@Test
public void testInvalidEnums() {
PropertyConfig.Builder builder = new PropertyConfig.Builder("test");
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AppSearchSessionTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/AppSearchSessionCtsTest.java
similarity index 97%
rename from appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AppSearchSessionTest.java
rename to appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/AppSearchSessionCtsTest.java
index d97a706..10eb6f1 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AppSearchSessionTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/AppSearchSessionCtsTest.java
@@ -14,19 +14,32 @@
* limitations under the License.
*/
-package androidx.appsearch.app;
+package androidx.appsearch.app.cts;
-import static androidx.appsearch.app.AppSearchTestUtils.checkIsBatchResultSuccess;
-import static androidx.appsearch.app.AppSearchTestUtils.checkIsResultSuccess;
-import static androidx.appsearch.app.AppSearchTestUtils.convertSearchResultsToDocuments;
-import static androidx.appsearch.app.AppSearchTestUtils.doGet;
+import static androidx.appsearch.app.util.AppSearchTestUtils.checkIsBatchResultSuccess;
+import static androidx.appsearch.app.util.AppSearchTestUtils.checkIsResultSuccess;
+import static androidx.appsearch.app.util.AppSearchTestUtils.convertSearchResultsToDocuments;
+import static androidx.appsearch.app.util.AppSearchTestUtils.doGet;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
+import androidx.appsearch.app.AppSearchBatchResult;
+import androidx.appsearch.app.AppSearchEmail;
+import androidx.appsearch.app.AppSearchResult;
+import androidx.appsearch.app.AppSearchSchema;
import androidx.appsearch.app.AppSearchSchema.PropertyConfig;
-import androidx.appsearch.app.customer.EmailDataClass;
+import androidx.appsearch.app.AppSearchSession;
+import androidx.appsearch.app.GenericDocument;
+import androidx.appsearch.app.GetByUriRequest;
+import androidx.appsearch.app.PutDocumentsRequest;
+import androidx.appsearch.app.RemoveByUriRequest;
+import androidx.appsearch.app.SearchResult;
+import androidx.appsearch.app.SearchResults;
+import androidx.appsearch.app.SearchSpec;
+import androidx.appsearch.app.SetSchemaRequest;
+import androidx.appsearch.app.cts.customer.EmailDataClass;
import androidx.appsearch.localstorage.LocalStorage;
import androidx.test.core.app.ApplicationProvider;
@@ -38,7 +51,7 @@
import java.util.List;
import java.util.Set;
-public class AppSearchSessionTest {
+public class AppSearchSessionCtsTest {
private AppSearchSession mDb1;
private AppSearchSession mDb2;
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/GenericDocumentTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/GenericDocumentCtsTest.java
similarity index 88%
rename from appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/GenericDocumentTest.java
rename to appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/GenericDocumentCtsTest.java
index 36a987e..6340517 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/GenericDocumentTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/GenericDocumentCtsTest.java
@@ -14,29 +14,31 @@
* limitations under the License.
*/
-package androidx.appsearch.app;
+package androidx.appsearch.app.cts;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
+import androidx.appsearch.app.GenericDocument;
+
import org.junit.Test;
-public class GenericDocumentTest {
+public class GenericDocumentCtsTest {
private static final byte[] sByteArray1 = new byte[]{(byte) 1, (byte) 2, (byte) 3};
private static final byte[] sByteArray2 = new byte[]{(byte) 4, (byte) 5, (byte) 6, (byte) 7};
private static final GenericDocument sDocumentProperties1 = new GenericDocument
- .Builder("sDocumentProperties1", "sDocumentPropertiesSchemaType1")
+ .Builder<>("sDocumentProperties1", "sDocumentPropertiesSchemaType1")
.setCreationTimestampMillis(12345L)
.build();
private static final GenericDocument sDocumentProperties2 = new GenericDocument
- .Builder("sDocumentProperties2", "sDocumentPropertiesSchemaType2")
+ .Builder<>("sDocumentProperties2", "sDocumentPropertiesSchemaType2")
.setCreationTimestampMillis(6789L)
.build();
@Test
public void testDocumentEquals_Identical() {
- GenericDocument document1 = new GenericDocument.Builder("uri1", "schemaType1")
+ GenericDocument document1 = new GenericDocument.Builder<>("uri1", "schemaType1")
.setCreationTimestampMillis(5L)
.setTtlMillis(1L)
.setPropertyLong("longKey1", 1L, 2L, 3L)
@@ -46,7 +48,7 @@
.setPropertyBytes("byteKey1", sByteArray1, sByteArray2)
.setPropertyDocument("documentKey1", sDocumentProperties1, sDocumentProperties2)
.build();
- GenericDocument document2 = new GenericDocument.Builder("uri1", "schemaType1")
+ GenericDocument document2 = new GenericDocument.Builder<>("uri1", "schemaType1")
.setCreationTimestampMillis(5L)
.setTtlMillis(1L)
.setPropertyLong("longKey1", 1L, 2L, 3L)
@@ -62,7 +64,7 @@
@Test
public void testDocumentEquals_DifferentOrder() {
- GenericDocument document1 = new GenericDocument.Builder("uri1", "schemaType1")
+ GenericDocument document1 = new GenericDocument.Builder<>("uri1", "schemaType1")
.setCreationTimestampMillis(5L)
.setPropertyLong("longKey1", 1L, 2L, 3L)
.setPropertyBytes("byteKey1", sByteArray1, sByteArray2)
@@ -73,7 +75,7 @@
.build();
// Create second document with same parameter but different order.
- GenericDocument document2 = new GenericDocument.Builder("uri1", "schemaType1")
+ GenericDocument document2 = new GenericDocument.Builder<>("uri1", "schemaType1")
.setCreationTimestampMillis(5L)
.setPropertyBoolean("booleanKey1", true, false, true)
.setPropertyDocument("documentKey1", sDocumentProperties1, sDocumentProperties2)
@@ -88,13 +90,13 @@
@Test
public void testDocumentEquals_Failure() {
- GenericDocument document1 = new GenericDocument.Builder("uri1", "schemaType1")
+ GenericDocument document1 = new GenericDocument.Builder<>("uri1", "schemaType1")
.setCreationTimestampMillis(5L)
.setPropertyLong("longKey1", 1L, 2L, 3L)
.build();
// Create second document with same order but different value.
- GenericDocument document2 = new GenericDocument.Builder("uri1", "schemaType1")
+ GenericDocument document2 = new GenericDocument.Builder<>("uri1", "schemaType1")
.setCreationTimestampMillis(5L)
.setPropertyLong("longKey1", 1L, 2L, 4L) // Different
.build();
@@ -104,13 +106,13 @@
@Test
public void testDocumentEquals_Failure_RepeatedFieldOrder() {
- GenericDocument document1 = new GenericDocument.Builder("uri1", "schemaType1")
+ GenericDocument document1 = new GenericDocument.Builder<>("uri1", "schemaType1")
.setCreationTimestampMillis(5L)
.setPropertyBoolean("booleanKey1", true, false, true)
.build();
// Create second document with same order but different value.
- GenericDocument document2 = new GenericDocument.Builder("uri1", "schemaType1")
+ GenericDocument document2 = new GenericDocument.Builder<>("uri1", "schemaType1")
.setCreationTimestampMillis(5L)
.setPropertyBoolean("booleanKey1", true, true, false) // Different
.build();
@@ -120,7 +122,7 @@
@Test
public void testDocumentGetSingleValue() {
- GenericDocument document = new GenericDocument.Builder("uri1", "schemaType1")
+ GenericDocument document = new GenericDocument.Builder<>("uri1", "schemaType1")
.setCreationTimestampMillis(5L)
.setScore(1)
.setTtlMillis(1L)
@@ -147,7 +149,7 @@
@Test
public void testDocumentGetArrayValues() {
- GenericDocument document = new GenericDocument.Builder("uri1", "schemaType1")
+ GenericDocument document = new GenericDocument.Builder<>("uri1", "schemaType1")
.setCreationTimestampMillis(5L)
.setPropertyLong("longKey1", 1L, 2L, 3L)
.setPropertyDouble("doubleKey1", 1.0, 2.0, 3.0)
@@ -173,8 +175,8 @@
}
@Test
- public void testDocument_ToString() throws Exception {
- GenericDocument document = new GenericDocument.Builder("uri1", "schemaType1")
+ public void testDocument_ToString() {
+ GenericDocument document = new GenericDocument.Builder<>("uri1", "schemaType1")
.setCreationTimestampMillis(5L)
.setPropertyLong("longKey1", 1L, 2L, 3L)
.setPropertyDouble("doubleKey1", 1.0, 2.0, 3.0)
@@ -217,7 +219,7 @@
@Test
public void testDocumentGetValues_DifferentTypes() {
- GenericDocument document = new GenericDocument.Builder("uri1", "schemaType1")
+ GenericDocument document = new GenericDocument.Builder<>("uri1", "schemaType1")
.setScore(1)
.setPropertyLong("longKey1", 1L)
.setPropertyBoolean("booleanKey1", true, false, true)
@@ -244,7 +246,7 @@
@Test
public void testDocumentInvalid() {
- GenericDocument.Builder builder = new GenericDocument.Builder("uri1", "schemaType1");
+ GenericDocument.Builder<?> builder = new GenericDocument.Builder<>("uri1", "schemaType1");
assertThrows(
IllegalArgumentException.class,
() -> builder.setPropertyBoolean("test", new boolean[]{}));
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/GlobalSearchSessionTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/GlobalSearchSessionCtsTest.java
similarity index 93%
rename from appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/GlobalSearchSessionTest.java
rename to appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/GlobalSearchSessionCtsTest.java
index b06ccfa..75363d0 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/GlobalSearchSessionTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/GlobalSearchSessionCtsTest.java
@@ -14,17 +14,27 @@
* limitations under the License.
*/
-package androidx.appsearch.app;
+package androidx.appsearch.app.cts;
-import static androidx.appsearch.app.AppSearchTestUtils.checkIsBatchResultSuccess;
-import static androidx.appsearch.app.AppSearchTestUtils.checkIsResultSuccess;
-import static androidx.appsearch.app.AppSearchTestUtils.convertSearchResultsToDocuments;
+import static androidx.appsearch.app.util.AppSearchTestUtils.checkIsBatchResultSuccess;
+import static androidx.appsearch.app.util.AppSearchTestUtils.checkIsResultSuccess;
+import static androidx.appsearch.app.util.AppSearchTestUtils.convertSearchResultsToDocuments;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
+import androidx.appsearch.app.AppSearchEmail;
+import androidx.appsearch.app.AppSearchSchema;
import androidx.appsearch.app.AppSearchSchema.PropertyConfig;
+import androidx.appsearch.app.AppSearchSession;
+import androidx.appsearch.app.GenericDocument;
+import androidx.appsearch.app.GlobalSearchSession;
+import androidx.appsearch.app.PutDocumentsRequest;
+import androidx.appsearch.app.SearchResult;
+import androidx.appsearch.app.SearchResults;
+import androidx.appsearch.app.SearchSpec;
+import androidx.appsearch.app.SetSchemaRequest;
import androidx.appsearch.localstorage.LocalStorage;
import androidx.test.core.app.ApplicationProvider;
@@ -36,7 +46,7 @@
import java.util.List;
import java.util.Set;
-public class GlobalSearchSessionTest {
+public class GlobalSearchSessionCtsTest {
private AppSearchSession mDb1;
private AppSearchSession mDb2;
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/SearchSpecCtsTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/SearchSpecCtsTest.java
new file mode 100644
index 0000000..d9eca0a
--- /dev/null
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/SearchSpecCtsTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.appsearch.app.cts;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.junit.Assert.assertThrows;
+
+import androidx.appsearch.app.SearchSpec;
+
+import org.junit.Test;
+
+public class SearchSpecCtsTest {
+ @Test
+ public void buildSearchSpecWithoutTermMatchType() {
+ RuntimeException e = assertThrows(RuntimeException.class, () -> new SearchSpec.Builder()
+ .addSchemaType("testSchemaType")
+ .build());
+ assertThat(e).hasMessageThat().contains("Missing termMatchType field");
+ }
+
+ @Test
+ public void testBuildSearchSpec() {
+ SearchSpec searchSpec = new SearchSpec.Builder()
+ .setTermMatch(SearchSpec.TERM_MATCH_PREFIX)
+ .addNamespace("namespace1", "namespace2")
+ .addSchemaType("schemaTypes1", "schemaTypes2")
+ .setSnippetCount(5)
+ .setSnippetCountPerProperty(10)
+ .setMaxSnippetSize(15)
+ .setNumPerPage(42)
+ .setOrder(SearchSpec.ORDER_ASCENDING)
+ .setRankingStrategy(SearchSpec.RANKING_STRATEGY_DOCUMENT_SCORE)
+ .build();
+
+ assertThat(searchSpec.getTermMatch()).isEqualTo(SearchSpec.TERM_MATCH_PREFIX);
+ assertThat(searchSpec.getNamespaces())
+ .containsExactly("namespace1", "namespace2").inOrder();
+ assertThat(searchSpec.getSchemaTypes())
+ .containsExactly("schemaTypes1", "schemaTypes2").inOrder();
+ assertThat(searchSpec.getSnippetCount()).isEqualTo(5);
+ assertThat(searchSpec.getSnippetCountPerProperty()).isEqualTo(10);
+ assertThat(searchSpec.getMaxSnippetSize()).isEqualTo(15);
+ assertThat(searchSpec.getNumPerPage()).isEqualTo(42);
+ assertThat(searchSpec.getOrder()).isEqualTo(SearchSpec.ORDER_ASCENDING);
+ assertThat(searchSpec.getRankingStrategy())
+ .isEqualTo(SearchSpec.RANKING_STRATEGY_DOCUMENT_SCORE);
+ }
+}
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/customer/CustomerDocumentTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/customer/CustomerDocumentTest.java
similarity index 80%
rename from appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/customer/CustomerDocumentTest.java
rename to appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/customer/CustomerDocumentTest.java
index 3afbde4..07297fb 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/customer/CustomerDocumentTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/customer/CustomerDocumentTest.java
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-package androidx.appsearch.app.customer;
+package androidx.appsearch.app.cts.customer;
+
+import static com.google.common.truth.Truth.assertThat;
import androidx.annotation.NonNull;
import androidx.appsearch.app.GenericDocument;
-import static com.google.common.truth.Truth.assertThat;
-
import org.junit.Test;
/**
@@ -32,13 +32,13 @@
*/
public class CustomerDocumentTest {
- private static byte[] sByteArray1 = new byte[]{(byte) 1, (byte) 2, (byte) 3};
- private static byte[] sByteArray2 = new byte[]{(byte) 4, (byte) 5, (byte) 6};
- private static GenericDocument sDocumentProperties1 = new GenericDocument
- .Builder("sDocumentProperties1", "sDocumentPropertiesSchemaType1")
+ private static final byte[] BYTE_ARRAY1 = new byte[]{(byte) 1, (byte) 2, (byte) 3};
+ private static final byte[] BYTE_ARRAY2 = new byte[]{(byte) 4, (byte) 5, (byte) 6};
+ private static final GenericDocument DOCUMENT_PROPERTIES1 = new GenericDocument
+ .Builder<>("sDocumentProperties1", "sDocumentPropertiesSchemaType1")
.build();
- private static GenericDocument sDocumentProperties2 = new GenericDocument
- .Builder("sDocumentProperties2", "sDocumentPropertiesSchemaType2")
+ private static final GenericDocument DOCUMENT_PROPERTIES2 = new GenericDocument
+ .Builder<>("sDocumentProperties2", "sDocumentPropertiesSchemaType2")
.build();
@Test
@@ -50,8 +50,8 @@
.setPropertyDouble("doubleKey1", 1.0, 2.0, 3.0)
.setPropertyBoolean("booleanKey1", true, false, true)
.setPropertyString("stringKey1", "test-value1", "test-value2", "test-value3")
- .setPropertyBytes("byteKey1", sByteArray1, sByteArray2)
- .setPropertyDocument("documentKey1", sDocumentProperties1, sDocumentProperties2)
+ .setPropertyBytes("byteKey1", BYTE_ARRAY1, BYTE_ARRAY2)
+ .setPropertyDocument("documentKey1", DOCUMENT_PROPERTIES1, DOCUMENT_PROPERTIES2)
.build();
assertThat(customerDocument.getUri()).isEqualTo("uri1");
@@ -67,9 +67,9 @@
assertThat(customerDocument.getPropertyStringArray("stringKey1")).asList()
.containsExactly("test-value1", "test-value2", "test-value3");
assertThat(customerDocument.getPropertyBytesArray("byteKey1")).asList()
- .containsExactly(sByteArray1, sByteArray2);
+ .containsExactly(BYTE_ARRAY1, BYTE_ARRAY2);
assertThat(customerDocument.getPropertyDocumentArray("documentKey1")).asList()
- .containsExactly(sDocumentProperties1, sDocumentProperties2);
+ .containsExactly(DOCUMENT_PROPERTIES1, DOCUMENT_PROPERTIES2);
}
/**
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/customer/EmailDataClass.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/customer/EmailDataClass.java
similarity index 95%
rename from appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/customer/EmailDataClass.java
rename to appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/customer/EmailDataClass.java
index 5af881a..ffdaf2a 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/customer/EmailDataClass.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/cts/customer/EmailDataClass.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package androidx.appsearch.app.customer;
+package androidx.appsearch.app.cts.customer;
import androidx.appsearch.annotation.AppSearchDocument;
import androidx.appsearch.app.AppSearchSchema.PropertyConfig;
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AppSearchTestUtils.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/util/AppSearchTestUtils.java
similarity index 88%
rename from appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AppSearchTestUtils.java
rename to appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/util/AppSearchTestUtils.java
index 7b2ec59..fe176c8 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/AppSearchTestUtils.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/app/util/AppSearchTestUtils.java
@@ -14,10 +14,18 @@
* limitations under the License.
*/
-package androidx.appsearch.app;
+package androidx.appsearch.app.util;
import static com.google.common.truth.Truth.assertThat;
+import androidx.appsearch.app.AppSearchBatchResult;
+import androidx.appsearch.app.AppSearchResult;
+import androidx.appsearch.app.AppSearchSession;
+import androidx.appsearch.app.GenericDocument;
+import androidx.appsearch.app.GetByUriRequest;
+import androidx.appsearch.app.SearchResult;
+import androidx.appsearch.app.SearchResults;
+
import junit.framework.AssertionFailedError;
import java.util.ArrayList;
diff --git a/appsearch/local-storage/src/main/java/androidx/appsearch/localstorage/AppSearchImpl.java b/appsearch/local-storage/src/main/java/androidx/appsearch/localstorage/AppSearchImpl.java
index f787b51..43a27b1 100644
--- a/appsearch/local-storage/src/main/java/androidx/appsearch/localstorage/AppSearchImpl.java
+++ b/appsearch/local-storage/src/main/java/androidx/appsearch/localstorage/AppSearchImpl.java
@@ -63,7 +63,6 @@
import java.io.File;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -430,8 +429,9 @@
SearchResultProto searchResultProto;
mReadWriteLock.readLock().lock();
try {
- // rewriteSearchSpecForDatabases will return false if none of the databases have
- // documents, so we can return an empty SearchResult and skip sending request to Icing.
+ // rewriteSearchSpecForDatabases will return false if none of the databases that the
+ // client is trying to search on exist, so we can return an empty SearchResult and skip
+ // sending request to Icing.
// We use the mNamespaceMap.keySet here because it's the smaller set of valid databases
// that could exist.
if (!rewriteSearchSpecForDatabases(searchSpecBuilder, databases)) {
@@ -732,7 +732,7 @@
@NonNull SearchSpecProto.Builder searchSpecBuilder,
@NonNull Set<String> databaseNames) {
// Create a copy since retainAll() modifies the original set.
- Set<String> existingDatabases = new HashSet<>(mNamespaceMap.keySet());
+ Set<String> existingDatabases = new ArraySet<>(mNamespaceMap.keySet());
existingDatabases.retainAll(databaseNames);
if (existingDatabases.isEmpty()) {
@@ -750,17 +750,17 @@
// Rewrite filters to include a database prefix.
for (String databaseName : existingDatabases) {
Set<String> existingSchemaTypes = mSchemaMap.get(databaseName);
+ String databaseNamePrefix = getDatabasePrefix(databaseName);
if (schemaTypeFilters.isEmpty()) {
// Include all schema types
searchSpecBuilder.addAllSchemaTypeFilters(existingSchemaTypes);
} else {
// Qualify the given schema types
- for (String schemaType : schemaTypeFilters) {
- String qualifiedType = getDatabasePrefix(databaseName) + schemaType;
+ for (int i = 0; i < schemaTypeFilters.size(); i++) {
+ String qualifiedType = databaseNamePrefix + schemaTypeFilters.get(i);
if (existingSchemaTypes.contains(qualifiedType)) {
searchSpecBuilder.addSchemaTypeFilters(qualifiedType);
}
-
}
}
@@ -770,8 +770,8 @@
searchSpecBuilder.addAllNamespaceFilters(existingNamespaces);
} else {
// Qualify the given namespaces.
- for (String namespace : namespaceFilters) {
- String qualifiedNamespace = getDatabasePrefix(databaseName) + namespace;
+ for (int i = 0; i < namespaceFilters.size(); i++) {
+ String qualifiedNamespace = databaseNamePrefix + namespaceFilters.get(i);
if (existingNamespaces.contains(qualifiedNamespace)) {
searchSpecBuilder.addNamespaceFilters(qualifiedNamespace);
}
@@ -843,7 +843,7 @@
private void addToMap(Map<String, Set<String>> map, String databaseName, String prefixedValue) {
Set<String> values = map.get(databaseName);
if (values == null) {
- values = new HashSet<>();
+ values = new ArraySet<>();
map.put(databaseName, values);
}
values.add(prefixedValue);
diff --git a/benchmark/benchmark-macro-runtime/src/androidTest/AndroidManifest.xml b/benchmark/benchmark-macro-runtime/src/androidTest/AndroidManifest.xml
index 03b4e49..94ac2ba 100644
--- a/benchmark/benchmark-macro-runtime/src/androidTest/AndroidManifest.xml
+++ b/benchmark/benchmark-macro-runtime/src/androidTest/AndroidManifest.xml
@@ -27,4 +27,14 @@
<queries>
<package android:name="androidx.benchmark.integration.macro.target" />
</queries>
+ <application>
+ <activity
+ android:name="androidx.benchmark.macro.test.TrivialStartupActivity"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
</manifest>
diff --git a/benchmark/benchmark-macro-runtime/src/androidTest/java/androidx/benchmark/macro/test/AppStartupHelperTest.kt b/benchmark/benchmark-macro-runtime/src/androidTest/java/androidx/benchmark/macro/test/AppStartupHelperTest.kt
new file mode 100644
index 0000000..83103ce
--- /dev/null
+++ b/benchmark/benchmark-macro-runtime/src/androidTest/java/androidx/benchmark/macro/test/AppStartupHelperTest.kt
@@ -0,0 +1,81 @@
+/*
+ * 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.benchmark.macro.test
+
+import android.content.Intent
+import androidx.benchmark.macro.AppStartupHelper
+import androidx.benchmark.macro.MacrobenchmarkScope
+import androidx.benchmark.macro.withPermissiveSeLinuxPolicy
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.LargeTest
+import androidx.test.filters.MediumTest
+import androidx.test.filters.SdkSuppress
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertTrue
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@SdkSuppress(minSdkVersion = 29)
+@RunWith(AndroidJUnit4::class)
+class AppStartupHelperTest {
+ @MediumTest
+ @Test
+ fun noResults() = withPermissiveSeLinuxPolicy {
+ val helper = AppStartupHelper()
+ helper.startCollecting()
+ helper.stopCollecting()
+ // assert equals to get clearer error in exception
+ assertEquals(
+ listOf<AppStartupHelper.AppStartupMetrics>(),
+ helper.getMetricStructure("fake.package.fiction.nostartups")
+ )
+ }
+
+ /**
+ * Launch [TrivialStartupActivity], and validate we see startupFullyDrawnMs if
+ * [reportFullyDrawn] is `true`.
+ *
+ * Note that unlike an actual macrobenchmark, we're launching an activity in our own process,
+ * since we don't care about perf or profiling or anything, just that we can observe the launch.
+ */
+ private fun validateStartupResults(reportFullyDrawn: Boolean) = withPermissiveSeLinuxPolicy {
+ val packageName = "androidx.benchmark.macro.runtime.test"
+ val helper = AppStartupHelper()
+ helper.startCollecting()
+ val scope = MacrobenchmarkScope(packageName)
+ // note: don't killProcess first, that's our process too!
+ // additionally, skip pressHome, since it's not needed, and skipping saves significant time
+ scope.launchPackageAndWait {
+ it.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
+ it.putExtra(TrivialStartupActivity.EXTRA_REPORT_FULLY_DRAWN, reportFullyDrawn)
+ }
+ helper.stopCollecting()
+
+ val metricsMap = helper.getMetrics(packageName)
+ assertTrue(metricsMap.isNotEmpty())
+ assertTrue(metricsMap.containsKey("startupMs"))
+ assertEquals(reportFullyDrawn, metricsMap.containsKey("startupFullyDrawnMs"))
+ }
+
+ @LargeTest
+ @Test
+ fun startupMetrics_reportFullyDrawn_false() = validateStartupResults(false)
+
+ @LargeTest
+ @Test
+ fun startupMetrics_reportFullyDrawn_true() = validateStartupResults(true)
+}
\ No newline at end of file
diff --git a/benchmark/benchmark-macro-runtime/src/androidTest/java/androidx/benchmark/macro/test/TrivialStartupActivity.kt b/benchmark/benchmark-macro-runtime/src/androidTest/java/androidx/benchmark/macro/test/TrivialStartupActivity.kt
new file mode 100644
index 0000000..a07b0329
--- /dev/null
+++ b/benchmark/benchmark-macro-runtime/src/androidTest/java/androidx/benchmark/macro/test/TrivialStartupActivity.kt
@@ -0,0 +1,37 @@
+/*
+ * 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.benchmark.macro.test
+
+import android.app.Activity
+import android.os.Build
+import android.os.Bundle
+
+class TrivialStartupActivity : Activity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ if (intent.getBooleanExtra(EXTRA_REPORT_FULLY_DRAWN, true)) {
+ reportFullyDrawn()
+ }
+ }
+ }
+
+ companion object {
+ const val EXTRA_REPORT_FULLY_DRAWN = "REPORT_FULLY_DRAWN"
+ }
+}
diff --git a/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/Actions.kt b/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/Actions.kt
index 544a39e..e3ca761 100644
--- a/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/Actions.kt
+++ b/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/Actions.kt
@@ -20,6 +20,7 @@
import android.util.Log
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
+import java.lang.IllegalStateException
private const val TAG = "MacroBenchmarks"
@@ -127,10 +128,9 @@
* Gets the SE Linux policy.
*/
private fun getSeLinuxPolicyEnforced(instrumentation: Instrumentation): Int {
- return when (instrumentation.device().executeShellCommand("getenforce")) {
- PERMISSIVE -> 0
- else -> 1
- }
+ // command returns "Permissive\n" or "Enforcing\n" (note the newline!)
+ val enforcingStatus = instrumentation.device().executeShellCommand("getenforce")
+ return if (enforcingStatus.contains(PERMISSIVE)) 0 else 1
}
/**
@@ -140,7 +140,13 @@
check(policy == 0 || policy == 1) {
"Policy can only be one of `0` or `1`"
}
+
+ // TODO: unable to see failure here, due to executeShellCommand output always being empty.
+ // for now, we just verify the `setenforce` worked with an extra `getenforce`
instrumentation.device().executeShellCommand("setenforce $policy")
+ if (getSeLinuxPolicyEnforced(instrumentation) != policy) {
+ throw IllegalStateException("\"setenforce $policy\" didn't succeed, is ADB session rooted?")
+ }
}
internal fun Instrumentation.device(): UiDevice {
diff --git a/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/AppStartupHelper.kt b/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/AppStartupHelper.kt
index 5c19bf7..795f693 100644
--- a/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/AppStartupHelper.kt
+++ b/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/AppStartupHelper.kt
@@ -18,7 +18,6 @@
import android.util.Log
import com.android.helpers.StatsdHelper
import com.android.os.nano.AtomsProto
-import com.android.os.nano.StatsLog
import java.util.ArrayList
/**
@@ -34,7 +33,7 @@
/**
* Set up the app startup statsd config to track the metrics during the app start occurred.
*/
- fun startCollecting(): Boolean {
+ fun startCollecting() {
Log.i("AppStartupHelper", "Adding app startup configs to statsd.")
val atomIdList: MutableList<Int> = ArrayList()
atomIdList.add(AtomsProto.Atom.APP_START_OCCURRED_FIELD_NUMBER)
@@ -42,13 +41,21 @@
if (!isProcStartDetailsDisabled) {
atomIdList.add(AtomsProto.Atom.PROCESS_START_TIME_FIELD_NUMBER)
}
- return statsdHelper.addEventConfig(atomIdList)
+ if (!statsdHelper.addEventConfig(atomIdList)) {
+ throw IllegalStateException("Unable to add event config to statsd")
+ }
}
- private fun toMetricStructure(
- list: List<StatsLog.EventMetricData>,
+ /**
+ * Captures all startup events as a List<AppStartupMetrics>.
+ *
+ * Note - this function supports capturing multiple startups for a given package, but
+ * [getMetrics] does not, to support only one value per metric, per iteration.
+ */
+ internal fun getMetricStructure(
packageName: String
): List<AppStartupMetrics> {
+ val list = statsdHelper.eventMetrics
val appStartOccurredList = list
.filter { it.atom.hasAppStartOccurred() }
.map { it.atom.appStartOccurred }
@@ -92,17 +99,31 @@
}
}
- fun getMetrics(packageName: String): Map<String, List<Long>> {
- val results = toMetricStructure(statsdHelper.eventMetrics, packageName)
- // TODO: potentially filter these for app vs system usage
+ fun getMetrics(packageName: String): Map<String, Long> {
+ val results = getMetricStructure(packageName)
+
+ if (results.isEmpty()) {
+ throw IllegalStateException(
+ "Saw no launches of package $packageName, did you launch an activity?"
+ )
+ }
+ if (results.size > 1) {
+ throw IllegalStateException(
+ "Saw more than one startup for package $packageName, this is not supported"
+ )
+ }
+ val result = results.first()
+ // TODO: potentially filter these further for app vs platform usage
return mapOf(
// AppStartupHelper originally reports this as simply startup time, so we do the same
- "startupMs" to results.mapNotNull { it.windowDrawnDelayMs },
- "transitionDelayMs" to results.mapNotNull { it.transitionDelayMs },
+ "startupMs" to result.windowDrawnDelayMs,
+ "transitionDelayMs" to result.transitionDelayMs,
// Though the proto calls this appStartupTime, we clarify this is "fully drawn" startup
- "startupFullyDrawnMs" to results.mapNotNull { it.appStartupTimeMs },
- "processStartDelayMs" to results.mapNotNull { it.processStartDelayMs },
- ).filterValues { it.isNotEmpty() }
+ "startupFullyDrawnMs" to result.appStartupTimeMs,
+ "processStartDelayMs" to result.processStartDelayMs,
+ )
+ .filterValues { it != null } // doesn't drop nullability for values...
+ .mapValues { it.value!! } // ...so we do that explicitly here
}
/**
@@ -119,7 +140,7 @@
isProcStartDetailsDisabled = true
}
- class AppStartupMetrics(
+ data class AppStartupMetrics(
val transitionType: String?,
val windowDrawnDelayMs: Long?,
val transitionDelayMs: Long?,
diff --git a/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/Macrobenchmark.kt b/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/Macrobenchmark.kt
index c7fedc3..55babbe 100644
--- a/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/Macrobenchmark.kt
+++ b/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/Macrobenchmark.kt
@@ -87,7 +87,8 @@
fun macrobenchmark(
benchmarkName: String,
config: MacrobenchmarkConfig,
- block: MacrobenchmarkScope.() -> Unit
+ setupBlock: MacrobenchmarkScope.() -> Unit = {},
+ measureBlock: MacrobenchmarkScope.() -> Unit
) = withPermissiveSeLinuxPolicy {
val scope = MacrobenchmarkScope(config.packageName)
@@ -95,7 +96,8 @@
scope.killProcess()
config.compilationMode.compile(config.packageName) {
- block(scope)
+ setupBlock(scope)
+ measureBlock(scope)
}
// Perfetto collector is separate from metrics, so we can control file
@@ -105,44 +107,52 @@
config.metrics.forEach {
it.configure(config)
}
- perfettoCollector.start()
- config.metrics.forEach {
- it.start()
- }
- repeat(config.iterations) {
+ val results = List(config.iterations) { iteration ->
if (config.killProcessEachIteration) {
+ // TODO: remove this flag, make this part of setupBlock
scope.killProcess()
}
- block(scope)
- }
- config.metrics.forEach {
- it.stop()
+ setupBlock(scope)
+ try {
+ perfettoCollector.start()
+ config.metrics.forEach {
+ it.start()
+ }
+ measureBlock(scope)
+ config.metrics.forEach {
+ it.stop()
+ }
+ } finally {
+ val iterString = iteration.toString().padStart(3, '0')
+ perfettoCollector.stop("${benchmarkName}_iter$iterString.trace")
+ }
+
+ config.metrics
+ // capture list of Map<String,Long> per metric
+ .map { it.getMetrics(config.packageName) }
+ // merge into one map
+ .reduce { sum, element -> sum + element }
}
- val statsList = config.metrics.getStatsList(config.packageName)
+ // merge each independent Map<String,Long> to one Map<String,List<Long>>
+ val setOfAllKeys = results.flatMap { it.keys }.toSet()
+ val listResults = setOfAllKeys.map { key ->
+ key to results.map { it[key] ?: error("Value $key missing from one iteration") }
+ }.toMap()
+
+ val statsList = listResults.map { (metricName, values) ->
+ Stats(values.toLongArray(), metricName)
+ }
+
InstrumentationResults.instrumentationReport {
ideSummaryRecord(ideSummaryString(benchmarkName, statsList))
statsList.forEach { it.putInBundle(bundle, "") }
}
} finally {
- perfettoCollector.stop("$benchmarkName.trace")
scope.killProcess()
}
}
-/**
- * Capture results from each metric, and create Stats container for each
- */
-fun List<Metric>.getStatsList(packageName: String): List<Stats> {
- val metricMap: Map<String, List<Long>> = this.flatMap {
- it.getMetrics(packageName).toList()
- }.toMap()
-
- return metricMap.map { (metricName, values) ->
- Stats(values.toLongArray(), metricName)
- }
-}
-
fun ideSummaryString(benchmarkName: String, statsList: List<Stats>): String {
val maxLabelLength = Collections.max(statsList.map { it.name.length })
diff --git a/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/MacrobenchmarkRule.kt b/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/MacrobenchmarkRule.kt
index babaad7..86e31bc 100644
--- a/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/MacrobenchmarkRule.kt
+++ b/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/MacrobenchmarkRule.kt
@@ -28,9 +28,10 @@
fun measureRepeated(
config: MacrobenchmarkConfig,
- block: MacrobenchmarkScope.() -> Unit
+ setupBlock: MacrobenchmarkScope.() -> Unit = {},
+ measureBlock: MacrobenchmarkScope.() -> Unit
) {
- macrobenchmark(benchmarkName, config, block)
+ macrobenchmark(benchmarkName, config, setupBlock, measureBlock)
}
override fun apply(base: Statement, description: Description) = object : Statement() {
diff --git a/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/Metric.kt b/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/Metric.kt
index 0bc8f1b..40f87de 100644
--- a/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/Metric.kt
+++ b/benchmark/benchmark-macro-runtime/src/main/java/androidx/benchmark/macro/Metric.kt
@@ -26,24 +26,28 @@
* Metric interface.
*/
sealed class Metric {
+ abstract fun configure(config: MacrobenchmarkConfig)
+
abstract fun start()
abstract fun stop()
- abstract fun configure(config: MacrobenchmarkConfig)
-
/**
* After stopping, collect metrics
*
* TODO: takes package for package level filtering, but probably want a
* general config object coming into [start].
*/
- abstract fun getMetrics(packageName: String): Map<String, List<Long>>
+ abstract fun getMetrics(packageName: String): Map<String, Long>
}
class StartupTimingMetric : Metric() {
private val helper = AppStartupHelper()
+ override fun configure(config: MacrobenchmarkConfig) {
+ // does nothing
+ }
+
override fun start() {
helper.startCollecting()
}
@@ -52,11 +56,7 @@
helper.stopCollecting()
}
- override fun configure(config: MacrobenchmarkConfig) {
- // does nothing
- }
-
- override fun getMetrics(packageName: String): Map<String, List<Long>> {
+ override fun getMetrics(packageName: String): Map<String, Long> {
return helper.getMetrics(packageName)
}
}
@@ -66,6 +66,10 @@
it.setEnableCpuUtilization()
}
+ override fun configure(config: MacrobenchmarkConfig) {
+ // does nothing
+ }
+
override fun start() {
helper.startCollecting()
}
@@ -74,12 +78,8 @@
helper.stopCollecting()
}
- override fun configure(config: MacrobenchmarkConfig) {
- // does nothing
- }
-
- override fun getMetrics(packageName: String): Map<String, List<Long>> {
- return helper.metrics.mapValues { listOf(it.value) }
+ override fun getMetrics(packageName: String): Map<String, Long> {
+ return helper.metrics
}
}
@@ -87,6 +87,11 @@
private lateinit var packageName: String
private val helper = JankCollectionHelper()
+ override fun configure(config: MacrobenchmarkConfig) {
+ packageName = config.packageName
+ helper.addTrackedPackages(packageName)
+ }
+
override fun start() {
try {
helper.startCollecting()
@@ -113,21 +118,20 @@
helper.stopCollecting()
}
- override fun configure(config: MacrobenchmarkConfig) {
- packageName = config.packageName
- helper.addTrackedPackages(packageName)
- }
-
- override fun getMetrics(packageName: String): Map<String, List<Long>> {
- return helper.metrics.map { (key, value) ->
- key to listOf(value.toLong())
- }.toMap()
+ override fun getMetrics(packageName: String): Map<String, Long> {
+ return helper.metrics.mapValues {
+ it.value.toLong()
+ }
}
}
class TotalPssMetric : Metric() {
private val helper = TotalPssHelper()
+ override fun configure(config: MacrobenchmarkConfig) {
+ helper.setUp(config.packageName)
+ }
+
override fun start() {
helper.startCollecting()
}
@@ -136,14 +140,7 @@
helper.stopCollecting()
}
- override fun configure(config: MacrobenchmarkConfig) {
- helper.setUp(config.packageName)
- helper.setMinIterations(config.iterations)
- }
-
- override fun getMetrics(packageName: String): Map<String, List<Long>> {
- return helper.metrics.map { (key, value) ->
- key to listOf(value)
- }.toMap()
+ override fun getMetrics(packageName: String): Map<String, Long> {
+ return helper.metrics
}
}
diff --git a/benchmark/benchmark-simple-macro-benchmark/src/androidTest/java/androidx/benchmark/macro/sample/JankMetricValidation.kt b/benchmark/benchmark-simple-macro-benchmark/src/androidTest/java/androidx/benchmark/macro/sample/JankMetricValidation.kt
index d16d636..2dc52e46 100644
--- a/benchmark/benchmark-simple-macro-benchmark/src/androidTest/java/androidx/benchmark/macro/sample/JankMetricValidation.kt
+++ b/benchmark/benchmark-simple-macro-benchmark/src/androidTest/java/androidx/benchmark/macro/sample/JankMetricValidation.kt
@@ -62,11 +62,15 @@
iterations = 10
)
- benchmarkRule.measureRepeated(config) {
- val intent = Intent()
- intent.action = ACTION
- intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
- launchIntentAndWait(intent)
+ benchmarkRule.measureRepeated(
+ config,
+ setupBlock = {
+ val intent = Intent()
+ intent.action = ACTION
+ intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
+ launchIntentAndWait(intent)
+ }
+ ) {
val recycler = device.findObject(By.res(PACKAGE_NAME, RESOURCE_ID))
// Setting a gesture margin is important otherwise gesture nav is triggered.
recycler.setGestureMargin(device.displayWidth / 5)
diff --git a/buildSrc/src/main/kotlin/androidx/build/AndroidXPlaygroundRootPlugin.kt b/buildSrc/src/main/kotlin/androidx/build/AndroidXPlaygroundRootPlugin.kt
index 48af767..20a622ef 100644
--- a/buildSrc/src/main/kotlin/androidx/build/AndroidXPlaygroundRootPlugin.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/AndroidXPlaygroundRootPlugin.kt
@@ -94,15 +94,25 @@
return requested
} else {
val sections = path.split(":")
- if (sections.size == 3) {
- // first is empty, second is project, third is artifact
- var group = "androidx.${sections[1]}"
- if (group == "androidx.arch") {
- group = "androidx.arch.core"
- }
- return "$group:${sections[2]}:$SNAPSHOT_MARKER"
+
+ if (sections[0].isNotEmpty()) {
+ throw GradleException(
+ "Expected projectOrArtifact path to start with empty section but got $path"
+ )
}
- throw GradleException("cannot find/replace project $path")
+
+ // Typically androidx projects have 3 sections, compose has 4.
+ if (sections.size >= 3) {
+ // first is empty, last is artifact
+ val group = if (sections[1] == "androidx.arch") {
+ "androidx.${sections.drop(1).dropLast(1).joinToString(".")}"
+ } else {
+ "androidx.arch.core"
+ }
+ return "$group:${sections.last()}:$SNAPSHOT_MARKER"
+ }
+
+ throw GradleException("projectOrArtifact cannot find/replace project $path")
}
}
diff --git a/buildSrc/src/main/kotlin/androidx/build/AndroidXPlugin.kt b/buildSrc/src/main/kotlin/androidx/build/AndroidXPlugin.kt
index 3d28b8d..42ea9a8 100644
--- a/buildSrc/src/main/kotlin/androidx/build/AndroidXPlugin.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/AndroidXPlugin.kt
@@ -33,6 +33,7 @@
import androidx.build.jacoco.Jacoco
import androidx.build.license.configureExternalDependencyLicenseCheck
import androidx.build.studio.StudioTask
+import com.android.build.api.extension.LibraryAndroidComponentsExtension
import com.android.build.gradle.AppExtension
import com.android.build.gradle.AppPlugin
import com.android.build.gradle.LibraryExtension
@@ -262,66 +263,12 @@
configureAndroidLibraryOptions(project, androidXExtension)
}
- try {
- val libraryAndroidComponentsExtensionType =
- Class.forName("com.android.build.api.extension.LibraryAndroidComponentsExtension")
- val androidComponentsExtension =
- project.extensions.getByType(libraryAndroidComponentsExtensionType)
- val selectorType = Class.forName("com.android.build.api.extension.VariantSelector")
- val selector = libraryAndroidComponentsExtensionType.getMethod("selector")
- .invoke(androidComponentsExtension)
- libraryAndroidComponentsExtensionType
- .getMethod("beforeUnitTest", selectorType, Function1::class.java)
- .invoke(
- androidComponentsExtension,
- selectorType.getMethod("withBuildType", String::class.java)
- .invoke(selector, "release"),
- { unitTest: Any ->
- unitTest.javaClass.getMethod("setEnabled", Boolean::class.java)
- .invoke(unitTest, false)
- }
- )
- } catch (cnfe: ClassNotFoundException) {
- // old iteration of the new API.
- val allVariants = libraryExtension.javaClass.getMethod("getOnVariants")
- .invoke(libraryExtension)
-
- allVariants.javaClass.getMethod(
- "withBuildType",
- String::class.java,
- Function1::class.java
- ).invoke(
- allVariants,
- "release",
- { variant: Any ->
- variant.javaClass.getMethod(
- "unitTest",
- Function1::class.java
- ).invoke(
- variant,
- { unitTest: Any ->
- unitTest.javaClass.getMethod(
- "setEnabled",
- Boolean::class.java
- ).invoke(
- unitTest,
- false
- )
- }
- )
- }
- )
+ project.extensions.getByType<LibraryAndroidComponentsExtension>().apply {
+ beforeUnitTest(selector().withBuildType("release")) { unitTest ->
+ unitTest.enabled = false
+ }
}
- // switch to this code once 4.2.0-beta1 can be used.
-
- // project.extensions.getByType<LibraryAndroidComponentsExtension>().apply {
- // beforeUnitTest(selector().withBuildType("release")) {
- // // Disable unit test for release build type
- // @Suppress("UnstableApiUsage")
- // enabled = false
- // }
- // }
libraryExtension.packagingOptions.resources {
// TODO: Replace this with a per-variant packagingOption for androidTest specifically
// once b/69953968 is resolved.
@@ -508,7 +455,7 @@
Jacoco.registerClassFilesTask(project, this)
}
- this.configureTestConfigGenerationViaReflection(project)
+ project.configureTestConfigGeneration(this)
val buildTestApksTask = project.rootProject.tasks.named(BUILD_TEST_APKS_TASK)
testVariants.all { variant ->
@@ -616,7 +563,7 @@
}
}
- project.addAppApkToTestConfigGenerationViaReflection()
+ project.addAppApkToTestConfigGeneration()
val buildTestApksTask = project.rootProject.tasks.named(BUILD_TEST_APKS_TASK)
applicationVariants.all { variant ->
diff --git a/buildSrc/src/main/kotlin/androidx/build/LibraryGroups.kt b/buildSrc/src/main/kotlin/androidx/build/LibraryGroups.kt
index 6241432b..9719f00 100644
--- a/buildSrc/src/main/kotlin/androidx/build/LibraryGroups.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/LibraryGroups.kt
@@ -92,7 +92,7 @@
val TRACING = LibraryGroup("androidx.tracing", LibraryVersions.TRACING)
val TRANSITION = LibraryGroup("androidx.transition", LibraryVersions.TRANSITION)
val TVPROVIDER = LibraryGroup("androidx.tvprovider", LibraryVersions.TVPROVIDER)
- val UI = LibraryGroup(System.getenv("COMPOSE_CUSTOM_GROUP_UI") ?: "androidx.ui", null)
+ val UI = LibraryGroup(System.getenv("COMPOSE_CUSTOM_GROUP_UI") ?: "androidx.ui", LibraryVersions.COMPOSE)
val VECTORDRAWABLE = LibraryGroup("androidx.vectordrawable", null)
val VERSIONEDPARCELABLE = LibraryGroup("androidx.versionedparcelable", null)
val VIEWPAGER = LibraryGroup("androidx.viewpager", LibraryVersions.VIEWPAGER)
@@ -104,13 +104,13 @@
object Compose {
private val group = System.getenv("COMPOSE_CUSTOM_GROUP") ?: "androidx.compose"
- val ANIMATION = LibraryGroup("$group.animation", null)
- val COMPILER = LibraryGroup("$group.compiler", null)
- val DESKTOP = LibraryGroup("$group.desktop", null)
- val FOUNDATION = LibraryGroup("$group.foundation", null)
- val MATERIAL = LibraryGroup("$group.material", null)
- val RUNTIME = LibraryGroup("$group.runtime", null)
- val UI = LibraryGroup("$group.ui", null)
+ val ANIMATION = LibraryGroup("$group.animation", LibraryVersions.COMPOSE)
+ val COMPILER = LibraryGroup("$group.compiler", LibraryVersions.COMPOSE)
+ val DESKTOP = LibraryGroup("$group.desktop", LibraryVersions.COMPOSE)
+ val FOUNDATION = LibraryGroup("$group.foundation", LibraryVersions.COMPOSE)
+ val MATERIAL = LibraryGroup("$group.material", LibraryVersions.COMPOSE)
+ val RUNTIME = LibraryGroup("$group.runtime", LibraryVersions.COMPOSE)
+ val UI = LibraryGroup("$group.ui", LibraryVersions.COMPOSE)
}
}
diff --git a/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt b/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
index 3d931bc..5cb9a47 100644
--- a/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
@@ -71,6 +71,7 @@
val IPC = Version("1.0.0-alpha01")
val JETIFIER = Version("1.0.0-beta10")
val LEANBACK = Version("1.1.0-alpha06")
+ val LEANBACK_PAGING = Version("1.1.0-alpha06")
val LEANBACK_PREFERENCE = Version("1.1.0-alpha06")
val LEGACY = Version("1.1.0-alpha01")
val LOCALBROADCASTMANAGER = Version("1.1.0-alpha02")
@@ -98,7 +99,7 @@
val SECURITY_BIOMETRIC = Version("1.0.0-alpha01")
val SECURITY_IDENTITY_CREDENTIAL = Version("1.0.0-alpha01")
val SERIALIZATION = Version("1.0.0-alpha01")
- val SHARETARGET = Version("1.1.0-beta01")
+ val SHARETARGET = Version("1.1.0-rc01")
val SLICE = Version("1.1.0-alpha02")
val SLICE_BENCHMARK = Version("1.1.0-alpha02")
val SLICE_BUILDERS_KTX = Version("1.0.0-alpha08")
diff --git a/buildSrc/src/main/kotlin/androidx/build/TestSuiteConfiguration.kt b/buildSrc/src/main/kotlin/androidx/build/TestSuiteConfiguration.kt
index dea292a..894da8c 100644
--- a/buildSrc/src/main/kotlin/androidx/build/TestSuiteConfiguration.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/TestSuiteConfiguration.kt
@@ -14,13 +14,16 @@
* limitations under the License.
*/
+@file:Suppress("UnstableApiUsage") // Incubating AGP APIs
+
package androidx.build
import androidx.build.dependencyTracker.AffectedModuleDetector
+import androidx.build.gradle.getByType
import com.android.build.api.artifact.ArtifactType
import com.android.build.api.artifact.Artifacts
-import com.android.build.api.dsl.ApplicationExtension
-import com.android.build.api.dsl.CommonExtension
+import com.android.build.api.extension.AndroidComponentsExtension
+import com.android.build.api.extension.ApplicationAndroidComponentsExtension
import com.android.build.gradle.TestedExtension
import org.gradle.api.Project
import org.gradle.api.tasks.TaskProvider
@@ -60,59 +63,15 @@
.dependsOn(generateTestConfigurationTask)
}
-fun Project.addAppApkToTestConfigGenerationViaReflection() {
- try {
- val androidComponentsExtensionType = Class.forName(
- "com.android.build.api.extension.ApplicationAndroidComponentsExtension"
- )
- val androidComponentsExtension =
- this.extensions.getByType(androidComponentsExtensionType)
- val selectorType = Class.forName(
- "com.android.build.api.extension.VariantSelector"
- )
- val selector = androidComponentsExtensionType.getMethod("selector")
- .invoke(androidComponentsExtension)
- androidComponentsExtensionType
- .getMethod("onVariants", selectorType, Function1::class.java)
- .invoke(
- androidComponentsExtension,
- selectorType.getMethod("withBuildType", String::class.java)
- .invoke(selector, "debug"),
- { debugVariant: Any ->
- val artifacts = debugVariant.javaClass.getMethod("getArtifacts")
- .invoke(debugVariant) as Artifacts
- this.tasks.withType(GenerateTestConfigurationTask::class.java) {
- it.appFolder.set(artifacts.get(ArtifactType.APK))
- it.appLoader.set(artifacts.getBuiltArtifactsLoader())
- }
- }
- )
- } catch (cnfe: ClassNotFoundException) {
- val applicationExtension = this.extensions.getByType(
- ApplicationExtension::class.java
- )
- applicationExtension.addAppApkToTestConfigGeneration(this)
- }
-}
-
-fun ApplicationExtension<*, *, *, *, *>
-.addAppApkToTestConfigGeneration(project: Project) {
- val allVariants = javaClass.getMethod("getOnVariantProperties")
- .invoke(this)
-
- allVariants.javaClass.getMethod("withBuildType", String::class.java, Function1::class.java)
- .invoke(
- allVariants,
- "debug",
- { debugVariant: Any ->
- val artifacts = debugVariant.javaClass.getMethod("getArtifacts")
- .invoke(debugVariant) as Artifacts
- project.tasks.withType(GenerateTestConfigurationTask::class.java) {
- it.appFolder.set(artifacts.get(ArtifactType.APK))
- it.appLoader.set(artifacts.getBuiltArtifactsLoader())
- }
+fun Project.addAppApkToTestConfigGeneration() {
+ extensions.getByType<ApplicationAndroidComponentsExtension>().apply {
+ onVariants(selector().withBuildType("debug")) { debugVariant ->
+ tasks.withType(GenerateTestConfigurationTask::class.java).configureEach {
+ it.appFolder.set(debugVariant.artifacts.get(ArtifactType.APK))
+ it.appLoader.set(debugVariant.artifacts.getBuiltArtifactsLoader())
}
- )
+ }
+ }
}
private fun getOrCreateMediaTestConfigTask(project: Project, isMedia2: Boolean):
@@ -204,139 +163,37 @@
}
}
-fun CommonExtension<*, *, *, *, *, *, *, *>
-.configureTestConfigGeneration(project: Project) {
- // old iteration of the new API.
- javaClass.getMethod("onVariants", Function1::class.java)
- .invoke(
- this,
- { variant: Any ->
- variant.javaClass.getMethod(
- "androidTestProperties",
- Function1::class.java
- ).invoke(
- variant,
- { androidTest: Any ->
- when {
- project.path.contains("media2:version-compat-tests") -> {
- project.createOrUpdateMediaTestConfigurationGenerationTask(
- androidTest.javaClass.getMethod(
- "getName"
- ).invoke(androidTest) as String,
- androidTest.javaClass.getMethod(
- "getArtifacts"
- ).invoke(androidTest) as Artifacts,
- defaultConfig.minSdk!!,
- defaultConfig.testInstrumentationRunner!!,
- true
- )
- }
- project.path.contains("media:version-compat-tests") -> {
- project.createOrUpdateMediaTestConfigurationGenerationTask(
- androidTest.javaClass.getMethod(
- "getName"
- ).invoke(androidTest) as String,
- androidTest.javaClass.getMethod(
- "getArtifacts"
- ).invoke(androidTest) as Artifacts,
- defaultConfig.minSdk!!,
- defaultConfig.testInstrumentationRunner!!,
- false
- )
- }
- else -> {
- project.createTestConfigurationGenerationTask(
- androidTest.javaClass.getMethod(
- "getName"
- ).invoke(androidTest) as String,
- androidTest.javaClass.getMethod(
- "getArtifacts"
- ).invoke(androidTest) as Artifacts,
- defaultConfig.minSdk!!,
- defaultConfig.testInstrumentationRunner!!
- )
- }
- }
- }
- )
- } as Function1<Any, Any>
- )
-}
-
-fun TestedExtension.configureTestConfigGenerationViaReflection(project: Project) {
- val commonExtension = project.extensions.getByType(CommonExtension::class.java)
- try {
- val androidComponentsExtensionType =
- Class.forName("com.android.build.api.extension.AndroidComponentsExtension")
- val androidComponentsExtension =
- project.extensions.getByType(androidComponentsExtensionType)
- val selectorType = Class.forName("com.android.build.api.extension.VariantSelector")
- val selector = androidComponentsExtensionType.getMethod("selector")
- .invoke(androidComponentsExtension)
- androidComponentsExtension.javaClass.getMethod(
- "androidTest",
- selectorType,
- Function1::class.java
- ).invoke(
- androidComponentsExtension,
- selector.javaClass.getMethod("all").invoke(selector),
- { androidTest: Any ->
- when {
- // support-media tests are special cased
- project.path.contains("media2:version-compat-tests") -> {
- project.createOrUpdateMediaTestConfigurationGenerationTask(
- androidTest.javaClass.getMethod(
- "getName"
- ).invoke(
- androidTest
- ) as String,
- androidTest.javaClass.getMethod(
- "getArtifacts"
- ).invoke(
- androidTest
- ) as Artifacts,
- defaultConfig.minSdk!!,
- defaultConfig.testInstrumentationRunner!!,
- true
- )
- }
- project.path.contains("media:version-compat-tests") -> {
- project.createOrUpdateMediaTestConfigurationGenerationTask(
- androidTest.javaClass.getMethod(
- "getName"
- ).invoke(
- androidTest
- ) as String,
- androidTest.javaClass.getMethod(
- "getArtifacts"
- ).invoke(
- androidTest
- ) as Artifacts,
- defaultConfig.minSdk!!,
- defaultConfig.testInstrumentationRunner!!,
- false
- )
- }
- else -> {
- project.createTestConfigurationGenerationTask(
- androidTest.javaClass.getMethod(
- "getName"
- ).invoke(
- androidTest
- ) as String,
- androidTest.javaClass.getMethod(
- "getArtifacts"
- ).invoke(
- androidTest
- ) as Artifacts,
- defaultConfig.minSdk!!,
- defaultConfig.testInstrumentationRunner!!
- )
- }
+fun Project.configureTestConfigGeneration(testedExtension: TestedExtension) {
+ extensions.getByType<AndroidComponentsExtension<*, *>>().apply {
+ androidTest(selector().all()) { androidTest ->
+ when {
+ path.contains("media2:version-compat-tests") -> {
+ createOrUpdateMediaTestConfigurationGenerationTask(
+ androidTest.name,
+ androidTest.artifacts,
+ testedExtension.defaultConfig.minSdk!!,
+ testedExtension.defaultConfig.testInstrumentationRunner!!,
+ isMedia2 = true
+ )
+ }
+ path.contains("media:version-compat-tests") -> {
+ createOrUpdateMediaTestConfigurationGenerationTask(
+ androidTest.name,
+ androidTest.artifacts,
+ testedExtension.defaultConfig.minSdk!!,
+ testedExtension.defaultConfig.testInstrumentationRunner!!,
+ isMedia2 = false
+ )
+ }
+ else -> {
+ createTestConfigurationGenerationTask(
+ androidTest.name,
+ androidTest.artifacts,
+ testedExtension.defaultConfig.minSdk!!,
+ testedExtension.defaultConfig.testInstrumentationRunner!!
+ )
}
}
- )
- } catch (cnfe: ClassNotFoundException) {
- commonExtension.configureTestConfigGeneration(project)
+ }
}
}
\ No newline at end of file
diff --git a/buildSrc/src/main/kotlin/androidx/build/uptodatedness/TaskUpToDateValidator.kt b/buildSrc/src/main/kotlin/androidx/build/uptodatedness/TaskUpToDateValidator.kt
index 41dc2a7..52d90c5 100644
--- a/buildSrc/src/main/kotlin/androidx/build/uptodatedness/TaskUpToDateValidator.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/uptodatedness/TaskUpToDateValidator.kt
@@ -35,10 +35,12 @@
const val DISALLOW_TASK_EXECUTION_FLAG_NAME = "disallowExecution"
const val RECORD_FLAG_NAME = "verifyUpToDate"
-// Temporary list of exempt tasks that are known to still be out-of-date after running once
+// Temporary set of exempt tasks that are known to still be out-of-date after running once
// Entries in this set may be task names (like assembleDebug) or task paths
// (like :core:core:assembleDebug)
-val EXEMPT_TASKS = setOf(
+// Entries in this set do still get rerun because they might produce files that are needed by
+// subsequent tasks
+val ALLOW_RERUNNING_TASKS = setOf(
"analyticsRecordingRelease",
"buildOnServer",
"checkExternalLicenses",
@@ -47,7 +49,6 @@
"createProjectZip",
"desugarPublicDebugFileDependencies",
"desugarTipOfTreeDebugFileDependencies",
- "dokkaKotlinDocs",
"externalNativeBuildDebug",
"externalNativeBuildRelease",
"generateJsonModelDebug",
@@ -81,9 +82,6 @@
"generatePomFileForSafeargsKotlinPluginMarkerMavenPublication",
"jacocoPublicDebug",
"jacocoTipOfTreeDebug",
- "lint",
- "lintDebug",
- "lintVitalRelease",
"partiallyDejetifyArchive",
"publishBenchmarkPluginMarkerMavenPublicationToMavenRepository",
"publishAndroidDebugPublicationToMavenRepository",
@@ -111,7 +109,6 @@
"verifyDependencyVersions",
"zipEcFiles",
"zipTestConfigsWithApks",
- "zipDokkaDocs",
":camera:integration-tests:camera-testapp-core:mergeLibDexDebug",
":camera:integration-tests:camera-testapp-core:packageDebug",
@@ -129,6 +126,20 @@
"publishInspectionPluginMarkerMavenPublicationToMavenRepository"
)
+// Additional tasks that are expected to be temporarily out-of-date after running once
+// Tasks in this set we don't even try to rerun, because they're known to be somewhat slow
+// and also known to not generate any new, necessary files during subsequent runs
+val DONT_TRY_RERUNNING_TASKS = setOf(
+ // More information about the fact that these dokka tasks rerun can be found at b/167569304
+ "dokkaKotlinDocs",
+ "zipDokkaDocs",
+
+ // We should be able to remove these entries when b/160392650 is fixed
+ "lint",
+ "lintDebug",
+ "lintVitalRelease",
+)
+
class TaskUpToDateValidator {
companion object {
@@ -142,8 +153,16 @@
return project.hasProperty(DISALLOW_TASK_EXECUTION_FLAG_NAME)
}
- private fun isExemptTask(task: Task): Boolean {
- return EXEMPT_TASKS.contains(task.name) || EXEMPT_TASKS.contains(task.path)
+ private fun isAllowedToRerunTask(task: Task): Boolean {
+ return ALLOW_RERUNNING_TASKS.contains(task.name) ||
+ ALLOW_RERUNNING_TASKS.contains(task.path)
+ }
+
+ private fun shouldTryRerunningTask(task: Task): Boolean {
+ return !(
+ DONT_TRY_RERUNNING_TASKS.contains(task.name) ||
+ DONT_TRY_RERUNNING_TASKS.contains(task.path)
+ )
}
private fun recordBuildStartTime(rootProject: Project) {
@@ -158,9 +177,14 @@
recordBuildStartTime(rootProject)
if (shouldValidate(rootProject)) {
val taskGraph = rootProject.gradle.taskGraph
+ taskGraph.beforeTask { task ->
+ if (!shouldTryRerunningTask(task)) {
+ task.enabled = false
+ }
+ }
taskGraph.afterTask { task ->
if (task.didWork) {
- if (!isExemptTask(task)) {
+ if (!isAllowedToRerunTask(task)) {
val message = "Ran two consecutive builds of the same tasks," +
" and in the second build, observed $task to be not UP-TO-DATE." +
" This indicates that $task does not declare" +
@@ -173,7 +197,7 @@
}
if (shouldRecord(rootProject)) {
rootProject.gradle.taskGraph.afterTask { task ->
- if (!isExemptTask(task)) {
+ if (shouldTryRerunningTask(task) && !isAllowedToRerunTask(task)) {
recordTaskInputs(task)
}
}
@@ -281,7 +305,7 @@
if (createdByTask == null) {
return "This file is not declared as the output of any task in this build."
}
- if (isExemptTask(createdByTask)) {
+ if (isAllowedToRerunTask(createdByTask)) {
return "This file is declared as an output of " + createdByTask +
", which is a task that is not yet validated by the TaskUpToDateValidator"
} else {
diff --git a/camera/camera-camera2/api/public_plus_experimental_1.0.0-beta12.txt b/camera/camera-camera2/api/public_plus_experimental_1.0.0-beta12.txt
index f20c9b9..ddf3bf4 100644
--- a/camera/camera-camera2/api/public_plus_experimental_1.0.0-beta12.txt
+++ b/camera/camera-camera2/api/public_plus_experimental_1.0.0-beta12.txt
@@ -21,7 +21,7 @@
}
public static interface Camera2CameraFilter.Camera2Filter {
- method public java.util.LinkedHashMap<java.lang.String!,android.hardware.camera2.CameraCharacteristics!> filter(java.util.LinkedHashMap<java.lang.String!,android.hardware.camera2.CameraCharacteristics!>);
+ method public java.util.List<androidx.camera.camera2.interop.Camera2CameraInfo!> filter(java.util.List<androidx.camera.camera2.interop.Camera2CameraInfo!>);
}
@androidx.camera.camera2.interop.ExperimentalCamera2Interop public final class Camera2CameraInfo {
diff --git a/camera/camera-camera2/api/public_plus_experimental_current.txt b/camera/camera-camera2/api/public_plus_experimental_current.txt
index f20c9b9..ddf3bf4 100644
--- a/camera/camera-camera2/api/public_plus_experimental_current.txt
+++ b/camera/camera-camera2/api/public_plus_experimental_current.txt
@@ -21,7 +21,7 @@
}
public static interface Camera2CameraFilter.Camera2Filter {
- method public java.util.LinkedHashMap<java.lang.String!,android.hardware.camera2.CameraCharacteristics!> filter(java.util.LinkedHashMap<java.lang.String!,android.hardware.camera2.CameraCharacteristics!>);
+ method public java.util.List<androidx.camera.camera2.interop.Camera2CameraInfo!> filter(java.util.List<androidx.camera.camera2.interop.Camera2CameraInfo!>);
}
@androidx.camera.camera2.interop.ExperimentalCamera2Interop public final class Camera2CameraInfo {
diff --git a/camera/camera-camera2/src/main/java/androidx/camera/camera2/interop/Camera2CameraFilter.java b/camera/camera-camera2/src/main/java/androidx/camera/camera2/interop/Camera2CameraFilter.java
index 50b30dc..b0e741b 100644
--- a/camera/camera-camera2/src/main/java/androidx/camera/camera2/interop/Camera2CameraFilter.java
+++ b/camera/camera-camera2/src/main/java/androidx/camera/camera2/interop/Camera2CameraFilter.java
@@ -19,15 +19,12 @@
import android.hardware.camera2.CameraCharacteristics;
import androidx.annotation.NonNull;
-import androidx.camera.camera2.internal.Camera2CameraInfoImpl;
-import androidx.camera.core.Camera;
import androidx.camera.core.CameraFilter;
import androidx.camera.core.CameraInfo;
-import androidx.core.util.Preconditions;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
/**
* Provides ability to filter cameras with camera IDs and characteristics and create the
@@ -41,38 +38,22 @@
*/
@NonNull
public static CameraFilter createCameraFilter(@NonNull Camera2Filter filter) {
- return (cameras) -> {
- LinkedHashMap<String, Camera> cameraMap = new LinkedHashMap<>();
- LinkedHashMap<String, CameraCharacteristics> characteristicsMap =
- new LinkedHashMap<>();
- for (Camera camera : cameras) {
- CameraInfo cameraInfo = camera.getCameraInfo();
- Preconditions.checkState(cameraInfo instanceof Camera2CameraInfoImpl,
- "CameraInfo does not contain any Camera2 information.");
- Camera2CameraInfoImpl camera2CameraInfoImpl =
- (Camera2CameraInfoImpl) cameraInfo;
- cameraMap.put(camera2CameraInfoImpl.getCameraId(), camera);
- characteristicsMap.put(camera2CameraInfoImpl.getCameraId(),
- camera2CameraInfoImpl
- .getCameraCharacteristicsCompat().toCameraCharacteristics());
+ return cameraInfos -> {
+ List<Camera2CameraInfo> input = new ArrayList<>();
+ for (CameraInfo cameraInfo : cameraInfos) {
+ input.add(Camera2CameraInfo.from(cameraInfo));
}
- LinkedHashMap<String, CameraCharacteristics> resultMap = filter.filter(
- characteristicsMap);
+ List<Camera2CameraInfo> result = filter.filter(Collections.unmodifiableList(input));
- LinkedHashSet<Camera> resultCameras = new LinkedHashSet<>();
- for (Map.Entry<String, CameraCharacteristics> entry : resultMap.entrySet()) {
- String cameraId = entry.getKey();
- // The extra camera IDs not contained in the camera map will be ignored.
- if (cameraMap.containsKey(cameraId)) {
- resultCameras.add(cameraMap.get(cameraId));
- } else {
- throw new IllegalArgumentException(
- "There are camera IDs not contained in the original camera map.");
+ List<CameraInfo> output = new ArrayList<>();
+ for (CameraInfo cameraInfo : cameraInfos) {
+ if (result.contains(Camera2CameraInfo.from(cameraInfo))) {
+ output.add(cameraInfo);
}
}
- return resultCameras;
+ return output;
};
}
@@ -82,28 +63,25 @@
*/
public interface Camera2Filter {
/**
- * Filters a map of camera IDs and their {@link CameraCharacteristics} then returns those
- * matching the requirements.
+ * Filters a list of {@link Camera2CameraInfo} then returns those matching the requirements.
*
- * <p>If the key set of the output map contains camera IDs not in the key set of the
- * input map, when used by a {@link androidx.camera.core.CameraSelector} then it will
- * result in an IllegalArgumentException thrown when calling bindToLifecycle.
+ * <p>If the output list contains Camera2CameraInfo not in the input list, when used by a
+ * {@link androidx.camera.core.CameraSelector} then it will result in an
+ * IllegalArgumentException thrown when calling bindToLifecycle.
*
- * <p>The camera ID that has lower index in the map has higher priority. When used by
+ * <p>The Camera2CameraInfo that has lower index in the map has higher priority. When
+ * used by
* {@link androidx.camera.core.CameraSelector.Builder#addCameraFilter(CameraFilter)}, the
- * available cameras will be filtered by the {@link Camera2CameraFilter} and all other
+ * available cameras will be filtered by the {@link Camera2Filter} and all other
* {@link CameraFilter}s by the order they were added. The first camera in the result
* will be selected if there are multiple cameras left.
*
- * @param idCharacteristicsMap The input map of camera IDs and their
- * {@link CameraCharacteristics} of the cameras being
- * filtered. It's not expected to be modified.
+ * @param cameraInfos An unmodifiable list of {@link Camera2CameraInfo}s being filtered.
* @return The output map of camera IDs and their {@link CameraCharacteristics} that
* match the requirements. Users are expected to create a new map to return with.
*/
@NonNull
- LinkedHashMap<String, CameraCharacteristics> filter(
- @NonNull LinkedHashMap<String, CameraCharacteristics> idCharacteristicsMap);
+ List<Camera2CameraInfo> filter(@NonNull List<Camera2CameraInfo> cameraInfos);
}
// Should not be instantiated.
diff --git a/camera/camera-camera2/src/test/java/androidx/camera/camera2/interop/Camera2CameraFilterTest.java b/camera/camera-camera2/src/test/java/androidx/camera/camera2/interop/Camera2CameraFilterTest.java
index 84cf479..820a234 100644
--- a/camera/camera-camera2/src/test/java/androidx/camera/camera2/interop/Camera2CameraFilterTest.java
+++ b/camera/camera-camera2/src/test/java/androidx/camera/camera2/interop/Camera2CameraFilterTest.java
@@ -39,9 +39,9 @@
import org.robolectric.annotation.Config;
import org.robolectric.annotation.internal.DoNotInstrument;
-import java.util.LinkedHashMap;
+import java.util.ArrayList;
import java.util.LinkedHashSet;
-import java.util.Map;
+import java.util.List;
@RunWith(RobolectricTestRunner.class)
@DoNotInstrument
@@ -50,75 +50,74 @@
public final class Camera2CameraFilterTest {
private static final String BACK_ID = "0";
private static final String FRONT_ID = "1";
- private static final String EXTRA_ID = "2";
private LinkedHashSet<CameraInternal> mCameras = new LinkedHashSet<>();
private CameraInternal mBackCamera;
private CameraInternal mFrontCamera;
- private LinkedHashMap<String, CameraCharacteristics> mIdCharMap = new LinkedHashMap<>();
+ private List<Camera2CameraInfo> mCameraInfos = new ArrayList<>();
+ private Camera2CameraInfo mCameraInfoBack;
+ private Camera2CameraInfo mCameraInfoFront;
@Before
public void setUp() {
- Camera2CameraInfoImpl mockCameraInfoBack = mock(Camera2CameraInfoImpl.class);
- when(mockCameraInfoBack.getCameraId()).thenReturn(BACK_ID);
- mBackCamera = new FakeCamera(null, mockCameraInfoBack);
- mCameras.add(mBackCamera);
- CameraCharacteristics mockCharacteristicsBack = mock(CameraCharacteristics.class);
- when(mockCharacteristicsBack.get(
+ CameraCharacteristicsCompat mockCharacteristicsCompatBack =
+ mock(CameraCharacteristicsCompat.class);
+ when(mockCharacteristicsCompatBack.get(
CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)).thenReturn(
CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL);
- mIdCharMap.put(BACK_ID, mockCharacteristicsBack);
- CameraCharacteristicsCompat characteristicsCompatBack =
- mock(CameraCharacteristicsCompat.class);
- when(characteristicsCompatBack.toCameraCharacteristics())
- .thenReturn(mockCharacteristicsBack);
- when(mockCameraInfoBack.getCameraCharacteristicsCompat())
- .thenReturn(characteristicsCompatBack);
+ Camera2CameraInfoImpl mockCameraInfoImplBack = mock(Camera2CameraInfoImpl.class);
+ when(mockCameraInfoImplBack.getCameraId()).thenReturn(BACK_ID);
+ when(mockCameraInfoImplBack.getCameraCharacteristicsCompat())
+ .thenReturn(mockCharacteristicsCompatBack);
+ mCameraInfoBack = new Camera2CameraInfo(mockCameraInfoImplBack);
+ when(mockCameraInfoImplBack.getCamera2CameraInfo()).thenReturn(mCameraInfoBack);
+ mCameraInfos.add(mCameraInfoBack);
+ mBackCamera = new FakeCamera(null, mockCameraInfoImplBack);
+ mCameras.add(mBackCamera);
- Camera2CameraInfoImpl mockCameraInfoFront = mock(Camera2CameraInfoImpl.class);
- when(mockCameraInfoFront.getCameraId()).thenReturn(FRONT_ID);
- mFrontCamera = new FakeCamera(null, mockCameraInfoFront);
- mCameras.add(mFrontCamera);
- CameraCharacteristics mockCharacteristicsFront = mock(CameraCharacteristics.class);
- when(mockCharacteristicsFront.get(
+ CameraCharacteristicsCompat mCharacteristicsCompatFront =
+ mock(CameraCharacteristicsCompat.class);
+ when(mCharacteristicsCompatFront.get(
CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)).thenReturn(
CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY);
- mIdCharMap.put(FRONT_ID, mockCharacteristicsFront);
- CameraCharacteristicsCompat characteristicsCompatFront =
- mock(CameraCharacteristicsCompat.class);
- when(characteristicsCompatFront.toCameraCharacteristics())
- .thenReturn(mockCharacteristicsFront);
- when(mockCameraInfoFront.getCameraCharacteristicsCompat())
- .thenReturn(characteristicsCompatFront);
-
+ Camera2CameraInfoImpl mockCameraInfoImplFront = mock(Camera2CameraInfoImpl.class);
+ when(mockCameraInfoImplFront.getCameraId()).thenReturn(FRONT_ID);
+ when(mockCameraInfoImplFront.getCameraCharacteristicsCompat())
+ .thenReturn(mCharacteristicsCompatFront);
+ mCameraInfoFront = new Camera2CameraInfo(mockCameraInfoImplFront);
+ when(mockCameraInfoImplFront.getCamera2CameraInfo()).thenReturn(mCameraInfoFront);
+ mCameraInfos.add(mCameraInfoFront);
+ mFrontCamera = new FakeCamera(null, mockCameraInfoImplFront);
+ mCameras.add(mFrontCamera);
}
@Test
public void canFilterWithCamera2Filter() {
- Camera2CameraFilter.Camera2Filter camera2Filter = (idCharMap) -> {
- LinkedHashMap<String, CameraCharacteristics> resultMap = new LinkedHashMap<>();
- for (Map.Entry<String, CameraCharacteristics> entry : idCharMap.entrySet()) {
- if (entry.getValue().get(
+ Camera2CameraFilter.Camera2Filter camera2Filter = cameraInfos -> {
+ List<Camera2CameraInfo> output = new ArrayList<>();
+ for (Camera2CameraInfo cameraInfo : cameraInfos) {
+ if (cameraInfo.getCameraCharacteristic(
CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL).equals(
CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY)) {
- resultMap.put(entry.getKey(), entry.getValue());
+ output.add(cameraInfo);
}
}
- return resultMap;
+ return output;
};
- assertThat(camera2Filter.filter(mIdCharMap).keySet()).containsExactly(FRONT_ID);
+ assertThat(camera2Filter.filter(mCameraInfos)).containsExactly(mCameraInfoFront);
}
@Test
public void canSelectWithCameraSelector() {
- CameraFilter filter = Camera2CameraFilter.createCameraFilter((idCharMap) -> {
- LinkedHashMap<String, CameraCharacteristics> resultMap = new LinkedHashMap<>();
- if (idCharMap.containsKey(FRONT_ID)) {
- CameraCharacteristics characteristics = idCharMap.get(FRONT_ID);
- resultMap.put(FRONT_ID, characteristics);
+ CameraFilter filter = Camera2CameraFilter.createCameraFilter(cameraInfos -> {
+ List<Camera2CameraInfo> output = new ArrayList<>();
+ for (Camera2CameraInfo cameraInfo : cameraInfos) {
+ if (cameraInfo.getCameraId().equals(FRONT_ID)) {
+ output.add(cameraInfo);
+ }
}
- return resultMap;
+ return output;
});
CameraSelector cameraSelector = new CameraSelector.Builder().addCameraFilter(
@@ -127,31 +126,30 @@
}
@Test(expected = IllegalArgumentException.class)
- public void exception_extraOutputCameraId() {
- CameraFilter filter = Camera2CameraFilter.createCameraFilter((idCharMap) -> {
- LinkedHashMap<String, CameraCharacteristics> resultMap = new LinkedHashMap<>();
+ public void exception_extraOutputCameraInfo() {
+ CameraFilter filter = Camera2CameraFilter.createCameraFilter(cameraInfos -> {
+ List<Camera2CameraInfo> output = new ArrayList<>();
// Add an extra camera id to output.
- resultMap.put(EXTRA_ID, null);
- return resultMap;
+ output.add(mock(Camera2CameraInfo.class));
+ return output;
});
+
CameraSelector cameraSelector = new CameraSelector.Builder().addCameraFilter(
filter).build();
cameraSelector.select(mCameras);
}
- @Test(expected = IllegalArgumentException.class)
- public void exception_extraInputAndOutputCameraId() {
- CameraFilter filter = Camera2CameraFilter.createCameraFilter((idCharMap) -> {
+ @Test(expected = UnsupportedOperationException.class)
+ public void exception_extraInputCameraInfo() {
+ CameraFilter filter = Camera2CameraFilter.createCameraFilter(cameraInfos -> {
// Add an extra camera id to input.
- idCharMap.put(EXTRA_ID, null);
- LinkedHashMap<String, CameraCharacteristics> resultMap = new LinkedHashMap<>();
- // Add an extra camera id to output.
- resultMap.put(EXTRA_ID, null);
- return resultMap;
+ cameraInfos.add(mock(Camera2CameraInfo.class));
+ return cameraInfos;
});
+
CameraSelector cameraSelector = new CameraSelector.Builder().addCameraFilter(
filter).build();
- // Should throw an exception even the extra camera id is also added to the input.
+ // Should throw an exception if the input is modified.
cameraSelector.select(mCameras);
}
}
diff --git a/camera/camera-core/api/public_plus_experimental_1.0.0-beta12.txt b/camera/camera-core/api/public_plus_experimental_1.0.0-beta12.txt
index 7b2943e..e432572 100644
--- a/camera/camera-core/api/public_plus_experimental_1.0.0-beta12.txt
+++ b/camera/camera-core/api/public_plus_experimental_1.0.0-beta12.txt
@@ -24,7 +24,7 @@
}
@androidx.camera.core.ExperimentalCameraFilter public interface CameraFilter {
- method public java.util.LinkedHashSet<androidx.camera.core.Camera!> filter(java.util.LinkedHashSet<androidx.camera.core.Camera!>);
+ method public java.util.List<androidx.camera.core.CameraInfo!> filter(java.util.List<androidx.camera.core.CameraInfo!>);
}
public interface CameraInfo {
diff --git a/camera/camera-core/api/public_plus_experimental_current.txt b/camera/camera-core/api/public_plus_experimental_current.txt
index 7b2943e..e432572 100644
--- a/camera/camera-core/api/public_plus_experimental_current.txt
+++ b/camera/camera-core/api/public_plus_experimental_current.txt
@@ -24,7 +24,7 @@
}
@androidx.camera.core.ExperimentalCameraFilter public interface CameraFilter {
- method public java.util.LinkedHashSet<androidx.camera.core.Camera!> filter(java.util.LinkedHashSet<androidx.camera.core.Camera!>);
+ method public java.util.List<androidx.camera.core.CameraInfo!> filter(java.util.List<androidx.camera.core.CameraInfo!>);
}
public interface CameraInfo {
diff --git a/camera/camera-core/src/main/java/androidx/camera/core/CameraFilter.java b/camera/camera-core/src/main/java/androidx/camera/core/CameraFilter.java
index c54a424..960447f 100644
--- a/camera/camera-core/src/main/java/androidx/camera/core/CameraFilter.java
+++ b/camera/camera-core/src/main/java/androidx/camera/core/CameraFilter.java
@@ -18,7 +18,7 @@
import androidx.annotation.NonNull;
-import java.util.LinkedHashSet;
+import java.util.List;
/**
* An interface for filtering cameras.
@@ -26,22 +26,21 @@
@ExperimentalCameraFilter
public interface CameraFilter {
/**
- * Filters a set of {@link Camera}s and returns those matching the requirements.
+ * Filters a list of {@link CameraInfo}s and returns those matching the requirements.
*
- * <p>If the output set contains cameras not in the input set, when used by a
+ * <p>If the output list contains CameraInfos not in the input list, when used by a
* {@link androidx.camera.core.CameraSelector} then it will result in an
* IllegalArgumentException thrown when calling bindToLifecycle.
*
- * <p>The camera that has lower index in the set has higher priority. When used by
+ * <p>The CameraInfo that has lower index in the list has higher priority. When used by
* {@link androidx.camera.core.CameraSelector.Builder#addCameraFilter(CameraFilter)}, the
* available cameras will be filtered by all {@link CameraFilter}s by the order they were
* added. The first camera in the result will be selected if there are multiple cameras left.
*
- * @param cameras The input set of {@link Camera}s being filtered. It's not expected to be
- * modified.
- * @return The output set of {@link Camera}s that match the requirements. Users are expected
- * to create a new set to return with.
+ * @param cameraInfos An unmodifiable list of {@link CameraInfo}s being filtered.
+ * @return The output list of {@link CameraInfo}s that match the requirements. Users are
+ * expected to create a new list to return with.
*/
@NonNull
- LinkedHashSet<Camera> filter(@NonNull LinkedHashSet<Camera> cameras);
+ List<CameraInfo> filter(@NonNull List<CameraInfo> cameraInfos);
}
diff --git a/camera/camera-core/src/main/java/androidx/camera/core/CameraSelector.java b/camera/camera-core/src/main/java/androidx/camera/core/CameraSelector.java
index 71a7d11..13e5d31 100644
--- a/camera/camera-core/src/main/java/androidx/camera/core/CameraSelector.java
+++ b/camera/camera-core/src/main/java/androidx/camera/core/CameraSelector.java
@@ -26,7 +26,10 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.LinkedHashSet;
+import java.util.List;
/**
* A set of requirements and priorities used to select a camera.
@@ -58,8 +61,7 @@
* {@link CameraSelector}.
*
* <p>When filtering with {@link CameraFilter}, the output set must be contained in the input
- * set, otherwise an IllegalArgumentException will be thrown. The output set is compared with
- * a copy of the original input set despite the input set isn't expected to be modified.
+ * set, otherwise an IllegalArgumentException will be thrown.
*
* @param cameras The camera set being filtered.
* @return The first camera filtered.
@@ -68,48 +70,79 @@
* @hide
*/
@RestrictTo(Scope.LIBRARY_GROUP)
- @UseExperimental(markerClass = ExperimentalCameraFilter.class)
@NonNull
public CameraInternal select(@NonNull LinkedHashSet<CameraInternal> cameras) {
return filter(cameras).iterator().next();
}
/**
- * Filters the input cameras using the {@link CameraFilter} assigned to the selector.
+ * Filters the input {@link CameraInfo}s using the {@link CameraFilter}s assigned to the
+ * selector.
*
- * <p>The camera filtered must be contained in the input set. Otherwise it will throw an
+ * <p>The camera infos filtered must be contained in the input set. Otherwise it will throw an
* exception.
*
- * @param cameras The camera set being filtered.
- * @return The remain set of cameras.
- * @throws IllegalArgumentException If there's no available camera after being filtered or
- * the filtered camera ids aren't contained in the input set.
+ * @param cameraInfos The camera infos list being filtered.
+ * @return The remain list of camera infos.
+ * @throws IllegalArgumentException If there's no available camera infos after being
+ * filtered or
+ * the filtered camera infos aren't contained in the input
+ * list.
+ * @throws UnsupportedOperationException If the {@link CameraFilter}s assigned to the selector
+ * try to modify the input camera infos.
* @hide
*/
@RestrictTo(Scope.LIBRARY_GROUP)
@UseExperimental(markerClass = ExperimentalCameraFilter.class)
@NonNull
- public LinkedHashSet<CameraInternal> filter(@NonNull LinkedHashSet<CameraInternal> cameras) {
- LinkedHashSet<Camera> camerasCopy = new LinkedHashSet<>(cameras);
- LinkedHashSet<Camera> resultCameras = new LinkedHashSet<>(cameras);
+ public List<CameraInfo> filter(@NonNull List<CameraInfo> cameraInfos) {
+ List<CameraInfo> input = new ArrayList<>(cameraInfos);
+ List<CameraInfo> output = new ArrayList<>(cameraInfos);
for (CameraFilter filter : mCameraFilterSet) {
- resultCameras = filter.filter(resultCameras);
+ output = filter.filter(Collections.unmodifiableList(output));
// If the result is empty or has extra camera that isn't contained in the input,
// throws an exception.
- if (resultCameras.isEmpty()) {
+ if (output.isEmpty()) {
throw new IllegalArgumentException("No available camera can be found.");
- } else if (!camerasCopy.containsAll(resultCameras)) {
+ } else if (!input.containsAll(output)) {
throw new IllegalArgumentException("The output isn't contained in the input.");
}
- camerasCopy.retainAll(resultCameras);
+ input.retainAll(output);
}
- LinkedHashSet<CameraInternal> returnCameras = new LinkedHashSet<>();
- for (Camera camera : resultCameras) {
- returnCameras.add((CameraInternal) camera);
+ return output;
+ }
+
+ /**
+ * Filters the input cameras using the {@link CameraFilter} assigned to the selector.
+ *
+ * <p>The cameras filtered must be contained in the input set. Otherwise it will throw an
+ * exception.
+ *
+ * @param cameras The camera set being filtered.
+ * @return The remain set of cameras.
+ * @throws IllegalArgumentException If there's no available camera after being filtered or
+ * the filtered cameras aren't contained in the input set.
+ * @hide
+ */
+ @RestrictTo(Scope.LIBRARY_GROUP)
+ @NonNull
+ public LinkedHashSet<CameraInternal> filter(@NonNull LinkedHashSet<CameraInternal> cameras) {
+ List<CameraInfo> input = new ArrayList<>();
+ for (CameraInternal camera : cameras) {
+ input.add(camera.getCameraInfo());
}
- return returnCameras;
+ List<CameraInfo> result = filter(input);
+
+ LinkedHashSet<CameraInternal> output = new LinkedHashSet<>();
+ for (CameraInternal camera : cameras) {
+ if (result.contains(camera.getCameraInfo())) {
+ output.add(camera);
+ }
+ }
+
+ return output;
}
/**
diff --git a/camera/camera-core/src/main/java/androidx/camera/core/impl/CameraFilters.java b/camera/camera-core/src/main/java/androidx/camera/core/impl/CameraFilters.java
index 5bc7177..7c3be42 100644
--- a/camera/camera-core/src/main/java/androidx/camera/core/impl/CameraFilters.java
+++ b/camera/camera-core/src/main/java/androidx/camera/core/impl/CameraFilters.java
@@ -18,21 +18,21 @@
import androidx.camera.core.CameraFilter;
-import java.util.LinkedHashSet;
+import java.util.Collections;
/**
* Implementations of different {@link CameraFilter}.
*/
public class CameraFilters {
/**
- * A camera filter which returns all input Cameras.
+ * A camera filter which returns all input camera infos.
*/
- public static final CameraFilter ANY = cameras -> cameras;
+ public static final CameraFilter ANY = cameraInfos -> cameraInfos;
/**
- * A camera filter which filters out all cameras.
+ * A camera filter which filters out all camera infos.
*/
- public static final CameraFilter NONE = cameras -> new LinkedHashSet<>();
+ public static final CameraFilter NONE = cameraInfos -> Collections.emptyList();
private CameraFilters() {
}
diff --git a/camera/camera-core/src/main/java/androidx/camera/core/impl/LensFacingCameraFilter.java b/camera/camera-core/src/main/java/androidx/camera/core/impl/LensFacingCameraFilter.java
index 69f1978..eb062bd 100644
--- a/camera/camera-core/src/main/java/androidx/camera/core/impl/LensFacingCameraFilter.java
+++ b/camera/camera-core/src/main/java/androidx/camera/core/impl/LensFacingCameraFilter.java
@@ -18,13 +18,14 @@
import androidx.annotation.NonNull;
import androidx.annotation.experimental.UseExperimental;
-import androidx.camera.core.Camera;
import androidx.camera.core.CameraFilter;
+import androidx.camera.core.CameraInfo;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.ExperimentalCameraFilter;
import androidx.core.util.Preconditions;
-import java.util.LinkedHashSet;
+import java.util.ArrayList;
+import java.util.List;
/**
* A filter that filters camera based on lens facing.
@@ -40,18 +41,18 @@
@NonNull
@Override
- public LinkedHashSet<Camera> filter(@NonNull LinkedHashSet<Camera> cameras) {
- LinkedHashSet<Camera> resultCameras = new LinkedHashSet<>();
- for (Camera camera : cameras) {
- Preconditions.checkState(camera instanceof CameraInternal,
- "The camera doesn't contain internal implementation.");
- Integer lensFacing = ((CameraInternal) camera).getCameraInfoInternal().getLensFacing();
+ public List<CameraInfo> filter(@NonNull List<CameraInfo> cameraInfos) {
+ List<CameraInfo> result = new ArrayList<>();
+ for (CameraInfo cameraInfo : cameraInfos) {
+ Preconditions.checkArgument(cameraInfo instanceof CameraInfoInternal,
+ "The camera info doesn't contain internal implementation.");
+ Integer lensFacing = ((CameraInfoInternal) cameraInfo).getLensFacing();
if (lensFacing != null && lensFacing == mLensFacing) {
- resultCameras.add(camera);
+ result.add(cameraInfo);
}
}
- return resultCameras;
+ return result;
}
/** Returns the lens facing associated with this lens facing camera id filter. */
diff --git a/camera/camera-core/src/test/java/androidx/camera/core/CameraSelectorTest.java b/camera/camera-core/src/test/java/androidx/camera/core/CameraSelectorTest.java
index a384f06..02f4bc5 100644
--- a/camera/camera-core/src/test/java/androidx/camera/core/CameraSelectorTest.java
+++ b/camera/camera-core/src/test/java/androidx/camera/core/CameraSelectorTest.java
@@ -35,7 +35,9 @@
import org.robolectric.annotation.Config;
import org.robolectric.annotation.internal.DoNotInstrument;
+import java.util.ArrayList;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.concurrent.ExecutionException;
@RunWith(RobolectricTestRunner.class)
@@ -126,29 +128,26 @@
@Test(expected = IllegalArgumentException.class)
public void exception_extraOutputCamera() {
CameraSelector.Builder cameraSelectorBuilder = new CameraSelector.Builder();
- cameraSelectorBuilder.addCameraFilter((cameras) -> {
- LinkedHashSet<Camera> resultCameras = new LinkedHashSet<>();
+ cameraSelectorBuilder.addCameraFilter(cameraInfos -> {
+ List<CameraInfo> result = new ArrayList<>();
// Add an extra camera to output.
- resultCameras.add(new FakeCamera());
- return resultCameras;
+ result.add(new FakeCameraInfoInternal());
+ return result;
});
cameraSelectorBuilder.build().select(mCameras);
}
@UseExperimental(markerClass = ExperimentalCameraFilter.class)
- @Test(expected = IllegalArgumentException.class)
- public void exception_extraInputAndOutputCamera() {
+ @Test(expected = UnsupportedOperationException.class)
+ public void exception_extraInputCamera() {
CameraSelector.Builder cameraSelectorBuilder = new CameraSelector.Builder();
- cameraSelectorBuilder.addCameraFilter((cameras) -> {
- Camera camera = new FakeCamera();
+ cameraSelectorBuilder.addCameraFilter(cameraInfos -> {
+ CameraInfo cameraInfo = new FakeCameraInfoInternal();
// Add an extra camera to input.
- cameras.add(camera);
- LinkedHashSet<Camera> resultCameras = new LinkedHashSet<>();
- // Add an extra camera to output.
- resultCameras.add(camera);
- return resultCameras;
+ cameraInfos.add(cameraInfo);
+ return cameraInfos;
});
- // Should throw an exception even the extra camera is also added to the input.
+ // Should throw an exception if the input is modified.
cameraSelectorBuilder.build().select(mCameras);
}
}
diff --git a/camera/camera-core/src/test/java/androidx/camera/core/impl/CameraFiltersTest.kt b/camera/camera-core/src/test/java/androidx/camera/core/impl/CameraFiltersTest.kt
index f74821d..8cfc8a7 100644
--- a/camera/camera-core/src/test/java/androidx/camera/core/impl/CameraFiltersTest.kt
+++ b/camera/camera-core/src/test/java/androidx/camera/core/impl/CameraFiltersTest.kt
@@ -16,9 +16,8 @@
package androidx.camera.core.impl
-import androidx.camera.core.Camera
+import androidx.camera.core.CameraInfo
import androidx.camera.core.CameraSelector
-import androidx.camera.testing.fakes.FakeCamera
import androidx.camera.testing.fakes.FakeCameraInfoInternal
import com.google.common.truth.Truth.assertThat
import org.junit.Before
@@ -33,34 +32,26 @@
@RunWith(RobolectricTestRunner::class)
@DoNotInstrument
class CameraFiltersTest {
- private val mCameras: LinkedHashSet<Camera> = linkedSetOf()
+ private val mCameraInfos: ArrayList<CameraInfo> = arrayListOf()
@Before
fun setUp() {
- val fakeCamera0 = FakeCamera(
- "0",
- null,
- FakeCameraInfoInternal("0", 0, CameraSelector.LENS_FACING_BACK)
- )
- mCameras.add(fakeCamera0)
+ val fakeCameraInfo0 = FakeCameraInfoInternal("0", 0, CameraSelector.LENS_FACING_BACK)
+ mCameraInfos.add(fakeCameraInfo0)
- val fakeCamera1 = FakeCamera(
- "1",
- null,
- FakeCameraInfoInternal("1", 180, CameraSelector.LENS_FACING_FRONT)
- )
- mCameras.add(fakeCamera1)
+ val fakeCameraInfo1 = FakeCameraInfoInternal("1", 180, CameraSelector.LENS_FACING_FRONT)
+ mCameraInfos.add(fakeCameraInfo1)
}
@Test
fun filterAny() {
- val resultCameras = CameraFilters.ANY.filter(mCameras)
- assertThat(resultCameras).isEqualTo(mCameras)
+ val resultCameras = CameraFilters.ANY.filter(mCameraInfos)
+ assertThat(resultCameras).isEqualTo(mCameraInfos)
}
@Test
fun filterNone() {
- val resultCameras = CameraFilters.NONE.filter(mCameras)
+ val resultCameras = CameraFilters.NONE.filter(mCameraInfos)
assertThat(resultCameras).isEmpty()
}
}
\ No newline at end of file
diff --git a/camera/camera-extensions/src/main/java/androidx/camera/extensions/ExtensionCameraFilter.java b/camera/camera-extensions/src/main/java/androidx/camera/extensions/ExtensionCameraFilter.java
index 8a82169..6b1924d 100644
--- a/camera/camera-extensions/src/main/java/androidx/camera/extensions/ExtensionCameraFilter.java
+++ b/camera/camera-extensions/src/main/java/androidx/camera/extensions/ExtensionCameraFilter.java
@@ -23,16 +23,16 @@
import androidx.annotation.experimental.UseExperimental;
import androidx.camera.camera2.interop.Camera2CameraInfo;
import androidx.camera.camera2.interop.ExperimentalCamera2Interop;
-import androidx.camera.core.Camera;
import androidx.camera.core.CameraFilter;
import androidx.camera.core.CameraInfo;
import androidx.camera.core.ExperimentalCameraFilter;
-import androidx.camera.core.impl.CameraInternal;
+import androidx.camera.core.impl.CameraInfoInternal;
import androidx.camera.extensions.impl.ImageCaptureExtenderImpl;
import androidx.camera.extensions.impl.PreviewExtenderImpl;
import androidx.core.util.Preconditions;
-import java.util.LinkedHashSet;
+import java.util.ArrayList;
+import java.util.List;
/**
* A filter that filters camera based on extender implementation. If the implementation is
@@ -62,12 +62,11 @@
@UseExperimental(markerClass = ExperimentalCamera2Interop.class)
@NonNull
@Override
- public LinkedHashSet<Camera> filter(@NonNull LinkedHashSet<Camera> cameras) {
- LinkedHashSet<Camera> resultCameras = new LinkedHashSet<>();
- for (Camera camera : cameras) {
- Preconditions.checkState(camera instanceof CameraInternal,
- "The camera doesn't contain internal implementation.");
- CameraInfo cameraInfo = camera.getCameraInfo();
+ public List<CameraInfo> filter(@NonNull List<CameraInfo> cameraInfos) {
+ List<CameraInfo> result = new ArrayList<>();
+ for (CameraInfo cameraInfo : cameraInfos) {
+ Preconditions.checkArgument(cameraInfo instanceof CameraInfoInternal,
+ "The camera info doesn't contain internal implementation.");
String cameraId = Camera2CameraInfo.from(cameraInfo).getCameraId();
CameraCharacteristics cameraCharacteristics =
Camera2CameraInfo.extractCameraCharacteristics(cameraInfo);
@@ -86,10 +85,10 @@
}
if (available) {
- resultCameras.add(camera);
+ result.add(cameraInfo);
}
}
- return resultCameras;
+ return result;
}
}
diff --git a/camera/camera-extensions/src/main/java/androidx/camera/extensions/Extensions.java b/camera/camera-extensions/src/main/java/androidx/camera/extensions/Extensions.java
index 71c05559..9c6f01d 100644
--- a/camera/camera-extensions/src/main/java/androidx/camera/extensions/Extensions.java
+++ b/camera/camera-extensions/src/main/java/androidx/camera/extensions/Extensions.java
@@ -25,6 +25,7 @@
import androidx.camera.core.Camera;
import androidx.camera.core.CameraFilter;
import androidx.camera.core.CameraInfo;
+import androidx.camera.core.CameraSelector;
import androidx.camera.core.ExperimentalCameraFilter;
import androidx.camera.core.UseCase;
import androidx.camera.core.impl.CameraFilters;
@@ -138,10 +139,10 @@
throw new IllegalArgumentException("Extension mode not supported on camera: " + mode);
}
- CameraFilter extensionsFilter = getFilter(mode);
+ CameraSelector cameraSelector =
+ new CameraSelector.Builder().addCameraFilter(getFilter(mode)).build();
Camera extensionCamera =
- extensionsFilter.filter(
- new LinkedHashSet<>(camera.getCameraInternals())).iterator().next();
+ cameraSelector.select(new LinkedHashSet<>(camera.getCameraInternals()));
CameraInfo extensionsCameraInfo = extensionCamera.getCameraInfo();
ExtensionsUseCaseConfigFactory factory = new ExtensionsUseCaseConfigFactory(mode,
@@ -190,11 +191,17 @@
*/
@UseExperimental(markerClass = ExperimentalCameraFilter.class)
public boolean isExtensionAvailable(@NonNull Camera camera, @ExtensionMode int mode) {
- CameraFilter filter = getFilter(mode);
+ CameraSelector cameraSelector =
+ new CameraSelector.Builder().addCameraFilter(getFilter(mode)).build();
// Extension is available for the camera if it contains a CameraInternal which supports
// the extension
- return !filter.filter(new LinkedHashSet<>(camera.getCameraInternals())).isEmpty();
+ try {
+ cameraSelector.select(new LinkedHashSet<>(camera.getCameraInternals()));
+ } catch (IllegalArgumentException e) {
+ return false;
+ }
+ return true;
}
@UseExperimental(markerClass = ExperimentalCameraFilter.class)
diff --git a/camera/camera-lifecycle/src/main/java/androidx/camera/lifecycle/ProcessCameraProvider.java b/camera/camera-lifecycle/src/main/java/androidx/camera/lifecycle/ProcessCameraProvider.java
index 470049c..2052233 100644
--- a/camera/camera-lifecycle/src/main/java/androidx/camera/lifecycle/ProcessCameraProvider.java
+++ b/camera/camera-lifecycle/src/main/java/androidx/camera/lifecycle/ProcessCameraProvider.java
@@ -246,8 +246,8 @@
* <p>The {@link Camera} returned is determined by the given camera selector, plus other
* internal requirements, possibly from use case configurations. The camera returned from
* bindToLifecycle may differ from the camera determined solely by a camera selector. If the
- * camera selector can't resolve a camera under the requirements, an IllegalArgumentException
- * will be thrown.
+ * camera selector can't resolve a valid camera under the requirements, an
+ * IllegalArgumentException will be thrown.
*
* <p>Only {@link UseCase} bound to latest active {@link Lifecycle} can keep alive.
* {@link UseCase} bound to other {@link Lifecycle} will be stopped.
diff --git a/car/app/app/build.gradle b/car/app/app/build.gradle
index 16e0e08..5e853f9 100644
--- a/car/app/app/build.gradle
+++ b/car/app/app/build.gradle
@@ -40,12 +40,6 @@
androidTestImplementation("junit:junit:4.13")
androidTestImplementation(TRUTH)
androidTestImplementation(MOCKITO_ANDROID)
- androidTestImplementation ROBOLECTRIC, {
- // The following are excluded as they are resulting in duplicated class conflicts with
- // the junit dependency above.
- exclude group: "org.apache.maven.wagon"
- exclude group: "org.apache.maven"
- }
}
android {
diff --git a/car/app/app/src/androidTest/AndroidManifest.xml b/car/app/app/src/androidTest/AndroidManifest.xml
index d84e190..3bc2684 100644
--- a/car/app/app/src/androidTest/AndroidManifest.xml
+++ b/car/app/app/src/androidTest/AndroidManifest.xml
@@ -16,5 +16,4 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="androidx.car.app">
-
</manifest>
diff --git a/car/app/app/src/androidTest/java/androidx/car/app/TestUtils.java b/car/app/app/src/androidTest/java/androidx/car/app/TestUtils.java
index 78d3eb4..5378ae2 100644
--- a/car/app/app/src/androidTest/java/androidx/car/app/TestUtils.java
+++ b/car/app/app/src/androidTest/java/androidx/car/app/TestUtils.java
@@ -20,8 +20,16 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
import android.text.SpannableString;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.car.app.model.Action;
@@ -163,4 +171,13 @@
assertThat(dateTimeWithZone.getTimeSinceEpochMillis())
.isEqualTo(dateTimeWithZone.getTimeSinceEpochMillis());
}
+
+ public static Context getMockContextWithPermission(@NonNull String permission) {
+ Context mockContext = mock(Context.class);
+ PackageManager packageManager = mock(PackageManager.class);
+ when(mockContext.getPackageManager()).thenReturn(packageManager);
+ when(packageManager.checkPermission(eq(permission), any())).thenReturn(
+ PackageManager.PERMISSION_GRANTED);
+ return mockContext;
+ }
}
diff --git a/car/app/app/src/androidTest/java/androidx/car/app/navigation/model/NavigationTemplateTest.java b/car/app/app/src/androidTest/java/androidx/car/app/navigation/model/NavigationTemplateTest.java
index 9c3724c..7b82386 100644
--- a/car/app/app/src/androidTest/java/androidx/car/app/navigation/model/NavigationTemplateTest.java
+++ b/car/app/app/src/androidTest/java/androidx/car/app/navigation/model/NavigationTemplateTest.java
@@ -22,6 +22,7 @@
import static org.junit.Assert.assertThrows;
+import androidx.car.app.CarAppPermission;
import androidx.car.app.TestUtils;
import androidx.car.app.model.ActionStrip;
import androidx.car.app.model.CarColor;
@@ -30,7 +31,7 @@
import androidx.car.app.utils.Logger;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
-import androidx.test.filters.SmallTest;
+import androidx.test.filters.LargeTest;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,7 +39,7 @@
import java.util.concurrent.TimeUnit;
/** Tests for {@link NavigationTemplate}. */
-@SmallTest
+@LargeTest
@RunWith(AndroidJUnit4.class)
public class NavigationTemplateTest {
private final ActionStrip mActionStrip =
@@ -417,23 +418,15 @@
@Test
public void checkPermissions_hasPermissions() {
- //TODO(rampara): Investigate failure to create ShadowPackageManager
-// NavigationTemplate template =
-// NavigationTemplate.builder()
-// .setActionStrip(mActionStrip)
-// .setBackgroundColor(CarColor.BLUE)
-// .build();
-//
-// Context context = ApplicationProvider.getApplicationContext();
-// PackageManager packageManager = context.getPackageManager();
-// PackageInfo pi = new PackageInfo();
-// pi.packageName = context.getPackageName();
-// pi.versionCode = 1;
-// pi.requestedPermissions = new String[]{CarAppPermission.NAVIGATION_TEMPLATES};
-// shadowOf(packageManager).installPackage(pi);
-//
-// // Expect that it does not throw
-// template.checkPermissions(context);
+ NavigationTemplate template =
+ NavigationTemplate.builder()
+ .setActionStrip(mActionStrip)
+ .setBackgroundColor(CarColor.BLUE)
+ .build();
+
+ // Expect that it does not throw
+ template.checkPermissions(
+ TestUtils.getMockContextWithPermission(CarAppPermission.NAVIGATION_TEMPLATES));
}
@Test
diff --git a/car/app/app/src/androidTest/java/androidx/car/app/navigation/model/PlaceListNavigationTemplateTest.java b/car/app/app/src/androidTest/java/androidx/car/app/navigation/model/PlaceListNavigationTemplateTest.java
index 18a4946..ff80881 100644
--- a/car/app/app/src/androidTest/java/androidx/car/app/navigation/model/PlaceListNavigationTemplateTest.java
+++ b/car/app/app/src/androidTest/java/androidx/car/app/navigation/model/PlaceListNavigationTemplateTest.java
@@ -23,6 +23,7 @@
import android.content.Context;
import android.text.SpannableString;
+import androidx.car.app.CarAppPermission;
import androidx.car.app.TestUtils;
import androidx.car.app.model.Action;
import androidx.car.app.model.ActionStrip;
@@ -41,13 +42,13 @@
import androidx.core.graphics.drawable.IconCompat;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
-import androidx.test.filters.SmallTest;
+import androidx.test.filters.LargeTest;
import org.junit.Test;
import org.junit.runner.RunWith;
/** Tests for {@link PlaceListNavigationTemplate}. */
-@SmallTest
+@LargeTest
@RunWith(AndroidJUnit4.class)
public class PlaceListNavigationTemplateTest {
private final Context mContext = ApplicationProvider.getApplicationContext();
@@ -491,23 +492,16 @@
@Test
public void checkPermissions_hasPermissions() {
- //TODO(rampara): Investigate failure to create ShadowPackageManager
-// PlaceListNavigationTemplate template =
-// PlaceListNavigationTemplate.builder()
-// .setItemList(
-// TestUtils.createItemListWithDistanceSpan(6, false, mDistanceSpan))
-// .setTitle("title")
-// .build();
-//
-// PackageManager packageManager = mContext.getPackageManager();
-// PackageInfo pi = new PackageInfo();
-// pi.packageName = mContext.getPackageName();
-// pi.versionCode = 1;
-// pi.requestedPermissions = new String[]{CarAppPermission.NAVIGATION_TEMPLATES};
-// shadowOf(packageManager).installPackage(pi);
-//
-// // Expect that it does not throw
-// template.checkPermissions(mContext);
+ PlaceListNavigationTemplate template =
+ PlaceListNavigationTemplate.builder()
+ .setItemList(
+ TestUtils.createItemListWithDistanceSpan(6, false, mDistanceSpan))
+ .setTitle("title")
+ .build();
+
+ // Expect that it does not throw
+ template.checkPermissions(
+ TestUtils.getMockContextWithPermission(CarAppPermission.NAVIGATION_TEMPLATES));
}
@Test
diff --git a/car/app/app/src/androidTest/java/androidx/car/app/navigation/model/RoutePreviewNavigationTemplateTest.java b/car/app/app/src/androidTest/java/androidx/car/app/navigation/model/RoutePreviewNavigationTemplateTest.java
index 3ff2ab1..6072876 100644
--- a/car/app/app/src/androidTest/java/androidx/car/app/navigation/model/RoutePreviewNavigationTemplateTest.java
+++ b/car/app/app/src/androidTest/java/androidx/car/app/navigation/model/RoutePreviewNavigationTemplateTest.java
@@ -26,6 +26,7 @@
import android.os.RemoteException;
import android.text.SpannableString;
+import androidx.car.app.CarAppPermission;
import androidx.car.app.IOnDoneCallback;
import androidx.car.app.TestUtils;
import androidx.car.app.model.Action;
@@ -42,13 +43,13 @@
import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
-import androidx.test.filters.SmallTest;
+import androidx.test.filters.LargeTest;
import org.junit.Test;
import org.junit.runner.RunWith;
/** Tests for {@link RoutePreviewNavigationTemplate}. */
-@SmallTest
+@LargeTest
@RunWith(AndroidJUnit4.class)
public class RoutePreviewNavigationTemplateTest {
private final Context mContext = ApplicationProvider.getApplicationContext();
@@ -583,25 +584,18 @@
@Test
public void checkPermissions_hasPermissions() {
- //TODO(rampara): Investigate failure to create ShadowPackageManager
-// RoutePreviewNavigationTemplate template =
-// RoutePreviewNavigationTemplate.builder()
-// .setTitle("Title")
-// .setItemList(TestUtils.createItemListWithDistanceSpan(2, true, DISTANCE))
-// .setNavigateAction(
-// Action.builder().setTitle("drive").setOnClickListener(() -> {
-// }).build())
-// .build();
-//
-// PackageManager packageManager = mContext.getPackageManager();
-// PackageInfo pi = new PackageInfo();
-// pi.packageName = mContext.getPackageName();
-// pi.versionCode = 1;
-// pi.requestedPermissions = new String[]{CarAppPermission.NAVIGATION_TEMPLATES};
-// shadowOf(packageManager).installPackage(pi);
-//
-// // Expect that it does not throw
-// template.checkPermissions(mContext);
+ RoutePreviewNavigationTemplate template =
+ RoutePreviewNavigationTemplate.builder()
+ .setTitle("Title")
+ .setItemList(TestUtils.createItemListWithDistanceSpan(2, true, DISTANCE))
+ .setNavigateAction(
+ Action.builder().setTitle("drive").setOnClickListener(() -> {
+ }).build())
+ .build();
+
+ // Expect that it does not throw
+ template.checkPermissions(
+ TestUtils.getMockContextWithPermission(CarAppPermission.NAVIGATION_TEMPLATES));
}
@Test
diff --git a/car/app/app/src/androidTest/java/androidx/car/app/serialization/BundlerTest.java b/car/app/app/src/androidTest/java/androidx/car/app/serialization/BundlerTest.java
index 7e45e9f..40f8fa4 100644
--- a/car/app/app/src/androidTest/java/androidx/car/app/serialization/BundlerTest.java
+++ b/car/app/app/src/androidTest/java/androidx/car/app/serialization/BundlerTest.java
@@ -25,7 +25,6 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
-import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
@@ -52,12 +51,12 @@
import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SdkSuppress;
import androidx.test.filters.SmallTest;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -194,7 +193,7 @@
Bundle bundle = Bundler.toBundle(value);
@SuppressWarnings("unchecked") // Casting of deserialized Object from Bundler.
- Map<String, LatLng> readIn = (Map<String, LatLng>) Bundler.fromBundle(bundle);
+ Map<String, LatLng> readIn = (Map<String, LatLng>) Bundler.fromBundle(bundle);
assertThat(readIn.keySet()).isEqualTo(value.keySet());
@@ -223,7 +222,7 @@
Bundle bundle = Bundler.toBundle(value);
@SuppressWarnings("unchecked") // Casting of deserialized Object from Bundler.
- List<LatLng> readIn = (List<LatLng>) Bundler.fromBundle(bundle);
+ List<LatLng> readIn = (List<LatLng>) Bundler.fromBundle(bundle);
assertThat(readIn).isEqualTo(value);
}
@@ -306,7 +305,7 @@
}
@Test
- @Config(sdk = Build.VERSION_CODES.M)
+ @SdkSuppress(minSdkVersion = 23)
public void imageSerialization_Icon() throws BundlerException {
Bitmap bitmap = Bitmap.createBitmap(48, 48, Bitmap.Config.ARGB_8888);
try {
diff --git a/collection/collection/api/api_lint.ignore b/collection/collection/api/api_lint.ignore
index a0c5243..60ae519 100644
--- a/collection/collection/api/api_lint.ignore
+++ b/collection/collection/api/api_lint.ignore
@@ -5,6 +5,8 @@
Method should return Collection<T> (or subclass) instead of raw array; was `T[]`
ArrayReturn: androidx.collection.ArraySet#toArray(T[]) parameter #0:
Method parameter should be Collection<T> (or subclass) instead of raw array; was `T[]`
+ArrayReturn: androidx.collection.ArraySet#ArraySet(E[]) parameter #0:
+ Method parameter should be Collection<E> (or subclass) instead of raw array; was `E[]`
KotlinOperator: androidx.collection.CircularArray#get(int):
diff --git a/collection/collection/api/current.txt b/collection/collection/api/current.txt
index ee60264..fec5af1 100644
--- a/collection/collection/api/current.txt
+++ b/collection/collection/api/current.txt
@@ -19,6 +19,7 @@
ctor public ArraySet(int);
ctor public ArraySet(androidx.collection.ArraySet<E!>?);
ctor public ArraySet(java.util.Collection<E!>?);
+ ctor public ArraySet(E![]?);
method public boolean add(E?);
method public void addAll(androidx.collection.ArraySet<? extends E>);
method public boolean addAll(java.util.Collection<? extends E>);
diff --git a/collection/collection/api/public_plus_experimental_current.txt b/collection/collection/api/public_plus_experimental_current.txt
index ee60264..fec5af1 100644
--- a/collection/collection/api/public_plus_experimental_current.txt
+++ b/collection/collection/api/public_plus_experimental_current.txt
@@ -19,6 +19,7 @@
ctor public ArraySet(int);
ctor public ArraySet(androidx.collection.ArraySet<E!>?);
ctor public ArraySet(java.util.Collection<E!>?);
+ ctor public ArraySet(E![]?);
method public boolean add(E?);
method public void addAll(androidx.collection.ArraySet<? extends E>);
method public boolean addAll(java.util.Collection<? extends E>);
diff --git a/collection/collection/api/restricted_current.txt b/collection/collection/api/restricted_current.txt
index ee60264..fec5af1 100644
--- a/collection/collection/api/restricted_current.txt
+++ b/collection/collection/api/restricted_current.txt
@@ -19,6 +19,7 @@
ctor public ArraySet(int);
ctor public ArraySet(androidx.collection.ArraySet<E!>?);
ctor public ArraySet(java.util.Collection<E!>?);
+ ctor public ArraySet(E![]?);
method public boolean add(E?);
method public void addAll(androidx.collection.ArraySet<? extends E>);
method public boolean addAll(java.util.Collection<? extends E>);
diff --git a/collection/collection/src/main/java/androidx/collection/ArraySet.java b/collection/collection/src/main/java/androidx/collection/ArraySet.java
index a74e3f9..eead69d 100644
--- a/collection/collection/src/main/java/androidx/collection/ArraySet.java
+++ b/collection/collection/src/main/java/androidx/collection/ArraySet.java
@@ -314,6 +314,18 @@
}
/**
+ * Create a new ArraySet with items from the given array.
+ */
+ public ArraySet(@Nullable E[] array) {
+ this();
+ if (array != null) {
+ for (E value : array) {
+ add(value);
+ }
+ }
+ }
+
+ /**
* Make the array map empty. All storage is released.
*/
@Override
diff --git a/collection/collection/src/test/java/androidx/collection/LruCacheTest.java b/collection/collection/src/test/java/androidx/collection/LruCacheTest.java
index ab173be..6e14244 100644
--- a/collection/collection/src/test/java/androidx/collection/LruCacheTest.java
+++ b/collection/collection/src/test/java/androidx/collection/LruCacheTest.java
@@ -452,6 +452,77 @@
assertEquals(Arrays.asList("a=1>2"), log);
}
+ /** Makes sure that LruCache operations are correctly synchronized to guarantee consistency. */
+ @Test
+ public void consistentMultithreadedAccess() {
+ class Tally {
+ int mNonNullValues;
+ int mNullValues;
+ int mValuesPut;
+ int mConflicts;
+ int mRemoved;
+ }
+
+ final Tally tally = new Tally();
+ final int rounds = 10000;
+ final String key = "key";
+ final int value = 42;
+ final LruCache<String, Integer> cache = new LruCache<String, Integer>(1) {
+ @Override
+ protected Integer create(String key) {
+ return value;
+ }
+ };
+
+ Runnable r0 = new Runnable() {
+ @Override
+ public void run() {
+ for (int i = 0; i < rounds; i++) {
+ if (cache.get(key) != null) {
+ tally.mNonNullValues++;
+ } else {
+ tally.mNullValues++;
+ }
+ }
+ }
+ };
+
+ Runnable r1 = new Runnable() {
+ @Override
+ public void run() {
+ for (int i = 0; i < rounds; i++) {
+ if (i % 2 == 0) {
+ if (cache.put(key, value) != null) {
+ tally.mConflicts++;
+ } else {
+ tally.mValuesPut++;
+ }
+ } else {
+ cache.remove(key);
+ tally.mRemoved++;
+ }
+ }
+ }
+ };
+
+
+ Thread t0 = new Thread(r0);
+ Thread t1 = new Thread(r1);
+
+ t0.start();
+ t1.start();
+ try {
+ t0.join();
+ t1.join();
+ } catch (InterruptedException e) {
+ fail();
+ }
+
+ assertEquals(rounds, tally.mNonNullValues);
+ assertEquals(0, tally.mNullValues);
+ assertEquals(rounds, tally.mValuesPut + tally.mConflicts + tally.mRemoved);
+ }
+
private LruCache<String, String> newCreatingCache() {
return new LruCache<String, String>(3) {
@Override protected String create(String key) {
diff --git a/compose/androidview/androidview/integration-tests/androidview-demos/src/main/java/androidx/compose/androidview/demos/ComplexInteractions.kt b/compose/androidview/androidview/integration-tests/androidview-demos/src/main/java/androidx/compose/androidview/demos/ComplexInteractions.kt
index 5822b2c..223f3c9 100644
--- a/compose/androidview/androidview/integration-tests/androidview-demos/src/main/java/androidx/compose/androidview/demos/ComplexInteractions.kt
+++ b/compose/androidview/androidview/integration-tests/androidview-demos/src/main/java/androidx/compose/androidview/demos/ComplexInteractions.kt
@@ -38,8 +38,8 @@
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.platform.ComposeView
-import androidx.compose.ui.platform.ContextAmbient
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
@@ -56,7 +56,7 @@
@Composable
fun ComposeInAndroidInComposeEtcTargetingDemo() {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
Column {
Text(
"In this demo, from the inside out, we have a Compose Button, wrapped in 2 Android " +
diff --git a/compose/animation/animation-core/build.gradle b/compose/animation/animation-core/build.gradle
index e11c31d..3967ac7 100644
--- a/compose/animation/animation-core/build.gradle
+++ b/compose/animation/animation-core/build.gradle
@@ -103,7 +103,6 @@
androidx {
name = "Compose Animation Core"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.ANIMATION
inceptionYear = "2019"
description = "Animation engine and animation primitives that are the building blocks of the Compose animation library"
diff --git a/compose/animation/animation-core/samples/build.gradle b/compose/animation/animation-core/samples/build.gradle
index c18fe89..9dd1810 100644
--- a/compose/animation/animation-core/samples/build.gradle
+++ b/compose/animation/animation-core/samples/build.gradle
@@ -48,7 +48,6 @@
androidx {
name = "AndroidX Compose UI Animation Library Core Classes Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.ANIMATION
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose UI Animation Core Classes"
diff --git a/compose/animation/animation/build.gradle b/compose/animation/animation/build.gradle
index f8a44f63..d45697a1 100644
--- a/compose/animation/animation/build.gradle
+++ b/compose/animation/animation/build.gradle
@@ -108,7 +108,6 @@
androidx {
name = "Compose Animation"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.ANIMATION
inceptionYear = "2019"
description = "Compose animation library"
diff --git a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/AnimatableSeekBarDemo.kt b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/AnimatableSeekBarDemo.kt
index e40f65e..caff0b4 100644
--- a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/AnimatableSeekBarDemo.kt
+++ b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/AnimatableSeekBarDemo.kt
@@ -42,14 +42,14 @@
import androidx.compose.ui.gesture.pressIndicatorGestureFilter
import androidx.compose.ui.gesture.rawDragGestureFilter
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@Composable
fun AnimatableSeekBarDemo() {
val clock = remember { ManualAnimationClock(0L) }
- Providers(AnimationClockAmbient provides clock) {
+ Providers(AmbientAnimationClock provides clock) {
Column {
Text(
"Drag to update AnimationClock",
diff --git a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/StateBasedRippleDemo.kt b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/StateBasedRippleDemo.kt
index 32cfb3b..03c4319 100644
--- a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/StateBasedRippleDemo.kt
+++ b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/StateBasedRippleDemo.kt
@@ -35,7 +35,7 @@
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.gesture.pressIndicatorGestureFilter
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.dp
@Composable
@@ -47,7 +47,7 @@
@Composable
private fun RippleRect() {
- val radius = with(DensityAmbient.current) { TargetRadius.toPx() }
+ val radius = with(AmbientDensity.current) { TargetRadius.toPx() }
val toState = remember { mutableStateOf(ButtonStatus.Initial) }
val rippleTransDef = remember { createTransDef(radius) }
val onPress: (Offset) -> Unit = { position ->
diff --git a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/SwipeToDismissDemo.kt b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/SwipeToDismissDemo.kt
index cad6c18..ca72348 100644
--- a/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/SwipeToDismissDemo.kt
+++ b/compose/animation/animation/integration-tests/animation-demos/src/main/java/androidx/compose/animation/demos/SwipeToDismissDemo.kt
@@ -40,7 +40,7 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import kotlin.math.sign
@@ -125,7 +125,7 @@
}
)
- val heightDp = with(DensityAmbient.current) { height.toDp() }
+ val heightDp = with(AmbientDensity.current) { height.toDp() }
Canvas(
modifier.fillMaxWidth()
diff --git a/compose/animation/animation/samples/build.gradle b/compose/animation/animation/samples/build.gradle
index 876d06b..58d3b8c 100644
--- a/compose/animation/animation/samples/build.gradle
+++ b/compose/animation/animation/samples/build.gradle
@@ -53,7 +53,6 @@
androidx {
name = "AndroidX Compose UI Animation Library Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.ANIMATION
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose UI Animation Library"
diff --git a/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimatedVisibilityTest.kt b/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimatedVisibilityTest.kt
index 2d6dbd1..f294292 100644
--- a/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimatedVisibilityTest.kt
+++ b/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimatedVisibilityTest.kt
@@ -29,7 +29,8 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
@@ -46,6 +47,7 @@
@RunWith(AndroidJUnit4::class)
@LargeTest
+@OptIn(ExperimentalTesting::class)
class AnimatedVisibilityTest {
@get:Rule
@@ -84,7 +86,7 @@
}
}
}
- density = DensityAmbient.current.density
+ density = AmbientDensity.current.density
}
rule.runOnIdle {
@@ -188,7 +190,7 @@
}
}
}
- density = DensityAmbient.current.density
+ density = AmbientDensity.current.density
}
rule.runOnIdle {
diff --git a/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimationModifierTest.kt b/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimationModifierTest.kt
index e27f2e1..8968251 100644
--- a/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimationModifierTest.kt
+++ b/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimationModifierTest.kt
@@ -28,9 +28,10 @@
import androidx.compose.ui.layout.Measurable
import androidx.compose.ui.layout.MeasureResult
import androidx.compose.ui.layout.MeasureScope
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.InspectableValue
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.IntSize
@@ -51,6 +52,7 @@
@RunWith(AndroidJUnit4::class)
@LargeTest
+@OptIn(ExperimentalTesting::class)
class AnimationModifierTest {
@get:Rule
@@ -95,7 +97,7 @@
}
.size(width.dp, height.dp)
)
- density = DensityAmbient.current.density
+ density = AmbientDensity.current.density
}
rule.runOnIdle {
diff --git a/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/CrossfadeTest.kt b/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/CrossfadeTest.kt
index 48388d0..a2a81cb 100644
--- a/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/CrossfadeTest.kt
+++ b/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/CrossfadeTest.kt
@@ -23,6 +23,7 @@
import androidx.compose.runtime.onDispose
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -34,6 +35,7 @@
@RunWith(AndroidJUnit4::class)
@MediumTest
+@OptIn(ExperimentalTesting::class)
class CrossfadeTest {
@get:Rule
diff --git a/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/SingleValueAnimationTest.kt b/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/SingleValueAnimationTest.kt
index c60995d4..857e076 100644
--- a/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/SingleValueAnimationTest.kt
+++ b/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/SingleValueAnimationTest.kt
@@ -33,6 +33,7 @@
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.lerp
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.Bounds
import androidx.compose.ui.unit.Position
@@ -47,6 +48,7 @@
@RunWith(AndroidJUnit4::class)
@MediumTest
+@OptIn(ExperimentalTesting::class)
class SingleValueAnimationTest {
@get:Rule
diff --git a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimatedValueEffects.kt b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimatedValueEffects.kt
index 986f12f..d8b3a1b 100644
--- a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimatedValueEffects.kt
+++ b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimatedValueEffects.kt
@@ -31,7 +31,7 @@
import androidx.compose.runtime.setValue
import androidx.compose.runtime.structuralEqualityPolicy
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
/**
* The animatedValue effect creates an [AnimatedValue] and positionally memoizes it. When the
@@ -49,7 +49,7 @@
initVal: T,
converter: TwoWayConverter<T, V>,
visibilityThreshold: T? = null,
- clock: AnimationClockObservable = AnimationClockAmbient.current
+ clock: AnimationClockObservable = AmbientAnimationClock.current
): AnimatedValue<T, V> = clock.asDisposableClock().let { disposableClock ->
remember(disposableClock) {
AnimatedValueModel(initVal, converter, disposableClock, visibilityThreshold)
@@ -67,7 +67,7 @@
fun animatedFloat(
initVal: Float,
visibilityThreshold: Float = Spring.DefaultDisplacementThreshold,
- clock: AnimationClockObservable = AnimationClockAmbient.current
+ clock: AnimationClockObservable = AmbientAnimationClock.current
): AnimatedFloat = clock.asDisposableClock().let { disposableClock ->
remember(disposableClock) { AnimatedFloatModel(initVal, disposableClock, visibilityThreshold) }
}
@@ -82,7 +82,7 @@
@Composable
fun animatedColor(
initVal: Color,
- clock: AnimationClockObservable = AnimationClockAmbient.current
+ clock: AnimationClockObservable = AmbientAnimationClock.current
): AnimatedValue<Color, AnimationVector4D> = clock.asDisposableClock().let { disposableClock ->
remember(disposableClock) {
AnimatedValueModel(
diff --git a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimatedVisibility.kt b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimatedVisibility.kt
index 9f4b753..2f5aa97 100644
--- a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimatedVisibility.kt
+++ b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimatedVisibility.kt
@@ -27,7 +27,7 @@
import androidx.compose.runtime.setValue
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.util.fastForEach
@@ -255,7 +255,7 @@
}
}
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
val animations = remember(clock, enter, exit) {
// TODO: Should we delay changing enter/exit after on-going animations are finished?
TransitionAnimations(enter, exit, clock) {
diff --git a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimationModifier.kt b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimationModifier.kt
index bf2a5c9..132dfda 100644
--- a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimationModifier.kt
+++ b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimationModifier.kt
@@ -30,7 +30,7 @@
import androidx.compose.ui.composed
import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.layout.MeasureResult
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.IntSize
@@ -69,7 +69,7 @@
}
) {
// TODO: Listener could be a fun interface after 1.4
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
val animModifier = remember {
SizeAnimationModifier(animSpec, clock)
}
diff --git a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/LegacyTransition.kt b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/LegacyTransition.kt
index 1e6e430..fcfad1b 100644
--- a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/LegacyTransition.kt
+++ b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/LegacyTransition.kt
@@ -20,7 +20,7 @@
import androidx.compose.animation.core.TransitionDefinition
import androidx.compose.animation.core.TransitionState
import androidx.compose.runtime.Composable
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
/**
* __Deprecated:__ [Transition] has been deprecated. Please use [transition] instead.
@@ -71,7 +71,7 @@
fun <T> Transition(
definition: TransitionDefinition<T>,
toState: T,
- clock: AnimationClockObservable = AnimationClockAmbient.current,
+ clock: AnimationClockObservable = AmbientAnimationClock.current,
initState: T = toState,
onStateChangeFinished: ((T) -> Unit)? = null,
children: @Composable (state: TransitionState) -> Unit
diff --git a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/SingleValueAnimation.kt b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/SingleValueAnimation.kt
index 2854a61..3bc15a2 100644
--- a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/SingleValueAnimation.kt
+++ b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/SingleValueAnimation.kt
@@ -30,7 +30,7 @@
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.unit.Bounds
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
@@ -83,7 +83,7 @@
visibilityThreshold: Float = 0.01f,
endListener: ((Float) -> Unit)? = null
): Float {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
val anim = remember {
AnimatedFloatModel(target, clock, visibilityThreshold)
}
@@ -454,7 +454,7 @@
visibilityThreshold: T? = null,
endListener: ((T) -> Unit)? = null
): T {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
val anim = remember(clock, converter) {
AnimatedValueModel(target, converter, clock, visibilityThreshold)
}
diff --git a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/Transition.kt b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/Transition.kt
index d28017e..cb8442f 100644
--- a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/Transition.kt
+++ b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/Transition.kt
@@ -30,7 +30,7 @@
import androidx.compose.runtime.onCommit
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.util.annotation.VisibleForTesting
/**
@@ -76,7 +76,7 @@
fun <T> transition(
definition: TransitionDefinition<T>,
toState: T,
- clock: AnimationClockObservable = AnimationClockAmbient.current,
+ clock: AnimationClockObservable = AmbientAnimationClock.current,
initState: T = toState,
label: String? = null,
onStateChangeFinished: ((T) -> Unit)? = null
diff --git a/compose/compiler/compiler-hosted/build.gradle b/compose/compiler/compiler-hosted/build.gradle
index 9af08f8..38ef9e7 100644
--- a/compose/compiler/compiler-hosted/build.gradle
+++ b/compose/compiler/compiler-hosted/build.gradle
@@ -43,7 +43,6 @@
// This is only published because that is required when exporting it to g3.
// Nobody should ever get this artifact from maven; just from studio or from source
type = LibraryType.COMPILER_PLUGIN
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.COMPILER
inceptionYear = "2019"
description = "Contains the Kotlin compiler plugin for Compose used in Android Studio and IDEA"
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/RememberIntrinsicTransformTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/RememberIntrinsicTransformTests.kt
index 162bae9..f0780f7 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/RememberIntrinsicTransformTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/RememberIntrinsicTransformTests.kt
@@ -685,4 +685,57 @@
}
"""
)
+
+ @Test
+ fun testOptimizationFailsIfDefaultsGroupIsUsed(): Unit = comparisonPropagation(
+ """
+ class Foo
+ fun someInt(): Int = 123
+ """,
+ """
+ @Composable
+ fun Test(a: Int = someInt()) {
+ val foo = remember { Foo() }
+ print(foo)
+ print(a)
+ }
+ """,
+ """
+ @Composable
+ fun Test(a: Int, %composer: Composer<*>?, %changed: Int, %default: Int) {
+ %composer.startRestartGroup(<>, "C(Test)<rememb...>:Test.kt")
+ val %dirty = %changed
+ val a = a
+ if (%changed and 0b1110 === 0) {
+ %dirty = %dirty or if (%default and 0b0001 === 0 && %composer.changed(a)) 0b0100 else 0b0010
+ }
+ if (%dirty and 0b1011 xor 0b0010 !== 0 || !%composer.skipping) {
+ if (%changed and 0b0001 === 0 || %composer.defaultsInvalid) {
+ %composer.startDefaults()
+ if (%default and 0b0001 !== 0) {
+ a = someInt()
+ %dirty = %dirty and 0b1110.inv()
+ }
+ %composer.endDefaults()
+ } else {
+ %composer.skipCurrentGroup()
+ if (%default and 0b0001 !== 0) {
+ %dirty = %dirty and 0b1110.inv()
+ }
+ }
+ val foo = remember({
+ val tmp0_return = Foo()
+ tmp0_return
+ }, %composer, 0)
+ print(foo)
+ print(a)
+ } else {
+ %composer.skipToGroupEnd()
+ }
+ %composer.endRestartGroup()?.updateScope { %composer: Composer<*>?, %force: Int ->
+ Test(a, %composer, %changed or 0b0001, %default)
+ }
+ }
+ """
+ )
}
\ No newline at end of file
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/RobolectricComposeTester.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/RobolectricComposeTester.kt
index ef08e12..6e67739 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/RobolectricComposeTester.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/RobolectricComposeTester.kt
@@ -27,7 +27,7 @@
import androidx.compose.runtime.Recomposer
import androidx.compose.runtime.compositionFor
import androidx.compose.ui.node.UiApplier
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import org.robolectric.Robolectric
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows.shadowOf
@@ -93,7 +93,7 @@
val realComposable: (Composer<*>, Int) -> Unit = { composer, _ ->
startProviders.invoke(
composer,
- listOf(ContextAmbient provides root.context).toTypedArray()
+ listOf(AmbientContext provides root.context).toTypedArray()
)
composable(composer, 0)
endProviders.invoke(composer)
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableFunctionBodyTransformer.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableFunctionBodyTransformer.kt
index 0ee8e8c..a0f051c 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableFunctionBodyTransformer.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableFunctionBodyTransformer.kt
@@ -1468,6 +1468,7 @@
bodyPreamble.statements.addAll(setDefaults.statements)
} else if (setDefaults.statements.isNotEmpty()) {
// otherwise, we wrap the whole thing in an if expression with a skip
+ scope.hasDefaultsGroup = true
bodyPreamble.statements.add(
irIfThenElse(
// this prevents us from re-executing the defaults if this function is getting
@@ -2569,7 +2570,7 @@
loop@ while (scope != null) {
when (scope) {
is Scope.FunctionScope -> {
- return if (scope.hasComposableCallsWithGroups) {
+ return if (scope.hasComposableCallsWithGroups || scope.hasDefaultsGroup) {
false
} else if (scope.isInlinedLambda) {
scope = scope.parent
@@ -3512,6 +3513,7 @@
}
}
+ var hasDefaultsGroup = false
var hasComposableCallsWithGroups = false
private set
var hasComposableCalls = false
diff --git a/compose/compiler/compiler/build.gradle b/compose/compiler/compiler/build.gradle
index 5ff293c..d2fce5f 100644
--- a/compose/compiler/compiler/build.gradle
+++ b/compose/compiler/compiler/build.gradle
@@ -56,7 +56,6 @@
androidx {
name = "Compose Compiler"
type = LibraryType.COMPILER_PLUGIN
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.COMPILER
inceptionYear = "2019"
description = "Compiler plugin that enables Compose"
diff --git a/compose/desktop/desktop/build.gradle b/compose/desktop/desktop/build.gradle
index 170651c..2ca4606 100644
--- a/compose/desktop/desktop/build.gradle
+++ b/compose/desktop/desktop/build.gradle
@@ -80,7 +80,6 @@
androidx {
name = "Jetpack Compose desktop implementation"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.DESKTOP
inceptionYear = "2020"
legacyDisableKotlinStrictApiMode = true
diff --git a/compose/desktop/desktop/src/jvmMain/kotlin/androidx/compose/ui/window/Popup.kt b/compose/desktop/desktop/src/jvmMain/kotlin/androidx/compose/ui/window/Popup.kt
index bec512f..b45012f 100644
--- a/compose/desktop/desktop/src/jvmMain/kotlin/androidx/compose/ui/window/Popup.kt
+++ b/compose/desktop/desktop/src/jvmMain/kotlin/androidx/compose/ui/window/Popup.kt
@@ -25,7 +25,7 @@
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.gesture.tapGestureFilter
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.DesktopOwner
import androidx.compose.ui.platform.DesktopOwnersAmbient
import androidx.compose.ui.platform.setContent
@@ -64,7 +64,7 @@
@Composable
private fun PopupLayout(children: @Composable () -> Unit) {
val owners = DesktopOwnersAmbient.current
- val density = DensityAmbient.current
+ val density = AmbientDensity.current
val owner = remember {
val owner = DesktopOwner(owners, density)
owner.setContent(children)
diff --git a/compose/foundation/foundation-layout/build.gradle b/compose/foundation/foundation-layout/build.gradle
index ae35467..0d9b4e1 100644
--- a/compose/foundation/foundation-layout/build.gradle
+++ b/compose/foundation/foundation-layout/build.gradle
@@ -110,7 +110,6 @@
androidx {
name = "Compose Layouts"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.FOUNDATION
inceptionYear = "2019"
description = "Compose layout implementations"
diff --git a/compose/foundation/foundation-layout/integration-tests/layout-demos/src/main/java/androidx/compose/foundation/layout/demos/RtlDemo.kt b/compose/foundation/foundation-layout/integration-tests/layout-demos/src/main/java/androidx/compose/foundation/layout/demos/RtlDemo.kt
index 98e9e17..af29cfe 100644
--- a/compose/foundation/foundation-layout/integration-tests/layout-demos/src/main/java/androidx/compose/foundation/layout/demos/RtlDemo.kt
+++ b/compose/foundation/foundation-layout/integration-tests/layout-demos/src/main/java/androidx/compose/foundation/layout/demos/RtlDemo.kt
@@ -34,7 +34,7 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.WithConstraints
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
@@ -61,10 +61,10 @@
)
CustomLayout(false)
Text("WITH CONSTRAINTS", Modifier.align(Alignment.CenterHorizontally))
- Providers(LayoutDirectionAmbient provides LayoutDirection.Ltr) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Ltr) {
LayoutWithConstraints("LD: set LTR via ambient")
}
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
LayoutWithConstraints("LD: set RTL via ambient")
}
LayoutWithConstraints(text = "LD: locale")
@@ -109,7 +109,7 @@
Row {
Box(boxSize.background(Color.Red)) {}
Box(boxSize.background(Color.Green)) {}
- Providers(LayoutDirectionAmbient provides LayoutDirection.Ltr) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Ltr) {
Row {
Box(boxSize.background(Color.Magenta)) {}
Box(boxSize.background(Color.Yellow)) {}
@@ -179,7 +179,7 @@
private fun LayoutWithConstraints(text: String) {
WithConstraints {
val w = maxWidth / 3
- val color = if (LayoutDirectionAmbient.current == LayoutDirection.Ltr) {
+ val color = if (AmbientLayoutDirection.current == LayoutDirection.Ltr) {
Color.Red
} else {
Color.Magenta
diff --git a/compose/foundation/foundation-layout/samples/build.gradle b/compose/foundation/foundation-layout/samples/build.gradle
index 910e241..fbfbca1 100644
--- a/compose/foundation/foundation-layout/samples/build.gradle
+++ b/compose/foundation/foundation-layout/samples/build.gradle
@@ -53,7 +53,6 @@
androidx {
name = "AndroidX Compose UI Core Layout Classes Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.FOUNDATION
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose UI Core Layout Classes"
diff --git a/compose/foundation/foundation-layout/samples/src/main/java/androidx/compose/foundation/layout/samples/RelativePaddingFromSamples.kt b/compose/foundation/foundation-layout/samples/src/main/java/androidx/compose/foundation/layout/samples/RelativePaddingFromSamples.kt
index 3919e3d..5709620 100644
--- a/compose/foundation/foundation-layout/samples/src/main/java/androidx/compose/foundation/layout/samples/RelativePaddingFromSamples.kt
+++ b/compose/foundation/foundation-layout/samples/src/main/java/androidx/compose/foundation/layout/samples/RelativePaddingFromSamples.kt
@@ -23,7 +23,7 @@
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.FirstBaseline
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@@ -34,7 +34,7 @@
// first line of text.
val distanceToBaseline = 30.sp
// We convert the 30.sp value to dps, which is required for the paddingFrom API.
- val distanceToBaselineDp = with(DensityAmbient.current) { distanceToBaseline.toDp() }
+ val distanceToBaselineDp = with(AmbientDensity.current) { distanceToBaseline.toDp() }
// The result will be a layout with 30.sp distance from the top of the layout box to the
// baseline of the first line of text.
Text(
diff --git a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/BoxTest.kt b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/BoxTest.kt
index 505c274..bf652ce 100644
--- a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/BoxTest.kt
+++ b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/BoxTest.kt
@@ -25,8 +25,8 @@
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInParent
import androidx.compose.ui.node.Ref
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.InspectableValue
-import androidx.compose.ui.platform.LayoutDirectionAmbient
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.IntSize
@@ -255,7 +255,7 @@
val childPosition = Array(9) { Ref<Offset>() }
show {
Box(Modifier.wrapContentSize(Alignment.TopStart)) {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Box(
Modifier
.preferredSize(tripleSizeDp)
diff --git a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/ConstraintLayoutTest.kt b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/ConstraintLayoutTest.kt
index d563339..ca0995c 100644
--- a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/ConstraintLayoutTest.kt
+++ b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/ConstraintLayoutTest.kt
@@ -26,8 +26,8 @@
import androidx.compose.ui.layout.positionInParent
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.node.Ref
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.InspectableValue
-import androidx.compose.ui.platform.LayoutDirectionAmbient
import androidx.compose.ui.platform.ValueElement
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
import androidx.compose.ui.test.junit4.createComposeRule
@@ -529,7 +529,7 @@
val position = Array(3) { Ref<Offset>() }
rule.setContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
ConstraintLayout(Modifier.fillMaxSize()) {
val (box0, box1, box2) = createRefs()
Box(
@@ -649,7 +649,7 @@
val position = Array(8) { 0f }
rule.setContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
ConstraintLayout(Modifier.size(size)) {
val guidelines = arrayOf(
createGuidelineFromStart(offset),
@@ -749,7 +749,7 @@
val position = Array(4) { 0f }
rule.setContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
ConstraintLayout(Modifier.size(size)) {
val (box1, box2) = createRefs()
val guideline1 = createGuidelineFromAbsoluteLeft(offset)
@@ -878,7 +878,7 @@
val position = Array(16) { 0f }
rule.setContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
ConstraintLayout(Modifier.size(size)) {
val box = createRef()
val guideline = createGuidelineFromAbsoluteLeft(offset)
diff --git a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutAlignTest.kt b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutAlignTest.kt
index 5e1e41f..8a9addc 100644
--- a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutAlignTest.kt
+++ b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutAlignTest.kt
@@ -26,7 +26,7 @@
import androidx.compose.ui.layout.positionInParent
import androidx.compose.ui.node.Ref
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
@@ -129,7 +129,7 @@
val childSize = Array(3) { Ref<IntSize>() }
val childPosition = Array(3) { Ref<Offset>() }
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Box(Modifier.fillMaxSize()) {
Box(Modifier.fillMaxSize().wrapContentSize(Alignment.TopStart)) {
Box(
diff --git a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutDirectionModifierTest.kt b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutDirectionModifierTest.kt
index d5251d3..94c094b 100644
--- a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutDirectionModifierTest.kt
+++ b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutDirectionModifierTest.kt
@@ -22,7 +22,7 @@
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.Modifier
import androidx.compose.ui.node.Ref
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
import androidx.test.filters.SmallTest
import org.junit.Assert.assertEquals
@@ -44,7 +44,7 @@
val resultLayoutDirection = Ref<LayoutDirection>()
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Layout(children = @Composable {}) { _, _ ->
resultLayoutDirection.value = layoutDirection
latch.countDown()
@@ -64,7 +64,7 @@
show {
@OptIn(ExperimentalLayout::class)
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Layout(
children = @Composable {},
modifier = Modifier.preferredWidth(IntrinsicSize.Max),
@@ -93,10 +93,10 @@
val resultLayoutDirection = Ref<LayoutDirection>()
show {
- val initialLayoutDirection = LayoutDirectionAmbient.current
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ val initialLayoutDirection = AmbientLayoutDirection.current
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Box {
- Providers(LayoutDirectionAmbient provides initialLayoutDirection) {
+ Providers(AmbientLayoutDirection provides initialLayoutDirection) {
Layout(emptyContent()) { _, _ ->
resultLayoutDirection.value = layoutDirection
latch.countDown()
diff --git a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutOffsetTest.kt b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutOffsetTest.kt
index a119603..a67d813 100644
--- a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutOffsetTest.kt
+++ b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutOffsetTest.kt
@@ -25,8 +25,8 @@
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInRoot
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.InspectableValue
-import androidx.compose.ui.platform.LayoutDirectionAmbient
import androidx.compose.ui.platform.ValueElement
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
import androidx.compose.ui.platform.testTag
@@ -101,7 +101,7 @@
var positionX = 0
var positionY = 0
rule.setContent {
- Providers((LayoutDirectionAmbient provides LayoutDirection.Rtl)) {
+ Providers((AmbientLayoutDirection provides LayoutDirection.Rtl)) {
Box(
Modifier.testTag("box")
.wrapContentSize(Alignment.TopEnd)
@@ -161,7 +161,7 @@
var positionX = 0
var positionY = 0
rule.setContent {
- Providers((LayoutDirectionAmbient provides LayoutDirection.Rtl)) {
+ Providers((AmbientLayoutDirection provides LayoutDirection.Rtl)) {
Box(
Modifier.testTag("box")
.wrapContentSize(Alignment.TopEnd)
@@ -224,7 +224,7 @@
var positionX = 0f
var positionY = 0f
rule.setContent {
- Providers((LayoutDirectionAmbient provides LayoutDirection.Rtl)) {
+ Providers((AmbientLayoutDirection provides LayoutDirection.Rtl)) {
Box(
Modifier.testTag("box")
.wrapContentSize(Alignment.TopEnd)
@@ -293,7 +293,7 @@
var positionX = 0f
var positionY = 0f
rule.setContent {
- Providers((LayoutDirectionAmbient provides LayoutDirection.Rtl)) {
+ Providers((AmbientLayoutDirection provides LayoutDirection.Rtl)) {
Box(
Modifier.testTag("box")
.wrapContentSize(Alignment.TopEnd)
diff --git a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutPaddingTest.kt b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutPaddingTest.kt
index 8531870..698198b 100644
--- a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutPaddingTest.kt
+++ b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutPaddingTest.kt
@@ -25,8 +25,8 @@
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.layout.onGloballyPositioned
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.InspectableValue
-import androidx.compose.ui.platform.LayoutDirectionAmbient
import androidx.compose.ui.platform.ValueElement
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
import androidx.compose.ui.unit.Constraints
@@ -260,7 +260,7 @@
// ltr: P1 S P2 | S P3 | P1 S
// rtl: S P1 | P3 S | P2 S P1
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(Modifier.fillMaxSize()) {
Box(
Modifier.padding(start = padding1Dp, end = padding2Dp)
@@ -336,7 +336,7 @@
// ltr: P1 S P2 | S P3
// rtl: S P3 | P1 S P2
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(Modifier.fillMaxSize()) {
Box(
Modifier.absolutePadding(left = padding1Dp, right = padding2Dp)
diff --git a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutTest.kt b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutTest.kt
index 42cb2176..9487eba 100644
--- a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutTest.kt
+++ b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/LayoutTest.kt
@@ -35,8 +35,8 @@
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.node.Ref
import androidx.compose.ui.layout.onGloballyPositioned
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.AndroidOwner
-import androidx.compose.ui.platform.DensityAmbient
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Density
@@ -205,7 +205,7 @@
modifier: Modifier = Modifier,
children: @Composable () -> Unit
) {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
val pxConstraints = Constraints(constraints)
Layout(
children,
diff --git a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/RowColumnTest.kt b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/RowColumnTest.kt
index 45a4350..59045d3 100644
--- a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/RowColumnTest.kt
+++ b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/RowColumnTest.kt
@@ -32,8 +32,8 @@
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.node.Ref
import androidx.compose.ui.layout.onGloballyPositioned
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.InspectableValue
-import androidx.compose.ui.platform.LayoutDirectionAmbient
import androidx.compose.ui.platform.ValueElement
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
import androidx.compose.ui.unit.Constraints
@@ -4024,7 +4024,7 @@
val drawLatch = CountDownLatch(2)
val childPosition = arrayOf(Offset.Zero, Offset.Zero)
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(Modifier.fillMaxWidth()) {
Container(
Modifier.preferredSize(sizeDp).onGloballyPositioned { coordinates ->
@@ -4068,7 +4068,7 @@
val childLayoutCoordinates = arrayOfNulls<LayoutCoordinates?>(childPosition.size)
var parentLayoutCoordinates: LayoutCoordinates? = null
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(
modifier = Modifier
.fillMaxWidth()
@@ -4124,7 +4124,7 @@
val childLayoutCoordinates = arrayOfNulls<LayoutCoordinates?>(childPosition.size)
var parentLayoutCoordinates: LayoutCoordinates? = null
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(
modifier = Modifier
.fillMaxWidth()
@@ -4179,7 +4179,7 @@
val childLayoutCoordinates = arrayOfNulls<LayoutCoordinates?>(childPosition.size)
var parentLayoutCoordinates: LayoutCoordinates? = null
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(
modifier = Modifier
.fillMaxWidth()
@@ -4232,7 +4232,7 @@
val childLayoutCoordinates = arrayOfNulls<LayoutCoordinates?>(childPosition.size)
var parentLayoutCoordinates: LayoutCoordinates? = null
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(
modifier = Modifier
.fillMaxWidth()
@@ -4282,7 +4282,7 @@
val drawLatch = CountDownLatch(2)
val childPosition = arrayOf(Offset.Zero, Offset.Zero)
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End
@@ -4329,7 +4329,7 @@
val rowSize = rowSizePx.toDp()
val latch = CountDownLatch(3)
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Column {
Row(
horizontalArrangement = Arrangement.spacedBy(space, Alignment.End),
@@ -4365,7 +4365,7 @@
val drawLatch = CountDownLatch(2)
val childPosition = arrayOf(Offset.Zero, Offset.Zero)
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Column(Modifier.fillMaxWidth()) {
Container(
Modifier.preferredSize(sizeDp).onGloballyPositioned { coordinates ->
@@ -4410,7 +4410,7 @@
val drawLatch = CountDownLatch(2)
val childPosition = arrayOf(Offset.Zero, Offset.Zero)
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Column(Modifier.fillMaxWidth()) {
Container(
Modifier.preferredSize(sizeDp)
@@ -4449,7 +4449,7 @@
val drawLatch = CountDownLatch(2)
val childPosition = arrayOf(Offset.Zero, Offset.Zero)
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Column(Modifier.fillMaxWidth()) {
Container(
Modifier.preferredSize(sizeDp)
@@ -4557,7 +4557,7 @@
arrayOfNulls<LayoutCoordinates?>(childPosition.size)
var parentLayoutCoordinates: LayoutCoordinates? = null
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(
Modifier
.fillMaxWidth()
@@ -4670,7 +4670,7 @@
arrayOfNulls<LayoutCoordinates?>(childPosition.size)
var parentLayoutCoordinates: LayoutCoordinates? = null
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(
modifier = Modifier
.fillMaxWidth()
@@ -4799,7 +4799,7 @@
arrayOfNulls<LayoutCoordinates?>(childPosition.size)
var parentLayoutCoordinates: LayoutCoordinates? = null
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(
modifier = Modifier
.fillMaxWidth()
@@ -4935,7 +4935,7 @@
arrayOfNulls<LayoutCoordinates?>(childPosition.size)
var parentLayoutCoordinates: LayoutCoordinates? = null
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(
modifier = Modifier
.fillMaxWidth()
@@ -5067,7 +5067,7 @@
arrayOfNulls<LayoutCoordinates?>(childPosition.size)
var parentLayoutCoordinates: LayoutCoordinates? = null
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(
modifier = Modifier
.fillMaxWidth()
@@ -5199,7 +5199,7 @@
arrayOfNulls<LayoutCoordinates?>(childPosition.size)
var parentLayoutCoordinates: LayoutCoordinates? = null
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Row(
modifier = Modifier
.fillMaxWidth()
@@ -5270,7 +5270,7 @@
val rowSize = rowSizePx.toDp()
val latch = CountDownLatch(3)
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Column {
Row(
horizontalArrangement = AbsoluteArrangement.spacedBy(space, Alignment.End),
diff --git a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/TextLayoutDirectionModifierTest.kt b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/TextLayoutDirectionModifierTest.kt
index 6a620f5..bad57a1 100644
--- a/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/TextLayoutDirectionModifierTest.kt
+++ b/compose/foundation/foundation-layout/src/androidAndroidTest/kotlin/androidx/compose/foundation/layout/TextLayoutDirectionModifierTest.kt
@@ -19,7 +19,7 @@
import androidx.compose.foundation.text.BasicText
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.runtime.Providers
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.TextFieldValue
@@ -43,7 +43,7 @@
var layoutDirection: LayoutDirection? = null
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
BasicTextField(
value = TextFieldValue("..."),
onValueChange = {},
@@ -65,7 +65,7 @@
val latch = CountDownLatch(1)
var layoutDirection: LayoutDirection? = null
show {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
BasicText(
text = AnnotatedString("..."),
style = TextStyle.Default,
diff --git a/compose/foundation/foundation/api/current.txt b/compose/foundation/foundation/api/current.txt
index 6175156..0e57886 100644
--- a/compose/foundation/foundation/api/current.txt
+++ b/compose/foundation/foundation/api/current.txt
@@ -473,7 +473,6 @@
public final class CoreTextFieldKt {
method @androidx.compose.runtime.Composable @androidx.compose.ui.text.InternalTextApi public static void CoreTextField--SxaZeI(androidx.compose.ui.text.input.TextFieldValue value, optional androidx.compose.ui.Modifier modifier, kotlin.jvm.functions.Function1<? super androidx.compose.ui.text.input.TextFieldValue,kotlin.Unit> onValueChange, optional androidx.compose.ui.text.TextStyle textStyle, optional kotlin.jvm.functions.Function1<? super androidx.compose.ui.text.input.ImeAction,kotlin.Unit> onImeActionPerformed, optional androidx.compose.ui.text.input.VisualTransformation visualTransformation, optional kotlin.jvm.functions.Function1<? super androidx.compose.ui.text.TextLayoutResult,kotlin.Unit> onTextLayout, optional kotlin.jvm.functions.Function1<? super androidx.compose.ui.text.SoftwareKeyboardController,kotlin.Unit> onTextInputStarted, optional long cursorColor, optional boolean softWrap, optional int maxLines, optional androidx.compose.ui.text.input.ImeOptions imeOptions);
- method @Deprecated @VisibleForTesting public static void setBlinkingCursorEnabled(boolean p);
}
public final class CoreTextKt {
@@ -519,12 +518,22 @@
property public final androidx.compose.foundation.text.KeyboardOptions Default;
}
+ public final class TextFieldCursorKt {
+ method @Deprecated @VisibleForTesting public static void setBlinkingCursorEnabled(boolean p);
+ }
+
public final class TextFieldDelegateKt {
}
+ public final class TextFieldDragGestureFilterKt {
+ }
+
public final class TextFieldScrollKt {
}
+ public final class TextFieldSizeKt {
+ }
+
}
package androidx.compose.foundation.text.selection {
diff --git a/compose/foundation/foundation/api/public_plus_experimental_current.txt b/compose/foundation/foundation/api/public_plus_experimental_current.txt
index 6175156..0e57886 100644
--- a/compose/foundation/foundation/api/public_plus_experimental_current.txt
+++ b/compose/foundation/foundation/api/public_plus_experimental_current.txt
@@ -473,7 +473,6 @@
public final class CoreTextFieldKt {
method @androidx.compose.runtime.Composable @androidx.compose.ui.text.InternalTextApi public static void CoreTextField--SxaZeI(androidx.compose.ui.text.input.TextFieldValue value, optional androidx.compose.ui.Modifier modifier, kotlin.jvm.functions.Function1<? super androidx.compose.ui.text.input.TextFieldValue,kotlin.Unit> onValueChange, optional androidx.compose.ui.text.TextStyle textStyle, optional kotlin.jvm.functions.Function1<? super androidx.compose.ui.text.input.ImeAction,kotlin.Unit> onImeActionPerformed, optional androidx.compose.ui.text.input.VisualTransformation visualTransformation, optional kotlin.jvm.functions.Function1<? super androidx.compose.ui.text.TextLayoutResult,kotlin.Unit> onTextLayout, optional kotlin.jvm.functions.Function1<? super androidx.compose.ui.text.SoftwareKeyboardController,kotlin.Unit> onTextInputStarted, optional long cursorColor, optional boolean softWrap, optional int maxLines, optional androidx.compose.ui.text.input.ImeOptions imeOptions);
- method @Deprecated @VisibleForTesting public static void setBlinkingCursorEnabled(boolean p);
}
public final class CoreTextKt {
@@ -519,12 +518,22 @@
property public final androidx.compose.foundation.text.KeyboardOptions Default;
}
+ public final class TextFieldCursorKt {
+ method @Deprecated @VisibleForTesting public static void setBlinkingCursorEnabled(boolean p);
+ }
+
public final class TextFieldDelegateKt {
}
+ public final class TextFieldDragGestureFilterKt {
+ }
+
public final class TextFieldScrollKt {
}
+ public final class TextFieldSizeKt {
+ }
+
}
package androidx.compose.foundation.text.selection {
diff --git a/compose/foundation/foundation/api/restricted_current.txt b/compose/foundation/foundation/api/restricted_current.txt
index 6175156..0e57886 100644
--- a/compose/foundation/foundation/api/restricted_current.txt
+++ b/compose/foundation/foundation/api/restricted_current.txt
@@ -473,7 +473,6 @@
public final class CoreTextFieldKt {
method @androidx.compose.runtime.Composable @androidx.compose.ui.text.InternalTextApi public static void CoreTextField--SxaZeI(androidx.compose.ui.text.input.TextFieldValue value, optional androidx.compose.ui.Modifier modifier, kotlin.jvm.functions.Function1<? super androidx.compose.ui.text.input.TextFieldValue,kotlin.Unit> onValueChange, optional androidx.compose.ui.text.TextStyle textStyle, optional kotlin.jvm.functions.Function1<? super androidx.compose.ui.text.input.ImeAction,kotlin.Unit> onImeActionPerformed, optional androidx.compose.ui.text.input.VisualTransformation visualTransformation, optional kotlin.jvm.functions.Function1<? super androidx.compose.ui.text.TextLayoutResult,kotlin.Unit> onTextLayout, optional kotlin.jvm.functions.Function1<? super androidx.compose.ui.text.SoftwareKeyboardController,kotlin.Unit> onTextInputStarted, optional long cursorColor, optional boolean softWrap, optional int maxLines, optional androidx.compose.ui.text.input.ImeOptions imeOptions);
- method @Deprecated @VisibleForTesting public static void setBlinkingCursorEnabled(boolean p);
}
public final class CoreTextKt {
@@ -519,12 +518,22 @@
property public final androidx.compose.foundation.text.KeyboardOptions Default;
}
+ public final class TextFieldCursorKt {
+ method @Deprecated @VisibleForTesting public static void setBlinkingCursorEnabled(boolean p);
+ }
+
public final class TextFieldDelegateKt {
}
+ public final class TextFieldDragGestureFilterKt {
+ }
+
public final class TextFieldScrollKt {
}
+ public final class TextFieldSizeKt {
+ }
+
}
package androidx.compose.foundation.text.selection {
diff --git a/compose/foundation/foundation/build.gradle b/compose/foundation/foundation/build.gradle
index 3442e7e..9994772 100644
--- a/compose/foundation/foundation/build.gradle
+++ b/compose/foundation/foundation/build.gradle
@@ -159,7 +159,6 @@
androidx {
name = "Compose Foundation"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.FOUNDATION
inceptionYear = "2018"
description = "Higher level abstractions of the Compose UI primitives. This library is design system agnostic, providing the high-level building blocks for both application and design-system developers"
diff --git a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/ListDemos.kt b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/ListDemos.kt
index 8c7e262..2c241d9 100644
--- a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/ListDemos.kt
+++ b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/ListDemos.kt
@@ -53,8 +53,8 @@
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.DensityAmbient
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@@ -122,7 +122,7 @@
Column {
FlowRow {
val buttonModifier = Modifier.padding(8.dp)
- val density = DensityAmbient.current
+ val density = AmbientDensity.current
val coroutineScope = rememberCoroutineScope()
Button(
modifier = buttonModifier,
@@ -231,7 +231,7 @@
@Composable
private fun RtlListDemo() {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
LazyRowForIndexed((0..100).toList(), Modifier.fillMaxWidth()) { index, item ->
Text(
"$item",
diff --git a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeInputField.kt b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeInputField.kt
index 9dd0a0b..434cd3e 100644
--- a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeInputField.kt
+++ b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeInputField.kt
@@ -18,30 +18,51 @@
import androidx.compose.foundation.ScrollableColumn
import androidx.compose.foundation.border
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.Providers
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.savedinstancestate.savedInstanceState
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.text.SoftwareKeyboardController
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
+import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
@Composable
fun InputFieldDemo() {
ScrollableColumn {
- TagLine(tag = "simple editing")
- EditLine()
- TagLine(tag = "simple editing2")
- EditLine()
+ TagLine(tag = "LTR Layout")
+ Providers(AmbientLayoutDirection provides LayoutDirection.Ltr) {
+ Column(modifier = Modifier.fillMaxWidth()) {
+ TagLine(tag = "simple editing single line")
+ EditLine(singleLine = true)
+ TagLine(tag = "simple editing multi line")
+ EditLine(text = displayTextHindi)
+ TagLine(tag = "simple editing RTL")
+ EditLine(text = displayTextArabic)
+ }
+ }
+ TagLine(tag = "RTL Layout")
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
+ Column(modifier = Modifier.fillMaxWidth()) {
+ TagLine(tag = "simple editing RTL")
+ EditLine()
+ EditLine(text = displayTextArabic)
+ EditLine(text = displayText)
+ }
+ }
}
}
@@ -49,10 +70,11 @@
internal fun EditLine(
keyboardType: KeyboardType = KeyboardType.Text,
imeAction: ImeAction = ImeAction.Unspecified,
- singleLine: Boolean = true
+ singleLine: Boolean = false,
+ text: String = ""
) {
val controller = remember { mutableStateOf<SoftwareKeyboardController?>(null) }
- val state = savedInstanceState(saver = TextFieldValue.Saver) { TextFieldValue() }
+ val state = savedInstanceState(saver = TextFieldValue.Saver) { TextFieldValue(text) }
BasicTextField(
modifier = demoTextFieldModifiers,
value = state.value,
diff --git a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeInputFieldMinMaxLines.kt b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeInputFieldMinMaxLines.kt
index 43e624a..e41e94e 100644
--- a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeInputFieldMinMaxLines.kt
+++ b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeInputFieldMinMaxLines.kt
@@ -17,7 +17,7 @@
package androidx.compose.foundation.demos.text
import androidx.compose.foundation.ScrollableColumn
-import androidx.compose.foundation.text.CoreTextField
+import androidx.compose.foundation.text.BasicTextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.savedinstancestate.savedInstanceState
import androidx.compose.ui.draw.clipToBounds
@@ -29,21 +29,26 @@
@Composable
fun CoreTextFieldMinMaxDemo() {
ScrollableColumn {
- CoreTextFieldWithMaxLines("", maxLines = Int.MAX_VALUE) // empty text, no maxLines
- CoreTextFieldWithMaxLines("abc", maxLines = 1) // maxLines == line count
- CoreTextFieldWithMaxLines("", maxLines = 2) // empty text, maxLines > line count
- CoreTextFieldWithMaxLines("abc", maxLines = 4) // maxLines > line count
- CoreTextFieldWithMaxLines("abc".repeat(20), maxLines = 1) // maxLines < line count
+ TagLine("empty text, no maxLines")
+ TextFieldWithMaxLines("", maxLines = Int.MAX_VALUE)
+ TagLine("maxLines == line count")
+ TextFieldWithMaxLines("abc", maxLines = 1)
+ TagLine("empty text, maxLines > line count")
+ TextFieldWithMaxLines("", maxLines = 2)
+ TagLine("maxLines > line count")
+ TextFieldWithMaxLines("abc", maxLines = 4)
+ TagLine("maxLines < line count")
+ TextFieldWithMaxLines("abc".repeat(20), maxLines = 1)
}
}
@Composable
@OptIn(InternalTextApi::class)
-private fun CoreTextFieldWithMaxLines(str: String? = null, maxLines: Int) {
+private fun TextFieldWithMaxLines(str: String? = null, maxLines: Int) {
val state = savedInstanceState(saver = TextFieldValue.Saver) {
TextFieldValue(str ?: "abc ".repeat(20))
}
- CoreTextField(
+ BasicTextField(
modifier = demoTextFieldModifiers.clipToBounds(),
value = state.value,
onValueChange = { state.value = it },
diff --git a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TextDemos.kt b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TextDemos.kt
index a561851..531a020 100644
--- a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TextDemos.kt
+++ b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TextDemos.kt
@@ -23,6 +23,7 @@
"Text",
listOf(
ComposableDemo("Static text") { TextDemo() },
+ ComposableDemo("Typeface") { TypefaceDemo() },
ComposableDemo("Text selection") { TextSelectionDemo() },
ComposableDemo("Text selection sample") { TextSelectionSample() },
ComposableDemo("Multi paragraph") { MultiParagraphDemo() },
diff --git a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TypefaceDemo.kt b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TypefaceDemo.kt
new file mode 100644
index 0000000..d562701
--- /dev/null
+++ b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TypefaceDemo.kt
@@ -0,0 +1,58 @@
+/*
+ * 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.compose.foundation.demos.text
+
+import android.graphics.Typeface
+import androidx.compose.foundation.ScrollableColumn
+import androidx.compose.material.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.platform.AmbientContext
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.font.FontFamily
+import androidx.compose.ui.text.font.fontFamily
+import androidx.compose.ui.text.font.typeface
+
+@Composable
+fun TypefaceDemo() {
+ ScrollableColumn {
+ TagLine(tag = "Android Typeface")
+ AndroidTypefaceDemo()
+ TagLine(tag = "Typeface from FontFamily")
+ TypefaceFromFontFamilyDemo()
+ TagLine(tag = "FontFamily from Android Typeface")
+ FontFamilyFromAndroidTypeface()
+ }
+}
+
+@Composable
+fun TypefaceFromFontFamilyDemo() {
+ val typeface = typeface(AmbientContext.current, FontFamily.Cursive)
+ val fontFamily = fontFamily(typeface)
+ Text("Hello World", style = TextStyle(fontFamily = fontFamily))
+}
+
+@Composable
+fun AndroidTypefaceDemo() {
+ val fontFamily = fontFamily(typeface(Typeface.DEFAULT_BOLD))
+ Text("Hello World", style = TextStyle(fontFamily = fontFamily))
+}
+
+@Composable
+fun FontFamilyFromAndroidTypeface() {
+ val fontFamily = fontFamily(Typeface.MONOSPACE)
+ Text("Hello World", style = TextStyle(fontFamily = fontFamily))
+}
diff --git a/compose/foundation/foundation/samples/build.gradle b/compose/foundation/foundation/samples/build.gradle
index 9815feb..cc60a60 100644
--- a/compose/foundation/foundation/samples/build.gradle
+++ b/compose/foundation/foundation/samples/build.gradle
@@ -55,7 +55,6 @@
androidx {
name = "AndroidX Compose UI Foundational Component Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.FOUNDATION
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose UI Foundational Components"
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/BackgroundTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/BackgroundTest.kt
index cd26a9e..25f718e 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/BackgroundTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/BackgroundTest.kt
@@ -27,7 +27,7 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.SolidColor
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.InspectableValue
import androidx.compose.ui.platform.ValueElement
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
@@ -192,7 +192,7 @@
@Composable
private fun SemanticParent(children: @Composable Density.() -> Unit) {
Box(Modifier.testTag(contentTag)) {
- DensityAmbient.current.children()
+ AmbientDensity.current.children()
}
}
}
\ No newline at end of file
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/BorderTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/BorderTest.kt
index 4b23f01..6796f88 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/BorderTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/BorderTest.kt
@@ -28,7 +28,7 @@
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.SolidColor
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.junit4.createComposeRule
@@ -183,7 +183,7 @@
fun SemanticParent(children: @Composable Density.() -> Unit) {
Box {
Box(modifier = Modifier.testTag(testTag)) {
- DensityAmbient.current.children()
+ AmbientDensity.current.children()
}
}
}
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/CanvasTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/CanvasTest.kt
index 1a61f63..14c436d 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/CanvasTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/CanvasTest.kt
@@ -29,7 +29,7 @@
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.graphics.toArgb
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.test.assertHeightIsEqualTo
import androidx.compose.ui.test.assertWidthIsEqualTo
import androidx.compose.ui.test.captureToImage
@@ -62,7 +62,7 @@
fun testCanvas() {
val strokeWidth = 5.0f
rule.setContent {
- val density = DensityAmbient.current.density
+ val density = AmbientDensity.current.density
val containerSize = (containerSize * 2 / density).dp
val minWidth = (boxWidth / density).dp
val minHeight = (boxHeight / density).dp
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ImageTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ImageTest.kt
index 8dafd6e..ebcff5c 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ImageTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ImageTest.kt
@@ -39,7 +39,6 @@
import androidx.compose.ui.graphics.painter.ImagePainter
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.layout.ContentScale
-import androidx.compose.ui.platform.DensityAmbient
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.loadVectorResource
import androidx.compose.ui.test.captureToImage
@@ -51,6 +50,7 @@
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.testutils.assertPixels
+import androidx.compose.ui.platform.AmbientDensity
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import androidx.test.filters.SdkSuppress
@@ -102,7 +102,7 @@
@Test
fun testImage() {
rule.setContent {
- val size = (containerSize / DensityAmbient.current.density).dp
+ val size = (containerSize / AmbientDensity.current.density).dp
Box(
Modifier.preferredSize(size)
.background(color = Color.White)
@@ -143,7 +143,7 @@
val subsectionWidth = imageWidth / 2
val subsectionHeight = imageHeight / 2
rule.setContent {
- val size = (containerSize / DensityAmbient.current.density).dp
+ val size = (containerSize / AmbientDensity.current.density).dp
Box(
Modifier.preferredSize(size)
.background(color = Color.White)
@@ -241,7 +241,7 @@
val imageComposableWidth = imageWidth * 2
val imageComposableHeight = imageHeight * 2
rule.setContent {
- val density = DensityAmbient.current.density
+ val density = AmbientDensity.current.density
val size = (containerSize * 2 / density).dp
Box(
Modifier.preferredSize(size)
@@ -301,7 +301,7 @@
val imageComposableHeight = imageHeight * 7
rule.setContent {
- val density = DensityAmbient.current
+ val density = AmbientDensity.current
val size = (containerSize * 2 / density.density).dp
val ImageBitmap = ImageBitmap(imageWidth, imageHeight)
CanvasDrawScope().draw(
@@ -340,7 +340,7 @@
val imageComposableWidth = imageWidth * 2
val imageComposableHeight = imageHeight * 2
rule.setContent {
- val density = DensityAmbient.current.density
+ val density = AmbientDensity.current.density
val size = (containerSize * 2 / density).dp
Box(
Modifier.preferredSize(size)
@@ -399,7 +399,7 @@
// latch used to wait until vector resource is loaded asynchronously
val vectorLatch = CountDownLatch(1)
rule.setContent {
- val density = DensityAmbient.current.density
+ val density = AmbientDensity.current.density
val size = (boxWidth * 2 / density).dp
val minWidth = (boxWidth / density).dp
val minHeight = (boxHeight / density).dp
@@ -496,7 +496,7 @@
}
this
}
- val heightDp = asset.height / DensityAmbient.current.density
+ val heightDp = asset.height / AmbientDensity.current.density
Image(
asset,
modifier = Modifier
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ScrollTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ScrollTest.kt
index 1455b85..73e8e32 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ScrollTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ScrollTest.kt
@@ -31,8 +31,8 @@
import androidx.compose.testutils.assertPixels
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.InspectableValue
-import androidx.compose.ui.platform.LayoutDirectionAmbient
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.GestureScope
@@ -799,7 +799,7 @@
with(rule.density) {
rule.setContent {
val direction = if (isRtl) LayoutDirection.Rtl else LayoutDirection.Ltr
- Providers(LayoutDirectionAmbient provides direction) {
+ Providers(AmbientLayoutDirection provides direction) {
Box {
ScrollableRow(
reverseScrollDirection = isReversed,
@@ -887,7 +887,7 @@
}
} else {
val direction = if (isRtl) LayoutDirection.Rtl else LayoutDirection.Ltr
- Providers(LayoutDirectionAmbient provides direction) {
+ Providers(AmbientLayoutDirection provides direction) {
ScrollableRow(
Modifier.testTag(scrollerTag),
scrollState = scrollState,
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/SoftwareKeyboardTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/SoftwareKeyboardTest.kt
index 1b30bcb..599019c 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/SoftwareKeyboardTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/SoftwareKeyboardTest.kt
@@ -22,7 +22,7 @@
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.TextInputServiceAmbient
+import androidx.compose.ui.platform.AmbientTextInputService
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.performClick
@@ -58,7 +58,7 @@
val onTextInputStarted: (SoftwareKeyboardController) -> Unit = mock()
rule.setContent {
Providers(
- TextInputServiceAmbient provides textInputService
+ AmbientTextInputService provides textInputService
) {
val state = remember { mutableStateOf(TextFieldValue("")) }
BasicTextField(
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldCursorTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldCursorTest.kt
index c85f1d7..85b30a6 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldCursorTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldCursorTest.kt
@@ -33,6 +33,7 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.RectangleShape
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.junit4.createComposeRule
@@ -54,7 +55,7 @@
import java.util.concurrent.TimeUnit
@LargeTest
-@OptIn(ExperimentalFocus::class)
+@OptIn(ExperimentalFocus::class, ExperimentalTesting::class)
class TextFieldCursorTest {
@get:Rule
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/BaseTextFieldDefaultWidthTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldDefaultWidthTest.kt
similarity index 98%
rename from compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/BaseTextFieldDefaultWidthTest.kt
rename to compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldDefaultWidthTest.kt
index b168f09..6a1f80e 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/BaseTextFieldDefaultWidthTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldDefaultWidthTest.kt
@@ -24,7 +24,7 @@
import androidx.compose.runtime.Providers
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontStyle
@@ -194,7 +194,7 @@
style = FontStyle.Normal
)
- Providers(DensityAmbient provides density) {
+ Providers(AmbientDensity provides density) {
androidx.compose.foundation.layout.Box {
BasicTextField(
value = TextFieldValue(text),
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldOnValueChangeTextFieldValueTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldOnValueChangeTextFieldValueTest.kt
index da81580..c99e5ba 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldOnValueChangeTextFieldValueTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldOnValueChangeTextFieldValueTest.kt
@@ -21,7 +21,7 @@
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.geometry.Offset
-import androidx.compose.ui.platform.TextInputServiceAmbient
+import androidx.compose.ui.platform.AmbientTextInputService
import androidx.compose.ui.test.click
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.junit4.createComposeRule
@@ -72,7 +72,7 @@
rule.setContent {
Providers(
- TextInputServiceAmbient provides textInputService
+ AmbientTextInputService provides textInputService
) {
val state = remember {
mutableStateOf(
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldTest.kt
index 4917618..573cb11 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/TextFieldTest.kt
@@ -43,9 +43,9 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.TextInputServiceAmbient
+import androidx.compose.ui.platform.AmbientTextInputService
+import androidx.compose.ui.platform.AmbientTextToolbar
import androidx.compose.ui.platform.TextToolbar
-import androidx.compose.ui.platform.TextToolbarAmbient
import androidx.compose.ui.platform.TextToolbarStatus
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.SemanticsActions
@@ -117,7 +117,7 @@
rule.setContent {
val state = remember { mutableStateOf(TextFieldValue("")) }
Providers(
- TextInputServiceAmbient provides inputService
+ AmbientTextInputService provides inputService
) {
BasicTextField(
value = state.value,
@@ -156,7 +156,7 @@
rule.setContent {
Providers(
- TextInputServiceAmbient provides textInputService
+ AmbientTextInputService provides textInputService
) {
TextFieldApp()
}
@@ -227,7 +227,7 @@
rule.setContent {
Providers(
- TextInputServiceAmbient provides textInputService
+ AmbientTextInputService provides textInputService
) {
OnlyDigitsApp()
}
@@ -286,7 +286,7 @@
val onTextLayout: (TextLayoutResult) -> Unit = mock()
rule.setContent {
Providers(
- TextInputServiceAmbient provides textInputService
+ AmbientTextInputService provides textInputService
) {
val state = remember { mutableStateOf(TextFieldValue("")) }
BasicTextField(
@@ -595,7 +595,7 @@
var toolbar: TextToolbar? = null
rule.setContent {
- toolbar = TextToolbarAmbient.current
+ toolbar = AmbientTextToolbar.current
BasicTextField(
modifier = Modifier.testTag(Tag),
value = value,
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ZoomableTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ZoomableTest.kt
index edc41ce..d658268 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ZoomableTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ZoomableTest.kt
@@ -27,8 +27,8 @@
import androidx.compose.ui.platform.InspectableValue
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.center
-import androidx.compose.ui.test.junit4.createAnimationClockRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performGesture
@@ -51,13 +51,11 @@
@MediumTest
@RunWith(AndroidJUnit4::class)
+@OptIn(ExperimentalTesting::class)
class ZoomableTest {
@get:Rule
val rule = createComposeRule()
- @get:Rule
- val clockRule = createAnimationClockRule()
-
@Before
fun before() {
isDebugInspectorInfoEnabled = true
@@ -73,7 +71,7 @@
var cumulativeScale = 1.0f
val controller = ZoomableController(
onZoomDelta = { cumulativeScale *= it },
- animationClock = clockRule.clock
+ animationClock = rule.clockTestRule.clock
)
setZoomableContent { Modifier.zoomable(controller) }
@@ -92,7 +90,7 @@
)
}
- clockRule.advanceClock(milliseconds = 1000)
+ rule.clockTestRule.advanceClock(milliseconds = 1000)
rule.runOnIdle {
assertWithMessage("Should have scaled at least 4x").that(cumulativeScale).isAtLeast(4f)
@@ -104,7 +102,7 @@
var cumulativeScale = 1.0f
val controller = ZoomableController(
onZoomDelta = { cumulativeScale *= it },
- animationClock = clockRule.clock
+ animationClock = rule.clockTestRule.clock
)
setZoomableContent { Modifier.zoomable(controller) }
@@ -123,7 +121,7 @@
)
}
- clockRule.advanceClock(milliseconds = 1000)
+ rule.clockTestRule.advanceClock(milliseconds = 1000)
rule.runOnIdle {
assertWithMessage("Should have scaled down at least 4x")
@@ -139,7 +137,7 @@
var stopTriggered = 0f
val controller = ZoomableController(
onZoomDelta = { cumulativeScale *= it },
- animationClock = clockRule.clock
+ animationClock = rule.clockTestRule.clock
)
setZoomableContent {
@@ -170,7 +168,7 @@
)
}
- clockRule.advanceClock(milliseconds = 1000)
+ rule.clockTestRule.advanceClock(milliseconds = 1000)
rule.runOnIdle {
assertThat(startTriggered).isEqualTo(1)
@@ -184,7 +182,7 @@
var cumulativeScale = 1.0f
val controller = ZoomableController(
onZoomDelta = { cumulativeScale *= it },
- animationClock = clockRule.clock
+ animationClock = rule.clockTestRule.clock
)
setZoomableContent {
@@ -206,7 +204,7 @@
)
}
- clockRule.advanceClock(milliseconds = 1000)
+ rule.clockTestRule.advanceClock(milliseconds = 1000)
val prevScale = rule.runOnIdle {
assertWithMessage("Should have scaled at least 4x").that(cumulativeScale).isAtLeast(4f)
@@ -241,7 +239,7 @@
var stopTriggered = 0f
val controller = ZoomableController(
onZoomDelta = { cumulativeScale *= it },
- animationClock = clockRule.clock
+ animationClock = rule.clockTestRule.clock
)
setZoomableContent {
@@ -274,7 +272,7 @@
)
}
- clockRule.advanceClock(milliseconds = 1000)
+ rule.clockTestRule.advanceClock(milliseconds = 1000)
rule.runOnIdle {
assertThat(cumulativeScale).isAtLeast(2f)
@@ -291,26 +289,26 @@
cumulativeScale *= it
callbackCount += 1
},
- animationClock = clockRule.clock
+ animationClock = rule.clockTestRule.clock
)
setZoomableContent { Modifier.zoomable(state) }
rule.runOnUiThread { state.smoothScaleBy(4f) }
- clockRule.advanceClock(milliseconds = 10)
+ rule.clockTestRule.advanceClock(milliseconds = 10)
rule.runOnIdle {
assertWithMessage("Scrolling should have been smooth").that(callbackCount).isAtLeast(1)
}
- clockRule.advanceClock(milliseconds = 10)
+ rule.clockTestRule.advanceClock(milliseconds = 10)
rule.runOnIdle {
assertWithMessage("Scrolling should have been smooth").that(callbackCount).isAtLeast(2)
}
- clockRule.advanceClock(milliseconds = 1000)
+ rule.clockTestRule.advanceClock(milliseconds = 1000)
rule.runOnIdle {
assertWithMessage("Scrolling should have been smooth").that(callbackCount).isAtLeast(3)
@@ -323,7 +321,7 @@
fun testInspectorValue() {
val controller = ZoomableController(
onZoomDelta = {},
- animationClock = clockRule.clock
+ animationClock = rule.clockTestRule.clock
)
rule.setContent {
val modifier = Modifier.zoomable(controller) as InspectableValue
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/LazyRowForTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/LazyRowForTest.kt
index 8b142aa..9999744 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/LazyRowForTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/LazyRowForTest.kt
@@ -32,7 +32,7 @@
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.assertHeightIsEqualTo
@@ -457,7 +457,7 @@
val items = (1..4).map { it.toString() }
rule.setContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Box(Modifier.preferredWidth(100.dp)) {
LazyRowFor(items, Modifier.testTag(LazyRowForTag)) {
Spacer(Modifier.preferredWidth(101.dp).fillParentMaxHeight().testTag(it))
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/CoreTextFieldMinMaxLineTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/CoreTextFieldMinMaxLineTest.kt
index 5e02d73..2591fcf 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/CoreTextFieldMinMaxLineTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/CoreTextFieldMinMaxLineTest.kt
@@ -20,7 +20,7 @@
import androidx.compose.runtime.Providers
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.text.InternalTextApi
import androidx.compose.ui.text.TextLayoutResult
@@ -61,7 +61,7 @@
@Test(expected = IllegalArgumentException::class)
fun textField_maxLines_should_be_greater_than_zero() {
rule.setContent {
- Providers(DensityAmbient provides density) {
+ Providers(AmbientDensity provides density) {
CoreTextField(
value = TextFieldValue(""),
onValueChange = {},
@@ -158,7 +158,7 @@
var height: Int? = null
rule.setContent {
- Providers(DensityAmbient provides density) {
+ Providers(AmbientDensity provides density) {
CoreTextField(
value = TextFieldValue(string),
onValueChange = {},
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/CoreTextFieldSoftWrapTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/CoreTextFieldSoftWrapTest.kt
index 43b6036..dc4d2fc 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/CoreTextFieldSoftWrapTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/CoreTextFieldSoftWrapTest.kt
@@ -20,7 +20,7 @@
import androidx.compose.runtime.Providers
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.text.InternalTextApi
import androidx.compose.ui.text.TextLayoutResult
@@ -67,7 +67,7 @@
var width: Int? = null
rule.setContent {
- Providers(DensityAmbient provides density) {
+ Providers(AmbientDensity provides density) {
CoreTextField(
value = TextFieldValue(string),
onValueChange = {},
@@ -102,7 +102,7 @@
var width: Int? = null
rule.setContent {
- Providers(DensityAmbient provides density) {
+ Providers(AmbientDensity provides density) {
CoreTextField(
value = TextFieldValue(string),
onValueChange = {},
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerTest.kt
index 3ba2377..ce3123c 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/text/selection/SelectionContainerTest.kt
@@ -38,8 +38,9 @@
import androidx.compose.ui.input.pointer.changedToUp
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.HapticFeedBackAmbient
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientHapticFeedback
+import androidx.compose.ui.platform.AmbientLayoutDirection
+import androidx.compose.ui.platform.AmbientView
import androidx.compose.ui.selection.Selection
import androidx.compose.ui.selection.SelectionContainer
import androidx.compose.ui.test.junit4.createAndroidComposeRule
@@ -249,7 +250,7 @@
with(rule.density) {
rule.setContent {
// Get the compose view position on screen
- val composeView = androidx.compose.ui.platform.ViewAmbient.current
+ val composeView = AmbientView.current
val positionArray = IntArray(2)
composeView.getLocationOnScreen(positionArray)
composeViewAbsolutePos = IntOffset(
@@ -257,8 +258,8 @@
positionArray[1]
)
Providers(
- HapticFeedBackAmbient provides hapticFeedback,
- LayoutDirectionAmbient provides layoutDirection
+ AmbientHapticFeedback provides hapticFeedback,
+ AmbientLayoutDirection provides layoutDirection
) {
TestParent(Modifier.gestureSpy(log)) {
SelectionContainer(
diff --git a/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/DarkTheme.kt b/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/DarkTheme.kt
index 785c201..2b0490d 100644
--- a/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/DarkTheme.kt
+++ b/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/DarkTheme.kt
@@ -19,7 +19,7 @@
import android.content.res.Configuration
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ComposableContract
-import androidx.compose.ui.platform.ConfigurationAmbient
+import androidx.compose.ui.platform.AmbientConfiguration
/**
* This function should be used to help build responsive UIs that follow the system setting, to
@@ -45,6 +45,6 @@
@Composable
@ComposableContract(readonly = true)
fun isSystemInDarkTheme(): Boolean {
- val uiMode = ConfigurationAmbient.current.uiMode
+ val uiMode = AmbientConfiguration.current.uiMode
return (uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
}
diff --git a/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/animation/AndroidFlingCalculator.kt b/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/animation/AndroidFlingCalculator.kt
index 0abfdb8..bb7cbcf 100644
--- a/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/animation/AndroidFlingCalculator.kt
+++ b/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/animation/AndroidFlingCalculator.kt
@@ -16,7 +16,6 @@
package androidx.compose.foundation.animation
-import androidx.compose.ui.platform.DensityAmbient
import androidx.compose.ui.unit.Density
import kotlin.math.exp
import kotlin.math.ln
diff --git a/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/animation/AndroidFlingConfig.kt b/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/animation/AndroidFlingConfig.kt
index 9dafb52..bf17aeb 100644
--- a/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/animation/AndroidFlingConfig.kt
+++ b/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/animation/AndroidFlingConfig.kt
@@ -19,13 +19,13 @@
import androidx.compose.animation.core.TargetAnimation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
@Composable
internal actual fun actualFlingConfig(adjustTarget: (Float) -> TargetAnimation?): FlingConfig {
// This function will internally update the calculation of fling decay when the density changes,
// but the reference to the returned FlingConfig will not change across calls.
- val density = DensityAmbient.current
+ val density = AmbientDensity.current
return remember(density.density) {
val decayAnimation = AndroidFlingDecaySpec(density)
FlingConfig(
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Scroll.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Scroll.kt
index 4ba5a84..b138ebe 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Scroll.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Scroll.kt
@@ -53,8 +53,8 @@
import androidx.compose.ui.layout.Measurable
import androidx.compose.ui.layout.MeasureResult
import androidx.compose.ui.layout.MeasureScope
-import androidx.compose.ui.platform.AnimationClockAmbient
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.semantics.AccessibilityScrollState
import androidx.compose.ui.semantics.horizontalAccessibilityScrollState
@@ -83,7 +83,7 @@
initial: Float = 0f,
interactionState: InteractionState? = null
): ScrollState {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
val config = defaultFlingConfig()
return rememberSavedInstanceState(
clock, config, interactionState,
@@ -424,7 +424,7 @@
)
}
}
- val isRtl = LayoutDirectionAmbient.current == LayoutDirection.Rtl
+ val isRtl = AmbientLayoutDirection.current == LayoutDirection.Rtl
val scrolling = Modifier.scrollable(
orientation = if (isVertical) Orientation.Vertical else Orientation.Horizontal,
// reverse scroll by default, to have "natural" gesture that goes reversed to layout
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt
index 45ad1e9..b48e708 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt
@@ -27,7 +27,7 @@
import androidx.compose.ui.gesture.dragGestureFilter
import androidx.compose.ui.gesture.scrollGestureFilter
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.unit.Density
@@ -73,7 +73,7 @@
onDrag: Density.(Float) -> Unit
): Modifier = composed(
factory = {
- val density = DensityAmbient.current
+ val density = AmbientDensity.current
onDispose {
interactionState?.removeInteraction(Interaction.Dragged)
}
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Scrollable.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Scrollable.kt
index f08153c..830e5bc 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Scrollable.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Scrollable.kt
@@ -44,7 +44,7 @@
import androidx.compose.ui.gesture.Direction
import androidx.compose.ui.gesture.ScrollCallback
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.platform.debugInspectorInfo
import kotlinx.coroutines.Job
import kotlinx.coroutines.coroutineScope
@@ -67,7 +67,7 @@
interactionState: InteractionState? = null,
consumeScrollDelta: (Float) -> Float
): ScrollableController {
- val clocks = AnimationClockAmbient.current.asDisposableClock()
+ val clocks = AmbientAnimationClock.current.asDisposableClock()
val flingConfig = defaultFlingConfig()
return remember(clocks, flingConfig, interactionState) {
ScrollableController(consumeScrollDelta, flingConfig, clocks, interactionState)
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Zoomable.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Zoomable.kt
index 3ad042a..d30ed1a 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Zoomable.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Zoomable.kt
@@ -30,7 +30,7 @@
import androidx.compose.ui.composed
import androidx.compose.ui.gesture.ScaleObserver
import androidx.compose.ui.gesture.scaleGestureFilter
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.platform.debugInspectorInfo
/**
@@ -42,7 +42,7 @@
*/
@Composable
fun rememberZoomableController(onZoomDelta: (Float) -> Unit): ZoomableController {
- val clocks = AnimationClockAmbient.current.asDisposableClock()
+ val clocks = AmbientAnimationClock.current.asDisposableClock()
return remember(clocks) { ZoomableController(clocks, onZoomDelta) }
}
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyList.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyList.kt
index 31d7c21..69eabaf 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyList.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyList.kt
@@ -26,7 +26,7 @@
import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
import androidx.compose.ui.layout.SubcomposeLayout
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
@Composable
@@ -40,7 +40,7 @@
isVertical: Boolean,
itemContentFactory: LazyItemScope.(Int) -> @Composable () -> Unit
) {
- val reverseDirection = LayoutDirectionAmbient.current == LayoutDirection.Rtl && !isVertical
+ val reverseDirection = AmbientLayoutDirection.current == LayoutDirection.Rtl && !isVertical
val cachingItemContentFactory = remember { CachingItemContentFactory(itemContentFactory) }
cachingItemContentFactory.itemContentFactory = itemContentFactory
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyListState.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyListState.kt
index 842c0e1..87a146c 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyListState.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/LazyListState.kt
@@ -41,7 +41,7 @@
import androidx.compose.ui.layout.Remeasurement
import androidx.compose.ui.layout.RemeasurementModifier
import androidx.compose.ui.layout.SubcomposeMeasureScope
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.constrainHeight
import androidx.compose.ui.unit.constrainWidth
@@ -83,7 +83,7 @@
initialFirstVisibleItemScrollOffset: Int = 0,
interactionState: InteractionState? = null
): LazyListState {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
val config = defaultFlingConfig()
// Avoid creating a new instance every invocation
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/CoreText.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/CoreText.kt
index a17dc7c..52ddd42 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/CoreText.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/CoreText.kt
@@ -44,11 +44,11 @@
import androidx.compose.ui.layout.MeasureBlock
import androidx.compose.ui.layout.globalPosition
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.DensityAmbient
-import androidx.compose.ui.platform.FontLoaderAmbient
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientFontLoader
+import androidx.compose.ui.selection.AmbientSelectionRegistrar
import androidx.compose.ui.selection.Selectable
import androidx.compose.ui.selection.SelectionRegistrar
-import androidx.compose.ui.selection.SelectionRegistrarAmbient
import androidx.compose.ui.semantics.getTextLayoutResult
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.AnnotatedString
@@ -111,9 +111,9 @@
require(maxLines > 0) { "maxLines should be greater than 0" }
// selection registrar, if no SelectionContainer is added ambient value will be null
- val selectionRegistrar = SelectionRegistrarAmbient.current
- val density = DensityAmbient.current
- val resourceLoader = FontLoaderAmbient.current
+ val selectionRegistrar = AmbientSelectionRegistrar.current
+ val density = AmbientDensity.current
+ val resourceLoader = AmbientFontLoader.current
val (placeholders, inlineComposables) = resolveInlineContent(text, inlineContent)
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/CoreTextField.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/CoreTextField.kt
index 2772551..ce731fd 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/CoreTextField.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/CoreTextField.kt
@@ -17,42 +17,26 @@
package androidx.compose.foundation.text
-import androidx.compose.animation.core.AnimatedFloat
-import androidx.compose.animation.core.AnimationClockObservable
-import androidx.compose.animation.core.AnimationConstants
-import androidx.compose.animation.core.AnimationSpec
-import androidx.compose.animation.core.Spring
-import androidx.compose.animation.core.keyframes
-import androidx.compose.animation.core.repeatable
import androidx.compose.foundation.text.selection.TextFieldSelectionHandle
import androidx.compose.foundation.text.selection.TextFieldSelectionManager
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.Stable
import androidx.compose.runtime.emptyContent
import androidx.compose.runtime.getValue
import androidx.compose.runtime.invalidate
import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.onCommit
import androidx.compose.runtime.onDispose
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
-import androidx.compose.runtime.structuralEqualityPolicy
import androidx.compose.ui.Modifier
-import androidx.compose.ui.composed
import androidx.compose.ui.drawBehind
-import androidx.compose.ui.drawWithContent
import androidx.compose.ui.focus
import androidx.compose.ui.focus.ExperimentalFocus
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.isFocused
import androidx.compose.ui.focusObserver
import androidx.compose.ui.focusRequester
-import androidx.compose.ui.geometry.Offset
-import androidx.compose.ui.geometry.Rect
-import androidx.compose.ui.gesture.DragObserver
import androidx.compose.ui.gesture.dragGestureFilter
import androidx.compose.ui.gesture.longPressDragGestureFilter
-import androidx.compose.ui.gesture.pressIndicatorGestureFilter
import androidx.compose.ui.gesture.tapGestureFilter
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
@@ -63,13 +47,12 @@
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.AnimationClockAmbient
-import androidx.compose.ui.platform.ClipboardManagerAmbient
-import androidx.compose.ui.platform.DensityAmbient
-import androidx.compose.ui.platform.FontLoaderAmbient
-import androidx.compose.ui.platform.HapticFeedBackAmbient
-import androidx.compose.ui.platform.TextInputServiceAmbient
-import androidx.compose.ui.platform.TextToolbarAmbient
+import androidx.compose.ui.platform.AmbientClipboardManager
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientFontLoader
+import androidx.compose.ui.platform.AmbientHapticFeedback
+import androidx.compose.ui.platform.AmbientTextInputService
+import androidx.compose.ui.platform.AmbientTextToolbar
import androidx.compose.ui.selection.SimpleLayout
import androidx.compose.ui.semantics.copyText
import androidx.compose.ui.semantics.cutText
@@ -97,12 +80,9 @@
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.ImeOptions
import androidx.compose.ui.text.input.NO_SESSION
-import androidx.compose.ui.text.input.OffsetMap
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.Density
-import androidx.compose.ui.unit.dp
-import androidx.compose.ui.util.annotation.VisibleForTesting
import kotlin.math.max
import kotlin.math.roundToInt
@@ -178,9 +158,9 @@
val focusRequester = FocusRequester()
// Ambients
- val textInputService = TextInputServiceAmbient.current
- val density = DensityAmbient.current
- val resourceLoader = FontLoaderAmbient.current
+ val textInputService = AmbientTextInputService.current
+ val density = AmbientDensity.current
+ val resourceLoader = AmbientFontLoader.current
// State
val (visualText, offsetMap) = remember(value, visualTransformation) {
@@ -225,9 +205,9 @@
manager.onValueChange = onValueChangeWrapper
manager.state = state
manager.value = value
- manager.clipboardManager = ClipboardManagerAmbient.current
- manager.textToolbar = TextToolbarAmbient.current
- manager.hapticFeedBack = HapticFeedBackAmbient.current
+ manager.clipboardManager = AmbientClipboardManager.current
+ manager.textToolbar = AmbientTextToolbar.current
+ manager.hapticFeedBack = AmbientHapticFeedback.current
val focusObserver = Modifier.focusObserver {
if (state.hasFocus == it.isFocused) {
@@ -440,6 +420,7 @@
.then(drawModifier)
.then(onPositionedModifier)
.then(semanticsModifier)
+ .textFieldMinSize(textStyle)
.textFieldKeyboardModifier(manager)
.focus()
@@ -577,151 +558,3 @@
)
}
}
-
-/**
- * Helper class for tracking dragging event.
- */
-internal class DragEventTracker {
- private var origin = Offset.Zero
- private var distance = Offset.Zero
-
- /**
- * Restart the tracking from given origin.
- *
- * @param origin The origin of the drag gesture.
- */
- fun init(origin: Offset) {
- this.origin = origin
- }
-
- /**
- * Pass distance parameter called by DragGestureDetector$onDrag callback
- *
- * @param distance The distance from the origin of the drag origin.
- */
- fun onDrag(distance: Offset) {
- this.distance = distance
- }
-
- /**
- * Returns the current position.
- *
- * @return The position of the current drag point.
- */
- fun getPosition(): Offset {
- return origin + distance
- }
-}
-
-/**
- * Helper composable for tracking drag position.
- */
-@Suppress("ModifierInspectorInfo")
-private fun Modifier.dragPositionGestureFilter(
- onPress: (Offset) -> Unit,
- onRelease: (Offset) -> Unit
-): Modifier = composed {
- val tracker = remember { DragEventTracker() }
- // TODO(shepshapard): PressIndicator doesn't seem to be the right thing to use here. It
- // actually may be functionally correct, but might mostly suggest that it should not
- // actually be called PressIndicator, but instead something else.
- pressIndicatorGestureFilter(
- onStart = {
- tracker.init(it)
- onPress(it)
- },
- onStop = {
- onRelease(tracker.getPosition())
- }
- )
- .dragGestureFilter(
- dragObserver = object :
- DragObserver {
- override fun onDrag(dragDistance: Offset): Offset {
- tracker.onDrag(dragDistance)
- return Offset.Zero
- }
- }
- )
-}
-
-private val cursorAnimationSpec: AnimationSpec<Float>
- get() = repeatable(
- iterations = AnimationConstants.Infinite,
- animation = keyframes {
- durationMillis = 1000
- 1f at 0
- 1f at 499
- 0f at 500
- 0f at 999
- }
- )
-
-private val DefaultCursorThickness = 2.dp
-
-@OptIn(InternalTextApi::class)
-@Suppress("ModifierInspectorInfo")
-private fun Modifier.cursor(
- state: TextFieldState,
- value: TextFieldValue,
- offsetMap: OffsetMap,
- cursorColor: Color
-) = composed {
- // this should be a disposable clock, but it's not available in this module
- // however, we only launch one animation and guarantee that we stop it (via snap) in dispose
- val animationClocks = AnimationClockAmbient.current
- val cursorAlpha = remember(animationClocks) { AnimatedFloatModel(0f, animationClocks) }
-
- if (state.hasFocus && value.selection.collapsed && cursorColor != Color.Unspecified) {
- onCommit(cursorColor, value.text) {
- if (@Suppress("DEPRECATION_ERROR") blinkingCursorEnabled) {
- cursorAlpha.animateTo(0f, anim = cursorAnimationSpec)
- } else {
- cursorAlpha.snapTo(1f)
- }
- onDispose {
- cursorAlpha.snapTo(0f)
- }
- }
- drawWithContent {
- this.drawContent()
- val cursorAlphaValue = cursorAlpha.value.coerceIn(0f, 1f)
- if (cursorAlphaValue != 0f) {
- val transformedOffset = offsetMap
- .originalToTransformed(value.selection.start)
- val cursorRect = state.layoutResult?.getCursorRect(transformedOffset)
- ?: Rect(0f, 0f, 0f, 0f)
- val cursorWidth = DefaultCursorThickness.toPx()
- val cursorX = (cursorRect.left + cursorWidth / 2)
- .coerceAtMost(size.width - cursorWidth / 2)
-
- drawLine(
- cursorColor,
- Offset(cursorX, cursorRect.top),
- Offset(cursorX, cursorRect.bottom),
- alpha = cursorAlphaValue,
- strokeWidth = cursorWidth
- )
- }
- }
- } else {
- Modifier
- }
-}
-
-@Stable
-private class AnimatedFloatModel(
- initialValue: Float,
- clock: AnimationClockObservable,
- visibilityThreshold: Float = Spring.DefaultDisplacementThreshold
-) : AnimatedFloat(clock, visibilityThreshold) {
- override var value: Float by mutableStateOf(initialValue, structuralEqualityPolicy())
-}
-
-// TODO(b/151940543): Remove this variable when we have a solution for idling animations
-/** @suppress */
-@InternalTextApi
-@Deprecated(level = DeprecationLevel.ERROR, message = "This is internal API and should not be used")
-var blinkingCursorEnabled: Boolean = true
- @VisibleForTesting
- set
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldCursor.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldCursor.kt
new file mode 100644
index 0000000..335667a
--- /dev/null
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldCursor.kt
@@ -0,0 +1,125 @@
+/*
+ * 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.compose.foundation.text
+
+import androidx.compose.animation.core.AnimatedFloat
+import androidx.compose.animation.core.AnimationClockObservable
+import androidx.compose.animation.core.AnimationConstants
+import androidx.compose.animation.core.AnimationSpec
+import androidx.compose.animation.core.Spring
+import androidx.compose.animation.core.keyframes
+import androidx.compose.animation.core.repeatable
+import androidx.compose.runtime.Stable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.onCommit
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.runtime.structuralEqualityPolicy
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.composed
+import androidx.compose.ui.drawWithContent
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.geometry.Rect
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.AmbientAnimationClock
+import androidx.compose.ui.text.InternalTextApi
+import androidx.compose.ui.text.input.OffsetMap
+import androidx.compose.ui.text.input.TextFieldValue
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.util.annotation.VisibleForTesting
+
+@OptIn(InternalTextApi::class)
+@Suppress("ModifierInspectorInfo")
+internal fun Modifier.cursor(
+ state: TextFieldState,
+ value: TextFieldValue,
+ offsetMap: OffsetMap,
+ cursorColor: Color
+) = composed {
+ // this should be a disposable clock, but it's not available in this module
+ // however, we only launch one animation and guarantee that we stop it (via snap) in dispose
+ val animationClocks = AmbientAnimationClock.current
+ val cursorAlpha = remember(animationClocks) { AnimatedFloatModel(0f, animationClocks) }
+
+ if (state.hasFocus && value.selection.collapsed && cursorColor != Color.Unspecified) {
+ onCommit(cursorColor, value.text) {
+ if (@Suppress("DEPRECATION_ERROR") blinkingCursorEnabled) {
+ cursorAlpha.animateTo(0f, anim = cursorAnimationSpec)
+ } else {
+ cursorAlpha.snapTo(1f)
+ }
+ onDispose {
+ cursorAlpha.snapTo(0f)
+ }
+ }
+ drawWithContent {
+ this.drawContent()
+ val cursorAlphaValue = cursorAlpha.value.coerceIn(0f, 1f)
+ if (cursorAlphaValue != 0f) {
+ val transformedOffset = offsetMap
+ .originalToTransformed(value.selection.start)
+ val cursorRect = state.layoutResult?.getCursorRect(transformedOffset)
+ ?: Rect(0f, 0f, 0f, 0f)
+ val cursorWidth = DefaultCursorThickness.toPx()
+ val cursorX = (cursorRect.left + cursorWidth / 2)
+ .coerceAtMost(size.width - cursorWidth / 2)
+
+ drawLine(
+ cursorColor,
+ Offset(cursorX, cursorRect.top),
+ Offset(cursorX, cursorRect.bottom),
+ alpha = cursorAlphaValue,
+ strokeWidth = cursorWidth
+ )
+ }
+ }
+ } else {
+ Modifier
+ }
+}
+
+@Stable
+private class AnimatedFloatModel(
+ initialValue: Float,
+ clock: AnimationClockObservable,
+ visibilityThreshold: Float = Spring.DefaultDisplacementThreshold
+) : AnimatedFloat(clock, visibilityThreshold) {
+ override var value: Float by mutableStateOf(initialValue, structuralEqualityPolicy())
+}
+
+private val cursorAnimationSpec: AnimationSpec<Float>
+ get() = repeatable(
+ iterations = AnimationConstants.Infinite,
+ animation = keyframes {
+ durationMillis = 1000
+ 1f at 0
+ 1f at 499
+ 0f at 500
+ 0f at 999
+ }
+ )
+
+internal val DefaultCursorThickness = 2.dp
+
+// TODO(b/151940543): Remove this variable when we have a solution for idling animations
+/** @suppress */
+@InternalTextApi
+@Deprecated(level = DeprecationLevel.ERROR, message = "This is internal API and should not be used")
+var blinkingCursorEnabled: Boolean = true
+ @VisibleForTesting
+ set
\ No newline at end of file
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldDelegate.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldDelegate.kt
index 52c1d89..4ba94526 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldDelegate.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldDelegate.kt
@@ -46,17 +46,13 @@
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.TextInputService
import androidx.compose.ui.text.input.TransformedText
-import androidx.compose.ui.text.resolveDefaults
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection
-import androidx.compose.ui.unit.constrainHeight
import kotlin.jvm.JvmStatic
-import androidx.compose.ui.unit.constrainWidth
import kotlin.math.ceil
-import kotlin.math.max
import kotlin.math.roundToInt
// visible for testing
@@ -74,7 +70,7 @@
*
* Until we have font metrics APIs, use the height of reference text as a workaround.
*/
-private fun computeSizeForEmptyText(
+internal fun computeSizeForEmptyText(
style: TextStyle,
density: Density,
resourceLoader: Font.ResourceLoader
@@ -119,22 +115,8 @@
): Triple<Int, Int, TextLayoutResult> {
val layoutResult = textDelegate.layout(constraints, layoutDirection, prevResultText)
- var height = layoutResult.size.height
- var width = layoutResult.size.width
-
- val constrainedWithDefaultSize = constrainWithDefaultSize(
- textDelegate,
- layoutResult,
- constraints,
- layoutDirection,
- width,
- height
- )
-
- height = constrainedWithDefaultSize.height
- width = constrainedWithDefaultSize.width
-
- height = constrainWithMaxLines(maxLines, height, layoutResult)
+ val height = constrainWithMaxLines(maxLines, layoutResult.size.height, layoutResult)
+ val width = layoutResult.size.width
return Triple(width, height, layoutResult)
}
@@ -151,42 +133,6 @@
}
}
- private fun constrainWithDefaultSize(
- textDelegate: TextDelegate,
- layoutResult: TextLayoutResult,
- constraints: Constraints,
- layoutDirection: LayoutDirection,
- width: Int,
- height: Int
- ): IntSize {
- val isEmptyText = textDelegate.text.text.isEmpty()
- val needDefaultWidth = layoutResult.size.width < constraints.maxWidth
-
- val defaultSize = if (isEmptyText || needDefaultWidth) {
- computeSizeForEmptyText(
- style = resolveDefaults(textDelegate.style, layoutDirection),
- density = textDelegate.density,
- resourceLoader = textDelegate.resourceLoader
- )
- } else {
- IntSize.Zero
- }
-
- val newHeight = if (isEmptyText) {
- constraints.constrainHeight(defaultSize.height)
- } else {
- height
- }
-
- val newWidth = if (needDefaultWidth) {
- constraints.constrainWidth(max(defaultSize.width, layoutResult.size.width))
- } else {
- width
- }
-
- return IntSize(newWidth, newHeight)
- }
-
/**
* Draw the text content to the canvas
*
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldDragGestureFilter.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldDragGestureFilter.kt
new file mode 100644
index 0000000..057acb3
--- /dev/null
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldDragGestureFilter.kt
@@ -0,0 +1,92 @@
+/*
+ * 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.compose.foundation.text
+
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.composed
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.gesture.DragObserver
+import androidx.compose.ui.gesture.dragGestureFilter
+import androidx.compose.ui.gesture.pressIndicatorGestureFilter
+
+/**
+ * Helper composable for tracking drag position.
+ */
+@Suppress("ModifierInspectorInfo")
+internal fun Modifier.dragPositionGestureFilter(
+ onPress: (Offset) -> Unit,
+ onRelease: (Offset) -> Unit
+): Modifier = composed {
+ val tracker = remember { DragEventTracker() }
+ // TODO(shepshapard): PressIndicator doesn't seem to be the right thing to use here. It
+ // actually may be functionally correct, but might mostly suggest that it should not
+ // actually be called PressIndicator, but instead something else.
+ pressIndicatorGestureFilter(
+ onStart = {
+ tracker.init(it)
+ onPress(it)
+ },
+ onStop = {
+ onRelease(tracker.getPosition())
+ }
+ )
+ .dragGestureFilter(
+ dragObserver = object :
+ DragObserver {
+ override fun onDrag(dragDistance: Offset): Offset {
+ tracker.onDrag(dragDistance)
+ return Offset.Zero
+ }
+ }
+ )
+}
+
+/**
+ * Helper class for tracking dragging event.
+ */
+internal class DragEventTracker {
+ private var origin = Offset.Zero
+ private var distance = Offset.Zero
+
+ /**
+ * Restart the tracking from given origin.
+ *
+ * @param origin The origin of the drag gesture.
+ */
+ fun init(origin: Offset) {
+ this.origin = origin
+ }
+
+ /**
+ * Pass distance parameter called by DragGestureDetector$onDrag callback
+ *
+ * @param distance The distance from the origin of the drag origin.
+ */
+ fun onDrag(distance: Offset) {
+ this.distance = distance
+ }
+
+ /**
+ * Returns the current position.
+ *
+ * @return The position of the current drag point.
+ */
+ fun getPosition(): Offset {
+ return origin + distance
+ }
+}
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldScroll.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldScroll.kt
index 31c63d1..905cd82 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldScroll.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldScroll.kt
@@ -34,7 +34,7 @@
import androidx.compose.ui.layout.MeasureResult
import androidx.compose.ui.layout.MeasureScope
import androidx.compose.ui.node.Ref
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextLayoutResult
@@ -44,7 +44,6 @@
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.LayoutDirection
-import androidx.compose.ui.unit.dp
import kotlin.math.min
import kotlin.math.roundToInt
@@ -57,7 +56,7 @@
) = composed(
factory = {
// do not reverse direction only in case of RTL in horizontal orientation
- val rtl = LayoutDirectionAmbient.current == LayoutDirection.Rtl
+ val rtl = AmbientLayoutDirection.current == LayoutDirection.Rtl
val reverseDirection = orientation == Orientation.Vertical || !rtl
val scroll = Modifier.scrollable(
orientation = orientation,
@@ -205,8 +204,6 @@
return cursorRect.copy(left = cursorLeft, right = cursorRight)
}
-private val DefaultCursorThickness = 2.dp
-
@Stable
internal class TextFieldScrollerPosition(initial: Float = 0f) {
/**
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldSize.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldSize.kt
new file mode 100644
index 0000000..7b57989
--- /dev/null
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/TextFieldSize.kt
@@ -0,0 +1,95 @@
+/*
+ * 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.compose.foundation.text
+
+import androidx.compose.foundation.layout.defaultMinSizeConstraints
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.composed
+import androidx.compose.ui.layout.layout
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientFontLoader
+import androidx.compose.ui.platform.AmbientLayoutDirection
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.font.Font
+import androidx.compose.ui.text.resolveDefaults
+import androidx.compose.ui.unit.Density
+import androidx.compose.ui.unit.IntSize
+import androidx.compose.ui.unit.LayoutDirection
+import kotlin.math.max
+
+@Suppress("ModifierInspectorInfo")
+internal fun Modifier.textFieldMinSize(style: TextStyle) = composed {
+ val density = AmbientDensity.current
+ val resourceLoader = AmbientFontLoader.current
+ val layoutDirection = AmbientLayoutDirection.current
+
+ val minSizeState = remember { TextFieldSize(layoutDirection, density, resourceLoader, style) }
+ minSizeState.update(layoutDirection, density, resourceLoader, style)
+
+ Modifier.layout { measurable, constraints ->
+ Modifier.defaultMinSizeConstraints()
+ val minSize = minSizeState.minSize
+ val childConstraints = constraints.copy(
+ minWidth = max(minSize.width, constraints.minWidth)
+ .coerceAtMost(constraints.maxWidth),
+ minHeight = max(minSize.height, constraints.minHeight)
+ .coerceAtMost(constraints.maxHeight)
+ )
+ val measured = measurable.measure(childConstraints)
+ layout(measured.width, measured.height) {
+ measured.placeRelative(0, 0)
+ }
+ }
+}
+
+private class TextFieldSize(
+ var layoutDirection: LayoutDirection,
+ var density: Density,
+ var resourceLoader: Font.ResourceLoader,
+ var style: TextStyle
+) {
+ var minSize = computeMinSize()
+ private set
+
+ fun update(
+ layoutDirection: LayoutDirection,
+ density: Density,
+ resourceLoader: Font.ResourceLoader,
+ style: TextStyle
+ ) {
+ if (layoutDirection != this.layoutDirection ||
+ density != this.density ||
+ resourceLoader != this.resourceLoader ||
+ style != this.style
+ ) {
+ this.layoutDirection = layoutDirection
+ this.density = density
+ this.resourceLoader = resourceLoader
+ this.style = style
+ minSize = computeMinSize()
+ }
+ }
+
+ private fun computeMinSize(): IntSize {
+ return computeSizeForEmptyText(
+ style = resolveDefaults(style, layoutDirection),
+ density = density,
+ resourceLoader = resourceLoader
+ )
+ }
+}
\ No newline at end of file
diff --git a/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/Scrollbar.kt b/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/Scrollbar.kt
index 295fd59..a49f026 100644
--- a/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/Scrollbar.kt
+++ b/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/Scrollbar.kt
@@ -43,7 +43,7 @@
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.MeasuringIntrinsicsMeasureBlocks
import androidx.compose.ui.node.ExperimentalLayoutNodeApi
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.constrainHeight
@@ -177,7 +177,7 @@
style: ScrollbarStyle,
interactionState: InteractionState,
isVertical: Boolean
-) = with(DensityAmbient.current) {
+) = with(AmbientDensity.current) {
onDispose {
interactionState.removeInteraction(Interaction.Dragged)
}
@@ -305,7 +305,7 @@
itemCount: Int,
averageItemSize: Dp
): ScrollbarAdapter {
- val averageItemSizePx = with(DensityAmbient.current) {
+ val averageItemSizePx = with(AmbientDensity.current) {
averageItemSize.toPx()
}
return remember(scrollState, itemCount, averageItemSizePx) {
diff --git a/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/animation/DesktopFlingConfig.kt b/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/animation/DesktopFlingConfig.kt
index 900d2dd..1272c0e 100644
--- a/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/animation/DesktopFlingConfig.kt
+++ b/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/animation/DesktopFlingConfig.kt
@@ -19,13 +19,13 @@
import androidx.compose.animation.core.TargetAnimation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
@Composable
internal actual fun actualFlingConfig(adjustTarget: (Float) -> TargetAnimation?): FlingConfig {
// This function will internally update the calculation of fling decay when the density changes,
// but the reference to the returned FlingConfig will not change across calls.
- val density = DensityAmbient.current
+ val density = AmbientDensity.current
return remember(density.density) {
val decayAnimation = DesktopFlingDecaySpec(density)
FlingConfig(
diff --git a/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/gestures/DesktopScrollable.kt b/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/gestures/DesktopScrollable.kt
index b6a296f..a58cb5f 100644
--- a/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/gestures/DesktopScrollable.kt
+++ b/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/gestures/DesktopScrollable.kt
@@ -23,7 +23,7 @@
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
import androidx.compose.ui.input.mouse.MouseScrollUnit
import androidx.compose.ui.input.mouse.mouseScrollFilter
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.DesktopPlatform
import androidx.compose.ui.platform.DesktopPlatformAmbient
import androidx.compose.ui.unit.Density
@@ -45,7 +45,7 @@
scrollCallback: ScrollCallback,
orientation: Orientation
): Modifier = composed {
- val density = DensityAmbient.current
+ val density = AmbientDensity.current
val desktopPlatform = DesktopPlatformAmbient.current
val config = PlatformScrollConfig(density, desktopPlatform)
diff --git a/compose/foundation/foundation/src/test/kotlin/androidx/compose/foundation/gestures/SuspendingGestureTestUtil.kt b/compose/foundation/foundation/src/test/kotlin/androidx/compose/foundation/gestures/SuspendingGestureTestUtil.kt
index 30d6dd4..48d14c9 100644
--- a/compose/foundation/foundation/src/test/kotlin/androidx/compose/foundation/gestures/SuspendingGestureTestUtil.kt
+++ b/compose/foundation/foundation/src/test/kotlin/androidx/compose/foundation/gestures/SuspendingGestureTestUtil.kt
@@ -59,11 +59,11 @@
import androidx.compose.ui.node.OwnedLayer
import androidx.compose.ui.node.Owner
import androidx.compose.ui.node.OwnerScope
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientViewConfiguration
import androidx.compose.ui.platform.ClipboardManager
-import androidx.compose.ui.platform.DensityAmbient
import androidx.compose.ui.platform.TextToolbar
import androidx.compose.ui.platform.ViewConfiguration
-import androidx.compose.ui.platform.ViewConfigurationAmbient
import androidx.compose.ui.semantics.SemanticsOwner
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.input.TextInputService
@@ -129,8 +129,8 @@
withRunningRecomposer { recomposer ->
compose(recomposer) {
Providers(
- DensityAmbient provides Density(1f),
- ViewConfigurationAmbient provides TestViewConfiguration()
+ AmbientDensity provides Density(1f),
+ AmbientViewConfiguration provides TestViewConfiguration()
) {
pointerInputFilter = currentComposer
.materialize(Modifier.pointerInput(gestureDetector)) as
diff --git a/compose/integration-tests/benchmark/src/androidTest/java/androidx/ui/benchmark/test/autofill/AndroidAutofillBenchmark.kt b/compose/integration-tests/benchmark/src/androidTest/java/androidx/ui/benchmark/test/autofill/AndroidAutofillBenchmark.kt
index 62ffc53..77859d6 100644
--- a/compose/integration-tests/benchmark/src/androidTest/java/androidx/ui/benchmark/test/autofill/AndroidAutofillBenchmark.kt
+++ b/compose/integration-tests/benchmark/src/androidTest/java/androidx/ui/benchmark/test/autofill/AndroidAutofillBenchmark.kt
@@ -25,8 +25,8 @@
import androidx.compose.ui.autofill.AutofillTree
import androidx.compose.ui.autofill.AutofillType
import androidx.compose.ui.geometry.Rect
-import androidx.compose.ui.platform.AutofillTreeAmbient
-import androidx.compose.ui.platform.ViewAmbient
+import androidx.compose.ui.platform.AmbientAutofillTree
+import androidx.compose.ui.platform.AmbientView
import androidx.test.annotation.UiThreadTest
import androidx.test.filters.LargeTest
import androidx.test.filters.SdkSuppress
@@ -53,8 +53,8 @@
@Before
fun setup() {
composeTestRule.setContent {
- autofillTree = AutofillTreeAmbient.current
- composeView = ViewAmbient.current
+ autofillTree = AmbientAutofillTree.current
+ composeView = AmbientView.current
}
}
diff --git a/compose/integration-tests/benchmark/src/androidTest/java/androidx/ui/pointerinput/ComposeTapIntegrationBenchmark.kt b/compose/integration-tests/benchmark/src/androidTest/java/androidx/ui/pointerinput/ComposeTapIntegrationBenchmark.kt
index fffe621..10abab3 100644
--- a/compose/integration-tests/benchmark/src/androidTest/java/androidx/ui/pointerinput/ComposeTapIntegrationBenchmark.kt
+++ b/compose/integration-tests/benchmark/src/androidTest/java/androidx/ui/pointerinput/ComposeTapIntegrationBenchmark.kt
@@ -27,7 +27,7 @@
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.unit.dp
import androidx.test.annotation.UiThreadTest
@@ -93,7 +93,7 @@
activityTestRule.runOnUiThreadIR {
activity.setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
itemHeightDp = ItemHeightPx.toDp()
}
App()
diff --git a/compose/integration-tests/demos/src/androidTest/java/androidx/compose/integration/demos/test/DemoTest.kt b/compose/integration-tests/demos/src/androidTest/java/androidx/compose/integration/demos/test/DemoTest.kt
index 7bd3c58..afe1022 100644
--- a/compose/integration-tests/demos/src/androidTest/java/androidx/compose/integration/demos/test/DemoTest.kt
+++ b/compose/integration-tests/demos/src/androidTest/java/androidx/compose/integration/demos/test/DemoTest.kt
@@ -30,6 +30,7 @@
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.filters.MediumTest
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.SemanticsNodeInteractionCollection
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.junit4.createAndroidComposeRule
@@ -49,6 +50,7 @@
@LargeTest
@RunWith(AndroidJUnit4::class)
+@OptIn(ExperimentalTesting::class)
class DemoTest {
@get:Rule
val rule = createAndroidComposeRule<DemoActivity>()
diff --git a/compose/integration-tests/demos/src/main/java/androidx/compose/integration/demos/DemoApp.kt b/compose/integration-tests/demos/src/main/java/androidx/compose/integration/demos/DemoApp.kt
index cfe6bf6..ec33bf0 100644
--- a/compose/integration-tests/demos/src/main/java/androidx/compose/integration/demos/DemoApp.kt
+++ b/compose/integration-tests/demos/src/main/java/androidx/compose/integration/demos/DemoApp.kt
@@ -47,7 +47,7 @@
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.LayoutDirection
@@ -174,7 +174,7 @@
private object AppBarIcons {
@Composable
fun Back(onClick: () -> Unit) {
- val icon = when (LayoutDirectionAmbient.current) {
+ val icon = when (AmbientLayoutDirection.current) {
LayoutDirection.Ltr -> Icons.Filled.ArrowBack
LayoutDirection.Rtl -> Icons.Filled.ArrowForward
}
diff --git a/compose/integration-tests/macro-benchmark/src/androidTest/java/androidx/ui/macrobenchmark/StartupUtils.kt b/compose/integration-tests/macro-benchmark/src/androidTest/java/androidx/ui/macrobenchmark/StartupUtils.kt
index 3bc5433..1b5599f 100644
--- a/compose/integration-tests/macro-benchmark/src/androidTest/java/androidx/ui/macrobenchmark/StartupUtils.kt
+++ b/compose/integration-tests/macro-benchmark/src/androidTest/java/androidx/ui/macrobenchmark/StartupUtils.kt
@@ -29,7 +29,8 @@
fun MacrobenchmarkRule.measureStartup(
profileCompiled: Boolean,
coldLaunch: Boolean,
- block: MacrobenchmarkScope.() -> Unit = {
+ setupBlock: MacrobenchmarkScope.() -> Unit = {},
+ measureBlock: MacrobenchmarkScope.() -> Unit = {
pressHome()
launchPackageAndWait()
}
@@ -45,5 +46,6 @@
killProcessEachIteration = coldLaunch,
iterations = 10
),
- block
+ setupBlock,
+ measureBlock
)
diff --git a/compose/integration-tests/src/androidTest/java/androidx/ui/integration/test/ImageVectorTest.kt b/compose/integration-tests/src/androidTest/java/androidx/ui/integration/test/ImageVectorTest.kt
index ac54717..102d854 100644
--- a/compose/integration-tests/src/androidTest/java/androidx/ui/integration/test/ImageVectorTest.kt
+++ b/compose/integration-tests/src/androidTest/java/androidx/ui/integration/test/ImageVectorTest.kt
@@ -23,7 +23,7 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.graphics.toArgb
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.test.captureToImage
@@ -91,7 +91,7 @@
val testTag = "testTag"
var insetRectSize: Int = 0
rule.setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
insetRectSize = (10f * this.density).roundToInt()
}
val imageVector =
diff --git a/compose/integration-tests/src/main/java/androidx/ui/integration/test/foundation/NestedScrollerTestCase.kt b/compose/integration-tests/src/main/java/androidx/ui/integration/test/foundation/NestedScrollerTestCase.kt
index 4ef4be1..5f8b39b 100644
--- a/compose/integration-tests/src/main/java/androidx/ui/integration/test/foundation/NestedScrollerTestCase.kt
+++ b/compose/integration-tests/src/main/java/androidx/ui/integration/test/foundation/NestedScrollerTestCase.kt
@@ -39,7 +39,7 @@
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import kotlin.random.Random
/**
@@ -75,7 +75,7 @@
val playStoreColor = Color(red = 0x00, green = 0x00, blue = 0x80)
val content: @Composable RowScope.() -> Unit = {
repeat(6) {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
Column(Modifier.fillMaxHeight()) {
val color = remember {
val red = Random.nextInt(256)
diff --git a/compose/material/material-icons-core/build.gradle b/compose/material/material-icons-core/build.gradle
index 8eac4c5..87619b4 100644
--- a/compose/material/material-icons-core/build.gradle
+++ b/compose/material/material-icons-core/build.gradle
@@ -76,7 +76,6 @@
androidx {
name = "Compose Material Icons Core"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.MATERIAL
inceptionYear = "2020"
description = "Compose Material Design core icons. This module contains the most commonly used set of Material icons."
diff --git a/compose/material/material-icons-core/samples/build.gradle b/compose/material/material-icons-core/samples/build.gradle
index 8ec2af4..50a9605 100644
--- a/compose/material/material-icons-core/samples/build.gradle
+++ b/compose/material/material-icons-core/samples/build.gradle
@@ -51,7 +51,6 @@
androidx {
name = "AndroidX Compose UI Core Material Icons Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.MATERIAL
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose UI Core Material Icons"
diff --git a/compose/material/material-icons-extended/build.gradle b/compose/material/material-icons-extended/build.gradle
index 11e9539..55eb397 100644
--- a/compose/material/material-icons-extended/build.gradle
+++ b/compose/material/material-icons-extended/build.gradle
@@ -106,7 +106,6 @@
androidx {
name = "Compose Material Icons Extended"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.MATERIAL
// This module has a large number (5000+) of generated source files and so doc generation /
// API tracking will simply take too long
diff --git a/compose/material/material-icons-extended/src/androidAndroidTest/kotlin/androidx/compose/material/icons/IconComparisonTest.kt b/compose/material/material-icons-extended/src/androidAndroidTest/kotlin/androidx/compose/material/icons/IconComparisonTest.kt
index d67762d..19ffeac 100644
--- a/compose/material/material-icons-extended/src/androidAndroidTest/kotlin/androidx/compose/material/icons/IconComparisonTest.kt
+++ b/compose/material/material-icons-extended/src/androidAndroidTest/kotlin/androidx/compose/material/icons/IconComparisonTest.kt
@@ -32,8 +32,8 @@
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.rememberVectorPainter
-import androidx.compose.ui.platform.ContextAmbient
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientContext
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.vectorResource
@@ -141,7 +141,7 @@
*/
@Composable
private fun String.toImageVector(): ImageVector {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
val resId = context.resources.getIdentifier(this, "drawable", context.packageName)
return vectorResource(resId)
}
@@ -215,7 +215,7 @@
// against in CI, on some devices using DP here causes there to be anti-aliasing issues.
// Using ipx directly ensures that we will always have a consistent layout / drawing
// story, so anti-aliasing should be identical.
- val layoutSize = with(DensityAmbient.current) {
+ val layoutSize = with(AmbientDensity.current) {
Modifier.preferredSize(72.toDp())
}
Row(Modifier.align(Alignment.Center)) {
diff --git a/compose/material/material/build.gradle b/compose/material/material/build.gradle
index c2008a6..2053ed0 100644
--- a/compose/material/material/build.gradle
+++ b/compose/material/material/build.gradle
@@ -132,7 +132,6 @@
androidx {
name = "Compose Material Components"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.MATERIAL
inceptionYear = "2018"
description = "Compose Material Design Components library"
diff --git a/compose/material/material/icons/generator/build.gradle b/compose/material/material/icons/generator/build.gradle
index 59c7c1a..e00b45a 100644
--- a/compose/material/material/icons/generator/build.gradle
+++ b/compose/material/material/icons/generator/build.gradle
@@ -46,7 +46,6 @@
name = "Material Icon Generator"
type = LibraryType.OTHER_CODE_PROCESSOR
publish = Publish.NONE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.MATERIAL
inceptionYear = "2020"
description = "Generator module that parses XML drawables to generate programmatic " +
diff --git a/compose/material/material/integration-tests/material-demos/src/main/java/androidx/compose/material/demos/ColorPickerDemo.kt b/compose/material/material/integration-tests/material-demos/src/main/java/androidx/compose/material/demos/ColorPickerDemo.kt
index 6f0f96f..0122b12c 100644
--- a/compose/material/material/integration-tests/material-demos/src/main/java/androidx/compose/material/demos/ColorPickerDemo.kt
+++ b/compose/material/material/integration-tests/material-demos/src/main/java/androidx/compose/material/demos/ColorPickerDemo.kt
@@ -66,7 +66,7 @@
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.graphics.toPixelMap
import androidx.compose.ui.layout.WithConstraints
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -166,7 +166,7 @@
*/
@Composable
private fun Magnifier(visible: Boolean, position: Offset, color: Color) {
- val offset = with(DensityAmbient.current) {
+ val offset = with(AmbientDensity.current) {
Modifier.offset(
position.x.toDp() - MagnifierWidth / 2,
// Align with the center of the selection circle
diff --git a/compose/material/material/integration-tests/material-studies/src/main/java/androidx/compose/material/studies/rally/RallyAnimatedCircle.kt b/compose/material/material/integration-tests/material-studies/src/main/java/androidx/compose/material/studies/rally/RallyAnimatedCircle.kt
index b3d83ba..43fbc2a 100644
--- a/compose/material/material/integration-tests/material-studies/src/main/java/androidx/compose/material/studies/rally/RallyAnimatedCircle.kt
+++ b/compose/material/material/integration-tests/material-studies/src/main/java/androidx/compose/material/studies/rally/RallyAnimatedCircle.kt
@@ -29,7 +29,7 @@
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.Stroke
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.dp
private const val DividerLengthInDegrees = 1.8f
@@ -67,7 +67,7 @@
proportions: List<Float>,
colors: List<Color>
) {
- val stroke = Stroke(5.dp.value * DensityAmbient.current.density)
+ val stroke = Stroke(5.dp.value * AmbientDensity.current.density)
val state = transition(definition = CircularTransition, initState = 0, toState = 1)
Canvas(modifier) {
val innerRadius = (size.minDimension - stroke.width) / 2
diff --git a/compose/material/material/samples/build.gradle b/compose/material/material/samples/build.gradle
index 9f3afe6..dcadaf0 100644
--- a/compose/material/material/samples/build.gradle
+++ b/compose/material/material/samples/build.gradle
@@ -55,7 +55,6 @@
androidx {
name = "AndroidX Compose UI Material Design Components Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.MATERIAL
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose UI Material Design Components"
diff --git a/compose/material/material/samples/src/main/java/androidx/compose/material/samples/SwipeableSamples.kt b/compose/material/material/samples/src/main/java/androidx/compose/material/samples/SwipeableSamples.kt
index 190e538..0c502af 100644
--- a/compose/material/material/samples/src/main/java/androidx/compose/material/samples/SwipeableSamples.kt
+++ b/compose/material/material/samples/src/main/java/androidx/compose/material/samples/SwipeableSamples.kt
@@ -32,7 +32,7 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@@ -46,7 +46,7 @@
val squareSize = 50.dp
val swipeableState = rememberSwipeableState("A")
- val sizePx = with(DensityAmbient.current) { (width - squareSize).toPx() }
+ val sizePx = with(AmbientDensity.current) { (width - squareSize).toPx() }
val anchors = mapOf(0f to "A", sizePx / 2 to "B", sizePx to "C")
Box(
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/BottomNavigationScreenshotTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/BottomNavigationScreenshotTest.kt
index 6e5e2484..4d647fa 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/BottomNavigationScreenshotTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/BottomNavigationScreenshotTest.kt
@@ -29,6 +29,7 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
@@ -43,7 +44,7 @@
@LargeTest
@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
-@OptIn(ExperimentalMaterialApi::class)
+@OptIn(ExperimentalMaterialApi::class, ExperimentalTesting::class)
class BottomNavigationScreenshotTest {
@get:Rule
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ButtonScreenshotTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ButtonScreenshotTest.kt
index 632ae05..1f907e6 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ButtonScreenshotTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ButtonScreenshotTest.kt
@@ -21,6 +21,7 @@
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.testutils.assertAgainstGolden
import androidx.compose.ui.Modifier
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.center
import androidx.compose.ui.test.down
@@ -41,6 +42,7 @@
@MediumTest
@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
+@OptIn(ExperimentalTesting::class)
class ButtonScreenshotTest {
@get:Rule
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/CheckboxScreenshotTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/CheckboxScreenshotTest.kt
index 1071227..23b19e1 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/CheckboxScreenshotTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/CheckboxScreenshotTest.kt
@@ -25,6 +25,7 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.state.ToggleableState
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.center
import androidx.compose.ui.test.down
@@ -45,6 +46,7 @@
@MediumTest
@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
+@OptIn(ExperimentalTesting::class)
class CheckboxScreenshotTest {
@get:Rule
@@ -201,4 +203,4 @@
.captureToImage()
.assertAgainstGolden(screenshotRule, goldenName)
}
-}
\ No newline at end of file
+}
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/DrawerTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/DrawerTest.kt
index 91cf6df..b8766c6 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/DrawerTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/DrawerTest.kt
@@ -25,7 +25,7 @@
import androidx.compose.runtime.emptyContent
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertLeftPositionInRootIsEqualTo
import androidx.compose.ui.test.assertTopPositionInRootIsEqualTo
@@ -345,7 +345,7 @@
rule.setMaterialContent {
drawerState = rememberDrawerState(DrawerValue.Closed)
// emulate click on the screen
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Box(Modifier.testTag("Drawer")) {
ModalDrawerLayout(
drawerState = drawerState,
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ElevationOverlayTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ElevationOverlayTest.kt
index babd592..829ad05 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ElevationOverlayTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ElevationOverlayTest.kt
@@ -25,7 +25,7 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.junit4.createComposeRule
@@ -210,7 +210,7 @@
MaterialTheme(colors) {
Box {
Surface(elevation = elevation) {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
// Make the surface size small so we compare less pixels
Box(
Modifier.preferredSize(
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/IconTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/IconTest.kt
index 0dbe68c..9953c9c 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/IconTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/IconTest.kt
@@ -28,7 +28,7 @@
import androidx.compose.ui.graphics.painter.ColorPainter
import androidx.compose.ui.graphics.painter.ImagePainter
import androidx.compose.ui.graphics.vector.ImageVector
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertHeightIsEqualTo
import androidx.compose.ui.test.assertWidthIsEqualTo
@@ -86,7 +86,7 @@
val height = 24.dp
rule
.setMaterialContentForSizeAssertions {
- val image = with(DensityAmbient.current) {
+ val image = with(AmbientDensity.current) {
ImageBitmap(width.toIntPx(), height.toIntPx())
}
@@ -103,7 +103,7 @@
rule
.setMaterialContentForSizeAssertions {
- val image = with(DensityAmbient.current) {
+ val image = with(AmbientDensity.current) {
ImageBitmap(width.toIntPx(), height.toIntPx())
}
@@ -133,7 +133,7 @@
rule
.setMaterialContentForSizeAssertions {
- val image = with(DensityAmbient.current) {
+ val image = with(AmbientDensity.current) {
ImageBitmap(width.toIntPx(), height.toIntPx())
}
@@ -152,7 +152,7 @@
val testTag = "testTag"
rule.setMaterialContentForSizeAssertions {
val image: ImageBitmap
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
image = createBitmapWithColor(
this,
width.toIntPx(),
@@ -175,7 +175,7 @@
val testTag = "testTag"
rule.setMaterialContentForSizeAssertions {
val image: ImageBitmap
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
image = createBitmapWithColor(
this,
width.toIntPx(),
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/MenuTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/MenuTest.kt
index a01aa52..29fdbcd 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/MenuTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/MenuTest.kt
@@ -26,8 +26,9 @@
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.hasAnyDescendant
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.isPopup
@@ -50,6 +51,7 @@
@MediumTest
@RunWith(AndroidJUnit4::class)
+@OptIn(ExperimentalTesting::class)
class MenuTest {
@get:Rule
val rule = createComposeRule()
@@ -93,7 +95,7 @@
@Test
fun menu_hasExpectedSize() {
rule.setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
DropdownMenu(
expanded = true,
toggle = {
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ProgressIndicatorTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ProgressIndicatorTest.kt
index db9b8ca..7f8b8ab 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ProgressIndicatorTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ProgressIndicatorTest.kt
@@ -20,6 +20,7 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.AccessibilityRangeInfo
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.assertHeightIsEqualTo
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertRangeInfoEquals
@@ -36,6 +37,7 @@
@LargeTest
@RunWith(AndroidJUnit4::class)
+@OptIn(ExperimentalTesting::class)
class ProgressIndicatorTest {
private val ExpectedLinearWidth = 240.dp
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/RadioButtonScreenshotTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/RadioButtonScreenshotTest.kt
index b6c2f98..747b65f 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/RadioButtonScreenshotTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/RadioButtonScreenshotTest.kt
@@ -25,6 +25,7 @@
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.center
import androidx.compose.ui.test.down
@@ -45,6 +46,7 @@
@MediumTest
@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
+@OptIn(ExperimentalTesting::class)
class RadioButtonScreenshotTest {
@get:Rule
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ScaffoldScreenshotTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ScaffoldScreenshotTest.kt
index f854c3e..8743192 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ScaffoldScreenshotTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ScaffoldScreenshotTest.kt
@@ -30,7 +30,7 @@
import androidx.compose.runtime.Providers
import androidx.compose.testutils.assertAgainstGolden
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.test.captureToImage
@@ -655,7 +655,7 @@
val layoutDirection = if (rtl) LayoutDirection.Rtl else LayoutDirection.Ltr
- Providers(LayoutDirectionAmbient provides layoutDirection) {
+ Providers(AmbientLayoutDirection provides layoutDirection) {
Box(
Modifier
.fillMaxSize(0.5f)
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SliderTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SliderTest.kt
index 0860607..7f909009 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SliderTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SliderTest.kt
@@ -20,7 +20,7 @@
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.AccessibilityRangeInfo
import androidx.compose.ui.semantics.SemanticsActions
@@ -222,7 +222,7 @@
val state = mutableStateOf(0f)
rule.setMaterialContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Slider(
modifier = Modifier.testTag(tag),
value = state.value,
@@ -255,7 +255,7 @@
val state = mutableStateOf(0f)
rule.setMaterialContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Slider(
modifier = Modifier.testTag(tag),
value = state.value,
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SwipeToDismissTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SwipeToDismissTest.kt
index abf3e7d..c78d22d 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SwipeToDismissTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SwipeToDismissTest.kt
@@ -22,7 +22,7 @@
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.runtime.Providers
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertLeftPositionInRootIsEqualTo
import androidx.compose.ui.test.junit4.createComposeRule
@@ -222,7 +222,7 @@
fun swipeToDismiss_dismissBySwipe_toEnd_rtl() {
val dismissState = DismissState(DismissValue.Default, clock)
rule.setContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
SwipeToDismiss(
modifier = Modifier.testTag(swipeToDismissTag),
state = dismissState,
@@ -246,7 +246,7 @@
fun swipeToDismiss_dismissBySwipe_toStart_rtl() {
val dismissState = DismissState(DismissValue.Default, clock)
rule.setContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
SwipeToDismiss(
modifier = Modifier.testTag(swipeToDismissTag),
state = dismissState,
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SwitchScreenshotTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SwitchScreenshotTest.kt
index 5afe047..9cf48ed 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SwitchScreenshotTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SwitchScreenshotTest.kt
@@ -27,8 +27,9 @@
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.center
import androidx.compose.ui.test.down
@@ -51,6 +52,7 @@
@MediumTest
@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
+@OptIn(ExperimentalTesting::class)
class SwitchScreenshotTest {
@get:Rule
@@ -81,7 +83,7 @@
fun switchTest_checked_rtl() {
rule.setMaterialContent {
Box(wrapperModifier) {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Switch(checked = true, onCheckedChange = { })
}
}
@@ -117,7 +119,7 @@
fun switchTest_unchecked_rtl() {
rule.setMaterialContent {
Box(wrapperModifier) {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Switch(checked = false, onCheckedChange = { })
}
}
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SwitchTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SwitchTest.kt
index 5cbf60d..e552475 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SwitchTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/SwitchTest.kt
@@ -23,7 +23,7 @@
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertHasNoClickAction
import androidx.compose.ui.test.assertHeightIsEqualTo
@@ -182,7 +182,7 @@
rule.setMaterialContent {
// Box is needed because otherwise the control will be expanded to fill its parent
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Box {
Switch(
modifier = Modifier.testTag(defaultSwitchTag),
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/TabScreenshotTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/TabScreenshotTest.kt
index 13f36b9..694bbc6 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/TabScreenshotTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/TabScreenshotTest.kt
@@ -27,6 +27,7 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
@@ -41,7 +42,7 @@
@LargeTest
@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
-@OptIn(ExperimentalMaterialApi::class)
+@OptIn(ExperimentalMaterialApi::class, ExperimentalTesting::class)
class TabScreenshotTest {
@get:Rule
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ripple/RippleIndicationTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ripple/RippleIndicationTest.kt
index 5725ab8..aaf3e13 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ripple/RippleIndicationTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/ripple/RippleIndicationTest.kt
@@ -46,6 +46,7 @@
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createComposeRule
@@ -63,7 +64,7 @@
@LargeTest
@RunWith(AndroidJUnit4::class)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
-@OptIn(ExperimentalMaterialApi::class)
+@OptIn(ExperimentalMaterialApi::class, ExperimentalTesting::class)
class RippleIndicationTest {
@get:Rule
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/OutlinedTextFieldScreenshotTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/OutlinedTextFieldScreenshotTest.kt
index 8c2efed..0b707f1 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/OutlinedTextFieldScreenshotTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/OutlinedTextFieldScreenshotTest.kt
@@ -25,7 +25,7 @@
import androidx.compose.runtime.Providers
import androidx.compose.testutils.assertAgainstGolden
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.test.captureToImage
@@ -110,7 +110,7 @@
@Test
fun outlinedTextField_focused_rtl() {
rule.setMaterialContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Box(Modifier.semantics(mergeDescendants = true) {}.testTag(TextFieldTag)) {
OutlinedTextField(
value = "",
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/OutlinedTextFieldTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/OutlinedTextFieldTest.kt
index e4c5cf0..1163d83 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/OutlinedTextFieldTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/OutlinedTextFieldTest.kt
@@ -45,8 +45,9 @@
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.node.Ref
-import androidx.compose.ui.platform.TextInputServiceAmbient
+import androidx.compose.ui.platform.AmbientTextInputService
import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.click
import androidx.compose.ui.test.junit4.createComposeRule
@@ -81,7 +82,7 @@
@MediumTest
@RunWith(AndroidJUnit4::class)
-@OptIn(ExperimentalFocus::class)
+@OptIn(ExperimentalFocus::class, ExperimentalTesting::class)
class OutlinedTextFieldTest {
private val ExpectedMinimumTextFieldHeight = 56.dp
private val ExpectedPadding = 16.dp
@@ -599,7 +600,7 @@
val textInputService = mock<TextInputService>()
rule.setContent {
Providers(
- TextInputServiceAmbient provides textInputService
+ AmbientTextInputService provides textInputService
) {
var text = remember { mutableStateOf(TextFieldValue("")) }
OutlinedTextField(
@@ -717,4 +718,4 @@
rule.clockTestRule.pauseClock()
rule.clockTestRule.advanceClock(time)
}
-}
\ No newline at end of file
+}
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/TextFieldScreenshotTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/TextFieldScreenshotTest.kt
index 9c24e7f..b039a0f 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/TextFieldScreenshotTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/TextFieldScreenshotTest.kt
@@ -25,7 +25,7 @@
import androidx.compose.runtime.Providers
import androidx.compose.testutils.assertAgainstGolden
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.test.captureToImage
@@ -110,7 +110,7 @@
@Test
fun textField_focused_rtl() {
rule.setMaterialContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Box(Modifier.semantics(mergeDescendants = true) {}.testTag(TextFieldTag)) {
TextField(
value = "",
diff --git a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/TextFieldTest.kt b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/TextFieldTest.kt
index c5a9e02..326a0e8 100644
--- a/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/TextFieldTest.kt
+++ b/compose/material/material/src/androidAndroidTest/kotlin/androidx/compose/material/textfield/TextFieldTest.kt
@@ -54,9 +54,10 @@
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.node.Ref
-import androidx.compose.ui.platform.TextInputServiceAmbient
-import androidx.compose.ui.platform.ViewAmbient
+import androidx.compose.ui.platform.AmbientTextInputService
+import androidx.compose.ui.platform.AmbientView
import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.assertHeightIsEqualTo
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.click
@@ -95,7 +96,7 @@
@MediumTest
@RunWith(AndroidJUnit4::class)
-@OptIn(ExperimentalFocus::class)
+@OptIn(ExperimentalFocus::class, ExperimentalTesting::class)
class TextFieldTest {
private val ExpectedMinimumTextFieldHeight = 56.dp
@@ -198,7 +199,7 @@
val focusRequester = FocusRequester()
lateinit var hostView: View
rule.setMaterialContent {
- hostView = ViewAmbient.current
+ hostView = AmbientView.current
Box {
TextField(
modifier = Modifier
@@ -229,7 +230,7 @@
lateinit var softwareKeyboardController: SoftwareKeyboardController
lateinit var hostView: View
rule.setMaterialContent {
- hostView = ViewAmbient.current
+ hostView = AmbientView.current
Box {
TextField(
modifier = Modifier
@@ -752,7 +753,7 @@
val textInputService = mock<TextInputService>()
rule.setContent {
Providers(
- TextInputServiceAmbient provides textInputService
+ AmbientTextInputService provides textInputService
) {
val text = remember { mutableStateOf(TextFieldValue("")) }
TextField(
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BackdropScaffold.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BackdropScaffold.kt
index f975c9c..3fe7dcd 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BackdropScaffold.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BackdropScaffold.kt
@@ -44,8 +44,8 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.layout.SubcomposeLayout
-import androidx.compose.ui.platform.AnimationClockAmbient
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -176,7 +176,7 @@
@ExperimentalMaterialApi
fun rememberBackdropScaffoldState(
initialValue: BackdropValue,
- clock: AnimationClockObservable = AnimationClockAmbient.current,
+ clock: AnimationClockObservable = AmbientAnimationClock.current,
animationSpec: AnimationSpec<Float> = SwipeableConstants.DefaultAnimationSpec,
confirmStateChange: (BackdropValue) -> Boolean = { true },
snackbarHostState: SnackbarHostState = remember { SnackbarHostState() }
@@ -284,8 +284,8 @@
backLayerContent: @Composable () -> Unit,
frontLayerContent: @Composable () -> Unit
) {
- val peekHeightPx = with(DensityAmbient.current) { peekHeight.toPx() }
- val headerHeightPx = with(DensityAmbient.current) { headerHeight.toPx() }
+ val peekHeightPx = with(AmbientDensity.current) { peekHeight.toPx() }
+ val headerHeightPx = with(AmbientDensity.current) { headerHeight.toPx() }
val backLayer = @Composable {
if (persistentAppBar) {
@@ -398,7 +398,7 @@
val animationProgress = animate(
target = if (target == Revealed) 0f else 2f, animSpec = TweenSpec()
)
- val animationSlideOffset = with(DensityAmbient.current) { AnimationSlideOffset.toPx() }
+ val animationSlideOffset = with(AmbientDensity.current) { AnimationSlideOffset.toPx() }
val appBarFloat = (animationProgress - 1).coerceIn(0f, 1f)
val contentFloat = (1 - animationProgress).coerceIn(0f, 1f)
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomSheetScaffold.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomSheetScaffold.kt
index 3fa8cb5..af35117 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomSheetScaffold.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomSheetScaffold.kt
@@ -44,8 +44,8 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.AnimationClockAmbient
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import kotlin.math.roundToInt
@@ -167,7 +167,7 @@
animationSpec: AnimationSpec<Float> = SwipeableConstants.DefaultAnimationSpec,
confirmStateChange: (BottomSheetValue) -> Boolean = { true }
): BottomSheetState {
- val disposableClock = AnimationClockAmbient.current.asDisposableClock()
+ val disposableClock = AmbientAnimationClock.current.asDisposableClock()
return rememberSavedInstanceState(
disposableClock,
saver = BottomSheetState.Saver(
@@ -296,7 +296,7 @@
) {
WithConstraints(modifier) {
val fullHeight = constraints.maxHeight.toFloat()
- val peekHeightPx = with(DensityAmbient.current) { sheetPeekHeight.toPx() }
+ val peekHeightPx = with(AmbientDensity.current) { sheetPeekHeight.toPx() }
var bottomSheetHeight by remember { mutableStateOf(fullHeight) }
val swipeable = Modifier.swipeable(
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Button.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Button.kt
index aa7388b..7c37fb2 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Button.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Button.kt
@@ -45,7 +45,7 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.compositeOver
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -371,7 +371,7 @@
// hovered: Dp = 4.dp,
disabledElevation: Dp = 0.dp
): ButtonElevation {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
return remember(defaultElevation, pressedElevation, disabledElevation, clock) {
DefaultButtonElevation(
defaultElevation = defaultElevation,
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Checkbox.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Checkbox.kt
index 81faea5..1ae6d72 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Checkbox.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Checkbox.kt
@@ -52,7 +52,7 @@
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.Fill
import androidx.compose.ui.graphics.drawscope.Stroke
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.state.ToggleableState
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.lerp
@@ -211,7 +211,7 @@
disabledColor: Color = MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled),
disabledIndeterminateColor: Color = checkedColor.copy(alpha = ContentAlpha.disabled)
): CheckboxColors {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
return remember(
checkedColor,
uncheckedColor,
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Drawer.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Drawer.kt
index 6775200..02d4f58 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Drawer.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Drawer.kt
@@ -39,9 +39,9 @@
import androidx.compose.ui.gesture.tapGestureFilter
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
-import androidx.compose.ui.platform.AnimationClockAmbient
-import androidx.compose.ui.platform.DensityAmbient
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
@@ -276,7 +276,7 @@
initialValue: DrawerValue,
confirmStateChange: (DrawerValue) -> Boolean = { true }
): DrawerState {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
return rememberSavedInstanceState(
clock,
saver = DrawerState.Saver(clock, confirmStateChange)
@@ -296,7 +296,7 @@
initialValue: BottomDrawerValue,
confirmStateChange: (BottomDrawerValue) -> Boolean = { true }
): BottomDrawerState {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
return rememberSavedInstanceState(
clock,
saver = BottomDrawerState.Saver(clock, confirmStateChange)
@@ -356,7 +356,7 @@
val maxValue = 0f
val anchors = mapOf(minValue to DrawerValue.Closed, maxValue to DrawerValue.Open)
- val isRtl = LayoutDirectionAmbient.current == LayoutDirection.Rtl
+ val isRtl = AmbientLayoutDirection.current == LayoutDirection.Rtl
Box(
Modifier.swipeable(
state = drawerState,
@@ -379,7 +379,7 @@
color = scrimColor
)
Surface(
- modifier = with(DensityAmbient.current) {
+ modifier = with(AmbientDensity.current) {
Modifier.preferredSizeIn(
minWidth = constraints.minWidth.toDp(),
minHeight = constraints.minHeight.toDp(),
@@ -493,7 +493,7 @@
color = scrimColor
)
Surface(
- modifier = with(DensityAmbient.current) {
+ modifier = with(AmbientDensity.current) {
Modifier.preferredSizeIn(
minWidth = constraints.minWidth.toDp(),
minHeight = constraints.minHeight.toDp(),
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/FloatingActionButton.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/FloatingActionButton.kt
index 352d434..6f21a64 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/FloatingActionButton.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/FloatingActionButton.kt
@@ -42,7 +42,7 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -224,7 +224,7 @@
// focused: Dp = 8.dp,
// hovered: Dp = 8.dp,
): FloatingActionButtonElevation {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
return remember(defaultElevation, pressedElevation, clock) {
DefaultFloatingActionButtonElevation(
defaultElevation = defaultElevation,
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Menu.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Menu.kt
index 0762382..58ac47a 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Menu.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Menu.kt
@@ -45,7 +45,7 @@
import androidx.compose.ui.DrawLayerModifier
import androidx.compose.ui.Modifier
import androidx.compose.ui.TransformOrigin
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntBounds
import androidx.compose.ui.unit.IntOffset
@@ -104,7 +104,7 @@
if (visibleMenu) {
var transformOrigin by remember { mutableStateOf(TransformOrigin.Center) }
- val density = DensityAmbient.current
+ val density = AmbientDensity.current
val popupPositionProvider = DropdownMenuPositionProvider(
dropdownOffset,
density
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ModalBottomSheet.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ModalBottomSheet.kt
index 94084a6..f9904cc 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ModalBottomSheet.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ModalBottomSheet.kt
@@ -39,7 +39,7 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.layout.SubcomposeLayout
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -166,7 +166,7 @@
@ExperimentalMaterialApi
fun rememberModalBottomSheetState(
initialValue: ModalBottomSheetValue,
- clock: AnimationClockObservable = AnimationClockAmbient.current,
+ clock: AnimationClockObservable = AmbientAnimationClock.current,
animationSpec: AnimationSpec<Float> = SwipeableConstants.DefaultAnimationSpec,
confirmStateChange: (ModalBottomSheetValue) -> Boolean = { true }
): ModalBottomSheetState {
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ProgressIndicator.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ProgressIndicator.kt
index 0be2779..09a97e0 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ProgressIndicator.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ProgressIndicator.kt
@@ -40,7 +40,7 @@
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.Stroke
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
@@ -177,7 +177,7 @@
color: Color = MaterialTheme.colors.primary,
strokeWidth: Dp = ProgressIndicatorConstants.DefaultStrokeWidth
) {
- val stroke = with(DensityAmbient.current) {
+ val stroke = with(AmbientDensity.current) {
Stroke(width = strokeWidth.toPx(), cap = StrokeCap.Butt)
}
Canvas(
@@ -205,7 +205,7 @@
color: Color = MaterialTheme.colors.primary,
strokeWidth: Dp = ProgressIndicatorConstants.DefaultStrokeWidth
) {
- val stroke = with(DensityAmbient.current) {
+ val stroke = with(AmbientDensity.current) {
Stroke(width = strokeWidth.toPx(), cap = StrokeCap.Square)
}
val state = transition(
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/RadioButton.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/RadioButton.kt
index c5d0e30..8a8a6eb 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/RadioButton.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/RadioButton.kt
@@ -42,7 +42,7 @@
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.Fill
import androidx.compose.ui.graphics.drawscope.Stroke
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -142,7 +142,7 @@
unselectedColor: Color = MaterialTheme.colors.onSurface.copy(alpha = 0.6f),
disabledColor: Color = MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled)
): RadioButtonColors {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
return remember(
selectedColor,
unselectedColor,
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Slider.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Slider.kt
index 447c371..05b57ec 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Slider.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Slider.kt
@@ -54,9 +54,9 @@
import androidx.compose.ui.graphics.PointMode
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.layout.WithConstraints
-import androidx.compose.ui.platform.AnimationClockAmbient
-import androidx.compose.ui.platform.DensityAmbient
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.semantics.AccessibilityRangeInfo
import androidx.compose.ui.semantics.accessibilityValue
import androidx.compose.ui.semantics.accessibilityValueRange
@@ -127,14 +127,14 @@
activeTickColor: Color = MaterialTheme.colors.onPrimary.copy(alpha = TickColorAlpha),
inactiveTickColor: Color = activeTrackColor.copy(alpha = TickColorAlpha)
) {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
val position = remember(valueRange, steps) {
SliderPosition(value, valueRange, steps, clock, onValueChange)
}
position.onValueChange = onValueChange
position.scaledValue = value
WithConstraints(modifier.sliderSemantics(value, position, onValueChange, valueRange, steps)) {
- val isRtl = LayoutDirectionAmbient.current == LayoutDirection.Rtl
+ val isRtl = AmbientLayoutDirection.current == LayoutDirection.Rtl
val maxPx = constraints.maxWidth.toFloat()
val minPx = 0f
position.setBounds(minPx, maxPx)
@@ -220,7 +220,7 @@
interactionState: InteractionState,
modifier: Modifier
) {
- val widthDp = with(DensityAmbient.current) {
+ val widthDp = with(AmbientDensity.current) {
width.toDp()
}
Box(modifier.then(DefaultSliderConstraints)) {
@@ -230,7 +230,7 @@
val trackStrokeWidth: Float
val thumbPx: Float
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
trackStrokeWidth = TrackHeight.toPx()
thumbPx = ThumbRadius.toPx()
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Surface.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Surface.kt
index a16e250..1213952 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Surface.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Surface.kt
@@ -28,7 +28,7 @@
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.layout.Layout
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -91,7 +91,7 @@
elevation: Dp = 0.dp,
content: @Composable () -> Unit
) {
- val elevationPx = with(DensityAmbient.current) { elevation.toPx() }
+ val elevationPx = with(AmbientDensity.current) { elevation.toPx() }
val elevationOverlay = AmbientElevationOverlay.current
val absoluteElevation = AmbientAbsoluteElevation.current + elevation
val backgroundColor = if (color == MaterialTheme.colors.surface && elevationOverlay != null) {
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/SwipeToDismiss.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/SwipeToDismiss.kt
index 793b937..bdcce40 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/SwipeToDismiss.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/SwipeToDismiss.kt
@@ -37,8 +37,8 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.WithConstraints
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
-import androidx.compose.ui.platform.AnimationClockAmbient
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
/**
@@ -167,7 +167,7 @@
initialValue: DismissValue = Default,
confirmStateChange: (DismissValue) -> Boolean = { true }
): DismissState {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
return rememberSavedInstanceState(
clock,
saver = DismissState.Saver(clock, confirmStateChange)
@@ -200,7 +200,7 @@
dismissContent: @Composable RowScope.() -> Unit
) = WithConstraints(modifier) {
val width = constraints.maxWidth.toFloat()
- val isRtl = LayoutDirectionAmbient.current == LayoutDirection.Rtl
+ val isRtl = AmbientLayoutDirection.current == LayoutDirection.Rtl
val anchors = mutableMapOf(0f to Default)
if (StartToEnd in directions) anchors += width to DismissedToEnd
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Swipeable.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Swipeable.kt
index 6fbd392..858066e 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Swipeable.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Swipeable.kt
@@ -43,8 +43,8 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
-import androidx.compose.ui.platform.AnimationClockAmbient
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
@@ -336,7 +336,7 @@
animationSpec: AnimationSpec<Float> = DefaultAnimationSpec,
confirmStateChange: (newValue: T) -> Boolean = { true }
): SwipeableState<T> {
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
return rememberSavedInstanceState(
clock,
saver = SwipeableState.Saver(
@@ -455,7 +455,7 @@
require(anchors.values.distinct().count() == anchors.size) {
"You cannot have two anchors mapped to the same state."
}
- val density = DensityAmbient.current
+ val density = AmbientDensity.current
onCommit(anchors) {
state.anchors = anchors
state.thresholds = { a, b ->
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Switch.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Switch.kt
index 493ed25..57e0c29 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Switch.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Switch.kt
@@ -45,8 +45,8 @@
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.graphics.drawscope.DrawScope
-import androidx.compose.ui.platform.DensityAmbient
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
@@ -78,9 +78,9 @@
colors: SwitchColors = SwitchConstants.defaultColors()
) {
val minBound = 0f
- val maxBound = with(DensityAmbient.current) { ThumbPathLength.toPx() }
+ val maxBound = with(AmbientDensity.current) { ThumbPathLength.toPx() }
val swipeableState = rememberSwipeableStateFor(checked, onCheckedChange, AnimationSpec)
- val isRtl = LayoutDirectionAmbient.current == LayoutDirection.Rtl
+ val isRtl = AmbientLayoutDirection.current == LayoutDirection.Rtl
Box(
modifier
.toggleable(
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ripple/RippleIndication.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ripple/RippleIndication.kt
index c4bd69d..f2a65ca 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ripple/RippleIndication.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ripple/RippleIndication.kt
@@ -42,7 +42,7 @@
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.clipRect
import androidx.compose.ui.graphics.useOrElse
-import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.AmbientAnimationClock
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.util.fastForEach
import androidx.compose.ui.util.nativeClass
@@ -86,7 +86,7 @@
color: Color = Color.Unspecified
): RippleIndication {
val theme = AmbientRippleTheme.current
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
val resolvedColor = color.useOrElse { theme.defaultColor() }
val colorState = remember { mutableStateOf(resolvedColor, structuralEqualityPolicy()) }
colorState.value = resolvedColor
@@ -127,7 +127,7 @@
color: Color = Color.Unspecified
): RippleIndication {
val theme = AmbientRippleTheme.current
- val clock = AnimationClockAmbient.current.asDisposableClock()
+ val clock = AmbientAnimationClock.current.asDisposableClock()
val resolvedColor = color.useOrElse { theme.defaultColor() }
val colorState = remember { mutableStateOf(resolvedColor, structuralEqualityPolicy()) }
colorState.value = resolvedColor
diff --git a/compose/runtime/runtime-dispatch/build.gradle b/compose/runtime/runtime-dispatch/build.gradle
index a8c1554..3b6b9e5 100644
--- a/compose/runtime/runtime-dispatch/build.gradle
+++ b/compose/runtime/runtime-dispatch/build.gradle
@@ -116,7 +116,6 @@
androidx {
name = "Compose Dispatch"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.RUNTIME
inceptionYear = "2020"
description = "Platform scheduling and event dispatch utilities used by Compose"
diff --git a/compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/AmbientNamingDetector.kt b/compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/AmbientNamingDetector.kt
new file mode 100644
index 0000000..71b3a2c
--- /dev/null
+++ b/compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/AmbientNamingDetector.kt
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+
+@file:Suppress("UnstableApiUsage")
+
+package androidx.compose.runtime.lint
+
+import com.android.tools.lint.client.api.UElementHandler
+import com.android.tools.lint.detector.api.Category
+import com.android.tools.lint.detector.api.Detector
+import com.android.tools.lint.detector.api.Implementation
+import com.android.tools.lint.detector.api.Issue
+import com.android.tools.lint.detector.api.JavaContext
+import com.android.tools.lint.detector.api.LintFix
+import com.android.tools.lint.detector.api.Scope
+import com.android.tools.lint.detector.api.Severity
+import com.android.tools.lint.detector.api.SourceCodeScanner
+import com.intellij.psi.util.InheritanceUtil
+import org.jetbrains.uast.UElement
+import org.jetbrains.uast.UVariable
+import java.util.Locale
+
+/**
+ * [Detector] that checks the naming of Ambient properties for consistency with guidelines.
+ *
+ * - `Ambient` should not be used as a noun (suffix) in the name of an Ambient property. It may
+ * be used as an adjective (prefix) in lieu of a more descriptive adjective.
+ */
+class AmbientNamingDetector : Detector(), SourceCodeScanner {
+ override fun getApplicableUastTypes() = listOf(UVariable::class.java)
+
+ override fun createUastHandler(context: JavaContext) = object : UElementHandler() {
+ override fun visitVariable(node: UVariable) {
+ val type = node.type
+ if (!InheritanceUtil.isInheritor(type, AmbientFqn)) return
+
+ val name = node.name
+ if (!name!!.endsWith(AmbientShortName)) return
+
+ val newName = AmbientShortName + name.replace(AmbientShortName, "")
+ .capitalize(Locale.getDefault())
+
+ // Kotlinc can't disambiguate overloads for report / getNameLocation otherwise
+ val uElementNode: UElement = node
+
+ context.report(
+ AmbientNaming,
+ uElementNode,
+ context.getNameLocation(uElementNode),
+ "`Ambient` should not be used as a noun when naming Ambient properties",
+ LintFix.create()
+ .replace()
+ .name("Use Ambient as an adjective (prefix)")
+ .text(name)
+ .with(newName)
+ .autoFix()
+ .build()
+ )
+ }
+ }
+
+ companion object {
+ val AmbientNaming = Issue.create(
+ "AmbientNaming",
+ "Incorrect naming for Ambient properties",
+ "`Ambient` should not be used as a anoun when naming Ambient properties. It may be " +
+ "used as an adjective in lieu of a more descriptive adjective. Otherwise Ambients" +
+ " follow standard property naming guidelines.",
+ Category.CORRECTNESS, 3, Severity.ERROR,
+ Implementation(
+ AmbientNamingDetector::class.java,
+ Scope.JAVA_FILE_SCOPE
+ )
+ )
+ }
+}
+
+private const val AmbientFqn = "androidx.compose.runtime.Ambient"
+private val AmbientShortName get() = AmbientFqn.split(".").last()
diff --git a/compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/RuntimeIssueRegistry.kt b/compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/RuntimeIssueRegistry.kt
index c6df662..724b589 100644
--- a/compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/RuntimeIssueRegistry.kt
+++ b/compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/RuntimeIssueRegistry.kt
@@ -27,6 +27,7 @@
override val api = 8
override val minApi = CURRENT_API
override val issues get() = listOf(
+ AmbientNamingDetector.AmbientNaming,
ComposableNamingDetector.ComposableNaming
)
}
diff --git a/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/AmbientNamingDetectorTest.kt b/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/AmbientNamingDetectorTest.kt
new file mode 100644
index 0000000..7290145
--- /dev/null
+++ b/compose/runtime/runtime-lint/src/test/java/androidx/compose/runtime/lint/AmbientNamingDetectorTest.kt
@@ -0,0 +1,182 @@
+/*
+ * 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.
+ */
+
+@file:Suppress("UnstableApiUsage")
+
+package androidx.compose.runtime.lint
+
+import com.android.tools.lint.checks.infrastructure.LintDetectorTest
+import com.android.tools.lint.detector.api.Detector
+import com.android.tools.lint.detector.api.Issue
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+/* ktlint-disable max-line-length */
+@RunWith(JUnit4::class)
+
+/**
+ * Test for [AmbientNamingDetector].
+ */
+class AmbientNamingDetectorTest : LintDetectorTest() {
+ override fun getDetector(): Detector = AmbientNamingDetector()
+
+ override fun getIssues(): MutableList<Issue> =
+ mutableListOf(AmbientNamingDetector.AmbientNaming)
+
+ // Simplified Ambient.kt stubs
+ private val ambientStub = kotlin(
+ """
+ package androidx.compose.runtime
+
+ sealed class Ambient<T> constructor(defaultFactory: (() -> T)? = null)
+
+ abstract class ProvidableAmbient<T> internal constructor(
+ defaultFactory: (() -> T)?
+ ) : Ambient<T>(defaultFactory)
+
+ internal class DynamicProvidableAmbient<T> constructor(
+ defaultFactory: (() -> T)?
+ ) : ProvidableAmbient<T>(defaultFactory)
+
+ internal class StaticProvidableAmbient<T>(
+ defaultFactory: (() -> T)?
+ ) : ProvidableAmbient<T>(defaultFactory)
+
+ fun <T> ambientOf(
+ defaultFactory: (() -> T)? = null
+ ): ProvidableAmbient<T> = DynamicProvidableAmbient(defaultFactory)
+
+ fun <T> staticAmbientOf(
+ defaultFactory: (() -> T)? = null
+ ): ProvidableAmbient<T> = StaticProvidableAmbient(defaultFactory)
+ """
+ )
+
+ @Test
+ fun ambientUsedAsNoun() {
+ lint().files(
+ kotlin(
+ """
+ package androidx.compose.runtime.foo
+
+ import androidx.compose.runtime.*
+
+ val FooAmbient = ambientOf { 5 }
+
+ object Test {
+ val BarAmbient: Ambient<String?> = staticAmbientOf { null }
+ }
+
+ class Test2 {
+ companion object {
+ val BazAmbient: ProvidableAmbient<Int> = ambientOf()
+ }
+ }
+ """
+ ),
+ ambientStub
+ )
+ .run()
+ .expect(
+ """
+src/androidx/compose/runtime/foo/Test.kt:6: Error: Ambient should not be used as a noun when naming Ambient properties [AmbientNaming]
+ val FooAmbient = ambientOf { 5 }
+ ~~~~~~~~~~
+src/androidx/compose/runtime/foo/Test.kt:9: Error: Ambient should not be used as a noun when naming Ambient properties [AmbientNaming]
+ val BarAmbient: Ambient<String?> = staticAmbientOf { null }
+ ~~~~~~~~~~
+src/androidx/compose/runtime/foo/Test.kt:14: Error: Ambient should not be used as a noun when naming Ambient properties [AmbientNaming]
+ val BazAmbient: ProvidableAmbient<Int> = ambientOf()
+ ~~~~~~~~~~
+3 errors, 0 warnings
+ """
+ )
+ .expectFixDiffs(
+ """
+Fix for src/androidx/compose/runtime/foo/Test.kt line 6: Use Ambient as an adjective (prefix):
+@@ -6 +6
+- val FooAmbient = ambientOf { 5 }
++ val AmbientFoo = ambientOf { 5 }
+Fix for src/androidx/compose/runtime/foo/Test.kt line 9: Use Ambient as an adjective (prefix):
+@@ -9 +9
+- val BarAmbient: Ambient<String?> = staticAmbientOf { null }
++ val AmbientBar: Ambient<String?> = staticAmbientOf { null }
+Fix for src/androidx/compose/runtime/foo/Test.kt line 14: Use Ambient as an adjective (prefix):
+@@ -14 +14
+- val BazAmbient: ProvidableAmbient<Int> = ambientOf()
++ val AmbientBaz: ProvidableAmbient<Int> = ambientOf()
+ """
+ )
+ }
+
+ @Test
+ fun ambientUsedAsAdjective() {
+ lint().files(
+ kotlin(
+ """
+ package androidx.compose.runtime.foo
+
+ import androidx.compose.runtime.*
+
+ val AmbientFoo = ambientOf { 5 }
+
+ object Test {
+ val AmbientBar: Ambient<String?> = staticAmbientOf { null }
+ }
+
+ class Test2 {
+ companion object {
+ val AmbientBaz: ProvidableAmbient<Int> = ambientOf()
+ }
+ }
+ """
+ ),
+ ambientStub
+ )
+ .run()
+ .expectClean()
+ }
+
+ @Test
+ fun descriptiveAdjectives() {
+ lint().files(
+ kotlin(
+ """
+ package androidx.compose.runtime.foo
+
+ import androidx.compose.runtime.*
+
+ val ThemeFoo = ambientOf { 5 }
+
+ object Test {
+ val ThemeBar: Ambient<String?> = staticAmbientOf { null }
+ }
+
+ class Test2 {
+ companion object {
+ val StyledBaz: ProvidableAmbient<Int> = ambientOf()
+ }
+ }
+ """
+ ),
+ ambientStub
+ )
+ .run()
+ .expectClean()
+ }
+}
+/* ktlint-enable max-line-length */
diff --git a/compose/runtime/runtime-livedata/build.gradle b/compose/runtime/runtime-livedata/build.gradle
index f357193..cc8ca82 100644
--- a/compose/runtime/runtime-livedata/build.gradle
+++ b/compose/runtime/runtime-livedata/build.gradle
@@ -46,7 +46,6 @@
androidx {
name = "Compose LiveData integration"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.RUNTIME
inceptionYear = "2020"
description = "Compose integration with LiveData"
diff --git a/compose/runtime/runtime-livedata/samples/build.gradle b/compose/runtime/runtime-livedata/samples/build.gradle
index 85f6d25..130994c 100644
--- a/compose/runtime/runtime-livedata/samples/build.gradle
+++ b/compose/runtime/runtime-livedata/samples/build.gradle
@@ -49,7 +49,6 @@
androidx {
name = "AndroidX Compose UI Livedata Interop Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.RUNTIME
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose UI Livedata Interop System"
diff --git a/compose/runtime/runtime-livedata/src/androidTest/java/androidx/compose/runtime/livedata/LiveDataAdapterTest.kt b/compose/runtime/runtime-livedata/src/androidTest/java/androidx/compose/runtime/livedata/LiveDataAdapterTest.kt
index 7038c84..46b3d0c 100644
--- a/compose/runtime/runtime-livedata/src/androidTest/java/androidx/compose/runtime/livedata/LiveDataAdapterTest.kt
+++ b/compose/runtime/runtime-livedata/src/androidTest/java/androidx/compose/runtime/livedata/LiveDataAdapterTest.kt
@@ -20,7 +20,7 @@
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
-import androidx.compose.ui.platform.LifecycleOwnerAmbient
+import androidx.compose.ui.platform.AmbientLifecycleOwner
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
@@ -88,7 +88,7 @@
var realValue: String? = null
val lifecycleOwner = rule.runOnUiThread { RegistryOwner() }
rule.setContent {
- Providers(LifecycleOwnerAmbient provides lifecycleOwner) {
+ Providers(AmbientLifecycleOwner provides lifecycleOwner) {
realValue = liveData.observeAsState().value
}
}
@@ -112,7 +112,7 @@
var emit by mutableStateOf(false)
val lifecycleOwner = rule.runOnUiThread { RegistryOwner() }
rule.setContent {
- Providers(LifecycleOwnerAmbient provides lifecycleOwner) {
+ Providers(AmbientLifecycleOwner provides lifecycleOwner) {
if (emit) {
liveData.observeAsState()
}
@@ -138,7 +138,7 @@
var realValue: String? = null
val lifecycleOwner = rule.runOnUiThread { RegistryOwner() }
rule.setContent {
- Providers(LifecycleOwnerAmbient provides lifecycleOwner) {
+ Providers(AmbientLifecycleOwner provides lifecycleOwner) {
realValue = liveData.observeAsState().value
}
}
@@ -176,7 +176,7 @@
}
}
rule.setContent {
- Providers(LifecycleOwnerAmbient provides lifecycleOwner) {
+ Providers(AmbientLifecycleOwner provides lifecycleOwner) {
realValue = liveData.observeAsState(null).value
}
}
@@ -195,7 +195,7 @@
}
}
rule.setContent {
- Providers(LifecycleOwnerAmbient provides lifecycleOwner) {
+ Providers(AmbientLifecycleOwner provides lifecycleOwner) {
realValue = liveData.observeAsState().value!!
}
}
diff --git a/compose/runtime/runtime-livedata/src/main/java/androidx/compose/runtime/livedata/LiveDataAdapter.kt b/compose/runtime/runtime-livedata/src/main/java/androidx/compose/runtime/livedata/LiveDataAdapter.kt
index 363eaa4..a677079 100644
--- a/compose/runtime/runtime-livedata/src/main/java/androidx/compose/runtime/livedata/LiveDataAdapter.kt
+++ b/compose/runtime/runtime-livedata/src/main/java/androidx/compose/runtime/livedata/LiveDataAdapter.kt
@@ -21,7 +21,7 @@
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.onCommit
import androidx.compose.runtime.remember
-import androidx.compose.ui.platform.LifecycleOwnerAmbient
+import androidx.compose.ui.platform.AmbientLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
@@ -53,7 +53,7 @@
*/
@Composable
fun <R, T : R> LiveData<T>.observeAsState(initial: R): State<R> {
- val lifecycleOwner = LifecycleOwnerAmbient.current
+ val lifecycleOwner = AmbientLifecycleOwner.current
val state = remember { mutableStateOf(initial) }
onCommit(this, lifecycleOwner) {
val observer = Observer<T> { state.value = it }
diff --git a/compose/runtime/runtime-rxjava2/build.gradle b/compose/runtime/runtime-rxjava2/build.gradle
index 52e59fe..9177fab 100644
--- a/compose/runtime/runtime-rxjava2/build.gradle
+++ b/compose/runtime/runtime-rxjava2/build.gradle
@@ -45,7 +45,6 @@
androidx {
name = "Compose RxJava 2 integration"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.RUNTIME
inceptionYear = "2020"
description = "Compose integration with RxJava 2"
diff --git a/compose/runtime/runtime-rxjava2/samples/build.gradle b/compose/runtime/runtime-rxjava2/samples/build.gradle
index d7bc0b9..8c30da7 100644
--- a/compose/runtime/runtime-rxjava2/samples/build.gradle
+++ b/compose/runtime/runtime-rxjava2/samples/build.gradle
@@ -49,7 +49,6 @@
androidx {
name = "AndroidX Compose RxJava 2 Integration Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.RUNTIME
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose RxJava 2 Integration System"
diff --git a/compose/runtime/runtime-rxjava3/build.gradle b/compose/runtime/runtime-rxjava3/build.gradle
index a5ad563..bac7e5f 100644
--- a/compose/runtime/runtime-rxjava3/build.gradle
+++ b/compose/runtime/runtime-rxjava3/build.gradle
@@ -45,7 +45,6 @@
androidx {
name = "Compose RxJava 3 integration"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.RUNTIME
inceptionYear = "2020"
description = "Compose integration with RxJava 3"
diff --git a/compose/runtime/runtime-rxjava3/samples/build.gradle b/compose/runtime/runtime-rxjava3/samples/build.gradle
index a0830ba..ac887e3 100644
--- a/compose/runtime/runtime-rxjava3/samples/build.gradle
+++ b/compose/runtime/runtime-rxjava3/samples/build.gradle
@@ -49,7 +49,6 @@
androidx {
name = "AndroidX Compose RxJava 3 Integration Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.RUNTIME
inceptionYear = "2020"
description = "Contains the sample code for the Androidx Compose RxJava 3 Integration System"
diff --git a/compose/runtime/runtime-saved-instance-state/api/current.txt b/compose/runtime/runtime-saved-instance-state/api/current.txt
index 0d0f37c..5143fdf 100644
--- a/compose/runtime/runtime-saved-instance-state/api/current.txt
+++ b/compose/runtime/runtime-saved-instance-state/api/current.txt
@@ -53,7 +53,8 @@
public final class UiSavedStateRegistryKt {
method public static androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry UiSavedStateRegistry(java.util.Map<java.lang.String,? extends java.util.List<?>>? restoredValues, kotlin.jvm.functions.Function1<java.lang.Object,java.lang.Boolean> canBeSaved);
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry> getUiSavedStateRegistryAmbient();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry> getAmbientUiSavedStateRegistry();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry>! getUiSavedStateRegistryAmbient();
}
}
diff --git a/compose/runtime/runtime-saved-instance-state/api/public_plus_experimental_current.txt b/compose/runtime/runtime-saved-instance-state/api/public_plus_experimental_current.txt
index 0d0f37c..5143fdf 100644
--- a/compose/runtime/runtime-saved-instance-state/api/public_plus_experimental_current.txt
+++ b/compose/runtime/runtime-saved-instance-state/api/public_plus_experimental_current.txt
@@ -53,7 +53,8 @@
public final class UiSavedStateRegistryKt {
method public static androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry UiSavedStateRegistry(java.util.Map<java.lang.String,? extends java.util.List<?>>? restoredValues, kotlin.jvm.functions.Function1<java.lang.Object,java.lang.Boolean> canBeSaved);
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry> getUiSavedStateRegistryAmbient();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry> getAmbientUiSavedStateRegistry();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry>! getUiSavedStateRegistryAmbient();
}
}
diff --git a/compose/runtime/runtime-saved-instance-state/api/restricted_current.txt b/compose/runtime/runtime-saved-instance-state/api/restricted_current.txt
index 0d0f37c..5143fdf 100644
--- a/compose/runtime/runtime-saved-instance-state/api/restricted_current.txt
+++ b/compose/runtime/runtime-saved-instance-state/api/restricted_current.txt
@@ -53,7 +53,8 @@
public final class UiSavedStateRegistryKt {
method public static androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry UiSavedStateRegistry(java.util.Map<java.lang.String,? extends java.util.List<?>>? restoredValues, kotlin.jvm.functions.Function1<java.lang.Object,java.lang.Boolean> canBeSaved);
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry> getUiSavedStateRegistryAmbient();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry> getAmbientUiSavedStateRegistry();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry>! getUiSavedStateRegistryAmbient();
}
}
diff --git a/compose/runtime/runtime-saved-instance-state/build.gradle b/compose/runtime/runtime-saved-instance-state/build.gradle
index 8c3f134..e40d6f8 100644
--- a/compose/runtime/runtime-saved-instance-state/build.gradle
+++ b/compose/runtime/runtime-saved-instance-state/build.gradle
@@ -117,7 +117,6 @@
androidx {
name = "Compose Saved Instance State support"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.RUNTIME
inceptionYear = "2020"
description = "Compose components that allow saving and restoring the local ui state"
diff --git a/compose/runtime/runtime-saved-instance-state/samples/build.gradle b/compose/runtime/runtime-saved-instance-state/samples/build.gradle
index 128f61b..85e0e6a 100644
--- a/compose/runtime/runtime-saved-instance-state/samples/build.gradle
+++ b/compose/runtime/runtime-saved-instance-state/samples/build.gradle
@@ -52,7 +52,6 @@
androidx {
name = "AndroidX Compose Saved Instance State System Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.RUNTIME
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose Saved Instance State System"
diff --git a/compose/runtime/runtime-saved-instance-state/src/androidAndroidTest/kotlin/androidx/compose/runtime/savedinstancestate/RememberSavedInstanceStateTest.kt b/compose/runtime/runtime-saved-instance-state/src/androidAndroidTest/kotlin/androidx/compose/runtime/savedinstancestate/RememberSavedInstanceStateTest.kt
index daef5d3..18e6da8 100644
--- a/compose/runtime/runtime-saved-instance-state/src/androidAndroidTest/kotlin/androidx/compose/runtime/savedinstancestate/RememberSavedInstanceStateTest.kt
+++ b/compose/runtime/runtime-saved-instance-state/src/androidAndroidTest/kotlin/androidx/compose/runtime/savedinstancestate/RememberSavedInstanceStateTest.kt
@@ -356,7 +356,7 @@
children: @Composable () -> Unit
) {
Providers(
- UiSavedStateRegistryAmbient provides wrap(UiSavedStateRegistryAmbient.current!!),
+ AmbientUiSavedStateRegistry provides wrap(AmbientUiSavedStateRegistry.current!!),
children = children
)
}
diff --git a/compose/runtime/runtime-saved-instance-state/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/RememberSavedInstanceState.kt b/compose/runtime/runtime-saved-instance-state/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/RememberSavedInstanceState.kt
index 776752d..2d4025f 100644
--- a/compose/runtime/runtime-saved-instance-state/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/RememberSavedInstanceState.kt
+++ b/compose/runtime/runtime-saved-instance-state/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/RememberSavedInstanceState.kt
@@ -68,7 +68,7 @@
@Suppress("UNCHECKED_CAST")
(saver as Saver<T, Any>)
- val registry = UiSavedStateRegistryAmbient.current
+ val registry = AmbientUiSavedStateRegistry.current
// value is restored using the registry or created via [init] lambda
val value = remember(*inputs) {
// TODO not restore when the input values changed (use hashKeys?) b/152014032
diff --git a/compose/runtime/runtime-saved-instance-state/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/RestorableStateHolder.kt b/compose/runtime/runtime-saved-instance-state/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/RestorableStateHolder.kt
index 098d3a4..d8b10a9 100644
--- a/compose/runtime/runtime-saved-instance-state/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/RestorableStateHolder.kt
+++ b/compose/runtime/runtime-saved-instance-state/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/RestorableStateHolder.kt
@@ -78,7 +78,7 @@
) {
RestorableStateHolderImpl<T>()
}.apply {
- parentSavedStateRegistry = UiSavedStateRegistryAmbient.current
+ parentSavedStateRegistry = AmbientUiSavedStateRegistry.current
}
@ExperimentalRestorableStateHolder
@@ -100,7 +100,7 @@
RegistryHolder(key)
}
Providers(
- UiSavedStateRegistryAmbient provides registryHolder.registry,
+ AmbientUiSavedStateRegistry provides registryHolder.registry,
children = content
)
onActive {
diff --git a/compose/runtime/runtime-saved-instance-state/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/UiSavedStateRegistry.kt b/compose/runtime/runtime-saved-instance-state/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/UiSavedStateRegistry.kt
index 4dc2bcc..b27176a 100644
--- a/compose/runtime/runtime-saved-instance-state/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/UiSavedStateRegistry.kt
+++ b/compose/runtime/runtime-saved-instance-state/src/commonMain/kotlin/androidx/compose/runtime/savedinstancestate/UiSavedStateRegistry.kt
@@ -84,7 +84,20 @@
/**
* Ambient with a current [UiSavedStateRegistry] instance.
*/
-val UiSavedStateRegistryAmbient = staticAmbientOf<UiSavedStateRegistry?> { null }
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientUiSavedStateRegistry",
+ replaceWith = ReplaceWith(
+ "AmbientUiSavedStateRegistry",
+ "androidx.compose.runtime.savedinstancestate.AmbientUiSavedStateRegistry"
+ )
+)
+val UiSavedStateRegistryAmbient get() = AmbientUiSavedStateRegistry
+
+/**
+ * Ambient with a current [UiSavedStateRegistry] instance.
+ */
+val AmbientUiSavedStateRegistry = staticAmbientOf<UiSavedStateRegistry?> { null }
private class UiSavedStateRegistryImpl(
restored: Map<String, List<Any?>>?,
diff --git a/compose/runtime/runtime/build.gradle b/compose/runtime/runtime/build.gradle
index da55ede..57fdeed 100644
--- a/compose/runtime/runtime/build.gradle
+++ b/compose/runtime/runtime/build.gradle
@@ -128,7 +128,6 @@
androidx {
name = "Compose Runtime"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.RUNTIME
inceptionYear = "2019"
description = "Tree composition support for code generated by the Compose compiler plugin and corresponding public API"
diff --git a/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/BaseComposeTest.kt b/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/BaseComposeTest.kt
index a9b066f..0f74688 100644
--- a/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/BaseComposeTest.kt
+++ b/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/BaseComposeTest.kt
@@ -26,7 +26,7 @@
import androidx.compose.runtime.snapshots.Snapshot
import androidx.compose.ui.node.ExperimentalLayoutNodeApi
import androidx.compose.ui.node.LayoutNode
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.platform.setViewContent
import androidx.compose.ui.platform.subcomposeInto
import java.util.concurrent.CountDownLatch
@@ -149,7 +149,7 @@
private fun initialComposition(composable: @Composable () -> Unit): Composition {
return activity.show {
Providers(
- ContextAmbient provides activity
+ AmbientContext provides activity
) {
composable()
}
diff --git a/compose/runtime/runtime/samples/build.gradle b/compose/runtime/runtime/samples/build.gradle
index 62d8887..a34f145 100644
--- a/compose/runtime/runtime/samples/build.gradle
+++ b/compose/runtime/runtime/samples/build.gradle
@@ -43,7 +43,6 @@
androidx {
name = "AndroidX Compose Runtime Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.RUNTIME
inceptionYear = "2019"
description = "Contains the sample code for the Compose runtime"
diff --git a/compose/ui/ui-android-stubs/build.gradle b/compose/ui/ui-android-stubs/build.gradle
index ccf006b..fee733e 100644
--- a/compose/ui/ui-android-stubs/build.gradle
+++ b/compose/ui/ui-android-stubs/build.gradle
@@ -39,7 +39,6 @@
androidx {
name = "Compose Android Stubs"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2020"
description = "Stubs for classes in older Android APIs"
diff --git a/compose/ui/ui-geometry/build.gradle b/compose/ui/ui-geometry/build.gradle
index 7b9b41e..3b961bc 100644
--- a/compose/ui/ui-geometry/build.gradle
+++ b/compose/ui/ui-geometry/build.gradle
@@ -83,7 +83,6 @@
androidx {
name = "Compose Geometry"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2020"
description = "Compose classes related to dimensions without units"
diff --git a/compose/ui/ui-graphics/build.gradle b/compose/ui/ui-graphics/build.gradle
index dbb130a..42642e2 100644
--- a/compose/ui/ui-graphics/build.gradle
+++ b/compose/ui/ui-graphics/build.gradle
@@ -119,7 +119,6 @@
androidx {
name = "Compose Graphics"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2020"
description = "Compose graphics"
diff --git a/compose/ui/ui-graphics/samples/build.gradle b/compose/ui/ui-graphics/samples/build.gradle
index 2f13870..21223a5 100644
--- a/compose/ui/ui-graphics/samples/build.gradle
+++ b/compose/ui/ui-graphics/samples/build.gradle
@@ -53,7 +53,6 @@
androidx {
name = "AndroidX Compose UI Graphics Components Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose UI Graphics Components"
diff --git a/compose/ui/ui-test-font/build.gradle b/compose/ui/ui-test-font/build.gradle
index 4a7f12b..16d1675 100644
--- a/compose/ui/ui-test-font/build.gradle
+++ b/compose/ui/ui-test-font/build.gradle
@@ -28,7 +28,6 @@
androidx {
name = "Compose Test Font resources"
publish = Publish.NONE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2020"
description = "Fonts designed for testing text capabilities"
diff --git a/compose/ui/ui-test-junit4/api/current.txt b/compose/ui/ui-test-junit4/api/current.txt
index 4b512926..cc099459 100644
--- a/compose/ui/ui-test-junit4/api/current.txt
+++ b/compose/ui/ui-test-junit4/api/current.txt
@@ -2,7 +2,7 @@
package androidx.compose.ui.test.junit4 {
public final class AndroidAnimationClockTestRuleKt {
- method public static androidx.compose.ui.test.junit4.AnimationClockTestRule createAnimationClockRule();
+ method @androidx.compose.ui.test.ExperimentalTesting public static androidx.compose.ui.test.junit4.AnimationClockTestRule createAnimationClockRule();
}
public final class AndroidComposeTestRule<R extends org.junit.rules.TestRule, A extends androidx.activity.ComponentActivity> implements androidx.compose.ui.test.junit4.ComposeTestRule {
@@ -39,14 +39,14 @@
public final class AndroidSynchronizationKt {
}
- public interface AnimationClockTestRule extends org.junit.rules.TestRule {
+ @androidx.compose.ui.test.ExperimentalTesting public interface AnimationClockTestRule extends org.junit.rules.TestRule {
method public default void advanceClock(long milliseconds);
method public androidx.compose.ui.test.TestAnimationClock getClock();
- method public boolean isPaused();
- method public void pauseClock();
+ method public default boolean isPaused();
+ method public default void pauseClock();
method public default void resumeClock();
property public abstract androidx.compose.ui.test.TestAnimationClock clock;
- property public abstract boolean isPaused;
+ property public default boolean isPaused;
}
public interface ComposeTestRule extends org.junit.rules.TestRule androidx.compose.ui.test.SemanticsNodeInteractionsProvider {
@@ -84,9 +84,9 @@
public final class ComposeIdlingResourceKt {
method public static void registerComposeWithEspresso();
- method public static void registerTestClock(androidx.compose.ui.test.TestAnimationClock clock);
+ method @androidx.compose.ui.test.ExperimentalTesting public static void registerTestClock(androidx.compose.ui.test.TestAnimationClock clock);
method public static void unregisterComposeFromEspresso();
- method public static void unregisterTestClock(androidx.compose.ui.test.TestAnimationClock clock);
+ method @androidx.compose.ui.test.ExperimentalTesting public static void unregisterTestClock(androidx.compose.ui.test.TestAnimationClock clock);
}
public final class ComposeNotIdleException extends java.lang.Throwable {
diff --git a/compose/ui/ui-test-junit4/api/public_plus_experimental_current.txt b/compose/ui/ui-test-junit4/api/public_plus_experimental_current.txt
index 4b512926..cc099459 100644
--- a/compose/ui/ui-test-junit4/api/public_plus_experimental_current.txt
+++ b/compose/ui/ui-test-junit4/api/public_plus_experimental_current.txt
@@ -2,7 +2,7 @@
package androidx.compose.ui.test.junit4 {
public final class AndroidAnimationClockTestRuleKt {
- method public static androidx.compose.ui.test.junit4.AnimationClockTestRule createAnimationClockRule();
+ method @androidx.compose.ui.test.ExperimentalTesting public static androidx.compose.ui.test.junit4.AnimationClockTestRule createAnimationClockRule();
}
public final class AndroidComposeTestRule<R extends org.junit.rules.TestRule, A extends androidx.activity.ComponentActivity> implements androidx.compose.ui.test.junit4.ComposeTestRule {
@@ -39,14 +39,14 @@
public final class AndroidSynchronizationKt {
}
- public interface AnimationClockTestRule extends org.junit.rules.TestRule {
+ @androidx.compose.ui.test.ExperimentalTesting public interface AnimationClockTestRule extends org.junit.rules.TestRule {
method public default void advanceClock(long milliseconds);
method public androidx.compose.ui.test.TestAnimationClock getClock();
- method public boolean isPaused();
- method public void pauseClock();
+ method public default boolean isPaused();
+ method public default void pauseClock();
method public default void resumeClock();
property public abstract androidx.compose.ui.test.TestAnimationClock clock;
- property public abstract boolean isPaused;
+ property public default boolean isPaused;
}
public interface ComposeTestRule extends org.junit.rules.TestRule androidx.compose.ui.test.SemanticsNodeInteractionsProvider {
@@ -84,9 +84,9 @@
public final class ComposeIdlingResourceKt {
method public static void registerComposeWithEspresso();
- method public static void registerTestClock(androidx.compose.ui.test.TestAnimationClock clock);
+ method @androidx.compose.ui.test.ExperimentalTesting public static void registerTestClock(androidx.compose.ui.test.TestAnimationClock clock);
method public static void unregisterComposeFromEspresso();
- method public static void unregisterTestClock(androidx.compose.ui.test.TestAnimationClock clock);
+ method @androidx.compose.ui.test.ExperimentalTesting public static void unregisterTestClock(androidx.compose.ui.test.TestAnimationClock clock);
}
public final class ComposeNotIdleException extends java.lang.Throwable {
diff --git a/compose/ui/ui-test-junit4/api/restricted_current.txt b/compose/ui/ui-test-junit4/api/restricted_current.txt
index 4b512926..cc099459 100644
--- a/compose/ui/ui-test-junit4/api/restricted_current.txt
+++ b/compose/ui/ui-test-junit4/api/restricted_current.txt
@@ -2,7 +2,7 @@
package androidx.compose.ui.test.junit4 {
public final class AndroidAnimationClockTestRuleKt {
- method public static androidx.compose.ui.test.junit4.AnimationClockTestRule createAnimationClockRule();
+ method @androidx.compose.ui.test.ExperimentalTesting public static androidx.compose.ui.test.junit4.AnimationClockTestRule createAnimationClockRule();
}
public final class AndroidComposeTestRule<R extends org.junit.rules.TestRule, A extends androidx.activity.ComponentActivity> implements androidx.compose.ui.test.junit4.ComposeTestRule {
@@ -39,14 +39,14 @@
public final class AndroidSynchronizationKt {
}
- public interface AnimationClockTestRule extends org.junit.rules.TestRule {
+ @androidx.compose.ui.test.ExperimentalTesting public interface AnimationClockTestRule extends org.junit.rules.TestRule {
method public default void advanceClock(long milliseconds);
method public androidx.compose.ui.test.TestAnimationClock getClock();
- method public boolean isPaused();
- method public void pauseClock();
+ method public default boolean isPaused();
+ method public default void pauseClock();
method public default void resumeClock();
property public abstract androidx.compose.ui.test.TestAnimationClock clock;
- property public abstract boolean isPaused;
+ property public default boolean isPaused;
}
public interface ComposeTestRule extends org.junit.rules.TestRule androidx.compose.ui.test.SemanticsNodeInteractionsProvider {
@@ -84,9 +84,9 @@
public final class ComposeIdlingResourceKt {
method public static void registerComposeWithEspresso();
- method public static void registerTestClock(androidx.compose.ui.test.TestAnimationClock clock);
+ method @androidx.compose.ui.test.ExperimentalTesting public static void registerTestClock(androidx.compose.ui.test.TestAnimationClock clock);
method public static void unregisterComposeFromEspresso();
- method public static void unregisterTestClock(androidx.compose.ui.test.TestAnimationClock clock);
+ method @androidx.compose.ui.test.ExperimentalTesting public static void unregisterTestClock(androidx.compose.ui.test.TestAnimationClock clock);
}
public final class ComposeNotIdleException extends java.lang.Throwable {
diff --git a/compose/ui/ui-test-junit4/build.gradle b/compose/ui/ui-test-junit4/build.gradle
index 64f4f6d..3c79cab 100644
--- a/compose/ui/ui-test-junit4/build.gradle
+++ b/compose/ui/ui-test-junit4/build.gradle
@@ -132,7 +132,6 @@
androidx {
name = "Compose Testing for JUnit4"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2020"
description = "Compose testing integration with JUnit4"
diff --git a/compose/ui/ui-test-junit4/src/androidAndroidTest/kotlin/androidx/compose/ui/test/junit4/TestAnimationClockTest.kt b/compose/ui/ui-test-junit4/src/androidAndroidTest/kotlin/androidx/compose/ui/test/junit4/TestAnimationClockTest.kt
index 0acb995..f3ff936 100644
--- a/compose/ui/ui-test-junit4/src/androidAndroidTest/kotlin/androidx/compose/ui/test/junit4/TestAnimationClockTest.kt
+++ b/compose/ui/ui-test-junit4/src/androidAndroidTest/kotlin/androidx/compose/ui/test/junit4/TestAnimationClockTest.kt
@@ -38,6 +38,7 @@
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.junit4.android.ComposeIdlingResource
import androidx.test.espresso.Espresso.onIdle
import androidx.test.filters.LargeTest
@@ -48,6 +49,7 @@
import org.junit.Test
@LargeTest
+@OptIn(ExperimentalTesting::class)
class TestAnimationClockTest {
companion object {
diff --git a/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/AndroidAnimationClockTestRule.kt b/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/AndroidAnimationClockTestRule.kt
index acae937..0f7da5e 100644
--- a/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/AndroidAnimationClockTestRule.kt
+++ b/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/AndroidAnimationClockTestRule.kt
@@ -18,6 +18,7 @@
import androidx.compose.animation.core.InternalAnimationApi
import androidx.compose.animation.core.rootAnimationClockFactory
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.TestAnimationClock
import androidx.test.espresso.IdlingResource
import androidx.compose.ui.test.junit4.android.registerTestClock
@@ -42,6 +43,7 @@
* animations. Otherwise, built in steps that make sure the UI is stable when performing actions
* or assertions will fail to work.
*/
+@ExperimentalTesting
internal class AndroidAnimationClockTestRule : AnimationClockTestRule {
/** Backing property for [clock] */
@@ -55,26 +57,6 @@
*/
override val clock: TestAnimationClock get() = _clock
- /**
- * Convenience property for calling [`clock.isPaused`][TestAnimationClock.isPaused]
- */
- override val isPaused: Boolean get() = clock.isPaused
-
- /**
- * Convenience method for calling [`clock.pauseClock()`][TestAnimationClock.pauseClock]
- */
- override fun pauseClock() = clock.pauseClock()
-
- /**
- * Convenience method for calling [`clock.resumeClock()`][TestAnimationClock.resumeClock]
- */
- override fun resumeClock() = clock.resumeClock()
-
- /**
- * Convenience method for calling [`clock.advanceClock()`][TestAnimationClock.advanceClock]
- */
- override fun advanceClock(milliseconds: Long) = clock.advanceClock(milliseconds)
-
override fun apply(base: Statement, description: Description?): Statement {
return AnimationClockStatement(base)
}
@@ -99,5 +81,6 @@
}
}
+@ExperimentalTesting
actual fun createAnimationClockRule(): AnimationClockTestRule =
AndroidAnimationClockTestRule()
diff --git a/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/AndroidComposeTestRule.kt b/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/AndroidComposeTestRule.kt
index 543c2c3..538fafe 100644
--- a/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/AndroidComposeTestRule.kt
+++ b/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/AndroidComposeTestRule.kt
@@ -115,6 +115,7 @@
private val activityProvider: (R) -> A
) : ComposeTestRule {
+ @ExperimentalTesting
override val clockTestRule: AnimationClockTestRule = AndroidAnimationClockTestRule()
internal var disposeContentHook: (() -> Unit)? = null
@@ -144,7 +145,7 @@
override fun apply(base: Statement, description: Description?): Statement {
@Suppress("NAME_SHADOWING")
- @OptIn(InternalTestingApi::class)
+ @OptIn(InternalTestingApi::class, ExperimentalTesting::class)
return RuleChain
.outerRule(clockTestRule)
.around { base, _ -> AndroidComposeStatement(base) }
diff --git a/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester.kt b/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester.kt
index 3f921b8..095e934 100644
--- a/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester.kt
+++ b/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester.kt
@@ -21,9 +21,9 @@
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
+import androidx.compose.runtime.savedinstancestate.AmbientUiSavedStateRegistry
import androidx.compose.runtime.setValue
import androidx.compose.runtime.savedinstancestate.UiSavedStateRegistry
-import androidx.compose.runtime.savedinstancestate.UiSavedStateRegistryAmbient
/**
* Helps to test the state restoration for your Composable component.
@@ -78,12 +78,12 @@
@Composable
private fun InjectRestorationRegistry(children: @Composable (RestorationRegistry) -> Unit) {
- val original = requireNotNull(UiSavedStateRegistryAmbient.current) {
+ val original = requireNotNull(AmbientUiSavedStateRegistry.current) {
"StateRestorationTester requires composeTestRule.setContent() to provide " +
"an UiSavedStateRegistry implementation via UiSavedStateRegistryAmbient"
}
val restorationRegistry = remember { RestorationRegistry(original) }
- Providers(UiSavedStateRegistryAmbient provides restorationRegistry) {
+ Providers(AmbientUiSavedStateRegistry provides restorationRegistry) {
if (restorationRegistry.shouldEmitChildren) {
children(restorationRegistry)
}
diff --git a/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/android/AndroidTestAnimationClock.kt b/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/android/AndroidTestAnimationClock.kt
index 27a4c4a..be6439b 100644
--- a/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/android/AndroidTestAnimationClock.kt
+++ b/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/android/AndroidTestAnimationClock.kt
@@ -19,6 +19,7 @@
import android.view.Choreographer
import androidx.compose.animation.core.AnimationClockObserver
import androidx.compose.animation.core.ManualAnimationClock
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.TestAnimationClock
import androidx.compose.ui.test.junit4.runOnUiThread
@@ -35,6 +36,7 @@
* @see advanceClock
* @see resumeClock
*/
+@ExperimentalTesting
internal class AndroidTestAnimationClock : TestAnimationClock {
/**
diff --git a/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/android/ComposeIdlingResource.kt b/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/android/ComposeIdlingResource.kt
index 63e15a5..d792d7c 100644
--- a/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/android/ComposeIdlingResource.kt
+++ b/compose/ui/ui-test-junit4/src/androidMain/kotlin/androidx/compose/ui/test/junit4/android/ComposeIdlingResource.kt
@@ -21,6 +21,7 @@
import androidx.compose.runtime.ExperimentalComposeApi
import androidx.compose.runtime.Recomposer
import androidx.compose.runtime.snapshots.Snapshot
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.IdlingResource
import androidx.compose.ui.test.TestAnimationClock
@@ -61,6 +62,7 @@
/**
* Registers the given [clock] so Espresso can await the animations subscribed to that clock.
*/
+@ExperimentalTesting
fun registerTestClock(clock: TestAnimationClock) {
ComposeIdlingResource.registerTestClock(clock)
}
@@ -68,6 +70,7 @@
/**
* Unregisters the [clock] that was registered with [registerTestClock].
*/
+@ExperimentalTesting
fun unregisterTestClock(clock: TestAnimationClock) {
ComposeIdlingResource.unregisterTestClock(clock)
}
@@ -86,6 +89,7 @@
private var isIdleCheckScheduled = false
+ @OptIn(ExperimentalTesting::class)
private val clocks = mutableSetOf<TestAnimationClock>()
private val handler = Handler(Looper.getMainLooper())
@@ -163,18 +167,21 @@
compositionAwaiters.decrementAndGet()
}
+ @OptIn(ExperimentalTesting::class)
internal fun registerTestClock(clock: TestAnimationClock) {
synchronized(clocks) {
clocks.add(clock)
}
}
+ @OptIn(ExperimentalTesting::class)
internal fun unregisterTestClock(clock: TestAnimationClock) {
synchronized(clocks) {
clocks.remove(clock)
}
}
+ @OptIn(ExperimentalTesting::class)
private fun areAllClocksIdle(): Boolean {
return synchronized(clocks) {
clocks.all { it.isIdle }
diff --git a/compose/ui/ui-test-junit4/src/desktopMain/kotlin/androidx/compose/ui/test/junit4/DesktopAnimationClockTestRule.kt b/compose/ui/ui-test-junit4/src/desktopMain/kotlin/androidx/compose/ui/test/junit4/DesktopAnimationClockTestRule.kt
index f6b6814..bacfaf2 100644
--- a/compose/ui/ui-test-junit4/src/desktopMain/kotlin/androidx/compose/ui/test/junit4/DesktopAnimationClockTestRule.kt
+++ b/compose/ui/ui-test-junit4/src/desktopMain/kotlin/androidx/compose/ui/test/junit4/DesktopAnimationClockTestRule.kt
@@ -18,10 +18,12 @@
import androidx.compose.animation.core.AnimationClockObserver
import androidx.compose.animation.core.InternalAnimationApi
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.TestAnimationClock
import org.junit.runner.Description
import org.junit.runners.model.Statement
+@ExperimentalTesting
internal class DesktopTestAnimationClock : TestAnimationClock {
override val isIdle: Boolean
get() = TODO("Not yet implemented")
@@ -50,6 +52,7 @@
}
}
+@ExperimentalTesting
internal class DesktopAnimationClockTestRule : AnimationClockTestRule {
override val clock: TestAnimationClock get() = DesktopTestAnimationClock()
@@ -86,5 +89,6 @@
}
}
+@ExperimentalTesting
actual fun createAnimationClockRule(): AnimationClockTestRule =
DesktopAnimationClockTestRule()
\ No newline at end of file
diff --git a/compose/ui/ui-test-junit4/src/desktopMain/kotlin/androidx/compose/ui/test/junit4/DesktopComposeTestRule.kt b/compose/ui/ui-test-junit4/src/desktopMain/kotlin/androidx/compose/ui/test/junit4/DesktopComposeTestRule.kt
index 7cb3269..73cdc85 100644
--- a/compose/ui/ui-test-junit4/src/desktopMain/kotlin/androidx/compose/ui/test/junit4/DesktopComposeTestRule.kt
+++ b/compose/ui/ui-test-junit4/src/desktopMain/kotlin/androidx/compose/ui/test/junit4/DesktopComposeTestRule.kt
@@ -62,6 +62,7 @@
var owners: DesktopOwners? = null
private var owner: DesktopOwner? = null
+ @ExperimentalTesting
override val clockTestRule: AnimationClockTestRule = DesktopAnimationClockTestRule()
override val density: Density
diff --git a/compose/ui/ui-test-junit4/src/jvmMain/kotlin/androidx/compose/ui/test/junit4/AnimationClockTestRule.kt b/compose/ui/ui-test-junit4/src/jvmMain/kotlin/androidx/compose/ui/test/junit4/AnimationClockTestRule.kt
index 1732d00..08c2c7c 100644
--- a/compose/ui/ui-test-junit4/src/jvmMain/kotlin/androidx/compose/ui/test/junit4/AnimationClockTestRule.kt
+++ b/compose/ui/ui-test-junit4/src/jvmMain/kotlin/androidx/compose/ui/test/junit4/AnimationClockTestRule.kt
@@ -16,9 +16,11 @@
package androidx.compose.ui.test.junit4
+import androidx.compose.ui.test.ExperimentalTesting
import androidx.compose.ui.test.TestAnimationClock
import org.junit.rules.TestRule
+@ExperimentalTesting
interface AnimationClockTestRule : TestRule {
/**
* The ambient animation clock that is provided at the root of the composition tree.
@@ -28,12 +30,12 @@
/**
* Convenience property for calling [`clock.isPaused`][TestAnimationClock.isPaused]
*/
- val isPaused: Boolean
+ val isPaused: Boolean get() = clock.isPaused
/**
* Convenience method for calling [`clock.pauseClock()`][TestAnimationClock.pauseClock]
*/
- fun pauseClock()
+ fun pauseClock() = clock.pauseClock()
/**
* Convenience method for calling [`clock.resumeClock()`][TestAnimationClock.resumeClock]
@@ -46,4 +48,5 @@
fun advanceClock(milliseconds: Long) = clock.advanceClock(milliseconds)
}
+@ExperimentalTesting
expect fun createAnimationClockRule(): AnimationClockTestRule
\ No newline at end of file
diff --git a/compose/ui/ui-test-junit4/src/jvmMain/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule.kt b/compose/ui/ui-test-junit4/src/jvmMain/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule.kt
index de8b3aa..9fb0445 100644
--- a/compose/ui/ui-test-junit4/src/jvmMain/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule.kt
+++ b/compose/ui/ui-test-junit4/src/jvmMain/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule.kt
@@ -45,6 +45,7 @@
/**
* A test rule that allows you to control the animation clock
*/
+ @OptIn(ExperimentalTesting::class)
val clockTestRule: AnimationClockTestRule
/**
diff --git a/compose/ui/ui-test/api/current.txt b/compose/ui/ui-test/api/current.txt
index 6fa8241..8144343 100644
--- a/compose/ui/ui-test/api/current.txt
+++ b/compose/ui/ui-test/api/current.txt
@@ -264,7 +264,7 @@
public final class SemanticsSelectorKt {
}
- public interface TestAnimationClock extends androidx.compose.animation.core.AnimationClockObservable {
+ @androidx.compose.ui.test.ExperimentalTesting public interface TestAnimationClock extends androidx.compose.animation.core.AnimationClockObservable {
method public void advanceClock(long milliseconds);
method public boolean isIdle();
method public boolean isPaused();
diff --git a/compose/ui/ui-test/api/public_plus_experimental_current.txt b/compose/ui/ui-test/api/public_plus_experimental_current.txt
index 6fa8241..8144343 100644
--- a/compose/ui/ui-test/api/public_plus_experimental_current.txt
+++ b/compose/ui/ui-test/api/public_plus_experimental_current.txt
@@ -264,7 +264,7 @@
public final class SemanticsSelectorKt {
}
- public interface TestAnimationClock extends androidx.compose.animation.core.AnimationClockObservable {
+ @androidx.compose.ui.test.ExperimentalTesting public interface TestAnimationClock extends androidx.compose.animation.core.AnimationClockObservable {
method public void advanceClock(long milliseconds);
method public boolean isIdle();
method public boolean isPaused();
diff --git a/compose/ui/ui-test/api/restricted_current.txt b/compose/ui/ui-test/api/restricted_current.txt
index 6fa8241..8144343 100644
--- a/compose/ui/ui-test/api/restricted_current.txt
+++ b/compose/ui/ui-test/api/restricted_current.txt
@@ -264,7 +264,7 @@
public final class SemanticsSelectorKt {
}
- public interface TestAnimationClock extends androidx.compose.animation.core.AnimationClockObservable {
+ @androidx.compose.ui.test.ExperimentalTesting public interface TestAnimationClock extends androidx.compose.animation.core.AnimationClockObservable {
method public void advanceClock(long milliseconds);
method public boolean isIdle();
method public boolean isPaused();
diff --git a/compose/ui/ui-test/build.gradle b/compose/ui/ui-test/build.gradle
index 6deb865..7a19f17 100644
--- a/compose/ui/ui-test/build.gradle
+++ b/compose/ui/ui-test/build.gradle
@@ -137,7 +137,6 @@
androidx {
name = "Compose Testing"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2019"
description = "Compose testing library"
diff --git a/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/LayoutCoordinatesHelperTest.kt b/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/LayoutCoordinatesHelperTest.kt
index 9242b2f..5385d5a 100644
--- a/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/LayoutCoordinatesHelperTest.kt
+++ b/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/LayoutCoordinatesHelperTest.kt
@@ -25,7 +25,7 @@
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.dp
import androidx.test.filters.MediumTest
@@ -81,7 +81,7 @@
var parentCoordinates: LayoutCoordinates? = null
var childCoordinates: LayoutCoordinates? = null
rule.setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
Box(Modifier.preferredWidth(40.toDp()), alignment = Alignment.Center) {
Column(
Modifier.preferredWidth(20.toDp())
diff --git a/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/ScrollToTest.kt b/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/ScrollToTest.kt
index 4c764c1..7919595 100644
--- a/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/ScrollToTest.kt
+++ b/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/ScrollToTest.kt
@@ -23,7 +23,7 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.semantics.scrollBy
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.Constraints
@@ -83,7 +83,7 @@
columnHeight: Int,
children: @Composable () -> Unit
) {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
Layout(
children,
modifier.size(crossAxisSize.toDp(), columnHeight.toDp()),
@@ -99,7 +99,7 @@
rowWidth: Int,
children: @Composable () -> Unit
) {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
Layout(
children,
modifier.size(rowWidth.toDp(), crossAxisSize.toDp()),
diff --git a/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/gesturescope/PositionsTest.kt b/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/gesturescope/PositionsTest.kt
index c519ea7..d9194da 100644
--- a/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/gesturescope/PositionsTest.kt
+++ b/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/gesturescope/PositionsTest.kt
@@ -21,7 +21,7 @@
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.bottom
import androidx.compose.ui.test.bottomCenter
@@ -120,7 +120,7 @@
private fun testPositionsInViewport(isVertical: Boolean, reverseScrollDirection: Boolean) {
rule.setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
if (isVertical) {
ScrollableColumn(
Modifier.size(100.toDp(), 100.toDp()).testTag("viewport"),
diff --git a/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/gesturescope/SendSwipeTest.kt b/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/gesturescope/SendSwipeTest.kt
index 48a8b80..4ed75e3 100644
--- a/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/gesturescope/SendSwipeTest.kt
+++ b/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/gesturescope/SendSwipeTest.kt
@@ -31,7 +31,7 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.gesture.TouchSlop
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.milliseconds
import androidx.test.filters.MediumTest
@@ -175,7 +175,7 @@
}
)
rule.setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
// Scrollable with a viewport the size of 10 boxes
ScrollableColumn(
Modifier.testTag("scrollable").size(100.toDp(), 1000.toDp()),
diff --git a/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/util/ClickableTestBox.kt b/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/util/ClickableTestBox.kt
index 9c8a27b..93c724e 100644
--- a/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/util/ClickableTestBox.kt
+++ b/compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/util/ClickableTestBox.kt
@@ -22,7 +22,7 @@
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.util.ClickableTestBox.defaultColor
import androidx.compose.ui.test.util.ClickableTestBox.defaultSize
@@ -42,7 +42,7 @@
color: Color = defaultColor,
tag: String = defaultTag
) {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
Box(
modifier = modifier.testTag(tag).size(width.toDp(), height.toDp()).background(color)
)
diff --git a/compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/AnimationClocks.kt b/compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/AnimationClocks.kt
index 11ea390..d2b0062 100644
--- a/compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/AnimationClocks.kt
+++ b/compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/AnimationClocks.kt
@@ -32,6 +32,7 @@
* Use [pauseClock] to switch from automatic ticking to manual ticking, [resumeClock] to switch
* from manual to automatic with; and manually tick the clock with [advanceClock].
*/
+@ExperimentalTesting
interface TestAnimationClock : AnimationClockObservable {
/**
* Whether the clock is idle or not. An idle clock is one that is not driving animations,
diff --git a/compose/ui/ui-text/api/current.txt b/compose/ui/ui-text/api/current.txt
index 1a7aa19..3f4dfba 100644
--- a/compose/ui/ui-text/api/current.txt
+++ b/compose/ui/ui-text/api/current.txt
@@ -523,11 +523,6 @@
public abstract sealed class TtsAnnotation {
}
- public interface Typeface {
- method public androidx.compose.ui.text.font.FontFamily getFontFamily();
- property public abstract androidx.compose.ui.text.font.FontFamily fontFamily;
- }
-
public final class VerbatimTtsAnnotation extends androidx.compose.ui.text.TtsAnnotation {
ctor public VerbatimTtsAnnotation(String verbatim);
method public String getVerbatim();
@@ -567,6 +562,12 @@
package androidx.compose.ui.text.font {
+ public final class AndroidTypefaceKt {
+ method public static androidx.compose.ui.text.font.FontFamily fontFamily(android.graphics.Typeface typeface);
+ method public static androidx.compose.ui.text.font.Typeface typeface(android.content.Context context, androidx.compose.ui.text.font.FontFamily fontFamily, optional java.util.List<? extends kotlin.Pair<androidx.compose.ui.text.font.FontWeight,? extends androidx.compose.ui.text.font.FontStyle>>? necessaryStyles);
+ method public static androidx.compose.ui.text.font.Typeface typeface(android.graphics.Typeface typeface);
+ }
+
public abstract sealed class FileBasedFontFamily extends androidx.compose.ui.text.font.FontFamily {
}
@@ -603,7 +604,7 @@
public final class FontFamilyKt {
method @androidx.compose.runtime.Stable public static androidx.compose.ui.text.font.FontListFontFamily fontFamily(java.util.List<? extends androidx.compose.ui.text.font.Font> fonts);
method @androidx.compose.runtime.Stable public static androidx.compose.ui.text.font.FontListFontFamily fontFamily(androidx.compose.ui.text.font.Font... fonts);
- method public static androidx.compose.ui.text.font.LoadedFontFamily fontFamily(androidx.compose.ui.text.Typeface typeface);
+ method public static androidx.compose.ui.text.font.LoadedFontFamily fontFamily(androidx.compose.ui.text.font.Typeface typeface);
}
public final class FontKt {
@@ -701,11 +702,11 @@
}
public final class LoadedFontFamily extends androidx.compose.ui.text.font.FontFamily {
- ctor public LoadedFontFamily(androidx.compose.ui.text.Typeface typeface);
- method public androidx.compose.ui.text.Typeface component1();
- method public androidx.compose.ui.text.font.LoadedFontFamily copy(androidx.compose.ui.text.Typeface typeface);
- method public androidx.compose.ui.text.Typeface getTypeface();
- property public final androidx.compose.ui.text.Typeface typeface;
+ ctor public LoadedFontFamily(androidx.compose.ui.text.font.Typeface typeface);
+ method public androidx.compose.ui.text.font.Typeface component1();
+ method public androidx.compose.ui.text.font.LoadedFontFamily copy(androidx.compose.ui.text.font.Typeface typeface);
+ method public androidx.compose.ui.text.font.Typeface getTypeface();
+ property public final androidx.compose.ui.text.font.Typeface typeface;
}
public final class ResourceFont implements androidx.compose.ui.text.font.Font {
@@ -725,6 +726,11 @@
public abstract sealed class SystemFontFamily extends androidx.compose.ui.text.font.FontFamily {
}
+ public interface Typeface {
+ method public androidx.compose.ui.text.font.FontFamily? getFontFamily();
+ property public abstract androidx.compose.ui.text.font.FontFamily? fontFamily;
+ }
+
}
package androidx.compose.ui.text.input {
@@ -1075,10 +1081,6 @@
public final class AndroidStringDelegateKt {
}
- public final class TypefaceAdapterKt {
- method public static androidx.compose.ui.text.Typeface typefaceFromFontFamily(android.content.Context context, androidx.compose.ui.text.font.FontFamily fontFamily, optional java.util.List<? extends kotlin.Pair<androidx.compose.ui.text.font.FontWeight,? extends androidx.compose.ui.text.font.FontStyle>>? necessaryStyles);
- }
-
}
package androidx.compose.ui.text.platform.extensions {
diff --git a/compose/ui/ui-text/api/public_plus_experimental_current.txt b/compose/ui/ui-text/api/public_plus_experimental_current.txt
index 1a7aa19..3f4dfba 100644
--- a/compose/ui/ui-text/api/public_plus_experimental_current.txt
+++ b/compose/ui/ui-text/api/public_plus_experimental_current.txt
@@ -523,11 +523,6 @@
public abstract sealed class TtsAnnotation {
}
- public interface Typeface {
- method public androidx.compose.ui.text.font.FontFamily getFontFamily();
- property public abstract androidx.compose.ui.text.font.FontFamily fontFamily;
- }
-
public final class VerbatimTtsAnnotation extends androidx.compose.ui.text.TtsAnnotation {
ctor public VerbatimTtsAnnotation(String verbatim);
method public String getVerbatim();
@@ -567,6 +562,12 @@
package androidx.compose.ui.text.font {
+ public final class AndroidTypefaceKt {
+ method public static androidx.compose.ui.text.font.FontFamily fontFamily(android.graphics.Typeface typeface);
+ method public static androidx.compose.ui.text.font.Typeface typeface(android.content.Context context, androidx.compose.ui.text.font.FontFamily fontFamily, optional java.util.List<? extends kotlin.Pair<androidx.compose.ui.text.font.FontWeight,? extends androidx.compose.ui.text.font.FontStyle>>? necessaryStyles);
+ method public static androidx.compose.ui.text.font.Typeface typeface(android.graphics.Typeface typeface);
+ }
+
public abstract sealed class FileBasedFontFamily extends androidx.compose.ui.text.font.FontFamily {
}
@@ -603,7 +604,7 @@
public final class FontFamilyKt {
method @androidx.compose.runtime.Stable public static androidx.compose.ui.text.font.FontListFontFamily fontFamily(java.util.List<? extends androidx.compose.ui.text.font.Font> fonts);
method @androidx.compose.runtime.Stable public static androidx.compose.ui.text.font.FontListFontFamily fontFamily(androidx.compose.ui.text.font.Font... fonts);
- method public static androidx.compose.ui.text.font.LoadedFontFamily fontFamily(androidx.compose.ui.text.Typeface typeface);
+ method public static androidx.compose.ui.text.font.LoadedFontFamily fontFamily(androidx.compose.ui.text.font.Typeface typeface);
}
public final class FontKt {
@@ -701,11 +702,11 @@
}
public final class LoadedFontFamily extends androidx.compose.ui.text.font.FontFamily {
- ctor public LoadedFontFamily(androidx.compose.ui.text.Typeface typeface);
- method public androidx.compose.ui.text.Typeface component1();
- method public androidx.compose.ui.text.font.LoadedFontFamily copy(androidx.compose.ui.text.Typeface typeface);
- method public androidx.compose.ui.text.Typeface getTypeface();
- property public final androidx.compose.ui.text.Typeface typeface;
+ ctor public LoadedFontFamily(androidx.compose.ui.text.font.Typeface typeface);
+ method public androidx.compose.ui.text.font.Typeface component1();
+ method public androidx.compose.ui.text.font.LoadedFontFamily copy(androidx.compose.ui.text.font.Typeface typeface);
+ method public androidx.compose.ui.text.font.Typeface getTypeface();
+ property public final androidx.compose.ui.text.font.Typeface typeface;
}
public final class ResourceFont implements androidx.compose.ui.text.font.Font {
@@ -725,6 +726,11 @@
public abstract sealed class SystemFontFamily extends androidx.compose.ui.text.font.FontFamily {
}
+ public interface Typeface {
+ method public androidx.compose.ui.text.font.FontFamily? getFontFamily();
+ property public abstract androidx.compose.ui.text.font.FontFamily? fontFamily;
+ }
+
}
package androidx.compose.ui.text.input {
@@ -1075,10 +1081,6 @@
public final class AndroidStringDelegateKt {
}
- public final class TypefaceAdapterKt {
- method public static androidx.compose.ui.text.Typeface typefaceFromFontFamily(android.content.Context context, androidx.compose.ui.text.font.FontFamily fontFamily, optional java.util.List<? extends kotlin.Pair<androidx.compose.ui.text.font.FontWeight,? extends androidx.compose.ui.text.font.FontStyle>>? necessaryStyles);
- }
-
}
package androidx.compose.ui.text.platform.extensions {
diff --git a/compose/ui/ui-text/api/restricted_current.txt b/compose/ui/ui-text/api/restricted_current.txt
index 1a7aa19..3f4dfba 100644
--- a/compose/ui/ui-text/api/restricted_current.txt
+++ b/compose/ui/ui-text/api/restricted_current.txt
@@ -523,11 +523,6 @@
public abstract sealed class TtsAnnotation {
}
- public interface Typeface {
- method public androidx.compose.ui.text.font.FontFamily getFontFamily();
- property public abstract androidx.compose.ui.text.font.FontFamily fontFamily;
- }
-
public final class VerbatimTtsAnnotation extends androidx.compose.ui.text.TtsAnnotation {
ctor public VerbatimTtsAnnotation(String verbatim);
method public String getVerbatim();
@@ -567,6 +562,12 @@
package androidx.compose.ui.text.font {
+ public final class AndroidTypefaceKt {
+ method public static androidx.compose.ui.text.font.FontFamily fontFamily(android.graphics.Typeface typeface);
+ method public static androidx.compose.ui.text.font.Typeface typeface(android.content.Context context, androidx.compose.ui.text.font.FontFamily fontFamily, optional java.util.List<? extends kotlin.Pair<androidx.compose.ui.text.font.FontWeight,? extends androidx.compose.ui.text.font.FontStyle>>? necessaryStyles);
+ method public static androidx.compose.ui.text.font.Typeface typeface(android.graphics.Typeface typeface);
+ }
+
public abstract sealed class FileBasedFontFamily extends androidx.compose.ui.text.font.FontFamily {
}
@@ -603,7 +604,7 @@
public final class FontFamilyKt {
method @androidx.compose.runtime.Stable public static androidx.compose.ui.text.font.FontListFontFamily fontFamily(java.util.List<? extends androidx.compose.ui.text.font.Font> fonts);
method @androidx.compose.runtime.Stable public static androidx.compose.ui.text.font.FontListFontFamily fontFamily(androidx.compose.ui.text.font.Font... fonts);
- method public static androidx.compose.ui.text.font.LoadedFontFamily fontFamily(androidx.compose.ui.text.Typeface typeface);
+ method public static androidx.compose.ui.text.font.LoadedFontFamily fontFamily(androidx.compose.ui.text.font.Typeface typeface);
}
public final class FontKt {
@@ -701,11 +702,11 @@
}
public final class LoadedFontFamily extends androidx.compose.ui.text.font.FontFamily {
- ctor public LoadedFontFamily(androidx.compose.ui.text.Typeface typeface);
- method public androidx.compose.ui.text.Typeface component1();
- method public androidx.compose.ui.text.font.LoadedFontFamily copy(androidx.compose.ui.text.Typeface typeface);
- method public androidx.compose.ui.text.Typeface getTypeface();
- property public final androidx.compose.ui.text.Typeface typeface;
+ ctor public LoadedFontFamily(androidx.compose.ui.text.font.Typeface typeface);
+ method public androidx.compose.ui.text.font.Typeface component1();
+ method public androidx.compose.ui.text.font.LoadedFontFamily copy(androidx.compose.ui.text.font.Typeface typeface);
+ method public androidx.compose.ui.text.font.Typeface getTypeface();
+ property public final androidx.compose.ui.text.font.Typeface typeface;
}
public final class ResourceFont implements androidx.compose.ui.text.font.Font {
@@ -725,6 +726,11 @@
public abstract sealed class SystemFontFamily extends androidx.compose.ui.text.font.FontFamily {
}
+ public interface Typeface {
+ method public androidx.compose.ui.text.font.FontFamily? getFontFamily();
+ property public abstract androidx.compose.ui.text.font.FontFamily? fontFamily;
+ }
+
}
package androidx.compose.ui.text.input {
@@ -1075,10 +1081,6 @@
public final class AndroidStringDelegateKt {
}
- public final class TypefaceAdapterKt {
- method public static androidx.compose.ui.text.Typeface typefaceFromFontFamily(android.content.Context context, androidx.compose.ui.text.font.FontFamily fontFamily, optional java.util.List<? extends kotlin.Pair<androidx.compose.ui.text.font.FontWeight,? extends androidx.compose.ui.text.font.FontStyle>>? necessaryStyles);
- }
-
}
package androidx.compose.ui.text.platform.extensions {
diff --git a/compose/ui/ui-text/build.gradle b/compose/ui/ui-text/build.gradle
index 7908495..9e9d531 100644
--- a/compose/ui/ui-text/build.gradle
+++ b/compose/ui/ui-text/build.gradle
@@ -155,7 +155,6 @@
androidx {
name = "Compose UI Text"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2019"
description = "Compose Text primitives and utilities"
diff --git a/compose/ui/ui-text/samples/build.gradle b/compose/ui/ui-text/samples/build.gradle
index 687e11b..2f53245 100644
--- a/compose/ui/ui-text/samples/build.gradle
+++ b/compose/ui/ui-text/samples/build.gradle
@@ -53,7 +53,6 @@
androidx {
name = "AndroidX Compose UI Text Core Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2019"
description = "Contains sample code for the Androidx Compose UI Text Core APIs and Utilities"
diff --git a/compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/platform/AndroidTypefaceSubsetTest.kt b/compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/platform/AndroidTypefaceSubsetTest.kt
index bf48f70..b2e7d33 100644
--- a/compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/platform/AndroidTypefaceSubsetTest.kt
+++ b/compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/platform/AndroidTypefaceSubsetTest.kt
@@ -23,6 +23,7 @@
import androidx.compose.ui.text.font.FontSynthesis
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.font.fontFamily
+import androidx.compose.ui.text.font.typeface
import androidx.compose.ui.text.matchers.assertThat
import androidx.test.filters.SmallTest
import androidx.test.platform.app.InstrumentationRegistry
@@ -62,7 +63,7 @@
fontFamily: FontFamily,
necessaryStyles: List<Pair<FontWeight, FontStyle>>? = null
): AndroidTypeface {
- return typefaceFromFontFamily(context, fontFamily, necessaryStyles) as AndroidTypeface
+ return typeface(context, fontFamily, necessaryStyles) as AndroidTypeface
}
@Test
diff --git a/compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/platform/AndroidTypefaceTest.kt b/compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/platform/AndroidTypefaceTest.kt
index da1e65c..fda4153 100644
--- a/compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/platform/AndroidTypefaceTest.kt
+++ b/compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/platform/AndroidTypefaceTest.kt
@@ -28,6 +28,7 @@
import androidx.compose.ui.text.font.asFontFamily
import androidx.compose.ui.text.font.font
import androidx.compose.ui.text.font.fontFamily
+import androidx.compose.ui.text.font.typeface
import androidx.compose.ui.text.matchers.assertThat
import androidx.compose.ui.text.test.R
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -55,7 +56,7 @@
context: Context,
fontFamily: FontFamily
): AndroidTypeface {
- return typefaceFromFontFamily(context, fontFamily) as AndroidTypeface
+ return typeface(context, fontFamily) as AndroidTypeface
}
@Test
@@ -524,4 +525,16 @@
assertThat(typeface500.isBold).isFalse()
assertThat(typeface600.isBold).isTrue()
}
+
+ @Test
+ fun typefaceWrapper_returnsExactSameInstance() {
+ val typeface = typeface(Typeface.MONOSPACE) as AndroidTypefaceWrapper
+ assertThat(
+ typeface.getNativeTypeface(
+ FontWeight.Light,
+ FontStyle.Italic,
+ FontSynthesis.None
+ )
+ ).isEqualTo(Typeface.MONOSPACE)
+ }
}
diff --git a/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/font/AndroidTypeface.kt b/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/font/AndroidTypeface.kt
new file mode 100644
index 0000000..8c27f73
--- /dev/null
+++ b/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/font/AndroidTypeface.kt
@@ -0,0 +1,70 @@
+/*
+ * 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.compose.ui.text.font
+
+import android.content.Context
+import android.graphics.Typeface
+import androidx.compose.ui.text.platform.AndroidDefaultTypeface
+import androidx.compose.ui.text.platform.AndroidFontListTypeface
+import androidx.compose.ui.text.platform.AndroidGenericFontFamilyTypeface
+import androidx.compose.ui.text.platform.AndroidTypefaceWrapper
+
+/**
+ * Android specific Typeface builder function from FontFamily.
+ *
+ * You can pass necessaryStyles for loading only specific styles. The font style matching happens
+ * only with the loaded Typeface.
+ *
+ * This function caches the internal native Typeface but always create the new Typeface object.
+ * Caller should cache if necessary.
+ *
+ * @param context the context to be used for loading Typeface.
+ * @param fontFamily the font family to be loaded
+ * @param necessaryStyles optional style filter for loading subset of fontFamily. null means load
+ * all fonts in fontFamily.
+ * @return A loaded Typeface.
+ */
+fun typeface(
+ context: Context,
+ fontFamily: FontFamily,
+ necessaryStyles: List<Pair<FontWeight, FontStyle>>? = null
+): androidx.compose.ui.text.font.Typeface {
+ return when (fontFamily) {
+ is FontListFontFamily -> AndroidFontListTypeface(fontFamily, context, necessaryStyles)
+ is GenericFontFamily -> AndroidGenericFontFamilyTypeface(fontFamily)
+ is DefaultFontFamily -> AndroidDefaultTypeface()
+ is LoadedFontFamily -> fontFamily.typeface
+ }
+}
+
+/**
+ * Returns a Compose [androidx.compose.ui.text.font.Typeface] from Android [Typeface].
+ *
+ * @param typeface Android Typeface instance
+ */
+fun typeface(typeface: Typeface): androidx.compose.ui.text.font.Typeface {
+ return AndroidTypefaceWrapper(typeface)
+}
+
+/**
+ * Creates a [FontFamily] from Android [Typeface].
+ *
+ * @param typeface Android Typeface instance
+ */
+fun fontFamily(typeface: Typeface): FontFamily {
+ return fontFamily(typeface(typeface))
+}
\ No newline at end of file
diff --git a/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/AndroidTypeface.kt b/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/AndroidTypeface.kt
index f30da6d..e525241 100644
--- a/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/AndroidTypeface.kt
+++ b/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/AndroidTypeface.kt
@@ -16,7 +16,7 @@
package androidx.compose.ui.text.platform
-import androidx.compose.ui.text.Typeface
+import androidx.compose.ui.text.font.Typeface
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontSynthesis
import androidx.compose.ui.text.font.FontWeight
diff --git a/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/AndroidTypefaceWrapper.kt b/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/AndroidTypefaceWrapper.kt
new file mode 100644
index 0000000..673e6ff
--- /dev/null
+++ b/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/AndroidTypefaceWrapper.kt
@@ -0,0 +1,39 @@
+/*
+ * 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.compose.ui.text.platform
+
+import android.graphics.Typeface
+import androidx.compose.ui.text.font.FontFamily
+import androidx.compose.ui.text.font.FontStyle
+import androidx.compose.ui.text.font.FontSynthesis
+import androidx.compose.ui.text.font.FontWeight
+
+/**
+ * [AndroidTypeface] that wraps Android [Typeface].
+ */
+internal class AndroidTypefaceWrapper(val typeface: Typeface) : AndroidTypeface {
+
+ override val fontFamily: FontFamily? = null
+
+ override fun getNativeTypeface(
+ fontWeight: FontWeight,
+ fontStyle: FontStyle,
+ synthesis: FontSynthesis
+ ): Typeface {
+ return typeface
+ }
+}
\ No newline at end of file
diff --git a/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/TypefaceAdapter.kt b/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/TypefaceAdapter.kt
index e81797b..9bc522f 100644
--- a/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/TypefaceAdapter.kt
+++ b/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/TypefaceAdapter.kt
@@ -16,7 +16,6 @@
package androidx.compose.ui.text.platform
-import android.content.Context
import android.graphics.Typeface
import android.os.Build
import androidx.collection.LruCache
@@ -254,31 +253,3 @@
return synthesize(typeface, font, fontWeight, fontStyle, fontSynthesis)
}
}
-
-/**
- * Android specific Typeface builder function from FontFamily.
- *
- * You can pass necessaryStyles for loading only specific styles. The font style matching happens
- * only with the loaded Typeface.
- *
- * This function caches the internal native Typeface but always create the new Typeface object.
- * Caller should cache if necessary.
- *
- * @param context the context to be used for loading Typeface.
- * @param fontFamily the font family to be loaded
- * @param necessaryStyles optional style filter for loading subset of fontFamily. null means load
- * all fonts in fontFamily.
- * @return A loaded Typeface.
- */
-fun typefaceFromFontFamily(
- context: Context,
- fontFamily: FontFamily,
- necessaryStyles: List<Pair<FontWeight, FontStyle>>? = null
-): androidx.compose.ui.text.Typeface {
- return when (fontFamily) {
- is FontListFontFamily -> AndroidFontListTypeface(fontFamily, context, necessaryStyles)
- is GenericFontFamily -> AndroidGenericFontFamilyTypeface(fontFamily)
- is DefaultFontFamily -> AndroidDefaultTypeface()
- is LoadedFontFamily -> fontFamily.typeface
- }
-}
\ No newline at end of file
diff --git a/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/font/FontFamily.kt b/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/font/FontFamily.kt
index b4e5aa7..b21a5e7 100644
--- a/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/font/FontFamily.kt
+++ b/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/font/FontFamily.kt
@@ -18,7 +18,6 @@
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
-import androidx.compose.ui.text.Typeface
/**
* The base class of the font families.
diff --git a/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/Typeface.kt b/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/font/Typeface.kt
similarity index 79%
rename from compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/Typeface.kt
rename to compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/font/Typeface.kt
index 7834fce..0470785 100644
--- a/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/Typeface.kt
+++ b/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/font/Typeface.kt
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-package androidx.compose.ui.text
-
-import androidx.compose.ui.text.font.FontFamily
+package androidx.compose.ui.text.font
/**
* A class that can be used for changing the font used in text.
*/
interface Typeface {
/**
- * The font family used for creating this Typeface
+ * The font family used for creating this Typeface. If a platform Typeface was used, will
+ * return null.
+ *
*/
- val fontFamily: FontFamily
+ val fontFamily: FontFamily?
}
diff --git a/compose/ui/ui-text/src/test/java/androidx/compose/ui/text/font/LoadedFontFamilyTest.kt b/compose/ui/ui-text/src/test/java/androidx/compose/ui/text/font/LoadedFontFamilyTest.kt
index 5502b71b..8ce9d56 100644
--- a/compose/ui/ui-text/src/test/java/androidx/compose/ui/text/font/LoadedFontFamilyTest.kt
+++ b/compose/ui/ui-text/src/test/java/androidx/compose/ui/text/font/LoadedFontFamilyTest.kt
@@ -16,7 +16,6 @@
package androidx.compose.ui.text.font
-import androidx.compose.ui.text.Typeface
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
diff --git a/compose/ui/ui-tooling/build.gradle b/compose/ui/ui-tooling/build.gradle
index 901ef56..4fc98e6c 100644
--- a/compose/ui/ui-tooling/build.gradle
+++ b/compose/ui/ui-tooling/build.gradle
@@ -58,7 +58,6 @@
androidx {
name = "Compose Tooling"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2019"
description = "Compose tooling library. This library exposes information to our tools for better IDE support."
diff --git a/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/ModifierInfoTest.kt b/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/ModifierInfoTest.kt
index a79800a..4629c9f 100644
--- a/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/ModifierInfoTest.kt
+++ b/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/ModifierInfoTest.kt
@@ -29,7 +29,7 @@
import androidx.compose.ui.layout.LayoutModifier
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.node.OwnedLayer
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.junit.Assert.assertEquals
@@ -48,7 +48,7 @@
val slotTableRecord = SlotTableRecord.create()
show {
Inspectable(slotTableRecord) {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
val px10 = 10f.toDp()
val px5 = 5f.toDp()
Box {
diff --git a/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/SimpleComposablePreview.kt b/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/SimpleComposablePreview.kt
index 4300586..227f0b5 100644
--- a/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/SimpleComposablePreview.kt
+++ b/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/SimpleComposablePreview.kt
@@ -19,9 +19,9 @@
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.savedinstancestate.UiSavedStateRegistryAmbient
+import androidx.compose.runtime.savedinstancestate.AmbientUiSavedStateRegistry
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.LifecycleOwnerAmbient
+import androidx.compose.ui.platform.AmbientLifecycleOwner
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.Lifecycle
@@ -70,7 +70,7 @@
@Preview
@Composable
private fun LifecyclePreview() {
- val lifecycleState = LifecycleOwnerAmbient.current.lifecycle.currentState
+ val lifecycleState = AmbientLifecycleOwner.current.lifecycle.currentState
if (lifecycleState != Lifecycle.State.RESUMED) throw IllegalArgumentException(
"Lifecycle state is not resumed. $lifecycleState"
)
@@ -80,7 +80,7 @@
@Preview
@Composable
private fun UiSavedStateRegistryPreview() {
- if (UiSavedStateRegistryAmbient.current == null) throw IllegalArgumentException(
+ if (AmbientUiSavedStateRegistry.current == null) throw IllegalArgumentException(
"UiSavedStateRegistry is not provided"
)
Text("UiSavedStateRegistry preview")
diff --git a/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt b/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt
index 79d7ae1..3c7441e 100644
--- a/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt
+++ b/compose/ui/ui-tooling/src/androidTest/java/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt
@@ -53,10 +53,17 @@
* Asserts that the given Composable method executes correct and outputs some [ViewInfo]s.
*/
private fun assertRendersCorrectly(className: String, methodName: String): List<ViewInfo> {
+ val committed = CountDownLatch(1)
activityTestRule.runOnUiThread {
- composeViewAdapter.init(className, methodName, debugViewInfos = true)
+ composeViewAdapter.init(
+ className, methodName, debugViewInfos = true,
+ onCommit = {
+ committed.countDown()
+ }
+ )
}
+ committed.await()
activityTestRule.runOnUiThread {
assertTrue(composeViewAdapter.viewInfos.isNotEmpty())
}
@@ -243,19 +250,21 @@
@Test
fun testNoInvalidation() {
compositionCount.set(0)
+ var onDrawCounter = 0
activityTestRule.runOnUiThread {
composeViewAdapter.init(
"androidx.compose.ui.tooling.TestInvalidationPreviewKt",
"CounterPreview",
- forceCompositionInvalidation = false
+ forceCompositionInvalidation = false,
+ onDraw = { onDrawCounter++ }
)
- assertEquals(1, compositionCount.get())
}
- activityTestRule.runOnUiThread {
- assertEquals(1, compositionCount.get())
- }
- activityTestRule.runOnUiThread {
- assertEquals(1, compositionCount.get())
+ repeat(5) {
+ activityTestRule.runOnUiThread {
+ assertEquals(1, compositionCount.get())
+ assertTrue("At most, 1 draw is expected", onDrawCounter < 2)
+ }
+ Thread.sleep(250)
}
}
@@ -265,20 +274,20 @@
@Test
fun testInvalidation() {
compositionCount.set(0)
+ val drawCountDownLatch = CountDownLatch(10)
activityTestRule.runOnUiThread {
composeViewAdapter.init(
"androidx.compose.ui.tooling.TestInvalidationPreviewKt",
"CounterPreview",
- forceCompositionInvalidation = true
+ forceCompositionInvalidation = true,
+ onDraw = { drawCountDownLatch.countDown() }
)
+ }
+ activityTestRule.runOnUiThread {
assertEquals(1, compositionCount.get())
}
- activityTestRule.runOnUiThread {
- assertEquals(2, compositionCount.get())
- }
- activityTestRule.runOnUiThread {
- assertEquals(3, compositionCount.get())
- }
+ // Draw will keep happening so, eventually this will hit 0
+ assertTrue(drawCountDownLatch.await(10, TimeUnit.SECONDS))
}
companion object {
diff --git a/compose/ui/ui-tooling/src/main/java/androidx/compose/ui/tooling/preview/ComposeViewAdapter.kt b/compose/ui/ui-tooling/src/main/java/androidx/compose/ui/tooling/preview/ComposeViewAdapter.kt
index 5a1c6c0..4e89d03 100644
--- a/compose/ui/ui-tooling/src/main/java/androidx/compose/ui/tooling/preview/ComposeViewAdapter.kt
+++ b/compose/ui/ui-tooling/src/main/java/androidx/compose/ui/tooling/preview/ComposeViewAdapter.kt
@@ -32,15 +32,17 @@
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Composition
import androidx.compose.runtime.Providers
-import androidx.compose.runtime.Recomposer
import androidx.compose.runtime.currentComposer
import androidx.compose.runtime.emptyContent
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.onCommit
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
+import androidx.compose.ui.platform.AmbientAnimationClock
+import androidx.compose.ui.platform.AmbientFontLoader
import androidx.compose.ui.platform.AndroidOwner
import androidx.compose.ui.platform.AnimationClockAmbient
-import androidx.compose.ui.platform.FontLoaderAmbient
-import androidx.compose.ui.platform.setContent
+import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.tooling.Group
import androidx.compose.ui.tooling.Inspectable
import androidx.compose.ui.tooling.SlotTableRecord
@@ -81,7 +83,7 @@
override fun toString(): String =
"""($fileName:$lineNumber,
|bounds=(top=${bounds.top}, left=${bounds.left},
- |location=${location?.let { "(${it.offset}L${it.length}"} ?: "<none>" }
+ |location=${location?.let { "(${it.offset}L${it.length}" } ?: "<none>"}
|bottom=${bounds.bottom}, right=${bounds.right}),
|childrenCount=${children.size})""".trimMargin()
}
@@ -109,10 +111,16 @@
private val TAG = "ComposeViewAdapter"
/**
+ * [ComposeView] that will contain the [Composable] to preview.
+ */
+ private val composeView = ComposeView(context)
+
+ /**
* When enabled, generate and cache [ViewInfo] tree that can be inspected by the Preview
* to map components to source code.
*/
private var debugViewInfos = false
+
/**
* When enabled, paint the boundaries generated by layout nodes.
*/
@@ -143,6 +151,13 @@
*/
private var previewComposition: @Composable () -> Unit = emptyContent()
+ // Note: the call to emptyContent() below instead of a literal {} works around
+ // https://youtrack.jetbrains.com/issue/KT-17467, which causes the compiler to emit classes
+ // named `content` and `Content` (from the Content method's composable update scope)
+ // which causes compilation problems on case-insensitive filesystems.
+ @Suppress("RemoveExplicitTypeArguments")
+ private val content = mutableStateOf<@Composable () -> Unit>(emptyContent())
+
/**
* When true, the composition will be immediately invalidated after being drawn. This will
* force it to be recomposed on the next render. This is useful for live literals so the
@@ -150,6 +165,11 @@
*/
private var forceCompositionInvalidation = false
+ /**
+ * Callback invoked when onDraw has been called.
+ */
+ private var onDraw = {}
+
private val debugBoundsPaint = Paint().apply {
pathEffect = DashPathEffect(floatArrayOf(5f, 10f, 15f, 20f), 0f)
style = Paint.Style.STROKE
@@ -213,14 +233,10 @@
)
}
- override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
- super.onLayout(changed, left, top, right, bottom)
-
- delayedException.getAndSet(null)?.let { exception ->
- // There was a pending exception. Throw it here since Studio will catch it and show
- // it to the user.
- throw exception
- }
+ /**
+ * Processes the recorded slot table and re-generates the [viewInfos] attribute.
+ */
+ private fun processViewInfos() {
viewInfos = slotTableRecord.store.map { it.asTree() }.map { it.toViewInfo() }.toList()
if (debugViewInfos) {
@@ -235,6 +251,16 @@
}
}
+ override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
+ super.onLayout(changed, left, top, right, bottom)
+
+ delayedException.getAndSet(null)?.let { exception ->
+ // There was a pending exception. Throw it here since Studio will catch it and show
+ // it to the user.
+ throw exception
+ }
+ }
+
/**
* Finds all the transition animations defined in the Compose tree where the root is the
* `@Composable` being previewed. We only return animations defined in the user code, i.e.
@@ -305,8 +331,8 @@
private fun invalidateComposition() {
// Invalidate the full composition by setting it to empty and back to the actual value
- composition?.setContent(emptyContent())
- composition?.setContent(previewComposition)
+ content.value = emptyContent()
+ content.value = previewComposition
// Invalidate the state of the view so it gets redrawn
invalidate()
}
@@ -316,6 +342,7 @@
if (forceCompositionInvalidation) invalidateComposition()
+ onDraw()
if (!debugPaintBounds) {
return
}
@@ -353,7 +380,7 @@
// We need to replace the FontResourceLoader to avoid using ResourcesCompat.
// ResourcesCompat can not load fonts within Layoutlib and, since Layoutlib always runs
// the latest version, we do not need it.
- Providers(FontLoaderAmbient provides LayoutlibFontResourceLoader(context)) {
+ Providers(AmbientFontLoader provides LayoutlibFontResourceLoader(context)) {
Inspectable(slotTableRecord, children)
}
}
@@ -373,6 +400,8 @@
* [clock] instead of the default clock, setting this value as the clock's initial time.
* @param forceCompositionInvalidation if true, the composition will be invalidated on every
* draw, forcing it to recompose on next render.
+ * @param onDraw callback invoked after every draw of the adapter. Only for test use.
+ * @param onCommit callback invoked after every commit of the preview composable.
*/
@VisibleForTesting
internal fun init(
@@ -383,17 +412,22 @@
debugPaintBounds: Boolean = false,
debugViewInfos: Boolean = false,
animationClockStartTime: Long = -1,
- forceCompositionInvalidation: Boolean = false
+ forceCompositionInvalidation: Boolean = false,
+ onCommit: () -> Unit = {},
+ onDraw: () -> Unit = {}
) {
- ViewTreeLifecycleOwner.set(this, FakeSavedStateRegistryOwnerOwner)
- ViewTreeSavedStateRegistryOwner.set(this, FakeSavedStateRegistryOwnerOwner)
- ViewTreeViewModelStoreOwner.set(this, FakeViewModelStoreOwner)
this.debugPaintBounds = debugPaintBounds
this.debugViewInfos = debugViewInfos
this.composableName = methodName
this.forceCompositionInvalidation = forceCompositionInvalidation
+ this.onDraw = onDraw
previewComposition = @Composable {
+ onCommit {
+ processViewInfos()
+ onCommit()
+ }
+
WrapPreview {
val composer = currentComposer
// We need to delay the reflection instantiation of the class until we are in the
@@ -424,12 +458,13 @@
// valid `animationClockStartTime` is passed. This clock will control the
// animations defined in this `ComposeViewAdapter` from Android Studio.
clock = PreviewAnimationClock(animationClockStartTime) {
- // Invalidate the descendants of this ComposeViewAdapter's only child (an
- // AndroidOwner) when setting the clock time to make sure the Compose
+ // Invalidate the descendants of this ComposeViewAdapter's only grandchild
+ // (an AndroidOwner) when setting the clock time to make sure the Compose
// Preview will animate when the states are read inside the draw scope.
- (getChildAt(0) as? AndroidOwner)?.invalidateDescendants()
+ val composeView = getChildAt(0) as ComposeView
+ (composeView.getChildAt(0) as? AndroidOwner)?.invalidateDescendants()
}
- Providers(AnimationClockAmbient provides clock) {
+ Providers(AmbientAnimationClock provides clock) {
composable()
}
} else {
@@ -437,15 +472,15 @@
}
}
}
- composition = setContent(Recomposer.current(), previewComposition)
+ composeView.setContent(previewComposition)
+ invalidate()
}
/**
* Disposes the Compose elements allocated during [init]
*/
internal fun dispose() {
- composition?.dispose()
- composition = null
+ composeView.disposeComposition()
if (::clock.isInitialized) {
clock.dispose()
}
@@ -463,6 +498,12 @@
fun hasAnimations() = hasAnimations
private fun init(attrs: AttributeSet) {
+ // ComposeView and lifecycle initialization
+ ViewTreeLifecycleOwner.set(this, FakeSavedStateRegistryOwnerOwner)
+ ViewTreeSavedStateRegistryOwner.set(this, FakeSavedStateRegistryOwnerOwner)
+ ViewTreeViewModelStoreOwner.set(this, FakeViewModelStoreOwner)
+ addView(composeView)
+
val composableName = attrs.getAttributeValue(TOOLS_NS_URI, "composableName") ?: return
val className = composableName.substringBeforeLast('.')
val methodName = composableName.substringAfterLast('.')
diff --git a/compose/ui/ui-unit/build.gradle b/compose/ui/ui-unit/build.gradle
index 4be34c94..53e5c03 100644
--- a/compose/ui/ui-unit/build.gradle
+++ b/compose/ui/ui-unit/build.gradle
@@ -101,7 +101,6 @@
androidx {
name = "Compose Unit"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2020"
description = "Compose classes for simple units"
diff --git a/compose/ui/ui-unit/samples/build.gradle b/compose/ui/ui-unit/samples/build.gradle
index 1eb41af..5fc2183 100644
--- a/compose/ui/ui-unit/samples/build.gradle
+++ b/compose/ui/ui-unit/samples/build.gradle
@@ -51,7 +51,6 @@
androidx {
name = "AndroidX Compose UI Simple Unit Classes Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose UI Simple Unit Classes"
diff --git a/compose/ui/ui-unit/samples/src/main/java/androidx/compose/ui/unit/samples/DensitySample.kt b/compose/ui/ui-unit/samples/src/main/java/androidx/compose/ui/unit/samples/DensitySample.kt
index d491af1..983599c 100644
--- a/compose/ui/ui-unit/samples/src/main/java/androidx/compose/ui/unit/samples/DensitySample.kt
+++ b/compose/ui/ui-unit/samples/src/main/java/androidx/compose/ui/unit/samples/DensitySample.kt
@@ -18,12 +18,12 @@
import androidx.annotation.Sampled
import androidx.compose.runtime.Composable
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.dp
@Sampled
@Composable
@Suppress("UNUSED_VARIABLE")
fun WithDensitySample() {
- val sizeInPx = with(DensityAmbient.current) { 16.dp.toPx() }
+ val sizeInPx = with(AmbientDensity.current) { 16.dp.toPx() }
}
diff --git a/compose/ui/ui-unit/src/commonMain/kotlin/androidx/compose/ui/unit/TextUnit.kt b/compose/ui/ui-unit/src/commonMain/kotlin/androidx/compose/ui/unit/TextUnit.kt
index b6169fd..a558db4 100644
--- a/compose/ui/ui-unit/src/commonMain/kotlin/androidx/compose/ui/unit/TextUnit.kt
+++ b/compose/ui/ui-unit/src/commonMain/kotlin/androidx/compose/ui/unit/TextUnit.kt
@@ -39,7 +39,7 @@
private const val UNIT_TYPE_EM = 0x02L shl 32 // 0x2_0000_0000
/**
- * An enum class defining for type of thextUnit.
+ * An enum class defining for type of [TextUnit].
*/
enum class TextUnitType(val value: Int) {
@Deprecated(
@@ -232,7 +232,7 @@
* A special [TextUnit] instance for representing inheriting from parent value.
*/
@Stable
- val Unspecified = pack(UNIT_TYPE_UNSPECIFIED, 0f)
+ val Unspecified = pack(UNIT_TYPE_UNSPECIFIED, Float.NaN)
/**
* A special [TextUnit] instance for representing inheriting from parent value.
diff --git a/compose/ui/ui-unit/src/test/kotlin/androidx/compose/ui/unit/TextUnitTest.kt b/compose/ui/ui-unit/src/test/kotlin/androidx/compose/ui/unit/TextUnitTest.kt
index 0a0bc4a..e3ec3b3 100644
--- a/compose/ui/ui-unit/src/test/kotlin/androidx/compose/ui/unit/TextUnitTest.kt
+++ b/compose/ui/ui-unit/src/test/kotlin/androidx/compose/ui/unit/TextUnitTest.kt
@@ -1047,6 +1047,11 @@
}
@Test
+ fun unspecified_value_equals_nan() {
+ assertThat(TextUnit.Unspecified.value).isEqualTo(Float.NaN)
+ }
+
+ @Test
@Suppress("DEPRECATION")
fun inherit_isEqualTo_unspecified() {
assertThat(TextUnit.Unspecified).isEqualTo(TextUnit.Inherit)
diff --git a/compose/ui/ui-util/build.gradle b/compose/ui/ui-util/build.gradle
index c4d321e..4dbda77 100644
--- a/compose/ui/ui-util/build.gradle
+++ b/compose/ui/ui-util/build.gradle
@@ -89,7 +89,6 @@
androidx {
name = "Compose Util"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2020"
description = "Internal Compose utilities used by other modules"
diff --git a/compose/ui/ui-viewbinding/build.gradle b/compose/ui/ui-viewbinding/build.gradle
index dbec57f..87f0e1f 100644
--- a/compose/ui/ui-viewbinding/build.gradle
+++ b/compose/ui/ui-viewbinding/build.gradle
@@ -44,7 +44,6 @@
androidx {
name = "Compose ViewBinding"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2020"
description = "Compose integration with ViewBinding"
diff --git a/compose/ui/ui-viewbinding/samples/build.gradle b/compose/ui/ui-viewbinding/samples/build.gradle
index afa8cc3..7108bb6 100644
--- a/compose/ui/ui-viewbinding/samples/build.gradle
+++ b/compose/ui/ui-viewbinding/samples/build.gradle
@@ -41,7 +41,6 @@
androidx {
name = "AndroidX Compose UI Simple Unit Classes Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose UI Simple Unit Classes"
diff --git a/compose/ui/ui-viewbinding/src/androidTest/java/androidx/compose/ui/viewinterop/AndroidViewBindingTest.kt b/compose/ui/ui-viewbinding/src/androidTest/java/androidx/compose/ui/viewinterop/AndroidViewBindingTest.kt
index 7686fd2..c7b8e9e 100644
--- a/compose/ui/ui-viewbinding/src/androidTest/java/androidx/compose/ui/viewinterop/AndroidViewBindingTest.kt
+++ b/compose/ui/ui-viewbinding/src/androidTest/java/androidx/compose/ui/viewinterop/AndroidViewBindingTest.kt
@@ -25,7 +25,7 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.junit4.createComposeRule
@@ -94,7 +94,7 @@
val size = 50.dp
val density = Density(3f)
val sizeIpx = with(density) { size.toIntPx() }
- Providers(DensityAmbient provides density) {
+ Providers(AmbientDensity provides density) {
AndroidViewBinding(
TestLayoutBinding::inflate,
Modifier.size(size).onGloballyPositioned {
diff --git a/compose/ui/ui-viewbinding/src/main/java/androidx/compose/ui/viewinterop/AndroidViewBinding.kt b/compose/ui/ui-viewbinding/src/main/java/androidx/compose/ui/viewinterop/AndroidViewBinding.kt
index 5dafdc09..482dcd5 100644
--- a/compose/ui/ui-viewbinding/src/main/java/androidx/compose/ui/viewinterop/AndroidViewBinding.kt
+++ b/compose/ui/ui-viewbinding/src/main/java/androidx/compose/ui/viewinterop/AndroidViewBinding.kt
@@ -26,8 +26,8 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.materialize
import androidx.compose.ui.node.UiApplier
-import androidx.compose.ui.platform.ContextAmbient
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientContext
+import androidx.compose.ui.platform.AmbientDensity
import androidx.viewbinding.ViewBinding
/**
@@ -53,14 +53,14 @@
modifier: Modifier = Modifier,
update: T.() -> Unit = {}
) {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
val materialized = currentComposer.materialize(modifier)
emit<ViewBindingHolder<T>, UiApplier>(
ctor = { ViewBindingHolder(context) },
update = {
set(Unit) { this.bindingBlock = bindingBlock }
set(materialized) { this.modifier = it }
- set(DensityAmbient.current) { this.density = it }
+ set(AmbientDensity.current) { this.density = it }
set(update) { this.updateBlock = it }
}
)
diff --git a/compose/ui/ui/api/current.txt b/compose/ui/ui/api/current.txt
index e126fed..c8c0d16 100644
--- a/compose/ui/ui/api/current.txt
+++ b/compose/ui/ui/api/current.txt
@@ -764,10 +764,10 @@
package androidx.compose.ui.input.key {
- @androidx.compose.ui.input.key.ExperimentalKeyInput public interface Alt {
- method public boolean isLeftAltPressed();
- method public default boolean isPressed();
- method public boolean isRightAltPressed();
+ @Deprecated @androidx.compose.ui.input.key.ExperimentalKeyInput public interface Alt {
+ method @Deprecated public boolean isLeftAltPressed();
+ method @Deprecated public default boolean isPressed();
+ method @Deprecated public boolean isRightAltPressed();
property public abstract boolean isLeftAltPressed;
property public default boolean isPressed;
property public abstract boolean isRightAltPressed;
@@ -1370,11 +1370,19 @@
}
@androidx.compose.ui.input.key.ExperimentalKeyInput public interface KeyEvent {
- method public androidx.compose.ui.input.key.Alt getAlt();
+ method @Deprecated public androidx.compose.ui.input.key.Alt getAlt();
method public int getKey-EK5gGoQ();
method public androidx.compose.ui.input.key.KeyEventType getType();
method public int getUtf16CodePoint();
- property public abstract androidx.compose.ui.input.key.Alt alt;
+ method public boolean isAltPressed();
+ method public boolean isCtrlPressed();
+ method public boolean isMetaPressed();
+ method public boolean isShiftPressed();
+ property @Deprecated public abstract androidx.compose.ui.input.key.Alt alt;
+ property public abstract boolean isAltPressed;
+ property public abstract boolean isCtrlPressed;
+ property public abstract boolean isMetaPressed;
+ property public abstract boolean isShiftPressed;
property public abstract int key;
property public abstract androidx.compose.ui.input.key.KeyEventType type;
property public abstract int utf16CodePoint;
@@ -2076,26 +2084,44 @@
}
public final class AmbientsKt {
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.animation.core.AnimationClockObservable> getAnimationClockAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.Autofill> getAutofillAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.AutofillTree> getAutofillTreeAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ClipboardManager> getClipboardManagerAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.Density> getDensityAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.focus.FocusManager> getFocusManagerAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.hapticfeedback.HapticFeedback> getHapticFeedBackAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.LayoutDirection> getLayoutDirectionAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.text.input.TextInputService> getTextInputServiceAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.TextToolbar> getTextToolbarAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.UriHandler> getUriHandlerAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ViewConfiguration> getViewConfigurationAmbient();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.animation.core.AnimationClockObservable> getAmbientAnimationClock();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.Autofill> getAmbientAutofill();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.AutofillTree> getAmbientAutofillTree();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ClipboardManager> getAmbientClipboardManager();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.Density> getAmbientDensity();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.focus.FocusManager> getAmbientFocusManager();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.hapticfeedback.HapticFeedback> getAmbientHapticFeedback();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.LayoutDirection> getAmbientLayoutDirection();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.text.input.TextInputService> getAmbientTextInputService();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.TextToolbar> getAmbientTextToolbar();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.UriHandler> getAmbientUriHandler();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ViewConfiguration> getAmbientViewConfiguration();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.animation.core.AnimationClockObservable>! getAnimationClockAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.Autofill>! getAutofillAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.AutofillTree>! getAutofillTreeAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ClipboardManager>! getClipboardManagerAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.Density>! getDensityAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.focus.FocusManager>! getFocusManagerAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.text.font.Font.ResourceLoader>! getFontLoaderAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.hapticfeedback.HapticFeedback>! getHapticFeedBackAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.LayoutDirection>! getLayoutDirectionAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.text.input.TextInputService>! getTextInputServiceAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.TextToolbar>! getTextToolbarAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.UriHandler>! getUriHandlerAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ViewConfiguration>! getViewConfigurationAmbient();
}
public final class AndroidAmbientsKt {
- method public static androidx.compose.runtime.ProvidableAmbient<android.content.res.Configuration> getConfigurationAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<android.content.Context> getContextAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.LifecycleOwner> getLifecycleOwnerAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<android.view.View> getViewAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.ViewModelStoreOwner> getViewModelStoreOwnerAmbient();
+ method public static androidx.compose.runtime.ProvidableAmbient<android.content.res.Configuration> getAmbientConfiguration();
+ method public static androidx.compose.runtime.ProvidableAmbient<android.content.Context> getAmbientContext();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.LifecycleOwner> getAmbientLifecycleOwner();
+ method public static androidx.compose.runtime.ProvidableAmbient<android.view.View> getAmbientView();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.ViewModelStoreOwner> getAmbientViewModelStoreOwner();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<android.content.res.Configuration>! getConfigurationAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<android.content.Context>! getContextAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.LifecycleOwner>! getLifecycleOwnerAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<android.view.View>! getViewAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.ViewModelStoreOwner>! getViewModelStoreOwnerAmbient();
}
public final class AndroidClipboardManagerKt {
@@ -2296,9 +2322,9 @@
}
public final class FontResourcesKt {
- method @androidx.compose.runtime.Composable public static androidx.compose.ui.text.Typeface fontResource(androidx.compose.ui.text.font.FontFamily fontFamily);
- method @androidx.compose.runtime.Composable public static androidx.compose.ui.res.DeferredResource<androidx.compose.ui.text.Typeface> loadFontResource(androidx.compose.ui.text.font.FontFamily fontFamily, optional androidx.compose.ui.text.font.FontFamily? pendingFontFamily, optional androidx.compose.ui.text.font.FontFamily? failedFontFamily);
- method @androidx.compose.runtime.Composable public static androidx.compose.ui.res.DeferredResource<androidx.compose.ui.text.Typeface> loadFontResource(androidx.compose.ui.text.font.FontFamily fontFamily, optional androidx.compose.ui.text.Typeface? pendingTypeface, optional androidx.compose.ui.text.Typeface? failedTypeface);
+ method @androidx.compose.runtime.Composable public static androidx.compose.ui.text.font.Typeface fontResource(androidx.compose.ui.text.font.FontFamily fontFamily);
+ method @androidx.compose.runtime.Composable public static androidx.compose.ui.res.DeferredResource<androidx.compose.ui.text.font.Typeface> loadFontResource(androidx.compose.ui.text.font.FontFamily fontFamily, optional androidx.compose.ui.text.font.FontFamily? pendingFontFamily, optional androidx.compose.ui.text.font.FontFamily? failedFontFamily);
+ method @androidx.compose.runtime.Composable public static androidx.compose.ui.res.DeferredResource<androidx.compose.ui.text.font.Typeface> loadFontResource(androidx.compose.ui.text.font.FontFamily fontFamily, optional androidx.compose.ui.text.font.Typeface? pendingTypeface, optional androidx.compose.ui.text.font.Typeface? failedTypeface);
}
public final class ImageResourcesKt {
@@ -2402,7 +2428,8 @@
}
public final class SelectionRegistrarKt {
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.selection.SelectionRegistrar> getSelectionRegistrarAmbient();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.selection.SelectionRegistrar> getAmbientSelectionRegistrar();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.selection.SelectionRegistrar>! getSelectionRegistrarAmbient();
}
public final class SimpleLayoutKt {
diff --git a/compose/ui/ui/api/public_plus_experimental_current.txt b/compose/ui/ui/api/public_plus_experimental_current.txt
index e126fed..c8c0d16 100644
--- a/compose/ui/ui/api/public_plus_experimental_current.txt
+++ b/compose/ui/ui/api/public_plus_experimental_current.txt
@@ -764,10 +764,10 @@
package androidx.compose.ui.input.key {
- @androidx.compose.ui.input.key.ExperimentalKeyInput public interface Alt {
- method public boolean isLeftAltPressed();
- method public default boolean isPressed();
- method public boolean isRightAltPressed();
+ @Deprecated @androidx.compose.ui.input.key.ExperimentalKeyInput public interface Alt {
+ method @Deprecated public boolean isLeftAltPressed();
+ method @Deprecated public default boolean isPressed();
+ method @Deprecated public boolean isRightAltPressed();
property public abstract boolean isLeftAltPressed;
property public default boolean isPressed;
property public abstract boolean isRightAltPressed;
@@ -1370,11 +1370,19 @@
}
@androidx.compose.ui.input.key.ExperimentalKeyInput public interface KeyEvent {
- method public androidx.compose.ui.input.key.Alt getAlt();
+ method @Deprecated public androidx.compose.ui.input.key.Alt getAlt();
method public int getKey-EK5gGoQ();
method public androidx.compose.ui.input.key.KeyEventType getType();
method public int getUtf16CodePoint();
- property public abstract androidx.compose.ui.input.key.Alt alt;
+ method public boolean isAltPressed();
+ method public boolean isCtrlPressed();
+ method public boolean isMetaPressed();
+ method public boolean isShiftPressed();
+ property @Deprecated public abstract androidx.compose.ui.input.key.Alt alt;
+ property public abstract boolean isAltPressed;
+ property public abstract boolean isCtrlPressed;
+ property public abstract boolean isMetaPressed;
+ property public abstract boolean isShiftPressed;
property public abstract int key;
property public abstract androidx.compose.ui.input.key.KeyEventType type;
property public abstract int utf16CodePoint;
@@ -2076,26 +2084,44 @@
}
public final class AmbientsKt {
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.animation.core.AnimationClockObservable> getAnimationClockAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.Autofill> getAutofillAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.AutofillTree> getAutofillTreeAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ClipboardManager> getClipboardManagerAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.Density> getDensityAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.focus.FocusManager> getFocusManagerAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.hapticfeedback.HapticFeedback> getHapticFeedBackAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.LayoutDirection> getLayoutDirectionAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.text.input.TextInputService> getTextInputServiceAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.TextToolbar> getTextToolbarAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.UriHandler> getUriHandlerAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ViewConfiguration> getViewConfigurationAmbient();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.animation.core.AnimationClockObservable> getAmbientAnimationClock();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.Autofill> getAmbientAutofill();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.AutofillTree> getAmbientAutofillTree();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ClipboardManager> getAmbientClipboardManager();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.Density> getAmbientDensity();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.focus.FocusManager> getAmbientFocusManager();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.hapticfeedback.HapticFeedback> getAmbientHapticFeedback();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.LayoutDirection> getAmbientLayoutDirection();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.text.input.TextInputService> getAmbientTextInputService();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.TextToolbar> getAmbientTextToolbar();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.UriHandler> getAmbientUriHandler();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ViewConfiguration> getAmbientViewConfiguration();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.animation.core.AnimationClockObservable>! getAnimationClockAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.Autofill>! getAutofillAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.AutofillTree>! getAutofillTreeAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ClipboardManager>! getClipboardManagerAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.Density>! getDensityAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.focus.FocusManager>! getFocusManagerAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.text.font.Font.ResourceLoader>! getFontLoaderAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.hapticfeedback.HapticFeedback>! getHapticFeedBackAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.LayoutDirection>! getLayoutDirectionAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.text.input.TextInputService>! getTextInputServiceAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.TextToolbar>! getTextToolbarAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.UriHandler>! getUriHandlerAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ViewConfiguration>! getViewConfigurationAmbient();
}
public final class AndroidAmbientsKt {
- method public static androidx.compose.runtime.ProvidableAmbient<android.content.res.Configuration> getConfigurationAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<android.content.Context> getContextAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.LifecycleOwner> getLifecycleOwnerAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<android.view.View> getViewAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.ViewModelStoreOwner> getViewModelStoreOwnerAmbient();
+ method public static androidx.compose.runtime.ProvidableAmbient<android.content.res.Configuration> getAmbientConfiguration();
+ method public static androidx.compose.runtime.ProvidableAmbient<android.content.Context> getAmbientContext();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.LifecycleOwner> getAmbientLifecycleOwner();
+ method public static androidx.compose.runtime.ProvidableAmbient<android.view.View> getAmbientView();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.ViewModelStoreOwner> getAmbientViewModelStoreOwner();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<android.content.res.Configuration>! getConfigurationAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<android.content.Context>! getContextAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.LifecycleOwner>! getLifecycleOwnerAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<android.view.View>! getViewAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.ViewModelStoreOwner>! getViewModelStoreOwnerAmbient();
}
public final class AndroidClipboardManagerKt {
@@ -2296,9 +2322,9 @@
}
public final class FontResourcesKt {
- method @androidx.compose.runtime.Composable public static androidx.compose.ui.text.Typeface fontResource(androidx.compose.ui.text.font.FontFamily fontFamily);
- method @androidx.compose.runtime.Composable public static androidx.compose.ui.res.DeferredResource<androidx.compose.ui.text.Typeface> loadFontResource(androidx.compose.ui.text.font.FontFamily fontFamily, optional androidx.compose.ui.text.font.FontFamily? pendingFontFamily, optional androidx.compose.ui.text.font.FontFamily? failedFontFamily);
- method @androidx.compose.runtime.Composable public static androidx.compose.ui.res.DeferredResource<androidx.compose.ui.text.Typeface> loadFontResource(androidx.compose.ui.text.font.FontFamily fontFamily, optional androidx.compose.ui.text.Typeface? pendingTypeface, optional androidx.compose.ui.text.Typeface? failedTypeface);
+ method @androidx.compose.runtime.Composable public static androidx.compose.ui.text.font.Typeface fontResource(androidx.compose.ui.text.font.FontFamily fontFamily);
+ method @androidx.compose.runtime.Composable public static androidx.compose.ui.res.DeferredResource<androidx.compose.ui.text.font.Typeface> loadFontResource(androidx.compose.ui.text.font.FontFamily fontFamily, optional androidx.compose.ui.text.font.FontFamily? pendingFontFamily, optional androidx.compose.ui.text.font.FontFamily? failedFontFamily);
+ method @androidx.compose.runtime.Composable public static androidx.compose.ui.res.DeferredResource<androidx.compose.ui.text.font.Typeface> loadFontResource(androidx.compose.ui.text.font.FontFamily fontFamily, optional androidx.compose.ui.text.font.Typeface? pendingTypeface, optional androidx.compose.ui.text.font.Typeface? failedTypeface);
}
public final class ImageResourcesKt {
@@ -2402,7 +2428,8 @@
}
public final class SelectionRegistrarKt {
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.selection.SelectionRegistrar> getSelectionRegistrarAmbient();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.selection.SelectionRegistrar> getAmbientSelectionRegistrar();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.selection.SelectionRegistrar>! getSelectionRegistrarAmbient();
}
public final class SimpleLayoutKt {
diff --git a/compose/ui/ui/api/restricted_current.txt b/compose/ui/ui/api/restricted_current.txt
index 573c28e..b51fdf1 100644
--- a/compose/ui/ui/api/restricted_current.txt
+++ b/compose/ui/ui/api/restricted_current.txt
@@ -764,10 +764,10 @@
package androidx.compose.ui.input.key {
- @androidx.compose.ui.input.key.ExperimentalKeyInput public interface Alt {
- method public boolean isLeftAltPressed();
- method public default boolean isPressed();
- method public boolean isRightAltPressed();
+ @Deprecated @androidx.compose.ui.input.key.ExperimentalKeyInput public interface Alt {
+ method @Deprecated public boolean isLeftAltPressed();
+ method @Deprecated public default boolean isPressed();
+ method @Deprecated public boolean isRightAltPressed();
property public abstract boolean isLeftAltPressed;
property public default boolean isPressed;
property public abstract boolean isRightAltPressed;
@@ -1370,11 +1370,19 @@
}
@androidx.compose.ui.input.key.ExperimentalKeyInput public interface KeyEvent {
- method public androidx.compose.ui.input.key.Alt getAlt();
+ method @Deprecated public androidx.compose.ui.input.key.Alt getAlt();
method public int getKey-EK5gGoQ();
method public androidx.compose.ui.input.key.KeyEventType getType();
method public int getUtf16CodePoint();
- property public abstract androidx.compose.ui.input.key.Alt alt;
+ method public boolean isAltPressed();
+ method public boolean isCtrlPressed();
+ method public boolean isMetaPressed();
+ method public boolean isShiftPressed();
+ property @Deprecated public abstract androidx.compose.ui.input.key.Alt alt;
+ property public abstract boolean isAltPressed;
+ property public abstract boolean isCtrlPressed;
+ property public abstract boolean isMetaPressed;
+ property public abstract boolean isShiftPressed;
property public abstract int key;
property public abstract androidx.compose.ui.input.key.KeyEventType type;
property public abstract int utf16CodePoint;
@@ -2117,16 +2125,7 @@
property public Object current;
}
- @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP) public interface ViewAdapter {
- method public void didInsert(android.view.View view, android.view.ViewGroup parent);
- method public void didUpdate(android.view.View view, android.view.ViewGroup parent);
- method public int getId();
- method public void willInsert(android.view.View view, android.view.ViewGroup parent);
- property public abstract int id;
- }
-
public final class ViewInteropKt {
- method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP) public static <T extends androidx.compose.ui.node.ViewAdapter> T getOrAddAdapter(android.view.View, int id, kotlin.jvm.functions.Function0<? extends T> factory);
}
}
@@ -2147,26 +2146,44 @@
}
public final class AmbientsKt {
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.animation.core.AnimationClockObservable> getAnimationClockAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.Autofill> getAutofillAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.AutofillTree> getAutofillTreeAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ClipboardManager> getClipboardManagerAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.Density> getDensityAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.focus.FocusManager> getFocusManagerAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.hapticfeedback.HapticFeedback> getHapticFeedBackAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.LayoutDirection> getLayoutDirectionAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.text.input.TextInputService> getTextInputServiceAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.TextToolbar> getTextToolbarAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.UriHandler> getUriHandlerAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ViewConfiguration> getViewConfigurationAmbient();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.animation.core.AnimationClockObservable> getAmbientAnimationClock();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.Autofill> getAmbientAutofill();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.AutofillTree> getAmbientAutofillTree();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ClipboardManager> getAmbientClipboardManager();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.Density> getAmbientDensity();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.focus.FocusManager> getAmbientFocusManager();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.hapticfeedback.HapticFeedback> getAmbientHapticFeedback();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.LayoutDirection> getAmbientLayoutDirection();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.text.input.TextInputService> getAmbientTextInputService();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.TextToolbar> getAmbientTextToolbar();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.UriHandler> getAmbientUriHandler();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ViewConfiguration> getAmbientViewConfiguration();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.animation.core.AnimationClockObservable>! getAnimationClockAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.Autofill>! getAutofillAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.autofill.AutofillTree>! getAutofillTreeAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ClipboardManager>! getClipboardManagerAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.Density>! getDensityAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.focus.FocusManager>! getFocusManagerAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.text.font.Font.ResourceLoader>! getFontLoaderAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.hapticfeedback.HapticFeedback>! getHapticFeedBackAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.unit.LayoutDirection>! getLayoutDirectionAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.text.input.TextInputService>! getTextInputServiceAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.TextToolbar>! getTextToolbarAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.UriHandler>! getUriHandlerAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.platform.ViewConfiguration>! getViewConfigurationAmbient();
}
public final class AndroidAmbientsKt {
- method public static androidx.compose.runtime.ProvidableAmbient<android.content.res.Configuration> getConfigurationAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<android.content.Context> getContextAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.LifecycleOwner> getLifecycleOwnerAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<android.view.View> getViewAmbient();
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.ViewModelStoreOwner> getViewModelStoreOwnerAmbient();
+ method public static androidx.compose.runtime.ProvidableAmbient<android.content.res.Configuration> getAmbientConfiguration();
+ method public static androidx.compose.runtime.ProvidableAmbient<android.content.Context> getAmbientContext();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.LifecycleOwner> getAmbientLifecycleOwner();
+ method public static androidx.compose.runtime.ProvidableAmbient<android.view.View> getAmbientView();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.ViewModelStoreOwner> getAmbientViewModelStoreOwner();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<android.content.res.Configuration>! getConfigurationAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<android.content.Context>! getContextAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.LifecycleOwner>! getLifecycleOwnerAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<android.view.View>! getViewAmbient();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.lifecycle.ViewModelStoreOwner>! getViewModelStoreOwnerAmbient();
}
public final class AndroidClipboardManagerKt {
@@ -2190,12 +2207,6 @@
property public abstract androidx.compose.ui.platform.AndroidOwner.ViewTreeOwners? viewTreeOwners;
}
- @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP) public static final class AndroidOwner.Companion {
- method public kotlin.jvm.functions.Function1<androidx.compose.ui.platform.AndroidOwner,kotlin.Unit>? getOnAndroidOwnerCreatedCallback();
- method @org.jetbrains.annotations.TestOnly public void setOnAndroidOwnerCreatedCallback(kotlin.jvm.functions.Function1<? super androidx.compose.ui.platform.AndroidOwner,kotlin.Unit>? p);
- property public final kotlin.jvm.functions.Function1<androidx.compose.ui.platform.AndroidOwner,kotlin.Unit>? onAndroidOwnerCreatedCallback;
- }
-
public static final class AndroidOwner.ViewTreeOwners {
ctor public AndroidOwner.ViewTreeOwners(androidx.lifecycle.LifecycleOwner lifecycleOwner, androidx.lifecycle.ViewModelStoreOwner viewModelStoreOwner, androidx.savedstate.SavedStateRegistryOwner savedStateRegistryOwner);
method public androidx.lifecycle.LifecycleOwner getLifecycleOwner();
@@ -2373,9 +2384,9 @@
}
public final class FontResourcesKt {
- method @androidx.compose.runtime.Composable public static androidx.compose.ui.text.Typeface fontResource(androidx.compose.ui.text.font.FontFamily fontFamily);
- method @androidx.compose.runtime.Composable public static androidx.compose.ui.res.DeferredResource<androidx.compose.ui.text.Typeface> loadFontResource(androidx.compose.ui.text.font.FontFamily fontFamily, optional androidx.compose.ui.text.font.FontFamily? pendingFontFamily, optional androidx.compose.ui.text.font.FontFamily? failedFontFamily);
- method @androidx.compose.runtime.Composable public static androidx.compose.ui.res.DeferredResource<androidx.compose.ui.text.Typeface> loadFontResource(androidx.compose.ui.text.font.FontFamily fontFamily, optional androidx.compose.ui.text.Typeface? pendingTypeface, optional androidx.compose.ui.text.Typeface? failedTypeface);
+ method @androidx.compose.runtime.Composable public static androidx.compose.ui.text.font.Typeface fontResource(androidx.compose.ui.text.font.FontFamily fontFamily);
+ method @androidx.compose.runtime.Composable public static androidx.compose.ui.res.DeferredResource<androidx.compose.ui.text.font.Typeface> loadFontResource(androidx.compose.ui.text.font.FontFamily fontFamily, optional androidx.compose.ui.text.font.FontFamily? pendingFontFamily, optional androidx.compose.ui.text.font.FontFamily? failedFontFamily);
+ method @androidx.compose.runtime.Composable public static androidx.compose.ui.res.DeferredResource<androidx.compose.ui.text.font.Typeface> loadFontResource(androidx.compose.ui.text.font.FontFamily fontFamily, optional androidx.compose.ui.text.font.Typeface? pendingTypeface, optional androidx.compose.ui.text.font.Typeface? failedTypeface);
}
public final class ImageResourcesKt {
@@ -2479,7 +2490,8 @@
}
public final class SelectionRegistrarKt {
- method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.selection.SelectionRegistrar> getSelectionRegistrarAmbient();
+ method public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.selection.SelectionRegistrar> getAmbientSelectionRegistrar();
+ method @Deprecated public static androidx.compose.runtime.ProvidableAmbient<androidx.compose.ui.selection.SelectionRegistrar>! getSelectionRegistrarAmbient();
}
public final class SimpleLayoutKt {
diff --git a/compose/ui/ui/build.gradle b/compose/ui/ui/build.gradle
index d3519b2..8d1b7d4 100644
--- a/compose/ui/ui/build.gradle
+++ b/compose/ui/ui/build.gradle
@@ -216,7 +216,6 @@
androidx {
name = "Compose UI primitives"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2019"
description = "Compose UI primitives. This library contains the primitives that form the Compose UI Toolkit, such as drawing, measurement and layout."
diff --git a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/autofill/ExplicitAutofillTypesDemo.kt b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/autofill/ExplicitAutofillTypesDemo.kt
index 27d310c..4579a8e 100644
--- a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/autofill/ExplicitAutofillTypesDemo.kt
+++ b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/autofill/ExplicitAutofillTypesDemo.kt
@@ -39,8 +39,8 @@
import androidx.compose.ui.graphics.toComposeRect
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.AutofillAmbient
-import androidx.compose.ui.platform.AutofillTreeAmbient
+import androidx.compose.ui.platform.AmbientAutofill
+import androidx.compose.ui.platform.AmbientAutofillTree
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
@@ -55,7 +55,7 @@
Column {
val nameState = remember { mutableStateOf(TextFieldValue("Enter name here")) }
val emailState = remember { mutableStateOf(TextFieldValue("Enter email here")) }
- val autofill = AutofillAmbient.current
+ val autofill = AmbientAutofill.current
val labelStyle = MaterialTheme.typography.subtitle1
val textStyle = MaterialTheme.typography.h6
@@ -121,7 +121,7 @@
) {
val autofillNode = AutofillNode(onFill = onFill, autofillTypes = autofillTypes)
- val autofillTree = AutofillTreeAmbient.current
+ val autofillTree = AmbientAutofillTree.current
autofillTree += autofillNode
Box(
diff --git a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/DragScaleGestureDetectorDemo.kt b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/DragScaleGestureDetectorDemo.kt
index 3af2f38..30ebd121 100644
--- a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/DragScaleGestureDetectorDemo.kt
+++ b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/DragScaleGestureDetectorDemo.kt
@@ -35,7 +35,7 @@
import androidx.compose.ui.gesture.dragGestureFilter
import androidx.compose.ui.gesture.scaleGestureFilter
import androidx.compose.ui.gesture.tapGestureFilter
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.dp
/**
@@ -86,7 +86,7 @@
}
val (offsetX, offsetY) =
- with(DensityAmbient.current) { offset.value.x.toDp() to offset.value.y.toDp() }
+ with(AmbientDensity.current) { offset.value.x.toDp() to offset.value.y.toDp() }
Column {
Text("Demonstrates combining dragging with scaling.")
diff --git a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/LongPressDragGestureDetectorDemo.kt b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/LongPressDragGestureDetectorDemo.kt
index db06d59..8410b39 100644
--- a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/LongPressDragGestureDetectorDemo.kt
+++ b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/LongPressDragGestureDetectorDemo.kt
@@ -32,7 +32,7 @@
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.gesture.LongPressDragObserver
import androidx.compose.ui.gesture.longPressDragGestureFilter
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.dp
/**
@@ -67,7 +67,7 @@
}
val (offsetX, offsetY) =
- with(DensityAmbient.current) { offset.value.x.toDp() to offset.value.y.toDp() }
+ with(AmbientDensity.current) { offset.value.x.toDp() to offset.value.y.toDp() }
Column {
Text("Demonstrates dragging that only begins once a long press has occurred!")
diff --git a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/RawDragGestureDetectorDemo.kt b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/RawDragGestureDetectorDemo.kt
index e0d8f8c..52197f7 100644
--- a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/RawDragGestureDetectorDemo.kt
+++ b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/RawDragGestureDetectorDemo.kt
@@ -32,7 +32,7 @@
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.gesture.DragObserver
import androidx.compose.ui.gesture.rawDragGestureFilter
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.dp
/**
@@ -50,7 +50,7 @@
}
val (offsetX, offsetY) =
- with(DensityAmbient.current) { offset.value.x.toDp() to offset.value.y.toDp() }
+ with(AmbientDensity.current) { offset.value.x.toDp() to offset.value.y.toDp() }
Column {
Text("Demonstrates dragging that starts immediately (no slop or anything else).")
diff --git a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/ScrollGestureFilterDemo.kt b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/ScrollGestureFilterDemo.kt
index 769b83c..36fcf6e 100644
--- a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/ScrollGestureFilterDemo.kt
+++ b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/ScrollGestureFilterDemo.kt
@@ -35,7 +35,7 @@
import androidx.compose.ui.gesture.scrollGestureFilter
import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -71,7 +71,7 @@
val color = remember { mutableStateOf(idleColor) }
val offsetPx = remember { mutableStateOf(0f) }
- val offsetDp = with(DensityAmbient.current) {
+ val offsetDp = with(AmbientDensity.current) {
offsetPx.value.toDp()
}
diff --git a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/TouchSlopDragGestureDetectorDemo.kt b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/TouchSlopDragGestureDetectorDemo.kt
index d8dd6e3..3a9635c 100644
--- a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/TouchSlopDragGestureDetectorDemo.kt
+++ b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/TouchSlopDragGestureDetectorDemo.kt
@@ -34,7 +34,7 @@
import androidx.compose.ui.gesture.DragObserver
import androidx.compose.ui.gesture.dragGestureFilter
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.dp
/**
@@ -105,7 +105,7 @@
}
val (offsetX, offsetY) =
- with(DensityAmbient.current) { offset.value.x.toDp() to offset.value.y.toDp() }
+ with(AmbientDensity.current) { offset.value.x.toDp() to offset.value.y.toDp() }
Column {
Text(
diff --git a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/VerticalScrollerInDrawerLayoutDemo.kt b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/VerticalScrollerInDrawerLayoutDemo.kt
index eba80c7..08f2981 100644
--- a/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/VerticalScrollerInDrawerLayoutDemo.kt
+++ b/compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/VerticalScrollerInDrawerLayoutDemo.kt
@@ -49,7 +49,7 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.clipRect
import androidx.compose.ui.layout.Layout
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -82,7 +82,7 @@
private fun DrawerLayout(drawerWidth: Dp, children: @Composable ColumnScope.() -> Unit) {
val minOffset =
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
-drawerWidth.toPx()
}
diff --git a/compose/ui/ui/samples/build.gradle b/compose/ui/ui/samples/build.gradle
index a3b8fbf..fc02f66 100644
--- a/compose/ui/ui/samples/build.gradle
+++ b/compose/ui/ui/samples/build.gradle
@@ -52,7 +52,6 @@
androidx {
name = "AndroidX Compose UI Core Classes Samples"
type = LibraryType.SAMPLES
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.Compose.UI
inceptionYear = "2019"
description = "Contains the sample code for the Androidx Compose UI Core Classes"
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/AccessibilityIteratorsTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/AccessibilityIteratorsTest.kt
index 14ae4ef..3d022ba 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/AccessibilityIteratorsTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/AccessibilityIteratorsTest.kt
@@ -24,7 +24,7 @@
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.AccessibilityIterators
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
@@ -426,7 +426,7 @@
var textLayoutResult: TextLayoutResult? = null
rule.setContent {
// TODO(yingleiw): use predefined DensityAmbient.current when b/163142237 is fixed.
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
BasicText(
style = TextStyle(
fontSize = fontSize,
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/AndroidComposeViewAccessibilityDelegateCompatTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/AndroidComposeViewAccessibilityDelegateCompatTest.kt
index 9034d88..dfad721 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/AndroidComposeViewAccessibilityDelegateCompatTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/AndroidComposeViewAccessibilityDelegateCompatTest.kt
@@ -26,9 +26,9 @@
import androidx.compose.ui.node.ExperimentalLayoutNodeApi
import androidx.compose.ui.node.InnerPlaceable
import androidx.compose.ui.node.LayoutNode
+import androidx.compose.ui.platform.AmbientClipboardManager
import androidx.compose.ui.platform.AndroidComposeView
import androidx.compose.ui.platform.AndroidComposeViewAccessibilityDelegateCompat
-import androidx.compose.ui.platform.ClipboardManagerAmbient
import androidx.compose.ui.semantics.AccessibilityRangeInfo
import androidx.compose.ui.semantics.AccessibilityScrollState
import androidx.compose.ui.semantics.SemanticsModifierCore
@@ -103,7 +103,7 @@
)
}
rule.setContent {
- ClipboardManagerAmbient.current.setText(AnnotatedString("test"))
+ AmbientClipboardManager.current.setText(AnnotatedString("test"))
}
}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/AndroidLayoutDrawTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/AndroidLayoutDrawTest.kt
index e242569..aac6d31 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/AndroidLayoutDrawTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/AndroidLayoutDrawTest.kt
@@ -77,11 +77,11 @@
import androidx.compose.ui.node.InternalCoreApi
import androidx.compose.ui.node.Owner
import androidx.compose.ui.node.Ref
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.AndroidComposeView
import androidx.compose.ui.platform.AndroidOwnerExtraAssertionsRule
import androidx.compose.ui.platform.ComposeView
-import androidx.compose.ui.platform.DensityAmbient
-import androidx.compose.ui.platform.LayoutDirectionAmbient
import androidx.compose.ui.platform.RenderNodeApi23
import androidx.compose.ui.platform.RenderNodeApi29
import androidx.compose.ui.platform.ViewLayer
@@ -1978,7 +1978,7 @@
val layoutDirection = Ref<LayoutDirection>()
activityTestRule.runOnUiThreadIR {
activity.setContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
FixedSize(
size = 50,
modifier = Modifier.drawBehind {
@@ -2011,7 +2011,7 @@
}
activityTestRule.runOnUiThreadIR {
activity.setContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
FixedSize(
size = 50,
modifier = layoutModifier
@@ -2799,7 +2799,7 @@
var zIndex by mutableStateOf(0f)
activityTestRule.runOnUiThread {
activity.setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
FixedSize(
size = 30,
modifier = Modifier.background(color = Color.Blue).drawLatchModifier()
@@ -3020,7 +3020,7 @@
activityTestRule.runOnUiThread {
view = ComposeView(activity)
view.setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
Box(
Modifier
.background(Color.Blue)
@@ -3064,7 +3064,7 @@
activityTestRule.runOnUiThread {
view = ComposeView(activity)
view.setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
Box(
Modifier
.background(Color.Blue)
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/autofill/AndroidAutoFillTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/autofill/AndroidAutoFillTest.kt
index cfe0cec..f5aa880 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/autofill/AndroidAutoFillTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/autofill/AndroidAutoFillTest.kt
@@ -23,9 +23,9 @@
import androidx.autofill.HintConstants.AUTOFILL_HINT_PERSON_NAME
import androidx.compose.testutils.fake.FakeViewStructure
import androidx.compose.ui.geometry.Rect
-import androidx.compose.ui.platform.AutofillAmbient
-import androidx.compose.ui.platform.AutofillTreeAmbient
-import androidx.compose.ui.platform.ViewAmbient
+import androidx.compose.ui.platform.AmbientAutofill
+import androidx.compose.ui.platform.AmbientAutofillTree
+import androidx.compose.ui.platform.AmbientView
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
@@ -49,9 +49,9 @@
@Before
fun setup() {
rule.setContent {
- ownerView = ViewAmbient.current
- autofill = AutofillAmbient.current
- autofillTree = AutofillTreeAmbient.current
+ ownerView = AmbientView.current
+ autofill = AmbientAutofill.current
+ autofillTree = AmbientAutofillTree.current
}
}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/draw/DrawShadowTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/draw/DrawShadowTest.kt
index 66ec42a..acd1a6f 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/draw/DrawShadowTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/draw/DrawShadowTest.kt
@@ -33,7 +33,7 @@
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.luminance
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.InspectableValue
import androidx.compose.ui.platform.ValueElement
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
@@ -166,7 +166,7 @@
rule.runOnUiThreadIR {
activity.setContent {
AtLeastSize(size = 12, modifier = background(Color.White)) {
- val elevation = with(DensityAmbient.current) { 4.dp.toPx() }
+ val elevation = with(AmbientDensity.current) { 4.dp.toPx() }
AtLeastSize(
size = 10,
modifier = Modifier.drawLayer(
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/draw/PainterModifierTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/draw/PainterModifierTest.kt
index 09458a6..5954ec7 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/draw/PainterModifierTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/draw/PainterModifierTest.kt
@@ -60,9 +60,9 @@
import androidx.compose.ui.layout.Measurable
import androidx.compose.ui.layout.MeasureResult
import androidx.compose.ui.layout.MeasureScope
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.InspectableValue
-import androidx.compose.ui.platform.LayoutDirectionAmbient
import androidx.compose.ui.platform.ValueElement
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
import androidx.compose.ui.platform.testTag
@@ -494,8 +494,8 @@
var composableWidth = 0f
var composableHeight = 0f
rule.setContent {
- composableWidth = composableWidthPx / DensityAmbient.current.density
- composableHeight = composableHeightPx / DensityAmbient.current.density
+ composableWidth = composableWidthPx / AmbientDensity.current.density
+ composableHeight = composableHeightPx / AmbientDensity.current.density
// Because the painter is told to fit inside the constraints, the width should
// match that of the provided fixed width and the height should match that of the
// composable as no scaling is being done
@@ -540,8 +540,8 @@
modifier = Modifier
.testTag(testTag)
.background(color = Color.Gray)
- .width((boxWidth / DensityAmbient.current.density).dp)
- .height((boxHeight / DensityAmbient.current.density).dp)
+ .width((boxWidth / AmbientDensity.current.density).dp)
+ .height((boxHeight / AmbientDensity.current.density).dp)
.paint(ImagePainter(srcImage), contentScale = ContentScale.FillHeight)
)
}
@@ -585,8 +585,8 @@
modifier = Modifier
.testTag(testTag)
.background(color = Color.Gray)
- .width((boxWidth / DensityAmbient.current.density).dp)
- .height((boxHeight / DensityAmbient.current.density).dp)
+ .width((boxWidth / AmbientDensity.current.density).dp)
+ .height((boxHeight / AmbientDensity.current.density).dp)
.paint(ImagePainter(srcImage), contentScale = ContentScale.FillBounds)
)
}
@@ -608,12 +608,12 @@
val vectorWidth = 100
val vectorHeight = 200
rule.setContent {
- val vectorWidthDp = (vectorWidth / DensityAmbient.current.density).dp
- val vectorHeightDp = (vectorHeight / DensityAmbient.current.density).dp
+ val vectorWidthDp = (vectorWidth / AmbientDensity.current.density).dp
+ val vectorHeightDp = (vectorHeight / AmbientDensity.current.density).dp
Box(
modifier = Modifier.background(color = Color.Gray)
- .width((boxWidth / DensityAmbient.current.density).dp)
- .height((boxHeight / DensityAmbient.current.density).dp)
+ .width((boxWidth / AmbientDensity.current.density).dp)
+ .height((boxHeight / AmbientDensity.current.density).dp)
.paint(
rememberVectorPainter(
defaultWidth = vectorWidthDp,
@@ -679,7 +679,7 @@
) {
val p = TestPainter(containerWidth, containerHeight)
val layoutDirection = if (rtl) LayoutDirection.Rtl else LayoutDirection.Ltr
- Providers(LayoutDirectionAmbient provides layoutDirection) {
+ Providers(AmbientLayoutDirection provides layoutDirection) {
AtLeastSize(
modifier = Modifier.background(Color.White)
.paint(p, alpha = alpha, colorFilter = colorFilter),
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/focus/FocusManagerAmbientTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/focus/FocusManagerAmbientTest.kt
index 871fd6b..ccf7260 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/focus/FocusManagerAmbientTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/focus/FocusManagerAmbientTest.kt
@@ -24,7 +24,7 @@
import androidx.compose.ui.focus.FocusState.Inactive
import androidx.compose.ui.focusObserver
import androidx.compose.ui.focusRequester
-import androidx.compose.ui.platform.FocusManagerAmbient
+import androidx.compose.ui.platform.AmbientFocusManager
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
@@ -47,7 +47,7 @@
lateinit var focusRequester: FocusRequester
var focusState = Inactive
rule.setFocusableContent {
- focusManager = FocusManagerAmbient.current
+ focusManager = AmbientFocusManager.current
focusRequester = FocusRequester()
Box(
modifier = Modifier
@@ -77,7 +77,7 @@
var parentFocusState = Inactive
var grandparentFocusState = Inactive
rule.setFocusableContent {
- focusManager = FocusManagerAmbient.current
+ focusManager = AmbientFocusManager.current
focusRequester = FocusRequester()
Box(
modifier = Modifier
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/focus/FocusRequesterTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/focus/FocusRequesterTest.kt
index f1e6593..3f04cfa 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/focus/FocusRequesterTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/focus/FocusRequesterTest.kt
@@ -25,7 +25,7 @@
import androidx.compose.ui.focus.FocusState.Inactive
import androidx.compose.ui.focusObserver
import androidx.compose.ui.focusRequester
-import androidx.compose.ui.platform.ViewAmbient
+import androidx.compose.ui.platform.AmbientView
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
@@ -262,7 +262,7 @@
val focusRequester1 = FocusRequester()
val focusRequester2 = FocusRequester()
rule.setFocusableContent {
- hostView = ViewAmbient.current
+ hostView = AmbientView.current
Column(
modifier = Modifier.focusObserver { focusState = it }
) {
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/focus/OwnerFocusTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/focus/OwnerFocusTest.kt
index 9681b28..88a6397 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/focus/OwnerFocusTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/focus/OwnerFocusTest.kt
@@ -25,7 +25,7 @@
import androidx.compose.ui.focus.FocusState.Inactive
import androidx.compose.ui.focusObserver
import androidx.compose.ui.focusRequester
-import androidx.compose.ui.platform.ViewAmbient
+import androidx.compose.ui.platform.AmbientView
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
@@ -184,5 +184,5 @@
}
@Composable
- private fun getOwner() = ViewAmbient.current
+ private fun getOwner() = AmbientView.current
}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/gesture/ScaleGestureFilterTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/gesture/ScaleGestureFilterTest.kt
index 5e7a49b..a385ae5 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/gesture/ScaleGestureFilterTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/gesture/ScaleGestureFilterTest.kt
@@ -22,7 +22,7 @@
import androidx.compose.runtime.emptyContent
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.InspectableValue
import androidx.compose.ui.platform.ValueElement
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
@@ -74,7 +74,7 @@
activityTestRule.runOnUiThreadIR {
activity.setContent {
Box {
- touchSlop = with(DensityAmbient.current) { TouchSlop.toPx() }
+ touchSlop = with(AmbientDensity.current) { TouchSlop.toPx() }
Layout(
modifier = Modifier.scaleGestureFilter(scaleObserver),
measureBlock = { _, _ ->
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/gesture/TouchSlopDragGestureFilterTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/gesture/TouchSlopDragGestureFilterTest.kt
index 9b94c64..faf3de0 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/gesture/TouchSlopDragGestureFilterTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/gesture/TouchSlopDragGestureFilterTest.kt
@@ -22,7 +22,7 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.Layout
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.test.TestActivity
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -265,7 +265,7 @@
activityTestRule.runOnUiThreadIR {
activity.setContent {
Box {
- touchSlop = with(DensityAmbient.current) { TouchSlop.toPx() }
+ touchSlop = with(AmbientDensity.current) { TouchSlop.toPx() }
Layout(
modifier = Modifier.dragGestureFilter(
dragObserver,
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/vector/VectorInvalidationTestCase.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/vector/VectorInvalidationTestCase.kt
index dfd021f..8355792 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/vector/VectorInvalidationTestCase.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/vector/VectorInvalidationTestCase.kt
@@ -25,7 +25,7 @@
import androidx.compose.ui.draw.paint
import androidx.compose.ui.drawBehind
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.res.loadVectorResource
import androidx.compose.ui.test.R
import java.util.concurrent.CountDownLatch
@@ -47,7 +47,7 @@
vectorState = state
val imageVector = loadVectorResource(state.value)
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
imageVector.resource.resource?.let {
val width = it.defaultWidth
vectorSize = width.toIntPx()
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/vector/VectorTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/vector/VectorTest.kt
index 9439875..febb8ba 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/vector/VectorTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/vector/VectorTest.kt
@@ -39,7 +39,7 @@
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.layout.ContentScale
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.junit4.createComposeRule
@@ -309,7 +309,7 @@
@Composable
private fun createTestVectorPainter(size: Int = 200): VectorPainter {
val sizePx = size.toFloat()
- val sizeDp = (size / DensityAmbient.current.density).dp
+ val sizeDp = (size / AmbientDensity.current.density).dp
return rememberVectorPainter(
defaultWidth = sizeDp,
defaultHeight = sizeDp,
@@ -334,7 +334,7 @@
alignment: Alignment = Alignment.Center
) {
val sizePx = size.toFloat()
- val sizeDp = (size / DensityAmbient.current.density).dp
+ val sizeDp = (size / AmbientDensity.current.density).dp
val background = Modifier.paint(
rememberVectorPainter(
defaultWidth = sizeDp,
@@ -387,7 +387,7 @@
alignment: Alignment = Alignment.Center
) {
val sizePx = size.toFloat()
- val sizeDp = (size / DensityAmbient.current.density).dp
+ val sizeDp = (size / AmbientDensity.current.density).dp
val background = Modifier.paint(
rememberVectorPainter(
defaultWidth = sizeDp,
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/AltMetaKeyTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/AltMetaKeyTest.kt
deleted file mode 100644
index 4f028d8..0000000
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/AltMetaKeyTest.kt
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.compose.ui.input.key
-
-import android.view.KeyEvent.META_ALT_LEFT_ON
-import android.view.KeyEvent.META_ALT_RIGHT_ON
-import androidx.test.ext.junit.runners.AndroidJUnit4
-import androidx.test.filters.SmallTest
-import com.google.common.truth.Truth.assertThat
-import org.junit.Test
-import org.junit.runner.RunWith
-
-@SmallTest
-@RunWith(AndroidJUnit4::class)
-@OptIn(ExperimentalKeyInput::class)
-class AltMetaKeyTest {
-
- @Test
- fun noMetaKeyIsPressed() {
- // Arrange.
- val keyEvent = testKeyEvent()
-
- // Assert.
- assertThat(keyEvent.alt.isPressed).isFalse()
- assertThat(keyEvent.alt.isLeftAltPressed).isFalse()
- assertThat(keyEvent.alt.isRightAltPressed).isFalse()
- }
-
- @Test
- fun altLeftIsPressed() {
- // Arrange.
- val keyEvent = testKeyEvent(androidMetaKeys = META_ALT_LEFT_ON)
-
- // Assert.
- assertThat(keyEvent.alt.isPressed).isTrue()
- assertThat(keyEvent.alt.isLeftAltPressed).isTrue()
- assertThat(keyEvent.alt.isRightAltPressed).isFalse()
- }
-
- @Test
- fun altRightIsPressed() {
- // Arrange.
- val keyEvent = testKeyEvent(androidMetaKeys = META_ALT_RIGHT_ON)
-
- // Assert.
- assertThat(keyEvent.alt.isPressed).isTrue()
- assertThat(keyEvent.alt.isLeftAltPressed).isFalse()
- assertThat(keyEvent.alt.isRightAltPressed).isTrue()
- }
-
- @Test
- fun altLeftAndAltRightArePressed() {
- // Arrange.
- val keyEvent = testKeyEvent(androidMetaKeys = META_ALT_LEFT_ON or META_ALT_RIGHT_ON)
-
- // Assert.
- assertThat(keyEvent.alt.isPressed).isTrue()
- assertThat(keyEvent.alt.isLeftAltPressed).isTrue()
- assertThat(keyEvent.alt.isRightAltPressed).isTrue()
- }
-
- private fun testKeyEvent(androidMetaKeys: Int = 0): KeyEvent {
- return keyEvent(Key.A, KeyEventType.KeyDown, androidMetaKeys)
- }
-}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/AndroidProcessKeyInputTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/AndroidProcessKeyInputTest.kt
index 99e653e..8ed2323 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/AndroidProcessKeyInputTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/AndroidProcessKeyInputTest.kt
@@ -30,7 +30,7 @@
import androidx.compose.ui.input.key.Key.Companion.A
import androidx.compose.ui.input.key.KeyEventType.KeyDown
import androidx.compose.ui.input.key.KeyEventType.KeyUp
-import androidx.compose.ui.platform.ViewAmbient
+import androidx.compose.ui.platform.AmbientView
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.filters.SmallTest
import com.google.common.truth.Truth.assertThat
@@ -67,7 +67,7 @@
lateinit var receivedKeyEvent: KeyEvent
val focusRequester = FocusRequester()
rule.setFocusableContent {
- ownerView = ViewAmbient.current
+ ownerView = AmbientView.current
Box(
modifier = Modifier
.focusRequester(focusRequester)
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/MetaKeyTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/MetaKeyTest.kt
new file mode 100644
index 0000000..d5ca9df
--- /dev/null
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/key/MetaKeyTest.kt
@@ -0,0 +1,133 @@
+/*
+ * 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.compose.ui.input.key
+
+import android.view.KeyEvent.META_ALT_ON
+import android.view.KeyEvent.META_CTRL_ON
+import android.view.KeyEvent.META_META_ON
+import android.view.KeyEvent.META_SHIFT_ON
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+@OptIn(ExperimentalKeyInput::class)
+class MetaKeyTest {
+
+ @Test
+ fun noMetaKeyIsPressed() {
+ // Arrange.
+ val keyEvent = testKeyEvent()
+
+ // Assert.
+ assertThat(keyEvent.isAltPressed).isFalse()
+ assertThat(keyEvent.isCtrlPressed).isFalse()
+ assertThat(keyEvent.isMetaPressed).isFalse()
+ assertThat(keyEvent.isShiftPressed).isFalse()
+ }
+
+ @Test
+ fun altIsPressed() {
+ // Arrange.
+ val keyEvent = testKeyEvent(META_ALT_ON)
+
+ // Assert.
+ assertThat(keyEvent.isAltPressed).isTrue()
+ assertThat(keyEvent.isCtrlPressed).isFalse()
+ assertThat(keyEvent.isMetaPressed).isFalse()
+ assertThat(keyEvent.isShiftPressed).isFalse()
+ }
+
+ @Test
+ fun ctrlIsPressed() {
+ // Arrange.
+ val keyEvent = testKeyEvent(META_CTRL_ON)
+
+ // Assert.
+ assertThat(keyEvent.isAltPressed).isFalse()
+ assertThat(keyEvent.isCtrlPressed).isTrue()
+ assertThat(keyEvent.isMetaPressed).isFalse()
+ assertThat(keyEvent.isShiftPressed).isFalse()
+ }
+
+ @Test
+ fun metaIsPressed() {
+ // Arrange.
+ val keyEvent = testKeyEvent(META_META_ON)
+
+ // Assert.
+ assertThat(keyEvent.isAltPressed).isFalse()
+ assertThat(keyEvent.isCtrlPressed).isFalse()
+ assertThat(keyEvent.isMetaPressed).isTrue()
+ assertThat(keyEvent.isShiftPressed).isFalse()
+ }
+
+ @Test
+ fun shiftIsPressed() {
+ // Arrange.
+ val keyEvent = testKeyEvent(META_SHIFT_ON)
+
+ // Assert.
+ assertThat(keyEvent.isAltPressed).isFalse()
+ assertThat(keyEvent.isCtrlPressed).isFalse()
+ assertThat(keyEvent.isMetaPressed).isFalse()
+ assertThat(keyEvent.isShiftPressed).isTrue()
+ }
+
+ @Test
+ fun CtrlShiftIsPressed() {
+ // Arrange.
+ val keyEvent = testKeyEvent(META_CTRL_ON or META_SHIFT_ON)
+
+ // Assert.
+ assertThat(keyEvent.isAltPressed).isFalse()
+ assertThat(keyEvent.isCtrlPressed).isTrue()
+ assertThat(keyEvent.isMetaPressed).isFalse()
+ assertThat(keyEvent.isShiftPressed).isTrue()
+ }
+
+ @Test
+ fun AltCtrlShiftIsPressed() {
+ // Arrange.
+ val keyEvent = testKeyEvent(META_ALT_ON or META_CTRL_ON or META_SHIFT_ON)
+
+ // Assert.
+ assertThat(keyEvent.isAltPressed).isTrue()
+ assertThat(keyEvent.isCtrlPressed).isTrue()
+ assertThat(keyEvent.isMetaPressed).isFalse()
+ assertThat(keyEvent.isShiftPressed).isTrue()
+ }
+
+ @Test
+ fun AltCtrlMetaShiftIsPressed() {
+ // Arrange.
+ val keyEvent = testKeyEvent(META_ALT_ON or META_CTRL_ON or META_META_ON or META_SHIFT_ON)
+
+ // Assert.
+ assertThat(keyEvent.isAltPressed).isTrue()
+ assertThat(keyEvent.isCtrlPressed).isTrue()
+ assertThat(keyEvent.isMetaPressed).isTrue()
+ assertThat(keyEvent.isShiftPressed).isTrue()
+ }
+
+ private fun testKeyEvent(androidMetaKeys: Int = 0): KeyEvent {
+ return keyEvent(Key.A, KeyEventType.KeyDown, androidMetaKeys)
+ }
+}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/ClipPointerInputTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/ClipPointerInputTest.kt
index bc44401..724b3b4 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/ClipPointerInputTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/ClipPointerInputTest.kt
@@ -29,7 +29,7 @@
import androidx.compose.ui.gesture.PointerCoords
import androidx.compose.ui.gesture.PointerProperties
import androidx.compose.ui.layout.Layout
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.runOnUiThreadIR
import androidx.compose.ui.test.TestActivity
@@ -224,7 +224,7 @@
rule.runOnUiThreadIR {
activity.setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
val children = @Composable {
child(Modifier.offset((-1f).toDp(), (-1f).toDp()).then(loggingPim1))
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/LayerTouchTransformTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/LayerTouchTransformTest.kt
index db6a5de..f2f061c 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/LayerTouchTransformTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/LayerTouchTransformTest.kt
@@ -35,7 +35,7 @@
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.layout.Layout
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.down
@@ -88,11 +88,11 @@
val latchDrawModifier = Modifier.drawBehind { latch?.countDown() }
- val containerDp = (200.0f / DensityAmbient.current.density).dp
- val boxDp = (50.0f / DensityAmbient.current.density).dp
+ val containerDp = (200.0f / AmbientDensity.current.density).dp
+ val boxDp = (50.0f / AmbientDensity.current.density).dp
- val offsetX = (270.0f / DensityAmbient.current.density).dp
- val offsetY = (120.0f / DensityAmbient.current.density).dp
+ val offsetX = (270.0f / AmbientDensity.current.density).dp
+ val offsetY = (120.0f / AmbientDensity.current.density).dp
Box(Modifier.testTag(testTag)) {
SimpleLayout(
modifier = Modifier.fillMaxSize().offset(offsetX, offsetY)
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInteropFilterAndroidViewOffsetsTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInteropFilterAndroidViewOffsetsTest.kt
index 6b7d2ddd..190561d 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInteropFilterAndroidViewOffsetsTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInteropFilterAndroidViewOffsetsTest.kt
@@ -26,8 +26,8 @@
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.ComposeView
-import androidx.compose.ui.platform.DensityAmbient
import androidx.compose.ui.test.TestActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.unit.dp
@@ -90,7 +90,7 @@
)
setPadding(3, 13, 0, 0)
setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
// Box is "three"
Box(
Modifier.padding(start = (2f / density).dp, top = (12f / density).dp)
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInteropFilterComposeHookupTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInteropFilterComposeHookupTest.kt
index d1257c4..ab8ec19 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInteropFilterComposeHookupTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInteropFilterComposeHookupTest.kt
@@ -25,8 +25,8 @@
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.ComposeView
-import androidx.compose.ui.platform.DensityAmbient
import androidx.compose.ui.test.TestActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -63,7 +63,7 @@
val parent = ComposeView(activity).apply {
setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
Box(
modifier = Modifier
.spyGestureFilter {
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/LayoutDensityTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/LayoutDensityTest.kt
index 7fa4fc5..06d73c6 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/LayoutDensityTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/LayoutDensityTest.kt
@@ -20,7 +20,7 @@
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.Density
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -45,7 +45,7 @@
var measureScopeDensity = 0f
var measureScopeFontScale = 0f
rule.setContent {
- Providers(DensityAmbient provides Density(ambientDensity, ambientFontScale)) {
+ Providers(AmbientDensity provides Density(ambientDensity, ambientFontScale)) {
Layout({}) { _, _ ->
measureScopeDensity = density
measureScopeFontScale = fontScale
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/OnGloballyPositionedTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/OnGloballyPositionedTest.kt
index a04c888..e5a6502 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/OnGloballyPositionedTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/OnGloballyPositionedTest.kt
@@ -35,8 +35,8 @@
import androidx.compose.ui.Wrap
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.ComposeView
-import androidx.compose.ui.platform.DensityAmbient
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.runOnUiThreadIR
import androidx.compose.ui.test.TestActivity
@@ -395,7 +395,7 @@
rule.runOnUiThread {
activity.setContent {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
DelayedMeasure(50) {
Box(Modifier.size(25.toDp())) {
Box(
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/OnSizeChangedTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/OnSizeChangedTest.kt
index 1393e09..89f2f97 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/OnSizeChangedTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/OnSizeChangedTest.kt
@@ -23,7 +23,7 @@
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.test.TestActivity
import androidx.compose.ui.unit.IntSize
@@ -64,7 +64,7 @@
rule.runOnUiThread {
activity.setContent {
- with (DensityAmbient.current) {
+ with (AmbientDensity.current) {
Box(
Modifier.padding(10.toDp()).onSizeChanged {
changedSize = it
@@ -99,7 +99,7 @@
rule.runOnUiThread {
activity.setContent {
- with (DensityAmbient.current) {
+ with (AmbientDensity.current) {
Box(
Modifier.padding(sizePx.toDp()).onSizeChanged {
changedSize = it
@@ -132,7 +132,7 @@
rule.runOnUiThread {
activity.setContent {
- with (DensityAmbient.current) {
+ with (AmbientDensity.current) {
Box(
Modifier.padding(10.toDp()).onSizeChanged {
changedSize = it
@@ -171,7 +171,7 @@
rule.runOnUiThread {
activity.setContent {
- with (DensityAmbient.current) {
+ with (AmbientDensity.current) {
val mod = if (addModifier) Modifier.onSizeChanged {
changedSize2 = it
latch2.countDown()
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/RtlLayoutTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/RtlLayoutTest.kt
index 5adf0f7..02dabef 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/RtlLayoutTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/RtlLayoutTest.kt
@@ -23,7 +23,7 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.node.Ref
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.runOnUiThreadIR
import androidx.compose.ui.test.TestActivity
@@ -173,7 +173,7 @@
layout(100, 100) {}
}
}
- Providers(LayoutDirectionAmbient provides direction.value) {
+ Providers(AmbientLayoutDirection provides direction.value) {
Layout(children) { measurables, constraints ->
layout(100, 100) {
measurables.first().measure(constraints).placeRelative(0, 0)
@@ -197,7 +197,7 @@
absolutePositioning: Boolean,
testLayoutDirection: LayoutDirection
) {
- Providers(LayoutDirectionAmbient provides testLayoutDirection) {
+ Providers(AmbientLayoutDirection provides testLayoutDirection) {
Layout(
children = @Composable {
FixedSize(size, modifier = saveLayoutInfo(position[0], countDownLatch)) {
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/SubcomposeLayoutTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/SubcomposeLayoutTest.kt
index 2c990fc..d49e031 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/SubcomposeLayoutTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/SubcomposeLayoutTest.kt
@@ -33,9 +33,9 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asAndroidBitmap
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.AndroidOwnerExtraAssertionsRule
import androidx.compose.ui.platform.ComposeView
-import androidx.compose.ui.platform.DensityAmbient
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertHeightIsEqualTo
import androidx.compose.ui.test.assertIsDisplayed
@@ -455,7 +455,7 @@
val size = 50.dp
val density = Density(3f)
val sizeIpx = with(density) { size.toIntPx() }
- Providers(DensityAmbient provides density) {
+ Providers(AmbientDensity provides density) {
SubcomposeLayout<Unit>(
Modifier.size(size).onGloballyPositioned {
assertThat(it.size).isEqualTo(IntSize(sizeIpx, sizeIpx))
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/WithConstraintsTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/WithConstraintsTest.kt
index 9a7ab5d..1725d81 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/WithConstraintsTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/layout/WithConstraintsTest.kt
@@ -38,8 +38,8 @@
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.node.Ref
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.AndroidOwnerExtraAssertionsRule
-import androidx.compose.ui.platform.DensityAmbient
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.runOnUiThreadIR
import androidx.compose.ui.test.TestActivity
@@ -682,7 +682,7 @@
Layout(
children = @Composable {
WithConstraints {
- with(DensityAmbient.current) {
+ with(AmbientDensity.current) {
assertEquals(minWidthConstraint.toIntPx(), minWidth.toIntPx())
assertEquals(maxWidthConstraint.toIntPx(), maxWidth.toIntPx())
assertEquals(minHeightConstraint.toIntPx(), minHeight.toIntPx())
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/lifecycleowner/LifecycleOwnerInAppCompatActivityTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/lifecycleowner/LifecycleOwnerInAppCompatActivityTest.kt
index 1a8f5f8..c047445 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/lifecycleowner/LifecycleOwnerInAppCompatActivityTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/lifecycleowner/LifecycleOwnerInAppCompatActivityTest.kt
@@ -17,8 +17,8 @@
package androidx.compose.ui.lifecycleowner
import androidx.appcompat.app.AppCompatActivity
+import androidx.compose.ui.platform.AmbientLifecycleOwner
import androidx.compose.ui.platform.ComposeView
-import androidx.compose.ui.platform.LifecycleOwnerAmbient
import androidx.compose.ui.platform.setContent
import androidx.lifecycle.LifecycleOwner
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -54,7 +54,7 @@
activityTestRule.runOnUiThread {
activity.setContent {
- owner = LifecycleOwnerAmbient.current
+ owner = AmbientLifecycleOwner.current
latch.countDown()
}
}
@@ -72,7 +72,7 @@
val view = ComposeView(activity)
activity.setContentView(view)
view.setContent {
- owner = LifecycleOwnerAmbient.current
+ owner = AmbientLifecycleOwner.current
latch.countDown()
}
}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/lifecycleowner/LifecycleOwnerInComponentActivityTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/lifecycleowner/LifecycleOwnerInComponentActivityTest.kt
index ba9f83a..59e1f94 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/lifecycleowner/LifecycleOwnerInComponentActivityTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/lifecycleowner/LifecycleOwnerInComponentActivityTest.kt
@@ -17,8 +17,8 @@
package androidx.compose.ui.lifecycleowner
import androidx.activity.ComponentActivity
+import androidx.compose.ui.platform.AmbientLifecycleOwner
import androidx.compose.ui.platform.ComposeView
-import androidx.compose.ui.platform.LifecycleOwnerAmbient
import androidx.compose.ui.platform.setContent
import androidx.lifecycle.LifecycleOwner
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -54,7 +54,7 @@
activityTestRule.runOnUiThread {
activity.setContent {
- owner = LifecycleOwnerAmbient.current
+ owner = AmbientLifecycleOwner.current
latch.countDown()
}
}
@@ -72,7 +72,7 @@
val view = ComposeView(activity)
activity.setContentView(view)
view.setContent {
- owner = LifecycleOwnerAmbient.current
+ owner = AmbientLifecycleOwner.current
latch.countDown()
}
}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/lifecycleowner/LifecycleOwnerInFragmentTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/lifecycleowner/LifecycleOwnerInFragmentTest.kt
index 1f638ae..234d49c 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/lifecycleowner/LifecycleOwnerInFragmentTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/lifecycleowner/LifecycleOwnerInFragmentTest.kt
@@ -19,8 +19,8 @@
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
+import androidx.compose.ui.platform.AmbientLifecycleOwner
import androidx.compose.ui.platform.ComposeView
-import androidx.compose.ui.platform.LifecycleOwnerAmbient
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentContainerView
@@ -80,7 +80,7 @@
savedInstanceState: Bundle?
) = ComposeView(requireContext()).apply {
setContent {
- owner = LifecycleOwnerAmbient.current
+ owner = AmbientLifecycleOwner.current
latch.countDown()
}
}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/node/HotReloadTests.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/node/HotReloadTests.kt
index bc92ae2..5a81e2e 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/node/HotReloadTests.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/node/HotReloadTests.kt
@@ -27,7 +27,7 @@
import androidx.compose.runtime.onCommit
import androidx.compose.runtime.simulateHotReload
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.accessibilityLabel
@@ -66,7 +66,7 @@
var value = "First value"
@Composable fun text(text: String, id: Int = -1) {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
emit<TextView, UiApplier>(
ctor = { TextView(context) },
update = {
@@ -77,7 +77,7 @@
}
@Composable fun column(children: @Composable () -> Unit) {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
emit<LinearLayout, UiApplier>(
ctor = { LinearLayout(context) },
update = {},
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/AndroidViewCompatTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/AndroidViewCompatTest.kt
index c8c4772..6a797b4 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/AndroidViewCompatTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/platform/AndroidViewCompatTest.kt
@@ -410,7 +410,7 @@
var size by mutableStateOf(20)
rule.setContent {
Box(Modifier.drawLayer().fillMaxSize()) {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
val view = remember { View(context) }
AndroidView({ view }, Modifier.testTag("view"))
view.layoutParams = ViewGroup.LayoutParams(size, size)
@@ -438,7 +438,7 @@
rule.setContent {
Box(Modifier.onGloballyPositioned { outer = it.globalPosition }) {
- val paddingDp = with(DensityAmbient.current) { padding.toDp() }
+ val paddingDp = with(AmbientDensity.current) { padding.toDp() }
Box(Modifier.padding(paddingDp)) {
AndroidView(::ComposeView) {
it.setContent {
@@ -478,7 +478,7 @@
view.setContent {
Box {
- val paddingDp = with(DensityAmbient.current) { padding.toDp() }
+ val paddingDp = with(AmbientDensity.current) { padding.toDp() }
Box(Modifier.padding(paddingDp)) {
AndroidView(::ComposeView) {
it.setContent {
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/ColorResourcesTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/ColorResourcesTest.kt
index 588427b..8de8d7e 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/ColorResourcesTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/ColorResourcesTest.kt
@@ -18,7 +18,7 @@
import androidx.compose.runtime.Providers
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.test.R
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -41,7 +41,7 @@
val context = InstrumentationRegistry.getInstrumentation().targetContext
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
assertThat(colorResource(R.color.color_resource))
.isEqualTo(Color(0x12345678))
}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/FontResourcesTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/FontResourcesTest.kt
index 9654b18..8d188a1 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/FontResourcesTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/FontResourcesTest.kt
@@ -17,9 +17,9 @@
package androidx.compose.ui.res
import androidx.compose.runtime.Providers
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.test.junit4.createComposeRule
-import androidx.compose.ui.text.Typeface
+import androidx.compose.ui.text.font.Typeface
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.font.asFontFamily
@@ -49,7 +49,7 @@
var syncLoadedTypeface: Typeface? = null
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
// async API
result = loadFontResource(
@@ -77,7 +77,7 @@
val context = InstrumentationRegistry.getInstrumentation().targetContext
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
loadFontResource(
fontFamily = font(R.font.sample_font).asFontFamily(),
pendingFontFamily = font(R.font.sample_font).asFontFamily(),
@@ -92,7 +92,7 @@
val context = InstrumentationRegistry.getInstrumentation().targetContext
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
loadFontResource(
fontFamily = font(R.font.sample_font).asFontFamily(),
pendingFontFamily = FontFamily.Serif,
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/PrimitiveResourcesTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/PrimitiveResourcesTest.kt
index 33d5f20..e836941 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/PrimitiveResourcesTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/PrimitiveResourcesTest.kt
@@ -17,7 +17,7 @@
package androidx.compose.ui.res
import androidx.compose.runtime.Providers
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.test.R
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.dp
@@ -41,7 +41,7 @@
val context = InstrumentationRegistry.getInstrumentation().targetContext
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
assertThat(integerResource(R.integer.integer_value)).isEqualTo(123)
}
}
@@ -52,7 +52,7 @@
val context = InstrumentationRegistry.getInstrumentation().targetContext
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
assertThat(integerArrayResource(R.array.integer_array))
.isEqualTo(intArrayOf(234, 345))
}
@@ -64,7 +64,7 @@
val context = InstrumentationRegistry.getInstrumentation().targetContext
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
assertThat(booleanResource(R.bool.boolean_value)).isTrue()
}
}
@@ -75,7 +75,7 @@
val context = InstrumentationRegistry.getInstrumentation().targetContext
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
assertThat(dimensionResource(R.dimen.dimension_value)).isEqualTo(32.dp)
}
}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/ResourcesTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/ResourcesTest.kt
index b47ba46..ab7dc0b 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/ResourcesTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/ResourcesTest.kt
@@ -21,7 +21,7 @@
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.graphics.imageFromResource
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.test.R
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -70,7 +70,7 @@
var res: DeferredResource<ImageBitmap>? = null
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
res = loadResourceInternal(
key = "random key string",
pendingResource = pendingImage,
@@ -133,7 +133,7 @@
var res: DeferredResource<ImageBitmap>? = null
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
res = loadResourceInternal(
key = "random key string",
pendingResource = pendingImage,
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/StringResourcesTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/StringResourcesTest.kt
index 9dce3fd..8bcbfcc 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/StringResourcesTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/res/StringResourcesTest.kt
@@ -17,7 +17,7 @@
package androidx.compose.ui.res
import androidx.compose.runtime.Providers
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.test.R
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -53,7 +53,7 @@
fun stringResource_not_localized_defaultLocale() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
assertThat(stringResource(R.string.not_localized)).isEqualTo(NotLocalizedText)
}
}
@@ -70,7 +70,7 @@
)
rule.setContent {
- Providers(ContextAmbient provides spanishContext) {
+ Providers(AmbientContext provides spanishContext) {
assertThat(stringResource(R.string.not_localized)).isEqualTo(NotLocalizedText)
}
}
@@ -80,7 +80,7 @@
fun stringResource_localized_defaultLocale() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
assertThat(stringResource(R.string.localized))
.isEqualTo(DefaultLocalizedText)
}
@@ -98,7 +98,7 @@
)
rule.setContent {
- Providers(ContextAmbient provides spanishContext) {
+ Providers(AmbientContext provides spanishContext) {
assertThat(stringResource(R.string.localized))
.isEqualTo(SpanishLocalizedText)
}
@@ -109,7 +109,7 @@
fun stringResource_not_localized_format_defaultLocale() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
assertThat(stringResource(R.string.not_localized_format, FormatValue))
.isEqualTo(NotLocalizedFormatText)
}
@@ -127,7 +127,7 @@
)
rule.setContent {
- Providers(ContextAmbient provides spanishContext) {
+ Providers(AmbientContext provides spanishContext) {
assertThat(stringResource(R.string.not_localized_format, FormatValue))
.isEqualTo(NotLocalizedFormatText)
}
@@ -138,7 +138,7 @@
fun stringResource_localized_format_defaultLocale() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
assertThat(stringResource(R.string.localized_format, FormatValue))
.isEqualTo(DefaultLocalizedFormatText)
}
@@ -156,7 +156,7 @@
)
rule.setContent {
- Providers(ContextAmbient provides spanishContext) {
+ Providers(AmbientContext provides spanishContext) {
assertThat(stringResource(R.string.localized_format, FormatValue))
.isEqualTo(SpanishLocalizedFormatText)
}
@@ -168,7 +168,7 @@
val context = InstrumentationRegistry.getInstrumentation().targetContext
rule.setContent {
- Providers(ContextAmbient provides context) {
+ Providers(AmbientContext provides context) {
assertThat(stringArrayResource(R.array.string_array))
.isEqualTo(arrayOf("string1", "string2"))
}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/selection/SelectionHandlePopupPositionTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/selection/SelectionHandlePopupPositionTest.kt
index a4abc30..85a1ce1 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/selection/SelectionHandlePopupPositionTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/selection/SelectionHandlePopupPositionTest.kt
@@ -23,7 +23,8 @@
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.node.Owner
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
+import androidx.compose.ui.platform.AmbientView
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.text.InternalTextApi
@@ -155,7 +156,7 @@
rule.setContent {
// Get the compose view position on screen
- val composeView = androidx.compose.ui.platform.ViewAmbient.current
+ val composeView = AmbientView.current
val positionArray = IntArray(2)
composeView.getLocationOnScreen(positionArray)
composeViewAbsolutePos = IntOffset(
@@ -166,7 +167,7 @@
// Align the parent of the popup on the top left corner, this results in the global
// position of the parent to be (0, 0)
val layoutDirection = if (isRtl) LayoutDirection.Rtl else LayoutDirection.Ltr
- Providers(LayoutDirectionAmbient provides layoutDirection) {
+ Providers(AmbientLayoutDirection provides layoutDirection) {
SimpleLayout {
SimpleContainer(width = parentWidthDp, height = parentHeightDp) {}
SelectionHandle(
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/AndroidViewTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/AndroidViewTest.kt
index 69a3f0f..bda5092 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/AndroidViewTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/AndroidViewTest.kt
@@ -38,8 +38,8 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onGloballyPositioned
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.ComposeView
-import androidx.compose.ui.platform.DensityAmbient
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.R
import androidx.compose.ui.test.captureToImage
@@ -326,7 +326,7 @@
val size = 50.dp
val density = Density(3f)
val sizeIpx = with(density) { size.toIntPx() }
- Providers(DensityAmbient provides density) {
+ Providers(AmbientDensity provides density) {
AndroidView(
{ FrameLayout(it) },
Modifier.size(size).onGloballyPositioned {
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ComposeViewTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ComposeViewTest.kt
index 03f2c14..7b461bf 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ComposeViewTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ComposeViewTest.kt
@@ -19,6 +19,7 @@
import android.content.Context
import android.view.View
import android.view.ViewGroup
+import android.view.ViewTreeObserver
import androidx.activity.ComponentActivity
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
@@ -34,6 +35,7 @@
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
+import androidx.compose.ui.unit.IntSize
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
@@ -165,6 +167,30 @@
}
@Test
+ fun viewSizeIsChildSizePlusPaddings() {
+ var size = IntSize.Zero
+ val latch = CountDownLatch(1)
+ rule.activityRule.scenario.onActivity { activity ->
+ val composeView = ComposeView(activity)
+ composeView.setPadding(10, 20, 30, 40)
+ activity.setContentView(composeView, ViewGroup.LayoutParams(100, 100))
+ composeView.viewTreeObserver.addOnPreDrawListener(
+ object : ViewTreeObserver.OnPreDrawListener {
+ override fun onPreDraw(): Boolean {
+ composeView.viewTreeObserver.removeOnPreDrawListener(this)
+ size = IntSize(composeView.measuredWidth, composeView.measuredHeight)
+ latch.countDown()
+ return true
+ }
+ }
+ )
+ }
+
+ assertTrue(latch.await(1, TimeUnit.SECONDS))
+ assertEquals(IntSize(100, 100), size)
+ }
+
+ @Test
@SmallTest
fun throwsOnAddView() {
rule.activityRule.scenario.onActivity { activity ->
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/EditTextInteropTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/EditTextInteropTest.kt
index b000a0a..03c512c 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/EditTextInteropTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/EditTextInteropTest.kt
@@ -21,7 +21,7 @@
import android.widget.EditText
import androidx.activity.ComponentActivity
import androidx.compose.ui.focus.ExperimentalFocus
-import androidx.compose.ui.platform.ViewAmbient
+import androidx.compose.ui.platform.AmbientView
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.text.InternalTextApi
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -44,7 +44,7 @@
lateinit var editText: EditText
lateinit var ownerView: View
rule.setContent {
- ownerView = ViewAmbient.current
+ ownerView = AmbientView.current
AndroidView({
EditText(it).apply { width = 500; editText = this }
})
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ViewModelInAppCompatActivityTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ViewModelInAppCompatActivityTest.kt
index 82bd026..548434f8 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ViewModelInAppCompatActivityTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ViewModelInAppCompatActivityTest.kt
@@ -17,8 +17,8 @@
package androidx.compose.ui.viewinterop
import androidx.appcompat.app.AppCompatActivity
+import androidx.compose.ui.platform.AmbientLifecycleOwner
import androidx.compose.ui.platform.ComposeView
-import androidx.compose.ui.platform.LifecycleOwnerAmbient
import androidx.compose.ui.platform.setContent
import androidx.lifecycle.LifecycleOwner
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -54,7 +54,7 @@
activityTestRule.runOnUiThread {
activity.setContent {
- owner = LifecycleOwnerAmbient.current
+ owner = AmbientLifecycleOwner.current
latch.countDown()
}
}
@@ -72,7 +72,7 @@
val view = ComposeView(activity)
activity.setContentView(view)
view.setContent {
- owner = LifecycleOwnerAmbient.current
+ owner = AmbientLifecycleOwner.current
latch.countDown()
}
}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ViewModelInComponentActivityTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ViewModelInComponentActivityTest.kt
index 62ad01d..5a5d8b2 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ViewModelInComponentActivityTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ViewModelInComponentActivityTest.kt
@@ -17,8 +17,8 @@
package androidx.compose.ui.viewinterop
import androidx.activity.ComponentActivity
+import androidx.compose.ui.platform.AmbientLifecycleOwner
import androidx.compose.ui.platform.ComposeView
-import androidx.compose.ui.platform.LifecycleOwnerAmbient
import androidx.compose.ui.platform.setContent
import androidx.lifecycle.LifecycleOwner
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -54,7 +54,7 @@
activityTestRule.runOnUiThread {
activity.setContent {
- owner = LifecycleOwnerAmbient.current
+ owner = AmbientLifecycleOwner.current
latch.countDown()
}
}
@@ -72,7 +72,7 @@
val view = ComposeView(activity)
activity.setContentView(view)
view.setContent {
- owner = LifecycleOwnerAmbient.current
+ owner = AmbientLifecycleOwner.current
latch.countDown()
}
}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ViewModelTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ViewModelTest.kt
index b74bb2b..57b10df 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ViewModelTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/viewinterop/ViewModelTest.kt
@@ -17,7 +17,7 @@
package androidx.compose.ui.viewinterop
import androidx.compose.runtime.Providers
-import androidx.compose.ui.platform.ViewModelStoreOwnerAmbient
+import androidx.compose.ui.platform.AmbientViewModelStoreOwner
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.lifecycle.HasDefaultViewModelProviderFactory
import androidx.lifecycle.ViewModel
@@ -42,7 +42,7 @@
fun viewModelCreatedViaDefaultFactory() {
val owner = FakeViewModelStoreOwner()
rule.setContent {
- Providers(ViewModelStoreOwnerAmbient provides owner) {
+ Providers(AmbientViewModelStoreOwner provides owner) {
viewModel<TestViewModel>()
}
}
@@ -55,7 +55,7 @@
val owner = FakeViewModelStoreOwner()
var createdInComposition: Any? = null
rule.setContent {
- Providers(ViewModelStoreOwnerAmbient provides owner) {
+ Providers(AmbientViewModelStoreOwner provides owner) {
createdInComposition = viewModel<TestViewModel>()
}
}
@@ -70,7 +70,7 @@
val owner = FakeViewModelStoreOwner()
var createdInComposition: Any? = null
rule.setContent {
- Providers(ViewModelStoreOwnerAmbient provides owner) {
+ Providers(AmbientViewModelStoreOwner provides owner) {
createdInComposition = viewModel<TestViewModel>()
}
}
@@ -85,7 +85,7 @@
val owner = FakeViewModelStoreOwner()
var createdInComposition: Any? = null
rule.setContent {
- Providers(ViewModelStoreOwnerAmbient provides owner) {
+ Providers(AmbientViewModelStoreOwner provides owner) {
createdInComposition = viewModel<TestViewModel>(key = "test")
}
}
@@ -100,7 +100,7 @@
val owner = FakeViewModelStoreOwner()
val customFactory = FakeViewModelProviderFactory()
rule.setContent {
- Providers(ViewModelStoreOwnerAmbient provides owner) {
+ Providers(AmbientViewModelStoreOwner provides owner) {
viewModel<TestViewModel>(factory = customFactory)
}
}
@@ -113,7 +113,7 @@
val owner = FakeViewModelStoreOwner()
val customFactory = FakeViewModelProviderFactory()
rule.setContent {
- Providers(ViewModelStoreOwnerAmbient provides owner) {
+ Providers(AmbientViewModelStoreOwner provides owner) {
viewModel<TestViewModel>(factory = customFactory)
}
}
@@ -127,7 +127,7 @@
var createdInComposition: Any? = null
val customFactory = FakeViewModelProviderFactory()
rule.setContent {
- Providers(ViewModelStoreOwnerAmbient provides owner) {
+ Providers(AmbientViewModelStoreOwner provides owner) {
createdInComposition = viewModel<TestViewModel>()
}
}
@@ -143,7 +143,7 @@
var createdInComposition: Any? = null
val customFactory = FakeViewModelProviderFactory()
rule.setContent {
- Providers(ViewModelStoreOwnerAmbient provides owner) {
+ Providers(AmbientViewModelStoreOwner provides owner) {
createdInComposition = viewModel<TestViewModel>(key = "test")
}
}
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/window/PopupAlignmentTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/window/PopupAlignmentTest.kt
index 23dcbf0..0c11a13 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/window/PopupAlignmentTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/window/PopupAlignmentTest.kt
@@ -24,8 +24,8 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.LayoutDirectionAmbient
-import androidx.compose.ui.platform.ViewAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
+import androidx.compose.ui.platform.AmbientView
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.IntBounds
import androidx.compose.ui.unit.IntOffset
@@ -308,7 +308,7 @@
rule.setContent {
// Get the compose view position on screen
- val composeView = ViewAmbient.current
+ val composeView = AmbientView.current
val positionArray = IntArray(2)
composeView.getLocationOnScreen(positionArray)
composeViewAbsolutePos = IntOffset(
@@ -320,7 +320,7 @@
// position of the parent to be (0, 0)
TestAlign {
val layoutDirection = if (isRtl) LayoutDirection.Rtl else LayoutDirection.Ltr
- Providers(LayoutDirectionAmbient provides layoutDirection) {
+ Providers(AmbientLayoutDirection provides layoutDirection) {
SimpleContainer(width = parentWidthDp, height = parentHeightDp) {
PopupTestTag(testTag) {
Popup(alignment = alignment, offset = offset) {
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/window/PopupTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/window/PopupTest.kt
index 3814a23..a5fa107 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/window/PopupTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/window/PopupTest.kt
@@ -30,7 +30,7 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.node.Owner
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
@@ -215,9 +215,9 @@
fun preservesLayoutDirection() {
var value = LayoutDirection.Ltr
rule.setContent {
- Providers(LayoutDirectionAmbient provides LayoutDirection.Rtl) {
+ Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {
Popup {
- value = LayoutDirectionAmbient.current
+ value = AmbientLayoutDirection.current
}
}
}
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/input/key/KeyEventAndroid.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/input/key/KeyEventAndroid.kt
index 4e04543..b5a86d7 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/input/key/KeyEventAndroid.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/input/key/KeyEventAndroid.kt
@@ -41,11 +41,24 @@
ACTION_UP -> KeyUp
else -> Unknown
}
+ override val isAltPressed: Boolean
+ get() = keyEvent.isAltPressed
+ override val isCtrlPressed: Boolean
+ get() = keyEvent.isCtrlPressed
+
+ override val isMetaPressed: Boolean
+ get() = keyEvent.isMetaPressed
+
+ override val isShiftPressed: Boolean
+ get() = keyEvent.isShiftPressed
+
+ @Suppress("DEPRECATION", "OverridingDeprecatedMember")
override val alt: Alt
get() = AltAndroid(keyEvent)
}
+@Suppress("DEPRECATION")
@OptIn(ExperimentalKeyInput::class)
internal inline class AltAndroid(val keyEvent: AndroidKeyEvent) : Alt {
override val isLeftAltPressed
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidAmbients.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidAmbients.kt
index 39abd69..e5c8bf2 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidAmbients.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidAmbients.kt
@@ -30,7 +30,7 @@
import androidx.compose.runtime.neverEqualPolicy
import androidx.compose.runtime.onDispose
import androidx.compose.runtime.remember
-import androidx.compose.runtime.savedinstancestate.UiSavedStateRegistryAmbient
+import androidx.compose.runtime.savedinstancestate.AmbientUiSavedStateRegistry
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticAmbientOf
import androidx.lifecycle.LifecycleOwner
@@ -40,7 +40,21 @@
* The Android [Configuration]. The [Configuration] is useful for determining how to organize the
* UI.
*/
-val ConfigurationAmbient = ambientOf<Configuration>(
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientConfiguration",
+ replaceWith = ReplaceWith(
+ "AmbientConfiguration",
+ "androidx.compose.ui.platform.AmbientConfiguration"
+ )
+)
+val ConfigurationAmbient get() = AmbientConfiguration
+
+/**
+ * The Android [Configuration]. The [Configuration] is useful for determining how to organize the
+ * UI.
+ */
+val AmbientConfiguration = ambientOf<Configuration>(
@OptIn(ExperimentalComposeApi::class)
neverEqualPolicy()
)
@@ -48,22 +62,74 @@
/**
* Provides a [Context] that can be used by Android applications.
*/
-val ContextAmbient = staticAmbientOf<Context>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientContext",
+ replaceWith = ReplaceWith(
+ "AmbientContext",
+ "androidx.compose.ui.platform.AmbientContext"
+ )
+)
+val ContextAmbient get() = AmbientContext
+
+/**
+ * Provides a [Context] that can be used by Android applications.
+ */
+val AmbientContext = staticAmbientOf<Context>()
/**
* The ambient containing the current [LifecycleOwner].
*/
-val LifecycleOwnerAmbient = staticAmbientOf<LifecycleOwner>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientLifecycleOwner",
+ replaceWith = ReplaceWith(
+ "AmbientLifecycleOwner",
+ "androidx.compose.ui.platform.AmbientLifecycleOwner"
+ )
+)
+val LifecycleOwnerAmbient get() = AmbientLifecycleOwner
+
+/**
+ * The ambient containing the current [LifecycleOwner].
+ */
+val AmbientLifecycleOwner = staticAmbientOf<LifecycleOwner>()
/**
* The ambient containing the current Compose [View].
*/
-val ViewAmbient = staticAmbientOf<View>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientView",
+ replaceWith = ReplaceWith(
+ "AmbientView",
+ "androidx.compose.ui.platform.AmbientView"
+ )
+)
+val ViewAmbient get() = AmbientView
+
+/**
+ * The ambient containing the current Compose [View].
+ */
+val AmbientView = staticAmbientOf<View>()
/**
* The ambient containing the current [ViewModelStoreOwner].
*/
-val ViewModelStoreOwnerAmbient = staticAmbientOf<ViewModelStoreOwner>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientViewModelStoreOwner",
+ replaceWith = ReplaceWith(
+ "AmbientViewModelStoreOwner",
+ "androidx.compose.ui.platform.AmbientViewModelStoreOwner"
+ )
+)
+val ViewModelStoreOwnerAmbient get() = AmbientViewModelStoreOwner
+
+/**
+ * The ambient containing the current [ViewModelStoreOwner].
+ */
+val AmbientViewModelStoreOwner = staticAmbientOf<ViewModelStoreOwner>()
@Composable
@OptIn(InternalAnimationApi::class)
@@ -95,12 +161,12 @@
}
Providers(
- ConfigurationAmbient provides configuration,
- ContextAmbient provides context,
- LifecycleOwnerAmbient provides viewTreeOwners.lifecycleOwner,
- UiSavedStateRegistryAmbient provides uiSavedStateRegistry,
- ViewAmbient provides owner.view,
- ViewModelStoreOwnerAmbient provides viewTreeOwners.viewModelStoreOwner
+ AmbientConfiguration provides configuration,
+ AmbientContext provides context,
+ AmbientLifecycleOwner provides viewTreeOwners.lifecycleOwner,
+ AmbientUiSavedStateRegistry provides uiSavedStateRegistry,
+ AmbientView provides owner.view,
+ AmbientViewModelStoreOwner provides viewTreeOwners.viewModelStoreOwner
) {
ProvideCommonAmbients(
owner = owner,
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/ComposeView.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/ComposeView.kt
index 197b625..825c0c0 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/ComposeView.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/ComposeView.kt
@@ -205,7 +205,10 @@
MeasureSpec.makeMeasureSpec(width, MeasureSpec.getMode(widthMeasureSpec)),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.getMode(heightMeasureSpec)),
)
- setMeasuredDimension(child.measuredWidthAndState, child.measuredHeightAndState)
+ setMeasuredDimension(
+ child.measuredWidth + paddingLeft + paddingRight,
+ child.measuredHeight + paddingTop + paddingBottom
+ )
}
final override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/Wrapper.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/Wrapper.kt
index 334ca59..562a02c 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/Wrapper.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/Wrapper.kt
@@ -71,7 +71,7 @@
}
).apply {
setContent {
- Providers(ContextAmbient provides this@setViewContent.context) {
+ Providers(AmbientContext provides this@setViewContent.context) {
composable()
}
}
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/ColorResources.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/ColorResources.kt
index 827d1e8..8bc1caf 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/ColorResources.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/ColorResources.kt
@@ -20,7 +20,7 @@
import androidx.annotation.ColorRes
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
/**
* Load a color resource.
@@ -30,7 +30,7 @@
*/
@Composable
fun colorResource(@ColorRes id: Int): Color {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
return if (Build.VERSION.SDK_INT >= 23) {
Color(context.resources.getColor(id, context.theme))
} else {
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/FontResources.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/FontResources.kt
index 1266a37..d85b45d 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/FontResources.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/FontResources.kt
@@ -20,14 +20,14 @@
import android.util.TypedValue
import androidx.annotation.GuardedBy
import androidx.compose.runtime.Composable
-import androidx.compose.ui.platform.ContextAmbient
-import androidx.compose.ui.text.Typeface
+import androidx.compose.ui.platform.AmbientContext
+import androidx.compose.ui.text.font.Typeface
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontListFontFamily
import androidx.compose.ui.text.font.LoadedFontFamily
import androidx.compose.ui.text.font.ResourceFont
import androidx.compose.ui.text.font.SystemFontFamily
-import androidx.compose.ui.text.platform.typefaceFromFontFamily
+import androidx.compose.ui.text.font.typeface
import androidx.compose.ui.util.fastForEach
private val cacheLock = Object()
@@ -47,18 +47,18 @@
*/
@Composable
fun fontResource(fontFamily: FontFamily): Typeface {
- return fontResourceFromContext(ContextAmbient.current, fontFamily)
+ return fontResourceFromContext(AmbientContext.current, fontFamily)
}
internal fun fontResourceFromContext(context: Context, fontFamily: FontFamily): Typeface {
if (fontFamily is SystemFontFamily || fontFamily is LoadedFontFamily) {
synchronized(cacheLock) {
return syncLoadedTypefaces.getOrPut(fontFamily) {
- typefaceFromFontFamily(context, fontFamily)
+ typeface(context, fontFamily)
}
}
} else {
- return typefaceFromFontFamily(context, fontFamily)
+ return typeface(context, fontFamily)
}
}
@@ -85,7 +85,7 @@
pendingFontFamily: FontFamily? = null,
failedFontFamily: FontFamily? = null
): DeferredResource<Typeface> {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
val pendingTypeface = if (pendingFontFamily == null) {
null
} else if (!pendingFontFamily.canLoadSynchronously) {
@@ -138,7 +138,7 @@
pendingTypeface: Typeface? = null,
failedTypeface: Typeface? = null
): DeferredResource<Typeface> {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
if (fontFamily.canLoadSynchronously) {
val typeface = synchronized(cacheLock) {
syncLoadedTypefaces.getOrPut(fontFamily) {
@@ -162,7 +162,7 @@
}
val key = fontFamily.cacheKey(context)
return loadResource(key, pendingTypeface, failedTypeface) {
- typefaceFromFontFamily(context, fontFamily)
+ typeface(context, fontFamily)
}
}
}
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/ImageResources.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/ImageResources.kt
index 1a0fe6b..c377937 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/ImageResources.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/ImageResources.kt
@@ -22,7 +22,7 @@
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.imageFromResource
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.util.trace
/**
@@ -35,7 +35,7 @@
*/
@Composable
fun imageResource(@DrawableRes id: Int): ImageBitmap {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
val value = remember { TypedValue() }
context.resources.getValue(id, value, true)
// We use the file path as a key of the request cache.
@@ -62,7 +62,7 @@
pendingImage: ImageBitmap? = null,
failedImage: ImageBitmap? = null
): DeferredResource<ImageBitmap> {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
val res = context.resources
val value = remember { TypedValue() }
res.getValue(id, value, true)
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/PrimitiveResources.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/PrimitiveResources.kt
index 1155ea5..41f15b8 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/PrimitiveResources.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/PrimitiveResources.kt
@@ -21,8 +21,8 @@
import androidx.annotation.DimenRes
import androidx.annotation.IntegerRes
import androidx.compose.runtime.Composable
-import androidx.compose.ui.platform.ContextAmbient
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientContext
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.Dp
/**
@@ -33,7 +33,7 @@
*/
@Composable
fun integerResource(@IntegerRes id: Int): Int {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
return context.resources.getInteger(id)
}
@@ -45,7 +45,7 @@
*/
@Composable
fun integerArrayResource(@ArrayRes id: Int): IntArray {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
return context.resources.getIntArray(id)
}
@@ -57,7 +57,7 @@
*/
@Composable
fun booleanResource(@BoolRes id: Int): Boolean {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
return context.resources.getBoolean(id)
}
@@ -69,8 +69,8 @@
*/
@Composable
fun dimensionResource(@DimenRes id: Int): Dp {
- val context = ContextAmbient.current
- val density = DensityAmbient.current
+ val context = AmbientContext.current
+ val density = AmbientDensity.current
val pxValue = context.resources.getDimension(id)
return Dp(pxValue / density.density)
}
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/StringResources.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/StringResources.kt
index 36a5a20..bb7e61a 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/StringResources.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/StringResources.kt
@@ -20,8 +20,8 @@
import androidx.annotation.ArrayRes
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
-import androidx.compose.ui.platform.ConfigurationAmbient
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientConfiguration
+import androidx.compose.ui.platform.AmbientContext
/**
* Load a string resource.
@@ -66,6 +66,6 @@
*/
@Composable
private fun resources(): Resources {
- ConfigurationAmbient.current
- return ContextAmbient.current.resources
+ AmbientConfiguration.current
+ return AmbientContext.current.resources
}
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/VectorResources.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/VectorResources.kt
index 3083835..8f59986 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/VectorResources.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/res/VectorResources.kt
@@ -28,7 +28,7 @@
import androidx.compose.ui.graphics.vector.compat.isAtEnd
import androidx.compose.ui.graphics.vector.compat.parseCurrentVectorNode
import androidx.compose.ui.graphics.vector.compat.seekToStartTag
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.util.trace
import org.xmlpull.v1.XmlPullParserException
@@ -42,7 +42,7 @@
*/
@Composable
fun vectorResource(@DrawableRes id: Int): ImageVector {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
val res = context.resources
val theme = context.theme
return remember(id) {
@@ -68,7 +68,7 @@
pendingResource: ImageVector? = null,
failedResource: ImageVector? = null
): DeferredResource<ImageVector> {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
val res = context.resources
val theme = context.theme
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/AndroidView.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/AndroidView.kt
index 778f332..9eb150b 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/AndroidView.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/AndroidView.kt
@@ -24,8 +24,8 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.materialize
import androidx.compose.ui.node.UiApplier
-import androidx.compose.ui.platform.ContextAmbient
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientContext
+import androidx.compose.ui.platform.AmbientDensity
/**
* Composes an Android [View] obtained from [viewBlock]. The [viewBlock] block will be called
@@ -49,14 +49,14 @@
modifier: Modifier = Modifier,
update: (T) -> Unit = NoOpUpdate
) {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
val materialized = currentComposer.materialize(modifier)
emit<ViewBlockHolder<T>, UiApplier>(
ctor = { ViewBlockHolder(context) },
update = {
set(Unit) { this.viewBlock = viewBlock }
set(materialized) { this.modifier = it }
- set(DensityAmbient.current) { this.density = it }
+ set(AmbientDensity.current) { this.density = it }
set(update) { this.updateBlock = update }
}
)
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/EmitView.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/EmitView.kt
index 102bf03..b35dee0 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/EmitView.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/EmitView.kt
@@ -22,7 +22,7 @@
import androidx.compose.runtime.Composable
import androidx.compose.runtime.emit
import androidx.compose.ui.node.UiApplier
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
@Suppress("ComposableNaming")
@Composable
@@ -35,7 +35,7 @@
ctor: (Context) -> T,
update: (T) -> Unit
) {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
emit<T, UiApplier>(
ctor = { ctor(context) },
update = {
@@ -56,7 +56,7 @@
update: (T) -> Unit,
children: @Composable () -> Unit
) {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
emit<T, UiApplier>(
ctor = { ctor(context) },
update = {
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/ViewModel.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/ViewModel.kt
index bda292d..3766859 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/ViewModel.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/ViewModel.kt
@@ -17,7 +17,7 @@
package androidx.compose.ui.viewinterop
import androidx.compose.runtime.Composable
-import androidx.compose.ui.platform.ViewModelStoreOwnerAmbient
+import androidx.compose.ui.platform.AmbientViewModelStoreOwner
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner
@@ -57,7 +57,7 @@
modelClass: Class<VM>,
key: String? = null,
factory: ViewModelProvider.Factory? = null
-): VM = ViewModelStoreOwnerAmbient.current.get(modelClass, key, factory)
+): VM = AmbientViewModelStoreOwner.current.get(modelClass, key, factory)
private fun <VM : ViewModel> ViewModelStoreOwner.get(
javaClass: Class<VM>,
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidDialog.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidDialog.kt
index 09a3cbd..c4bed82 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidDialog.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidDialog.kt
@@ -33,7 +33,7 @@
import androidx.compose.runtime.remember
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.ViewAmbient
+import androidx.compose.ui.platform.AmbientView
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.semantics.dialog
import androidx.compose.ui.semantics.semantics
@@ -76,7 +76,7 @@
properties: DialogProperties?,
content: @Composable () -> Unit
) {
- val view = ViewAmbient.current
+ val view = AmbientView.current
val dialog = remember(view) { DialogWrapper(view) }
dialog.onCloseRequest = onDismissRequest
diff --git a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidPopup.kt b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidPopup.kt
index 95251f8..9156573 100644
--- a/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidPopup.kt
+++ b/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidPopup.kt
@@ -39,8 +39,8 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.DensityAmbient
-import androidx.compose.ui.platform.ViewAmbient
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientView
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.semantics.popup
import androidx.compose.ui.semantics.semantics
@@ -87,14 +87,14 @@
properties: PopupProperties?,
content: @Composable () -> Unit
) {
- val view = ViewAmbient.current
- val density = DensityAmbient.current
+ val view = AmbientView.current
+ val density = AmbientDensity.current
val popupLayout = remember { PopupLayout(view, density) }
// Refresh anything that might have changed
popupLayout.onDismissRequest = onDismissRequest
- popupLayout.testTag = PopupTestTagAmbient.current
+ popupLayout.testTag = AmbientPopupTestTag.current
remember(popupPositionProvider) { popupLayout.setPositionProvider(popupPositionProvider) }
remember(isFocusable) { popupLayout.setIsFocusable(isFocusable) }
remember(properties) { popupLayout.setProperties(properties) }
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/draw/DrawShadow.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/draw/DrawShadow.kt
index 0cfff37..ea00e99 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/draw/DrawShadow.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/draw/DrawShadow.kt
@@ -22,7 +22,7 @@
import androidx.compose.ui.drawLayer
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -58,7 +58,7 @@
}
) {
drawLayer(
- shadowElevation = with(DensityAmbient.current) { elevation.toPx() },
+ shadowElevation = with(AmbientDensity.current) { elevation.toPx() },
shape = shape,
clip = clip
)
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/gesture/DragSlopExceededGestureFilter.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/gesture/DragSlopExceededGestureFilter.kt
index 58d8b46..5c386f1 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/gesture/DragSlopExceededGestureFilter.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/gesture/DragSlopExceededGestureFilter.kt
@@ -32,7 +32,7 @@
import androidx.compose.ui.input.pointer.PointerInputFilter
import androidx.compose.ui.input.pointer.changedToUpIgnoreConsumed
import androidx.compose.ui.input.pointer.positionChange
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.unit.IntSize
import kotlin.math.abs
@@ -71,7 +71,7 @@
properties["orientation"] = orientation
}
) {
- val touchSlop = with(DensityAmbient.current) { TouchSlop.toPx() }
+ val touchSlop = with(AmbientDensity.current) { TouchSlop.toPx() }
val filter = remember {
DragSlopExceededGestureFilter(touchSlop)
}
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/gesture/ScaleSlopExceededGestureFilter.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/gesture/ScaleSlopExceededGestureFilter.kt
index e3243d4..cc9fa7a 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/gesture/ScaleSlopExceededGestureFilter.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/gesture/ScaleSlopExceededGestureFilter.kt
@@ -23,7 +23,7 @@
import androidx.compose.ui.input.pointer.PointerEventPass
import androidx.compose.ui.input.pointer.PointerInputFilter
import androidx.compose.ui.input.pointer.changedToUpIgnoreConsumed
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.unit.IntSize
import kotlin.math.absoluteValue
@@ -55,7 +55,7 @@
properties["onScaleSlopExceeded"] = onScaleSlopExceeded
}
) {
- val scaleSlop = with(DensityAmbient.current) { ScaleSlop.toPx() }
+ val scaleSlop = with(AmbientDensity.current) { ScaleSlop.toPx() }
val filter = remember { ScaleSlopExceededGestureFilter(scaleSlop) }
// TODO(b/129784010): Consider also allowing onStart, onScale, and onEnd to be set individually.
filter.onScaleSlopExceeded = onScaleSlopExceeded
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/graphics/vector/VectorPainter.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/graphics/vector/VectorPainter.kt
index 2f68107..370ccd9 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/graphics/vector/VectorPainter.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/graphics/vector/VectorPainter.kt
@@ -27,7 +27,7 @@
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.painter.Painter
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.unit.Dp
/**
@@ -59,7 +59,7 @@
name: String = RootGroupName,
children: @Composable (viewportWidth: Float, viewportHeight: Float) -> Unit
): VectorPainter {
- val density = DensityAmbient.current
+ val density = AmbientDensity.current
val widthPx = with(density) { defaultWidth.toPx() }
val heightPx = with(density) { defaultHeight.toPx() }
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/key/KeyEvent.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/key/KeyEvent.kt
index 38080dc..47f001c 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/key/KeyEvent.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/key/KeyEvent.kt
@@ -19,9 +19,6 @@
/**
* When a user presses a key on a hardware keyboard, a [KeyEvent] is sent to the
* [KeyInputModifier] that is currently active.
- *
- * @property key the key that was pressed.
- * @property type the [type][KeyEventType] of key event.
*/
@ExperimentalKeyInput
interface KeyEvent {
@@ -54,8 +51,34 @@
val type: KeyEventType
/**
+ * Indicates whether the Alt key is pressed.
+ */
+ val isAltPressed: Boolean
+
+ /**
+ * Indicates whether the Ctrl key is pressed.
+ */
+ val isCtrlPressed: Boolean
+
+ /**
+ * Indicates whether the Meta key is pressed.
+ */
+ val isMetaPressed: Boolean
+
+ /**
+ * Indicates whether the Shift key is pressed.
+ */
+ val isShiftPressed: Boolean
+
+ /**
* Indicates the status of the Alt key.
*/
+ @Suppress("DEPRECATION")
+ @Deprecated(
+ "alt is replaced by isAltPressed",
+ ReplaceWith("isAltPressed"),
+ DeprecationLevel.ERROR
+ )
val alt: Alt
}
@@ -83,6 +106,10 @@
/**
* Indicates the status of the Alt key.
*/
+@Deprecated(
+ message = "Alt is replaced by KeyEvent.isAltPressed",
+ level = DeprecationLevel.WARNING
+)
@ExperimentalKeyInput
interface Alt {
/**
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/pointer/SuspendingPointerInputFilter.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/pointer/SuspendingPointerInputFilter.kt
index e96cd80..c339382 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/pointer/SuspendingPointerInputFilter.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/pointer/SuspendingPointerInputFilter.kt
@@ -23,9 +23,9 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.gesture.ExperimentalPointerInput
-import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientViewConfiguration
import androidx.compose.ui.platform.ViewConfiguration
-import androidx.compose.ui.platform.ViewConfigurationAmbient
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntSize
@@ -158,8 +158,8 @@
this.properties["block"] = block
}
) {
- val density = DensityAmbient.current
- val viewConfiguration = ViewConfigurationAmbient.current
+ val density = AmbientDensity.current
+ val viewConfiguration = AmbientViewConfiguration.current
remember(density) { SuspendingPointerInputFilter(viewConfiguration, density) }.apply {
LaunchedEffect(this) {
block()
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/Layout.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/Layout.kt
index 3401337..6b62912 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/Layout.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/Layout.kt
@@ -31,8 +31,8 @@
import androidx.compose.ui.node.ExperimentalLayoutNodeApi
import androidx.compose.ui.node.LayoutEmitHelper
import androidx.compose.ui.node.LayoutNode
-import androidx.compose.ui.platform.DensityAmbient
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.simpleIdentityToString
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Density
@@ -234,8 +234,8 @@
ctor = LayoutEmitHelper.constructor,
update = {
set(measureBlocks, LayoutEmitHelper.setMeasureBlocks)
- set(DensityAmbient.current, LayoutEmitHelper.setDensity)
- set(LayoutDirectionAmbient.current, LayoutEmitHelper.setLayoutDirection)
+ set(AmbientDensity.current, LayoutEmitHelper.setDensity)
+ set(AmbientLayoutDirection.current, LayoutEmitHelper.setLayoutDirection)
},
skippableUpdate = materializerOf(modifier),
children = children
@@ -273,8 +273,8 @@
update = {
set(materialized, LayoutEmitHelper.setModifier)
set(measureBlocks, LayoutEmitHelper.setMeasureBlocks)
- set(DensityAmbient.current, LayoutEmitHelper.setDensity)
- set(LayoutDirectionAmbient.current, LayoutEmitHelper.setLayoutDirection)
+ set(AmbientDensity.current, LayoutEmitHelper.setDensity)
+ set(AmbientLayoutDirection.current, LayoutEmitHelper.setLayoutDirection)
@Suppress("DEPRECATION")
set(Unit) { this.canMultiMeasure = true }
},
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/SubcomposeLayout.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/SubcomposeLayout.kt
index 615fd53..427031d 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/SubcomposeLayout.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/SubcomposeLayout.kt
@@ -34,8 +34,8 @@
import androidx.compose.ui.node.LayoutNode
import androidx.compose.ui.node.LayoutNode.LayoutState
import androidx.compose.ui.node.isAttached
-import androidx.compose.ui.platform.DensityAmbient
-import androidx.compose.ui.platform.LayoutDirectionAmbient
+import androidx.compose.ui.platform.AmbientDensity
+import androidx.compose.ui.platform.AmbientLayoutDirection
import androidx.compose.ui.platform.subcomposeInto
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.LayoutDirection
@@ -75,8 +75,8 @@
set(Unit, state.setRoot)
set(materialized, LayoutEmitHelper.setModifier)
set(measureBlock, state.setMeasureBlock)
- set(DensityAmbient.current, LayoutEmitHelper.setDensity)
- set(LayoutDirectionAmbient.current, LayoutEmitHelper.setLayoutDirection)
+ set(AmbientDensity.current, LayoutEmitHelper.setDensity)
+ set(AmbientLayoutDirection.current, LayoutEmitHelper.setLayoutDirection)
}
)
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/Ambients.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/Ambients.kt
index a0fa226..6101e56 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/Ambients.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/Ambients.kt
@@ -34,12 +34,38 @@
/**
* The default animation clock used for animations when an explicit clock isn't provided.
*/
-val AnimationClockAmbient = staticAmbientOf<AnimationClockObservable>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientAnimationClock",
+ replaceWith = ReplaceWith(
+ "AmbientAnimationClock",
+ "androidx.compose.ui.platform.AmbientAnimationClock"
+ )
+)
+val AnimationClockAmbient get() = AmbientAnimationClock
+
+/**
+ * The default animation clock used for animations when an explicit clock isn't provided.
+ */
+val AmbientAnimationClock = staticAmbientOf<AnimationClockObservable>()
/**
* The ambient that can be used to trigger autofill actions. Eg. [Autofill.requestAutofillForNode].
*/
-val AutofillAmbient = staticAmbientOf<Autofill?>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientAutofill",
+ replaceWith = ReplaceWith(
+ "AmbientAutofill",
+ "androidx.compose.ui.platform.AmbientAutofill"
+ )
+)
+val AutofillAmbient get() = AmbientAutofill
+
+/**
+ * The ambient that can be used to trigger autofill actions. Eg. [Autofill.requestAutofillForNode].
+ */
+val AmbientAutofill = staticAmbientOf<Autofill?>()
/**
* The ambient that can be used to add
@@ -47,12 +73,41 @@
* [AutofillTree] is a temporary data structure that will be replaced by Autofill Semantics
* (b/138604305).
*/
-val AutofillTreeAmbient = staticAmbientOf<AutofillTree>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientAutofillTree",
+ replaceWith = ReplaceWith(
+ "AmbientAutofillTree",
+ "androidx.compose.ui.platform.AmbientAutofillTree"
+ )
+)
+val AutofillTreeAmbient get() = AmbientAutofillTree
+
+/**
+ * The ambient that can be used to add
+ * [AutofillNode][import androidx.compose.ui.autofill.AutofillNode]s to the autofill tree. The
+ * [AutofillTree] is a temporary data structure that will be replaced by Autofill Semantics
+ * (b/138604305).
+ */
+val AmbientAutofillTree = staticAmbientOf<AutofillTree>()
/**
* The ambient to provide communication with platform clipboard service.
*/
-val ClipboardManagerAmbient = staticAmbientOf<ClipboardManager>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientClipboardManager",
+ replaceWith = ReplaceWith(
+ "AmbientClipboardManager",
+ "androidx.compose.ui.platform.AmbientClipboardManager"
+ )
+)
+val ClipboardManagerAmbient get() = AmbientClipboardManager
+
+/**
+ * The ambient to provide communication with platform clipboard service.
+ */
+val AmbientClipboardManager = staticAmbientOf<ClipboardManager>()
/**
* Provides the [Density] to be used to transform between [density-independent pixel
@@ -61,13 +116,44 @@
* [pixel units][androidx.compose.ui.unit.Px]. This is typically used when a [DP][androidx.compose.ui.unit.Dp]
* is provided and it must be converted in the body of [Layout] or [DrawModifier].
*/
-val DensityAmbient = staticAmbientOf<Density>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientDensity",
+ replaceWith = ReplaceWith(
+ "AmbientDensity",
+ "androidx.compose.ui.platform.AmbientDensity"
+ )
+)
+val DensityAmbient get() = AmbientDensity
+
+/**
+ * Provides the [Density] to be used to transform between [density-independent pixel
+ * units (DP)][androidx.compose.ui.unit.Dp] and [pixel units][androidx.compose.ui.unit.Px] or
+ * [scale-independent pixel units (SP)][androidx.compose.ui.unit.TextUnit] and
+ * [pixel units][androidx.compose.ui.unit.Px]. This is typically used when a [DP][androidx.compose.ui.unit.Dp]
+ * is provided and it must be converted in the body of [Layout] or [DrawModifier].
+ */
+val AmbientDensity = staticAmbientOf<Density>()
+
+/**
+ * The ambient that can be used to control focus within Compose.
+ */
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientFocusManager",
+ replaceWith = ReplaceWith(
+ "AmbientFocusManager",
+ "androidx.compose.ui.platform.AmbientFocusManager"
+ )
+)
+@ExperimentalFocus
+val FocusManagerAmbient get() = AmbientFocusManager
/**
* The ambient that can be used to control focus within Compose.
*/
@ExperimentalFocus
-val FocusManagerAmbient = staticAmbientOf<FocusManager>()
+val AmbientFocusManager = staticAmbientOf<FocusManager>()
/**
* The ambient to provide platform font loading methods.
@@ -75,37 +161,131 @@
* Use [androidx.compose.ui.res.fontResource] instead.
* @suppress
*/
-val FontLoaderAmbient = staticAmbientOf<Font.ResourceLoader>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientFontLoader",
+ replaceWith = ReplaceWith(
+ "AmbientFontLoader",
+ "androidx.compose.ui.platform.AmbientFontLoader"
+ )
+)
+val FontLoaderAmbient get() = AmbientFontLoader
+
+/**
+ * The ambient to provide platform font loading methods.
+ *
+ * Use [androidx.compose.ui.res.fontResource] instead.
+ * @suppress
+ */
+val AmbientFontLoader = staticAmbientOf<Font.ResourceLoader>()
/**
* The ambient to provide haptic feedback to the user.
*/
-val HapticFeedBackAmbient = staticAmbientOf<HapticFeedback>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientHapticFeedback",
+ replaceWith = ReplaceWith(
+ "AmbientHapticFeedback",
+ "androidx.compose.ui.platform.AmbientHapticFeedback"
+ )
+)
+val HapticFeedBackAmbient get() = AmbientHapticFeedback
+
+/**
+ * The ambient to provide haptic feedback to the user.
+ */
+val AmbientHapticFeedback = staticAmbientOf<HapticFeedback>()
/**
* The ambient to provide the layout direction.
*/
-val LayoutDirectionAmbient = staticAmbientOf<LayoutDirection>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientLayoutDirection",
+ replaceWith = ReplaceWith(
+ "AmbientLayoutDirection",
+ "androidx.compose.ui.platform.AmbientLayoutDirection"
+ )
+)
+val LayoutDirectionAmbient get() = AmbientLayoutDirection
+
+/**
+ * The ambient to provide the layout direction.
+ */
+val AmbientLayoutDirection = staticAmbientOf<LayoutDirection>()
/**
* The ambient to provide communication with platform text input service.
*/
-val TextInputServiceAmbient = staticAmbientOf<TextInputService?>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientTextInputService",
+ replaceWith = ReplaceWith(
+ "AmbientTextInputService",
+ "androidx.compose.ui.platform.AmbientTextInputService"
+ )
+)
+val TextInputServiceAmbient get() = AmbientTextInputService
+
+/**
+ * The ambient to provide communication with platform text input service.
+ */
+val AmbientTextInputService = staticAmbientOf<TextInputService?>()
/**
* The ambient to provide text-related toolbar.
*/
-val TextToolbarAmbient = staticAmbientOf<TextToolbar>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientTextToolbar",
+ replaceWith = ReplaceWith(
+ "AmbientTextToolbar",
+ "androidx.compose.ui.platform.AmbientTextToolbar"
+ )
+)
+val TextToolbarAmbient get() = AmbientTextToolbar
+
+/**
+ * The ambient to provide text-related toolbar.
+ */
+val AmbientTextToolbar = staticAmbientOf<TextToolbar>()
/**
* The ambient to provide functionality related to URL, e.g. open URI.
*/
-val UriHandlerAmbient = staticAmbientOf<UriHandler>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientUriHandler",
+ replaceWith = ReplaceWith(
+ "AmbientUriHandler",
+ "androidx.compose.ui.platform.AmbientUriHandler"
+ )
+)
+val UriHandlerAmbient get() = AmbientUriHandler
+
+/**
+ * The ambient to provide functionality related to URL, e.g. open URI.
+ */
+val AmbientUriHandler = staticAmbientOf<UriHandler>()
/**
* The ambient that provides the ViewConfiguration.
*/
-val ViewConfigurationAmbient = staticAmbientOf<ViewConfiguration>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientViewConfiguration",
+ replaceWith = ReplaceWith(
+ "AmbientViewConfiguration",
+ "androidx.compose.ui.platform.AmbientViewConfiguration"
+ )
+)
+val ViewConfigurationAmbient get() = AmbientViewConfiguration
+
+/**
+ * The ambient that provides the ViewConfiguration.
+ */
+val AmbientViewConfiguration = staticAmbientOf<ViewConfiguration>()
@OptIn(ExperimentalFocus::class)
@Composable
@@ -116,19 +296,19 @@
content: @Composable () -> Unit
) {
Providers(
- AnimationClockAmbient provides animationClock,
- AutofillAmbient provides owner.autofill,
- AutofillTreeAmbient provides owner.autofillTree,
- ClipboardManagerAmbient provides owner.clipboardManager,
- DensityAmbient provides owner.density,
- FocusManagerAmbient provides owner.focusManager,
- FontLoaderAmbient provides owner.fontLoader,
- HapticFeedBackAmbient provides owner.hapticFeedBack,
- LayoutDirectionAmbient providesDefault owner.layoutDirection,
- TextInputServiceAmbient provides owner.textInputService,
- TextToolbarAmbient provides owner.textToolbar,
- UriHandlerAmbient provides uriHandler,
- ViewConfigurationAmbient provides owner.viewConfiguration,
+ AmbientAnimationClock provides animationClock,
+ AmbientAutofill provides owner.autofill,
+ AmbientAutofillTree provides owner.autofillTree,
+ AmbientClipboardManager provides owner.clipboardManager,
+ AmbientDensity provides owner.density,
+ AmbientFocusManager provides owner.focusManager,
+ AmbientFontLoader provides owner.fontLoader,
+ AmbientHapticFeedback provides owner.hapticFeedBack,
+ AmbientLayoutDirection providesDefault owner.layoutDirection,
+ AmbientTextInputService provides owner.textInputService,
+ AmbientTextToolbar provides owner.textToolbar,
+ AmbientUriHandler provides uriHandler,
+ AmbientViewConfiguration provides owner.viewConfiguration,
children = content
)
}
\ No newline at end of file
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/selection/SelectionContainer.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/selection/SelectionContainer.kt
index 6293e8a..3b36b69 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/selection/SelectionContainer.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/selection/SelectionContainer.kt
@@ -27,9 +27,9 @@
import androidx.compose.ui.gesture.dragGestureFilter
import androidx.compose.ui.gesture.noConsumptionTapGestureFilter
import androidx.compose.ui.layout.onGloballyPositioned
-import androidx.compose.ui.platform.ClipboardManagerAmbient
-import androidx.compose.ui.platform.HapticFeedBackAmbient
-import androidx.compose.ui.platform.TextToolbarAmbient
+import androidx.compose.ui.platform.AmbientClipboardManager
+import androidx.compose.ui.platform.AmbientHapticFeedback
+import androidx.compose.ui.platform.AmbientTextToolbar
import androidx.compose.ui.text.InternalTextApi
/**
@@ -61,7 +61,7 @@
@Composable
fun DisableSelection(content: @Composable () -> Unit) {
Providers(
- SelectionRegistrarAmbient provides null,
+ AmbientSelectionRegistrar provides null,
children = content
)
}
@@ -88,9 +88,9 @@
val registrarImpl = remember { SelectionRegistrarImpl() }
val manager = remember { SelectionManager(registrarImpl) }
- manager.hapticFeedBack = HapticFeedBackAmbient.current
- manager.clipboardManager = ClipboardManagerAmbient.current
- manager.textToolbar = TextToolbarAmbient.current
+ manager.hapticFeedBack = AmbientHapticFeedback.current
+ manager.clipboardManager = AmbientClipboardManager.current
+ manager.textToolbar = AmbientTextToolbar.current
manager.onSelectionChange = onSelectionChange
manager.selection = selection
@@ -110,7 +110,7 @@
}
}
- Providers(SelectionRegistrarAmbient provides registrarImpl) {
+ Providers(AmbientSelectionRegistrar provides registrarImpl) {
// Get the layout coordinates of the selection container. This is for hit test of
// cross-composable selection.
SimpleLayout(
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/selection/SelectionRegistrar.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/selection/SelectionRegistrar.kt
index 14be1d1..3dbff76 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/selection/SelectionRegistrar.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/selection/SelectionRegistrar.kt
@@ -58,4 +58,18 @@
* Ambient of SelectionRegistrar. Composables that implement selection logic can use this ambient
* to get a [SelectionRegistrar] in order to subscribe and unsubscribe to [SelectionRegistrar].
*/
-val SelectionRegistrarAmbient = ambientOf<SelectionRegistrar?>()
+@Suppress("AmbientNaming")
+@Deprecated(
+ "Renamed to AmbientSelectionRegistrar",
+ replaceWith = ReplaceWith(
+ "AmbientSelectionRegistrar",
+ "androidx.compose.ui.selection.AmbientSelectionRegistrar"
+ )
+)
+val SelectionRegistrarAmbient get() = AmbientSelectionRegistrar
+
+/**
+ * Ambient of SelectionRegistrar. Composables that implement selection logic can use this ambient
+ * to get a [SelectionRegistrar] in order to subscribe and unsubscribe to [SelectionRegistrar].
+ */
+val AmbientSelectionRegistrar = ambientOf<SelectionRegistrar?>()
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/window/Popup.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/window/Popup.kt
index 9697054..03dd641 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/window/Popup.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/window/Popup.kt
@@ -116,11 +116,11 @@
// TODO(b/142431825): This is a hack to work around Popups not using Semantics for test tags
// We should either remove it, or come up with an abstracted general solution that isn't specific
// to Popup
-internal val PopupTestTagAmbient = ambientOf { "DEFAULT_TEST_TAG" }
+internal val AmbientPopupTestTag = ambientOf { "DEFAULT_TEST_TAG" }
@Composable
internal fun PopupTestTag(tag: String, children: @Composable () -> Unit) {
- Providers(PopupTestTagAmbient provides tag, children = children)
+ Providers(AmbientPopupTestTag provides tag, children = children)
}
/**
diff --git a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/input/key/KeyEventDesktop.kt b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/input/key/KeyEventDesktop.kt
index 78d70c5..c8aeb01 100644
--- a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/input/key/KeyEventDesktop.kt
+++ b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/input/key/KeyEventDesktop.kt
@@ -36,10 +36,24 @@
else -> KeyEventType.Unknown
}
+ override val isAltPressed: Boolean
+ get() = keyEvent.isAltDown || keyEvent.isAltGraphDown
+
+ override val isCtrlPressed: Boolean
+ get() = keyEvent.isControlDown
+
+ override val isMetaPressed: Boolean
+ get() = keyEvent.isMetaDown
+
+ override val isShiftPressed: Boolean
+ get() = keyEvent.isShiftDown
+
+ @Suppress("DEPRECATION", "OverridingDeprecatedMember")
override val alt: Alt
get() = AltDesktop(keyEvent)
}
+@Suppress("DEPRECATION")
@OptIn(ExperimentalKeyInput::class)
internal inline class AltDesktop(val keyEvent: KeyEventAwt) : Alt {
@@ -48,4 +62,4 @@
override val isRightAltPressed
get() = keyEvent.isAltGraphDown
-}
\ No newline at end of file
+}
diff --git a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/DesktopSelection.kt b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/DesktopSelection.kt
index d1e97e8..de8fff5 100644
--- a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/DesktopSelection.kt
+++ b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/DesktopSelection.kt
@@ -28,8 +28,8 @@
import androidx.compose.ui.gesture.rawDragGestureFilter
import androidx.compose.ui.gesture.rawPressStartGestureFilter
import androidx.compose.ui.layout.onGloballyPositioned
+import androidx.compose.ui.selection.AmbientSelectionRegistrar
import androidx.compose.ui.selection.Selection
-import androidx.compose.ui.selection.SelectionRegistrarAmbient
import androidx.compose.ui.selection.SelectionRegistrarImpl
import kotlin.math.max
@@ -118,7 +118,7 @@
}
}
- Providers(SelectionRegistrarAmbient provides registrarImpl) {
+ Providers(AmbientSelectionRegistrar provides registrarImpl) {
Wrap(modifier) {
children()
}
diff --git a/core/core/src/androidTest/java/androidx/core/view/WindowInsetsCompatActivityTest.kt b/core/core/src/androidTest/java/androidx/core/view/WindowInsetsCompatActivityTest.kt
index 0f87b96..f100253 100644
--- a/core/core/src/androidTest/java/androidx/core/view/WindowInsetsCompatActivityTest.kt
+++ b/core/core/src/androidTest/java/androidx/core/view/WindowInsetsCompatActivityTest.kt
@@ -34,7 +34,6 @@
import androidx.test.espresso.matcher.ViewMatchers.assertThat
import androidx.test.espresso.matcher.ViewMatchers.hasFocus
import androidx.test.espresso.matcher.ViewMatchers.withId
-import androidx.test.filters.FlakyTest
import androidx.test.filters.LargeTest
import androidx.test.filters.SdkSuppress
import androidx.testutils.withActivity
@@ -45,6 +44,7 @@
import org.junit.Assume.assumeFalse
import org.junit.Assume.assumeThat
import org.junit.Before
+import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
@@ -57,14 +57,14 @@
@RequiresApi(16) // View.setSystemUiVisibility
@LargeTest
@RunWith(Parameterized::class)
-class WindowInsetsCompatActivityTest(
+public class WindowInsetsCompatActivityTest(
private val softInputMode: Int,
private val orientation: Int
) {
private lateinit var scenario: ActivityScenario<WindowInsetsCompatActivity>
@Before
- fun setup() {
+ public fun setup() {
scenario = ActivityScenario.launch(WindowInsetsCompatActivity::class.java)
scenario.withActivity {
@@ -84,13 +84,18 @@
onView(withId(R.id.edittext)).perform(closeSoftKeyboard())
}
+ @After
+ public fun cleanup() {
+ scenario.close()
+ }
+
/**
* IME visibility is only reliable on API 23+, where we have access to the root WindowInsets
*/
@SdkSuppress(minSdkVersion = 23)
@Test
- @FlakyTest(detail = "IME tests are inherently flaky, but still useful for local testing.")
- fun ime_viewInsets() {
+ @Ignore("IME tests are inherently flaky, but still useful for local testing.")
+ public fun ime_viewInsets() {
// Insets are only dispatched to views with adjustResize
assumeSoftInputMode(SOFT_INPUT_ADJUST_RESIZE)
// Test do not currently work on Cuttlefish
@@ -134,8 +139,8 @@
*/
@SdkSuppress(minSdkVersion = 23)
@Test
- @FlakyTest(detail = "IME tests are inherently flaky, but still useful for local testing.")
- fun ime_rootInsets() {
+ @Ignore("IME tests are inherently flaky, but still useful for local testing.")
+ public fun ime_rootInsets() {
// Test do not currently work on Cuttlefish
assumeNotCuttlefish()
@@ -178,7 +183,8 @@
@SdkSuppress(minSdkVersion = 23)
@Test
- fun systemBars_viewInsets() {
+ @Ignore("IME tests are inherently flaky, but still useful for local testing.")
+ public fun systemBars_viewInsets() {
// Insets are only dispatched to views with adjustResize
assumeSoftInputMode(SOFT_INPUT_ADJUST_RESIZE)
// Test do not currently work on Cuttlefish
@@ -204,9 +210,9 @@
}
@SdkSuppress(minSdkVersion = 23)
- @FlakyTest(detail = "IME tests are inherently flaky, but still useful for local testing.")
+ @Ignore("IME tests are inherently flaky, but still useful for local testing.")
@Test
- fun systemBars_rootInsets() {
+ public fun systemBars_rootInsets() {
// Test do not currently work on Cuttlefish
assumeNotCuttlefish()
@@ -247,25 +253,9 @@
}
}
- @After
- fun cleanup() {
- scenario.close()
- }
-
- companion object {
- @JvmStatic
- @Parameterized.Parameters
- fun data() = listOf(
- arrayOf(SOFT_INPUT_ADJUST_PAN, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE),
- arrayOf(SOFT_INPUT_ADJUST_PAN, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT),
- arrayOf(SOFT_INPUT_ADJUST_RESIZE, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE),
- arrayOf(SOFT_INPUT_ADJUST_RESIZE, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
- )
- }
-
@Test
@SdkSuppress(minSdkVersion = 20)
- fun equality_when_converted() {
+ public fun equality_when_converted() {
// Insets are only dispatched to views with adjustResize
assumeSoftInputMode(SOFT_INPUT_ADJUST_RESIZE)
val container: View = scenario.withActivity { findViewById(R.id.container) }
@@ -280,6 +270,17 @@
assertEquals(originalInsets.getInsets(Type.ime()), convertedInsets.getInsets(Type.ime()))
assertEquals(originalInsets, convertedInsets)
}
+
+ public companion object {
+ @JvmStatic
+ @Parameterized.Parameters
+ public fun data(): List<Array<Int>> = listOf(
+ arrayOf(SOFT_INPUT_ADJUST_PAN, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE),
+ arrayOf(SOFT_INPUT_ADJUST_PAN, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT),
+ arrayOf(SOFT_INPUT_ADJUST_RESIZE, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE),
+ arrayOf(SOFT_INPUT_ADJUST_RESIZE, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
+ )
+ }
}
private fun View.doAndAwaitNextInsets(action: (View) -> Unit): WindowInsetsCompat {
diff --git a/docs-public/build.gradle b/docs-public/build.gradle
index acf69ae..5a145f5 100644
--- a/docs-public/build.gradle
+++ b/docs-public/build.gradle
@@ -76,10 +76,10 @@
docs("androidx.core:core-ktx:1.5.0-alpha05")
docs("androidx.cursoradapter:cursoradapter:1.0.0")
docs("androidx.customview:customview:1.1.0")
- docs("androidx.datastore:datastore:1.0.0-alpha03")
- docs("androidx.datastore:datastore-core:1.0.0-alpha03")
- docs("androidx.datastore:datastore-preferences:1.0.0-alpha03")
- docs("androidx.datastore:datastore-preferences-core:1.0.0-alpha03")
+ docs("androidx.datastore:datastore:1.0.0-alpha04")
+ docs("androidx.datastore:datastore-core:1.0.0-alpha04")
+ docs("androidx.datastore:datastore-preferences:1.0.0-alpha04")
+ docs("androidx.datastore:datastore-preferences-core:1.0.0-alpha04")
docs("androidx.documentfile:documentfile:1.0.0")
docs("androidx.drawerlayout:drawerlayout:1.1.1")
docs("androidx.dynamicanimation:dynamicanimation:1.1.0-alpha02")
diff --git a/leanback/leanback-paging/build.gradle b/leanback/leanback-paging/build.gradle
index 318a6c0..a9f0497 100644
--- a/leanback/leanback-paging/build.gradle
+++ b/leanback/leanback-paging/build.gradle
@@ -49,7 +49,7 @@
androidx {
name = "AndroidX Leanback Paging"
publish = Publish.SNAPSHOT_AND_RELEASE
- mavenVersion = LibraryVersions.LEANBACK
+ mavenVersion = LibraryVersions.LEANBACK_PAGING
mavenGroup = LibraryGroups.LEANBACK
inceptionYear = "2020"
description = "AndroidX Leanback Paging"
diff --git a/navigation/navigation-compose/build.gradle b/navigation/navigation-compose/build.gradle
index 748ddb7..cb028e2 100644
--- a/navigation/navigation-compose/build.gradle
+++ b/navigation/navigation-compose/build.gradle
@@ -30,20 +30,20 @@
}
dependencies {
- kotlinPlugin project(path: ":compose:compiler:compiler")
+ kotlinPlugin projectOrArtifact(":compose:compiler:compiler")
implementation(KOTLIN_STDLIB)
- api project(":compose:runtime:runtime")
- api project(":compose:runtime:runtime-saved-instance-state")
- api project(":compose:ui:ui")
+ api projectOrArtifact(":compose:runtime:runtime")
+ api projectOrArtifact(":compose:runtime:runtime-saved-instance-state")
+ api projectOrArtifact(":compose:ui:ui")
api "androidx.navigation:navigation-runtime-ktx:2.3.1"
- androidTestImplementation project(":compose:material:material")
+ androidTestImplementation projectOrArtifact(":compose:material:material")
androidTestImplementation 'androidx.navigation:navigation-testing:2.3.1'
- androidTestImplementation project(path: ':internal-testutils-navigation'), {
+ androidTestImplementation projectOrArtifact(":internal-testutils-navigation"), {
exclude group: 'androidx.navigation', module: 'navigation-common-ktx'
}
- androidTestImplementation project(":compose:ui:ui-test-junit4")
+ androidTestImplementation projectOrArtifact(":compose:ui:ui-test-junit4")
androidTestImplementation(ANDROIDX_TEST_RUNNER)
androidTestImplementation(JUNIT)
androidTestImplementation(TRUTH)
diff --git a/navigation/navigation-compose/integration-tests/navigation-demos/build.gradle b/navigation/navigation-compose/integration-tests/navigation-demos/build.gradle
index f6e312a..bb1243d 100644
--- a/navigation/navigation-compose/integration-tests/navigation-demos/build.gradle
+++ b/navigation/navigation-compose/integration-tests/navigation-demos/build.gradle
@@ -28,14 +28,14 @@
}
dependencies {
- kotlinPlugin project(path: ":compose:compiler:compiler")
+ kotlinPlugin projectOrArtifact(":compose:compiler:compiler")
implementation(KOTLIN_STDLIB)
- implementation project(":compose:integration-tests:demos:common")
- implementation project(":compose:foundation:foundation")
- implementation project(":compose:material:material")
- implementation project(":navigation:navigation-compose")
- implementation project(":navigation:navigation-compose:navigation-compose-samples")
+ implementation projectOrArtifact(":compose:integration-tests:demos:common")
+ implementation projectOrArtifact(":compose:foundation:foundation")
+ implementation projectOrArtifact(":compose:material:material")
+ implementation projectOrArtifact(":navigation:navigation-compose")
+ implementation projectOrArtifact(":navigation:navigation-compose:navigation-compose-samples")
}
android {
diff --git a/navigation/navigation-compose/samples/build.gradle b/navigation/navigation-compose/samples/build.gradle
index 6c7d9a5..caf0856 100644
--- a/navigation/navigation-compose/samples/build.gradle
+++ b/navigation/navigation-compose/samples/build.gradle
@@ -30,13 +30,13 @@
}
dependencies {
- kotlinPlugin project(path: ":compose:compiler:compiler")
+ kotlinPlugin projectOrArtifact(":compose:compiler:compiler")
implementation(KOTLIN_STDLIB)
- compileOnly project(":annotation:annotation-sampled")
- implementation project(":compose:foundation:foundation")
- implementation project(":navigation:navigation-compose")
- implementation project(":compose:material:material")
+ compileOnly projectOrArtifact(":annotation:annotation-sampled")
+ implementation projectOrArtifact(":compose:foundation:foundation")
+ implementation projectOrArtifact(":navigation:navigation-compose")
+ implementation projectOrArtifact(":compose:material:material")
}
android {
diff --git a/navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavGraphBuilderTest.kt b/navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavGraphBuilderTest.kt
index 8c82eae..31a82cf 100644
--- a/navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavGraphBuilderTest.kt
+++ b/navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavGraphBuilderTest.kt
@@ -17,7 +17,7 @@
package androidx.navigation.compose
import android.net.Uri
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.core.net.toUri
import androidx.navigation.NavDeepLinkRequest
@@ -45,7 +45,7 @@
val key = "key"
val arg = "myarg"
composeTestRule.setContent {
- navController = TestNavHostController(ContextAmbient.current)
+ navController = TestNavHostController(AmbientContext.current)
navController.navigatorProvider.addNavigator(ComposeNavigator())
NavHost(navController, startDestination = firstRoute) {
@@ -67,7 +67,7 @@
val key = "key"
val defaultArg = "default"
composeTestRule.setContent {
- navController = TestNavHostController(ContextAmbient.current)
+ navController = TestNavHostController(AmbientContext.current)
navController.navigatorProvider.addNavigator(ComposeNavigator())
NavHost(navController, startDestination = firstRoute) {
@@ -92,7 +92,7 @@
val uriString = "https://www.example.com"
val deeplink = NavDeepLinkRequest.Builder.fromUri(Uri.parse(uriString)).build()
composeTestRule.setContent {
- navController = TestNavHostController(ContextAmbient.current)
+ navController = TestNavHostController(AmbientContext.current)
navController.navigatorProvider.addNavigator(ComposeNavigator())
NavHost(navController, startDestination = firstRoute) {
@@ -115,7 +115,7 @@
fun testNavigationNested() {
lateinit var navController: TestNavHostController
composeTestRule.setContent {
- navController = TestNavHostController(ContextAmbient.current)
+ navController = TestNavHostController(AmbientContext.current)
navController.navigatorProvider.addNavigator(ComposeNavigator())
NavHost(navController, startDestination = firstRoute) {
diff --git a/navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostControllerTest.kt b/navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostControllerTest.kt
index e4f454b7..829b1c12 100644
--- a/navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostControllerTest.kt
+++ b/navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostControllerTest.kt
@@ -18,7 +18,7 @@
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController
@@ -46,7 +46,7 @@
fun testCurrentBackStackEntrySetGraph() {
var currentBackStackEntry: State<NavBackStackEntry?> = mutableStateOf(null)
composeTestRule.setContent {
- val navController = TestNavHostController(ContextAmbient.current)
+ val navController = TestNavHostController(AmbientContext.current)
navController.graph = navController.createGraph(startDestination = FIRST_DESTINATION) {
test(FIRST_DESTINATION)
@@ -65,7 +65,7 @@
var currentBackStackEntry: State<NavBackStackEntry?> = mutableStateOf(null)
lateinit var navController: NavController
composeTestRule.setContent {
- navController = TestNavHostController(ContextAmbient.current)
+ navController = TestNavHostController(AmbientContext.current)
navController.graph = navController.createGraph(startDestination = FIRST_DESTINATION) {
test(FIRST_DESTINATION)
@@ -93,7 +93,7 @@
var currentBackStackEntry: State<NavBackStackEntry?> = mutableStateOf(null)
lateinit var navController: TestNavHostController
composeTestRule.setContent {
- navController = TestNavHostController(ContextAmbient.current)
+ navController = TestNavHostController(AmbientContext.current)
navController.graph = navController.createGraph(startDestination = FIRST_DESTINATION) {
test(FIRST_DESTINATION)
@@ -119,7 +119,7 @@
lateinit var navController: NavController
val navigator = TestNavigator()
composeTestRule.setContent {
- navController = TestNavHostController(ContextAmbient.current)
+ navController = TestNavHostController(AmbientContext.current)
navController.navigatorProvider.addNavigator(navigator)
navController.graph = navController.createGraph(startDestination = FIRST_DESTINATION) {
@@ -155,7 +155,7 @@
lateinit var navController: NavController
val navigator = TestNavigator()
composeTestRule.setContent {
- navController = TestNavHostController(ContextAmbient.current)
+ navController = TestNavHostController(AmbientContext.current)
navController.navigatorProvider.addNavigator(navigator)
navController.graph = navController.createGraph(startDestination = FIRST_DESTINATION) {
diff --git a/navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostTest.kt b/navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostTest.kt
index a1b852e..1440b95 100644
--- a/navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostTest.kt
+++ b/navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostTest.kt
@@ -28,7 +28,7 @@
import androidx.compose.runtime.savedinstancestate.rememberSavedInstanceState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
@@ -55,7 +55,7 @@
fun testSingleDestinationSet() {
lateinit var navController: NavHostController
composeTestRule.setContent {
- navController = TestNavHostController(ContextAmbient.current)
+ navController = TestNavHostController(AmbientContext.current)
NavHost(navController, startDestination = "first") {
test("first")
@@ -71,7 +71,7 @@
fun testNavigate() {
lateinit var navController: NavHostController
composeTestRule.setContent {
- navController = TestNavHostController(ContextAmbient.current)
+ navController = TestNavHostController(AmbientContext.current)
NavHost(navController, startDestination = "first") {
test("first")
@@ -149,7 +149,7 @@
fun testPop() {
lateinit var navController: TestNavHostController
composeTestRule.setContent {
- navController = TestNavHostController(ContextAmbient.current)
+ navController = TestNavHostController(AmbientContext.current)
NavHost(navController, startDestination = "first") {
test("first")
@@ -175,7 +175,7 @@
lateinit var state: MutableState<String>
composeTestRule.setContent {
state = remember { mutableStateOf("first") }
- val context = ContextAmbient.current
+ val context = AmbientContext.current
navController = remember { TestNavHostController(context) }
NavHost(navController, startDestination = state.value) {
diff --git a/navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHost.kt b/navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHost.kt
index 9e907fe..6e074d7 100644
--- a/navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHost.kt
+++ b/navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHost.kt
@@ -25,9 +25,9 @@
import androidx.compose.runtime.savedinstancestate.ExperimentalRestorableStateHolder
import androidx.compose.runtime.savedinstancestate.RestorableStateHolder
import androidx.compose.runtime.savedinstancestate.rememberRestorableStateHolder
-import androidx.compose.ui.platform.ContextAmbient
-import androidx.compose.ui.platform.LifecycleOwnerAmbient
-import androidx.compose.ui.platform.ViewModelStoreOwnerAmbient
+import androidx.compose.ui.platform.AmbientContext
+import androidx.compose.ui.platform.AmbientLifecycleOwner
+import androidx.compose.ui.platform.AmbientViewModelStoreOwner
import androidx.compose.ui.viewinterop.viewModel
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
@@ -82,9 +82,9 @@
@OptIn(ExperimentalRestorableStateHolder::class)
@Composable
public fun NavHost(navController: NavHostController, graph: NavGraph) {
- var context = ContextAmbient.current
- val lifecycleOwner = LifecycleOwnerAmbient.current
- val viewModelStore = ViewModelStoreOwnerAmbient.current.viewModelStore
+ var context = AmbientContext.current
+ val lifecycleOwner = AmbientLifecycleOwner.current
+ val viewModelStore = AmbientViewModelStoreOwner.current.viewModelStore
val rememberedGraph = remember { graph }
// on successful recompose we setup the navController with proper inputs
@@ -124,8 +124,8 @@
// while in the scope of the composable, we provide the navBackStackEntry as the
// ViewModelStoreOwner and LifecycleOwner
Providers(
- ViewModelStoreOwnerAmbient provides currentNavBackStackEntry,
- LifecycleOwnerAmbient provides currentNavBackStackEntry
+ AmbientViewModelStoreOwner provides currentNavBackStackEntry,
+ AmbientLifecycleOwner provides currentNavBackStackEntry
) {
restorableStateHolder.RestorableStateProvider {
destination.content(currentNavBackStackEntry)
diff --git a/navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHostController.kt b/navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHostController.kt
index 059c05f..f4ecc50 100644
--- a/navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHostController.kt
+++ b/navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHostController.kt
@@ -26,7 +26,7 @@
import androidx.compose.runtime.remember
import androidx.compose.runtime.savedinstancestate.Saver
import androidx.compose.runtime.savedinstancestate.rememberSavedInstanceState
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.core.net.toUri
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController
@@ -76,7 +76,7 @@
*/
@Composable
public fun rememberNavController(): NavHostController {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
return rememberSavedInstanceState(saver = NavControllerSaver(context)) {
createNavController(context)
}
diff --git a/navigation/navigation-fragment/src/androidTest/java/androidx/navigation/fragment/DialogFragmentNavigatorTest.kt b/navigation/navigation-fragment/src/androidTest/java/androidx/navigation/fragment/DialogFragmentNavigatorTest.kt
index 4c7b39a..ccaa444 100644
--- a/navigation/navigation-fragment/src/androidTest/java/androidx/navigation/fragment/DialogFragmentNavigatorTest.kt
+++ b/navigation/navigation-fragment/src/androidTest/java/androidx/navigation/fragment/DialogFragmentNavigatorTest.kt
@@ -23,6 +23,8 @@
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentFactory
import androidx.fragment.app.FragmentManager
+import androidx.navigation.NavController
+import androidx.navigation.Navigation
import androidx.test.annotation.UiThreadTest
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
@@ -83,6 +85,28 @@
@UiThreadTest
@Test
+ fun testFindNavController() {
+ val dialogFragment = EmptyDialogFragment()
+ // Fake using a NavHostFragment and instead just manually show the DialogFragment
+ dialogFragment.showNow(fragmentManager, null)
+ assertWithMessage("Dialog should be shown")
+ .that(dialogFragment.requireDialog().isShowing)
+ .isTrue()
+
+ // And set a NavController on the root view
+ val navController = NavController(emptyActivity)
+ Navigation.setViewNavController(
+ dialogFragment.requireDialog().window!!.decorView,
+ navController
+ )
+
+ val returnedNavController = NavHostFragment.findNavController(dialogFragment)
+ assertThat(returnedNavController)
+ .isEqualTo(navController)
+ }
+
+ @UiThreadTest
+ @Test
fun testPop() {
lateinit var dialogFragment: DialogFragment
fragmentManager.fragmentFactory = object : FragmentFactory() {
diff --git a/navigation/navigation-fragment/src/main/java/androidx/navigation/fragment/NavHostFragment.java b/navigation/navigation-fragment/src/main/java/androidx/navigation/fragment/NavHostFragment.java
index 744d5f4..2d0bbea 100644
--- a/navigation/navigation-fragment/src/main/java/androidx/navigation/fragment/NavHostFragment.java
+++ b/navigation/navigation-fragment/src/main/java/androidx/navigation/fragment/NavHostFragment.java
@@ -16,6 +16,7 @@
package androidx.navigation.fragment;
+import android.app.Dialog;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
@@ -30,6 +31,7 @@
import androidx.annotation.NavigationRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentContainerView;
import androidx.navigation.NavController;
@@ -119,6 +121,15 @@
if (view != null) {
return Navigation.findNavController(view);
}
+
+ // For DialogFragments, look at the dialog's decor view
+ Dialog dialog = fragment instanceof DialogFragment
+ ? ((DialogFragment) fragment).getDialog()
+ : null;
+ if (dialog != null && dialog.getWindow() != null) {
+ return Navigation.findNavController(dialog.getWindow().getDecorView());
+ }
+
throw new IllegalStateException("Fragment " + fragment
+ " does not have a NavController set");
}
diff --git a/navigation/settings.gradle b/navigation/settings.gradle
index 6b6da84..0e81dbb 100644
--- a/navigation/settings.gradle
+++ b/navigation/settings.gradle
@@ -20,7 +20,6 @@
setupPlayground(this, "..")
selectProjectsFromAndroidX({ name ->
// Compose projects are not supported in playground yet
- if (name.startsWith(":navigation:navigation-compose")) return false
if (name.startsWith(":navigation")) return true
if (name.startsWith(":internal-testutils-navigation")) return true
if (name.startsWith(":internal-testutils-runtime")) return true
diff --git a/paging/compose/OWNERS b/paging/paging-compose/OWNERS
similarity index 100%
rename from paging/compose/OWNERS
rename to paging/paging-compose/OWNERS
diff --git a/paging/compose/api/current.txt b/paging/paging-compose/api/current.txt
similarity index 100%
rename from paging/compose/api/current.txt
rename to paging/paging-compose/api/current.txt
diff --git a/paging/compose/api/public_plus_experimental_current.txt b/paging/paging-compose/api/public_plus_experimental_current.txt
similarity index 100%
rename from paging/compose/api/public_plus_experimental_current.txt
rename to paging/paging-compose/api/public_plus_experimental_current.txt
diff --git a/paging/compose/api/res-current.txt b/paging/paging-compose/api/res-current.txt
similarity index 100%
rename from paging/compose/api/res-current.txt
rename to paging/paging-compose/api/res-current.txt
diff --git a/paging/compose/api/restricted_current.txt b/paging/paging-compose/api/restricted_current.txt
similarity index 100%
rename from paging/compose/api/restricted_current.txt
rename to paging/paging-compose/api/restricted_current.txt
diff --git a/paging/compose/build.gradle b/paging/paging-compose/build.gradle
similarity index 85%
rename from paging/compose/build.gradle
rename to paging/paging-compose/build.gradle
index b7a36ca..2d099c2 100644
--- a/paging/compose/build.gradle
+++ b/paging/paging-compose/build.gradle
@@ -31,14 +31,14 @@
}
dependencies {
- kotlinPlugin project(path: ":compose:compiler:compiler")
+ kotlinPlugin projectOrArtifact(":compose:compiler:compiler")
implementation(KOTLIN_STDLIB)
- api project(":compose:foundation:foundation")
+ api projectOrArtifact(":compose:foundation:foundation")
api("androidx.paging:paging-common-ktx:3.0.0-alpha06")
- androidTestImplementation project(":compose:ui:ui-test-junit4")
- androidTestImplementation project(':internal-testutils-paging')
+ androidTestImplementation projectOrArtifact(":compose:ui:ui-test-junit4")
+ androidTestImplementation projectOrArtifact(':internal-testutils-paging')
androidTestImplementation(ANDROIDX_TEST_RUNNER)
androidTestImplementation(JUNIT)
androidTestImplementation(TRUTH)
diff --git a/paging/compose/integration-tests/paging-demos/build.gradle b/paging/paging-compose/integration-tests/paging-demos/build.gradle
similarity index 77%
rename from paging/compose/integration-tests/paging-demos/build.gradle
rename to paging/paging-compose/integration-tests/paging-demos/build.gradle
index 958db48..7991870 100644
--- a/paging/compose/integration-tests/paging-demos/build.gradle
+++ b/paging/paging-compose/integration-tests/paging-demos/build.gradle
@@ -29,14 +29,14 @@
}
dependencies {
- kotlinPlugin project(path: ":compose:compiler:compiler")
+ kotlinPlugin projectOrArtifact(":compose:compiler:compiler")
implementation(KOTLIN_STDLIB)
- implementation project(":compose:integration-tests:demos:common")
- implementation project(":compose:foundation:foundation")
- implementation project(":compose:material:material")
- implementation project(":paging:paging-compose")
- implementation project(":paging:paging-compose:paging-compose-samples")
+ implementation projectOrArtifact(":compose:integration-tests:demos:common")
+ implementation projectOrArtifact(":compose:foundation:foundation")
+ implementation projectOrArtifact(":compose:material:material")
+ implementation projectOrArtifact(":paging:paging-compose")
+ implementation projectOrArtifact(":paging:paging-compose:paging-compose-samples")
def room_version = "2.3.0-alpha02"
api "androidx.room:room-runtime:$room_version"
diff --git a/paging/compose/integration-tests/paging-demos/src/main/AndroidManifest.xml b/paging/paging-compose/integration-tests/paging-demos/src/main/AndroidManifest.xml
similarity index 100%
rename from paging/compose/integration-tests/paging-demos/src/main/AndroidManifest.xml
rename to paging/paging-compose/integration-tests/paging-demos/src/main/AndroidManifest.xml
diff --git a/paging/compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/PagingDemos.kt b/paging/paging-compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/PagingDemos.kt
similarity index 100%
rename from paging/compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/PagingDemos.kt
rename to paging/paging-compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/PagingDemos.kt
diff --git a/paging/compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/AppDatabase.kt b/paging/paging-compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/AppDatabase.kt
similarity index 100%
rename from paging/compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/AppDatabase.kt
rename to paging/paging-compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/AppDatabase.kt
diff --git a/paging/compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/PagingRoomSample.kt b/paging/paging-compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/PagingRoomSample.kt
similarity index 97%
rename from paging/compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/PagingRoomSample.kt
rename to paging/paging-compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/PagingRoomSample.kt
index 30d641c..93dea17 100644
--- a/paging/compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/PagingRoomSample.kt
+++ b/paging/paging-compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/PagingRoomSample.kt
@@ -23,7 +23,7 @@
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
-import androidx.compose.ui.platform.ContextAmbient
+import androidx.compose.ui.platform.AmbientContext
import androidx.compose.ui.unit.sp
import androidx.paging.Pager
import androidx.paging.PagingConfig
@@ -35,7 +35,7 @@
@Composable
fun PagingRoomDemo() {
- val context = ContextAmbient.current
+ val context = AmbientContext.current
val dao: UserDao = AppDatabase.getInstance(context).userDao()
val scope = rememberCoroutineScope()
diff --git a/paging/compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/User.kt b/paging/paging-compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/User.kt
similarity index 100%
rename from paging/compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/User.kt
rename to paging/paging-compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/User.kt
diff --git a/paging/compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/UserDao.kt b/paging/paging-compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/UserDao.kt
similarity index 100%
rename from paging/compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/UserDao.kt
rename to paging/paging-compose/integration-tests/paging-demos/src/main/java/androidx/paging/compose/demos/room/UserDao.kt
diff --git a/paging/compose/samples/build.gradle b/paging/paging-compose/samples/build.gradle
similarity index 81%
rename from paging/compose/samples/build.gradle
rename to paging/paging-compose/samples/build.gradle
index f226e0a..3acd447 100644
--- a/paging/compose/samples/build.gradle
+++ b/paging/paging-compose/samples/build.gradle
@@ -29,13 +29,13 @@
}
dependencies {
- kotlinPlugin project(path: ":compose:compiler:compiler")
+ kotlinPlugin projectOrArtifact(":compose:compiler:compiler")
implementation(KOTLIN_STDLIB)
- compileOnly project(":annotation:annotation-sampled")
- implementation project(":compose:foundation:foundation")
- implementation project(":compose:material:material")
- implementation project(":paging:paging-compose")
+ compileOnly projectOrArtifact(":annotation:annotation-sampled")
+ implementation projectOrArtifact(":compose:foundation:foundation")
+ implementation projectOrArtifact(":compose:material:material")
+ implementation projectOrArtifact(":paging:paging-compose")
}
androidx {
diff --git a/paging/compose/samples/src/main/AndroidManifest.xml b/paging/paging-compose/samples/src/main/AndroidManifest.xml
similarity index 100%
rename from paging/compose/samples/src/main/AndroidManifest.xml
rename to paging/paging-compose/samples/src/main/AndroidManifest.xml
diff --git a/paging/compose/samples/src/main/java/androidx/paging/compose/samples/PagingSample.kt b/paging/paging-compose/samples/src/main/java/androidx/paging/compose/samples/PagingSample.kt
similarity index 100%
rename from paging/compose/samples/src/main/java/androidx/paging/compose/samples/PagingSample.kt
rename to paging/paging-compose/samples/src/main/java/androidx/paging/compose/samples/PagingSample.kt
diff --git a/paging/compose/src/androidTest/AndroidManifest.xml b/paging/paging-compose/src/androidTest/AndroidManifest.xml
similarity index 100%
rename from paging/compose/src/androidTest/AndroidManifest.xml
rename to paging/paging-compose/src/androidTest/AndroidManifest.xml
diff --git a/paging/compose/src/androidTest/java/androidx/paging/compose/LazyPagingItemsTest.kt b/paging/paging-compose/src/androidTest/java/androidx/paging/compose/LazyPagingItemsTest.kt
similarity index 100%
rename from paging/compose/src/androidTest/java/androidx/paging/compose/LazyPagingItemsTest.kt
rename to paging/paging-compose/src/androidTest/java/androidx/paging/compose/LazyPagingItemsTest.kt
diff --git a/paging/compose/src/main/AndroidManifest.xml b/paging/paging-compose/src/main/AndroidManifest.xml
similarity index 100%
rename from paging/compose/src/main/AndroidManifest.xml
rename to paging/paging-compose/src/main/AndroidManifest.xml
diff --git a/paging/compose/src/main/java/androidx/paging/compose/LazyPagingItems.kt b/paging/paging-compose/src/main/java/androidx/paging/compose/LazyPagingItems.kt
similarity index 100%
rename from paging/compose/src/main/java/androidx/paging/compose/LazyPagingItems.kt
rename to paging/paging-compose/src/main/java/androidx/paging/compose/LazyPagingItems.kt
diff --git a/paging/settings.gradle b/paging/settings.gradle
index 3120ebe..c737672e 100644
--- a/paging/settings.gradle
+++ b/paging/settings.gradle
@@ -19,7 +19,6 @@
apply from: "../playground-common/playground-include-settings.gradle"
setupPlayground(this, "..")
selectProjectsFromAndroidX({ name ->
- if (name.startsWith(":paging:paging-compose")) return false
if (name.startsWith(":paging")) return true
return false
})
diff --git a/playground-common/playground-include-settings.gradle b/playground-common/playground-include-settings.gradle
index 4228541..f08d223 100644
--- a/playground-common/playground-include-settings.gradle
+++ b/playground-common/playground-include-settings.gradle
@@ -70,6 +70,10 @@
new File(supportRoot, "testutils/testutils-common"))
settings.includeProject(":internal-testutils-gradle-plugin",
new File(supportRoot, "testutils/testutils-gradle-plugin"))
+
+ // AndroidXUiPlugin dependencies
+ settings.includeProject(":compose:internal-lint-checks",
+ new File(supportRoot, "compose/internal-lint-checks"))
}
/**
diff --git a/room/compiler-processing/src/main/java/androidx/room/compiler/processing/XType.kt b/room/compiler-processing/src/main/java/androidx/room/compiler/processing/XType.kt
index db41d40..8ba6067 100644
--- a/room/compiler-processing/src/main/java/androidx/room/compiler/processing/XType.kt
+++ b/room/compiler-processing/src/main/java/androidx/room/compiler/processing/XType.kt
@@ -134,11 +134,6 @@
fun isType(): Boolean
/**
- * Returns true if this represented by an [Enum].
- */
- fun isEnum(): Boolean
-
- /**
* Returns `true` if this is the same raw type as [other]
*/
fun isTypeOf(other: KClass<*>): Boolean
diff --git a/room/compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacType.kt b/room/compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacType.kt
index dc9a6be..de5dc66 100644
--- a/room/compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacType.kt
+++ b/room/compiler-processing/src/main/java/androidx/room/compiler/processing/javac/JavacType.kt
@@ -25,7 +25,6 @@
import androidx.room.compiler.processing.safeTypeName
import com.google.auto.common.MoreTypes
import com.squareup.javapoet.TypeName
-import javax.lang.model.element.ElementKind
import javax.lang.model.type.TypeKind
import javax.lang.model.type.TypeMirror
import kotlin.reflect.KClass
@@ -139,7 +138,4 @@
private val BOXED_LONG = TypeName.LONG.box()
private val BOXED_BYTE = TypeName.BYTE.box()
}
-
- override fun isEnum() = typeMirror.kind == TypeKind.DECLARED &&
- MoreTypes.asElement(typeMirror).kind == ElementKind.ENUM
}
diff --git a/room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspType.kt b/room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspType.kt
index 5329363..aad772f 100644
--- a/room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspType.kt
+++ b/room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspType.kt
@@ -20,7 +20,6 @@
import androidx.room.compiler.processing.XNullability
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.XTypeElement
-import com.google.devtools.ksp.symbol.ClassKind
import androidx.room.compiler.processing.tryBox
import androidx.room.compiler.processing.tryUnbox
import com.google.devtools.ksp.symbol.KSClassDeclaration
@@ -152,8 +151,4 @@
override fun toString(): String {
return ksType.toString()
}
-
- override fun isEnum(): Boolean {
- return (ksType.declaration as? KSClassDeclaration)?.classKind == ClassKind.ENUM_CLASS
- }
}
diff --git a/room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeArgumentType.kt b/room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeArgumentType.kt
index 19ac355..36a3e12 100644
--- a/room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeArgumentType.kt
+++ b/room/compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KspTypeArgumentType.kt
@@ -17,9 +17,9 @@
package androidx.room.compiler.processing.ksp
import androidx.room.compiler.processing.XType
+import com.squareup.javapoet.TypeName
import com.google.devtools.ksp.symbol.KSTypeArgument
import com.google.devtools.ksp.symbol.KSTypeParameter
-import com.squareup.javapoet.TypeName
/**
* The typeName for type arguments requires the type parameter, hence we have a special type
diff --git a/room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt b/room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
index f4cf3a5..d79a71c 100644
--- a/room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
@@ -16,16 +16,16 @@
package androidx.room.solver
+import androidx.room.ext.CommonTypeNames
+import androidx.room.ext.GuavaBaseTypeNames
+import androidx.room.ext.isEntityElement
+import androidx.room.parser.ParsedQuery
+import androidx.room.parser.SQLTypeAffinity
import androidx.room.compiler.processing.XType
import androidx.room.compiler.processing.asDeclaredType
import androidx.room.compiler.processing.isArray
import androidx.room.compiler.processing.isDeclared
-import androidx.room.ext.CommonTypeNames
-import androidx.room.ext.GuavaBaseTypeNames
-import androidx.room.ext.isEntityElement
import androidx.room.ext.isNotByte
-import androidx.room.parser.ParsedQuery
-import androidx.room.parser.SQLTypeAffinity
import androidx.room.processor.Context
import androidx.room.processor.EntityProcessor
import androidx.room.processor.FieldProcessor
@@ -86,7 +86,6 @@
import androidx.room.solver.types.CompositeAdapter
import androidx.room.solver.types.CompositeTypeConverter
import androidx.room.solver.types.CursorValueReader
-import androidx.room.solver.types.EnumColumnTypeAdapter
import androidx.room.solver.types.NoOpConverter
import androidx.room.solver.types.PrimitiveBooleanToIntConverter
import androidx.room.solver.types.PrimitiveColumnTypeAdapter
@@ -219,26 +218,13 @@
if (adapter != null) {
return adapter
}
-
- fun findTypeConverterAdapter(): ColumnTypeAdapter? {
- val targetTypes = targetTypeMirrorsFor(affinity)
- val binder = findTypeConverter(input, targetTypes) ?: return null
- // columnAdapter should not be null but we are receiving errors on crash in `first()` so
- // this safeguard allows us to dispatch the real problem to the user (e.g. why we couldn't
- // find the right adapter)
- val columnAdapter = getAllColumnAdapters(binder.to).firstOrNull() ?: return null
- return CompositeAdapter(input, columnAdapter, binder, null)
- }
-
- val adapterByTypeConverter = findTypeConverterAdapter()
- if (adapterByTypeConverter != null) {
- return adapterByTypeConverter
- }
- val enumAdapter = createEnumTypeAdapter(input)
- if (enumAdapter != null) {
- return enumAdapter
- }
- return null
+ val targetTypes = targetTypeMirrorsFor(affinity)
+ val binder = findTypeConverter(input, targetTypes) ?: return null
+ // columnAdapter should not be null but we are receiving errors on crash in `first()` so
+ // this safeguard allows us to dispatch the real problem to the user (e.g. why we couldn't
+ // find the right adapter)
+ val columnAdapter = getAllColumnAdapters(binder.to).firstOrNull() ?: return null
+ return CompositeAdapter(input, columnAdapter, binder, null)
}
/**
@@ -265,28 +251,13 @@
// two way is better
return adapter
}
-
- fun findTypeConverterAdapter(): ColumnTypeAdapter? {
- val targetTypes = targetTypeMirrorsFor(affinity)
- val converter = findTypeConverter(targetTypes, output) ?: return null
- return CompositeAdapter(
- output,
- getAllColumnAdapters(converter.from).first(), null, converter
- )
- }
-
// we could not find a two way version, search for anything
- val typeConverterAdapter = findTypeConverterAdapter()
- if (typeConverterAdapter != null) {
- return typeConverterAdapter
- }
-
- val enumAdapter = createEnumTypeAdapter(output)
- if (enumAdapter != null) {
- return enumAdapter
- }
-
- return null
+ val targetTypes = targetTypeMirrorsFor(affinity)
+ val converter = findTypeConverter(targetTypes, output) ?: return null
+ return CompositeAdapter(
+ output,
+ getAllColumnAdapters(converter.from).first(), null, converter
+ )
}
/**
@@ -322,34 +293,15 @@
if (adapter != null) {
return adapter
}
-
- fun findTypeConverterAdapter(): ColumnTypeAdapter? {
- val targetTypes = targetTypeMirrorsFor(affinity)
- val intoStatement = findTypeConverter(out, targetTypes) ?: return null
- // ok found a converter, try the reverse now
- val fromCursor = reverse(intoStatement) ?: findTypeConverter(intoStatement.to, out)
- ?: return null
- return CompositeAdapter(
- out, getAllColumnAdapters(intoStatement.to).first(), intoStatement, fromCursor
- )
- }
-
- val adapterByTypeConverter = findTypeConverterAdapter()
- if (adapterByTypeConverter != null) {
- return adapterByTypeConverter
- }
- val enumAdapter = createEnumTypeAdapter(out)
- if (enumAdapter != null) {
- return enumAdapter
- }
- return null
- }
-
- private fun createEnumTypeAdapter(type: XType): ColumnTypeAdapter? {
- if (type.isEnum()) {
- return EnumColumnTypeAdapter(type)
- }
- return null
+ val targetTypes = targetTypeMirrorsFor(affinity)
+ val intoStatement = findTypeConverter(out, targetTypes) ?: return null
+ // ok found a converter, try the reverse now
+ val fromCursor = reverse(intoStatement) ?: findTypeConverter(intoStatement.to, out)
+ ?: return null
+ return CompositeAdapter(
+ out, getAllColumnAdapters(intoStatement.to).first(), intoStatement,
+ fromCursor
+ )
}
private fun findDirectAdapterFor(
@@ -561,17 +513,17 @@
if (typeMirror.isType() &&
context.COMMON_TYPES.COLLECTION.rawType.isAssignableFrom(typeMirror)
) {
- val collectionBinder = findStatementValueBinder(typeMirror, null)
- if (collectionBinder != null) {
- // user has a converter for the collection itself
- return BasicQueryParameterAdapter(collectionBinder)
- }
-
val declared = typeMirror.asDeclaredType()
val binder = findStatementValueBinder(
declared.typeArguments.first().extendsBoundOrSelf(), null
- ) ?: return null
- return CollectionQueryParameterAdapter(binder)
+ )
+ if (binder != null) {
+ return CollectionQueryParameterAdapter(binder)
+ } else {
+ // maybe user wants to convert this collection themselves. look for a match
+ val collectionBinder = findStatementValueBinder(typeMirror, null) ?: return null
+ return BasicQueryParameterAdapter(collectionBinder)
+ }
} else if (typeMirror.isArray() && typeMirror.componentType.isNotByte()) {
val component = typeMirror.componentType
val binder = findStatementValueBinder(component, null) ?: return null
diff --git a/room/compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt b/room/compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt
deleted file mode 100644
index 1194b1d..0000000
--- a/room/compiler/src/main/kotlin/androidx/room/solver/types/EnumColumnTypeAdapter.kt
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 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.room.solver.types
-
-import androidx.room.compiler.processing.XType
-import androidx.room.ext.L
-import androidx.room.ext.T
-import androidx.room.parser.SQLTypeAffinity.TEXT
-import androidx.room.solver.CodeGenScope
-
-/**
- * Uses enum string representation.
- */
-class EnumColumnTypeAdapter(out: XType) :
- ColumnTypeAdapter(out, TEXT) {
- private val enumTypeName = out.typeName
- override fun readFromCursor(
- outVarName: String,
- cursorVarName: String,
- indexVarName: String,
- scope: CodeGenScope
- ) {
- scope.builder()
- .addStatement(
- "$L = $T.valueOf($L.getString($L))", outVarName, enumTypeName,
- cursorVarName,
- indexVarName
- )
- }
-
- override fun bindToStmt(
- stmtName: String,
- indexVarName: String,
- valueVarName: String,
- scope: CodeGenScope
- ) {
- scope.builder().apply {
- beginControlFlow("if ($L == null)", valueVarName)
- .addStatement("$L.bindNull($L)", stmtName, indexVarName)
- nextControlFlow("else")
- .addStatement("$L.bindString($L, $L.name())", stmtName, indexVarName, valueVarName)
- endControlFlow()
- }
- }
-}
\ No newline at end of file
diff --git a/room/compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt b/room/compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
index 1f1d6cb..085b391 100644
--- a/room/compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
@@ -50,24 +50,6 @@
}
@Test
- fun testUnusedEnumCompilesWithoutError() {
- singleDao(
- """
- @Dao abstract class MyDao {
- @Query("SELECT uid FROM User")
- abstract int[] getIds();
- enum Fruit {
- APPLE,
- BANANA,
- STRAWBERRY
- }
- }
- """
- ) { _, _ ->
- }.compilesWithoutError()
- }
-
- @Test
fun testNonAbstract() {
singleDao("@Dao public class MyDao {}") { _, _ -> }
.failsToCompile()
diff --git a/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt b/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
index 3d437fc..e520c12 100644
--- a/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
+++ b/room/compiler/src/test/kotlin/androidx/room/solver/TypeAdapterStoreTest.kt
@@ -20,8 +20,6 @@
import androidx.paging.DataSource
import androidx.paging.PagingSource
import androidx.room.Entity
-import androidx.room.compiler.processing.XProcessingEnv
-import androidx.room.compiler.processing.asDeclaredType
import androidx.room.ext.GuavaUtilConcurrentTypeNames
import androidx.room.ext.L
import androidx.room.ext.LifecyclesTypeNames
@@ -32,6 +30,8 @@
import androidx.room.ext.RxJava3TypeNames
import androidx.room.ext.T
import androidx.room.parser.SQLTypeAffinity
+import androidx.room.compiler.processing.XProcessingEnv
+import androidx.room.compiler.processing.asDeclaredType
import androidx.room.processor.Context
import androidx.room.processor.ProcessorErrors
import androidx.room.solver.binderprovider.DataSourceFactoryQueryResultBinderProvider
@@ -44,7 +44,6 @@
import androidx.room.solver.shortcut.binderprovider.RxCallableDeleteOrUpdateMethodBinderProvider
import androidx.room.solver.shortcut.binderprovider.RxCallableInsertMethodBinderProvider
import androidx.room.solver.types.CompositeAdapter
-import androidx.room.solver.types.EnumColumnTypeAdapter
import androidx.room.solver.types.TypeConverter
import androidx.room.testing.TestInvocation
import androidx.room.testing.TestProcessor
@@ -104,30 +103,6 @@
}
@Test
- fun testJavaLangEnumCompilesWithoutError() {
- simpleRun(
- JavaFileObjects.forSourceString(
- "foo.bar.Fruit",
- """ package foo.bar;
- import androidx.room.*;
- enum Fruit {
- APPLE,
- BANANA,
- STRAWBERRY}
- """.trimMargin()
- )
- ) { invocation ->
- val store = TypeAdapterStore.create(Context(invocation.processingEnv))
- val enum = invocation
- .processingEnv
- .requireType("foo.bar.Fruit")
- val adapter = store.findColumnTypeAdapter(enum, null)
- assertThat(adapter, notNullValue())
- assertThat(adapter, instanceOf(EnumColumnTypeAdapter::class.java))
- }.compilesWithoutError()
- }
-
- @Test
fun testVia1TypeAdapter() {
singleRun { invocation ->
val store = TypeAdapterStore.create(Context(invocation.processingEnv))
diff --git a/room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/EnumColumnTypeAdapterTest.java b/room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/EnumColumnTypeAdapterTest.java
deleted file mode 100644
index 4c0df94..0000000
--- a/room/integration-tests/testapp/src/androidTest/java/androidx/room/integration/testapp/test/EnumColumnTypeAdapterTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.room.integration.testapp.test;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-import android.content.Context;
-
-import androidx.room.Dao;
-import androidx.room.Database;
-import androidx.room.Entity;
-import androidx.room.PrimaryKey;
-import androidx.room.Query;
-import androidx.room.Room;
-import androidx.room.RoomDatabase;
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-import androidx.test.filters.SmallTest;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class EnumColumnTypeAdapterTest {
-
- private EnumColumnTypeAdapterDatabase mDb;
-
- @Entity
- public static class EntityWithEnum {
- @PrimaryKey
- public Long id;
- public Fruit fruit;
- }
-
- public enum Fruit {
- BANANA,
- STRAWBERRY,
- WILDBERRY
- }
-
- @Dao
- public interface SampleDao {
- @Query("INSERT INTO EntityWithEnum (id, fruit) VALUES (:id, :fruit)")
- long insert(long id, Fruit fruit);
-
- @Query("SELECT * FROM EntityWithEnum WHERE id = :id")
- EntityWithEnum getValueWithId(long id);
- }
-
- @Database(entities = {EntityWithEnum.class}, version = 1, exportSchema = false)
- public abstract static class EnumColumnTypeAdapterDatabase extends RoomDatabase {
- public abstract EnumColumnTypeAdapterTest.SampleDao dao();
- }
-
- @Before
- public void initDb() {
- Context context = ApplicationProvider.getApplicationContext();
- mDb = Room.inMemoryDatabaseBuilder(
- context,
- EnumColumnTypeAdapterDatabase.class)
- .build();
- }
-
- @Test
- public void readAndWriteEnumToDatabase() {
- final long id1 = mDb.dao().insert(1, Fruit.BANANA);
- final long id2 = mDb.dao().insert(2, Fruit.STRAWBERRY);
-
- assertThat(mDb.dao().getValueWithId(1).fruit, is(equalTo(Fruit.BANANA)));
- assertThat(mDb.dao().getValueWithId(2).fruit, is(equalTo(Fruit.STRAWBERRY)));
- }
-}
diff --git a/settings.gradle b/settings.gradle
index 3977f56..371eb21 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -385,9 +385,9 @@
includeProject(":paging:integration-tests:testapp", "paging/integration-tests/testapp", [BuildType.MAIN])
includeProject(":paging:paging-common", "paging/common", [BuildType.MAIN, BuildType.COMPOSE])
includeProject(":paging:paging-common-ktx", "paging/common/ktx", [BuildType.MAIN])
-includeProject(":paging:paging-compose", "paging/compose", [BuildType.COMPOSE])
-includeProject(":paging:paging-compose:paging-compose-samples", "paging/compose/samples", [BuildType.COMPOSE])
-includeProject(":paging:paging-compose:integration-tests:paging-demos", "paging/compose/integration-tests/paging-demos", [BuildType.COMPOSE])
+includeProject(":paging:paging-compose", "paging/paging-compose", [BuildType.COMPOSE])
+includeProject(":paging:paging-compose:paging-compose-samples", "paging/paging-compose/samples", [BuildType.COMPOSE])
+includeProject(":paging:paging-compose:integration-tests:paging-demos", "paging/paging-compose/integration-tests/paging-demos", [BuildType.COMPOSE])
includeProject(":paging:paging-guava", "paging/guava", [BuildType.MAIN])
includeProject(":paging:paging-runtime", "paging/runtime", [BuildType.MAIN])
includeProject(":paging:paging-runtime-ktx", "paging/runtime/ktx", [BuildType.MAIN])
diff --git a/sharetarget/integration-tests/testapp/build.gradle b/sharetarget/integration-tests/testapp/build.gradle
index d52bb03..7cdbf10 100644
--- a/sharetarget/integration-tests/testapp/build.gradle
+++ b/sharetarget/integration-tests/testapp/build.gradle
@@ -22,8 +22,8 @@
}
dependencies {
- api("androidx.core:core:1.2.0")
+ api("androidx.core:core:1.3.2")
api(project(":sharetarget:sharetarget"))
- api("androidx.appcompat:appcompat:1.1.0")
+ api("androidx.appcompat:appcompat:1.2.0")
api(CONSTRAINT_LAYOUT, { transitive = true })
}
diff --git a/sharetarget/sharetarget/build.gradle b/sharetarget/sharetarget/build.gradle
index df91c67..3713624 100644
--- a/sharetarget/sharetarget/build.gradle
+++ b/sharetarget/sharetarget/build.gradle
@@ -25,8 +25,8 @@
}
dependencies {
- api("androidx.core:core:1.2.0")
- api("androidx.collection:collection:1.0.0")
+ api("androidx.core:core:1.3.2")
+ api("androidx.collection:collection:1.1.0")
api(GUAVA_LISTENABLE_FUTURE)
implementation("androidx.concurrent:concurrent-futures:1.0.0")
diff --git a/sharetarget/sharetarget/src/main/java/androidx/sharetarget/ShortcutInfoCompatSaverImpl.java b/sharetarget/sharetarget/src/main/java/androidx/sharetarget/ShortcutInfoCompatSaverImpl.java
index dc4305b..d13e905 100644
--- a/sharetarget/sharetarget/src/main/java/androidx/sharetarget/ShortcutInfoCompatSaverImpl.java
+++ b/sharetarget/sharetarget/src/main/java/androidx/sharetarget/ShortcutInfoCompatSaverImpl.java
@@ -21,7 +21,6 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.graphics.drawable.Icon;
import android.text.TextUtils;
import android.util.Log;
@@ -377,17 +376,18 @@
IconCompat icon = shortcut.getIcon();
if (icon != null) {
switch (icon.getType()) {
- case Icon.TYPE_RESOURCE:
+ case IconCompat.TYPE_RESOURCE:
resourceName = mContext.getResources().getResourceName(icon.getResId());
break;
- case Icon.TYPE_BITMAP:
- case Icon.TYPE_ADAPTIVE_BITMAP:
+ case IconCompat.TYPE_BITMAP:
+ case IconCompat.TYPE_ADAPTIVE_BITMAP:
// Choose a unique file name to serialize the bitmap
bitmapPath = new File(mBitmapsDir, UUID.randomUUID().toString())
.getAbsolutePath();
break;
- case Icon.TYPE_DATA:
- case Icon.TYPE_URI:
+ case IconCompat.TYPE_DATA:
+ case IconCompat.TYPE_URI:
+ case IconCompat.TYPE_URI_ADAPTIVE_BITMAP:
case IconCompat.TYPE_UNKNOWN:
break;
}
diff --git a/ui/ui-animation-tooling-internal/build.gradle b/ui/ui-animation-tooling-internal/build.gradle
index 9b1a82ec4..b31553c 100644
--- a/ui/ui-animation-tooling-internal/build.gradle
+++ b/ui/ui-animation-tooling-internal/build.gradle
@@ -34,7 +34,6 @@
name = "Compose Animation Tooling"
description = "Compose Animation APIs for tooling support. Internal use only."
publish = Publish.SNAPSHOT_ONLY
- mavenVersion = LibraryVersions.COMPOSE
mavenGroup = LibraryGroups.UI
runApiTasks = new RunApiTasks.Yes()
}
diff --git a/wear/wear-complications-data/api/current.txt b/wear/wear-complications-data/api/current.txt
index fdd13cb..1c19ae3 100644
--- a/wear/wear-complications-data/api/current.txt
+++ b/wear/wear-complications-data/api/current.txt
@@ -215,7 +215,6 @@
ctor public BackgroundImageComplicationData.Builder(androidx.wear.complications.data.BackgroundImage icon);
method public androidx.wear.complications.data.BackgroundImageComplicationData build();
method public androidx.wear.complications.data.BackgroundImageComplicationData.Builder setContentDescription(androidx.wear.complications.data.ComplicationText? contentDescription);
- method public androidx.wear.complications.data.BackgroundImageComplicationData.Builder setTapAction(android.app.PendingIntent? tapAction);
method public androidx.wear.complications.data.BackgroundImageComplicationData.Builder setValidTimeRange(androidx.wear.complications.data.TimeRange? validTimeRange);
}
@@ -344,7 +343,6 @@
ctor public NoPermissionComplicationData.Builder();
method public androidx.wear.complications.data.NoPermissionComplicationData build();
method public androidx.wear.complications.data.NoPermissionComplicationData.Builder setImage(androidx.wear.complications.data.MonochromaticImage? image);
- method public androidx.wear.complications.data.NoPermissionComplicationData.Builder setTapAction(android.app.PendingIntent? tapAction);
method public androidx.wear.complications.data.NoPermissionComplicationData.Builder setText(androidx.wear.complications.data.ComplicationText? text);
method public androidx.wear.complications.data.NoPermissionComplicationData.Builder setTitle(androidx.wear.complications.data.ComplicationText? title);
}
diff --git a/wear/wear-complications-data/api/public_plus_experimental_current.txt b/wear/wear-complications-data/api/public_plus_experimental_current.txt
index da69a8c..c2518ff 100644
--- a/wear/wear-complications-data/api/public_plus_experimental_current.txt
+++ b/wear/wear-complications-data/api/public_plus_experimental_current.txt
@@ -216,7 +216,6 @@
ctor public BackgroundImageComplicationData.Builder(androidx.wear.complications.data.BackgroundImage icon);
method public androidx.wear.complications.data.BackgroundImageComplicationData build();
method public androidx.wear.complications.data.BackgroundImageComplicationData.Builder setContentDescription(androidx.wear.complications.data.ComplicationText? contentDescription);
- method public androidx.wear.complications.data.BackgroundImageComplicationData.Builder setTapAction(android.app.PendingIntent? tapAction);
method public androidx.wear.complications.data.BackgroundImageComplicationData.Builder setValidTimeRange(androidx.wear.complications.data.TimeRange? validTimeRange);
}
@@ -351,7 +350,6 @@
ctor public NoPermissionComplicationData.Builder();
method public androidx.wear.complications.data.NoPermissionComplicationData build();
method public androidx.wear.complications.data.NoPermissionComplicationData.Builder setImage(androidx.wear.complications.data.MonochromaticImage? image);
- method public androidx.wear.complications.data.NoPermissionComplicationData.Builder setTapAction(android.app.PendingIntent? tapAction);
method public androidx.wear.complications.data.NoPermissionComplicationData.Builder setText(androidx.wear.complications.data.ComplicationText? text);
method public androidx.wear.complications.data.NoPermissionComplicationData.Builder setTitle(androidx.wear.complications.data.ComplicationText? title);
}
diff --git a/wear/wear-complications-data/api/restricted_current.txt b/wear/wear-complications-data/api/restricted_current.txt
index 83e4f49..b4eb6ea 100644
--- a/wear/wear-complications-data/api/restricted_current.txt
+++ b/wear/wear-complications-data/api/restricted_current.txt
@@ -257,7 +257,6 @@
ctor public BackgroundImageComplicationData.Builder(androidx.wear.complications.data.BackgroundImage icon);
method public androidx.wear.complications.data.BackgroundImageComplicationData build();
method public androidx.wear.complications.data.BackgroundImageComplicationData.Builder setContentDescription(androidx.wear.complications.data.ComplicationText? contentDescription);
- method public androidx.wear.complications.data.BackgroundImageComplicationData.Builder setTapAction(android.app.PendingIntent? tapAction);
method public androidx.wear.complications.data.BackgroundImageComplicationData.Builder setValidTimeRange(androidx.wear.complications.data.TimeRange? validTimeRange);
}
@@ -402,7 +401,6 @@
ctor public NoPermissionComplicationData.Builder();
method public androidx.wear.complications.data.NoPermissionComplicationData build();
method public androidx.wear.complications.data.NoPermissionComplicationData.Builder setImage(androidx.wear.complications.data.MonochromaticImage? image);
- method public androidx.wear.complications.data.NoPermissionComplicationData.Builder setTapAction(android.app.PendingIntent? tapAction);
method public androidx.wear.complications.data.NoPermissionComplicationData.Builder setText(androidx.wear.complications.data.ComplicationText? text);
method public androidx.wear.complications.data.NoPermissionComplicationData.Builder setTitle(androidx.wear.complications.data.ComplicationText? title);
}
diff --git a/wear/wear-complications-data/src/main/java/androidx/wear/complications/data/Data.kt b/wear/wear-complications-data/src/main/java/androidx/wear/complications/data/Data.kt
index f83c0de6..956cc79 100644
--- a/wear/wear-complications-data/src/main/java/androidx/wear/complications/data/Data.kt
+++ b/wear/wear-complications-data/src/main/java/androidx/wear/complications/data/Data.kt
@@ -181,6 +181,7 @@
setShortText(text.asWireComplicationText())
setShortTitle(title?.asWireComplicationText())
image?.addToWireComplicationData(this)
+ setTapAction(tapAction)
}.build()
/** @hide */
@@ -266,6 +267,7 @@
setLongTitle(title?.asWireComplicationText())
monochromaticImage?.addToWireComplicationData(this)
smallImage?.addToWireComplicationData(this)
+ setTapAction(tapAction)
}.build()
/** @hide */
@@ -354,6 +356,7 @@
image?.addToWireComplicationData(this)
setShortText(text?.asWireComplicationText())
setShortTitle(title?.asWireComplicationText())
+ setTapAction(tapAction)
}.build()
/** @hide */
@@ -415,6 +418,7 @@
WireComplicationDataBuilder(TYPE.asWireComplicationType()).apply {
image.addToWireComplicationData(this)
setContentDescription(contentDescription?.asWireComplicationText())
+ setTapAction(tapAction)
}.build()
/** @hide */
@@ -476,6 +480,7 @@
WireComplicationDataBuilder(TYPE.asWireComplicationType()).apply {
image.addToWireComplicationData(this)
setContentDescription(contentDescription?.asWireComplicationText())
+ setTapAction(tapAction)
}.build()
/** @hide */
@@ -501,24 +506,17 @@
public class BackgroundImageComplicationData internal constructor(
public val image: BackgroundImage,
public val contentDescription: ComplicationText?,
- tapAction: PendingIntent?,
validTimeRange: TimeRange?
-) : ComplicationData(TYPE, tapAction, validTimeRange) {
+) : ComplicationData(TYPE, null, validTimeRange) {
/**
* Builder for [BackgroundImageComplicationData].
*
* You must at a minimum set the [icon] field.
*/
public class Builder(private val icon: BackgroundImage) {
- private var tapAction: PendingIntent? = null
private var validTimeRange: TimeRange? = null
private var contentDescription: ComplicationText? = null
- /** Sets optional pending intent to be invoked when the complication is tapped. */
- public fun setTapAction(tapAction: PendingIntent?): Builder = apply {
- this.tapAction = tapAction
- }
-
/** Sets optional time range during which the complication has to be shown. */
public fun setValidTimeRange(validTimeRange: TimeRange?): Builder = apply {
this.validTimeRange = validTimeRange
@@ -531,7 +529,7 @@
/** Builds the [BackgroundImageComplicationData]. */
public fun build(): BackgroundImageComplicationData =
- BackgroundImageComplicationData(icon, contentDescription, tapAction, validTimeRange)
+ BackgroundImageComplicationData(icon, contentDescription, validTimeRange)
}
@RestrictTo(RestrictTo.Scope.LIBRARY)
@@ -563,8 +561,7 @@
public val text: ComplicationText?,
public val title: ComplicationText?,
public val image: MonochromaticImage?,
- tapAction: PendingIntent?
-) : ComplicationData(TYPE, tapAction, TimeRange.ALWAYS) {
+) : ComplicationData(TYPE, null, TimeRange.ALWAYS) {
/**
* Builder for [NoPermissionComplicationData].
*
@@ -576,11 +573,6 @@
private var title: ComplicationText? = null
private var image: MonochromaticImage? = null
- /** Sets optional pending intent to be invoked when the complication is tapped. */
- public fun setTapAction(tapAction: PendingIntent?): Builder = apply {
- this.tapAction = tapAction
- }
-
/** Sets optional text associated with the complication data. */
public fun setText(text: ComplicationText?): Builder = apply {
this.text = text
@@ -598,7 +590,7 @@
/** Builds the [NoPermissionComplicationData]. */
public fun build(): NoPermissionComplicationData =
- NoPermissionComplicationData(text, title, image, tapAction)
+ NoPermissionComplicationData(text, title, image)
}
/** @hide */
@@ -673,14 +665,12 @@
BackgroundImageComplicationData.TYPE.asWireComplicationType() ->
BackgroundImageComplicationData.Builder(parseLargeImage()!!).apply {
- setTapAction(tapAction)
setValidTimeRange(parseTimeRange())
setContentDescription(contentDescription?.asApiComplicationText())
}.build()
NoPermissionComplicationData.TYPE.asWireComplicationType() ->
NoPermissionComplicationData.Builder().apply {
- setTapAction(tapAction)
setImage(parseIcon())
setTitle(shortTitle?.asApiComplicationText())
setText(shortText?.asApiComplicationText())
diff --git a/wear/wear-complications-data/src/test/java/androidx/wear/complications/data/DataTest.kt b/wear/wear-complications-data/src/test/java/androidx/wear/complications/data/DataTest.kt
index acde5f3..78c71ec 100644
--- a/wear/wear-complications-data/src/test/java/androidx/wear/complications/data/DataTest.kt
+++ b/wear/wear-complications-data/src/test/java/androidx/wear/complications/data/DataTest.kt
@@ -16,7 +16,10 @@
package androidx.wear.complications.data
+import android.app.PendingIntent
+import android.content.Intent
import android.graphics.drawable.Icon
+import androidx.test.core.app.ApplicationProvider
import androidx.wear.complications.ParcelableSubject
import androidx.wear.complications.SharedRobolectricTestRunner
import com.google.common.truth.Truth.assertThat
@@ -266,4 +269,65 @@
}
}
+@RunWith(SharedRobolectricTestRunner::class)
+public class TapActionTest {
+ private val mPendingIntent = PendingIntent.getBroadcast(
+ ApplicationProvider.getApplicationContext(),
+ 0,
+ Intent(),
+ 0
+ )
+
+ @Test
+ public fun shortTextComplicationData() {
+ assertThat(
+ ShortTextComplicationData.Builder("text".complicationText)
+ .setTapAction(mPendingIntent)
+ .build().asWireComplicationData().tapAction
+ ).isEqualTo(mPendingIntent)
+ }
+
+ @Test
+ public fun longTextComplicationData() {
+ assertThat(
+ LongTextComplicationData.Builder("text".complicationText)
+ .setTapAction(mPendingIntent)
+ .build().asWireComplicationData().tapAction
+ ).isEqualTo(mPendingIntent)
+ }
+
+ @Test
+ public fun rangedValueComplicationData() {
+ assertThat(
+ RangedValueComplicationData.Builder(value = 95f, min = 0f, max = 100f)
+ .setTapAction(mPendingIntent)
+ .build().asWireComplicationData().tapAction
+ ).isEqualTo(mPendingIntent)
+ }
+
+ @Test
+ public fun monochromaticImageComplicationData() {
+ val icon = Icon.createWithContentUri("someuri")
+ val image = MonochromaticImage.Builder(icon).build()
+ assertThat(
+ MonochromaticImageComplicationData.Builder(image)
+ .setTapAction(mPendingIntent)
+ .build()
+ .asWireComplicationData()
+ .tapAction
+ ).isEqualTo(mPendingIntent)
+ }
+
+ @Test
+ public fun smallImageComplicationData() {
+ val icon = Icon.createWithContentUri("someuri")
+ val image = SmallImage.Builder(icon, SmallImageType.PHOTO).build()
+ assertThat(
+ SmallImageComplicationData.Builder(image).setTapAction(mPendingIntent).build()
+ .asWireComplicationData()
+ .tapAction
+ ).isEqualTo(mPendingIntent)
+ }
+}
+
private val String.complicationText get() = ComplicationText.plain(this)
diff --git a/wear/wear-complications-provider/api/restricted_current.txt b/wear/wear-complications-provider/api/restricted_current.txt
index ac0085e..4d26b059 100644
--- a/wear/wear-complications-provider/api/restricted_current.txt
+++ b/wear/wear-complications-provider/api/restricted_current.txt
@@ -8,7 +8,6 @@
method @UiThread public void onComplicationActivated(int, int);
method @UiThread public void onComplicationDeactivated(int);
method @UiThread public abstract void onComplicationUpdate(int, androidx.wear.complications.data.ComplicationType, androidx.wear.complications.ComplicationProviderService.ComplicationUpdateCallback);
- method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP) @VisibleForTesting public void setRetailModeProvider(androidx.wear.complications.ComplicationProviderService.RetailModeProvider);
field public static final String ACTION_COMPLICATION_UPDATE_REQUEST = "android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST";
field public static final String CATEGORY_PROVIDER_CONFIG_ACTION = "android.support.wearable.complications.category.PROVIDER_CONFIG";
field public static final String EXTRA_CONFIG_COMPLICATION_ID = "android.support.wearable.complications.EXTRA_CONFIG_COMPLICATION_ID";
@@ -24,10 +23,6 @@
method public void onUpdateComplication(androidx.wear.complications.data.ComplicationData?) throws android.os.RemoteException;
}
- @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP) @VisibleForTesting public static interface ComplicationProviderService.RetailModeProvider {
- method public boolean inRetailMode();
- }
-
public class ProviderUpdateRequester {
ctor public ProviderUpdateRequester(android.content.Context, android.content.ComponentName);
method public void requestUpdate(int...);
diff --git a/wear/wear-complications-provider/build.gradle b/wear/wear-complications-provider/build.gradle
index 0fd86a4..21a6584 100644
--- a/wear/wear-complications-provider/build.gradle
+++ b/wear/wear-complications-provider/build.gradle
@@ -47,7 +47,7 @@
aidl = true
}
defaultConfig {
- minSdkVersion 27
+ minSdkVersion 24
}
// Use Robolectric 4.+
diff --git a/wear/wear-complications-provider/src/main/java/androidx/wear/complications/ComplicationProviderService.java b/wear/wear-complications-provider/src/main/java/androidx/wear/complications/ComplicationProviderService.java
index 1484815..24d3a20 100644
--- a/wear/wear-complications-provider/src/main/java/androidx/wear/complications/ComplicationProviderService.java
+++ b/wear/wear-complications-provider/src/main/java/androidx/wear/complications/ComplicationProviderService.java
@@ -16,14 +16,11 @@
package androidx.wear.complications;
-import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
-
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
-import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -36,7 +33,6 @@
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.annotation.UiThread;
-import androidx.annotation.VisibleForTesting;
import androidx.wear.complications.data.ComplicationData;
import androidx.wear.complications.data.ComplicationType;
@@ -131,10 +127,6 @@
public static final String ACTION_COMPLICATION_UPDATE_REQUEST =
"android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST";
- private static final String RETAIL_PACKAGE = "com.google.android.apps.wearable.settings";
- private static final String RETAIL_CLASS =
- "com.google.android.clockwork.settings.RetailStatusService";
-
/**
* Metadata key used to declare supported complication types.
*
@@ -271,37 +263,6 @@
private IComplicationProviderWrapper mWrapper;
private final Handler mMainThreadHandler = new Handler(Looper.getMainLooper());
- /** @hide */
- @RestrictTo(LIBRARY_GROUP)
- @VisibleForTesting
- public interface RetailModeProvider {
- /**
- * Returns true if the device is currently running in retail mode (e.g. the watch is being
- * demonstrated in a store, or the watch face is being configured by the system UI).
- */
- boolean inRetailMode();
- }
-
- private RetailModeProvider mRetailModeProvider = new RetailModeProvider() {
- /**
- * Returns true if the device is currently running in retail mode (e.g. the watch is being
- * demonstrated in a store, or the watch face is being configured by the system UI).
- */
- @Override
- public boolean inRetailMode() {
- ComponentName component = new ComponentName(RETAIL_PACKAGE, RETAIL_CLASS);
- return (getPackageManager().getComponentEnabledSetting(component)
- == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
- }
- };
-
- /** @hide */
- @RestrictTo(LIBRARY_GROUP)
- @VisibleForTesting
- public void setRetailModeProvider(@NonNull RetailModeProvider retailModeProvider) {
- mRetailModeProvider = retailModeProvider;
- }
-
@SuppressLint("SyntheticAccessor")
@Override
@Nullable
@@ -397,34 +358,28 @@
final ComplicationType complicationType = ComplicationType.fromWireType(type);
final IComplicationManager iComplicationManager =
IComplicationManager.Stub.asInterface(manager);
- if (mRetailModeProvider.inRetailMode()) {
- try {
- iComplicationManager.updateComplicationData(
- complicationId,
- getPreviewData(complicationType).asWireComplicationData());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- } else {
- mMainThreadHandler.post(
- () -> onComplicationUpdate(complicationId, complicationType,
- complicationData -> {
- // This can be run on an arbitrary thread, but that's OK.
- ComplicationType dataType =
- complicationData != null ? complicationData.getType() :
- ComplicationType.NO_DATA;
- if (dataType == ComplicationType.NOT_CONFIGURED
- || dataType == ComplicationType.EMPTY) {
- throw new IllegalArgumentException(
- "Cannot send data of TYPE_NOT_CONFIGURED or "
- + "TYPE_EMPTY. Use TYPE_NO_DATA instead.");
- }
+ mMainThreadHandler.post(
+ () -> onComplicationUpdate(complicationId, complicationType,
+ complicationData -> {
+ // This can be run on an arbitrary thread, but that's OK.
+ ComplicationType dataType =
+ complicationData != null ? complicationData.getType() :
+ ComplicationType.NO_DATA;
+ if (dataType == ComplicationType.NOT_CONFIGURED
+ || dataType == ComplicationType.EMPTY) {
+ throw new IllegalArgumentException(
+ "Cannot send data of TYPE_NOT_CONFIGURED or "
+ + "TYPE_EMPTY. Use TYPE_NO_DATA instead.");
+ }
- iComplicationManager.updateComplicationData(
- complicationId,
- complicationData.asWireComplicationData());
- }));
- }
+ // When no update is needed, the complicationData is going to be
+ // null.
+ iComplicationManager.updateComplicationData(
+ complicationId,
+ (complicationData != null)
+ ? complicationData.asWireComplicationData()
+ : null);
+ }));
}
@Override
diff --git a/wear/wear-complications-provider/src/test/java/androidx/wear/complications/ComplicationProviderServiceTest.java b/wear/wear-complications-provider/src/test/java/androidx/wear/complications/ComplicationProviderServiceTest.java
index 8418ce5..cb86a36 100644
--- a/wear/wear-complications-provider/src/test/java/androidx/wear/complications/ComplicationProviderServiceTest.java
+++ b/wear/wear-complications-provider/src/test/java/androidx/wear/complications/ComplicationProviderServiceTest.java
@@ -62,6 +62,7 @@
};
private IComplicationProvider.Stub mComplicationProvider;
+ private IComplicationProvider.Stub mNoUpdateComplicationProvider;
private ComplicationProviderService mTestService = new ComplicationProviderService() {
@@ -90,13 +91,40 @@
}
};
+ private ComplicationProviderService mNoUpdateTestService = new ComplicationProviderService() {
+
+ @Override
+ public void onComplicationUpdate(
+ int complicationId,
+ @NonNull ComplicationType type,
+ @NonNull ComplicationUpdateCallback callback) {
+ try {
+ // Null means no update required.
+ callback.onUpdateComplication(null);
+ } catch (RemoteException e) {
+ Log.e(TAG, "onComplicationUpdate failed with error: ", e);
+ }
+ }
+
+ @Nullable
+ @Override
+ public ComplicationData getPreviewData(@NonNull ComplicationType type) {
+ return new LongTextComplicationData.Builder(
+ ComplicationText.plain("hello preview")
+ ).build();
+ }
+ };
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mComplicationProvider =
(IComplicationProvider.Stub) mTestService.onBind(
new Intent(ComplicationProviderService.ACTION_COMPLICATION_UPDATE_REQUEST));
- mTestService.setRetailModeProvider(() -> false);
+
+ mNoUpdateComplicationProvider =
+ (IComplicationProvider.Stub) mNoUpdateTestService.onBind(
+ new Intent(ComplicationProviderService.ACTION_COMPLICATION_UPDATE_REQUEST));
}
@Test
@@ -116,6 +144,20 @@
}
@Test
+ public void testOnComplicationUpdateNoUpdateRequired() throws Exception {
+ int id = 123;
+ mNoUpdateComplicationProvider.onUpdate(
+ id, ComplicationType.LONG_TEXT.asWireComplicationType(), mLocalManager);
+ ShadowLooper.runUiThreadTasks();
+
+ ArgumentCaptor<android.support.wearable.complications.ComplicationData> data =
+ ArgumentCaptor.forClass(
+ android.support.wearable.complications.ComplicationData.class);
+ verify(mRemoteManager).updateComplicationData(eq(id), data.capture());
+ assertThat(data.getValue()).isNull();
+ }
+
+ @Test
public void testGetComplicationPreviewData() throws Exception {
assertThat(mComplicationProvider.getComplicationPreviewData(
ComplicationType.LONG_TEXT.asWireComplicationType()
diff --git a/wear/wear-watchface-client/api/current.txt b/wear/wear-watchface-client/api/current.txt
index 4e593ce..4807807 100644
--- a/wear/wear-watchface-client/api/current.txt
+++ b/wear/wear-watchface-client/api/current.txt
@@ -87,14 +87,14 @@
public interface InteractiveWatchFaceWcsClient extends java.lang.AutoCloseable {
method public android.os.IBinder asBinder();
method public default static androidx.wear.watchface.client.InteractiveWatchFaceWcsClient createFromBinder(android.os.IBinder binder);
- method public java.util.Map<java.lang.Integer,androidx.wear.watchface.data.ComplicationStateWireFormat> getComplicationStateWireFormat();
+ method public java.util.Map<java.lang.Integer,androidx.wear.watchface.client.ComplicationState> getComplicationState();
method public String getInstanceId();
method public long getPreviewReferenceTimeMillis();
method public androidx.wear.watchface.style.UserStyleSchema getUserStyleSchema();
method public void setUserStyle(androidx.wear.watchface.style.UserStyle userStyle);
method public android.graphics.Bitmap takeWatchFaceScreenshot(androidx.wear.watchface.RenderParameters renderParameters, @IntRange(from=0, to=100) int compressionQuality, long calendarTimeMillis, androidx.wear.watchface.style.UserStyle? userStyle, java.util.Map<java.lang.Integer,? extends androidx.wear.complications.data.ComplicationData>? idAndComplicationData);
method public void updateComplicationData(java.util.Map<java.lang.Integer,? extends androidx.wear.complications.data.ComplicationData> idToComplicationData);
- property public abstract java.util.Map<java.lang.Integer,androidx.wear.watchface.data.ComplicationStateWireFormat> complicationStateWireFormat;
+ property public abstract java.util.Map<java.lang.Integer,androidx.wear.watchface.client.ComplicationState> complicationState;
property public abstract String instanceId;
property public abstract long previewReferenceTimeMillis;
property public abstract androidx.wear.watchface.style.UserStyleSchema userStyleSchema;
diff --git a/wear/wear-watchface-client/api/public_plus_experimental_current.txt b/wear/wear-watchface-client/api/public_plus_experimental_current.txt
index 8b42a9b..92e4a46c 100644
--- a/wear/wear-watchface-client/api/public_plus_experimental_current.txt
+++ b/wear/wear-watchface-client/api/public_plus_experimental_current.txt
@@ -87,14 +87,14 @@
public interface InteractiveWatchFaceWcsClient extends java.lang.AutoCloseable {
method public android.os.IBinder asBinder();
method public default static androidx.wear.watchface.client.InteractiveWatchFaceWcsClient createFromBinder(android.os.IBinder binder);
- method public java.util.Map<java.lang.Integer,androidx.wear.watchface.data.ComplicationStateWireFormat> getComplicationStateWireFormat();
+ method public java.util.Map<java.lang.Integer,androidx.wear.watchface.client.ComplicationState> getComplicationState();
method public String getInstanceId();
method public long getPreviewReferenceTimeMillis();
method public androidx.wear.watchface.style.UserStyleSchema getUserStyleSchema();
method public void setUserStyle(androidx.wear.watchface.style.UserStyle userStyle);
method public android.graphics.Bitmap takeWatchFaceScreenshot(androidx.wear.watchface.RenderParameters renderParameters, @IntRange(from=0, to=100) int compressionQuality, long calendarTimeMillis, androidx.wear.watchface.style.UserStyle? userStyle, java.util.Map<java.lang.Integer,? extends androidx.wear.complications.data.ComplicationData>? idAndComplicationData);
method public void updateComplicationData(java.util.Map<java.lang.Integer,? extends androidx.wear.complications.data.ComplicationData> idToComplicationData);
- property public abstract java.util.Map<java.lang.Integer,androidx.wear.watchface.data.ComplicationStateWireFormat> complicationStateWireFormat;
+ property public abstract java.util.Map<java.lang.Integer,androidx.wear.watchface.client.ComplicationState> complicationState;
property public abstract String instanceId;
property public abstract long previewReferenceTimeMillis;
property public abstract androidx.wear.watchface.style.UserStyleSchema userStyleSchema;
diff --git a/wear/wear-watchface-client/api/restricted_current.txt b/wear/wear-watchface-client/api/restricted_current.txt
index 62a3fbc..d2ce3fa 100644
--- a/wear/wear-watchface-client/api/restricted_current.txt
+++ b/wear/wear-watchface-client/api/restricted_current.txt
@@ -87,14 +87,14 @@
public interface InteractiveWatchFaceWcsClient extends java.lang.AutoCloseable {
method public android.os.IBinder asBinder();
method public default static androidx.wear.watchface.client.InteractiveWatchFaceWcsClient createFromBinder(android.os.IBinder binder);
- method public java.util.Map<java.lang.Integer,androidx.wear.watchface.data.ComplicationStateWireFormat> getComplicationStateWireFormat();
+ method public java.util.Map<java.lang.Integer,androidx.wear.watchface.client.ComplicationState> getComplicationState();
method public String getInstanceId();
method public long getPreviewReferenceTimeMillis();
method public androidx.wear.watchface.style.UserStyleSchema getUserStyleSchema();
method public void setUserStyle(androidx.wear.watchface.style.UserStyle userStyle);
method public android.graphics.Bitmap takeWatchFaceScreenshot(androidx.wear.watchface.RenderParameters renderParameters, @IntRange(from=0, to=100) int compressionQuality, long calendarTimeMillis, androidx.wear.watchface.style.UserStyle? userStyle, java.util.Map<java.lang.Integer,? extends androidx.wear.complications.data.ComplicationData>? idAndComplicationData);
method public void updateComplicationData(java.util.Map<java.lang.Integer,? extends androidx.wear.complications.data.ComplicationData> idToComplicationData);
- property public abstract java.util.Map<java.lang.Integer,androidx.wear.watchface.data.ComplicationStateWireFormat> complicationStateWireFormat;
+ property public abstract java.util.Map<java.lang.Integer,androidx.wear.watchface.client.ComplicationState> complicationState;
property public abstract String instanceId;
property public abstract long previewReferenceTimeMillis;
property public abstract androidx.wear.watchface.style.UserStyleSchema userStyleSchema;
diff --git a/wear/wear-watchface-client/src/androidTest/AndroidManifest.xml b/wear/wear-watchface-client/src/androidTest/AndroidManifest.xml
index 48ecaba..90f1021 100644
--- a/wear/wear-watchface-client/src/androidTest/AndroidManifest.xml
+++ b/wear/wear-watchface-client/src/androidTest/AndroidManifest.xml
@@ -15,7 +15,7 @@
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="androidx.wear.watchface.server.test">
+ package="androidx.wear.watchface.client.test">
<application android:requestLegacyExternalStorage="true">
<service android:name="androidx.wear.watchface.client.test.WatchFaceControlTestService"/>
</application>
diff --git a/wear/wear-watchface-client/src/androidTest/java/androidx/wear/watchface/client/test/WatchFaceControlClientTest.kt b/wear/wear-watchface-client/src/androidTest/java/androidx/wear/watchface/client/test/WatchFaceControlClientTest.kt
index 5dfc50a..d6e760d 100644
--- a/wear/wear-watchface-client/src/androidTest/java/androidx/wear/watchface/client/test/WatchFaceControlClientTest.kt
+++ b/wear/wear-watchface-client/src/androidTest/java/androidx/wear/watchface/client/test/WatchFaceControlClientTest.kt
@@ -193,6 +193,33 @@
}
@Test
+ fun headlessUserStyleSchema() {
+ val headlessInstance = service.createHeadlessWatchFaceClient(
+ exampleWatchFaceComponentName,
+ deviceConfig,
+ 400,
+ 400
+ ).get(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)!!
+
+ assertThat(headlessInstance.userStyleSchema.userStyleSettings.size).isEqualTo(4)
+ assertThat(headlessInstance.userStyleSchema.userStyleSettings[0].id).isEqualTo(
+ "color_style_setting"
+ )
+ assertThat(headlessInstance.userStyleSchema.userStyleSettings[1].id).isEqualTo(
+ "draw_hour_pips_style_setting"
+ )
+ assertThat(headlessInstance.userStyleSchema.userStyleSettings[2].id).isEqualTo(
+ "watch_hand_length_style_setting"
+ )
+ assertThat(headlessInstance.userStyleSchema.userStyleSettings[3].id).isEqualTo(
+ "complications_style_setting"
+ )
+
+ headlessInstance.close()
+ service.close()
+ }
+
+ @Test
@Ignore("Creation of new screenshots is currently broken b/171983840")
fun getOrCreateWallpaperServiceBackedInteractiveWatchFaceWcsClient() {
val interactiveInstanceFuture =
@@ -235,6 +262,77 @@
}
@Test
+ fun wallpaperServiceBackedInteractiveWatchFaceWcsClient_ComplicationDetails() {
+ val interactiveInstanceFuture =
+ service.getOrCreateWallpaperServiceBackedInteractiveWatchFaceWcsClient(
+ "testId",
+ deviceConfig,
+ systemState,
+ null,
+ complications
+ )
+
+ Mockito.`when`(surfaceHolder.surfaceFrame)
+ .thenReturn(Rect(0, 0, 400, 400))
+
+ val wallpaperService = TestExampleCanvasAnalogWatchFaceService(context, surfaceHolder)
+
+ // Create the engine which triggers creation of InteractiveWatchFaceWcsClient.
+ val handler = Handler(Looper.getMainLooper())
+ lateinit var engine: WallpaperService.Engine
+ handler.post { engine = wallpaperService.onCreateEngine() }
+
+ val interactiveInstance =
+ interactiveInstanceFuture.get(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)!!
+
+ assertThat(interactiveInstance.complicationState.size).isEqualTo(2)
+
+ val leftComplicationDetails = interactiveInstance.complicationState[
+ EXAMPLE_CANVAS_WATCHFACE_LEFT_COMPLICATION_ID
+ ]!!
+ assertThat(leftComplicationDetails.bounds).isEqualTo(Rect(80, 160, 160, 240))
+ assertThat(leftComplicationDetails.boundsType).isEqualTo(ComplicationBoundsType.ROUND_RECT)
+ assertThat(leftComplicationDetails.defaultProviderPolicy.systemProviderFallback).isEqualTo(
+ SystemProviders.DAY_OF_WEEK
+ )
+ assertThat(leftComplicationDetails.defaultProviderType).isEqualTo(
+ ComplicationType.SHORT_TEXT
+ )
+ assertThat(leftComplicationDetails.supportedTypes).containsExactly(
+ ComplicationType.RANGED_VALUE,
+ ComplicationType.LONG_TEXT,
+ ComplicationType.SHORT_TEXT,
+ ComplicationType.MONOCHROMATIC_IMAGE,
+ ComplicationType.SMALL_IMAGE
+ )
+ assertTrue(leftComplicationDetails.isEnabled)
+
+ val rightComplicationDetails = interactiveInstance.complicationState[
+ EXAMPLE_CANVAS_WATCHFACE_RIGHT_COMPLICATION_ID
+ ]!!
+ assertThat(rightComplicationDetails.bounds).isEqualTo(Rect(240, 160, 320, 240))
+ assertThat(rightComplicationDetails.boundsType).isEqualTo(ComplicationBoundsType.ROUND_RECT)
+ assertThat(rightComplicationDetails.defaultProviderPolicy.systemProviderFallback).isEqualTo(
+ SystemProviders.STEP_COUNT
+ )
+ assertThat(rightComplicationDetails.defaultProviderType).isEqualTo(
+ ComplicationType.SHORT_TEXT
+ )
+ assertThat(rightComplicationDetails.supportedTypes).containsExactly(
+ ComplicationType.RANGED_VALUE,
+ ComplicationType.LONG_TEXT,
+ ComplicationType.SHORT_TEXT,
+ ComplicationType.MONOCHROMATIC_IMAGE,
+ ComplicationType.SMALL_IMAGE
+ )
+ assertTrue(rightComplicationDetails.isEnabled)
+
+ engine.onDestroy()
+ interactiveInstance.close()
+ service.close()
+ }
+
+ @Test
fun getOrCreateWallpaperServiceBackedInteractiveWatchFaceWcsClient_existingOpenInstance() {
val interactiveInstanceFuture =
service.getOrCreateWallpaperServiceBackedInteractiveWatchFaceWcsClient(
diff --git a/wear/wear-watchface-client/src/main/AndroidManifest.xml b/wear/wear-watchface-client/src/main/AndroidManifest.xml
index be3e098..5849c92 100644
--- a/wear/wear-watchface-client/src/main/AndroidManifest.xml
+++ b/wear/wear-watchface-client/src/main/AndroidManifest.xml
@@ -16,6 +16,6 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="androidx.watchface.server">
+ package="androidx.wear.watchface.client">
<uses-permission android:name="com.google.android.wearable.permission.BIND_WATCH_FACE_CONTROL"/>
</manifest>
diff --git a/wear/wear-watchface-client/src/main/java/androidx/wear/watchface/client/InteractiveWatchFaceSysUiClient.kt b/wear/wear-watchface-client/src/main/java/androidx/wear/watchface/client/InteractiveWatchFaceSysUiClient.kt
index 748fced..d4aa068 100644
--- a/wear/wear-watchface-client/src/main/java/androidx/wear/watchface/client/InteractiveWatchFaceSysUiClient.kt
+++ b/wear/wear-watchface-client/src/main/java/androidx/wear/watchface/client/InteractiveWatchFaceSysUiClient.kt
@@ -33,6 +33,7 @@
import androidx.wear.watchface.data.IdAndComplicationDataWireFormat
import androidx.wear.watchface.data.SystemState
import androidx.wear.watchface.style.UserStyle
+import java.util.Objects
/**
* The type of tap event passed to the watch face.
@@ -46,7 +47,10 @@
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public annotation class TapType
-/** Controls a stateful remote interactive watch face with an interface tailored for SysUI. */
+/**
+ * Controls a stateful remote interactive watch face with an interface tailored for SysUI the
+ * WearOS 3.0 launcher app. Typically this will be used for the current active watch face.
+ */
public interface InteractiveWatchFaceSysUiClient : AutoCloseable {
public companion object {
@@ -97,6 +101,20 @@
*/
public fun getTextAt(resources: Resources, dateTimeMillis: Long): CharSequence =
text.getTextAt(resources, dateTimeMillis)
+
+ override fun equals(other: Any?): Boolean =
+ other is ContentDescriptionLabel &&
+ text == other.text &&
+ bounds == other.bounds &&
+ tapAction == other.tapAction
+
+ override fun hashCode(): Int {
+ return Objects.hash(
+ text,
+ bounds,
+ tapAction
+ )
+ }
}
/**
diff --git a/wear/wear-watchface-client/src/main/java/androidx/wear/watchface/client/InteractiveWatchFaceWcsClient.kt b/wear/wear-watchface-client/src/main/java/androidx/wear/watchface/client/InteractiveWatchFaceWcsClient.kt
index 56d8278..64e84c5 100644
--- a/wear/wear-watchface-client/src/main/java/androidx/wear/watchface/client/InteractiveWatchFaceWcsClient.kt
+++ b/wear/wear-watchface-client/src/main/java/androidx/wear/watchface/client/InteractiveWatchFaceWcsClient.kt
@@ -24,12 +24,15 @@
import androidx.wear.watchface.RenderParameters
import androidx.wear.watchface.control.IInteractiveWatchFaceWCS
import androidx.wear.watchface.control.data.WatchfaceScreenshotParams
-import androidx.wear.watchface.data.ComplicationStateWireFormat
import androidx.wear.watchface.data.IdAndComplicationDataWireFormat
import androidx.wear.watchface.style.UserStyle
import androidx.wear.watchface.style.UserStyleSchema
-/** Controls a stateful remote interactive watch face with an interface tailored for WCS. */
+/**
+ * Controls a stateful remote interactive watch face with an interface tailored for WCS the
+ * WearOS 3.0 system server responsible for watch face management. Typically this will be used for
+ * the current active watch face.
+ */
public interface InteractiveWatchFaceWcsClient : AutoCloseable {
public companion object {
@@ -72,7 +75,7 @@
public val previewReferenceTimeMillis: Long
/**
- * Sets the watch face's current [UserStyle]. Note this may alter [complicationStateWireFormat].
+ * Sets the watch face's current [UserStyle]. Note this may alter [complicationState].
*/
public fun setUserStyle(userStyle: UserStyle)
@@ -83,10 +86,10 @@
public val userStyleSchema: UserStyleSchema
/**
- * Map of complication ids to [ComplicationStateWireFormat] for each complication slot. Note
+ * Map of complication ids to [ComplicationState] for each complication slot. Note
* this can change, typically in response to styling.
*/
- public val complicationStateWireFormat: Map<Int, ComplicationStateWireFormat>
+ public val complicationState: Map<Int, ComplicationState>
/** Returns the associated [IBinder]. Allows this interface to be passed over AIDL. */
public fun asBinder(): IBinder
@@ -142,10 +145,10 @@
override val userStyleSchema: UserStyleSchema
get() = UserStyleSchema(iInteractiveWatchFaceWcs.userStyleSchema)
- override val complicationStateWireFormat: Map<Int, ComplicationStateWireFormat>
+ override val complicationState: Map<Int, ComplicationState>
get() = iInteractiveWatchFaceWcs.complicationDetails.associateBy(
{ it.id },
- { it.complicationState }
+ { ComplicationState(it.complicationState) }
)
override fun close() {
diff --git a/wear/wear-watchface-complications-rendering/api/current.txt b/wear/wear-watchface-complications-rendering/api/current.txt
index 6b99a6c..5cab738b 100644
--- a/wear/wear-watchface-complications-rendering/api/current.txt
+++ b/wear/wear-watchface-complications-rendering/api/current.txt
@@ -19,14 +19,14 @@
method public boolean isInAmbientMode();
method public boolean isLowBitAmbient();
method public boolean isRangedValueProgressHidden();
- method public boolean onTap(int, int);
+ method public boolean onTap(@Px int, @Px int);
method public void setAlpha(int);
method public void setBurnInProtection(boolean);
method public void setColorFilter(android.graphics.ColorFilter?);
method public void setComplicationData(android.support.wearable.complications.ComplicationData?);
method public void setContext(android.content.Context);
method public void setCurrentTimeMillis(long);
- method public void setHighlightDuration(long);
+ method public void setHighlightDuration(@IntRange(from=0) long);
method public void setHighlighted(boolean);
method public void setInAmbientMode(boolean);
method public void setLowBitAmbient(boolean);
@@ -40,44 +40,44 @@
method @ColorInt public int getBackgroundColor();
method public android.graphics.drawable.Drawable? getBackgroundDrawable();
method @ColorInt public int getBorderColor();
- method public int getBorderDashGap();
- method public int getBorderDashWidth();
- method public int getBorderRadius();
+ method @Px public int getBorderDashGap();
+ method @Px public int getBorderDashWidth();
+ method @Px public int getBorderRadius();
method public int getBorderStyle();
- method public int getBorderWidth();
+ method @Px public int getBorderWidth();
method @ColorInt public int getHighlightColor();
method @ColorInt public int getIconColor();
method public android.graphics.ColorFilter? getImageColorFilter();
method @ColorInt public int getRangedValuePrimaryColor();
- method public int getRangedValueRingWidth();
+ method @Px public int getRangedValueRingWidth();
method @ColorInt public int getRangedValueSecondaryColor();
method @ColorInt public int getTextColor();
- method public int getTextSize();
+ method @Px public int getTextSize();
method public android.graphics.Typeface? getTextTypeface();
method @ColorInt public int getTitleColor();
- method public int getTitleSize();
+ method @Px public int getTitleSize();
method public android.graphics.Typeface? getTitleTypeface();
method public void setBackgroundColor(@ColorInt int);
method public void setBackgroundDrawable(android.graphics.drawable.Drawable?);
method public void setBorderColor(@ColorInt int);
- method public void setBorderDashGap(int);
- method public void setBorderDashWidth(int);
- method public void setBorderRadius(int);
+ method public void setBorderDashGap(@Px int);
+ method public void setBorderDashWidth(@Px int);
+ method public void setBorderRadius(@Px int);
method public void setBorderStyle(int);
- method public void setBorderWidth(int);
+ method public void setBorderWidth(@Px int);
method public void setHighlightColor(@ColorInt int);
method public void setIconColor(@ColorInt int);
method public void setImageColorFilter(android.graphics.ColorFilter?);
method public void setRangedValuePrimaryColor(@ColorInt int);
- method public void setRangedValueRingWidth(int);
+ method public void setRangedValueRingWidth(@Px int);
method public void setRangedValueSecondaryColor(@ColorInt int);
method public void setTextColor(@ColorInt int);
- method public void setTextSize(int);
+ method public void setTextSize(@Px int);
method public void setTextTypeface(android.graphics.Typeface);
method public void setTitleColor(@ColorInt int);
- method public void setTitleSize(int);
+ method public void setTitleSize(@Px int);
method public void setTitleTypeface(android.graphics.Typeface);
- field public static final int BORDER_RADIUS_DEFAULT = 2147483647; // 0x7fffffff
+ field @Px public static final int BORDER_RADIUS_DEFAULT = 2147483647; // 0x7fffffff
field public static final int BORDER_STYLE_DASHED = 2; // 0x2
field public static final int BORDER_STYLE_NONE = 0; // 0x0
field public static final int BORDER_STYLE_SOLID = 1; // 0x1
diff --git a/wear/wear-watchface-complications-rendering/api/public_plus_experimental_current.txt b/wear/wear-watchface-complications-rendering/api/public_plus_experimental_current.txt
index 6b99a6c..5cab738b 100644
--- a/wear/wear-watchface-complications-rendering/api/public_plus_experimental_current.txt
+++ b/wear/wear-watchface-complications-rendering/api/public_plus_experimental_current.txt
@@ -19,14 +19,14 @@
method public boolean isInAmbientMode();
method public boolean isLowBitAmbient();
method public boolean isRangedValueProgressHidden();
- method public boolean onTap(int, int);
+ method public boolean onTap(@Px int, @Px int);
method public void setAlpha(int);
method public void setBurnInProtection(boolean);
method public void setColorFilter(android.graphics.ColorFilter?);
method public void setComplicationData(android.support.wearable.complications.ComplicationData?);
method public void setContext(android.content.Context);
method public void setCurrentTimeMillis(long);
- method public void setHighlightDuration(long);
+ method public void setHighlightDuration(@IntRange(from=0) long);
method public void setHighlighted(boolean);
method public void setInAmbientMode(boolean);
method public void setLowBitAmbient(boolean);
@@ -40,44 +40,44 @@
method @ColorInt public int getBackgroundColor();
method public android.graphics.drawable.Drawable? getBackgroundDrawable();
method @ColorInt public int getBorderColor();
- method public int getBorderDashGap();
- method public int getBorderDashWidth();
- method public int getBorderRadius();
+ method @Px public int getBorderDashGap();
+ method @Px public int getBorderDashWidth();
+ method @Px public int getBorderRadius();
method public int getBorderStyle();
- method public int getBorderWidth();
+ method @Px public int getBorderWidth();
method @ColorInt public int getHighlightColor();
method @ColorInt public int getIconColor();
method public android.graphics.ColorFilter? getImageColorFilter();
method @ColorInt public int getRangedValuePrimaryColor();
- method public int getRangedValueRingWidth();
+ method @Px public int getRangedValueRingWidth();
method @ColorInt public int getRangedValueSecondaryColor();
method @ColorInt public int getTextColor();
- method public int getTextSize();
+ method @Px public int getTextSize();
method public android.graphics.Typeface? getTextTypeface();
method @ColorInt public int getTitleColor();
- method public int getTitleSize();
+ method @Px public int getTitleSize();
method public android.graphics.Typeface? getTitleTypeface();
method public void setBackgroundColor(@ColorInt int);
method public void setBackgroundDrawable(android.graphics.drawable.Drawable?);
method public void setBorderColor(@ColorInt int);
- method public void setBorderDashGap(int);
- method public void setBorderDashWidth(int);
- method public void setBorderRadius(int);
+ method public void setBorderDashGap(@Px int);
+ method public void setBorderDashWidth(@Px int);
+ method public void setBorderRadius(@Px int);
method public void setBorderStyle(int);
- method public void setBorderWidth(int);
+ method public void setBorderWidth(@Px int);
method public void setHighlightColor(@ColorInt int);
method public void setIconColor(@ColorInt int);
method public void setImageColorFilter(android.graphics.ColorFilter?);
method public void setRangedValuePrimaryColor(@ColorInt int);
- method public void setRangedValueRingWidth(int);
+ method public void setRangedValueRingWidth(@Px int);
method public void setRangedValueSecondaryColor(@ColorInt int);
method public void setTextColor(@ColorInt int);
- method public void setTextSize(int);
+ method public void setTextSize(@Px int);
method public void setTextTypeface(android.graphics.Typeface);
method public void setTitleColor(@ColorInt int);
- method public void setTitleSize(int);
+ method public void setTitleSize(@Px int);
method public void setTitleTypeface(android.graphics.Typeface);
- field public static final int BORDER_RADIUS_DEFAULT = 2147483647; // 0x7fffffff
+ field @Px public static final int BORDER_RADIUS_DEFAULT = 2147483647; // 0x7fffffff
field public static final int BORDER_STYLE_DASHED = 2; // 0x2
field public static final int BORDER_STYLE_NONE = 0; // 0x0
field public static final int BORDER_STYLE_SOLID = 1; // 0x1
diff --git a/wear/wear-watchface-complications-rendering/api/restricted_current.txt b/wear/wear-watchface-complications-rendering/api/restricted_current.txt
index 7bdb898..c42224a 100644
--- a/wear/wear-watchface-complications-rendering/api/restricted_current.txt
+++ b/wear/wear-watchface-complications-rendering/api/restricted_current.txt
@@ -19,14 +19,14 @@
method public boolean isInAmbientMode();
method public boolean isLowBitAmbient();
method public boolean isRangedValueProgressHidden();
- method public boolean onTap(int, int);
+ method public boolean onTap(@Px int, @Px int);
method public void setAlpha(int);
method public void setBurnInProtection(boolean);
method public void setColorFilter(android.graphics.ColorFilter?);
method public void setComplicationData(android.support.wearable.complications.ComplicationData?);
method public void setContext(android.content.Context);
method public void setCurrentTimeMillis(long);
- method public void setHighlightDuration(long);
+ method public void setHighlightDuration(@IntRange(from=0) long);
method public void setHighlighted(boolean);
method public void setInAmbientMode(boolean);
method public void setLowBitAmbient(boolean);
@@ -40,44 +40,44 @@
method @ColorInt public int getBackgroundColor();
method public android.graphics.drawable.Drawable? getBackgroundDrawable();
method @ColorInt public int getBorderColor();
- method public int getBorderDashGap();
- method public int getBorderDashWidth();
- method public int getBorderRadius();
+ method @Px public int getBorderDashGap();
+ method @Px public int getBorderDashWidth();
+ method @Px public int getBorderRadius();
method @androidx.wear.watchface.complications.rendering.ComplicationStyle.BorderStyle public int getBorderStyle();
- method public int getBorderWidth();
+ method @Px public int getBorderWidth();
method @ColorInt public int getHighlightColor();
method @ColorInt public int getIconColor();
method public android.graphics.ColorFilter? getImageColorFilter();
method @ColorInt public int getRangedValuePrimaryColor();
- method public int getRangedValueRingWidth();
+ method @Px public int getRangedValueRingWidth();
method @ColorInt public int getRangedValueSecondaryColor();
method @ColorInt public int getTextColor();
- method public int getTextSize();
+ method @Px public int getTextSize();
method public android.graphics.Typeface? getTextTypeface();
method @ColorInt public int getTitleColor();
- method public int getTitleSize();
+ method @Px public int getTitleSize();
method public android.graphics.Typeface? getTitleTypeface();
method public void setBackgroundColor(@ColorInt int);
method public void setBackgroundDrawable(android.graphics.drawable.Drawable?);
method public void setBorderColor(@ColorInt int);
- method public void setBorderDashGap(int);
- method public void setBorderDashWidth(int);
- method public void setBorderRadius(int);
+ method public void setBorderDashGap(@Px int);
+ method public void setBorderDashWidth(@Px int);
+ method public void setBorderRadius(@Px int);
method public void setBorderStyle(@androidx.wear.watchface.complications.rendering.ComplicationStyle.BorderStyle int);
- method public void setBorderWidth(int);
+ method public void setBorderWidth(@Px int);
method public void setHighlightColor(@ColorInt int);
method public void setIconColor(@ColorInt int);
method public void setImageColorFilter(android.graphics.ColorFilter?);
method public void setRangedValuePrimaryColor(@ColorInt int);
- method public void setRangedValueRingWidth(int);
+ method public void setRangedValueRingWidth(@Px int);
method public void setRangedValueSecondaryColor(@ColorInt int);
method public void setTextColor(@ColorInt int);
- method public void setTextSize(int);
+ method public void setTextSize(@Px int);
method public void setTextTypeface(android.graphics.Typeface);
method public void setTitleColor(@ColorInt int);
- method public void setTitleSize(int);
+ method public void setTitleSize(@Px int);
method public void setTitleTypeface(android.graphics.Typeface);
- field public static final int BORDER_RADIUS_DEFAULT = 2147483647; // 0x7fffffff
+ field @Px public static final int BORDER_RADIUS_DEFAULT = 2147483647; // 0x7fffffff
field public static final int BORDER_STYLE_DASHED = 2; // 0x2
field public static final int BORDER_STYLE_NONE = 0; // 0x0
field public static final int BORDER_STYLE_SOLID = 1; // 0x1
diff --git a/wear/wear-watchface-complications-rendering/src/main/java/androidx/wear/watchface/complications/rendering/ComplicationDrawable.java b/wear/wear-watchface-complications-rendering/src/main/java/androidx/wear/watchface/complications/rendering/ComplicationDrawable.java
index bf98b1b..b455604 100644
--- a/wear/wear-watchface-complications-rendering/src/main/java/androidx/wear/watchface/complications/rendering/ComplicationDrawable.java
+++ b/wear/wear-watchface-complications-rendering/src/main/java/androidx/wear/watchface/complications/rendering/ComplicationDrawable.java
@@ -37,8 +37,10 @@
import android.util.Log;
import android.util.Xml;
+import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.annotation.Px;
import androidx.annotation.VisibleForTesting;
import androidx.wear.complications.ComplicationHelperActivity;
import androidx.wear.watchface.complications.rendering.ComplicationRenderer.OnInvalidateListener;
@@ -729,7 +731,7 @@
* android.app.PendingIntent}) is cancelled, or the given x and y are not inside the
* complication bounds.
*/
- public boolean onTap(int x, int y) {
+ public boolean onTap(@Px int x, @Px int y) {
if (mComplicationRenderer == null) {
return false;
}
@@ -786,7 +788,7 @@
*
* @param highlightDurationMillis highlight duration in milliseconds
*/
- public void setHighlightDuration(long highlightDurationMillis) {
+ public void setHighlightDuration(@IntRange(from = 0) long highlightDurationMillis) {
if (highlightDurationMillis < 0) {
throw new IllegalArgumentException("Highlight duration should be non-negative.");
}
diff --git a/wear/wear-watchface-complications-rendering/src/main/java/androidx/wear/watchface/complications/rendering/ComplicationStyle.java b/wear/wear-watchface-complications-rendering/src/main/java/androidx/wear/watchface/complications/rendering/ComplicationStyle.java
index 00f4076..86b57d81 100644
--- a/wear/wear-watchface-complications-rendering/src/main/java/androidx/wear/watchface/complications/rendering/ComplicationStyle.java
+++ b/wear/wear-watchface-complications-rendering/src/main/java/androidx/wear/watchface/complications/rendering/ComplicationStyle.java
@@ -26,6 +26,7 @@
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.annotation.Px;
import androidx.annotation.RestrictTo;
import java.lang.annotation.Retention;
@@ -77,6 +78,7 @@
private static final int BORDER_COLOR_DEFAULT = Color.WHITE;
/** Default text size. */
+ @Px
private static final int TEXT_SIZE_DEFAULT = Integer.MAX_VALUE;
/** Default typeface. */
@@ -84,18 +86,23 @@
Typeface.create("sans-serif-condensed", Typeface.NORMAL);
/** Default dash width. */
+ @Px
private static final int DASH_WIDTH_DEFAULT = 3;
/** Default dash gap. */
+ @Px
private static final int DASH_GAP_DEFAULT = 3;
/** Default border width. */
+ @Px
private static final int BORDER_WIDTH_DEFAULT = 1;
/** Default ring width. */
+ @Px
private static final int RING_WIDTH_DEFAULT = 2;
/** Default border radius. */
+ @Px
public static final int BORDER_RADIUS_DEFAULT = Integer.MAX_VALUE;
@ColorInt
@@ -107,18 +114,26 @@
private int mTitleColor = SECONDARY_COLOR_DEFAULT;
private Typeface mTextTypeface = TYPEFACE_DEFAULT;
private Typeface mTitleTypeface = TYPEFACE_DEFAULT;
+ @Px
private int mTextSize = TEXT_SIZE_DEFAULT;
+ @Px
private int mTitleSize = TEXT_SIZE_DEFAULT;
private ColorFilter mImageColorFilter = null;
@ColorInt
private int mIconColor = PRIMARY_COLOR_DEFAULT;
@ColorInt
private int mBorderColor = BORDER_COLOR_DEFAULT;
+ @BorderStyle
private int mBorderStyle = BORDER_STYLE_SOLID;
+ @Px
private int mBorderDashWidth = DASH_WIDTH_DEFAULT;
+ @Px
private int mBorderDashGap = DASH_GAP_DEFAULT;
+ @Px
private int mBorderRadius = BORDER_RADIUS_DEFAULT;
+ @Px
private int mBorderWidth = BORDER_WIDTH_DEFAULT;
+ @Px
private int mRangedValueRingWidth = RING_WIDTH_DEFAULT;
@ColorInt
private int mRangedValuePrimaryColor = PRIMARY_COLOR_DEFAULT;
@@ -214,11 +229,13 @@
}
/** Returns the text size to be used for short and long text. */
+ @Px
public int getTextSize() {
return mTextSize;
}
/** Returns the text size to be used for short and long title. */
+ @Px
public int getTitleSize() {
return mTitleSize;
}
@@ -237,6 +254,7 @@
/**
* Returns the dash width to be used when drawing borders of type {@link #BORDER_STYLE_DASHED}.
*/
+ @Px
public int getBorderDashWidth() {
return mBorderDashWidth;
}
@@ -244,6 +262,7 @@
/**
* Returns the dash gap to be used when drawing borders of type {@link #BORDER_STYLE_DASHED}.
*/
+ @Px
public int getBorderDashGap() {
return mBorderDashGap;
}
@@ -253,16 +272,19 @@
* border radius should be reduced to half of the minimum of width or height during the
* rendering.
*/
+ @Px
public int getBorderRadius() {
return mBorderRadius;
}
/** Returns the border width. */
+ @Px
public int getBorderWidth() {
return mBorderWidth;
}
/** Returns the ring width to be used when rendering ranged value indicator. */
+ @Px
public int getRangedValueRingWidth() {
return mRangedValueRingWidth;
}
@@ -369,7 +391,7 @@
*
* @param textSize The size of the text=
*/
- public void setTextSize(int textSize) {
+ public void setTextSize(@Px int textSize) {
mTextSize = textSize;
mDirty = true;
}
@@ -379,7 +401,7 @@
*
* @param titleSize The size of the title text=
*/
- public void setTitleSize(int titleSize) {
+ public void setTitleSize(@Px int titleSize) {
mTitleSize = titleSize;
mDirty = true;
}
@@ -419,7 +441,7 @@
*
* @param borderDashWidth The dash widths to render the complication border with
*/
- public void setBorderDashWidth(int borderDashWidth) {
+ public void setBorderDashWidth(@Px int borderDashWidth) {
mBorderDashWidth = borderDashWidth;
mDirty = true;
}
@@ -430,7 +452,7 @@
*
* @param borderDashGap The dash gap render the complication border with
*/
- public void setBorderDashGap(int borderDashGap) {
+ public void setBorderDashGap(@Px int borderDashGap) {
mBorderDashGap = borderDashGap;
mDirty = true;
}
@@ -442,7 +464,7 @@
*
* @param borderRadius The radius to render the complication border with
*/
- public void setBorderRadius(int borderRadius) {
+ public void setBorderRadius(@Px int borderRadius) {
mBorderRadius = borderRadius;
mDirty = true;
}
@@ -452,7 +474,7 @@
*
* @param borderWidth The width to render the complication border with
*/
- public void setBorderWidth(int borderWidth) {
+ public void setBorderWidth(@Px int borderWidth) {
mBorderWidth = borderWidth;
mDirty = true;
}
@@ -462,7 +484,7 @@
*
* @param rangedValueRingWidth The width to render the ranged value ring with
*/
- public void setRangedValueRingWidth(int rangedValueRingWidth) {
+ public void setRangedValueRingWidth(@Px int rangedValueRingWidth) {
mRangedValueRingWidth = rangedValueRingWidth;
mDirty = true;
}
diff --git a/wear/wear-watchface-data/src/main/java/androidx/wear/watchface/style/data/ComplicationsUserStyleSettingWireFormat.java b/wear/wear-watchface-data/src/main/java/androidx/wear/watchface/style/data/ComplicationsUserStyleSettingWireFormat.java
index e12401d..2340a93 100644
--- a/wear/wear-watchface-data/src/main/java/androidx/wear/watchface/style/data/ComplicationsUserStyleSettingWireFormat.java
+++ b/wear/wear-watchface-data/src/main/java/androidx/wear/watchface/style/data/ComplicationsUserStyleSettingWireFormat.java
@@ -182,7 +182,8 @@
*/
@ParcelField(100)
@NonNull
- public ComplicationOverlayWireFormat[] mComplicationOverlays;
+ public ComplicationOverlayWireFormat[] mComplicationOverlays =
+ new ComplicationOverlayWireFormat[0];
ComplicationsOptionWireFormat() {
}
diff --git a/wear/wear-watchface-style/src/test/java/androidx/wear/watchface/style/StyleParcelableTest.kt b/wear/wear-watchface-style/src/test/java/androidx/wear/watchface/style/StyleParcelableTest.kt
index 26b58f0..fa2c3de 100644
--- a/wear/wear-watchface-style/src/test/java/androidx/wear/watchface/style/StyleParcelableTest.kt
+++ b/wear/wear-watchface-style/src/test/java/androidx/wear/watchface/style/StyleParcelableTest.kt
@@ -17,13 +17,15 @@
package androidx.wear.watchface.style
import android.graphics.drawable.Icon
-import androidx.versionedparcelable.ParcelUtils
-import androidx.wear.watchface.style.data.UserStyleSchemaWireFormat
-import androidx.wear.watchface.style.data.UserStyleWireFormat
+import android.os.Parcel
import androidx.wear.watchface.style.UserStyleSetting.BooleanUserStyleSetting
+import androidx.wear.watchface.style.UserStyleSetting.ComplicationsUserStyleSetting
import androidx.wear.watchface.style.UserStyleSetting.DoubleRangeUserStyleSetting
import androidx.wear.watchface.style.UserStyleSetting.ListUserStyleSetting
import androidx.wear.watchface.style.UserStyleSetting.LongRangeUserStyleSetting
+import androidx.wear.watchface.style.data.UserStyleSchemaWireFormat
+import androidx.wear.watchface.style.data.UserStyleSettingWireFormat
+import androidx.wear.watchface.style.data.UserStyleWireFormat
import com.google.common.truth.Truth.assertThat
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
@@ -54,10 +56,17 @@
listOf(Layer.BASE_LAYER)
)
- val parcelable = ParcelUtils.toParcelable(styleSetting.toWireFormat())
+ val parcel = Parcel.obtain()
+ styleSetting.toWireFormat().writeToParcel(parcel, 0)
+
+ parcel.setDataPosition(0)
val unparceled =
- UserStyleSetting.createFromWireFormat(ParcelUtils.fromParcelable(parcelable))
+ UserStyleSetting.createFromWireFormat(
+ UserStyleSettingWireFormat.CREATOR.createFromParcel(parcel)
+ )
+ parcel.recycle()
+
assert(unparceled is ListUserStyleSetting)
assertThat(unparceled.id).isEqualTo("id")
@@ -134,28 +143,32 @@
listOf(Layer.BASE_LAYER)
)
- val parceled = ParcelUtils.toParcelable(
- UserStyleSchemaWireFormat(
- listOf(
- styleSetting1.toWireFormat(),
- styleSetting2.toWireFormat(),
- styleSetting3.toWireFormat()
- )
+ val srcSchema = UserStyleSchema(
+ listOf(
+ styleSetting1,
+ styleSetting2,
+ styleSetting3
)
)
- val unparceled: UserStyleSchemaWireFormat = ParcelUtils.fromParcelable(parceled)
- val schema = unparceled.mSchema.map { UserStyleSetting.createFromWireFormat(it) }
+ val parcel = Parcel.obtain()
+ srcSchema.toWireFormat().writeToParcel(parcel, 0)
- assert(schema[0] is ListUserStyleSetting)
- assertThat(schema[0].id).isEqualTo("id1")
- assertThat(schema[0].displayName).isEqualTo("displayName1")
- assertThat(schema[0].description).isEqualTo("description1")
- assertThat(schema[0].icon!!.uri.toString()).isEqualTo("settingIcon1")
- assertThat(schema[0].affectsLayers.size).isEqualTo(1)
- assertThat(schema[0].affectsLayers.first()).isEqualTo(Layer.BASE_LAYER)
+ parcel.setDataPosition(0)
+
+ val schema =
+ UserStyleSchema(UserStyleSchemaWireFormat.CREATOR.createFromParcel(parcel))
+ parcel.recycle()
+
+ assert(schema.userStyleSettings[0] is ListUserStyleSetting)
+ assertThat(schema.userStyleSettings[0].id).isEqualTo("id1")
+ assertThat(schema.userStyleSettings[0].displayName).isEqualTo("displayName1")
+ assertThat(schema.userStyleSettings[0].description).isEqualTo("description1")
+ assertThat(schema.userStyleSettings[0].icon!!.uri.toString()).isEqualTo("settingIcon1")
+ assertThat(schema.userStyleSettings[0].affectsLayers.size).isEqualTo(1)
+ assertThat(schema.userStyleSettings[0].affectsLayers.first()).isEqualTo(Layer.BASE_LAYER)
val optionArray1 =
- schema[0].options.filterIsInstance<ListUserStyleSetting.ListOption>()
+ schema.userStyleSettings[0].options.filterIsInstance<ListUserStyleSetting.ListOption>()
.toTypedArray()
assertThat(optionArray1.size).isEqualTo(2)
assertThat(optionArray1[0].id).isEqualTo("1")
@@ -165,15 +178,15 @@
assertThat(optionArray1[1].displayName).isEqualTo("two")
assertThat(optionArray1[1].icon!!.uri.toString()).isEqualTo("icon2")
- assert(schema[1] is ListUserStyleSetting)
- assertThat(schema[1].id).isEqualTo("id2")
- assertThat(schema[1].displayName).isEqualTo("displayName2")
- assertThat(schema[1].description).isEqualTo("description2")
- assertThat(schema[1].icon!!.uri.toString()).isEqualTo("settingIcon2")
- assertThat(schema[1].affectsLayers.size).isEqualTo(1)
- assertThat(schema[1].affectsLayers.first()).isEqualTo(Layer.TOP_LAYER)
+ assert(schema.userStyleSettings[1] is ListUserStyleSetting)
+ assertThat(schema.userStyleSettings[1].id).isEqualTo("id2")
+ assertThat(schema.userStyleSettings[1].displayName).isEqualTo("displayName2")
+ assertThat(schema.userStyleSettings[1].description).isEqualTo("description2")
+ assertThat(schema.userStyleSettings[1].icon!!.uri.toString()).isEqualTo("settingIcon2")
+ assertThat(schema.userStyleSettings[1].affectsLayers.size).isEqualTo(1)
+ assertThat(schema.userStyleSettings[1].affectsLayers.first()).isEqualTo(Layer.TOP_LAYER)
val optionArray2 =
- schema[1].options.filterIsInstance<ListUserStyleSetting.ListOption>()
+ schema.userStyleSettings[1].options.filterIsInstance<ListUserStyleSetting.ListOption>()
.toTypedArray()
assertThat(optionArray2.size).isEqualTo(2)
assertThat(optionArray2[0].id).isEqualTo("3")
@@ -183,13 +196,13 @@
assertThat(optionArray2[1].displayName).isEqualTo("four")
assertThat(optionArray2[1].icon!!.uri.toString()).isEqualTo("icon4")
- assert(schema[2] is BooleanUserStyleSetting)
- assertThat(schema[2].id).isEqualTo("id3")
- assertThat(schema[2].displayName).isEqualTo("displayName3")
- assertThat(schema[2].description).isEqualTo("description3")
- assertThat(schema[2].icon).isEqualTo(null)
- assertThat(schema[2].affectsLayers.size).isEqualTo(1)
- assertThat(schema[2].affectsLayers.first()).isEqualTo(Layer.BASE_LAYER)
+ assert(schema.userStyleSettings[2] is BooleanUserStyleSetting)
+ assertThat(schema.userStyleSettings[2].id).isEqualTo("id3")
+ assertThat(schema.userStyleSettings[2].displayName).isEqualTo("displayName3")
+ assertThat(schema.userStyleSettings[2].description).isEqualTo("description3")
+ assertThat(schema.userStyleSettings[2].icon).isEqualTo(null)
+ assertThat(schema.userStyleSettings[2].affectsLayers.size).isEqualTo(1)
+ assertThat(schema.userStyleSettings[2].affectsLayers.first()).isEqualTo(Layer.BASE_LAYER)
}
@Test
@@ -219,10 +232,16 @@
styleSetting2 as UserStyleSetting to option3 as UserStyleSetting.Option
)
)
- val parceled = ParcelUtils.toParcelable(userStyle.toWireFormat())
+
+ val parcel = Parcel.obtain()
+ userStyle.toWireFormat().writeToParcel(parcel, 0)
+
+ parcel.setDataPosition(0)
val unparcelled =
- UserStyle(ParcelUtils.fromParcelable(parceled) as UserStyleWireFormat, schema)
+ UserStyle(UserStyleWireFormat.CREATOR.createFromParcel(parcel), schema)
+ parcel.recycle()
+
assertThat(unparcelled.selectedOptions.size).isEqualTo(2)
assertThat(unparcelled.selectedOptions[styleSetting1]!!.id).isEqualTo(option2.id)
assertThat(unparcelled.selectedOptions[styleSetting2]!!.id).isEqualTo(option3.id)
@@ -328,4 +347,102 @@
)
assertThat(longRangeUserStyleSettingDefaultMax.getDefaultValue()).isEqualTo(10)
}
-}
\ No newline at end of file
+
+ @Test
+ fun parcelAndUnparcelComplicationsUserStyleSetting() {
+ val leftComplicationID = 101
+ val rightComplicationID = 102
+ val src = ComplicationsUserStyleSetting(
+ "complications_style_setting",
+ "Complications",
+ "Number and position",
+ icon = null,
+ complicationConfig = listOf(
+ ComplicationsUserStyleSetting.ComplicationsOption(
+ "LEFT_AND_RIGHT_COMPLICATIONS",
+ "Both",
+ null,
+ listOf()
+ ),
+ ComplicationsUserStyleSetting.ComplicationsOption(
+ "NO_COMPLICATIONS",
+ "None",
+ null,
+ listOf(
+ ComplicationsUserStyleSetting.ComplicationOverlay(
+ leftComplicationID,
+ enabled = false
+ ),
+ ComplicationsUserStyleSetting.ComplicationOverlay(
+ rightComplicationID,
+ enabled = false
+ )
+ )
+ ),
+ ComplicationsUserStyleSetting.ComplicationsOption(
+ "LEFT_COMPLICATION",
+ "Left",
+ null,
+ listOf(
+ ComplicationsUserStyleSetting.ComplicationOverlay(
+ rightComplicationID,
+ enabled = false
+ )
+ )
+ ),
+ ComplicationsUserStyleSetting.ComplicationsOption(
+ "RIGHT_COMPLICATION",
+ "Right",
+ null,
+ listOf(
+ ComplicationsUserStyleSetting.ComplicationOverlay(
+ leftComplicationID,
+ enabled = false
+ )
+ )
+ )
+ ),
+ listOf(Layer.COMPLICATIONS)
+ )
+
+ val parcel = Parcel.obtain()
+ src.toWireFormat().writeToParcel(parcel, 0)
+
+ parcel.setDataPosition(0)
+
+ val unparceled =
+ UserStyleSetting.createFromWireFormat(
+ UserStyleSettingWireFormat.CREATOR.createFromParcel(parcel)
+ )
+ parcel.recycle()
+
+ assert(unparceled is ComplicationsUserStyleSetting)
+ assertThat(unparceled.id).isEqualTo("complications_style_setting")
+
+ val options = unparceled.options.filterIsInstance<
+ ComplicationsUserStyleSetting.ComplicationsOption>()
+ assertThat(options.size).isEqualTo(4)
+ assertThat(options[0].id).isEqualTo("LEFT_AND_RIGHT_COMPLICATIONS")
+ assertThat(options[0].complicationOverlays.size).isEqualTo(0)
+
+ assertThat(options[1].id).isEqualTo("NO_COMPLICATIONS")
+ assertThat(options[1].complicationOverlays.size).isEqualTo(2)
+ val options1Overlays = ArrayList(options[1].complicationOverlays)
+ assertThat(options1Overlays[0].complicationId).isEqualTo(leftComplicationID)
+ assertFalse(options1Overlays[0].enabled!!)
+ assertThat(options1Overlays[1].complicationId).isEqualTo(rightComplicationID)
+ assertFalse(options1Overlays[1].enabled!!)
+
+ assertThat(options[2].id).isEqualTo("LEFT_COMPLICATION")
+ assertThat(options[2].complicationOverlays.size).isEqualTo(1)
+ val options2Overlays = ArrayList(options[2].complicationOverlays)
+ assertThat(options2Overlays[0].complicationId).isEqualTo(rightComplicationID)
+ assertFalse(options2Overlays[0].enabled!!)
+
+ assertThat(options[3].id).isEqualTo("RIGHT_COMPLICATION")
+ assertThat(options[3].complicationOverlays.size).isEqualTo(1)
+ val options3Overlays = ArrayList(options[3].complicationOverlays)
+ assertThat(options3Overlays[0].complicationId).isEqualTo(leftComplicationID)
+ assertFalse(options3Overlays[0].enabled!!)
+ }
+}
diff --git a/wear/wear-watchface/api/current.txt b/wear/wear-watchface/api/current.txt
index b251430..c6f4652 100644
--- a/wear/wear-watchface/api/current.txt
+++ b/wear/wear-watchface/api/current.txt
@@ -36,6 +36,8 @@
}
public final class Complication {
+ method public static androidx.wear.watchface.Complication.Builder createBackgroundComplicationBuilder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy);
+ method public static androidx.wear.watchface.Complication.Builder createRoundRectComplicationBuilder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy, android.graphics.RectF unitSquareBounds);
method @UiThread public androidx.wear.complications.DefaultComplicationProviderPolicy getDefaultProviderPolicy();
method @UiThread public androidx.wear.complications.data.ComplicationType getDefaultProviderType();
method @UiThread public androidx.wear.watchface.CanvasComplication getRenderer();
@@ -56,14 +58,17 @@
property @UiThread public final androidx.wear.watchface.CanvasComplication renderer;
property @UiThread public final java.util.List<androidx.wear.complications.data.ComplicationType> supportedTypes;
property @UiThread public final android.graphics.RectF unitSquareBounds;
+ field public static final androidx.wear.watchface.Complication.Companion Companion;
}
public static final class Complication.Builder {
- ctor public Complication.Builder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy);
method public androidx.wear.watchface.Complication build();
- method public androidx.wear.watchface.Complication.Builder setAsBackgroundComplication();
method public androidx.wear.watchface.Complication.Builder setDefaultProviderType(androidx.wear.complications.data.ComplicationType defaultProviderType);
- method public androidx.wear.watchface.Complication.Builder setUnitSquareBounds(android.graphics.RectF unitSquareBounds);
+ }
+
+ public static final class Complication.Companion {
+ method public androidx.wear.watchface.Complication.Builder createBackgroundComplicationBuilder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy);
+ method public androidx.wear.watchface.Complication.Builder createRoundRectComplicationBuilder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy, android.graphics.RectF unitSquareBounds);
}
public final class ComplicationOutlineRenderer {
@@ -196,7 +201,7 @@
method public Long? getOverridePreviewReferenceTimeMillis();
method public static boolean isLegacyWatchFaceOverlayStyleSupported();
method public androidx.wear.watchface.WatchFace setLegacyWatchFaceStyle(androidx.wear.watchface.WatchFace.LegacyWatchFaceOverlayStyle legacyWatchFaceStyle);
- method public androidx.wear.watchface.WatchFace setPreviewReferenceTimeMillis(long previewReferenceTimeMillis);
+ method public androidx.wear.watchface.WatchFace setOverridePreviewReferenceTimeMillis(@IntRange(from=0) long previewReferenceTimeMillis);
method public androidx.wear.watchface.WatchFace setTapListener(androidx.wear.watchface.WatchFace.TapListener? tapListener);
property public final androidx.wear.watchface.WatchFace.LegacyWatchFaceOverlayStyle legacyWatchFaceStyle;
property public final Long? overridePreviewReferenceTimeMillis;
diff --git a/wear/wear-watchface/api/public_plus_experimental_current.txt b/wear/wear-watchface/api/public_plus_experimental_current.txt
index b251430..c6f4652 100644
--- a/wear/wear-watchface/api/public_plus_experimental_current.txt
+++ b/wear/wear-watchface/api/public_plus_experimental_current.txt
@@ -36,6 +36,8 @@
}
public final class Complication {
+ method public static androidx.wear.watchface.Complication.Builder createBackgroundComplicationBuilder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy);
+ method public static androidx.wear.watchface.Complication.Builder createRoundRectComplicationBuilder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy, android.graphics.RectF unitSquareBounds);
method @UiThread public androidx.wear.complications.DefaultComplicationProviderPolicy getDefaultProviderPolicy();
method @UiThread public androidx.wear.complications.data.ComplicationType getDefaultProviderType();
method @UiThread public androidx.wear.watchface.CanvasComplication getRenderer();
@@ -56,14 +58,17 @@
property @UiThread public final androidx.wear.watchface.CanvasComplication renderer;
property @UiThread public final java.util.List<androidx.wear.complications.data.ComplicationType> supportedTypes;
property @UiThread public final android.graphics.RectF unitSquareBounds;
+ field public static final androidx.wear.watchface.Complication.Companion Companion;
}
public static final class Complication.Builder {
- ctor public Complication.Builder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy);
method public androidx.wear.watchface.Complication build();
- method public androidx.wear.watchface.Complication.Builder setAsBackgroundComplication();
method public androidx.wear.watchface.Complication.Builder setDefaultProviderType(androidx.wear.complications.data.ComplicationType defaultProviderType);
- method public androidx.wear.watchface.Complication.Builder setUnitSquareBounds(android.graphics.RectF unitSquareBounds);
+ }
+
+ public static final class Complication.Companion {
+ method public androidx.wear.watchface.Complication.Builder createBackgroundComplicationBuilder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy);
+ method public androidx.wear.watchface.Complication.Builder createRoundRectComplicationBuilder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy, android.graphics.RectF unitSquareBounds);
}
public final class ComplicationOutlineRenderer {
@@ -196,7 +201,7 @@
method public Long? getOverridePreviewReferenceTimeMillis();
method public static boolean isLegacyWatchFaceOverlayStyleSupported();
method public androidx.wear.watchface.WatchFace setLegacyWatchFaceStyle(androidx.wear.watchface.WatchFace.LegacyWatchFaceOverlayStyle legacyWatchFaceStyle);
- method public androidx.wear.watchface.WatchFace setPreviewReferenceTimeMillis(long previewReferenceTimeMillis);
+ method public androidx.wear.watchface.WatchFace setOverridePreviewReferenceTimeMillis(@IntRange(from=0) long previewReferenceTimeMillis);
method public androidx.wear.watchface.WatchFace setTapListener(androidx.wear.watchface.WatchFace.TapListener? tapListener);
property public final androidx.wear.watchface.WatchFace.LegacyWatchFaceOverlayStyle legacyWatchFaceStyle;
property public final Long? overridePreviewReferenceTimeMillis;
diff --git a/wear/wear-watchface/api/restricted_current.txt b/wear/wear-watchface/api/restricted_current.txt
index 4423921..7eb09a9 100644
--- a/wear/wear-watchface/api/restricted_current.txt
+++ b/wear/wear-watchface/api/restricted_current.txt
@@ -36,6 +36,8 @@
}
public final class Complication {
+ method public static androidx.wear.watchface.Complication.Builder createBackgroundComplicationBuilder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy);
+ method public static androidx.wear.watchface.Complication.Builder createRoundRectComplicationBuilder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy, android.graphics.RectF unitSquareBounds);
method @UiThread public androidx.wear.complications.DefaultComplicationProviderPolicy getDefaultProviderPolicy();
method @UiThread public androidx.wear.complications.data.ComplicationType getDefaultProviderType();
method @UiThread public androidx.wear.watchface.CanvasComplication getRenderer();
@@ -56,14 +58,17 @@
property @UiThread public final androidx.wear.watchface.CanvasComplication renderer;
property @UiThread public final java.util.List<androidx.wear.complications.data.ComplicationType> supportedTypes;
property @UiThread public final android.graphics.RectF unitSquareBounds;
+ field public static final androidx.wear.watchface.Complication.Companion Companion;
}
public static final class Complication.Builder {
- ctor public Complication.Builder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy);
method public androidx.wear.watchface.Complication build();
- method public androidx.wear.watchface.Complication.Builder setAsBackgroundComplication();
method public androidx.wear.watchface.Complication.Builder setDefaultProviderType(androidx.wear.complications.data.ComplicationType defaultProviderType);
- method public androidx.wear.watchface.Complication.Builder setUnitSquareBounds(android.graphics.RectF unitSquareBounds);
+ }
+
+ public static final class Complication.Companion {
+ method public androidx.wear.watchface.Complication.Builder createBackgroundComplicationBuilder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy);
+ method public androidx.wear.watchface.Complication.Builder createRoundRectComplicationBuilder(int id, androidx.wear.watchface.CanvasComplication renderer, java.util.List<? extends androidx.wear.complications.data.ComplicationType> supportedTypes, androidx.wear.complications.DefaultComplicationProviderPolicy defaultProviderPolicy, android.graphics.RectF unitSquareBounds);
}
public final class ComplicationOutlineRenderer {
@@ -226,7 +231,7 @@
method public Long? getOverridePreviewReferenceTimeMillis();
method public static boolean isLegacyWatchFaceOverlayStyleSupported();
method public androidx.wear.watchface.WatchFace setLegacyWatchFaceStyle(androidx.wear.watchface.WatchFace.LegacyWatchFaceOverlayStyle legacyWatchFaceStyle);
- method public androidx.wear.watchface.WatchFace setPreviewReferenceTimeMillis(long previewReferenceTimeMillis);
+ method public androidx.wear.watchface.WatchFace setOverridePreviewReferenceTimeMillis(@IntRange(from=0) long previewReferenceTimeMillis);
method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP) public androidx.wear.watchface.WatchFace setSystemTimeProvider(androidx.wear.watchface.WatchFace.SystemTimeProvider systemTimeProvider);
method public androidx.wear.watchface.WatchFace setTapListener(androidx.wear.watchface.WatchFace.TapListener? tapListener);
property public final androidx.wear.watchface.WatchFace.LegacyWatchFaceOverlayStyle legacyWatchFaceStyle;
diff --git a/wear/wear-watchface/samples/src/main/java/androidx/wear/watchface/samples/ExampleCanvasAnalogWatchFaceService.kt b/wear/wear-watchface/samples/src/main/java/androidx/wear/watchface/samples/ExampleCanvasAnalogWatchFaceService.kt
index 0dc238d..33152ef 100644
--- a/wear/wear-watchface/samples/src/main/java/androidx/wear/watchface/samples/ExampleCanvasAnalogWatchFaceService.kt
+++ b/wear/wear-watchface/samples/src/main/java/androidx/wear/watchface/samples/ExampleCanvasAnalogWatchFaceService.kt
@@ -200,7 +200,7 @@
)
)
)
- val leftComplication = Complication.Builder(
+ val leftComplication = Complication.createRoundRectComplicationBuilder(
EXAMPLE_CANVAS_WATCHFACE_LEFT_COMPLICATION_ID,
watchFaceStyle.getComplicationDrawableRenderer(context, watchState),
listOf(
@@ -210,11 +210,11 @@
ComplicationType.MONOCHROMATIC_IMAGE,
ComplicationType.SMALL_IMAGE
),
- DefaultComplicationProviderPolicy(SystemProviders.DAY_OF_WEEK)
- ).setUnitSquareBounds(RectF(0.2f, 0.4f, 0.4f, 0.6f))
- .setDefaultProviderType(ComplicationType.SHORT_TEXT)
+ DefaultComplicationProviderPolicy(SystemProviders.DAY_OF_WEEK),
+ RectF(0.2f, 0.4f, 0.4f, 0.6f)
+ ).setDefaultProviderType(ComplicationType.SHORT_TEXT)
.build()
- val rightComplication = Complication.Builder(
+ val rightComplication = Complication.createRoundRectComplicationBuilder(
EXAMPLE_CANVAS_WATCHFACE_RIGHT_COMPLICATION_ID,
watchFaceStyle.getComplicationDrawableRenderer(context, watchState),
listOf(
@@ -224,9 +224,9 @@
ComplicationType.MONOCHROMATIC_IMAGE,
ComplicationType.SMALL_IMAGE
),
- DefaultComplicationProviderPolicy(SystemProviders.STEP_COUNT)
- ).setUnitSquareBounds(RectF(0.6f, 0.4f, 0.8f, 0.6f))
- .setDefaultProviderType(ComplicationType.SHORT_TEXT)
+ DefaultComplicationProviderPolicy(SystemProviders.STEP_COUNT),
+ RectF(0.6f, 0.4f, 0.8f, 0.6f)
+ ).setDefaultProviderType(ComplicationType.SHORT_TEXT)
.build()
val complicationsManager = ComplicationsManager(
listOf(leftComplication, rightComplication),
diff --git a/wear/wear-watchface/samples/src/main/java/androidx/wear/watchface/samples/ExampleOpenGLWatchFaceService.kt b/wear/wear-watchface/samples/src/main/java/androidx/wear/watchface/samples/ExampleOpenGLWatchFaceService.kt
index ad425d4..458071d 100644
--- a/wear/wear-watchface/samples/src/main/java/androidx/wear/watchface/samples/ExampleOpenGLWatchFaceService.kt
+++ b/wear/wear-watchface/samples/src/main/java/androidx/wear/watchface/samples/ExampleOpenGLWatchFaceService.kt
@@ -111,7 +111,7 @@
val userStyleRepository = UserStyleRepository(UserStyleSchema(listOf(colorStyleSetting)))
val complicationsManager = ComplicationsManager(
listOf(
- Complication.Builder(
+ Complication.createRoundRectComplicationBuilder(
EXAMPLE_OPENGL_COMPLICATION_ID,
watchFaceStyle.getComplicationDrawableRenderer(context, watchState),
listOf(
@@ -121,9 +121,9 @@
ComplicationType.MONOCHROMATIC_IMAGE,
ComplicationType.SMALL_IMAGE
),
- DefaultComplicationProviderPolicy(SystemProviders.DAY_OF_WEEK)
- ).setUnitSquareBounds(RectF(0.2f, 0.7f, 0.4f, 0.9f))
- .setDefaultProviderType(ComplicationType.SHORT_TEXT)
+ DefaultComplicationProviderPolicy(SystemProviders.DAY_OF_WEEK),
+ RectF(0.2f, 0.7f, 0.4f, 0.9f)
+ ).setDefaultProviderType(ComplicationType.SHORT_TEXT)
.build()
),
userStyleRepository
diff --git a/wear/wear-watchface/samples/src/main/java/androidx/wear/watchface/samples/KDocExampleWatchFace.kt b/wear/wear-watchface/samples/src/main/java/androidx/wear/watchface/samples/KDocExampleWatchFace.kt
index 7c2da6a..8da96bb 100644
--- a/wear/wear-watchface/samples/src/main/java/androidx/wear/watchface/samples/KDocExampleWatchFace.kt
+++ b/wear/wear-watchface/samples/src/main/java/androidx/wear/watchface/samples/KDocExampleWatchFace.kt
@@ -103,7 +103,7 @@
)
val complicationSlots = ComplicationsManager(
listOf(
- Complication.Builder(
+ Complication.createRoundRectComplicationBuilder(
/*id */ 0,
CanvasComplicationDrawable(
ComplicationDrawable(this),
@@ -116,11 +116,11 @@
ComplicationType.MONOCHROMATIC_IMAGE,
ComplicationType.SMALL_IMAGE
),
- DefaultComplicationProviderPolicy(SystemProviders.DAY_OF_WEEK)
- ).setUnitSquareBounds(RectF(0.15625f, 0.1875f, 0.84375f, 0.3125f))
- .setDefaultProviderType(ComplicationType.SHORT_TEXT)
+ DefaultComplicationProviderPolicy(SystemProviders.DAY_OF_WEEK),
+ RectF(0.15625f, 0.1875f, 0.84375f, 0.3125f)
+ ).setDefaultProviderType(ComplicationType.SHORT_TEXT)
.build(),
- Complication.Builder(
+ Complication.createRoundRectComplicationBuilder(
/*id */ 1,
CanvasComplicationDrawable(
ComplicationDrawable(this),
@@ -133,9 +133,9 @@
ComplicationType.MONOCHROMATIC_IMAGE,
ComplicationType.SMALL_IMAGE
),
- DefaultComplicationProviderPolicy(SystemProviders.STEP_COUNT)
- ).setUnitSquareBounds(RectF(0.1f, 0.5625f, 0.35f, 0.8125f))
- .setDefaultProviderType(ComplicationType.SHORT_TEXT)
+ DefaultComplicationProviderPolicy(SystemProviders.STEP_COUNT),
+ RectF(0.1f, 0.5625f, 0.35f, 0.8125f)
+ ).setDefaultProviderType(ComplicationType.SHORT_TEXT)
.build()
),
userStyleRepository
diff --git a/wear/wear-watchface/src/main/java/androidx/wear/watchface/Complication.kt b/wear/wear-watchface/src/main/java/androidx/wear/watchface/Complication.kt
index 02185b38..e24e842 100644
--- a/wear/wear-watchface/src/main/java/androidx/wear/watchface/Complication.kt
+++ b/wear/wear-watchface/src/main/java/androidx/wear/watchface/Complication.kt
@@ -209,39 +209,100 @@
defaultProviderPolicy: DefaultComplicationProviderPolicy,
defaultProviderType: ComplicationType
) {
- /** @hide */
- private companion object {
+ public companion object {
internal val unitSquare = RectF(0f, 0f, 1f, 1f)
+
+ /**
+ * Constructs a [Builder] for a complication with bounds type
+ * [ComplicationBoundsType.ROUND_RECT]. This is the most common type of complication.
+ * These can be single tapped by the user to either trigger the associated intent or
+ * double tapped to open the provider selector.
+ */
+ @JvmStatic
+ public fun createRoundRectComplicationBuilder(
+ /** The watch face's ID for this complication. */
+ id: Int,
+
+ /**
+ * The renderer for this Complication. Renderers may not be sharable between complications.
+ */
+ renderer: CanvasComplication,
+
+ /**
+ * The types of complication supported by this Complication. Passed into
+ * [ComplicationHelperActivity.createProviderChooserHelperIntent] during complication
+ * configuration.
+ */
+ supportedTypes: List<ComplicationType>,
+
+ /** The [DefaultComplicationProviderPolicy] to use. */
+ defaultProviderPolicy: DefaultComplicationProviderPolicy,
+
+ /**
+ * The fractional bounds for the complication which are clamped to the unit square
+ * [0..1], and subsequently converted to screen space coordinates. NB 0 and 1 are
+ * included in the unit square.
+ */
+ unitSquareBounds: RectF
+ ): Builder = Builder(
+ id,
+ renderer,
+ supportedTypes,
+ defaultProviderPolicy,
+ ComplicationBoundsType.ROUND_RECT,
+ RectF().apply {
+ setIntersect(
+ unitSquareBounds,
+ unitSquare
+ )
+ }
+ )
+
+ /**
+ * Constructs a [Builder] for a complication with bound type
+ * [ComplicationBoundsType.BACKGROUND] whose bounds cover the entire screen. A background
+ * complication is for watch faces that wish to have a full screen user selectable
+ * backdrop. This sort of complication isn't clickable and at most one may be present in
+ * the list of complications.
+ */
+ @JvmStatic
+ public fun createBackgroundComplicationBuilder(
+ /** The watch face's ID for this complication. */
+ id: Int,
+
+ /**
+ * The renderer for this Complication. Renderers may not be sharable between complications.
+ */
+ renderer: CanvasComplication,
+
+ /**
+ * The types of complication supported by this Complication. Passed into
+ * [ComplicationHelperActivity.createProviderChooserHelperIntent] during complication
+ * configuration.
+ */
+ supportedTypes: List<ComplicationType>,
+
+ /** The [DefaultComplicationProviderPolicy] to use. */
+ defaultProviderPolicy: DefaultComplicationProviderPolicy
+ ): Builder = Builder(
+ id,
+ renderer,
+ supportedTypes,
+ defaultProviderPolicy,
+ ComplicationBoundsType.BACKGROUND,
+ RectF(0f, 0f, 1f, 1f)
+ )
}
- /**
- * Builder for constructing [Complication]s. Note before [Builder.build] the complication's
- * bounds & type must be specified by calling one of: [Builder.setUnitSquareBounds] or
- * [Builder.setAsBackgroundComplication].
- */
- public class Builder(
- /** The watch face's ID for this complication. */
+ /** Builder for constructing [Complication]s. */
+ public class Builder internal constructor(
private val id: Int,
-
- /**
- * The renderer for this Complication. Renderers may not be sharable between complications.
- */
private val renderer: CanvasComplication,
-
- /**
- * The types of complication supported by this Complication. Passed into
- * [ComplicationHelperActivity.createProviderChooserHelperIntent] during complication
- * configuration.
- */
private val supportedTypes: List<ComplicationType>,
-
- /** The [DefaultComplicationProviderPolicy] to use. */
- private val defaultProviderPolicy: DefaultComplicationProviderPolicy
+ private val defaultProviderPolicy: DefaultComplicationProviderPolicy,
+ @ComplicationBoundsType private val boundsType: Int,
+ private val unitSquareBounds: RectF
) {
- @ComplicationBoundsType
- private var boundsType: Int? = null
- private lateinit var unitSquareBounds: RectF
-
private var defaultProviderType = ComplicationType.NOT_CONFIGURED
/**
@@ -254,44 +315,10 @@
return this
}
- /**
- * Sets the fractional bounds for the complication and marks it as having type
- * [ComplicationBoundsType.ROUND_RECT]. The bounds are clamped to the unit square [0..1],
- * and subsequently converted to screen space coordinates. NB 0 and 1 are included in the
- * unit square.
- */
- public fun setUnitSquareBounds(unitSquareBounds: RectF): Builder {
- boundsType = ComplicationBoundsType.ROUND_RECT
-
- this.unitSquareBounds = RectF().apply {
- setIntersect(
- unitSquareBounds,
- unitSquare
- )
- }
- return this
- }
-
- /**
- * Marks the complication as having type [ComplicationBoundsType.BACKGROUND] and sets
- * the fractional bounds to cover the entire screen. A background complication is for
- * watch faces that wish to have a full screen user selectable backdrop. This sort of
- * complication isn't clickable and at most one may be present in the list of complications.
- */
- public fun setAsBackgroundComplication(): Builder {
- boundsType = ComplicationBoundsType.BACKGROUND
- this.unitSquareBounds = RectF(0f, 0f, 1f, 1f)
- return this
- }
-
- /**
- * Constructs the [Complication]. Note we require the complication's bounds & type to have
- * been be specified by calling one of: [Builder.setUnitSquareBounds] or
- * [Builder.setAsBackgroundComplication].
- */
+ /** Constructs the [Complication]. */
public fun build(): Complication = Complication(
id,
- boundsType!!,
+ boundsType,
unitSquareBounds,
renderer,
supportedTypes,
diff --git a/wear/wear-watchface/src/main/java/androidx/wear/watchface/Renderer.kt b/wear/wear-watchface/src/main/java/androidx/wear/watchface/Renderer.kt
index 2e6804d..7e5269ad 100644
--- a/wear/wear-watchface/src/main/java/androidx/wear/watchface/Renderer.kt
+++ b/wear/wear-watchface/src/main/java/androidx/wear/watchface/Renderer.kt
@@ -71,7 +71,12 @@
)
}
- /** The bounds of the [SurfaceHolder] this Renderer renders into. */
+ /**
+ * The bounds of the [SurfaceHolder] this Renderer renders into. Depending on the shape of the
+ * device's screen not all of these pixels may be visible to the user (see
+ * [WatchState.screenShape]). Note also that Wear 3 devices draw indicators in the top and
+ * bottom 24dp of the screen, avoid rendering anything important there.
+ */
public var screenBounds: Rect = surfaceHolder.surfaceFrame
private set
diff --git a/wear/wear-watchface/src/main/java/androidx/wear/watchface/WatchFace.kt b/wear/wear-watchface/src/main/java/androidx/wear/watchface/WatchFace.kt
index e1f61fa..cdb2fff 100644
--- a/wear/wear-watchface/src/main/java/androidx/wear/watchface/WatchFace.kt
+++ b/wear/wear-watchface/src/main/java/androidx/wear/watchface/WatchFace.kt
@@ -31,6 +31,7 @@
import android.view.ViewConfiguration
import androidx.annotation.ColorInt
import androidx.annotation.IntDef
+import androidx.annotation.IntRange
import androidx.annotation.Px
import androidx.annotation.RestrictTo
import androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP
@@ -211,6 +212,7 @@
/** The preview time in milliseconds since the epoch, or null if not set. */
@get:SuppressWarnings("AutoBoxing")
+ @IntRange(from = 0)
public var overridePreviewReferenceTimeMillis: Long? = null
private set
@@ -229,10 +231,10 @@
/**
* Overrides the reference time for editor preview images.
*
- * @param previewReferenceTimeMillis The preview time in milliseconds since the epoch
+ * @param previewReferenceTimeMillis The UTC preview time in milliseconds since the epoch
*/
- public fun setPreviewReferenceTimeMillis(
- previewReferenceTimeMillis: Long
+ public fun setOverridePreviewReferenceTimeMillis(
+ @IntRange(from = 0) previewReferenceTimeMillis: Long
): WatchFace = apply {
overridePreviewReferenceTimeMillis = previewReferenceTimeMillis
}
@@ -551,6 +553,7 @@
watchState.interruptionFilter.removeObserver(interruptionFilterObserver)
watchState.isVisible.removeObserver(visibilityObserver)
WatchFaceConfigActivity.unregisterWatchFace(componentName)
+ unregisterReceivers()
}
private fun registerReceivers() {
diff --git a/wear/wear-watchface/src/main/java/androidx/wear/watchface/WatchFaceService.kt b/wear/wear-watchface/src/main/java/androidx/wear/watchface/WatchFaceService.kt
index 4c46ad9..08570a6 100644
--- a/wear/wear-watchface/src/main/java/androidx/wear/watchface/WatchFaceService.kt
+++ b/wear/wear-watchface/src/main/java/androidx/wear/watchface/WatchFaceService.kt
@@ -621,7 +621,7 @@
unregisterReceiver(timeTickReceiver)
}
- if (!watchFaceCreated()) {
+ if (this::watchFaceImpl.isInitialized) {
watchFaceImpl.onDestroy()
}
diff --git a/wear/wear-watchface/src/main/java/androidx/wear/watchface/control/InteractiveInstanceManager.kt b/wear/wear-watchface/src/main/java/androidx/wear/watchface/control/InteractiveInstanceManager.kt
index 0d8e448..aa96ae8 100644
--- a/wear/wear-watchface/src/main/java/androidx/wear/watchface/control/InteractiveInstanceManager.kt
+++ b/wear/wear-watchface/src/main/java/androidx/wear/watchface/control/InteractiveInstanceManager.kt
@@ -59,9 +59,10 @@
@SuppressLint("SyntheticAccessor")
fun releaseInstance(instanceId: String) {
synchronized(pendingWallpaperInteractiveWatchFaceInstanceLock) {
- val instance = instances[instanceId]!!
- if (--instance.refcount == 0) {
- instances.remove(instanceId)
+ instances[instanceId]?.let {
+ if (--it.refcount == 0) {
+ instances.remove(instanceId)
+ }
}
}
}
diff --git a/wear/wear-watchface/src/test/java/androidx/wear/watchface/WatchFaceServiceTest.kt b/wear/wear-watchface/src/test/java/androidx/wear/watchface/WatchFaceServiceTest.kt
index eae361a..f40588e 100644
--- a/wear/wear-watchface/src/test/java/androidx/wear/watchface/WatchFaceServiceTest.kt
+++ b/wear/wear-watchface/src/test/java/androidx/wear/watchface/WatchFaceServiceTest.kt
@@ -150,7 +150,7 @@
ListUserStyleSetting.ListOption("bad_option", "Bad", icon = null)
private val leftComplication =
- Complication.Builder(
+ Complication.createRoundRectComplicationBuilder(
LEFT_COMPLICATION_ID,
CanvasComplicationDrawable(
complicationDrawableLeft,
@@ -165,13 +165,13 @@
ComplicationType.MONOCHROMATIC_IMAGE,
ComplicationType.SMALL_IMAGE
),
- DefaultComplicationProviderPolicy(SystemProviders.SUNRISE_SUNSET)
+ DefaultComplicationProviderPolicy(SystemProviders.SUNRISE_SUNSET),
+ RectF(0.2f, 0.4f, 0.4f, 0.6f)
).setDefaultProviderType(ComplicationType.SHORT_TEXT)
- .setUnitSquareBounds(RectF(0.2f, 0.4f, 0.4f, 0.6f))
.build()
private val rightComplication =
- Complication.Builder(
+ Complication.createRoundRectComplicationBuilder(
RIGHT_COMPLICATION_ID,
CanvasComplicationDrawable(
complicationDrawableRight,
@@ -186,13 +186,13 @@
ComplicationType.MONOCHROMATIC_IMAGE,
ComplicationType.SMALL_IMAGE
),
- DefaultComplicationProviderPolicy(SystemProviders.DAY_OF_WEEK)
+ DefaultComplicationProviderPolicy(SystemProviders.DAY_OF_WEEK),
+ RectF(0.6f, 0.4f, 0.8f, 0.6f)
).setDefaultProviderType(ComplicationType.SHORT_TEXT)
- .setUnitSquareBounds(RectF(0.6f, 0.4f, 0.8f, 0.6f))
.build()
private val backgroundComplication =
- Complication.Builder(
+ Complication.createBackgroundComplicationBuilder(
BACKGROUND_COMPLICATION_ID,
CanvasComplicationDrawable(
complicationDrawableRight,
@@ -205,7 +205,6 @@
),
DefaultComplicationProviderPolicy()
).setDefaultProviderType(ComplicationType.BACKGROUND_IMAGE)
- .setAsBackgroundComplication()
.build()
private val leftAndRightComplicationsOption = ComplicationsOption(
@@ -1396,7 +1395,7 @@
fun defaultProvidersWithFallbacks_newApi() {
val provider1 = ComponentName("com.app1", "com.app1.App1")
val provider2 = ComponentName("com.app2", "com.app2.App2")
- val complication = Complication.Builder(
+ val complication = Complication.createRoundRectComplicationBuilder(
LEFT_COMPLICATION_ID,
CanvasComplicationDrawable(complicationDrawableLeft, watchState.asWatchState()),
emptyList(),
@@ -1404,9 +1403,9 @@
provider1,
provider2,
SystemProviders.SUNRISE_SUNSET
- )
+ ),
+ RectF(0.2f, 0.4f, 0.4f, 0.6f)
).setDefaultProviderType(ComplicationType.SHORT_TEXT)
- .setUnitSquareBounds(RectF(0.2f, 0.4f, 0.4f, 0.6f))
.build()
initEngine(WatchFaceType.ANALOG, listOf(complication), UserStyleSchema(emptyList()))
@@ -1424,7 +1423,7 @@
fun defaultProvidersWithFallbacks_oldApi() {
val provider1 = ComponentName("com.app1", "com.app1.App1")
val provider2 = ComponentName("com.app2", "com.app2.App2")
- val complication = Complication.Builder(
+ val complication = Complication.createRoundRectComplicationBuilder(
LEFT_COMPLICATION_ID,
CanvasComplicationDrawable(complicationDrawableLeft, watchState.asWatchState()),
emptyList(),
@@ -1432,9 +1431,9 @@
provider1,
provider2,
SystemProviders.SUNRISE_SUNSET
- )
+ ),
+ RectF(0.2f, 0.4f, 0.4f, 0.6f)
).setDefaultProviderType(ComplicationType.SHORT_TEXT)
- .setUnitSquareBounds(RectF(0.2f, 0.4f, 0.4f, 0.6f))
.build()
initEngine(
WatchFaceType.ANALOG,
diff --git a/wear/wear-watchface/src/test/java/androidx/wear/watchface/ui/WatchFaceConfigUiTest.kt b/wear/wear-watchface/src/test/java/androidx/wear/watchface/ui/WatchFaceConfigUiTest.kt
index c501321..b40232e 100644
--- a/wear/wear-watchface/src/test/java/androidx/wear/watchface/ui/WatchFaceConfigUiTest.kt
+++ b/wear/wear-watchface/src/test/java/androidx/wear/watchface/ui/WatchFaceConfigUiTest.kt
@@ -119,7 +119,7 @@
)
private val leftComplication =
- Complication.Builder(
+ Complication.createRoundRectComplicationBuilder(
LEFT_COMPLICATION_ID,
CanvasComplicationDrawable(
complicationDrawableLeft,
@@ -134,13 +134,13 @@
ComplicationType.MONOCHROMATIC_IMAGE,
ComplicationType.SMALL_IMAGE
),
- DefaultComplicationProviderPolicy(SystemProviders.SUNRISE_SUNSET)
+ DefaultComplicationProviderPolicy(SystemProviders.SUNRISE_SUNSET),
+ RectF(0.2f, 0.4f, 0.4f, 0.6f)
).setDefaultProviderType(ComplicationType.SHORT_TEXT)
- .setUnitSquareBounds(RectF(0.2f, 0.4f, 0.4f, 0.6f))
.build()
private val rightComplication =
- Complication.Builder(
+ Complication.createRoundRectComplicationBuilder(
RIGHT_COMPLICATION_ID,
CanvasComplicationDrawable(
complicationDrawableRight,
@@ -155,13 +155,13 @@
ComplicationType.MONOCHROMATIC_IMAGE,
ComplicationType.SMALL_IMAGE
),
- DefaultComplicationProviderPolicy(SystemProviders.DAY_OF_WEEK)
+ DefaultComplicationProviderPolicy(SystemProviders.DAY_OF_WEEK),
+ RectF(0.6f, 0.4f, 0.8f, 0.6f)
).setDefaultProviderType(ComplicationType.SHORT_TEXT)
- .setUnitSquareBounds(RectF(0.6f, 0.4f, 0.8f, 0.6f))
.build()
private val backgroundComplication =
- Complication.Builder(
+ Complication.createBackgroundComplicationBuilder(
BACKGROUND_COMPLICATION_ID,
CanvasComplicationDrawable(
complicationDrawableRight,
@@ -174,7 +174,6 @@
),
DefaultComplicationProviderPolicy()
).setDefaultProviderType(ComplicationType.BACKGROUND_IMAGE)
- .setAsBackgroundComplication()
.build()
private val calendar = Calendar.getInstance().apply {