Merge 5789796d61d1dbdc0ce87c1a98e736440d781944 on remote branch

Change-Id: I449315f9b1249bf5f19ae4a3e7b80fe71c800782
diff --git a/InCallUI/res/layout/primary_call_info.xml b/InCallUI/res/layout/primary_call_info.xml
index 2fa3b94..28e8ac7 100644
--- a/InCallUI/res/layout/primary_call_info.xml
+++ b/InCallUI/res/layout/primary_call_info.xml
@@ -178,7 +178,9 @@
                 android:textDirection="ltr"
                 android:visibility="gone" />
 
-            <TextView android:id="@+id/phoneNumber"
+            <com.android.phone.common.widget.ResizingTextTextView
+                xmlns:ex="http://schemas.android.com/apk/res-auto"
+                android:id="@+id/phoneNumber"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_weight="1"
@@ -187,7 +189,9 @@
                 android:textAppearance="?android:attr/textAppearanceSmall"
                 android:textColor="@color/incall_call_banner_subtext_color"
                 android:textSize="@dimen/call_label_text_size"
-                android:singleLine="false"
+                android:singleLine="true"
+                android:ellipsize="end"
+                ex:resizing_text_min_size="@dimen/call_label_text_min_size"
                 android:visibility="gone" />
 
         </LinearLayout>
diff --git a/InCallUI/res/values-sw360dp/dimens.xml b/InCallUI/res/values-sw360dp/dimens.xml
index 9fbcd60..0436a4c 100644
--- a/InCallUI/res/values-sw360dp/dimens.xml
+++ b/InCallUI/res/values-sw360dp/dimens.xml
@@ -24,6 +24,7 @@
     <dimen name="call_name_text_size">45dp</dimen>
     <dimen name="call_name_text_min_size">34sp</dimen>
     <dimen name="call_label_text_size">18sp</dimen>
+    <dimen name="call_labe_text_min_size">8sp</dimen>
 
     <!-- The InCallUI dialpad will sometimes want digits sizes that are different from dialer. -->
     <dimen name="dialpad_key_number_margin_bottom">@dimen/dialpad_key_number_default_margin_bottom</dimen>
diff --git a/InCallUI/res/values/dimens.xml b/InCallUI/res/values/dimens.xml
index 15520e5..3a926b6 100644
--- a/InCallUI/res/values/dimens.xml
+++ b/InCallUI/res/values/dimens.xml
@@ -52,6 +52,7 @@
     <dimen name="call_name_text_size">34dp</dimen>
     <dimen name="call_name_text_min_size">28sp</dimen>
     <dimen name="call_label_text_size">16sp</dimen>
+    <dimen name="call_label_text_min_size">6sp</dimen>
     <!-- Right padding for name and number fields in the call banner.
          This padding is used to ensure that ultra-long names or
          numbers won't overlap the elapsed time indication. -->
diff --git a/InCallUI/src/com/android/incallui/InCallOrientationEventListener.java b/InCallUI/src/com/android/incallui/InCallOrientationEventListener.java
index 3cab6dc..ed10b73 100644
--- a/InCallUI/src/com/android/incallui/InCallOrientationEventListener.java
+++ b/InCallUI/src/com/android/incallui/InCallOrientationEventListener.java
@@ -20,7 +20,9 @@
 import android.content.res.Configuration;
 import android.view.OrientationEventListener;
 import android.hardware.SensorManager;
+import android.view.Display;
 import android.view.Surface;
+import android.view.WindowManager;
 import android.content.pm.ActivityInfo;
 
 /**
@@ -51,7 +53,7 @@
      * within x degrees right or left of the screen orientation angles. If it's not within those
      * ranges, we return SCREEN_ORIENTATION_UNKNOWN and ignore it.
      */
-    private static int SCREEN_ORIENTATION_UNKNOWN = -1;
+    public static int SCREEN_ORIENTATION_UNKNOWN = -1;
 
     // Rotation threshold is 10 degrees. So if the rotation angle is within 10 degrees of any of
     // the above angles, we will notify orientation changed.
@@ -64,8 +66,11 @@
     private static int sCurrentOrientation = SCREEN_ORIENTATION_0;
     private boolean mEnabled = false;
 
