Merge "Import translations. DO NOT MERGE" into lmp-dev
diff --git a/Android.mk b/Android.mk
index a6c4efc..124549b 100644
--- a/Android.mk
+++ b/Android.mk
@@ -10,12 +10,14 @@
 res_dirs := res $(contacts_common_dir)/res $(phone_common_dir)/res
 
 LOCAL_SRC_FILES := $(call all-java-files-under, $(src_dirs))
-LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dirs))
+LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dirs)) \
+    frameworks/support/v7/cardview/res
 
 LOCAL_AAPT_FLAGS := \
     --auto-add-overlay \
     --extra-packages com.android.contacts.common \
-    --extra-packages com.android.phone.common
+    --extra-packages com.android.phone.common \
+    --extra-packages android.support.v7.cardview
 
 LOCAL_JAVA_LIBRARIES := telephony-common voip-common
 LOCAL_STATIC_JAVA_LIBRARIES := \
@@ -23,6 +25,7 @@
     android-common \
     guava \
     android-support-v13 \
+    android-support-v7-cardview \
     android-support-v7-palette \
     android-support-v4 \
     libphonenumber \
diff --git a/res/layout/expanding_entry_card_item.xml b/res/layout/expanding_entry_card_item.xml
index dfd450c..174ddf9 100644
--- a/res/layout/expanding_entry_card_item.xml
+++ b/res/layout/expanding_entry_card_item.xml
@@ -36,12 +36,14 @@
 
     <TextView
         android:id="@+id/header"
+        android:textSize="@dimen/expanding_entry_card_title_text_size"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentTop="true"
         android:layout_toEndOf="@+id/icon"
         android:layout_toStartOf="@+id/icon_alternate"
-        android:textColor="@color/quickcontact_entry_header_text_color" />
+        android:textColor="@color/quickcontact_entry_header_text_color"
+        android:layout_marginBottom="@dimen/expanding_entry_card_header_margin_bottom" />
 
     <TextView
         android:id="@+id/sub_header"
diff --git a/res/layout/expanding_entry_card_view.xml b/res/layout/expanding_entry_card_view.xml
index 7c4464a..6b89759 100644
--- a/res/layout/expanding_entry_card_view.xml
+++ b/res/layout/expanding_entry_card_view.xml
@@ -13,7 +13,11 @@
      See the License for the specific language governing permissions and
      limitations under the License.
 -->
-<merge xmlns:android="http://schemas.android.com/apk/res/android">
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:id="@+id/container">
 
     <TextView
         android:id="@+id/title"
@@ -39,4 +43,4 @@
         android:layout_height="wrap_content"
         android:orientation="vertical" />
 
-</merge>
\ No newline at end of file
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/quickcontact_content.xml b/res/layout/quickcontact_content.xml
index b72340b..494b93b 100644
--- a/res/layout/quickcontact_content.xml
+++ b/res/layout/quickcontact_content.xml
@@ -15,6 +15,7 @@
 -->
 <com.android.contacts.widget.TouchlessScrollView
     xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:cardview="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:fillViewport="true"
@@ -32,22 +33,26 @@
         <com.android.contacts.quickcontact.ExpandingEntryCardView
             style="@style/ExpandingEntryCardStyle"
             android:id="@+id/no_contact_data_card"
-            android:visibility="gone" />
+            android:visibility="gone"
+            cardview:cardCornerRadius="@dimen/expanding_entry_card_card_corner_radius" />
 
         <com.android.contacts.quickcontact.ExpandingEntryCardView
             style="@style/ExpandingEntryCardStyle"
             android:id="@+id/communication_card"
-            android:visibility="gone" />
+            android:visibility="gone"
+            cardview:cardCornerRadius="@dimen/expanding_entry_card_card_corner_radius" />
 
         <com.android.contacts.quickcontact.ExpandingEntryCardView
             style="@style/ExpandingEntryCardStyle"
             android:id="@+id/recent_card"
-            android:visibility="gone" />
+            android:visibility="gone"
+            cardview:cardCornerRadius="@dimen/expanding_entry_card_card_corner_radius" />
 
         <com.android.contacts.quickcontact.ExpandingEntryCardView
             style="@style/ExpandingEntryCardStyle"
             android:id="@+id/about_card"
