-
Notifications
You must be signed in to change notification settings - Fork 213
Adding Autofill snippets #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MagicalMeghan
wants to merge
17
commits into
main
Choose a base branch
from
autofill-snippets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8fab99e
Adding Autofill snippets
MagicalMeghan b510be2
Apply Spotless
MagicalMeghan 996e15e
Update shared element parameters
MagicalMeghan bab62b6
Merge branch 'autofill-snippets' of https://github.com/android/snippe…
MagicalMeghan 3b9233a
Update UserInteractions.kt
MagicalMeghan 315d4f1
Update AutofillSnippets.kt
MagicalMeghan 4266212
Added Drag and Drop updates
MagicalMeghan b50ebf5
Apply Spotless
MagicalMeghan 6722af8
Clean up
MagicalMeghan 8bc39e3
Merge branch 'autofill-snippets' of https://github.com/android/snippe…
MagicalMeghan 86ee57c
Apply Spotless
MagicalMeghan 105645a
Update AutofillSnippets.kt
MagicalMeghan 347c502
Merge branch 'autofill-snippets' of https://github.com/android/snippe…
MagicalMeghan 635ea2c
Update AutofillSnippets.kt
MagicalMeghan 8927d2d
Update AutofillSnippets.kt
MagicalMeghan 77bd621
Update AutofillSnippets.kt
MagicalMeghan cfeb99f
Update AutofillSnippets.kt
MagicalMeghan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
compose/snippets/src/main/java/com/example/compose/snippets/text/AutofillSnippets.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* Copyright 2025 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 | ||
* | ||
* https://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 com.example.compose.snippets.text | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.text.LocalAutofillHighlightColor | ||
import androidx.compose.material3.TextField | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.autofill.ContentType | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalAutofillManager | ||
import androidx.compose.ui.semantics.contentType | ||
import androidx.compose.ui.semantics.semantics | ||
import androidx.compose.ui.text.input.TextFieldValue | ||
import androidx.compose.ui.unit.dp | ||
import com.example.compose.snippets.touchinput.Button | ||
|
||
@Composable | ||
fun AddAutofill() { | ||
var textFieldValue = remember { | ||
mutableStateOf(TextFieldValue("")) | ||
} | ||
// [START android_compose_autofill_1] | ||
TextField( | ||
value = textFieldValue.value, | ||
onValueChange = {textFieldValue.value = it}, | ||
modifier = Modifier.semantics { contentType = ContentType.Username } | ||
) | ||
// [END android_compose_autofill_1] | ||
} | ||
|
||
@Composable | ||
fun AddMultipleTypesOfAutofill() { | ||
var textFieldValue = remember { | ||
mutableStateOf(TextFieldValue("")) | ||
} | ||
// [START android_compose_autofill_2] | ||
TextField( | ||
value = textFieldValue.value, | ||
onValueChange = { textFieldValue.value = it }, | ||
modifier = Modifier.semantics { | ||
contentType = ContentType.Username + ContentType.EmailAddress | ||
} | ||
) | ||
// [END android_compose_autofill_2] | ||
} | ||
|
||
@Composable | ||
fun AutofillManager() { | ||
// [START android_compose_autofill_3] | ||
val autofillManager = LocalAutofillManager.current | ||
MagicalMeghan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// [END android_compose_autofill_3] | ||
} | ||
|
||
@Composable | ||
fun SaveDataWithAutofill() { | ||
var textFieldValue = remember { | ||
mutableStateOf(TextFieldValue("")) | ||
} | ||
// [START android_compose_autofill_4] | ||
val autofillManager = LocalAutofillManager.current | ||
|
||
Column { | ||
TextField( | ||
value = textFieldValue.value, | ||
onValueChange = { textFieldValue.value = it }, | ||
modifier = Modifier.semantics { contentType = ContentType.NewUsername } | ||
) | ||
|
||
Spacer(modifier = Modifier.height(16.dp)) | ||
MagicalMeghan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
TextField( | ||
value = textFieldValue.value, | ||
onValueChange = { textFieldValue.value = it }, | ||
modifier = Modifier.semantics { contentType = ContentType.NewPassword } | ||
) | ||
} | ||
// [END android_compose_autofill_4] | ||
} | ||
|
||
@Composable | ||
fun SaveDataWithAutofillOnClick() { | ||
var textFieldValue = remember { | ||
mutableStateOf(TextFieldValue("")) | ||
} | ||
// [START android_compose_autofill_5] | ||
val autofillManager = LocalAutofillManager.current | ||
|
||
Column { | ||
TextField( | ||
value = textFieldValue.value, | ||
onValueChange = { textFieldValue.value = it }, | ||
modifier = Modifier.semantics { contentType = ContentType.NewUsername }, | ||
) | ||
|
||
Spacer(modifier = Modifier.height(16.dp)) | ||
|
||
TextField( | ||
value = textFieldValue.value, | ||
onValueChange = { textFieldValue.value = it }, | ||
modifier = Modifier.semantics { contentType = ContentType.NewPassword }, | ||
) | ||
|
||
// Submit button | ||
Button(onClick = { autofillManager?.commit() }) { Text("Reset credentials") } | ||
} | ||
// [END android_compose_autofill_5] | ||
} | ||
|
||
@Composable | ||
fun CustomAutofillHighlight(customHighlightColor: Color = Color.Red) { | ||
var textFieldValue = remember { | ||
mutableStateOf(TextFieldValue("")) | ||
} | ||
// [START android_compose_autofill_6] | ||
val customHighlightColor = Color.Red | ||
|
||
CompositionLocalProvider(LocalAutofillHighlightColor provides customHighlightColor) { | ||
TextField( | ||
value = textFieldValue.value, | ||
onValueChange = { textFieldValue.value = it }, | ||
modifier = Modifier.semantics { contentType = ContentType.Username } | ||
) | ||
} | ||
// [END android_compose_autofill_6] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -23,7 +23,7 @@ androidxHiltNavigationCompose = "1.2.0" | |||||
coil = "2.7.0" | ||||||
# @keep | ||||||
compileSdk = "35" | ||||||
compose-latest = "1.7.6" | ||||||
compose-latest = "1.8.0-alpha08" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
composeUiTooling = "1.4.0" | ||||||
coreSplashscreen = "1.0.1" | ||||||
coroutines = "1.10.1" | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.