QuickContact for multi-window mode

Bug 27614994

Change-Id: Ifd875f3602b799c419c6c3b0bad4865e727a6d59
diff --git a/res/layout-land/quickcontact_activity.xml b/res/layout-w500dp-land/quickcontact_activity.xml
similarity index 92%
rename from res/layout-land/quickcontact_activity.xml
rename to res/layout-w500dp-land/quickcontact_activity.xml
index af622dc..63cab3c 100644
--- a/res/layout-land/quickcontact_activity.xml
+++ b/res/layout-w500dp-land/quickcontact_activity.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<!-- Copyright (C) 2016 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.
diff --git a/res/layout/expanding_entry_card_item.xml b/res/layout/expanding_entry_card_item.xml
index 7c7337e..99f9174 100644
--- a/res/layout/expanding_entry_card_item.xml
+++ b/res/layout/expanding_entry_card_item.xml
@@ -43,7 +43,7 @@
         android:layout_alignParentTop="true"
         android:paddingTop="5dp"
         android:layout_toEndOf="@+id/icon"
-        android:layout_toStartOf="@+id/icon_alternate"
+        android:layout_toStartOf="@+id/third_icon"
         android:textColor="@color/quickcontact_entry_header_text_color"
         android:textAlignment="viewStart"
         android:layout_marginBottom="@dimen/expanding_entry_card_header_margin_bottom" />
@@ -54,7 +54,7 @@
         android:layout_height="wrap_content"
         android:layout_below="@+id/header"
         android:layout_toEndOf="@+id/icon_sub_header"
-        android:layout_toStartOf="@+id/icon_alternate"
+        android:layout_toStartOf="@+id/third_icon"
         android:textAlignment="viewStart"
         android:textColor="@color/quickcontact_entry_sub_header_text_color" />
 
@@ -73,7 +73,7 @@
         android:id="@+id/text"
         android:layout_below="@+id/sub_header"
         android:layout_toEndOf="@+id/icon_text"
-        android:layout_toStartOf="@+id/icon_alternate"
+        android:layout_toStartOf="@+id/third_icon"
         android:textAlignment="viewStart"
         android:textColor="@color/quickcontact_entry_sub_header_text_color" />
 
diff --git a/res/values-land/bools.xml b/res/values-land/bools.xml
index bd0650f..beaa960 100644
--- a/res/values-land/bools.xml
+++ b/res/values-land/bools.xml
@@ -15,6 +15,7 @@
 -->
 <resources>
 
-    <bool name="quickcontact_two_panel">true</bool>
+    <bool name="quickcontact_two_panel">false</bool>
+    <bool name="contacteditor_two_panel">true</bool>
 
 </resources>
diff --git a/res/layout-land/quickcontact_activity.xml b/res/values-w500dp-land/bools.xml
similarity index 81%
copy from res/layout-land/quickcontact_activity.xml
copy to res/values-w500dp-land/bools.xml
index af622dc..65174ba 100644
--- a/res/layout-land/quickcontact_activity.xml
+++ b/res/values-w500dp-land/bools.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<!-- Copyright (C) 2016 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.
@@ -13,6 +13,8 @@
      See the License for the specific language governing permissions and
      limitations under the License.
 -->
-<merge>
-    <include layout="@layout/quickcontact_activity_landscape" />
-</merge>
\ No newline at end of file
+<resources>
+
+    <bool name="quickcontact_two_panel">true</bool>
+
+</resources>
diff --git a/res/values/bools.xml b/res/values/bools.xml
index b94cc85..eef3808 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -17,5 +17,6 @@
 
     <bool name="quickcontact_two_panel">false</bool>
     <bool name="contact_all_list_show_card_frame">false</bool>
+    <bool name="contacteditor_two_panel">false</bool>
 
 </resources>
diff --git a/src/com/android/contacts/editor/CompactPhotoEditorView.java b/src/com/android/contacts/editor/CompactPhotoEditorView.java
index 1696a12..899e22a 100644
--- a/src/com/android/contacts/editor/CompactPhotoEditorView.java
+++ b/src/com/android/contacts/editor/CompactPhotoEditorView.java
@@ -78,7 +78,7 @@
 
         mLandscapePhotoRatio = getTypedFloat(R.dimen.quickcontact_landscape_photo_ratio);
         mPortraitPhotoRatio = getTypedFloat(R.dimen.editor_portrait_photo_ratio);
