Unicode wrap subject and snippet in convo list.

Fixes b/5987892.

Change-Id: Iaff34c3ca725dd3023a53ba30b916db6fa571232
diff --git a/src/com/android/mail/browse/ConversationItemView.java b/src/com/android/mail/browse/ConversationItemView.java
index ac991a0..7c8c8da 100644
--- a/src/com/android/mail/browse/ConversationItemView.java
+++ b/src/com/android/mail/browse/ConversationItemView.java
@@ -36,6 +36,7 @@
 import android.graphics.Typeface;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.InsetDrawable;
+import android.support.v4.text.BidiFormatter;
 import android.support.v4.view.ViewCompat;
 import android.text.Layout.Alignment;
 import android.text.Spannable;
@@ -1036,11 +1037,14 @@
     private void createSubject(final boolean isUnread) {
         // Need to check if we're in wide mode because the badge
         // does not get added if we're in wide mode.
-        final String badgeText = mCoordinates.isWideMode() ? "" : mHeader.badgeText;
-        final String subject = filterTag(mHeader.conversation.subject);
-        final String snippet = mHeader.conversation.getSnippet();
+        final BidiFormatter bidiFormatter = mAdapter.getBidiFormatter();
+        final String badgeText = mCoordinates.isWideMode() || mHeader.badgeText == null ? "" :
+                bidiFormatter.unicodeWrap(mHeader.badgeText);
+        final String subject = bidiFormatter.unicodeWrap(filterTag(mHeader.conversation.subject));
+        final String snippet = bidiFormatter.unicodeWrap(mHeader.conversation.getSnippet());
         final Spannable displayedStringBuilder = new SpannableString(
-                Conversation.getSubjectAndSnippetForDisplay(mContext, badgeText, subject, snippet));
+                Conversation.getSubjectAndSnippetForDisplay(
+                        mContext, badgeText, subject, snippet));
 
         // since spans affect text metrics, add spans to the string before measure/layout or fancy
         // ellipsizing
diff --git a/src/com/android/mail/providers/Conversation.java b/src/com/android/mail/providers/Conversation.java
index 26d5506..a9692e9 100644
--- a/src/com/android/mail/providers/Conversation.java
+++ b/src/com/android/mail/providers/Conversation.java
@@ -855,9 +855,6 @@
      */
     public static String getSubjectAndSnippetForDisplay(Context context,
             String badgeText, String filteredSubject, String snippet) {
-        if (sSubjectAndSnippet == null) {
-            sSubjectAndSnippet = context.getString(R.string.subject_and_snippet);
-        }
         if (TextUtils.isEmpty(filteredSubject) && TextUtils.isEmpty(snippet)) {
             return "";
         } else if (TextUtils.isEmpty(filteredSubject)) {
@@ -871,6 +868,10 @@
             return String.format(sBadgeSubjectAndSnippet, badgeText, filteredSubject, snippet);
         }
 
+        if (sSubjectAndSnippet == null) {
+            sSubjectAndSnippet = context.getString(R.string.subject_and_snippet);
+        }
+
         return String.format(sSubjectAndSnippet, filteredSubject, snippet);
     }
 
diff --git a/src/com/android/mail/ui/AnimatedAdapter.java b/src/com/android/mail/ui/AnimatedAdapter.java
index d898fc1..0ca0448 100644
--- a/src/com/android/mail/ui/AnimatedAdapter.java
+++ b/src/com/android/mail/ui/AnimatedAdapter.java
@@ -28,6 +28,7 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
+import android.support.v4.text.BidiFormatter;
 import android.util.SparseArray;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -196,6 +197,8 @@
      */
     private final List<ConversationSpecialItemView> mFleetingViews;
 
+    private final BidiFormatter mBidiFormatter = BidiFormatter.getInstance();
+
     /**
      * @return <code>true</code> if a relevant part of the account has changed, <code>false</code>
      *         otherwise
@@ -650,6 +653,10 @@
         return mCoordinatesCache;
     }
 
+    public BidiFormatter getBidiFormatter() {
+        return mBidiFormatter;
+    }
+
     public SwipeableListView getListView() {
         return mListView;
     }
diff --git a/src/com/android/mail/widget/WidgetConversationListItemViewBuilder.java b/src/com/android/mail/widget/WidgetConversationListItemViewBuilder.java
index ea8ec90..29cd006 100644
--- a/src/com/android/mail/widget/WidgetConversationListItemViewBuilder.java
+++ b/src/com/android/mail/widget/WidgetConversationListItemViewBuilder.java
@@ -21,8 +21,10 @@
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.Typeface;
+import android.support.v4.text.BidiFormatter;
 import android.text.Spannable;
 import android.text.SpannableStringBuilder;
+import android.text.TextUtils;
 import android.text.style.AbsoluteSizeSpan;
 import android.text.style.ForegroundColorSpan;
 import android.text.style.StyleSpan;
@@ -49,6 +51,7 @@
     private static Bitmap ATTACHMENT;
 
     private final Context mContext;
+
     private WidgetFolderDisplayer mFolderDisplayer;
 
     /**
@@ -148,7 +151,7 @@
      */
     public RemoteViews getStyledView(final CharSequence date, final Conversation conversation,
             final FolderUri folderUri, final int ignoreFolderType,
-            final SpannableStringBuilder senders, final String filteredSubject) {
+            final SpannableStringBuilder senders, final String subject) {
 
         final boolean isUnread = !conversation.read;
         final String snippet = conversation.getSnippet();
@@ -159,9 +162,13 @@
 
         // Add style to subject
         final int subjectColor = isUnread ? SUBJECT_TEXT_COLOR_UNREAD : SUBJECT_TEXT_COLOR_READ;
+        final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
+        final String filteredSubject =
+                TextUtils.isEmpty(subject) ? "" : bidiFormatter.unicodeWrap(subject);
         final SpannableStringBuilder subjectAndSnippet = new SpannableStringBuilder(
                 Conversation.getSubjectAndSnippetForDisplay(
-                        mContext, null /* badgeText */, filteredSubject, snippet));
+                        mContext, null /* badgeText */, filteredSubject,
+                        bidiFormatter.unicodeWrap(snippet)));
         if (isUnread) {
             subjectAndSnippet.setSpan(new StyleSpan(Typeface.BOLD), 0, filteredSubject.length(),
                     Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
diff --git a/src/com/android/mail/widget/WidgetService.java b/src/com/android/mail/widget/WidgetService.java
index e35ec24..8b18222 100644
--- a/src/com/android/mail/widget/WidgetService.java
+++ b/src/com/android/mail/widget/WidgetService.java
@@ -437,21 +437,6 @@
             }
         }
 
-        private CharacterStyle getUnreadStyle() {
-            if (mUnreadStyle == null) {
-                mUnreadStyle = new TextAppearanceSpan(mContext,
-                        R.style.SendersUnreadTextAppearance);
-            }
-            return CharacterStyle.wrap(mUnreadStyle);
-        }
-
-        private CharacterStyle getReadStyle() {
-            if (mReadStyle == null) {
-                mReadStyle = new TextAppearanceSpan(mContext, R.style.SendersReadTextAppearance);
-            }
-            return CharacterStyle.wrap(mReadStyle);
-        }
-
         private SpannableStringBuilder ellipsizeStyledSenders(
                 ArrayList<SpannableString> styledSenders) {
             SpannableStringBuilder builder = new SpannableStringBuilder();