Bug 1331995 - Reset text direction to locale in order to reveal text hint, r=sebastian draft
authormaliu <max@mxli.us>
Wed, 01 Mar 2017 14:04:52 +0800
changeset 490819 564ed5df5a5800a89d112430adbdb24f2c491878
parent 490433 1bc2ad020aee2830e0a7941f10958dbec108c254
child 490885 ef5ad67cd289b3fe1fc68571564661a2faa65312
push id47235
push userbmo:max@mxli.us
push dateWed, 01 Mar 2017 09:58:58 +0000
reviewerssebastian
bugs1331995
milestone54.0a1
Bug 1331995 - Reset text direction to locale in order to reveal text hint, r=sebastian MozReview-Commit-ID: I1FIL7QDRSu
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
@@ -21,16 +21,17 @@ import org.mozilla.gecko.SiteIdentity.Tr
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.animation.PropertyAnimator;
 import org.mozilla.gecko.animation.ViewHelper;
 import org.mozilla.gecko.toolbar.BrowserToolbarTabletBase.ForwardButtonAnimation;
 import org.mozilla.gecko.Experiments;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.StringUtils;
+import org.mozilla.gecko.util.ViewUtil;
 import org.mozilla.gecko.widget.themed.ThemedLinearLayout;
 import org.mozilla.gecko.widget.themed.ThemedTextView;
 
 import android.content.Context;
 import android.os.SystemClock;
 import android.support.annotation.NonNull;
 import android.support.v4.view.ViewCompat;
 import android.text.Spannable;
@@ -240,16 +241,24 @@ public class ToolbarDisplayLayout extend
         if (flags.contains(UpdateFlags.PRIVATE_MODE)) {
             mTitle.setPrivateMode(tab.isPrivate());
         }
     }
 
     void setTitle(CharSequence title) {
         mTitle.setText(title);
 
+        if (TextUtils.isEmpty(title)) {
+            //  Reset TextDirection to Locale in order to reveal text hint in correct direction
+            ViewUtil.setTextDirection(mTitle, TEXT_DIRECTION_LOCALE);
+        } else {
+            //  Otherwise, fall back to default first strong strategy
+            ViewUtil.setTextDirection(mTitle, TEXT_DIRECTION_FIRST_STRONG);
+        }
+
         if (mTitleChangeListener != null) {
             mTitleChangeListener.onTitleChange(title);
         }
     }
 
     private void updateTitle(@NonNull Tab tab) {
         // Keep the title unchanged if there's no selected tab,
         // or if the tab is entering reader mode.
--- a/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java
+++ b/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java
@@ -160,17 +160,28 @@ public class ViewUtil {
             case ViewCompat.LAYOUT_DIRECTION_LTR:
             default:
                 ViewCompat.setLayoutDirection(view, ViewCompat.LAYOUT_DIRECTION_LTR);
                 break;
         }
     }
 
     /**
-     * RTL compatibility wrapper to force set TextDirection for JB mr1 and above
+     * RTL compatibility wrapper to set TextDirection
+     * @param textView
+     * @param textDirection
+     */
+    public static void setTextDirection(TextView textView, int textDirection) {
+        if(AppConstants.Versions.feature17Plus) {
+            textView.setTextDirection(textDirection);
+        }
+    }
+
+    /**
+     * RTL compatibility wrapper to force set TextDirection as RTL for JB mr1 and above
      *
      * @param textView
      * @param isRtl
      */
     public static void setTextDirectionRtlCompat(TextView textView, boolean isRtl) {
         if (AppConstants.Versions.feature17Plus) {
             setTextDirectionRtlCompat17(textView, isRtl);
         }