Merge "Fix clear call log option in overflow menu" into klp-dev
diff --git a/res/drawable-hdpi/ic_star_marked_as_fav.png b/res/drawable-hdpi/ic_star_marked_as_fav.png
new file mode 100644
index 0000000..8a138c4
--- /dev/null
+++ b/res/drawable-hdpi/ic_star_marked_as_fav.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_star_marked_as_fav.png b/res/drawable-mdpi/ic_star_marked_as_fav.png
new file mode 100644
index 0000000..ee1b5ec
--- /dev/null
+++ b/res/drawable-mdpi/ic_star_marked_as_fav.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_star_marked_as_fav.png b/res/drawable-xhdpi/ic_star_marked_as_fav.png
new file mode 100644
index 0000000..372747a
--- /dev/null
+++ b/res/drawable-xhdpi/ic_star_marked_as_fav.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_star_marked_as_fav.png b/res/drawable-xxhdpi/ic_star_marked_as_fav.png
new file mode 100644
index 0000000..3eeff4c
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_star_marked_as_fav.png
Binary files differ
diff --git a/res/layout/phone_favorite_regular_row_view.xml b/res/layout/phone_favorite_regular_row_view.xml
index bf63642..b3c37d8 100644
--- a/res/layout/phone_favorite_regular_row_view.xml
+++ b/res/layout/phone_favorite_regular_row_view.xml
@@ -53,6 +53,35 @@
             android:ellipsize="marquee"
             android:textAlignment="viewStart" />
 
+        <TextView
+            android:id="@+id/contact_tile_phone_type"
+            android:layout_height="wrap_content"
+            android:layout_width="wrap_content"
+            android:layout_below="@id/contact_tile_name"
+            android:layout_toRightOf="@id/contact_tile_quick"
+            android:layout_toEndOf="@id/contact_tile_quick"
+            android:textSize="12sp"
+            android:ellipsize="marquee"
+            android:singleLine="true"
+            android:textColor="@color/dialtacts_secondary_text_color"
+            android:layout_marginLeft="8dip"
+            android:layout_marginStart="8dip"
+            android:layout_gravity="bottom" />
+
+        <ImageView
+            android:id="@+id/contact_favorite_star"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignRight="@id/contact_tile_quick"
+            android:layout_alignEnd="@id/contact_tile_quick"
+            android:layout_alignBottom="@id/contact_tile_quick"
+            android:layout_marginRight="7dip"
+            android:layout_marginEnd="7dip"
+            android:layout_marginBottom="7dip"
+            android:layout_centerVertical="true"
+            android:src="@drawable/ic_star_marked_as_fav"
+            android:visibility="gone" />
+
     </RelativeLayout>
 
     <LinearLayout
diff --git a/res/layout/phone_favorite_tile_view.xml b/res/layout/phone_favorite_tile_view.xml
index 1117bdc..1e79a10 100644
--- a/res/layout/phone_favorite_tile_view.xml
+++ b/res/layout/phone_favorite_tile_view.xml
@@ -66,6 +66,20 @@
             android:nextFocusRight="@+id/contact_tile_secondary_button"
             android:background="?android:attr/selectableItemBackground" />
 
+        <ImageView
+            android:id="@+id/contact_favorite_star"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignRight="@id/contact_tile_image"
+            android:layout_alignEnd="@id/contact_tile_image"
+            android:layout_alignBottom="@id/contact_tile_image"
+            android:layout_marginRight="7dip"
+            android:layout_marginEnd="7dip"
+            android:layout_marginBottom="7dip"
+            android:src="@drawable/ic_star_marked_as_fav"
+            android:visibility="gone" />
+
+
         <ImageButton
             android:id="@id/contact_tile_secondary_button"
             android:src="@drawable/ic_contact_info"
diff --git a/res/mipmap-xxxhdpi/ic_launcher_phone.png b/res/mipmap-xxxhdpi/ic_launcher_phone.png
new file mode 100644
index 0000000..8c92ac1
--- /dev/null
+++ b/res/mipmap-xxxhdpi/ic_launcher_phone.png
Binary files differ
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 958dbfb..2f04833 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -625,6 +625,6 @@
     <string name="num_missed_calls"><xliff:g id="number">%s</xliff:g> new missed calls</string>
 
     <!-- Shows when there are no favorites. -->
-    <string name="no_favorites">Favorites &amp; contacts you call often will show here. So, start calling.</string>
+    <string name="no_favorites">Favorites &amp; contacts you\ncall often will show here.\nSo, start calling.</string>
 
 </resources>
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java
index 7a08708..79a9956 100644
--- a/src/com/android/dialer/CallDetailActivity.java
+++ b/src/com/android/dialer/CallDetailActivity.java
@@ -632,7 +632,7 @@
             // If this is not a regular number, there is no point in looking it up in the contacts.
             ContactInfo info =
                     PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)
