blob: 26bec9ef0c2b8ae5dd9bcc3ea795040809194b26 [file]
/*
* Copyright (C) 2026 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 com.android.settings.binarytransparency
import android.content.Context
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.TtsSpan
import com.android.settings.R
/** Utility class for accessibility related operations. */
object AccessibilityUtils {
const val TAG = "AccessibilityUtils"
/**
* Returns the IMEI string with TTS spans for accessibility.
*
* @param context The context to get the string resources from.
* @param imei The IMEI string to be converted to a TTS span.
* @return The IMEI string with TTS spans for accessibility.
*/
fun getAccessibleImeiSummary(context: Context, imei: String): CharSequence {
val spannable = SpannableStringBuilder(imei)
val breakIndex = imei.indexOf('\n')
if (breakIndex != -1) {
spannable.setSpan(
TtsSpan.DigitsBuilder(imei.substring(0, breakIndex)).build(),
0,
breakIndex,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE,
)
val andConjunction = context.getString(R.string.and_conjunction)
spannable.setSpan(
TtsSpan.TextBuilder(andConjunction).build(),
breakIndex,
breakIndex + 1,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE,
)
spannable.setSpan(
TtsSpan.DigitsBuilder(imei.substring(breakIndex + 1)).build(),
breakIndex + 1,
spannable.length,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE,
)
} else {
spannable.setSpan(
TtsSpan.DigitsBuilder(imei).build(),
0,
spannable.length,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE,
)
}
return spannable
}
}