From 87bc65c9e41f45735de578665e33d0a2a65f00b5 Mon Sep 17 00:00:00 2001 From: menghanli Date: Tue, 25 Apr 2023 13:34:51 +0800 Subject: [PATCH] Fix the gradient drawable orientation is not mirrored for RTL alignment Root cause: The orientation of the gradient drawable follows the view alignment. It should consider the text alignment. Solution: Use getLayoutDirectionFromLocale# to get the text alignment to set the correct orientation of the gradient drawable. Bug: 278950655 Test: Manual test for RTL and LTR language Change-Id: If94af75172ace137ac5168763f4cb47951f9e943 Merged-In: If94af75172ace137ac5168763f4cb47951f9e943 (cherry picked from commit 95fbb04106d084aa8fa5753a7f19971a19693765) --- .../settings/accessibility/PaletteListPreference.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/accessibility/PaletteListPreference.java b/src/com/android/settings/accessibility/PaletteListPreference.java index 4e10b936485..eec8b5a6cde 100644 --- a/src/com/android/settings/accessibility/PaletteListPreference.java +++ b/src/com/android/settings/accessibility/PaletteListPreference.java @@ -34,6 +34,7 @@ import android.widget.TextView; import androidx.annotation.ColorInt; import androidx.annotation.IntDef; +import androidx.core.text.TextUtilsCompat; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; @@ -49,6 +50,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Locale; import java.util.stream.Collectors; /** Preference that easier preview by matching name to color. */ @@ -156,10 +158,11 @@ public final class PaletteListPreference extends Preference { mGradientColors.set(Position.END, color); final GradientDrawable gradientDrawable = new GradientDrawable(); + final Locale locale = Locale.getDefault(); final Orientation orientation = - rootView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL - ? Orientation.RIGHT_LEFT - : Orientation.LEFT_RIGHT; + TextUtilsCompat.getLayoutDirectionFromLocale(locale) == View.LAYOUT_DIRECTION_RTL + ? Orientation.RIGHT_LEFT + : Orientation.LEFT_RIGHT; gradientDrawable.setOrientation(orientation); gradientDrawable.setColors(Ints.toArray(mGradientColors), Floats.toArray(mGradientOffsets));