Merge "Change button to ToggleButton." into androidx-main
diff --git a/compose/ui/ui-graphics/api/current.ignore b/compose/ui/ui-graphics/api/current.ignore
new file mode 100644
index 0000000..ac8aa37
--- /dev/null
+++ b/compose/ui/ui-graphics/api/current.ignore
@@ -0,0 +1,5 @@
+// Baseline format: 1.0
+AddedAbstractMethod: androidx.compose.ui.graphics.PathMeasure#getPosition(float):
+ Added method androidx.compose.ui.graphics.PathMeasure.getPosition(float)
+AddedAbstractMethod: androidx.compose.ui.graphics.PathMeasure#getTangent(float):
+ Added method androidx.compose.ui.graphics.PathMeasure.getTangent(float)
diff --git a/compose/ui/ui-graphics/api/current.txt b/compose/ui/ui-graphics/api/current.txt
index f1c4192..8f387eca 100644
--- a/compose/ui/ui-graphics/api/current.txt
+++ b/compose/ui/ui-graphics/api/current.txt
@@ -115,7 +115,9 @@
public final class AndroidPathMeasure implements androidx.compose.ui.graphics.PathMeasure {
method public float getLength();
+ method public long getPosition(float distance);
method public boolean getSegment(float startDistance, float stopDistance, androidx.compose.ui.graphics.Path destination, boolean startWithMoveTo);
+ method public long getTangent(float distance);
method public void setPath(androidx.compose.ui.graphics.Path? path, boolean forceClosed);
property public float length;
}
@@ -666,7 +668,9 @@
@kotlin.jvm.JvmDefaultWithCompatibility public interface PathMeasure {
method public float getLength();
+ method public long getPosition(float distance);
method public boolean getSegment(float startDistance, float stopDistance, androidx.compose.ui.graphics.Path destination, optional boolean startWithMoveTo);
+ method public long getTangent(float distance);
method public void setPath(androidx.compose.ui.graphics.Path? path, boolean forceClosed);
property public abstract float length;
}
diff --git a/compose/ui/ui-graphics/api/public_plus_experimental_current.txt b/compose/ui/ui-graphics/api/public_plus_experimental_current.txt
index 90bb660..f5a56d4 100644
--- a/compose/ui/ui-graphics/api/public_plus_experimental_current.txt
+++ b/compose/ui/ui-graphics/api/public_plus_experimental_current.txt
@@ -115,7 +115,9 @@
public final class AndroidPathMeasure implements androidx.compose.ui.graphics.PathMeasure {
method public float getLength();
+ method public long getPosition(float distance);
method public boolean getSegment(float startDistance, float stopDistance, androidx.compose.ui.graphics.Path destination, boolean startWithMoveTo);
+ method public long getTangent(float distance);
method public void setPath(androidx.compose.ui.graphics.Path? path, boolean forceClosed);
property public float length;
}
@@ -669,7 +671,9 @@
@kotlin.jvm.JvmDefaultWithCompatibility public interface PathMeasure {
method public float getLength();
+ method public long getPosition(float distance);
method public boolean getSegment(float startDistance, float stopDistance, androidx.compose.ui.graphics.Path destination, optional boolean startWithMoveTo);
+ method public long getTangent(float distance);
method public void setPath(androidx.compose.ui.graphics.Path? path, boolean forceClosed);
property public abstract float length;
}
diff --git a/compose/ui/ui-graphics/api/restricted_current.ignore b/compose/ui/ui-graphics/api/restricted_current.ignore
new file mode 100644
index 0000000..ac8aa37
--- /dev/null
+++ b/compose/ui/ui-graphics/api/restricted_current.ignore
@@ -0,0 +1,5 @@
+// Baseline format: 1.0
+AddedAbstractMethod: androidx.compose.ui.graphics.PathMeasure#getPosition(float):
+ Added method androidx.compose.ui.graphics.PathMeasure.getPosition(float)
+AddedAbstractMethod: androidx.compose.ui.graphics.PathMeasure#getTangent(float):
+ Added method androidx.compose.ui.graphics.PathMeasure.getTangent(float)
diff --git a/compose/ui/ui-graphics/api/restricted_current.txt b/compose/ui/ui-graphics/api/restricted_current.txt
index adad1a5..a7f88e5 100644
--- a/compose/ui/ui-graphics/api/restricted_current.txt
+++ b/compose/ui/ui-graphics/api/restricted_current.txt
@@ -145,7 +145,9 @@
public final class AndroidPathMeasure implements androidx.compose.ui.graphics.PathMeasure {
method public float getLength();
+ method public long getPosition(float distance);
method public boolean getSegment(float startDistance, float stopDistance, androidx.compose.ui.graphics.Path destination, boolean startWithMoveTo);
+ method public long getTangent(float distance);
method public void setPath(androidx.compose.ui.graphics.Path? path, boolean forceClosed);
property public float length;
}
@@ -698,7 +700,9 @@
@kotlin.jvm.JvmDefaultWithCompatibility public interface PathMeasure {
method public float getLength();
+ method public long getPosition(float distance);
method public boolean getSegment(float startDistance, float stopDistance, androidx.compose.ui.graphics.Path destination, optional boolean startWithMoveTo);
+ method public long getTangent(float distance);
method public void setPath(androidx.compose.ui.graphics.Path? path, boolean forceClosed);
property public abstract float length;
}
diff --git a/compose/ui/ui-graphics/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/PathMeasureTest.kt b/compose/ui/ui-graphics/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/PathMeasureTest.kt
new file mode 100644
index 0000000..afacfe3
--- /dev/null
+++ b/compose/ui/ui-graphics/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/PathMeasureTest.kt
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2022 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.graphics
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import org.junit.Assert
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class PathMeasureTest {
+
+ @Test
+ fun testGetPositionAndTangent() {
+ val width = 100f
+ val height = 100f
+ val path = Path().apply {
+ lineTo(width, height)
+ }
+ val pathMeasure = PathMeasure()
+
+ pathMeasure.setPath(path, false)
+ val distance = pathMeasure.length
+ val position = pathMeasure.getPosition(distance * 0.5f)
+
+ val tangent = pathMeasure.getTangent(distance * 0.5f)
+
+ Assert.assertEquals(50f, position.x)
+ Assert.assertEquals(50f, position.y)
+ Assert.assertEquals(0.707106f, tangent.x, 0.00001f)
+ Assert.assertEquals(0.707106f, tangent.y, 0.00001f)
+ }
+}
\ No newline at end of file
diff --git a/compose/ui/ui-graphics/src/androidMain/kotlin/androidx/compose/ui/graphics/AndroidPathMeasure.android.kt b/compose/ui/ui-graphics/src/androidMain/kotlin/androidx/compose/ui/graphics/AndroidPathMeasure.android.kt
index d9996fa..358b3af 100644
--- a/compose/ui/ui-graphics/src/androidMain/kotlin/androidx/compose/ui/graphics/AndroidPathMeasure.android.kt
+++ b/compose/ui/ui-graphics/src/androidMain/kotlin/androidx/compose/ui/graphics/AndroidPathMeasure.android.kt
@@ -16,6 +16,8 @@
package androidx.compose.ui.graphics
+import androidx.compose.ui.geometry.Offset
+
actual fun PathMeasure(): PathMeasure = AndroidPathMeasure(android.graphics.PathMeasure())
class AndroidPathMeasure internal constructor(
@@ -25,6 +27,10 @@
override val length: Float
get() = internalPathMeasure.length
+ private var positionArray: FloatArray? = null
+
+ private var tangentArray: FloatArray? = null
+
override fun getSegment(
startDistance: Float,
stopDistance: Float,
@@ -42,4 +48,38 @@
override fun setPath(path: Path?, forceClosed: Boolean) {
internalPathMeasure.setPath(path?.asAndroidPath(), forceClosed)
}
+
+ override fun getPosition(
+ distance: Float
+ ): Offset {
+ if (positionArray == null) {
+ positionArray = FloatArray(2)
+ }
+ if (tangentArray == null) {
+ tangentArray = FloatArray(2)
+ }
+ val result = internalPathMeasure.getPosTan(distance, positionArray, tangentArray)
+ return if (result) {
+ Offset(positionArray!![0], positionArray!![1])
+ } else {
+ Offset.Unspecified
+ }
+ }
+
+ override fun getTangent(
+ distance: Float
+ ): Offset {
+ if (positionArray == null) {
+ positionArray = FloatArray(2)
+ }
+ if (tangentArray == null) {
+ tangentArray = FloatArray(2)
+ }
+ val result = internalPathMeasure.getPosTan(distance, positionArray, tangentArray)
+ return if (result) {
+ Offset(tangentArray!![0], tangentArray!![1])
+ } else {
+ Offset.Unspecified
+ }
+ }
}
diff --git a/compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/PathMeasure.kt b/compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/PathMeasure.kt
index 9e168cb..d2ee71f 100644
--- a/compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/PathMeasure.kt
+++ b/compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/PathMeasure.kt
@@ -16,6 +16,7 @@
package androidx.compose.ui.graphics
+import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.internal.JvmDefaultWithCompatibility
/**
@@ -53,4 +54,22 @@
* Assign a new path, or null to have none.
*/
fun setPath(path: Path?, forceClosed: Boolean)
+
+ /**
+ * Pins distance to 0 <= distance <= getLength(), and then computes the corresponding position
+ *
+ * @param distance The distance along the current contour to sample
+ *
+ * @return [Offset.Unspecified] if there is no path set
+ */
+ fun getPosition(distance: Float): Offset
+
+ /**
+ * Pins distance to 0 <= distance <= getLength(), and then computes the corresponding tangent
+ *
+ * @param distance The distance along the current contour to sample
+ *
+ * @return [Offset.Unspecified] if there is no path set
+ */
+ fun getTangent(distance: Float): Offset
}
diff --git a/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedPathMeasure.skiko.kt b/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedPathMeasure.skiko.kt
index 7658c68..810a409 100644
--- a/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedPathMeasure.skiko.kt
+++ b/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedPathMeasure.skiko.kt
@@ -16,6 +16,7 @@
package androidx.compose.ui.graphics
+import androidx.compose.ui.geometry.Offset
/**
* Convert the [org.jetbrains.skia.PathMeasure] instance into a Compose-compatible PathMeasure
*/
@@ -49,6 +50,28 @@
override val length: Float
get() = skia.length
+
+ override fun getPosition(
+ distance: Float
+ ): Offset {
+ val result = skia.getPosition(distance)
+ return if (result != null) {
+ Offset(result.x, result.y)
+ } else {
+ Offset.Unspecified
+ }
+ }
+
+ override fun getTangent(
+ distance: Float
+ ): Offset {
+ val result = skia.getTangent(distance)
+ return if (result != null) {
+ Offset(result.x, result.y)
+ } else {
+ Offset.Unspecified
+ }
+ }
}
actual fun PathMeasure(): PathMeasure =
diff --git a/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/ImageDragActivity.java b/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/ImageDragActivity.java
index 1ae07c2..1569ff6 100644
--- a/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/ImageDragActivity.java
+++ b/webkit/integration-tests/testapp/src/main/java/com/example/androidx/webkit/ImageDragActivity.java
@@ -18,6 +18,7 @@
import android.os.Bundle;
import android.webkit.WebView;
+import android.webkit.WebViewClient;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
@@ -33,6 +34,7 @@
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_drag);
WebView demoWebview = findViewById(R.id.image_webview);
+ demoWebview.setWebViewClient(new WebViewClient()); // Open links in this WebView.
demoWebview.loadUrl("www.google.com");
}
diff --git a/webkit/webkit/api/current.txt b/webkit/webkit/api/current.txt
index faf13cb..0c9d5ee 100644
--- a/webkit/webkit/api/current.txt
+++ b/webkit/webkit/api/current.txt
@@ -5,6 +5,16 @@
method @RequiresFeature(name=androidx.webkit.WebViewFeature.GET_COOKIE_INFO, enforcement="androidx.webkit.WebViewFeature#isFeatureSupported") public static java.util.List<java.lang.String!> getCookieInfo(android.webkit.CookieManager, String);
}
+ public final class DropDataContentProvider extends android.content.ContentProvider {
+ ctor public DropDataContentProvider();
+ method public int delete(android.net.Uri, String?, String![]?);
+ method public String? getType(android.net.Uri);
+ method public android.net.Uri? insert(android.net.Uri, android.content.ContentValues?);
+ method public boolean onCreate();
+ method public android.database.Cursor? query(android.net.Uri, String![]?, String?, String![]?, String?);
+ method public int update(android.net.Uri, android.content.ContentValues?, String?, String![]?);
+ }
+
public abstract class JavaScriptReplyProxy {
method @RequiresFeature(name=androidx.webkit.WebViewFeature.WEB_MESSAGE_LISTENER, enforcement="androidx.webkit.WebViewFeature#isFeatureSupported") public abstract void postMessage(String);
}
diff --git a/webkit/webkit/api/public_plus_experimental_current.txt b/webkit/webkit/api/public_plus_experimental_current.txt
index faf13cb..0c9d5ee 100644
--- a/webkit/webkit/api/public_plus_experimental_current.txt
+++ b/webkit/webkit/api/public_plus_experimental_current.txt
@@ -5,6 +5,16 @@
method @RequiresFeature(name=androidx.webkit.WebViewFeature.GET_COOKIE_INFO, enforcement="androidx.webkit.WebViewFeature#isFeatureSupported") public static java.util.List<java.lang.String!> getCookieInfo(android.webkit.CookieManager, String);
}
+ public final class DropDataContentProvider extends android.content.ContentProvider {
+ ctor public DropDataContentProvider();
+ method public int delete(android.net.Uri, String?, String![]?);
+ method public String? getType(android.net.Uri);
+ method public android.net.Uri? insert(android.net.Uri, android.content.ContentValues?);
+ method public boolean onCreate();
+ method public android.database.Cursor? query(android.net.Uri, String![]?, String?, String![]?, String?);
+ method public int update(android.net.Uri, android.content.ContentValues?, String?, String![]?);
+ }
+
public abstract class JavaScriptReplyProxy {
method @RequiresFeature(name=androidx.webkit.WebViewFeature.WEB_MESSAGE_LISTENER, enforcement="androidx.webkit.WebViewFeature#isFeatureSupported") public abstract void postMessage(String);
}
diff --git a/webkit/webkit/api/restricted_current.txt b/webkit/webkit/api/restricted_current.txt
index faf13cb..0c9d5ee 100644
--- a/webkit/webkit/api/restricted_current.txt
+++ b/webkit/webkit/api/restricted_current.txt
@@ -5,6 +5,16 @@
method @RequiresFeature(name=androidx.webkit.WebViewFeature.GET_COOKIE_INFO, enforcement="androidx.webkit.WebViewFeature#isFeatureSupported") public static java.util.List<java.lang.String!> getCookieInfo(android.webkit.CookieManager, String);
}
+ public final class DropDataContentProvider extends android.content.ContentProvider {
+ ctor public DropDataContentProvider();
+ method public int delete(android.net.Uri, String?, String![]?);
+ method public String? getType(android.net.Uri);
+ method public android.net.Uri? insert(android.net.Uri, android.content.ContentValues?);
+ method public boolean onCreate();
+ method public android.database.Cursor? query(android.net.Uri, String![]?, String?, String![]?, String?);
+ method public int update(android.net.Uri, android.content.ContentValues?, String?, String![]?);
+ }
+
public abstract class JavaScriptReplyProxy {
method @RequiresFeature(name=androidx.webkit.WebViewFeature.WEB_MESSAGE_LISTENER, enforcement="androidx.webkit.WebViewFeature#isFeatureSupported") public abstract void postMessage(String);
}
diff --git a/webkit/webkit/src/main/java/androidx/webkit/DropDataContentProvider.java b/webkit/webkit/src/main/java/androidx/webkit/DropDataContentProvider.java
index 6c38760..6af699c 100644
--- a/webkit/webkit/src/main/java/androidx/webkit/DropDataContentProvider.java
+++ b/webkit/webkit/src/main/java/androidx/webkit/DropDataContentProvider.java
@@ -25,7 +25,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import androidx.annotation.RestrictTo;
import androidx.webkit.internal.WebViewGlueCommunicator;
import org.chromium.support_lib_boundary.DropDataContentProviderBoundaryInterface;
@@ -33,13 +32,23 @@
import java.io.FileNotFoundException;
/**
- * TODO(1353048): Un-hide this after finishing the feature.
+ * WebView provides partial support for Android
+ * <a href="https://developer.android.com/develop/ui/views/touch-and-input/drag-drop">
+ * Drag and Drop</a> allowing images, text and links to be dragged out of a WebView.
*
- * @hide
- * This should be added to the manifest in order to enable dragging images out.
+ * The content provider is required to make the images drag work, to enable, you should add this
+ * class to your manifest, for example:
+ *
+ * <pre class="prettyprint">
+ * <provider
+ * android:authorities="{{your package}}.DropDataProvider"
+ * android:name="androidx.webkit.DropDataContentProvider"
+ * android:exported="false"
+ * android:grantUriPermissions="true"/>
+ * </pre>
+ *
*/
-@RestrictTo(RestrictTo.Scope.LIBRARY)
-public class DropDataContentProvider extends ContentProvider {
+public final class DropDataContentProvider extends ContentProvider {
DropDataContentProviderBoundaryInterface mImpl;
@Override