-            android:visibility="gone" />
+            android:visibility="gone"
+            cardview:cardCornerRadius="@dimen/expanding_entry_card_card_corner_radius" />
 
     </LinearLayout>
 
diff --git a/res/layout/quickcontact_expanding_entry_card_button.xml b/res/layout/quickcontact_expanding_entry_card_button.xml
index fef2959..7bf7e67 100644
--- a/res/layout/quickcontact_expanding_entry_card_button.xml
+++ b/res/layout/quickcontact_expanding_entry_card_button.xml
@@ -34,13 +34,14 @@
             android:id="@+id/text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:drawablePadding="@dimen/expanding_entry_card_button_drawable_padding"
+            android:drawablePadding="@dimen/expanding_entry_card_item_image_spacing"
             android:gravity="center_vertical"
             android:layout_weight="0"
             android:paddingBottom="@dimen/expanding_entry_card_button_padding_vertical"
-            android:paddingStart="@dimen/expanding_entry_card_button_padding_start"
+            android:paddingStart="@dimen/expanding_entry_card_item_padding_start"
             android:paddingTop="@dimen/expanding_entry_card_button_padding_vertical"
-            android:textColor="@color/expanding_entry_card_button_text_color" />
+            android:textColor="@color/expanding_entry_card_button_text_color"
+            android:textSize="@dimen/expanding_entry_card_title_text_size" />
 
         <LinearLayout
             android:id="@+id/badge_container"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 0d516eb..6439c1d 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -125,8 +125,8 @@
 
 
     <!-- Margins for ExpandingEntryCardView -->
-    <dimen name="expanding_entry_card_marginStart">12dp</dimen>
-    <dimen name="expanding_entry_card_marginEnd">12dp</dimen>
+    <dimen name="expanding_entry_card_marginStart">8dp</dimen>
+    <dimen name="expanding_entry_card_marginEnd">8dp</dimen>
     <dimen name="expanding_entry_card_marginBottom">12dp</dimen>
     <!-- Width of the grey border surrounding the expanding entry cards. If we ever add
          a rounded corner to the expanding entry cards, than we will need to increase this value -->
@@ -136,7 +136,7 @@
     <dimen name="first_card_marginTop">12dp</dimen>
 
     <!-- Elevation of an ExpandingEntryCard, for the sake of shadow casting -->
-    <dimen name="expanding_entry_card_elevation">1dp</dimen>
+    <dimen name="expanding_entry_card_elevation">2dp</dimen>
     <!-- Elevation of the QuickContact's Toolbar, for the sake of shadow casting -->
     <dimen name="quick_contact_toolbar_elevation">4.5dp</dimen>
 
@@ -150,25 +150,28 @@
     <!-- Dimensions for an entry in ExpandingEntryCardView -->
     <dimen name="expanding_entry_card_item_padding_start">20dp</dimen>
     <dimen name="expanding_entry_card_item_padding_end">20dp</dimen>
-    <dimen name="expanding_entry_card_item_padding_top">16dp</dimen>
+    <dimen name="expanding_entry_card_item_padding_top">18dp</dimen>
     <dimen name="expanding_entry_card_item_padding_bottom">16dp</dimen>
-    <dimen name="expanding_entry_card_item_image_spacing">20dp</dimen>
+    <dimen name="expanding_entry_card_item_image_spacing">27dp</dimen>
 
     <!-- Dimensions for a button in ExpandingEntryCardView -->
-    <dimen name="expanding_entry_card_button_padding_start">20dp</dimen>
-    <dimen name="expanding_entry_card_button_padding_vertical">16dp</dimen>
-    <dimen name="expanding_entry_card_button_drawable_padding">20dp</dimen>
+    <dimen name="expanding_entry_card_button_padding_vertical">18dp</dimen>
 
     <dimen name="expanding_entry_card_item_text_icon_margin_top">7dp</dimen>
     <dimen name="expanding_entry_card_item_text_icon_margin_right">7dp</dimen>
     <dimen name="expanding_entry_card_item_sub_header_icon_margin_right">4dp</dimen>
     <dimen name="expanding_entry_card_item_sub_header_icon_margin_bottom">14dp</dimen>
 
