Moving dependencies of PhoneFavoriteFragment.

Move common classes from Contacts to Contacts Common.

Bug: 6993891
Change-Id: Idd0b3115df810090340d1b10b04eb698d5facfb6
diff --git a/src/com/android/contacts/common/format/SpannedTestUtils.java b/src/com/android/contacts/common/format/SpannedTestUtils.java
new file mode 100644
index 0000000..8c2a22d
--- /dev/null
+++ b/src/com/android/contacts/common/format/SpannedTestUtils.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.contacts.common.format;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import android.text.Html;
+import android.text.Spanned;
+import android.text.TextUtils;
+import android.text.style.ForegroundColorSpan;
+import android.widget.TextView;
+
+import junit.framework.Assert;
+
+/**
+ * Utility class to check the value of spanned text in text views.
+ */
+@SmallTest
+public class SpannedTestUtils {
+    /**
+     * Checks that the text contained in the text view matches the given HTML text.
+     *
+     * @param expectedHtmlText the expected text to be in the text view
+     * @param textView the text view from which to get the text
+     */
+    public static void checkHtmlText(String expectedHtmlText, TextView textView) {
+        String actualHtmlText = Html.toHtml((Spanned) textView.getText());
+        if (TextUtils.isEmpty(expectedHtmlText)) {
+            // If the text is empty, it does not add the <p></p> bits to it.
+            Assert.assertEquals("", actualHtmlText);
+        } else {
+            Assert.assertEquals("<p dir=ltr>" + expectedHtmlText + "</p>\n", actualHtmlText);
+        }
+    }
+
+
+    /**
+     * Assert span exists in the correct location.
+     *
+     * @param seq The spannable string to check.
+     * @param start The starting index.
+     * @param end The ending index.
+     */
+    public static void assertPrefixSpan(CharSequence seq, int start, int end) {
+        Assert.assertTrue(seq instanceof Spanned);
+        Spanned spannable = (Spanned) seq;
+
+        if (start > 0) {
+            Assert.assertEquals(0, getNumForegroundColorSpansBetween(spannable, 0, start - 1));
+        }
+        Assert.assertEquals(1, getNumForegroundColorSpansBetween(spannable, start, end));
+        Assert.assertEquals(0, getNumForegroundColorSpansBetween(spannable, end + 1,
+                spannable.length() - 1));
+    }
+
+    private static int getNumForegroundColorSpansBetween(Spanned value, int start, int end) {
+        return value.getSpans(start, end, ForegroundColorSpan.class).length;
+    }
+
+    /**
+     * Asserts that the given character sequence is not a Spanned object and text is correct.
+     *
+     * @param seq The sequence to check.
+     * @param expected The expected text.
+     */
+    public static void assertNotSpanned(CharSequence seq, String expected) {
+        Assert.assertFalse(seq instanceof Spanned);
+        Assert.assertEquals(expected, seq);
+    }
+}