make sure we properly represent quoted text in drafts.

Change-Id: I86c0c09541e20d65bb3a91be9bbd229fe7c8fb1f
diff --git a/src/com/android/mail/compose/ComposeActivity.java b/src/com/android/mail/compose/ComposeActivity.java
index 6324686..d038a7b 100644
--- a/src/com/android/mail/compose/ComposeActivity.java
+++ b/src/com/android/mail/compose/ComposeActivity.java
@@ -803,12 +803,28 @@
                 addAttachmentAndUpdateView(a);
             }
         }
-
+        int quotedTextIndex = message.appendRefMessageContent && !mForward ?
+                message.quotedTextOffset : -1;
         // Set the body
+        CharSequence quotedText = null;
         if (!TextUtils.isEmpty(message.bodyHtml)) {
-            mBodyView.setText(Html.fromHtml(message.bodyHtml));
+            CharSequence htmlText = Html.fromHtml(message.bodyHtml);
+            if (quotedTextIndex > -1) {
+                htmlText = htmlText.subSequence(0, quotedTextIndex);
+                quotedText = message.bodyHtml.subSequence(quotedTextIndex,
+                        message.bodyHtml.length());
+            }
+            mBodyView.setText(htmlText);
         } else {
-            mBodyView.setText(message.bodyText);
+            CharSequence bodyText = quotedTextIndex > -1 ?
+                    message.bodyText.substring(0, quotedTextIndex) : message.bodyText;
+            if (quotedTextIndex > -1) {
+                quotedText = message.bodyText.substring(quotedTextIndex);
+            }
+            mBodyView.setText(bodyText);
+        }
+        if (quotedTextIndex > -1 && quotedText != null) {
+            mQuotedTextView.setQuotedTextFromDraft(quotedText);
         }
     }
 
@@ -1826,21 +1842,7 @@
                 fullBody.append(text);
             }
         }
-        int draftType = -1;
-        switch (composeMode) {
-            case ComposeActivity.COMPOSE:
-                draftType = DraftType.COMPOSE;
-                break;
-            case ComposeActivity.REPLY:
-                draftType = DraftType.REPLY;
-                break;
-            case ComposeActivity.REPLY_ALL:
-                draftType = DraftType.REPLY_ALL;
-                break;
-            case ComposeActivity.FORWARD:
-                draftType = DraftType.FORWARD;
-                break;
-        }
+        int draftType = getDraftType(composeMode);
         MessageModification.putDraftType(values, draftType);
         if (refMessage != null) {
             if (!TextUtils.isEmpty(refMessage.bodyHtml)) {
@@ -1871,6 +1873,25 @@
         return sendOrSaveMessage.requestId();
     }
 
+    private static int getDraftType(int mode) {
+        int draftType = -1;
+        switch (mode) {
+            case ComposeActivity.COMPOSE:
+                draftType = DraftType.COMPOSE;
+                break;
+            case ComposeActivity.REPLY:
+                draftType = DraftType.REPLY;
+                break;
+            case ComposeActivity.REPLY_ALL:
+                draftType = DraftType.REPLY_ALL;
+                break;
+            case ComposeActivity.FORWARD:
+                draftType = DraftType.FORWARD;
+                break;
+        }
+        return draftType;
+    }
+
     private void sendOrSave(Spanned body, boolean save, boolean showToast,
             boolean orientationChanged) {
         // Check if user is a monkey. Monkeys can compose and hit send
diff --git a/src/com/android/mail/compose/QuotedTextView.java b/src/com/android/mail/compose/QuotedTextView.java
index 5337ca4..58a8e41 100644
--- a/src/com/android/mail/compose/QuotedTextView.java
+++ b/src/com/android/mail/compose/QuotedTextView.java
@@ -294,6 +294,15 @@
         allowRespondInline(true);
     }
 
+    public void setQuotedTextFromDraft(CharSequence htmlText) {
+        setVisibility(View.VISIBLE);
+        setQuotedText(htmlText);
+        allowQuotedText(true);
+        // If there is quoted text, we always allow respond inline, since this
+        // may be a forward.
+        allowRespondInline(true);
+    }
+
     /**
      * Set quoted text. Some use cases may not want to display the check box (i.e. forwarding) so
      * allow control of that.