-        mIsTwoPanel = getResources().getBoolean(R.bool.quickcontact_two_panel);
+        mIsTwoPanel = getResources().getBoolean(R.bool.contacteditor_two_panel);
 
         final TypedArray styledAttributes = getContext().getTheme().obtainStyledAttributes(
                 new int[] { android.R.attr.actionBarSize });
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 3654c8a..c63c989 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -32,6 +32,7 @@
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.content.res.ColorStateList;
+import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
@@ -113,6 +114,7 @@
 import com.android.contacts.common.activity.RequestPermissionsActivity;
 import com.android.contacts.common.compat.CompatUtils;
 import com.android.contacts.common.compat.EventCompat;
+import com.android.contacts.common.compat.MultiWindowCompat;
 import com.android.contacts.common.dialog.CallSubjectDialog;
 import com.android.contacts.common.editor.SelectAccountDialogFragment;
 import com.android.contacts.common.interactions.TouchPointManager;
@@ -1039,7 +1041,9 @@
         mWindowScrim.setAlpha(0);
         getWindow().setBackgroundDrawable(mWindowScrim);
 
-        mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED);
+        mScroller.initialize(mMultiShrinkScrollerListener, mExtraMode == MODE_FULLY_EXPANDED,
+                /* maximumHeaderTextSize */ -1,
+                /* shouldUpdateNameViewHeight */ true);
         // mScroller needs to perform asynchronous measurements after initalize(), therefore
         // we can't mark this as GONE.
         mScroller.setVisibility(View.INVISIBLE);
@@ -1152,7 +1156,11 @@
                     ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
         }
         mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, QuickContact.MODE_LARGE);
-        mExtraPrioritizedMimeType = getIntent().getStringExtra(QuickContact.EXTRA_PRIORITIZED_MIMETYPE);
+        if (isMultiWindowOnPhone()) {
+            mExtraMode = QuickContact.MODE_LARGE;
+        }
+        mExtraPrioritizedMimeType =
+                getIntent().getStringExtra(QuickContact.EXTRA_PRIORITIZED_MIMETYPE);
         final Uri oldLookupUri = mLookupUri;
 
         if (lookupUri == null) {
@@ -1189,7 +1197,12 @@
             return;
         }
         mHasAlreadyBeenOpened = true;
-        mScroller.scrollUpForEntranceAnimation(mExtraMode != MODE_FULLY_EXPANDED);
+        mScroller.scrollUpForEntranceAnimation(/* scrollToCurrentPosition */ !isMultiWindowOnPhone()
+                && (mExtraMode != MODE_FULLY_EXPANDED));
+    }
+
+    private boolean isMultiWindowOnPhone() {
+        return MultiWindowCompat.isInMultiWindowMode(this) && PhoneCapabilityTester.isPhone(this);
     }
 
     /** Assign this string to the view if it is not empty. */
