Merge "Remove extra code which set Activity to null." into klp-dev
diff --git a/InCallUI/res/layout/answer_fragment.xml b/InCallUI/res/layout/answer_fragment.xml
index f6b1320..8b553a6 100644
--- a/InCallUI/res/layout/answer_fragment.xml
+++ b/InCallUI/res/layout/answer_fragment.xml
@@ -19,16 +19,11 @@
 <com.android.incallui.GlowPadWrapper
         xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:dc="http://schemas.android.com/apk/res-auto"
-
         android:id="@+id/glow_pad_view"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginBottom="@dimen/glowpadview_margin_bottom"
         android:focusable="true"
-        android:layout_alignParentBottom="true"
         android:layout_centerHorizontal="true"
-        android:gravity="center"
-        android:layout_gravity="bottom|center_horizontal"
         android:background="@android:color/black"
 
         dc:targetDrawables="@array/incoming_call_widget_2way_targets"
diff --git a/InCallUI/res/layout/incall_screen.xml b/InCallUI/res/layout/incall_screen.xml
index 25241ba..86f67c9 100644
--- a/InCallUI/res/layout/incall_screen.xml
+++ b/InCallUI/res/layout/incall_screen.xml
@@ -62,7 +62,9 @@
               android:layout_height="wrap_content"
               android:layout_alignParentBottom="true"
               android:layout_centerHorizontal="true"
-              android:gravity="center"
-              android:layout_gravity="bottom|center_horizontal" />
+              android:gravity="top"
+              android:layout_gravity="bottom|center_horizontal"
+              android:layout_marginBottom="@dimen/glowpadview_margin_bottom"
+              android:visibility="gone" />
 
 </FrameLayout>
diff --git a/InCallUI/res/values/dimens.xml b/InCallUI/res/values/dimens.xml
index c0a001c..1d94971 100644
--- a/InCallUI/res/values/dimens.xml
+++ b/InCallUI/res/values/dimens.xml
@@ -113,7 +113,7 @@
     <!-- Default distance from each snap target that GlowPadView considers a "hit" -->
     <dimen name="glowpadview_inner_radius">15dip</dimen>
 
-    <dimen name="glowpadview_margin_bottom">-64dip</dimen>
+    <dimen name="glowpadview_margin_bottom">-48dip</dimen>
     <dimen name="glowpadview_margin_right">0dip</dimen>
 
 </resources>
diff --git a/InCallUI/src/com/android/incallui/CallCardFragment.java b/InCallUI/src/com/android/incallui/CallCardFragment.java
index b77dc4c..be1c514 100644
--- a/InCallUI/src/com/android/incallui/CallCardFragment.java
+++ b/InCallUI/src/com/android/incallui/CallCardFragment.java
@@ -16,6 +16,7 @@
 
 package com.android.incallui;
 
+import android.animation.LayoutTransition;
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.drawable.BitmapDrawable;
@@ -49,6 +50,7 @@
     private View mProviderInfo;
     private TextView mProviderLabel;
     private TextView mProviderNumber;
+    private ViewGroup mSupplementaryInfoContainer;
 
     // Secondary caller info
     private ViewStub mSecondaryCallInfo;
@@ -99,6 +101,8 @@
         mProviderInfo = view.findViewById(R.id.providerInfo);
         mProviderLabel = (TextView) view.findViewById(R.id.providerLabel);
         mProviderNumber = (TextView) view.findViewById(R.id.providerAddress);
+        mSupplementaryInfoContainer =
+            (ViewGroup) view.findViewById(R.id.supplementary_info_container);
     }
 
     @Override
@@ -208,9 +212,23 @@
         Log.v(this, "bluetooth on ", bluetoothOn);
 
         if (!TextUtils.isEmpty(callStateLabel)) {
+            // There are cases where we totally skip the animation
+            final boolean skipAnimation = (state == Call.State.DIALING
+                    || state == Call.State.DISCONNECTED);
+
+            LayoutTransition transition = null;
+            if (skipAnimation) {
+                transition = mSupplementaryInfoContainer.getLayoutTransition();
+                mSupplementaryInfoContainer.setLayoutTransition(null);
+            }
+
             mCallStateLabel.setVisibility(View.VISIBLE);
             mCallStateLabel.setText(callStateLabel);
 
+            if (skipAnimation) {
+                mSupplementaryInfoContainer.setLayoutTransition(transition);
+            }
+
             if (Call.State.INCOMING == state) {
                 setBluetoothOn(bluetoothOn);
             }
diff --git a/InCallUI/src/com/android/incallui/CallList.java b/InCallUI/src/com/android/incallui/CallList.java
index 7890b997..200f10f 100644
--- a/InCallUI/src/com/android/incallui/CallList.java
+++ b/InCallUI/src/com/android/incallui/CallList.java
@@ -38,7 +38,9 @@
  */
 public class CallList {
 
-    private static final int DISCONNECTED_CALL_TIMEOUT_MS = 2000;
+    private static final int DISCONNECTED_CALL_SHORT_TIMEOUT_MS = 200;
+    private static final int DISCONNECTED_CALL_MEDIUM_TIMEOUT_MS = 2000;
+    private static final int DISCONNECTED_CALL_LONG_TIMEOUT_MS = 5000;
 
     private static final int EVENT_DISCONNECTED_TIMEOUT = 1;
 
@@ -264,7 +266,7 @@
 
                 // Set up a timer to destroy the call after X seconds.
                 final Message msg = mHandler.obtainMessage(EVENT_DISCONNECTED_TIMEOUT, call);
-                mHandler.sendMessageDelayed(msg, DISCONNECTED_CALL_TIMEOUT_MS);
+                mHandler.sendMessageDelayed(msg, getDelayForDisconnect(call));
 
                 mCallMap.put(id, call);
             }
@@ -275,6 +277,32 @@
         }
     }
 
