Add VideoCallFragment back into InCallUI

Statically add VideoCallFragment into the view hierarchy
so that video calls can be shown in the UI.

Change-Id: I8afbaaa750371a4afe3946d268882f46f5ec7eb4
diff --git a/InCallUI/res/layout-land/call_card_fragment.xml b/InCallUI/res/layout-land/call_card_fragment.xml
index 4c76b95..ed4d411 100644
--- a/InCallUI/res/layout-land/call_card_fragment.xml
+++ b/InCallUI/res/layout-land/call_card_fragment.xml
@@ -37,7 +37,7 @@
 
         <fragment android:name="com.android.incallui.CallButtonFragment"
             android:id="@+id/callButtonFragment"
-            android:layout_width="match_parent"
+            android:layout_width="wrap_content"
             android:layout_height="wrap_content" />
 
         <FrameLayout
@@ -66,6 +66,14 @@
         android:background="@android:color/white"
         android:src="@drawable/img_no_image_automirrored" />
 
+   <fragment android:name="com.android.incallui.VideoCallFragment"
+        android:id="@+id/videoCallFragment"
+        android:layout_alignParentTop="true"
+        android:layout_gravity="top|center_horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:visibility="gone" />
+
     <include layout="@layout/manage_conference_call_button"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
@@ -91,7 +99,7 @@
             android:indeterminate="true" />
     </FrameLayout>
 
-    <!-- Placeholder for the dialpad which is replaced with the dialpad fragment when shown. -->
+    <!-- Placeholder for various fragments that are added dynamically underneath the caller info. -->
     <FrameLayout
         android:id="@+id/answer_and_dialpad_container"
         android:layout_toEndOf="@id/primary_call_info_container"
diff --git a/InCallUI/res/layout/call_card_fragment.xml b/InCallUI/res/layout/call_card_fragment.xml
index 920f8cb..548eed4 100644
--- a/InCallUI/res/layout/call_card_fragment.xml
+++ b/InCallUI/res/layout/call_card_fragment.xml
@@ -98,7 +98,15 @@
         android:layout_height="wrap_content"
         android:layout_alignTop="@id/photo" />
 
-    <!-- Placeholder for various fragments that are added dynamically underneath the caller info -->
+    <fragment android:name="com.android.incallui.VideoCallFragment"
+        android:layout_alignParentStart="true"
+        android:layout_gravity="start|center_vertical"
+        android:id="@+id/videoCallFragment"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:visibility="gone" />
+
+    <!-- Placeholder for various fragments that are added dynamically underneath the caller info. -->
     <FrameLayout
         android:id="@+id/answer_and_dialpad_container"
         android:layout_below="@id/primary_call_info_container"
diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java
index 9d15856..3478b7d 100644
--- a/InCallUI/src/com/android/incallui/InCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/InCallPresenter.java
@@ -1264,6 +1264,10 @@
      *      and landscape.  {@Code False} if the in-call UI should be locked in portrait.
      */
     public void setInCallAllowsOrientationChange(boolean allowOrientationChange) {
+        if (mInCallActivity == null) {
+            return;
+        }
+
         if (!allowOrientationChange) {
             mInCallActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
         } else {
diff --git a/InCallUI/src/com/android/incallui/InCallVideoCallListener.java b/InCallUI/src/com/android/incallui/InCallVideoCallListener.java
index 363bd41..3d975db 100644
--- a/InCallUI/src/com/android/incallui/InCallVideoCallListener.java
+++ b/InCallUI/src/com/android/incallui/InCallVideoCallListener.java
@@ -130,7 +130,9 @@
      */
     @Override
     public void onCameraCapabilitiesChanged(CameraCapabilities cameraCapabilities) {
-        InCallVideoCallListenerNotifier.getInstance().cameraDimensionsChanged(
-                mCall, cameraCapabilities.getWidth(), cameraCapabilities.getHeight());
+        if (cameraCapabilities != null) {
+            InCallVideoCallListenerNotifier.getInstance().cameraDimensionsChanged(
+                    mCall, cameraCapabilities.getWidth(), cameraCapabilities.getHeight());
+        }
     }
 }
diff --git a/InCallUI/src/com/android/incallui/VideoCallFragment.java b/InCallUI/src/com/android/incallui/VideoCallFragment.java
index 7cc945a..6e4abfc 100644
--- a/InCallUI/src/com/android/incallui/VideoCallFragment.java
+++ b/InCallUI/src/com/android/incallui/VideoCallFragment.java
@@ -34,6 +34,8 @@
  */
 public class VideoCallFragment extends BaseFragment<VideoCallPresenter,
         VideoCallPresenter.VideoCallUi> implements VideoCallPresenter.VideoCallUi {
+    private static final String TAG = VideoCallFragment.class.getSimpleName();
+    private static final boolean DEBUG = false;
 
     /**
      * Used to indicate that the surface dimensions are not set.
@@ -138,6 +140,10 @@
          * @param view The {@link TextureView}.
          */
         public void recreateView(TextureView view) {
+            if (DEBUG) {
+                Log.i(TAG, "recreateView: " + view);
+            }
+
             if (mTextureView == view) {
                 return;
             }
@@ -163,6 +169,9 @@
         public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width,
                 int height) {
             boolean surfaceCreated;
+            if (DEBUG) {
+                Log.i(TAG, "onSurfaceTextureAvailable: " + surfaceTexture);
+            }
             // Where there is no saved {@link SurfaceTexture} available, use the newly created one.
             // If a saved {@link SurfaceTexture} is available, we are re-creating after an
             // orientation change.
@@ -334,7 +343,6 @@
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
-
         super.onCreateView(inflater, container, savedInstanceState);
 
         final View view = inflater.inflate(R.layout.video_call_fragment, container, false);
diff --git a/InCallUI/src/com/android/incallui/VideoCallPresenter.java b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
index c566264..04d304b 100644
--- a/InCallUI/src/com/android/incallui/VideoCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
@@ -62,6 +62,10 @@
         InCallDetailsListener, SurfaceChangeListener, VideoEventListener,
         InCallVideoCallListenerNotifier.SessionModificationListener {
 
+    private static final String TAG = VideoCallPresenter.class.getSimpleName();
+
+    public static final boolean DEBUG = false;
+
     /**
      * Determines the device orientation (portrait/lanscape).
      */
@@ -211,6 +215,9 @@
      * @param surface The surface which was created.
      */
     public void onSurfaceCreated(int surface) {
+        if (DEBUG) {
+            Log.i(TAG, "onSurfaceCreated: " + surface);
+        }
         final VideoCallUi ui = getUi();
 
         if (ui == null || mVideoCall == null) {
@@ -400,6 +407,9 @@
      * TODO(vt): Need to adjust size and orientation of preview surface here.
      */
     private void enterVideoMode() {
+        if (DEBUG) {
+            Log.i(TAG, "enterVideoMode");
+        }
         VideoCallUi ui = getUi();
         if (ui == null) {
             return;
@@ -422,7 +432,9 @@
                     getInCallCameraManager();
             mVideoCall.setCamera(cameraManager.getActiveCameraId());
             mVideoCall.requestCameraCapabilities();
-
+            if (DEBUG) {
+                Log.i(TAG, "isDisplayVideoSurfacedCreated: " + ui.isDisplayVideoSurfaceCreated());
+            }
             if (ui.isDisplayVideoSurfaceCreated()) {
                 mVideoCall.setDisplaySurface(ui.getDisplayVideoSurface());
             }
@@ -561,7 +573,7 @@
 
     @Override
     public void onDowngradeToAudio(Call call) {
-        // Implementing to satsify interface.
+        // Implementing to satisfy interface.
     }
 
     /**