Remove dependencies on "Legacy" classes.

Prefactor to remove dependencies on "Legacy" classes in
PhoneNumberPickerFragment. PhoneNumberPickerFragment needs to be used
by Dialer but the Legacy class do not.  This change will allow
PhoneNumberPickerFragment to be moved into common without the other
legacy classes.

Bug: 6993891
Change-Id: I598c985f41188ab6ac65898f31236056be5007bf
diff --git a/src/com/android/contacts/activities/ContactSelectionActivity.java b/src/com/android/contacts/activities/ContactSelectionActivity.java
index b527f84..078bed7 100644
--- a/src/com/android/contacts/activities/ContactSelectionActivity.java
+++ b/src/com/android/contacts/activities/ContactSelectionActivity.java
@@ -48,13 +48,13 @@
 import com.android.contacts.list.ContactsRequest;
 import com.android.contacts.common.list.DirectoryListLoader;
 import com.android.contacts.list.EmailAddressPickerFragment;
+import com.android.contacts.list.LegacyPhoneNumberPickerFragment;
 import com.android.contacts.list.OnContactPickerActionListener;
 import com.android.contacts.list.OnEmailAddressPickerActionListener;
 import com.android.contacts.list.OnPhoneNumberPickerActionListener;
 import com.android.contacts.list.OnPostalAddressPickerActionListener;
 import com.android.contacts.list.PhoneNumberPickerFragment;
 import com.android.contacts.list.PostalAddressPickerFragment;
-import com.android.contacts.widget.ContextMenuAdapter;
 import com.google.common.collect.Sets;
 
 import java.util.Set;
@@ -338,7 +338,7 @@
             }
 
             case ContactsRequest.ACTION_PICK_PHONE: {
-                PhoneNumberPickerFragment fragment = new PhoneNumberPickerFragment();
+                PhoneNumberPickerFragment fragment = getPhoneNumberPickerFragment(mRequest);
                 mListFragment = fragment;
                 break;
             }
@@ -349,7 +349,7 @@
             }
 
             case ContactsRequest.ACTION_CREATE_SHORTCUT_CALL: {
-                PhoneNumberPickerFragment fragment = new PhoneNumberPickerFragment();
+                PhoneNumberPickerFragment fragment = getPhoneNumberPickerFragment(mRequest);
                 fragment.setShortcutAction(Intent.ACTION_CALL);
 
                 mListFragment = fragment;
@@ -357,7 +357,7 @@
             }
 
             case ContactsRequest.ACTION_CREATE_SHORTCUT_SMS: {
-                PhoneNumberPickerFragment fragment = new PhoneNumberPickerFragment();
+                PhoneNumberPickerFragment fragment = getPhoneNumberPickerFragment(mRequest);
                 fragment.setShortcutAction(Intent.ACTION_SENDTO);
 
                 mListFragment = fragment;
@@ -374,6 +374,9 @@
                 throw new IllegalStateException("Invalid action code: " + mActionCode);
         }
 
+        // Setting compatibility is no longer needed for PhoneNumberPickerFragment since that logic
+        // has been separated into LegacyPhoneNumberPickerFragment.  But we still need to set
+        // compatibility for other fragments.
         mListFragment.setLegacyCompatibilityMode(mRequest.isLegacyCompatibilityMode());
         mListFragment.setDirectoryResultLimit(DEFAULT_DIRECTORY_RESULT_LIMIT);
 
@@ -382,6 +385,14 @@
                 .commitAllowingStateLoss();
     }
 