-    <dimen name="expanding_entry_card_item_icon_margin_top">8dp</dimen>
+    <dimen name="expanding_entry_card_item_icon_margin_top">7dp</dimen>
+    <dimen name="expanding_entry_card_item_header_only_margin_top">6dp</dimen>
     <dimen name="expanding_entry_card_item_alternate_icon_margin_end">0dp</dimen>
     <dimen name="expanding_entry_card_item_alternate_icon_margin_bottom">10dp</dimen>
 
     <dimen name="expanding_entry_card_badge_separator_margin">8dp</dimen>
+    <dimen name="expanding_entry_card_card_corner_radius">2dp</dimen>
+    <dimen name="expanding_entry_card_header_margin_bottom">2dp</dimen>
+    <!-- The top margin when the sub header and text views are both gone -->
+    <dimen name="expanding_entry_card_item_header_only_margin_bottom">2dp</dimen>
 
     <dimen name="people_activity_card_elevation">2dp</dimen>
     <!-- The width the that the tabs occupy in the ActionBar when in landscape mode.
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 815b5b0..37d0c94 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -28,6 +28,7 @@
 
     <style name="EditorActivityTheme" parent="@style/PeopleTheme">
         <item name="android:listViewStyle">@style/ListViewStyle</item>
+        <item name="android:actionBarStyle">@style/EditorActionBarStyle</item>
     </style>
 
     <style name="Theme">
@@ -109,6 +110,11 @@
         <item name="android:icon">@android:color/transparent</item>
     </style>
 
+    <style name="EditorActionBarStyle" parent="@style/ContactsActionBarStyle">
+        <!-- Do not use a contentInsetStart, since we are setting a custom ActionBar view -->
+        <item name="android:contentInsetStart">0dp</item>
+    </style>
+
     <!-- When this style was added, android:toolbarStyle was private. Therefore, this style
          must be directly applied to every toolbar -->
     <style name="ContactsToolbarStyle" parent="@android:style/Widget.Toolbar">
diff --git a/src/com/android/contacts/list/EmailAddressListAdapter.java b/src/com/android/contacts/list/EmailAddressListAdapter.java
index 5396364..21b9c60 100644
--- a/src/com/android/contacts/list/EmailAddressListAdapter.java
+++ b/src/com/android/contacts/list/EmailAddressListAdapter.java
@@ -23,7 +23,6 @@
 import android.net.Uri.Builder;
 import android.provider.ContactsContract;
 import android.provider.ContactsContract.CommonDataKinds.Email;
-import android.provider.ContactsContract.ContactCounts;
 import android.provider.ContactsContract.Data;
 import android.text.TextUtils;
 import android.view.View;
@@ -87,7 +86,7 @@
         } else {
             builder = Email.CONTENT_URI.buildUpon();
             if (isSectionHeaderDisplayEnabled()) {
-                builder.appendQueryParameter(ContactCounts.ADDRESS_BOOK_INDEX_EXTRAS, "true");
+                builder.appendQueryParameter(Email.ADDRESS_BOOK_INDEX_EXTRAS, "true");
             }
         }
         builder.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY,
diff --git a/src/com/android/contacts/list/PostalAddressListAdapter.java b/src/com/android/contacts/list/PostalAddressListAdapter.java
index 35fccfe..5194b69 100644
--- a/src/com/android/contacts/list/PostalAddressListAdapter.java
+++ b/src/com/android/contacts/list/PostalAddressListAdapter.java
@@ -23,7 +23,6 @@
 import android.net.Uri.Builder;
 import android.provider.ContactsContract;
 import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
-import android.provider.ContactsContract.ContactCounts;
 import android.provider.ContactsContract.Data;
 import android.view.View;
 import android.view.ViewGroup;
@@ -81,7 +80,7 @@
         final Builder builder = StructuredPostal.CONTENT_URI.buildUpon()
                 .appendQueryParameter(ContactsContract.REMOVE_DUPLICATE_ENTRIES, "true");
         if (isSectionHeaderDisplayEnabled()) {
-            builder.appendQueryParameter(ContactCounts.ADDRESS_BOOK_INDEX_EXTRAS, "true");
+            builder.appendQueryParameter(StructuredPostal.ADDRESS_BOOK_INDEX_EXTRAS, "true");
         }
         loader.setUri(builder.build());
 
diff --git a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
index 4bfc225..6812ac4 100644
--- a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
+++ b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
@@ -21,6 +21,7 @@
 import android.graphics.ColorFilter;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
+import android.support.v7.widget.CardView;
 import android.text.TextUtils;
 import android.transition.ChangeBounds;
 import android.transition.ChangeScroll;
