Skip to content

Commit 4266212

Browse files
committed
Added Drag and Drop updates
1 parent 315d4f1 commit 4266212

File tree

4 files changed

+60
-25
lines changed

4 files changed

+60
-25
lines changed

compose/snippets/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ android {
7777

7878
dependencies {
7979
implementation(libs.androidx.work.runtime.ktx)
80+
implementation(libs.testng)
81+
implementation(libs.androidx.ui.test.android)
82+
implementation(libs.androidx.ui.test.junit4.android)
8083
val composeBom = platform(libs.androidx.compose.bom)
8184
implementation(composeBom)
8285
androidTestImplementation(composeBom)

compose/snippets/src/main/java/com/example/compose/snippets/draganddrop/DragAndDropSnippets.kt

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,29 @@ private fun DragAndDropSnippet() {
4141
val url = ""
4242

4343
// [START android_compose_drag_and_drop_1]
44-
Modifier.dragAndDropSource {
45-
detectTapGestures(onLongPress = {
46-
// Transfer data here.
47-
})
44+
Modifier.dragAndDropSource { _ ->
45+
// Transfer data here.
46+
TODO()
4847
}
4948
// [END android_compose_drag_and_drop_1]
5049

5150
// [START android_compose_drag_and_drop_2]
52-
Modifier.dragAndDropSource {
53-
detectTapGestures(onLongPress = {
54-
startTransfer(
55-
DragAndDropTransferData(
56-
ClipData.newPlainText(
57-
"image Url", url
58-
)
59-
)
60-
)
61-
})
51+
Modifier.dragAndDropSource { _ ->
52+
DragAndDropTransferData(
53+
ClipData.newPlainText(
54+
"image Url", url)
55+
)
6256
}
6357
// [END android_compose_drag_and_drop_2]
6458

6559
// [START android_compose_drag_and_drop_3]
66-
Modifier.dragAndDropSource {
67-
detectTapGestures(onLongPress = {
68-
startTransfer(
69-
DragAndDropTransferData(
70-
ClipData.newPlainText(
71-
"image Url", url
72-
),
73-
flags = View.DRAG_FLAG_GLOBAL
74-
)
75-
)
76-
})
60+
Modifier.dragAndDropSource { _ ->
61+
DragAndDropTransferData(
62+
ClipData.newPlainText(
63+
"image Url", url
64+
),
65+
flags = View.DRAG_FLAG_GLOBAL
66+
)
7767
}
7868
// [END android_compose_drag_and_drop_3]
7969

compose/snippets/src/main/java/com/example/compose/snippets/text/AutofillSnippets.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import androidx.compose.foundation.layout.height
2222
import androidx.compose.foundation.text.BasicTextField
2323
import androidx.compose.foundation.text.LocalAutofillHighlightColor
2424
import androidx.compose.foundation.text.input.TextFieldState
25+
import androidx.compose.material.TextField
26+
import androidx.compose.material3.Surface
2527
import androidx.compose.material3.Text
2628
import androidx.compose.runtime.Composable
2729
import androidx.compose.runtime.CompositionLocalProvider
@@ -30,10 +32,20 @@ import androidx.compose.ui.Modifier
3032
import androidx.compose.ui.autofill.ContentType
3133
import androidx.compose.ui.graphics.Color
3234
import androidx.compose.ui.platform.LocalAutofillManager
35+
import androidx.compose.ui.platform.testTag
36+
import androidx.compose.ui.semantics.SemanticsProperties
37+
import androidx.compose.ui.semantics.SemanticsProperties.TestTag
3338
import androidx.compose.ui.semantics.contentType
3439
import androidx.compose.ui.semantics.semantics
40+
import androidx.compose.ui.test.SemanticsMatcher
41+
import androidx.compose.ui.test.assert
42+
import androidx.compose.ui.test.junit4.createComposeRule
43+
import androidx.compose.ui.test.onNodeWithTag
3544
import androidx.compose.ui.unit.dp
3645
import com.example.compose.snippets.touchinput.Button
46+
import org.junit.Rule
47+
import org.testng.annotations.Test
48+
3749

3850
@Composable
3951
fun AddAutofill() {
@@ -140,3 +152,27 @@ fun customizeAutofillHighlight() {
140152
}
141153
}
142154
// [END android_compose_autofill_6]
155+
156+
@get:Rule
157+
val rule = createComposeRule()
158+
@Test
159+
fun autofillHintTest(): Unit {
160+
val autofillHintString = "test autofill string"
161+
val TestTag = "semantics-test-tag"
162+
163+
// rule.setContent {
164+
// Surface {
165+
// TextField(
166+
// state = remember { TextFieldState() },
167+
// modifier = Modifier
168+
// .testTag(TestTag)
169+
// .semantics { contentType = autofillHintString }
170+
// )
171+
// }
172+
// }
173+
//
174+
// rule.onNodeWithTag(TestTag)
175+
// .assert(SemanticsMatcher.expectValue(
176+
// SemanticsProperties.ContentType, autofillHintString)
177+
// )
178+
}

gradle/libs.versions.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ wear = "1.3.0"
6161
wearComposeFoundation = "1.4.0"
6262
wearComposeMaterial = "1.4.0"
6363
wearToolingPreview = "1.0.0"
64+
testng = "6.9.6"
65+
uiTestAndroid = "1.7.6"
66+
uiTestJunit4Android = "1.7.6"
6467

6568
[libraries]
6669
accompanist-adaptive = { module = "com.google.accompanist:accompanist-adaptive", version.ref = "accompanist" }
@@ -149,6 +152,9 @@ kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutine
149152
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
150153
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
151154
play-services-wearable = { module = "com.google.android.gms:play-services-wearable", version.ref = "playServicesWearable" }
155+
testng = { group = "org.testng", name = "testng", version.ref = "testng" }
156+
androidx-ui-test-android = { group = "androidx.compose.ui", name = "ui-test-android", version.ref = "uiTestAndroid" }
157+
androidx-ui-test-junit4-android = { group = "androidx.compose.ui", name = "ui-test-junit4-android", version.ref = "uiTestJunit4Android" }
152158

153159
[plugins]
154160
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }

0 commit comments

Comments
 (0)