-                    && new PhoneNumberUtilsWrapper().isVoicemailNumber(number)
+                    && !new PhoneNumberUtilsWrapper().isVoicemailNumber(number)
                             ? mContactInfoHelper.lookupNumber(number, countryIso)
                             : null;
             if (info == null) {
diff --git a/src/com/android/dialer/list/PhoneFavoriteRegularRowView.java b/src/com/android/dialer/list/PhoneFavoriteRegularRowView.java
index b4ad784..91b09d7 100644
--- a/src/com/android/dialer/list/PhoneFavoriteRegularRowView.java
+++ b/src/com/android/dialer/list/PhoneFavoriteRegularRowView.java
@@ -18,15 +18,11 @@
 import android.content.Context;
 import android.content.res.Resources;
 import android.util.AttributeSet;
-import android.view.GestureDetector;
 import android.view.View;
 
 import com.android.contacts.common.util.ViewUtil;
 import com.android.dialer.R;
 
-import com.android.dialer.list.PhoneFavoritesTileAdapter.ContactTileRow;
-
-
 public class PhoneFavoriteRegularRowView extends PhoneFavoriteTileView {
     private static final String TAG = PhoneFavoriteRegularRowView.class.getSimpleName();
     private static final boolean DEBUG = false;
diff --git a/src/com/android/dialer/list/PhoneFavoriteSquareTileView.java b/src/com/android/dialer/list/PhoneFavoriteSquareTileView.java
index e2548a3..85e7216 100644
--- a/src/com/android/dialer/list/PhoneFavoriteSquareTileView.java
+++ b/src/com/android/dialer/list/PhoneFavoriteSquareTileView.java
@@ -24,6 +24,7 @@
 import android.widget.ImageButton;
 
 import com.android.contacts.common.R;
+import com.android.contacts.common.list.ContactEntry;
 
 import java.util.regex.Pattern;
 
@@ -48,12 +49,6 @@
         super.onFinishInflate();
 
         mSecondaryButton = (ImageButton) findViewById(R.id.contact_tile_secondary_button);
-        mSecondaryButton.setOnClickListener(new OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                launchQuickContact();
-            }
-        });
     }
 
     @Override
@@ -74,4 +69,29 @@
         if (tokens.length < 1) return name;
         return tokens[0];
     }
+
+    @Override
+    public void loadFromContact(ContactEntry entry) {
+        super.loadFromContact(entry);
+        if (entry != null) {
+            final boolean contactIsFavorite = entry.isFavorite;
+            mSecondaryButton.setVisibility(contactIsFavorite ? GONE : VISIBLE);
+
+            if (contactIsFavorite) {
+                mStarView.setOnClickListener(new OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        launchQuickContact();
+                    }
+                });
+            } else {
+                mSecondaryButton.setOnClickListener(new OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        launchQuickContact();
+                    }
+                });
+            }
+        }
+    }
 }
diff --git a/src/com/android/dialer/list/PhoneFavoriteTileView.java b/src/com/android/dialer/list/PhoneFavoriteTileView.java
index 57d258f..7657451 100644
--- a/src/com/android/dialer/list/PhoneFavoriteTileView.java
+++ b/src/com/android/dialer/list/PhoneFavoriteTileView.java
@@ -27,6 +27,7 @@
 import android.view.GestureDetector;
 import android.view.MotionEvent;
 import android.view.View;
+import android.widget.ImageView;
 
 import com.android.contacts.common.MoreContactUtils;
 import com.android.contacts.common.list.ContactEntry;
@@ -58,6 +59,8 @@
     private View mUndoRemovalButton;
     /** The view that holds the list view row. */
     protected ContactTileRow mParentRow;
+    /** The view that indicates whether the contact is a favorate. */
+    protected ImageView mStarView;
 
     /** Users' most frequent phone number. */
     private String mPhoneNumberString;
@@ -81,6 +84,7 @@
         mRemovalDialogue = findViewById(com.android.dialer.R.id.favorite_remove_dialogue);
         mUndoRemovalButton = findViewById(com.android.dialer.R.id
                 .favorite_remove_undo_button);
