Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 92cb1500 authored by Frank Sposaro's avatar Frank Sposaro
Browse files

Added phone number and phone number type to frequent phone contacts.

Bug: 4975604
Change-Id: I75629dd9e8b52dc67317e1b80a010ad1f9613ee6
parent c275cb52
Loading
Loading
Loading
Loading
+72 −0
Original line number Diff line number Diff line
<?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.
-->
<view
    xmlns:android="http://schemas.android.com/apk/res/android"
    class="com.android.contacts.list.ContactTileView"
    android:focusable="true"
    android:background="@drawable/list_selector"
    android:paddingRight="16dip"
    android:paddingLeft="16dip" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <QuickContactBadge
            android:id="@+id/contact_tile_quick"
            android:layout_width="64dip"
            android:layout_height="64dip"
            android:scaleType="centerCrop"
            android:layout_alignParentLeft="true" />

        <TextView
            android:id="@+id/contact_tile_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:ellipsize="end"
            android:layout_marginLeft="8dip"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_marginTop="8dip"
            android:layout_toRightOf="@id/contact_tile_quick" />

        <TextView
            android:id="@+id/contact_tile_phone_number"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp"
            android:ellipsize="end"
            android:singleLine="true"
            android:textColor="#cccccc"
            android:layout_marginLeft="12dip"
            android:layout_toRightOf="@id/contact_tile_quick"
            android:layout_below="@id/contact_tile_name" />

        <TextView
            android:id="@+id/contact_tile_phone_type"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp"
            android:ellipsize="end"
            android:singleLine="true"
            android:textColor="#cccccc"
            android:layout_marginLeft="12dip"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@id/contact_tile_phone_number" />

    </RelativeLayout>

</view>
+16 −21
Original line number Diff line number Diff line
@@ -35,29 +35,24 @@
            android:layout_alignParentBottom="true"
            style="@style/ContactTileStarredShadowBox" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="48dip"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal" >

        <TextView
            android:id="@+id/contact_tile_name"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center_vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="8dip"
            android:layout_marginBottom="20dip"
            android:textColor="@android:color/white"
            stlye="@style/ContactTileStarredName" />

        <ImageButton
            android:id="@+id/contact_tile_secondary_button"
            android:src="@drawable/ic_tab_unselected_contacts"
                android:layout_height="match_parent"
                android:layout_width="wrap_content" />

        </LinearLayout>
            android:layout_height="@dimen/contact_tile_shadowbox_height"
            android:layout_width="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true" />

    </RelativeLayout>

+32 −8
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@ import android.content.Context;
import android.content.CursorLoader;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Contacts.Data;