@@ -35,6 +36,7 @@
 import android.view.TouchDelegate;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.RelativeLayout;
@@ -48,7 +50,7 @@
 /**
  * Display entries in a LinearLayout that can be expanded to show all entries.
  */
-public class ExpandingEntryCardView extends LinearLayout {
+public class ExpandingEntryCardView extends CardView {
 
     private static final String TAG = "ExpandingEntryCardView";
     private static final int DURATION_EXPAND_ANIMATION_FADE_IN = 200;
@@ -184,6 +186,7 @@
     private ViewGroup mAnimationViewGroup;
     private LinearLayout mBadgeContainer;
     private final List<ImageView> mBadges;
+    private LinearLayout mContainer;
 
     private final OnClickListener mExpandCollapseButtonListener = new OnClickListener() {
         @Override
@@ -207,6 +210,7 @@
         mEntriesViewGroup = (LinearLayout)
                 expandingEntryCardView.findViewById(R.id.content_area_linear_layout);
         mTitleTextView = (TextView) expandingEntryCardView.findViewById(R.id.title);
+        mContainer = (LinearLayout) expandingEntryCardView.findViewById(R.id.container);
         mCollapseArrowDrawable =
                 getResources().getDrawable(R.drawable.expanding_entry_card_collapse_white_24);
         mExpandArrowDrawable =
@@ -315,7 +319,7 @@
         removeView(mExpandCollapseButton);
         if (mCollapsedEntriesCount < mNumEntries
                 && mExpandCollapseButton.getParent() == null && !mIsAlwaysExpanded) {
-            addView(mExpandCollapseButton, -1);
+            mContainer.addView(mExpandCollapseButton, -1);
         }
     }
 
@@ -325,23 +329,22 @@
 
     private void addSeparator(View entry) {
         View separator = new View(getContext());
-        separator.setBackgroundColor(getResources().getColor(
+        Resources res = getResources();
+
+        separator.setBackgroundColor(res.getColor(
                 R.color.expanding_entry_card_item_separator_color));
-        LayoutParams layoutParams = generateDefaultLayoutParams();
-        Resources resources = getResources();
-        layoutParams.height = resources.getDimensionPixelSize(
-                R.dimen.expanding_entry_card_item_separator_height);
+        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
+                ViewGroup.LayoutParams.MATCH_PARENT,
+                res.getDimensionPixelSize(R.dimen.expanding_entry_card_item_separator_height));
         // The separator is aligned with the text in the entry. This is offset by a default
         // margin. If there is an icon present, the icon's width and margin are added
-        int marginStart = resources.getDimensionPixelSize(
+        int marginStart = res.getDimensionPixelSize(
                 R.dimen.expanding_entry_card_item_padding_start);
         ImageView entryIcon = (ImageView) entry.findViewById(R.id.icon);
         if (entryIcon.getVisibility() == View.VISIBLE) {
             int imageWidthAndMargin =
-                    resources.getDimensionPixelSize(
-                            R.dimen.expanding_entry_card_item_icon_width) +
-                    resources.getDimensionPixelSize(
-                            R.dimen.expanding_entry_card_item_image_spacing);
+                    res.getDimensionPixelSize(R.dimen.expanding_entry_card_item_icon_width) +
+                    res.getDimensionPixelSize(R.dimen.expanding_entry_card_item_image_spacing);
             marginStart += imageWidthAndMargin;
         }
         layoutParams.setMarginStart(marginStart);
@@ -521,13 +524,16 @@
             view.setTag(entry.getIntent());
         }
 
-        // If only the header is visible, add a top margin to match icon's top margin
+        // If only the header is visible, add a top margin to match icon's top margin.
+        // Also increase the space below the header for visual comfort.
         if (header.getVisibility() == View.VISIBLE && subHeader.getVisibility() == View.GONE &&
                 text.getVisibility() == View.GONE) {
             RelativeLayout.LayoutParams headerLayoutParams =
                     (RelativeLayout.LayoutParams) header.getLayoutParams();
             headerLayoutParams.topMargin = (int) (getResources().getDimension(
-                    R.dimen.expanding_entry_card_item_icon_margin_top));
+                    R.dimen.expanding_entry_card_item_header_only_margin_top));
+            headerLayoutParams.bottomMargin += (int) (getResources().getDimension(
+                    R.dimen.expanding_entry_card_item_header_only_margin_bottom));
             header.setLayoutParams(headerLayoutParams);
         }
 
@@ -562,6 +568,12 @@
             });
         }
 