+    private int getDelayForDisconnect(Call call) {
+        Preconditions.checkState(call.getState() == Call.State.DISCONNECTED);
+
+
+        final Call.DisconnectCause cause = call.getDisconnectCause();
+        final int delay;
+        switch (cause) {
+            case LOCAL:
+                delay = DISCONNECTED_CALL_SHORT_TIMEOUT_MS;
+                break;
+            case NORMAL:
+                delay = DISCONNECTED_CALL_MEDIUM_TIMEOUT_MS;
+                break;
+            case INCOMING_REJECTED:
+            case INCOMING_MISSED:
+                // no delay for missed/rejected incoming calls
+                delay = 0;
+                break;
+            default:
+                delay = DISCONNECTED_CALL_LONG_TIMEOUT_MS;
+                break;
+        }
+
+        return delay;
+    }
+
     private void updateCallTextMap(Call call, List<String> textResponses) {
         Preconditions.checkNotNull(call);
 
diff --git a/InCallUI/src/com/android/incallui/ProximitySensor.java b/InCallUI/src/com/android/incallui/ProximitySensor.java
index fb8e468..0012e8a 100644
--- a/InCallUI/src/com/android/incallui/ProximitySensor.java
+++ b/InCallUI/src/com/android/incallui/ProximitySensor.java
@@ -165,17 +165,17 @@
      * 4) If the slider is open(i.e. the hardkeyboard is *not* hidden)
      */
     private void updateProximitySensorMode() {
-        Log.v(this, "updateProximitySensorMode");
+        Log.i(this, "updateProximitySensorMode");
 
         if (proximitySensorModeEnabled()) {
-            Log.v(this, "keyboard open: ", mIsHardKeyboardOpen);
-            Log.v(this, "dialpad visible: ", mDialpadVisible);
+            Log.i(this, "keyboard open: " + mIsHardKeyboardOpen);
+            Log.i(this, "dialpad visible: " + mDialpadVisible);
             Log.v(this, "isOffhook: ", mIsPhoneOffhook);
 
             synchronized (mProximityWakeLock) {
 
                 final int audioMode = mAudioModeProvider.getAudioMode();
-                Log.v(this, "audioMode: ", AudioMode.toString(audioMode));
+                Log.i(this, "audioMode: " + AudioMode.toString(audioMode));
 
                 // turn proximity sensor off and turn screen on immediately if
                 // we are using a headset, the keyboard is open, or the device
@@ -190,7 +190,7 @@
                 // proximity sensor goes negative.
                 final boolean horizontal =
                         (mOrientation == AccelerometerListener.ORIENTATION_HORIZONTAL);
-                Log.v(this, "horizontal: ", horizontal);
+                Log.i(this, "horizontal: " + horizontal);
                 screenOnImmediately |= !mUiShowing && horizontal;
 
                 // We do not keep the screen off when dialpad is visible, we are horizontal, and
@@ -202,6 +202,7 @@
                 Log.v(this, "screenonImmediately: ", screenOnImmediately);
 
                 if (mIsPhoneOffhook && !screenOnImmediately) {
+                    Log.i(this, "turning on proximity sensor");
                     // Phone is in use!  Arrange for the screen to turn off
                     // automatically when the sensor detects a close object.
                     if (!mProximityWakeLock.isHeld()) {
@@ -211,6 +212,7 @@
                         Log.v(this, "updateProximitySensorMode: lock already held.");
                     }
                 } else {
+                    Log.i(this, "turning off proximity sensor");
                     // Phone is either idle, or ringing.  We don't want any
                     // special proximity sensor behavior in either case.
                     if (mProximityWakeLock.isHeld()) {