/**
 * Used to create {@link CursorLoader}s to load different groups of {@link ContactTileView}s
@@ -36,14 +38,36 @@ public final class ContactTileLoaderFactory {
    public final static int CONTACT_PRESENCE = 5;
    public final static int CONTACT_STATUS = 6;

    // Only used for StrequentPhoneOnlyLoader
    public final static int PHONE_NUMBER = 5;
    public final static int PHONE_NUMBER_TYPE = 6;
    public final static int PHONE_NUMBER_LABEL = 7;

    private static final String[] COLUMNS = new String[] {
        Contacts._ID,
        Contacts.DISPLAY_NAME,
        Contacts.STARRED,
        Contacts.PHOTO_URI,
        Contacts.LOOKUP_KEY,
        Contacts.CONTACT_PRESENCE,
        Contacts.CONTACT_STATUS,
        Contacts._ID, // ..........................................0
        Contacts.DISPLAY_NAME, // .................................1
        Contacts.STARRED, // ......................................2
        Contacts.PHOTO_URI, // ....................................3
        Contacts.LOOKUP_KEY, // ...................................4
        Contacts.CONTACT_PRESENCE, // .............................5
        Contacts.CONTACT_STATUS, // ...............................6
    };

    /**
     * Projection used for the {@link Contacts#CONTENT_STREQUENT_URI}
     * query when {@link ContactsContract#STREQUENT_PHONE_ONLY} flag
     * is set to true. The main difference is the lack of presence
     * and status data and the addition of phone number and label.
     */
    private static final String[] COLUMNS_PHONE_ONLY = new String[] {
        Contacts._ID, // ..........................................0
        Contacts.DISPLAY_NAME, // .................................1
        Contacts.STARRED, // ......................................2
        Contacts.PHOTO_URI, // ....................................3
        Contacts.LOOKUP_KEY, // ...................................4
        Phone.NUMBER, // ..........................................5
        Phone.TYPE, // ............................................6
        Phone.LABEL // ............................................7
    };

    public static CursorLoader createStrequentLoader(Context context) {
@@ -54,7 +78,7 @@ public final class ContactTileLoaderFactory {
        Uri uri = Contacts.CONTENT_STREQUENT_URI.buildUpon()
                .appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "true").build();

        return new CursorLoader(context, uri, COLUMNS, null, null, null);
        return new CursorLoader(context, uri, COLUMNS_PHONE_ONLY, null, null, null);
    }

    public static CursorLoader createStarredLoader(Context context) {
+32 −2
Original line number Diff line number Diff line
@@ -19,11 +19,16 @@ import com.android.contacts.ContactPhotoManager;
import com.android.contacts.ContactTileLoaderFactory;
import com.android.contacts.GroupMemberLoader;
import com.android.contacts.R;
import com.android.contacts.model.AccountTypeManager;
import com.android.contacts.model.DataKind;

import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.view.View;
import android.view.View.OnClickListener;
@@ -62,6 +67,13 @@ public class ContactTileAdapter extends BaseAdapter {
    private int mPresenceIndex;
    private int mStatusIndex;

    /**
     * Only valid when {@link DisplayType#STREQUENT_PHONE_ONLY} is true
     */
    private int mPhoneNumberIndex;
    private int mPhoneNumberTypeIndex;
    private int mPhoneNumberLabelIndex;

    private boolean mIsQuickContactEnabled = false;

    /**
@@ -151,6 +163,10 @@ public class ContactTileAdapter extends BaseAdapter {
            mStarredIndex = ContactTileLoaderFactory.STARRED;
            mPresenceIndex = ContactTileLoaderFactory.CONTACT_PRESENCE;
            mStatusIndex = ContactTileLoaderFactory.CONTACT_STATUS;

            mPhoneNumberIndex = ContactTileLoaderFactory.PHONE_NUMBER;
            mPhoneNumberTypeIndex = ContactTileLoaderFactory.PHONE_NUMBER_TYPE;
            mPhoneNumberLabelIndex = ContactTileLoaderFactory.PHONE_NUMBER_LABEL;
        }
    }

@@ -168,7 +184,7 @@ public class ContactTileAdapter extends BaseAdapter {
    /**
     * Iterates over the {@link Cursor}
     * Returns position of the first NON Starred Contact
     * Returns -1 if not {@link DisplayType#}
     * Returns -1 if not {@link DisplayType#STREQUENT} or {@link DisplayType#STREQUENT_PHONE_ONLY}
     */
    private int getDividerPosition(Cursor cursor) {
        if (cursor == null || cursor.isClosed() || (mDisplayType != DisplayType.STREQUENT
@@ -204,6 +220,17 @@ public class ContactTileAdapter extends BaseAdapter {
                Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey), id);
        contact.presence = cursor.isNull(mPresenceIndex) ? null : cursor.getInt(mPresenceIndex);

        if (mDisplayType == DisplayType.STREQUENT_PHONE_ONLY) {
            int phoneNumberType = cursor.getInt(mPhoneNumberTypeIndex);
            String phoneNumberCustomLabel = cursor.getString(mPhoneNumberLabelIndex);
            contact.phoneLabel = (String) Phone.getTypeLabel(mContext.getResources(),
                    phoneNumberType, phoneNumberCustomLabel);
            contact.phoneNumber = cursor.getString(mPhoneNumberIndex);
        } else {
            contact.status = cursor.getString(mStatusIndex);
            contact.presence = cursor.isNull(mPresenceIndex) ? null : cursor.getInt(mPresenceIndex);
        }

        return contact;
    }

@@ -345,7 +372,8 @@ public class ContactTileAdapter extends BaseAdapter {
                return mIsQuickContactEnabled ?
                        R.layout.contact_tile_starred_quick_contact : R.layout.contact_tile_starred;
            case ViewTypes.FREQUENT:
                return R.layout.contact_tile_frequent;
                return mDisplayType == DisplayType.STREQUENT_PHONE_ONLY ?
                        R.layout.contact_tile_frequent_phone : R.layout.contact_tile_frequent;
            case ViewTypes.STARRED_WITH_SECONDARY_ACTION:
                return R.layout.contact_tile_starred_secondary_target;
            default:
@@ -466,6 +494,8 @@ public class ContactTileAdapter extends BaseAdapter {
    public static class ContactEntry {
        public String name;
        public String status;
        public String phoneLabel;
        public String phoneNumber;
        public Uri photoUri;
        public Uri lookupKey;
        public Integer presence;
+14 −5
Original line number Diff line number Diff line
@@ -21,9 +21,8 @@ import com.android.contacts.R;
import com.android.contacts.list.ContactTileAdapter.ContactEntry;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.ContactsContract.StatusUpdates;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
@@ -32,9 +31,6 @@ import android.widget.ImageView;
import android.widget.QuickContactBadge;
import android.widget.TextView;

import android.provider.ContactsContract.StatusUpdates;


/**
 * A ContactTile displays the contact's picture overlayed with their name
 */
@@ -47,6 +43,8 @@ public class ContactTileView extends FrameLayout {
    private QuickContactBadge mQuickContact;
    private TextView mName;
    private TextView mStatus;
    private TextView mPhoneLabel;
    private TextView mPhoneNumber;
    private ContactPhotoManager mPhotoManager = null;

    public ContactTileView(Context context, AttributeSet attrs) {
@@ -63,6 +61,8 @@ public class ContactTileView extends FrameLayout {
        mPhoto = (ImageView) findViewById(R.id.contact_tile_image);
        mPresence = (ImageView) findViewById(R.id.contact_tile_presence);
        mStatus = (TextView) findViewById(R.id.contact_tile_status);
        mPhoneLabel = (TextView) findViewById(R.id.contact_tile_phone_type);
        mPhoneNumber = (TextView) findViewById(R.id.contact_tile_phone_number);
    }

    public void setPhotoManager(ContactPhotoManager photoManager) {
@@ -97,6 +97,15 @@ public class ContactTileView extends FrameLayout {
                mStatus.setText(statusText);
            }

            if (mPhoneLabel != null) {
                mPhoneLabel.setText(entry.phoneLabel);
            }

            if (mPhoneNumber != null) {
                // TODO: Format number correctly
                mPhoneNumber.setText(entry.phoneNumber);
            }

            if (mQuickContact != null) {
                mQuickContact.assignContactUri(mLookupUri);
                mQuickContact.setImageBitmap(null);