Merge "Check if cursor is closed." into jb-mr2-dev
diff --git a/src/com/android/contacts/activities/ContactDetailActivity.java b/src/com/android/contacts/activities/ContactDetailActivity.java
index 3cbc39d..86f638c 100644
--- a/src/com/android/contacts/activities/ContactDetailActivity.java
+++ b/src/com/android/contacts/activities/ContactDetailActivity.java
@@ -260,12 +260,23 @@
         actionBar.setTitle(displayName);
         actionBar.setSubtitle(company);
 
+        final StringBuilder talkback = new StringBuilder();
         if (!TextUtils.isEmpty(displayName)) {
+            talkback.append(displayName);
+        }
+        if (!TextUtils.isEmpty(company)) {
+            if (talkback.length() != 0) {
+                talkback.append(", ");
+            }
+            talkback.append(company);
+        }
+
+        if (talkback.length() != 0) {
             AccessibilityManager accessibilityManager =
                     (AccessibilityManager) this.getSystemService(Context.ACCESSIBILITY_SERVICE);
             if (accessibilityManager.isEnabled()) {
                 View decorView = getWindow().getDecorView();
-                decorView.setContentDescription(displayName);
+                decorView.setContentDescription(talkback);
                 decorView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
             }
         }
diff --git a/src/com/android/contacts/detail/ContactDetailFragmentCarousel.java b/src/com/android/contacts/detail/ContactDetailFragmentCarousel.java
index a66baa5..f85bd23 100644
--- a/src/com/android/contacts/detail/ContactDetailFragmentCarousel.java
+++ b/src/com/android/contacts/detail/ContactDetailFragmentCarousel.java
@@ -116,7 +116,9 @@
             View child = getChildAt(0);
             // If we enable swipe, then the {@link LinearLayout} child width must be the sum of the
             // width of all its children fragments.
-            if (mEnableSwipe) {
+            // Or the current page may already be set to something other than the first.  If so,
+            // it also means there are multiple child fragments.
+            if (mEnableSwipe || mCurrentPage != 0) {
                 child.measure(MeasureSpec.makeMeasureSpec(
                         mMinFragmentWidth * MAX_FRAGMENT_VIEW_COUNT, MeasureSpec.EXACTLY),
                         MeasureSpec.makeMeasureSpec(screenHeight, MeasureSpec.EXACTLY));
@@ -163,11 +165,7 @@
             mEnableSwipe = enable;
             if (mUpdatesFragment != null) {
                 mUpdatesFragment.setVisibility(enable ? View.VISIBLE : View.GONE);
-                if (mCurrentPage == ABOUT_PAGE) {
-                    mAboutFragment.requestFocus();
-                } else {
-                    mUpdatesFragment.requestFocus();
-                }
+                snapToEdge();
                 updateTouchInterceptors();
             }
         }
@@ -179,7 +177,7 @@
     public void reset() {
         if (mCurrentPage != ABOUT_PAGE) {
             mCurrentPage = ABOUT_PAGE;
-            snapToEdge();
+            snapToEdgeSmooth();
         }
     }
 
@@ -191,7 +189,7 @@
         @Override
         public void onClick(View v) {
             mCurrentPage = ABOUT_PAGE;
-            snapToEdge();
+            snapToEdgeSmooth();
         }
     };
 
@@ -199,7 +197,7 @@
         @Override
         public void onClick(View v) {
             mCurrentPage = UPDATES_PAGE;
-            snapToEdge();
+            snapToEdgeSmooth();
         }
     };
 
@@ -222,13 +220,27 @@
         mLastScrollPosition = l;
     }
 
+    /**
+     * Used to set initial scroll offset.  Not smooth.
+     */
     private void snapToEdge() {
-        final int x = mCurrentPage == ABOUT_PAGE ? 0 : mAllowedHorizontalScrollLength;
-        smoothScrollTo(x,0);
+        setScrollX(calculateHorizontalOffset());
         updateTouchInterceptors();
     }
 
     /**
+     * Smooth version of snapToEdge().
+     */
+    private void snapToEdgeSmooth() {
+        smoothScrollTo(calculateHorizontalOffset(), 0);
+        updateTouchInterceptors();
+    }
+
+    private int calculateHorizontalOffset() {
+        return mCurrentPage == ABOUT_PAGE ? 0 : mAllowedHorizontalScrollLength;
+    }
+
+    /**
      * Returns the desired page we should scroll to based on the current X scroll position and the
      * current page.
      */
@@ -253,7 +265,7 @@
         }
         if (event.getAction() == MotionEvent.ACTION_UP) {
             mCurrentPage = getDesiredPage();
-            snapToEdge();
+            snapToEdgeSmooth();
             return true;
         }
         return false;