mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-14 08:08:21 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user