diff --git a/src/com/android/contacts/widget/MultiShrinkScroller.java b/src/com/android/contacts/widget/MultiShrinkScroller.java
index eb3283f..b1deb90 100644
--- a/src/com/android/contacts/widget/MultiShrinkScroller.java
+++ b/src/com/android/contacts/widget/MultiShrinkScroller.java
@@ -66,7 +66,7 @@
 public class MultiShrinkScroller extends FrameLayout {
 
     /**
-     * 1000 pixels per millisecond. Ie, 1 pixel per second.
+     * 1000 pixels per second. Ie, 1 pixel per millisecond.
      */
     private static final int PIXELS_PER_SECOND = 1000;
 
@@ -135,6 +135,8 @@
      */
     private boolean mIsOpenContactSquare;
     private int mMaximumHeaderTextSize;
+    private int mMaximumPhoneticNameViewHeight;
+    private int mMaximumFullNameViewHeight;
     private int mCollapsedTitleBottomMargin;
     private int mCollapsedTitleStartMargin;
     private int mMinimumPortraitHeaderHeight;
@@ -287,7 +289,8 @@
     /**
      * This method must be called inside the Activity's OnCreate.
      */
-    public void initialize(MultiShrinkScrollerListener listener, boolean isOpenContactSquare) {
+    public void initialize(MultiShrinkScrollerListener listener, boolean isOpenContactSquare,
+                final int maximumHeaderTextSize, final boolean shouldUpdateNameViewHeight) {
         mScrollView = (ScrollView) findViewById(R.id.content_scroller);
         mScrollViewChild = findViewById(R.id.card_container);
         mToolbar = findViewById(R.id.toolbar_parent);
@@ -346,7 +349,20 @@
                 mMaximumPortraitHeaderHeight = mIsTwoPanel ? getHeight()
                         : mPhotoViewContainer.getWidth();
                 setHeaderHeight(getMaximumScrollableHeaderHeight());
-                mMaximumHeaderTextSize = mTitleAndPhoneticNameView.getHeight();
+                if (shouldUpdateNameViewHeight) {
+                    mMaximumHeaderTextSize = mTitleAndPhoneticNameView.getHeight();
+                    mMaximumFullNameViewHeight = mLargeTextView.getHeight();
+                    // We cannot rely on mPhoneticNameView.getHeight() since it could be 0
+                    final int phoneticNameSize = getResources().getDimensionPixelSize(
+                            R.dimen.quickcontact_maximum_phonetic_name_size);
+                    final int fullNameSize = getResources().getDimensionPixelSize(
+                            R.dimen.quickcontact_maximum_title_size);
+                    mMaximumPhoneticNameViewHeight =
+                            mMaximumFullNameViewHeight * phoneticNameSize / fullNameSize;
+                }
+                if (maximumHeaderTextSize > 0) {
+                    mMaximumHeaderTextSize = maximumHeaderTextSize;
+                }
                 if (mIsTwoPanel) {
                     mMaximumHeaderHeight = getHeight();
                     mMinimumHeaderHeight = mMaximumHeaderHeight;
@@ -393,7 +409,7 @@
         final float TITLE_GRADIENT_SIZE_COEFFICIENT = 1.25f;
         final FrameLayout.LayoutParams largeTextLayoutParms
                 = (FrameLayout.LayoutParams) mTitleAndPhoneticNameView.getLayoutParams();
-        titleGradientLayoutParams.height = (int) ((mTitleAndPhoneticNameView.getHeight()
+        titleGradientLayoutParams.height = (int) ((mMaximumHeaderTextSize
                 + largeTextLayoutParms.bottomMargin) * TITLE_GRADIENT_SIZE_COEFFICIENT);
         mTitleGradientView.setLayoutParams(titleGradientLayoutParams);
     }
@@ -418,7 +434,9 @@
         // in case it just changed from Visibility=GONE.
         mPhoneticNameView.setVisibility(View.VISIBLE);
         // TODO try not using initialize() to refresh phonetic name view: b/27410518
-        initialize(mListener, mIsOpenContactSquare);
+        initialize(mListener, mIsOpenContactSquare, /* maximumHeaderTextSize */
+                (mMaximumFullNameViewHeight + mMaximumPhoneticNameViewHeight),
+                /* shouldUpdateNameViewHeight */ false);
     }
 
     public void setPhoneticNameGone() {
@@ -429,7 +447,9 @@
         mPhoneticNameView.setVisibility(View.GONE);
         // Initialize to make Visibility work.
         // TODO try not using initialize() to refresh phonetic name view: b/27410518
-        initialize(mListener, mIsOpenContactSquare);
+        initialize(mListener, mIsOpenContactSquare,
+                /* maximumHeaderTextSize */ mMaximumFullNameViewHeight,
+                /* shouldUpdateNameViewHeight */ false);
     }
 
     @Override
@@ -1039,7 +1059,7 @@
         } else {
             mTitleAndPhoneticNameView.setPivotX(0);
         }
-        mTitleAndPhoneticNameView.setPivotY(mTitleAndPhoneticNameView.getHeight() / 2);
+        mTitleAndPhoneticNameView.setPivotY(mMaximumHeaderTextSize / 2);
 
         final int toolbarHeight = mToolbar.getLayoutParams().height;
         mPhotoTouchInterceptOverlay.setClickable(toolbarHeight != mMaximumHeaderHeight);
@@ -1085,7 +1105,7 @@
         // Padding needed on the mTitleAndPhoneticNameView so that it has the same amount of
         // padding as the target rectangle.
         mCollapsedTitleBottomMargin =
-                desiredTopToCenter - mTitleAndPhoneticNameView.getHeight() / 2;
+                desiredTopToCenter - mMaximumHeaderTextSize / 2;
     }
 
     /**