Fix Glance title's alignment on RTL when the title string is RTL

Co-authored-by: Daria Hamrah Paytakht <info@dariarnd.ir>
Co-authored-by: Fateme Maleki <f.maleki@ddariahamrah.ir>
This commit is contained in:
Yasan Ghaffarian
2022-06-20 12:04:41 +04:30
parent 4b476a8f01
commit 50ad8182b3
2 changed files with 11 additions and 3 deletions

View File

@@ -129,8 +129,9 @@ class BcSmartspaceCard @JvmOverloads constructor(
fun setTitle(title: CharSequence?, contentDescription: CharSequence?, hasIcon: Boolean) {
val titleView = titleTextView ?: return
val isRTL = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL
titleView.textAlignment = if (isRTL) TEXT_ALIGNMENT_TEXT_END else TEXT_ALIGNMENT_TEXT_START
val isRtlLayout = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL
val isRtlText = isStringRTL(title.toString())
titleView.textAlignment = if (isRtlLayout && !isRtlText) TEXT_ALIGNMENT_TEXT_END else TEXT_ALIGNMENT_TEXT_START
titleView.text = title
titleView.setCompoundDrawablesRelative(
if (hasIcon) iconDrawable else null, null,
@@ -148,6 +149,14 @@ class BcSmartspaceCard @JvmOverloads constructor(
}
}
private fun isStringRTL(string: String): Boolean {
if (TextUtils.isEmpty(string)) {
return false
}
val c = string[0]
return c.code in 0x590..0x6ff
}
private fun setSubtitle(subtitle: CharSequence?, charSequence2: CharSequence?) {
val subtitleView = subtitleTextView ?: return
subtitleView.text = subtitle

View File

@@ -61,7 +61,6 @@ class IcuDateTextView @JvmOverloads constructor(
if (isShown) {
val timeText = getTimeText(updateFormatter)
if (text != timeText) {
textAlignment = if (shouldAlignToTextEnd()) TEXT_ALIGNMENT_TEXT_END else TEXT_ALIGNMENT_TEXT_START
text = timeText
contentDescription = timeText
}