+        mStarView = (ImageView) findViewById(com.android.dialer.R.id.contact_favorite_star);
 
         mUndoRemovalButton.setOnClickListener(new OnClickListener() {
             @Override
@@ -118,6 +122,8 @@
         if (entry != null) {
             // Grab the phone-number to call directly... see {@link onClick()}
             mPhoneNumberString = entry.phoneNumber;
+
+            mStarView.setVisibility(entry.isFavorite ? VISIBLE : GONE);
             // If this is a blank entry, don't show anything.
             // TODO krelease:Just hide the view for now. For this to truly look like an empty row
             // the entire ContactTileRow needs to be hidden.
diff --git a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
index 2b232e8..1247d35 100644
--- a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
+++ b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
@@ -106,16 +106,11 @@
     protected int mPresenceIndex;
     protected int mStatusIndex;
 
-    /**
-     * Only valid when {@link DisplayType#STREQUENT_PHONE_ONLY} is true
-     *
-     * TODO krelease: Remove entirely if not needed
-     */
     private int mPhoneNumberIndex;
     private int mPhoneNumberTypeIndex;
     private int mPhoneNumberLabelIndex;
     protected int mPinnedIndex;
-    protected int mContactIdForFrequentIndex;
+    protected int mContactIdIndex;
 
     private final int mPaddingInPixels;
 
@@ -209,7 +204,7 @@
         mPhoneNumberTypeIndex = ContactTileLoaderFactory.PHONE_NUMBER_TYPE;
         mPhoneNumberLabelIndex = ContactTileLoaderFactory.PHONE_NUMBER_LABEL;
         mPinnedIndex = ContactTileLoaderFactory.PINNED;
-        mContactIdForFrequentIndex = ContactTileLoaderFactory.CONTACT_ID_FOR_FREQUENT;
+        mContactIdIndex = ContactTileLoaderFactory.CONTACT_ID_FOR_DATA;
     }
 
     /**
@@ -274,14 +269,12 @@
             final int starred = cursor.getInt(mStarredIndex);
             final long id;
 
-            if (starred > 0) {
-                id = cursor.getLong(mIdIndex);
-            } else if (counter >= TILES_SOFT_LIMIT) {
+            // We display a maximum of TILES_SOFT_LIMIT contacts, or the total number of starred
+            // whichever is greater.
+            if (starred < 1 && counter >= TILES_SOFT_LIMIT) {
                 break;
             } else {
-                // The contact id for frequent contacts is stored in the .contact_id field rather
-                // than the _id field
-                id = cursor.getLong(mContactIdForFrequentIndex);
+                id = cursor.getLong(mContactIdIndex);
             }
 
             if (duplicates.get(id) == null) {
@@ -294,6 +287,7 @@
             final String lookupKey = cursor.getString(mLookupIndex);
             final int pinned = cursor.getInt(mPinnedIndex);
             final String name = cursor.getString(mNameIndex);
+            final boolean isStarred = cursor.getInt(mStarredIndex) > 0;
 
             final ContactEntry contact = new ContactEntry();
 
@@ -303,22 +297,14 @@
             contact.photoUri = (photoUri != null ? Uri.parse(photoUri) : null);
             contact.lookupKey = ContentUris.withAppendedId(
                     Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey), id);
+            contact.isFavorite = isStarred;
 
-
-            // TODO krelease: These columns are temporarily unused for now so that
-            // the contact tiles will be treated like favorites since they don't have a phone
-            // number. Depending on how the final UX goes we will either remove or enable
-            // them again.
-
-            /*
-                // Set phone number, label and status
-                final int phoneNumberType = cursor.getInt(mPhoneNumberTypeIndex);
-                final String phoneNumberCustomLabel = cursor.getString(mPhoneNumberLabelIndex);
-                contact.phoneLabel = (String) Phone.getTypeLabel(mResources, phoneNumberType,
-                        phoneNumberCustomLabel);
-                contact.phoneNumber = cursor.getString(mPhoneNumberIndex);
-                contact.status = cursor.getString(mStatusIndex);
-            */
+            // Set phone number, label and status
+            final int phoneNumberType = cursor.getInt(mPhoneNumberTypeIndex);
+            final String phoneNumberCustomLabel = cursor.getString(mPhoneNumberLabelIndex);
+            contact.phoneLabel = (String) Phone.getTypeLabel(mResources, phoneNumberType,
+                    phoneNumberCustomLabel);
+            contact.phoneNumber = cursor.getString(mPhoneNumberIndex);
 
             contact.pinned = pinned;
             mContactEntries.add(contact);
@@ -633,8 +619,7 @@
             if (changed && mDropEntryIndex < PIN_LIMIT) {
                 final ContentValues cv = getReflowedPinnedPositions(mContactEntries, mDraggedEntry,
                         mDraggedEntryIndex, mDropEntryIndex);
-                final Uri pinUri = PinnedPositions.UPDATE_URI.buildUpon().appendQueryParameter(
-                        PinnedPositions.STAR_WHEN_PINNING, "true").build();
+                final Uri pinUri = PinnedPositions.UPDATE_URI.buildUpon().build();
                 // update the database here with the new pinned positions
                 mContext.getContentResolver().update(pinUri, cv, null, null);
             }