Merge "Import translations. DO NOT MERGE" into jb-mr1.1-dev
diff --git a/res/values-rm/strings.xml b/res/values-rm/strings.xml
index 69b0b40..513e527 100644
--- a/res/values-rm/strings.xml
+++ b/res/values-rm/strings.xml
@@ -833,7 +833,9 @@
     <skip />
     <!-- no translation found for add_new_account (5748627740680940264) -->
     <skip />
-    <string name="dialog_phone_call_prohibited_message" msgid="6554711866586660441">"Il clom n\'è betg vegnì exequì."</string>
+    <!-- no translation found for dialog_phone_call_prohibited_message (6554711866586660441) -->
+    <!-- no translation found for dialog_phone_call_prohibited_message (4313552620858880999) -->
+    <skip />
     <!-- no translation found for dialog_voicemail_not_ready_message (4384716252789515378) -->
     <skip />
     <!-- no translation found for dialog_voicemail_airplane_mode_message (530922773669546093) -->
diff --git a/src/com/android/contacts/detail/ContactDetailFragment.java b/src/com/android/contacts/detail/ContactDetailFragment.java
index 3dfaf8d..3773bda 100644
--- a/src/com/android/contacts/detail/ContactDetailFragment.java
+++ b/src/com/android/contacts/detail/ContactDetailFragment.java
@@ -1862,6 +1862,11 @@
         menu.add(ContextMenu.NONE, ContextMenuIds.COPY_TEXT,
                 ContextMenu.NONE, getString(R.string.copy_text));
 
+        // Don't allow setting or clearing of defaults for directory contacts
+        if (mContactData.isDirectoryEntry()) {
+            return;
+        }
+
         String selectedMimeType = selectedEntry.mimetype;
 
         // Defaults to true will only enable the detail to be copied to the clipboard.
diff --git a/src/com/android/contacts/list/ContactBrowseListFragment.java b/src/com/android/contacts/list/ContactBrowseListFragment.java
index 3e8e4a3..09b6d42 100644
--- a/src/com/android/contacts/list/ContactBrowseListFragment.java
+++ b/src/com/android/contacts/list/ContactBrowseListFragment.java
@@ -490,8 +490,15 @@
                 mSelectionRequired = false;
 
                 // If we were looking at a different specific contact, just reload
