Merge "Fix some broken Dialer tests" into lmp-mr1-dev
diff --git a/res/layout/call_log_list_item.xml b/res/layout/call_log_list_item.xml
index 761f352..c77a1f7 100644
--- a/res/layout/call_log_list_item.xml
+++ b/res/layout/call_log_list_item.xml
@@ -14,8 +14,7 @@
      limitations under the License.
 -->
 
-<view xmlns:android="http://schemas.android.com/apk/res/android"
-    class="com.android.dialer.calllog.CallLogListItemView"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/call_log_list_item"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
@@ -160,4 +159,4 @@
               android:layout="@layout/call_log_list_item_extra"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"/>
-</view>
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index beb7fe2..7a88b98 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -804,10 +804,15 @@
     <!-- Title of settings screen for managing the "Respond via SMS" feature. [CHAR LIMIT=30] -->
     <string name="respond_via_sms_setting_title">Quick responses</string>
 
-    <!-- Label for the call settings section [CHAR LIMIT=30]-->
+    <!-- Label for the call settings section [CHAR LIMIT=30] -->
     <string name="call_settings_label">Call settings</string>
 
-    <!-- Label for the call settings section description [CHAR LIMIT=80]-->
+    <!-- Label for the call settings section description [CHAR LIMIT=80] -->
     <string name="call_settings_description">Voicemail, call waiting, and others</string>
 
+    <!-- Label for the phone account settings [CHAR LIMIT=30] -->
+    <string name="phone_account_settings_label">Phone account settings</string>
+
+    <!-- Label for the phone account settings description [CHAR LIMIT=80] -->
+    <string name="phone_account_settings_description">Manage SIM and call settings</string>
 </resources>
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index bd20d22..50520bb 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -74,10 +74,10 @@
     /** Interface used to inform a parent UI element that a list item has been expanded. */
     public interface CallItemExpandedListener {
         /**
-         * @param view The {@link CallLogListItemView} that represents the item that was clicked
+         * @param view The {@link View} that represents the item that was clicked
          *         on.
          */
-        public void onItemExpanded(CallLogListItemView view);
+        public void onItemExpanded(View view);
 
         /**
          * Retrieves the call log view for the specified call Id.  If the view is not currently
@@ -86,7 +86,7 @@
          * @param callId The call Id.
          * @return The call log view.
          */
-        public CallLogListItemView getViewForCallId(long callId);
+        public View getViewForCallId(long callId);
     }
 
     /** Interface used to initiate a refresh of the content. */
@@ -267,6 +267,7 @@
     private int mCallLogBackgroundColor;
     private int mExpandedBackgroundColor;
     private float mExpandedTranslationZ;
+    private int mPhotoSize;
 
     /** Listener for the primary or secondary actions in the list.
      *  Primary opens the call details.
@@ -286,7 +287,7 @@
     private final View.OnClickListener mExpandCollapseListener = new View.OnClickListener() {
         @Override
         public void onClick(View v) {
-            final CallLogListItemView callLogItem = (CallLogListItemView) v.getParent().getParent();
+            final View callLogItem = (View) v.getParent().getParent();
             handleRowExpanded(callLogItem, true /* animate */, false /* forceExpand */);
         }
     };
