Moving ProportionalLayout to ContactsCommon.

Bug: 6993891
Change-Id: If47fdd3b3fe29bc8a490f9b5bf3d2bb045e5cd8f
diff --git a/res/layout-land/quickcontact_activity.xml b/res/layout-land/quickcontact_activity.xml
index 689ab9d..dd47a0b 100644
--- a/res/layout-land/quickcontact_activity.xml
+++ b/res/layout-land/quickcontact_activity.xml
@@ -30,7 +30,7 @@
         android:padding="32dip"
         android:orientation="horizontal">
         <view
-            class="com.android.contacts.widget.ProportionalLayout"
+            class="com.android.contacts.common.widget.ProportionalLayout"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             ex:ratio="1.0"
diff --git a/res/layout-sw580dp/detail_header_contact_with_updates.xml b/res/layout-sw580dp/detail_header_contact_with_updates.xml
index c7fd25a..c515a76 100644
--- a/res/layout-sw580dp/detail_header_contact_with_updates.xml
+++ b/res/layout-sw580dp/detail_header_contact_with_updates.xml
@@ -31,7 +31,7 @@
 
     <!-- Add a first item that gives us enough space to show the carousel -->
     <view
-        class="com.android.contacts.widget.ProportionalLayout"
+        class="com.android.contacts.common.widget.ProportionalLayout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         ex:ratio="0.6667"
diff --git a/res/layout-sw580dp/detail_header_contact_without_updates.xml b/res/layout-sw580dp/detail_header_contact_without_updates.xml
index bc5a8e1..f8f560d 100644
--- a/res/layout-sw580dp/detail_header_contact_without_updates.xml
+++ b/res/layout-sw580dp/detail_header_contact_without_updates.xml
@@ -29,7 +29,7 @@
     <!-- Ensure that the contact photo for a contact WITHOUT social updates is the same width and
     height as a contact WITH social updates (where the photo is 2/3 of the screen width). -->
     <view
-        class="com.android.contacts.widget.ProportionalLayout"
+        class="com.android.contacts.common.widget.ProportionalLayout"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         ex:ratio="0.6667"
diff --git a/res/layout-sw580dp/updates_header_contact.xml b/res/layout-sw580dp/updates_header_contact.xml
index 6079499..10b6bd8 100644
--- a/res/layout-sw580dp/updates_header_contact.xml
+++ b/res/layout-sw580dp/updates_header_contact.xml
@@ -26,7 +26,7 @@
 
     <!-- This blank view pushes the other content down because of the tab carousel -->
     <view
-        class="com.android.contacts.widget.ProportionalLayout"
+        class="com.android.contacts.common.widget.ProportionalLayout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginBottom="8dip"
diff --git a/res/layout/detail_header_contact_with_updates.xml b/res/layout/detail_header_contact_with_updates.xml
index 3391595..dc4cf8b 100644
--- a/res/layout/detail_header_contact_with_updates.xml
+++ b/res/layout/detail_header_contact_with_updates.xml
@@ -26,7 +26,7 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
     <view
-        class="com.android.contacts.widget.ProportionalLayout"
+        class="com.android.contacts.common.widget.ProportionalLayout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginBottom="@dimen/detail_contact_photo_shadow_height"
diff --git a/res/layout/detail_header_contact_without_updates.xml b/res/layout/detail_header_contact_without_updates.xml
index b261511..27f6288 100644
--- a/res/layout/detail_header_contact_without_updates.xml
+++ b/res/layout/detail_header_contact_without_updates.xml
@@ -27,7 +27,7 @@
 
     <!-- Contact photo -->
     <view
-        class="com.android.contacts.widget.ProportionalLayout"
+        class="com.android.contacts.common.widget.ProportionalLayout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         ex:ratio="0.5"
diff --git a/res/layout/quickcontact_activity.xml b/res/layout/quickcontact_activity.xml
index b3351ba..66ddbc6 100644
--- a/res/layout/quickcontact_activity.xml
+++ b/res/layout/quickcontact_activity.xml
@@ -32,7 +32,7 @@
         android:paddingTop="8dip"
         android:orientation="vertical">
         <view
-            class="com.android.contacts.widget.ProportionalLayout"
+            class="com.android.contacts.common.widget.ProportionalLayout"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             ex:ratio="0.5"
diff --git a/res/layout/stream_item_row_images.xml b/res/layout/stream_item_row_images.xml
index 7e440ab..a96e2d2 100644
--- a/res/layout/stream_item_row_images.xml
+++ b/res/layout/stream_item_row_images.xml
@@ -22,7 +22,7 @@
     android:layout_marginTop="@dimen/detail_update_section_between_items_padding">
 
     <view
-        class="com.android.contacts.widget.ProportionalLayout"
+        class="com.android.contacts.common.widget.ProportionalLayout"
         android:layout_width="0dip"
         android:layout_height="wrap_content"
         android:layout_marginRight="@dimen/detail_update_section_between_items_padding"
