Merge "Import translations. DO NOT MERGE" into klp-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 37b78c0..6f37841 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -67,7 +67,7 @@
             android:launchMode="singleTask"
             android:clearTaskOnLaunch="true"
             android:icon="@mipmap/ic_launcher_phone"
-            android:screenOrientation="nosensor"
+            android:screenOrientation="portrait"
             android:enabled="@*android:bool/config_voice_capable"
             android:windowSoftInputMode="stateAlwaysHidden|adjustNothing">
             <intent-filter>
diff --git a/res/menu/dialtacts_options.xml b/res/menu/dialtacts_options.xml
index b306979..7e84818 100644
--- a/res/menu/dialtacts_options.xml
+++ b/res/menu/dialtacts_options.xml
@@ -21,9 +21,12 @@
         android:id="@+id/menu_clear_frequents"
         android:title="@string/menu_clear_frequents" />
     <item
-        android:id="@+id/add_contact"
+        android:id="@+id/menu_add_contact"
         android:title="@string/menu_newContact"/>
     <item
+        android:id="@+id/menu_all_contacts"
+        android:title="@string/menu_allContacts"/>
+    <item
         android:id="@+id/menu_call_settings"
         android:title="@string/call_settings"
         android:orderInCategory="2" />
diff --git a/res/menu/phone_favorite_options.xml b/res/menu/phone_favorite_options.xml
deleted file mode 100644
index e37759c..0000000
--- a/res/menu/phone_favorite_options.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- 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.
--->
-<menu xmlns:android="http://schemas.android.com/apk/res/android">
-    <item
-        android:id="@+id/menu_import_export"
-        android:title="@string/menu_import_export" />
-
-    <item
-        android:id="@+id/menu_clear_frequents"
-        android:title="@string/menu_clear_frequents" />
-
-    <item
-        android:id="@+id/menu_accounts"
-        android:title="@string/menu_accounts" />
-</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3235d77..65746bb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -338,6 +338,9 @@
     <!-- Menu item to create a new contact -->
     <string name="menu_newContact">New contact</string>
 
+    <!-- Menu item to display all contacts -->
+    <string name="menu_allContacts">All contacts</string>
+
     <!-- Title bar for call detail screen -->
     <string name="callDetailTitle">Call details</string>
 
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 4e5592a..99855f4 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -347,7 +347,7 @@
             case R.id.menu_clear_frequents:
                 ClearFrequentsDialog.show(getFragmentManager());
                 return true;
-            case R.id.add_contact:
+            case R.id.menu_add_contact:
                 try {
                     startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
                 } catch (ActivityNotFoundException e) {
@@ -360,6 +360,10 @@
             case R.id.menu_call_settings:
                 final Intent settingsIntent = DialtactsActivity.getCallSettingsIntent();
                 startActivity(settingsIntent);
+                return true;
+            case R.id.menu_all_contacts:
+                onShowAllContacts();
+                return true;
         }
         return false;
     }
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index da29bbd..9ac7bea 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -598,10 +598,9 @@
                     formattedNumber, countryIso, geocode, callTypes, date,
                     duration);
         } else {
-            // We do not pass a photo id since we do not need the high-res picture.
             details = new PhoneCallDetails(number, numberPresentation,
                     formattedNumber, countryIso, geocode, callTypes, date,
-                    duration, name, ntype, label, lookupUri, null);
+                    duration, name, ntype, label, lookupUri, photoUri);
         }
 
         final boolean isNew = c.getInt(CallLogQuery.IS_READ) == 0;
diff --git a/src/com/android/dialer/calllog/ContactInfo.java b/src/com/android/dialer/calllog/ContactInfo.java
index 08633f8..ac858df 100644
--- a/src/com/android/dialer/calllog/ContactInfo.java
+++ b/src/com/android/dialer/calllog/ContactInfo.java
@@ -24,7 +24,7 @@
 /**
  * Information for a contact as needed by the Call Log.
  */