@@ -296,7 +297,7 @@
         public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child,
                 AccessibilityEvent event) {
             if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
-                handleRowExpanded((CallLogListItemView) host, false /* animate */,
+                handleRowExpanded(host, false /* animate */,
                         true /* forceExpand */);
             }
             return super.onRequestSendAccessibilityEvent(host, child, event);
@@ -365,6 +366,7 @@
         mCallLogBackgroundColor = resources.getColor(R.color.background_dialer_list_items);
         mExpandedBackgroundColor = resources.getColor(R.color.call_log_expanded_background_color);
         mExpandedTranslationZ = resources.getDimension(R.dimen.call_log_expanded_translation_z);
+        mPhotoSize = resources.getDimensionPixelSize(R.dimen.contact_photo_size);
 
         mContactPhotoManager = ContactPhotoManager.getInstance(mContext);
         mPhoneNumberHelper = new PhoneNumberDisplayHelper(mContext, resources);
@@ -588,8 +590,7 @@
     @Override
     protected View newChildView(Context context, ViewGroup parent) {
         LayoutInflater inflater = LayoutInflater.from(context);
-        CallLogListItemView view =
-                (CallLogListItemView) inflater.inflate(R.layout.call_log_list_item, parent, false);
+        View view = inflater.inflate(R.layout.call_log_list_item, parent, false);
 
         // Get the views to bind to and cache them.
         CallLogListItemViews views = CallLogListItemViews.fromView(view);
@@ -624,14 +625,13 @@
     /**
      * Binds the views in the entry to the data in the call log.
      *
-     * @param view the view corresponding to this entry
+     * @param callLogItemView the view corresponding to this entry
      * @param c the cursor pointing to the entry in the call log
      * @param count the number of entries in the current item, greater than 1 if it is a group
      */
-    private void bindView(View view, Cursor c, int count) {
-        view.setAccessibilityDelegate(mAccessibilityDelegate);
-        final CallLogListItemView callLogItemView = (CallLogListItemView) view;
-        final CallLogListItemViews views = (CallLogListItemViews) view.getTag();
+    private void bindView(View callLogItemView, Cursor c, int count) {
+        callLogItemView.setAccessibilityDelegate(mAccessibilityDelegate);
+        final CallLogListItemViews views = (CallLogListItemViews) callLogItemView.getTag();
 
         // Default case: an item in the call log.
         views.primaryActionView.setVisibility(View.VISIBLE);
@@ -813,11 +813,11 @@
 
         // Listen for the first draw
         if (mViewTreeObserver == null) {
-            mViewTreeObserver = view.getViewTreeObserver();
+            mViewTreeObserver = callLogItemView.getViewTreeObserver();
             mViewTreeObserver.addOnPreDrawListener(this);
         }
 
-        bindBadge(view, info, details, callType);
+        bindBadge(callLogItemView, info, details, callType);
     }
 
     /**
@@ -886,12 +886,13 @@
     }
 
     /**
-     * Expands or collapses the view containing the CALLBACK, VOICEMAIL and DETAILS action buttons.
+     * Expands or collapses the view containing the CALLBACK/REDIAL, VOICEMAIL and DETAILS action
+     * buttons.
      *
      * @param callLogItem The call log entry parent view.
      * @param isExpanded The new expansion state of the view.
      */
-    private void expandOrCollapseActions(CallLogListItemView callLogItem, boolean isExpanded) {
+    private void expandOrCollapseActions(View callLogItem, boolean isExpanded) {
         final CallLogListItemViews views = (CallLogListItemViews)callLogItem.getTag();
 
         expandVoicemailTranscriptionView(views, isExpanded);
@@ -1234,7 +1235,7 @@
         views.quickContactView.setOverlay(null);
         DefaultImageRequest request = new DefaultImageRequest(displayName, identifier,
                 contactType, true /* isCircular */);
-        mContactPhotoManager.loadDirectoryPhoto(views.quickContactView, photoUri,
+        mContactPhotoManager.loadPhoto(views.quickContactView, photoUri, mPhotoSize,
                 false /* darkTheme */, true /* isCircular */, request);
     }
 
@@ -1386,7 +1387,7 @@
      * @param forceExpand Whether or not to force the call log row into an expanded state regardless
      *        of its previous state
      */
-    private void handleRowExpanded(CallLogListItemView view, boolean animate, boolean forceExpand) {
+    private void handleRowExpanded(View view, boolean animate, boolean forceExpand) {
         final CallLogListItemViews views = (CallLogListItemViews) view.getTag();
 
         if (forceExpand && isExpanded(views.rowId)) {
@@ -1407,7 +1408,7 @@
 
             // Animate the collapse of the previous item if it is still visible on screen.
             if (mPreviouslyExpanded != NONE_EXPANDED) {
-                CallLogListItemView previousItem = mCallItemExpandedListener.getViewForCallId(
+                View previousItem = mCallItemExpandedListener.getViewForCallId(
                         mPreviouslyExpanded);
 
                 if (previousItem != null) {
diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java
index f4db080..dfb7749 100644
--- a/src/com/android/dialer/calllog/CallLogFragment.java
+++ b/src/com/android/dialer/calllog/CallLogFragment.java
@@ -548,7 +548,7 @@
     }
 
     @Override
-    public void onItemExpanded(final CallLogListItemView view) {
+    public void onItemExpanded(final View view) {
         final int startingHeight = view.getHeight();
         final CallLogListItemViews viewHolder = (CallLogListItemViews) view.getTag();
         final ViewTreeObserver observer = getListView().getViewTreeObserver();
@@ -661,7 +661,7 @@
      * @return The call log view.
      */
     @Override
-    public CallLogListItemView getViewForCallId(long callId) {
+    public View getViewForCallId(long callId) {
         ListView listView = getListView();
 
         int firstPosition = listView.getFirstVisiblePosition();
@@ -673,7 +673,7 @@
             if (view != null) {
                 final CallLogListItemViews viewHolder = (CallLogListItemViews) view.getTag();
                 if (viewHolder != null && viewHolder.rowId == callId) {
-                    return (CallLogListItemView)view;
+                    return view;
                 }
             }
         }
diff --git a/src/com/android/dialer/calllog/CallLogListItemView.java b/src/com/android/dialer/calllog/CallLogListItemView.java
deleted file mode 100644
index b8990f5..0000000
--- a/src/com/android/dialer/calllog/CallLogListItemView.java
+++ /dev/null
@@ -1,38 +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.dialer.calllog;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.widget.LinearLayout;
-
-/**
- * An entry in the call log.
- */
-public class CallLogListItemView extends LinearLayout {
-    public CallLogListItemView(Context context) {
-        super(context);
-    }
-
-    public CallLogListItemView(Context context, AttributeSet attrs) {
-        super(context, attrs);
-    }
-
-    public CallLogListItemView(Context context, AttributeSet attrs, int defStyle) {
-        super(context, attrs, defStyle);
-    }
-}
diff --git a/src/com/android/dialer/list/ShortcutCardsAdapter.java b/src/com/android/dialer/list/ShortcutCardsAdapter.java
index 4fe638e..78b774b 100644
--- a/src/com/android/dialer/list/ShortcutCardsAdapter.java
+++ b/src/com/android/dialer/list/ShortcutCardsAdapter.java
@@ -32,7 +32,6 @@
 
 import com.android.dialer.R;
 import com.android.dialer.calllog.CallLogAdapter;
-import com.android.dialer.calllog.CallLogListItemView;
 import com.android.dialer.calllog.CallLogNotificationsHelper;
 import com.android.dialer.calllog.CallLogQueryHandler;
 import com.android.dialer.list.SwipeHelper.OnItemGestureListener;
@@ -266,8 +265,7 @@
                     R.dimen.recent_call_log_item_translation_z);
             view.setTranslationZ(mPreviousTranslationZ);
 
-            final CallLogListItemView callLogItem =
-                    (CallLogListItemView) view.findViewById(R.id.call_log_list_item);
+            final ViewGroup callLogItem = (ViewGroup) view.findViewById(R.id.call_log_list_item);
             // Reset the internal call log item view if it is being recycled
             callLogItem.setTranslationX(0);
             callLogItem.setTranslationY(0);
diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java
index 7d80ac3..4318666 100644
--- a/src/com/android/dialer/settings/DialerSettingsActivity.java
+++ b/src/com/android/dialer/settings/DialerSettingsActivity.java
@@ -3,11 +3,15 @@
 import com.google.common.collect.Lists;
 
 import android.content.Context;
+import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.preference.PreferenceManager;
+import android.preference.PreferenceActivity.Header;
+import android.telecom.TelecomManager;
+import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.MenuItem;
@@ -45,13 +49,28 @@
         generalSettingsHeader.fragment = GeneralSettingsFragment.class.getName();
         target.add(generalSettingsHeader);
 
-        // Only add the call settings header if the current user is the primary/owner user.
+        // Only show call setting menus if the current user is the primary/owner user.
         if (isPrimaryUser()) {
-            final Header callSettingHeader = new Header();
-            callSettingHeader.titleRes = R.string.call_settings_label;
-            callSettingHeader.summaryRes = R.string.call_settings_description;
-            callSettingHeader.intent = DialtactsActivity.getCallSettingsIntent();
-            target.add(callSettingHeader);
+            final TelephonyManager telephonyManager =
+                    (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
+            // Show "Call Settings" if there is one SIM and "Phone Accounts" if there are more.
+            if (telephonyManager.getPhoneCount() <= 1) {
+                final Header callSettingsHeader = new Header();
+                callSettingsHeader.titleRes = R.string.call_settings_label;
+                callSettingsHeader.summaryRes = R.string.call_settings_description;
+                callSettingsHeader.intent = DialtactsActivity.getCallSettingsIntent();
+                target.add(callSettingsHeader);
+            } else {
+                final Header phoneAccountSettingsHeader = new Header();
+                final Intent phoneAccountSettingsIntent =
+                        new Intent(TelecomManager.ACTION_CHANGE_PHONE_ACCOUNTS);
+                phoneAccountSettingsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+
+                phoneAccountSettingsHeader.titleRes = R.string.phone_account_settings_label;
+                phoneAccountSettingsHeader.summaryRes = R.string.phone_account_settings_description;
+                phoneAccountSettingsHeader.intent = phoneAccountSettingsIntent;
+                target.add(phoneAccountSettingsHeader);
+            }
         }
     }
 
diff --git a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java
index b7f06d3..9b3e6bc 100644
--- a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java
+++ b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java
@@ -21,6 +21,7 @@
 import android.test.AndroidTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.view.View;
+import android.widget.LinearLayout;
 
 import com.google.common.collect.Lists;
 
@@ -68,7 +69,7 @@
         mCursor = new MatrixCursor(CallLogQuery._PROJECTION);
         mCursor.moveToFirst();
         // The views into which to store the data.
-        mView = new CallLogListItemView(getContext());
+        mView = new LinearLayout(getContext());
         mView.setTag(CallLogListItemViews.createForTest(getContext()));
     }
 
diff --git a/tests/src/com/android/dialer/widget/ActionBarControllerTest.java b/tests/src/com/android/dialer/widget/ActionBarControllerTest.java
index cafa747..2e38838 100644
--- a/tests/src/com/android/dialer/widget/ActionBarControllerTest.java
+++ b/tests/src/com/android/dialer/widget/ActionBarControllerTest.java
@@ -17,25 +17,53 @@
 package com.android.dialer.widget;
 
 import android.app.ActionBar;
+import android.app.Activity;
 import android.content.Context;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.AndroidTestCase;
 import android.test.InstrumentationTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
+import android.view.View;
 
+import com.android.dialer.DialtactsActivity;
 import com.android.dialer.widget.ActionBarController.ActivityUi;
+import com.android.internal.app.WindowDecorActionBar;
 
 @SmallTest
-public class ActionBarControllerTest extends InstrumentationTestCase {
+public class ActionBarControllerTest extends ActivityInstrumentationTestCase2<DialtactsActivity> {
 
     private static final int ACTION_BAR_HEIGHT = 100;
     private ActionBarController mActionBarController;
     private SearchEditTextLayout mSearchBox;
     private MockActivityUi mActivityUi;
 
+    private class MockActionBar extends WindowDecorActionBar {
+        private int mHideOffset = 0;
+
+        public MockActionBar(Activity activity) {
+            super(activity);
+        }
+
+        @Override
+        public void setHideOffset(int offset) {
+            mHideOffset = offset;
+        }
+
+        @Override
+        public int getHideOffset() {
+            return mHideOffset;
+        }
+    }
+
     private class MockActivityUi implements ActivityUi {
         boolean isInSearchUi;
         boolean hasSearchQuery;
         boolean shouldShowActionBar;
-        int actionBarHideOffset;
+        private ActionBar mActionBar;
+
+        public MockActivityUi() {
+             mActionBar = new MockActionBar(getActivity());
+        }
 
         @Override
         public boolean isInSearchUi() {
@@ -59,7 +87,7 @@
 
         @Override
         public ActionBar getActionBar() {
-            return null;
+            return mActionBar;
         }
     }
 
@@ -83,6 +111,11 @@
         }
     }
 
+    public ActionBarControllerTest() {
+        super(DialtactsActivity.class);
+    }
+
+
     @Override
     protected void setUp() {
         mActivityUi = new MockActivityUi();