Merge "Enable transations for dialpad digits" into klp-dev
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 726c176..79d8d69 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -422,15 +422,19 @@
     }
 
     private void showDialpadFragment(boolean animate) {
+        mDialpadFragment.setAdjustTranslationForAnimation(animate);
         final FragmentTransaction ft = getFragmentManager().beginTransaction();
         if (animate) {
             ft.setCustomAnimations(R.anim.slide_in, 0);
+        } else {
+            mDialpadFragment.setYFraction(0);
         }
         ft.show(mDialpadFragment);
         ft.commit();
     }
 
     private void hideDialpadFragment(boolean animate) {
+        mDialpadFragment.setAdjustTranslationForAnimation(animate);
         final FragmentTransaction ft = getFragmentManager().beginTransaction();
         if (animate) {
             ft.setCustomAnimations(0, R.anim.slide_out);
@@ -619,9 +623,7 @@
 
         if (mDialpadFragment != null && (phoneIsInUse() || isDialIntent(intent))) {
             mDialpadFragment.setStartedFromNewIntent(true);
-            // TODO krelease: This should use showDialpadFragment(false) to avoid animating
-            // the dialpad in. Need to fix the onPreDrawListener in NewDialpadFragment first.
-            showDialpadFragment(true);
+            showDialpadFragment(false);
         }
     }
 
diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java
index 5d75004..a76d0c1 100644
--- a/src/com/android/dialer/calllog/CallLogFragment.java
+++ b/src/com/android/dialer/calllog/CallLogFragment.java
@@ -90,7 +90,6 @@
     private final Handler mHandler = new Handler();
 
     private TelephonyManager mTelephonyManager;
-    private PhoneStateListener mPhoneStateListener;
 
     private class CustomContentObserver extends ContentObserver {
         public CustomContentObserver() {
@@ -322,7 +321,6 @@
         mAdapter.changeCursor(null);
         getActivity().getContentResolver().unregisterContentObserver(mCallLogObserver);
         getActivity().getContentResolver().unregisterContentObserver(mContactsObserver);
-        unregisterPhoneCallReceiver();
     }
 
     @Override
@@ -340,12 +338,6 @@
     }
 
     private void updateCallList(int filterType) {
-        if (filterType == CallLogQueryHandler.CALL_TYPE_ALL) {
-            unregisterPhoneCallReceiver();
-        } else {
-            // TODO krelease: Make this work
-            //registerPhoneCallReceiver();
-        }
         mCallLogQueryHandler.fetchCalls(filterType);
     }
 
@@ -487,48 +479,4 @@
         serviceIntent.setAction(CallLogNotificationsService.ACTION_UPDATE_NOTIFICATIONS);
         getActivity().startService(serviceIntent);
     }
-
-    // TODO krelease: Make the ViewPager switch to the correct tab (All) when a phone call is
-    // placed.
-    // This should probably be moved to the call log activity.
-    /**
-     * Register a phone call filter to reset the call type when a phone call is place.
-     */
-    /*
-    private void registerPhoneCallReceiver() {
-        if (mPhoneStateListener != null) {
-            return; // Already registered.
-        }
-        mTelephonyManager = (TelephonyManager) getActivity().getSystemService(
-                Context.TELEPHONY_SERVICE);
-        mPhoneStateListener = new PhoneStateListener() {
-            @Override
-            public void onCallStateChanged(int state, String incomingNumber) {
-                if (state != TelephonyManager.CALL_STATE_OFFHOOK &&
-                        state != TelephonyManager.CALL_STATE_RINGING) {
-                    return;
-                }
-                mHandler.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        if (getActivity() == null || getActivity().isFinishing()) {
-                            return;
-                        }
-                    }
-                 });
-            }
-        };
-        mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
-    }
-    */
-
-    /**
-     * Un-registers the phone call receiver.
-     */
-    private void unregisterPhoneCallReceiver() {
-        if (mPhoneStateListener != null) {
-            mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
-            mPhoneStateListener = null;
-        }
-    }
 }
diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java
index 3052c67..e113374 100644
--- a/src/com/android/dialer/dialpad/DialpadFragment.java
+++ b/src/com/android/dialer/dialpad/DialpadFragment.java
@@ -262,6 +262,7 @@
 
     private boolean mStartedFromNewIntent = false;
     private boolean mFirstLaunch = false;
+    private boolean mAdjustTranslationForAnimation = false;
 
     private static final String PREF_DIGITS_FILLED_BY_INTENT = "pref_digits_filled_by_intent";
 
@@ -350,15 +351,17 @@
                 false);
         fragmentView.buildLayer();
 
-        // TODO krelease: Get rid of this ugly hack which is to prevent the first frame of the
-        // animation from drawing the fragment at translationY = 0
         final ViewTreeObserver vto = fragmentView.getViewTreeObserver();
+        // Adjust the translation of the DialpadFragment in a preDrawListener instead of in
+        // DialtactsActivity, because at the point in time when the DialpadFragment is added,
+        // its views have not been laid out yet.
         final OnPreDrawListener preDrawListener = new OnPreDrawListener() {
 
             @Override
             public boolean onPreDraw() {
+
                 if (isHidden()) return true;
-                if (fragmentView.getTranslationY() == 0) {
+                if (mAdjustTranslationForAnimation && fragmentView.getTranslationY() == 0) {
                     ((DialpadSlidingLinearLayout) fragmentView).setYFraction(
                             DIALPAD_SLIDE_FRACTION);
                 }
@@ -1691,4 +1694,12 @@
             activity.hideSearchBar();
         }
     }
+
+    public void setAdjustTranslationForAnimation(boolean value) {
+        mAdjustTranslationForAnimation = value;
+    }
+
+    public void setYFraction(float yFraction) {
+        ((DialpadSlidingLinearLayout) getView()).setYFraction(yFraction);
+    }
 }