+        // Decrease margin for entries that have an invisible icon
+        if (iconVisibility == View.INVISIBLE) {
+            view.setPaddingRelative(view.getPaddingStart(), 0, view.getPaddingEnd(),
+                    view.getPaddingBottom());
+        }
+
         return view;
     }
 
diff --git a/src/com/android/contacts/widget/MultiShrinkScroller.java b/src/com/android/contacts/widget/MultiShrinkScroller.java
index 8f1146a..370c3ae 100644
--- a/src/com/android/contacts/widget/MultiShrinkScroller.java
+++ b/src/com/android/contacts/widget/MultiShrinkScroller.java
@@ -111,6 +111,10 @@
     private int mCollapsedTitleStartMargin;
     private int mMinimumPortraitHeaderHeight;
     private int mMaximumPortraitHeaderHeight;
+    /**
+     * True once the header has touched the top of the screen at least once.
+     */
+    private boolean mHasEverTouchedTheTop;
 
     private final Scroller mScroller;
     private final EdgeEffect mEdgeGlowBottom;
@@ -490,6 +494,11 @@
      * If needed, snap the subviews to the top of the Window.
      */
     private boolean snapToTop(int flingDelta) {
+        if (mHasEverTouchedTheTop) {
+            // Only when first interacting with QuickContacts should QuickContacts snap to the top
+            // of the screen. After this, QuickContacts can be placed most anywhere on the screen.
+            return false;
+        }
         final int requiredScroll = -getScroll_ignoreOversizedHeaderForSnapping()
                 + mTransparentStartHeight;
         if (-getScroll_ignoreOversizedHeaderForSnapping() - flingDelta < 0
@@ -508,7 +517,18 @@
      * If needed, scroll all the subviews off the bottom of the Window.
      */
     private void snapToBottom(int flingDelta) {
-        if (-getScroll_ignoreOversizedHeaderForSnapping() - flingDelta > 0) {
+        if (mHasEverTouchedTheTop) {
+            // If QuickContacts has touched the top of the screen previously, then we
+            // will less aggressively snap to the bottom of the screen.
+            final float predictedScrollPastTop = -getScroll() + mIntermediateHeaderHeight
+                    - flingDelta;
+            final float heightMinusHeader = getHeight() - mIntermediateHeaderHeight;
+            if (predictedScrollPastTop > heightMinusHeader) {
+                scrollOffBottom();
+            }
+            return;
+        }
+        if (-getScroll() - flingDelta > 0) {
             scrollOffBottom();
         }
     }
@@ -560,6 +580,7 @@
         updatePhotoTintAndDropShadow();
         updateHeaderTextSize();
         final boolean isFullscreen = getScrollNeededToBeFullScreen() <= 0;
+        mHasEverTouchedTheTop |= isFullscreen;
         if (mListener != null) {
             if (wasFullscreen && !isFullscreen) {
                  mListener.onExitFullscreen();
diff --git a/tests/src/com/android/contacts/activities/PeopleActivityTest.java b/tests/src/com/android/contacts/activities/PeopleActivityTest.java
index a9eac20..023d48b 100644
--- a/tests/src/com/android/contacts/activities/PeopleActivityTest.java
+++ b/tests/src/com/android/contacts/activities/PeopleActivityTest.java
@@ -23,7 +23,6 @@
 import android.net.Uri;
 import android.os.AsyncTask;
 import android.provider.ContactsContract;
-import android.provider.ContactsContract.ContactCounts;
 import android.provider.ContactsContract.Contacts;
 import android.provider.ContactsContract.Directory;
 import android.provider.ContactsContract.Groups;
@@ -140,7 +139,7 @@
 
     private void expectContactListQuery(int count) {
         Uri uri = Contacts.CONTENT_URI.buildUpon()
-                .appendQueryParameter(ContactCounts.ADDRESS_BOOK_INDEX_EXTRAS, "true")
+                .appendQueryParameter(Contacts.ADDRESS_BOOK_INDEX_EXTRAS, "true")
                 .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY,
                         String.valueOf(Directory.DEFAULT))
                 .build();