-public final class ContactInfo {
+public class ContactInfo {
     public Uri lookupUri;
     public String name;
     public int type;
diff --git a/src/com/android/dialer/list/PhoneFavoriteSquareTileView.java b/src/com/android/dialer/list/PhoneFavoriteSquareTileView.java
index 17f2b8a..e2548a3 100644
--- a/src/com/android/dialer/list/PhoneFavoriteSquareTileView.java
+++ b/src/com/android/dialer/list/PhoneFavoriteSquareTileView.java
@@ -17,16 +17,15 @@
 package com.android.dialer.list;
 
 import android.content.Context;
-import android.content.Intent;
 import android.provider.ContactsContract.QuickContact;
+import android.text.TextUtils;
 import android.util.AttributeSet;
-import android.view.GestureDetector;
 import android.view.View;
 import android.widget.ImageButton;
 
 import com.android.contacts.common.R;
-import com.android.dialer.list.PhoneFavoriteDragAndDropListeners.PhoneFavoriteDragListener;
-import com.android.dialer.list.PhoneFavoritesTileAdapter.ContactTileRow;
+
+import java.util.regex.Pattern;
 
 /**
  * Displays the contact's picture overlayed with their name
@@ -36,6 +35,10 @@
     private static final String TAG = PhoneFavoriteSquareTileView.class.getSimpleName();
     private ImageButton mSecondaryButton;
 
+    // TODO: Use a more expansive name token separator if needed. For now it should be fine to
+    // not split by dashes, underscore etc.
+    private static final Pattern NAME_TOKEN_SEPARATOR_PATTERN = Pattern.compile("\\s+");
+
     public PhoneFavoriteSquareTileView(Context context, AttributeSet attrs) {
         super(context, attrs);
     }
@@ -63,4 +66,12 @@
         QuickContact.showQuickContact(getContext(), PhoneFavoriteSquareTileView.this,
                 getLookupUri(), QuickContact.MODE_LARGE, null);
     }
+
+    @Override
+    protected String getNameForView(String name) {
+        if (TextUtils.isEmpty(name)) return name;
+        final String[] tokens = NAME_TOKEN_SEPARATOR_PATTERN.split(name, 2);
+        if (tokens.length < 1) return name;
+        return tokens[0];
+    }
 }
diff --git a/src/com/android/dialer/list/RegularSearchFragment.java b/src/com/android/dialer/list/RegularSearchFragment.java
index 47dd075..ccbd3d0 100644
--- a/src/com/android/dialer/list/RegularSearchFragment.java
+++ b/src/com/android/dialer/list/RegularSearchFragment.java
@@ -15,10 +15,17 @@
  */
 package com.android.dialer.list;
 
+import com.android.contacts.common.list.ContactEntryListAdapter;
+import com.android.dialerbind.ServiceFactory;
+import com.android.dialer.service.CachedNumberLookupService;
+
 public class RegularSearchFragment extends SearchFragment {
 
     private static final int SEARCH_DIRECTORY_RESULT_LIMIT = 5;
 
+    private static final CachedNumberLookupService mCachedNumberLookupService =
+        ServiceFactory.newCachedNumberLookupService();
+
     public RegularSearchFragment() {
         configureDirectorySearch();
     }
@@ -27,4 +34,22 @@
         setDirectorySearchEnabled(true);
         setDirectoryResultLimit(SEARCH_DIRECTORY_RESULT_LIMIT);
     }
+
+    @Override
+    protected ContactEntryListAdapter createListAdapter() {
+        RegularSearchListAdapter adapter = new RegularSearchListAdapter(getActivity());
+        adapter.setDisplayPhotos(true);
+        adapter.setUseCallableUri(usesCallableUri());
+        return adapter;
+    }
+
+    @Override
+    protected void cacheContactInfo(int position) {
+        if (mCachedNumberLookupService != null) {
+            final RegularSearchListAdapter adapter =
+                (RegularSearchListAdapter) getAdapter();
+            mCachedNumberLookupService.addContact(getContext(),
+                    adapter.getContactInfo(position));
+        }
+    }
 }
diff --git a/src/com/android/dialer/list/RegularSearchListAdapter.java b/src/com/android/dialer/list/RegularSearchListAdapter.java
new file mode 100644
index 0000000..390dbb5
--- /dev/null
+++ b/src/com/android/dialer/list/RegularSearchListAdapter.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2013 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.list;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.ContactsContract;
+
+import com.android.contacts.common.list.DirectoryPartition;
+import com.android.contacts.common.list.PhoneNumberListAdapter;
+import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo;
+
+/**
+ * List adapter to display regular search results.
+ */
+public class RegularSearchListAdapter extends PhoneNumberListAdapter {
+
+    public RegularSearchListAdapter(Context context) {
+        super(context);
+    }
+
+    public CachedContactInfo getContactInfo(int position) {
+        CachedContactInfo info = new CachedContactInfo();
+        final Cursor item = (Cursor) getItem(position);
+        if (item != null) {
+            info.name = item.getString(PhoneQuery.DISPLAY_NAME);
+            info.type = item.getInt(PhoneQuery.PHONE_TYPE);
+            info.label = item.getString(PhoneQuery.PHONE_LABEL);
+            info.number = item.getString(PhoneQuery.PHONE_NUMBER);
+            final String photoUriStr = item.getString(PhoneQuery.PHOTO_URI);
+            info.photoUri = photoUriStr == null ? null : Uri.parse(photoUriStr);
+            info.lookupKey = item.getString(PhoneQuery.LOOKUP_KEY);
+
+            final int partitionIndex = getPartitionForPosition(position);
+            final DirectoryPartition partition =
+                (DirectoryPartition) getPartition(partitionIndex);
+            final long directoryId = partition.getDirectoryId();
+            if (isExtendedDirectory(directoryId)) {
+               info.sourceType = CachedContactInfo.SOURCE_TYPE_EXTENDED;
+                // TODO source_id for extended directory?
+            } else {
+                info.sourceType = CachedContactInfo.SOURCE_TYPE_DIRECTORY;
+                info.sourceId = (int) directoryId;
+            }
+        }
+        return info;
+    }
+}
diff --git a/src/com/android/dialer/service/CachedNumberLookupService.java b/src/com/android/dialer/service/CachedNumberLookupService.java
index a08c285..27bf589 100644
--- a/src/com/android/dialer/service/CachedNumberLookupService.java
+++ b/src/com/android/dialer/service/CachedNumberLookupService.java
@@ -1,10 +1,23 @@
 package com.android.dialer.service;
 
+import android.content.ContentValues;
 import android.content.Context;
 
 import com.android.dialer.calllog.ContactInfo;
 
 public interface CachedNumberLookupService {
+
+    public class CachedContactInfo extends ContactInfo {
+        public static final int SOURCE_TYPE_DIRECTORY = 1;
+        public static final int SOURCE_TYPE_EXTENDED = 2;
+        public static final int SOURCE_TYPE_PLACES = 3;
+        public static final int SOURCE_TYPE_PROFILE = 4;
+
+        public int    sourceType;
+        public int    sourceId;
+        public String lookupKey;
+    }
+
     /**
      * Perform a lookup using the cached number lookup service to return contact
      * information stored in the cache that corresponds to the given number.
@@ -16,4 +29,6 @@
      * not found in the cache, and null if there was an error when querying the cache.
      */
     public ContactInfo lookupCachedContactFromNumber(Context context, String number);
+
+    public void addContact(Context context, CachedContactInfo info);
 }