diff --git a/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java b/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java index 35873460f66a..f7f2cf4f0371 100644 --- a/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java +++ b/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java @@ -4,6 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.mozilla.gecko.util; +import android.annotation.TargetApi; import android.content.res.TypedArray; import android.os.Build; import android.support.v4.text.TextUtilsCompat; @@ -11,6 +12,7 @@ import android.support.v4.view.MarginLayoutParamsCompat; import android.support.v4.view.ViewCompat; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import org.mozilla.gecko.AppConstants; import org.mozilla.gecko.R; @@ -72,4 +74,25 @@ public class ViewUtil { break; } } + + /** + * RTL compatibility wrapper to force set TextDirection for JB mr1 and above + * + * @param textView + * @param isRtl + */ + public static void setTextDirectionRtlCompat(TextView textView, boolean isRtl) { + if (AppConstants.Versions.feature17Plus) { + setTextDirectionRtlCompat17(textView, isRtl); + } + } + + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) + private static void setTextDirectionRtlCompat17(TextView textView, boolean isRtl) { + if (isRtl) { + textView.setTextDirection(View.TEXT_DIRECTION_RTL); + } else { + textView.setTextDirection(View.TEXT_DIRECTION_LTR); + } + } } diff --git a/mobile/android/base/java/org/mozilla/gecko/widget/FadedSingleColorTextView.java b/mobile/android/base/java/org/mozilla/gecko/widget/FadedSingleColorTextView.java index 012300f1c6ec..6d6acc737aa5 100644 --- a/mobile/android/base/java/org/mozilla/gecko/widget/FadedSingleColorTextView.java +++ b/mobile/android/base/java/org/mozilla/gecko/widget/FadedSingleColorTextView.java @@ -10,9 +10,12 @@ import android.graphics.Canvas; import android.graphics.LinearGradient; import android.graphics.Shader; import android.support.v4.text.BidiFormatter; +import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; +import org.mozilla.gecko.util.ViewUtil; + /** * Fades the end of the text by gecko:fadeWidth amount, * if the text is too long and requires an ellipsis. @@ -49,10 +52,14 @@ public class FadedSingleColorTextView extends FadedTextView { @Override public void setText(CharSequence text, BufferType type) { super.setText(text, type); - mIsTextDirectionRtl = BidiFormatter.getInstance().isRtl((String) text); - if (mIsTextDirectionRtl) { - setTextDirection(TEXT_DIRECTION_RTL); + final boolean previousTextDirectionRtl = mIsTextDirectionRtl; + if (!TextUtils.isEmpty(text)) { + mIsTextDirectionRtl = BidiFormatter.getInstance().isRtl((String) text); } + if (mIsTextDirectionRtl != previousTextDirectionRtl) { + mTextGradient = null; + } + ViewUtil.setTextDirectionRtlCompat(this, mIsTextDirectionRtl); } @Override