+                // FILTER_TYPE_ALL_ACCOUNTS is needed for the case where a new contact is added
+                // on a tablet and the loader is returning a stale list.  In this case, the contact
+                // will not be found until the next load. b/7621855 This will only fix the most
+                // common case where all accounts are shown. It will not fix the one account case.
+                // TODO: we may want to add more FILTER_TYPEs or relax this check to fix all other
+                // FILTER_TYPE cases.
                 if (mFilter != null
-                        && mFilter.filterType == ContactListFilter.FILTER_TYPE_SINGLE_CONTACT) {
+                        && (mFilter.filterType == ContactListFilter.FILTER_TYPE_SINGLE_CONTACT
+                        || mFilter.filterType == ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS)) {
                     reloadData();
                 } else {
                     // Otherwise, call the listener, which will adjust the filter.
diff --git a/tests/src/com/android/contacts/format/PrefixHighligherTest.java b/tests/src/com/android/contacts/format/PrefixHighligherTest.java
index 668330b..7f6e491 100644
--- a/tests/src/com/android/contacts/format/PrefixHighligherTest.java
+++ b/tests/src/com/android/contacts/format/PrefixHighligherTest.java
@@ -16,77 +16,70 @@
 
 package com.android.contacts.format;
 
-import android.test.AndroidTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
-import android.widget.TextView;
+
+import junit.framework.TestCase;
 
 /**
  * Unit tests for {@link PrefixHighlighter}.
  */
 @SmallTest
-public class PrefixHighligherTest extends AndroidTestCase {
+public class PrefixHighligherTest extends TestCase {
     private static final int TEST_PREFIX_HIGHLIGHT_COLOR = 0xFF0000;
-    /** The HTML code used to mark the start of the highlighted part. */
-    private static final String START = "<font color =\"#1ff0000\">";
-    /** The HTML code used to mark the end of the highlighted part. */
-    private static final String END = "</font>";
 
     /** The object under test. */
     private PrefixHighlighter mPrefixHighlighter;
-    /** The view to on which the text is set. */
-    private TextView mView;
 
     @Override
     protected void setUp() throws Exception {
         super.setUp();
         mPrefixHighlighter = new PrefixHighlighter(TEST_PREFIX_HIGHLIGHT_COLOR);
-        mView = new TextView(getContext());
-        // This guarantees that the text will be stored as a spannable so that we can determine
-        // which styles have been applied to it.
-        mView.setText("", TextView.BufferType.SPANNABLE);
     }
 
-    public void testSetText_EmptyPrefix() {
-        mPrefixHighlighter.setText(mView, "", new char[0]);
-        SpannedTestUtils.checkHtmlText("", mView);
+    public void testApply_EmptyPrefix() {
+        CharSequence seq = mPrefixHighlighter.apply("", new char[0]);
+        SpannedTestUtils.assertNotSpanned(seq, "");
 
-        mPrefixHighlighter.setText(mView, "test", new char[0]);
-        SpannedTestUtils.checkHtmlText("test", mView);
+        seq = mPrefixHighlighter.apply("test", new char[0]);
+        SpannedTestUtils.assertNotSpanned(seq, "test");
     }
 
     public void testSetText_MatchingPrefix() {
-        mPrefixHighlighter.setText(mView, "test", "TE".toCharArray());
-        SpannedTestUtils.checkHtmlText(START + "te" + END + "st", mView);
+        final char[] charArray = "TE".toCharArray();
 
-        mPrefixHighlighter.setText(mView, "Test", "TE".toCharArray());
-        SpannedTestUtils.checkHtmlText(START + "Te" + END + "st", mView);
+        CharSequence seq = mPrefixHighlighter.apply("test", charArray);
+        SpannedTestUtils.assertPrefixSpan(seq, 0, 1);
 
-        mPrefixHighlighter.setText(mView, "TEst", "TE".toCharArray());
-        SpannedTestUtils.checkHtmlText(START + "TE" + END + "st", mView);
+        seq = mPrefixHighlighter.apply("Test", charArray);
+        SpannedTestUtils.assertPrefixSpan(seq, 0, 1);
 
-        mPrefixHighlighter.setText(mView, "a test", "TE".toCharArray());
-        SpannedTestUtils.checkHtmlText("a " + START + "te" + END + "st", mView);
+        seq = mPrefixHighlighter.apply("TEst", charArray);
+        SpannedTestUtils.assertPrefixSpan(seq, 0, 1);
+
+        seq = mPrefixHighlighter.apply("a test", charArray);
+        SpannedTestUtils.assertPrefixSpan(seq, 2, 3);
     }
 
     public void testSetText_NotMatchingPrefix() {
-        mPrefixHighlighter.setText(mView, "test", "TA".toCharArray());
-        SpannedTestUtils.checkHtmlText("test", mView);
+        final CharSequence seq = mPrefixHighlighter.apply("test", "TA".toCharArray());
+        SpannedTestUtils.assertNotSpanned(seq, "test");
     }
 
     public void testSetText_FirstMatch() {
-        mPrefixHighlighter.setText(mView, "a test's tests are not tests", "TE".toCharArray());
-        SpannedTestUtils.checkHtmlText("a " +START + "te" + END + "st's tests are not tests",
-                mView);
+        final CharSequence seq = mPrefixHighlighter.apply("a test's tests are not tests",
+                "TE".toCharArray());
+        SpannedTestUtils.assertPrefixSpan(seq, 2, 3);
     }
 
     public void testSetText_NoMatchingMiddleOfWord() {
-        mPrefixHighlighter.setText(mView, "atest", "TE".toCharArray());
-        SpannedTestUtils.checkHtmlText("atest", mView);
+        final char[] charArray = "TE".toCharArray();
+        CharSequence seq = mPrefixHighlighter.apply("atest", charArray);
+        SpannedTestUtils.assertNotSpanned(seq, "atest");
 
-        mPrefixHighlighter.setText(mView, "atest otest", "TE".toCharArray());
-        SpannedTestUtils.checkHtmlText("atest otest", mView);
+        seq = mPrefixHighlighter.apply("atest otest", charArray);
+        SpannedTestUtils.assertNotSpanned(seq, "atest otest");
 
-        mPrefixHighlighter.setText(mView, "atest test", "TE".toCharArray());
-        SpannedTestUtils.checkHtmlText("atest " + START + "te" + END + "st", mView);
+        seq = mPrefixHighlighter.apply("atest test", charArray);
+        SpannedTestUtils.assertPrefixSpan(seq, 6, 7);
     }
 }
diff --git a/tests/src/com/android/contacts/format/SpannedTestUtils.java b/tests/src/com/android/contacts/format/SpannedTestUtils.java
index ce228a7..6fa028d 100644
--- a/tests/src/com/android/contacts/format/SpannedTestUtils.java
+++ b/tests/src/com/android/contacts/format/SpannedTestUtils.java
@@ -20,6 +20,7 @@
 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;
@@ -45,4 +46,38 @@
         }
     }
 
+
+    /**
+     * 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);
+    }
 }
diff --git a/tests/src/com/android/contacts/list/ContactListItemViewTest.java b/tests/src/com/android/contacts/list/ContactListItemViewTest.java
index 748876f..7847ebb 100644
--- a/tests/src/com/android/contacts/list/ContactListItemViewTest.java
+++ b/tests/src/com/android/contacts/list/ContactListItemViewTest.java
@@ -21,12 +21,15 @@
 import android.provider.ContactsContract;
 import android.test.ActivityInstrumentationTestCase2;
 import android.test.suitebuilder.annotation.LargeTest;
+import android.text.SpannableString;
+import android.text.Spanned;
 import android.widget.TextView;
 
 import com.android.contacts.activities.PeopleActivity;
 import com.android.contacts.format.SpannedTestUtils;
 import com.android.contacts.util.IntegrationTestUtils;
 
+
 /**
  * Unit tests for {@link ContactListItemView}.
  *
@@ -66,7 +69,7 @@
 
         view.showDisplayName(cursor, 0, ContactsContract.Preferences.DISPLAY_ORDER_PRIMARY);
 
-        SpannedTestUtils.checkHtmlText("John Doe", view.getNameTextView());
+        assertEquals(view.getNameTextView().getText().toString(), "John Doe");
     }
 
     public void testShowDisplayName_Unknown() {
@@ -76,7 +79,7 @@
         view.setUnknownNameText("unknown");
         view.showDisplayName(cursor, 0, ContactsContract.Preferences.DISPLAY_ORDER_PRIMARY);
 
-        SpannedTestUtils.checkHtmlText("unknown", view.getNameTextView());
+        assertEquals(view.getNameTextView().getText().toString(), "unknown");
     }
 
     public void testShowDisplayName_WithPrefix() {
@@ -86,8 +89,9 @@
         view.setHighlightedPrefix("DOE".toCharArray());
         view.showDisplayName(cursor, 0, ContactsContract.Preferences.DISPLAY_ORDER_PRIMARY);
 
-        SpannedTestUtils.checkHtmlText("John " + START + "Doe" + END,
-                view.getNameTextView());
+        CharSequence seq = view.getNameTextView().getText();
+        assertEquals("John Doe", seq.toString());
+        SpannedTestUtils.assertPrefixSpan(seq, 5, 7);
     }
 
     public void testShowDisplayName_WithPrefixReversed() {
@@ -97,16 +101,20 @@
         view.setHighlightedPrefix("DOE".toCharArray());
         view.showDisplayName(cursor, 0, ContactsContract.Preferences.DISPLAY_ORDER_ALTERNATIVE);
 
-        SpannedTestUtils.checkHtmlText("John " + START + "Doe" + END,
-                view.getNameTextView());
+        CharSequence seq = view.getNameTextView().getText();
+        assertEquals("John Doe", seq.toString());
+        SpannedTestUtils.assertPrefixSpan(seq, 5, 7);
     }
 
     public void testSetSnippet_Prefix() {
         ContactListItemView view = createView();
         view.setHighlightedPrefix("TEST".toCharArray());
         view.setSnippet("This is a test");
-        SpannedTestUtils.checkHtmlText("This is a " + START + "test" + END,
-                view.getSnippetView());
+
+        CharSequence seq = view.getSnippetView().getText();
+
+        assertEquals("This is a test", seq.toString());
+        SpannedTestUtils.assertPrefixSpan(seq, 10, 13);
     }
 
     /** Creates the view to be tested. */
diff --git a/tests/src/com/android/contacts/util/BitmapUtilTests.java b/tests/src/com/android/contacts/util/BitmapUtilTests.java
index 554fc97..8180b7c 100644
--- a/tests/src/com/android/contacts/util/BitmapUtilTests.java
+++ b/tests/src/com/android/contacts/util/BitmapUtilTests.java
@@ -60,7 +60,7 @@
     }
 
     public void testFindOptimalSampleSizeSmaller3() throws Exception {
-        assertEquals(2, BitmapUtil.findOptimalSampleSize(512, 129));
+        assertEquals(4, BitmapUtil.findOptimalSampleSize(512, 129));
     }
 
     public void testFindOptimalSampleSizeSmaller4() throws Exception {