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
| val originalToTransformed = mutableListOf<Int>() | |
| val transformedToOriginal = mutableListOf<Int>() | |
| var specialCharsCount = 0 | |
| formatted?.forEachIndexed { index, char -> | |
| if (!PhoneNumberUtils.isNonSeparator(char)) { | |
| specialCharsCount++ | |
| } else { | |
| originalToTransformed.add(index) | |
| } | |
| transformedToOriginal.add(index - specialCharsCount) |
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
| s.forEachIndexed { index, char -> | |
| if (PhoneNumberUtils.isNonSeparator(char)) { | |
| if (lastNonSeparator.code != 0) { | |
| formatted = getFormattedNumber(lastNonSeparator, hasCursor) | |
| hasCursor = false | |
| } | |
| lastNonSeparator = char | |
| } | |
| if (index == curIndex) { | |
| hasCursor = true |
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
| private val countryCode: String = Locale.getDefault().country | |
| private val phoneNumberFormatter = PhoneNumberUtil.getInstance().getAsYouTypeFormatter(countryCode) | |
| private fun getFormattedNumber(lastNonSeparator: Char, hasCursor: Boolean): String? { | |
| return if (hasCursor) { | |
| phoneNumberFormatter.inputDigitAndRememberPosition(lastNonSeparator) | |
| } else { | |
| phoneNumberFormatter.inputDigit(lastNonSeparator) | |
| } | |
| } |
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
| TextField( | |
| modifier = modifier.fillMaxWidth(), | |
| text = text, | |
| hint = hint, | |
| singleLine = true, | |
| leadingIcon = null, | |
| visualTransformation = PhoneNumberVisualTransformation(), | |
| keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Phone) | |
| ) |
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
| // Making XXXX-XXXX-XXXX-XXXX string. | |
| val creditCardOffsetMapping = object : OffsetMapping { | |
| override fun originalToTransformed(offset: Int): Int { | |
| if (offset <= 3) return offset | |
| if (offset <= 7) return offset + 1 | |
| if (offset <= 11) return offset + 2 | |
| if (offset <= 16) return offset + 3 | |
| return 19 | |
| } |
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
| class PasswordVisualTransformation(val mask: Char = '\u2022') : VisualTransformation { | |
| override fun filter(text: AnnotatedString): TransformedText { | |
| return TransformedText( | |
| text = AnnotatedString(mask.toString().repeat(text.text.length)), | |
| offsetMapping = object : OffsetMapping { | |
| override fun originalToTransformed(offset: Int): Int = offset | |
| override fun transformedToOriginal(offset: Int): Int = offset | |
| } |
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
| fun interface VisualTransformation { | |
| fun filter(text: AnnotatedString): TransformedText | |
| companion object { | |
| @Stable | |
| val None: VisualTransformation = VisualTransformation { text -> | |
| TransformedText(text, OffsetMapping.Identity) | |
| } |
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
| class MyApplication : Application() { | |
| override fun onCreate() { | |
| super.onCreate() | |
| grantAssistantPermissions() | |
| } | |
| private fun grantAssistantPermissions() { | |
| getAssistantPackage()?.let { assistantPackage -> | |
| val sliceProviderUri = Uri.Builder() |
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
| class TodoProvider : SliceProvider() { | |
| override fun onCreateSliceProvider() = true | |
| override fun onBindSlice(sliceUri: Uri): Slice? { | |
| val context = context ?: return null | |
| val activityAction = createActivityAction() ?: return null | |
| return if (sliceUri.path == "/todo") { | |
| list(context, sliceUri, ListBuilder.INFINITY) { | |
| header { |
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
| class MyActivity : AppCompatActivity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| intent.handleIntent() | |
| } | |
| } | |
| private fun Intent.handleIntent() { | |
| when (action) { | |
| Intent.ACTION_VIEW -> controller.handleDeepLink(data) |
NewerOlder