+    private static WindowManager sWindowManager = null;
+
     public InCallOrientationEventListener(Context context) {
         super(context);
+        sWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
     }
 
     /**
@@ -175,4 +180,32 @@
     private static boolean isInRightRange(int value, int center, int threshold) {
         return isWithinRange(value, center, center + threshold);
     }
+
+    /**
+     * Returns the current display orientation.
+     * return values 0, 90, 180 and 270
+     * -1 if unknown
+     */
+    public static int getCurrentUiOrientation() {
+        if (sWindowManager == null) return SCREEN_ORIENTATION_UNKNOWN;
+        Display display = sWindowManager.getDefaultDisplay();
+        if (display == null) return SCREEN_ORIENTATION_UNKNOWN;
+        int rotation = display.getRotation();
+        int orientation = SCREEN_ORIENTATION_UNKNOWN;
+        switch (rotation) {
+            case Surface.ROTATION_0:
+                orientation = SCREEN_ORIENTATION_0;
+                break;
+            case Surface.ROTATION_90:
+                orientation = SCREEN_ORIENTATION_90;
+                break;
+            case Surface.ROTATION_180:
+                orientation = SCREEN_ORIENTATION_180;
+                break;
+            case Surface.ROTATION_270:
+                orientation = SCREEN_ORIENTATION_270;
+                break;
+        }
+        return orientation;
+    }
 }
diff --git a/InCallUI/src/com/android/incallui/VideoCallFragment.java b/InCallUI/src/com/android/incallui/VideoCallFragment.java
index a210e6e..fe1422f 100644
--- a/InCallUI/src/com/android/incallui/VideoCallFragment.java
+++ b/InCallUI/src/com/android/incallui/VideoCallFragment.java
@@ -780,13 +780,6 @@
                 }
                 mPreviewVideoContainer.setLayoutParams(containerParams);
             }
-
-            // The width and height are interchanged outside of this method based on the current
-            // orientation, so we can transform using "width", which will be either the width or
-            // the height.
-            Matrix transform = new Matrix();
-            transform.setScale(-1, 1, width/2, 0);
-            preview.setTransform(transform);
         }
     }
 
@@ -813,7 +806,10 @@
                 return;
             }
 
-            preview.setRotation(orientation);
+            // Set transform matrix based on orientation
+            ViewGroup.LayoutParams params = preview.getLayoutParams();
+            setTransformMatrixForRotation(preview, orientation,
+                    params.width, params.height);
         }
     }
 
@@ -969,6 +965,56 @@
     }
 
     /**
+     * Sets the transform matrix to textureview based on orientation so that image
+     * is always up right.
+     */
+    private void setTransformMatrixForRotation(TextureView textureView, int rotation,
+            int width, int height) {
+
+        Matrix matrix = new Matrix();
+
+        if (rotation != InCallOrientationEventListener.SCREEN_ORIENTATION_0) {
+
+            float[] srcArray =  new float[] {
+                    0.f, 0.f, // top left
+                    width, 0.f, // top right
+                    0.f, height, // bottom left
+                    width, height, // bottom right
+            };
+
+            float[] destArray = srcArray;
+
+            // Rotate the image for landscape device orientations
+            if (rotation == InCallOrientationEventListener.SCREEN_ORIENTATION_90) {
+                destArray = new float[] {
+                        0.f, height, // top left
+                        0.f, 0.f, // top right
+                        width, height, // bottom left
+                        width, 0.f, // bottom right
+                };
+            } else if (rotation == InCallOrientationEventListener.SCREEN_ORIENTATION_270) {
+                destArray = new float[] {
+                        width, 0.f, // top left
+                        width, height, // top right
+                        0.f, 0.f, // bottom left
+                        0.f, height, // bottom right
+                };
+            } else if (rotation == InCallOrientationEventListener.SCREEN_ORIENTATION_180) {
+                // Flip the image vertically and horizontally for reverse portrait
+                destArray = new float[] {
+                        width, height, // top left
+                        0.f, height, // top right
+                        width, 0.f, // bottom left
+                        0.f, 0.f, // bottom right
+                };
+            }
+
+            matrix.setPolyToPoly(srcArray, 0, destArray, 0, 4);
+        }
+        textureView.setTransform(matrix);
+    }
+
+    /**
      * Resizes a surface so that it has the same size as the full screen and so that it is
      * centered vertically below the call card.
      *
diff --git a/InCallUI/src/com/android/incallui/VideoCallPresenter.java b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
index 6a04de2..92bd5e5 100644
--- a/InCallUI/src/com/android/incallui/VideoCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
@@ -284,6 +284,13 @@
             return;
         }
 
+        // Initialize current ui rotation
+        final int uiOrientation = InCallOrientationEventListener.getCurrentUiOrientation();
+        Log.d(this, "onUiReady: uiOrientation = " + uiOrientation);
+        if (uiOrientation != InCallOrientationEventListener.SCREEN_ORIENTATION_UNKNOWN) {
+            mDeviceOrientation = uiOrientation;
+        }
+
         // Register for call state changes last
         InCallPresenter.getInstance().addListener(this);
         InCallPresenter.getInstance().addDetailsListener(this);
@@ -1241,6 +1248,7 @@
 
         mPreviewSurfaceState = PreviewSurfaceState.CAPABILITIES_RECEIVED;
         changePreviewDimensions(width, height);
+        ui.setPreviewRotation(mDeviceOrientation);
 
         if (shallTransmitStaticImage()) {
             setPauseImage();