@@ -38,7 +38,7 @@
 
     <view
         android:id="@+id/second_image_container"
-        class="com.android.contacts.widget.ProportionalLayout"
+        class="com.android.contacts.common.widget.ProportionalLayout"
         android:layout_width="0dip"
         android:layout_height="wrap_content"
         android:layout_weight="1"
diff --git a/res/layout/updates_header_contact.xml b/res/layout/updates_header_contact.xml
index 9b59c82..33e1c02 100644
--- a/res/layout/updates_header_contact.xml
+++ b/res/layout/updates_header_contact.xml
@@ -26,7 +26,7 @@
 
     <!-- This blank view pushes the other content down because of the tab carousel -->
     <view
-        class="com.android.contacts.widget.ProportionalLayout"
+        class="com.android.contacts.common.widget.ProportionalLayout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginBottom="@dimen/detail_contact_photo_shadow_height"
diff --git a/src/com/android/contacts/widget/ProportionalLayout.java b/src/com/android/contacts/widget/ProportionalLayout.java
deleted file mode 100644
index d069eb7..0000000
--- a/src/com/android/contacts/widget/ProportionalLayout.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * 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.widget;
-
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.util.AttributeSet;
-import android.view.View;
-import android.view.ViewGroup;
-
-import com.android.contacts.R;
-
-/**
- * Layout that calculates its height based on its width, or vice versa (depending on the set
- * {@link #setDirection(Direction)}. The factor is specified in {@link #setRatio(float)}.
- * <p>For {@link Direction#heightToWidth}: width := height * factor</p>
- * <p>For {@link Direction#widthToHeight}: height := width * factor</p>
- * <p>Only one child is allowed; if more are required, another ViewGroup can be used as the direct
- * child of this layout.</p>
- */
-public class ProportionalLayout extends ViewGroup {
-    /** Specifies whether the width should be calculated based on the height or vice-versa  */
-    public enum Direction {
-        widthToHeight("widthToHeight"),
-        heightToWidth("heightToWidth");
-
-        public final String XmlName;
-
-        private Direction(String xmlName) {
-            XmlName = xmlName;
-        }
-
-        /**
-         * Parses the given direction string and returns the Direction instance. This
-         * should be used when inflating from xml
-         */
-        public static Direction parse(String value) {
-            if (widthToHeight.XmlName.equals(value)) {
-                return Direction.widthToHeight;
-            } else if (heightToWidth.XmlName.equals(value)) {
-                return Direction.heightToWidth;
-            } else {
-                throw new IllegalStateException("direction must be either " +
-                        widthToHeight.XmlName + " or " + heightToWidth.XmlName);
-            }
-        }
-    }
-
-    private Direction mDirection;
-    private float mRatio;
-
-    public ProportionalLayout(Context context) {
-        super(context);
-    }
-
-    public ProportionalLayout(Context context, AttributeSet attrs) {
-        super(context, attrs);
-        initFromAttributes(context, attrs);
-    }
-
-    public ProportionalLayout(Context context, AttributeSet attrs, int defStyle) {
-        super(context, attrs, defStyle);
-        initFromAttributes(context, attrs);
-    }
-
-    private void initFromAttributes(Context context, AttributeSet attrs) {
-        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProportionalLayout);
-
-        mDirection = Direction.parse(a.getString(R.styleable.ProportionalLayout_direction));
-        mRatio = a.getFloat(R.styleable.ProportionalLayout_ratio, 1.0f);
-
-        a.recycle();
-    }
-
-    @Override
-    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-        if (getChildCount() != 1) {
-            throw new IllegalStateException("ProportionalLayout requires exactly one child");
-        }
-
-        final View child = getChildAt(0);
-
-        // Do a first pass to get the optimal size
-        measureChild(child, widthMeasureSpec, heightMeasureSpec);
-        final int childWidth = child.getMeasuredWidth();
-        final int childHeight = child.getMeasuredHeight();
-
-        final int width;
-        final int height;
-        if (mDirection == Direction.heightToWidth) {
-            width = Math.round(childHeight * mRatio);
-            height = childHeight;
-        } else {
-            width = childWidth;
-            height = Math.round(childWidth * mRatio);
-        }
-
-        // Do a second pass so that all children are informed of the new size
-        measureChild(child,
-                MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
-                MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
-
-        setMeasuredDimension(
-                resolveSize(width, widthMeasureSpec), resolveSize(height, heightMeasureSpec));
-    }
-
-    @Override
-    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
-        if (getChildCount() != 1) {
-            throw new IllegalStateException("ProportionalLayout requires exactly one child");
-        }
-
-        final View child = getChildAt(0);
-        child.layout(0, 0, right-left, bottom-top);
-    }
-
-    public Direction getDirection() {
-        return mDirection;
-    }
-
-    public void setDirection(Direction direction) {
-        mDirection = direction;
-    }
-
-    public float getRatio() {
-        return mRatio;
-    }
-
-    public void setRatio(float ratio) {
-        mRatio = ratio;
-    }
-}