+    private PhoneNumberPickerFragment getPhoneNumberPickerFragment(ContactsRequest request) {
+        if (mRequest.isLegacyCompatibilityMode()) {
+            return new LegacyPhoneNumberPickerFragment();
+        } else {
+            return new PhoneNumberPickerFragment();
+        }
+    }
+
     public void setupActionListener() {
         if (mListFragment instanceof ContactPickerFragment) {
             ((ContactPickerFragment) mListFragment).setOnContactPickerActionListener(
diff --git a/src/com/android/contacts/list/LegacyPhoneNumberPickerFragment.java b/src/com/android/contacts/list/LegacyPhoneNumberPickerFragment.java
new file mode 100644
index 0000000..08b1477
--- /dev/null
+++ b/src/com/android/contacts/list/LegacyPhoneNumberPickerFragment.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2012 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.contacts.list;
+
+import android.net.Uri;
+import android.util.Log;
+
+import com.android.contacts.common.list.ContactEntryListAdapter;
+import com.android.contacts.common.list.ContactListItemView;
+
+/**
+ * Version of PhoneNumberPickerFragment used specifically for legacy support.
+ */
+public class LegacyPhoneNumberPickerFragment extends PhoneNumberPickerFragment {
+
+    private static final String TAG = LegacyPhoneNumberPickerFragment.class.getSimpleName();
+
+    @Override
+    protected boolean getVisibleScrollbarEnabled() {
+        return false;
+    }
+
+    @Override
+    protected Uri getPhoneUri(int position) {
+        final LegacyPhoneNumberListAdapter adapter = (LegacyPhoneNumberListAdapter) getAdapter();
+        return adapter.getPhoneUri(position);
+    }
+
+    @Override
+    protected ContactEntryListAdapter createListAdapter() {
+        LegacyPhoneNumberListAdapter adapter = new LegacyPhoneNumberListAdapter(getActivity());
+        adapter.setDisplayPhotos(true);
+        return adapter;
+    }
+
+    @Override
+    protected void setPhotoPosition(ContactEntryListAdapter adapter) {
+        // no-op
+    }
+
+    @Override
+    protected void startPhoneNumberShortcutIntent(Uri uri) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void setPhotoPosition(ContactListItemView.PhotoPosition photoPosition) {
+        Log.w(TAG, "setPhotoPosition() is ignored in legacy compatibility mode.");
+    }
+}
diff --git a/src/com/android/contacts/list/PhoneNumberPickerFragment.java b/src/com/android/contacts/list/PhoneNumberPickerFragment.java
index 3fc3135..491aa70 100644
--- a/src/com/android/contacts/list/PhoneNumberPickerFragment.java
+++ b/src/com/android/contacts/list/PhoneNumberPickerFragment.java
@@ -108,7 +108,11 @@
         mAccountFilterHeader.setOnClickListener(mFilterHeaderClickListener);
         updateFilterHeaderView();
 
-        setVisibleScrollbarEnabled(!isLegacyCompatibilityMode());
+        setVisibleScrollbarEnabled(getVisibleScrollbarEnabled());
+    }
+
+    protected boolean getVisibleScrollbarEnabled() {
+        return true;
     }
 
     @Override
@@ -176,15 +180,7 @@
 
     @Override
     protected void onItemClick(int position, long id) {
-        final Uri phoneUri;
-        if (!isLegacyCompatibilityMode()) {
-            PhoneNumberListAdapter adapter = (PhoneNumberListAdapter) getAdapter();
-            phoneUri = adapter.getDataUri(position);
-
-        } else {
-            LegacyPhoneNumberListAdapter adapter = (LegacyPhoneNumberListAdapter) getAdapter();
-            phoneUri = adapter.getPhoneUri(position);
-        }
+        final Uri phoneUri = getPhoneUri(position);
 
         if (phoneUri != null) {
             pickPhoneNumber(phoneUri);
@@ -193,6 +189,11 @@
         }
     }
 
+    protected Uri getPhoneUri(int position) {
+        final PhoneNumberListAdapter adapter = (PhoneNumberListAdapter) getAdapter();
+        return adapter.getDataUri(position);
+    }
+
     @Override
     protected void startLoading() {
         mLoaderStarted = true;
@@ -217,16 +218,10 @@
 
     @Override
     protected ContactEntryListAdapter createListAdapter() {
-        if (!isLegacyCompatibilityMode()) {
-            PhoneNumberListAdapter adapter = new PhoneNumberListAdapter(getActivity());
-            adapter.setDisplayPhotos(true);
-            adapter.setUseCallableUri(mUseCallableUri);
-            return adapter;
-        } else {
-            LegacyPhoneNumberListAdapter adapter = new LegacyPhoneNumberListAdapter(getActivity());
-            adapter.setDisplayPhotos(true);
-            return adapter;
-        }
+        PhoneNumberListAdapter adapter = new PhoneNumberListAdapter(getActivity());
+        adapter.setDisplayPhotos(true);
+        adapter.setUseCallableUri(mUseCallableUri);
+        return adapter;
     }
 
     @Override
@@ -242,9 +237,11 @@
             adapter.setFilter(mFilter);
         }
 
-        if (!isLegacyCompatibilityMode()) {
-            ((PhoneNumberListAdapter) adapter).setPhotoPosition(mPhotoPosition);
-        }
+        setPhotoPosition(adapter);
+    }
+
+    protected void setPhotoPosition(ContactEntryListAdapter adapter) {
+        ((PhoneNumberListAdapter) adapter).setPhotoPosition(mPhotoPosition);
     }
 
     @Override
@@ -256,14 +253,15 @@
         if (mShortcutAction == null) {
             mListener.onPickPhoneNumberAction(uri);
         } else {
-            if (isLegacyCompatibilityMode()) {
-                throw new UnsupportedOperationException();
-            }
-            ShortcutIntentBuilder builder = new ShortcutIntentBuilder(getActivity(), this);
-            builder.createPhoneNumberShortcutIntent(uri, mShortcutAction);
+            startPhoneNumberShortcutIntent(uri);
         }
     }
 
+    protected void startPhoneNumberShortcutIntent(Uri uri) {
+        ShortcutIntentBuilder builder = new ShortcutIntentBuilder(getActivity(), this);
+        builder.createPhoneNumberShortcutIntent(uri, mShortcutAction);
+    }
+
     public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) {
         mListener.onShortcutIntentCreated(shortcutIntent);
     }
@@ -304,13 +302,10 @@
 
     public void setPhotoPosition(ContactListItemView.PhotoPosition photoPosition) {
         mPhotoPosition = photoPosition;
-        if (!isLegacyCompatibilityMode()) {
-            final PhoneNumberListAdapter adapter = (PhoneNumberListAdapter) getAdapter();
-            if (adapter != null) {
-                adapter.setPhotoPosition(photoPosition);
-            }
-        } else {
-            Log.w(TAG, "setPhotoPosition() is ignored in legacy compatibility mode.");
+
+        final PhoneNumberListAdapter adapter = (PhoneNumberListAdapter) getAdapter();
+        if (adapter != null) {
+            adapter.setPhotoPosition(photoPosition);
         }
     }
 }