From fe7e9e1d5a083bfe376df0d54bcf632f60012dcf Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Tue, 17 Oct 2017 15:54:45 -0700 Subject: Contacts are now searchable by company name. This change coalesces Cp2 contacts into a new cursor so that they can be associated with the Company name. The following logs can help explain how the data is organizes in the original cursor: display Name (A Pixel), lookupKey (3535i7a9673fc89b77de3), mimeType (vnd.android.cursor.item/name), data1 (A Pixel) display Name (A Pixel), lookupKey (3535i7a9673fc89b77de3), mimeType (vnd.android.cursor.item/note), data1 () display Name (A Pixel), lookupKey (3535i7a9673fc89b77de3), mimeType (vnd.android.cursor.item/group_membership), data1 (1) display Name (A Pixel), lookupKey (3535i7a9673fc89b77de3), mimeType (vnd.android.cursor.item/phone_v2), data1 (+1 650-200-7932) display Name (A Pixel), lookupKey (3535i7a9673fc89b77de3), mimeType (vnd.android.cursor.item/phone_v2), data1 (+1 540-555-6666) display Name (A Pixel), lookupKey (3535i7a9673fc89b77de3), mimeType (vnd.android.cursor.item/organization), data1 (Walmart) This is an example of what is returned for a single contact. We can easily associate contact rows together using the lookup key and determine which rows have relevant data by checking the mime type. I use the data here to coalesce the contacts together into one row for easy parsing in ContactFilterCursor. Rows with mime type phone_v2 contain contact information (for example, this contact has 2 phone numbers). Rows with mime type organization contain contact's company information (for example, this contact works at Walmart). Bug: 67675742,64894607,67848713 Test: existing + SCCT.filter_companyName PiperOrigin-RevId: 172528797 Change-Id: I5c9f66ff0c27276869295eff97bb0216f92995be --- .../dialer/searchfragment/cp2/Cp2Contact.java | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 java/com/android/dialer/searchfragment/cp2/Cp2Contact.java (limited to 'java/com/android/dialer/searchfragment/cp2/Cp2Contact.java') diff --git a/java/com/android/dialer/searchfragment/cp2/Cp2Contact.java b/java/com/android/dialer/searchfragment/cp2/Cp2Contact.java new file mode 100644 index 000000000..f199f679b --- /dev/null +++ b/java/com/android/dialer/searchfragment/cp2/Cp2Contact.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2017 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.searchfragment.cp2; + +import android.database.Cursor; +import android.support.annotation.Nullable; +import com.android.dialer.searchfragment.common.Projections; +import com.google.auto.value.AutoValue; + +/** POJO Representation for contacts returned in {@link SearchContactsCursorLoader}. */ +@AutoValue +public abstract class Cp2Contact { + + public abstract long phoneId(); + + public abstract int phoneType(); + + @Nullable + public abstract String phoneLabel(); + + public abstract String phoneNumber(); + + @Nullable + public abstract String displayName(); + + public abstract int photoId(); + + @Nullable + public abstract String photoUri(); + + public abstract String lookupKey(); + + public abstract int carrierPresence(); + + public abstract int contactId(); + + @Nullable + public abstract String companyName(); + + @Nullable + public abstract String nickName(); + + public abstract String mimeType(); + + /** Builder for {@link Cp2Contact}. */ + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder setPhoneId(long id); + + public abstract Builder setPhoneType(int type); + + public abstract Builder setPhoneLabel(@Nullable String label); + + public abstract Builder setPhoneNumber(String number); + + public abstract Builder setDisplayName(@Nullable String name); + + public abstract Builder setPhotoId(int id); + + public abstract Builder setPhotoUri(@Nullable String uri); + + public abstract Builder setLookupKey(String lookupKey); + + public abstract Builder setCarrierPresence(int presence); + + public abstract Builder setContactId(int id); + + public abstract Builder setCompanyName(@Nullable String name); + + public abstract Builder setNickName(@Nullable String nickName); + + public abstract Builder setMimeType(String mimeType); + + public abstract Cp2Contact build(); + } + + public static Builder builder() { + return new AutoValue_Cp2Contact.Builder(); + } + + public static Cp2Contact fromCursor(Cursor cursor) { + return Cp2Contact.builder() + .setPhoneId(cursor.getLong(Projections.CONTACT_ID)) + .setPhoneType(cursor.getInt(Projections.PHONE_TYPE)) + .setPhoneLabel(cursor.getString(Projections.PHONE_LABEL)) + .setPhoneNumber(cursor.getString(Projections.PHONE_NUMBER)) + .setDisplayName(cursor.getString(Projections.DISPLAY_NAME)) + .setPhotoId(cursor.getInt(Projections.PHOTO_ID)) + .setPhotoUri(cursor.getString(Projections.PHOTO_URI)) + .setLookupKey(cursor.getString(Projections.LOOKUP_KEY)) + .setCarrierPresence(cursor.getInt(Projections.CARRIER_PRESENCE)) + .setContactId(cursor.getInt(Projections.CONTACT_ID)) + .setCompanyName(cursor.getString(Projections.COMPANY_NAME)) + .setNickName(cursor.getString(Projections.NICKNAME)) + .setMimeType(cursor.getString(Projections.MIME_TYPE)) + .build(); + } + + public Object[] toCursorRow() { + Object[] row = new Object[Projections.DATA_PROJECTION.length]; + row[Projections.ID] = phoneId(); + row[Projections.PHONE_TYPE] = phoneType(); + row[Projections.PHONE_LABEL] = phoneLabel(); + row[Projections.PHONE_NUMBER] = phoneNumber(); + row[Projections.DISPLAY_NAME] = displayName(); + row[Projections.PHOTO_ID] = photoId(); + row[Projections.PHOTO_URI] = photoUri(); + row[Projections.LOOKUP_KEY] = lookupKey(); + row[Projections.CARRIER_PRESENCE] = carrierPresence(); + row[Projections.CONTACT_ID] = contactId(); + row[Projections.COMPANY_NAME] = companyName(); + row[Projections.NICKNAME] = nickName(); + row[Projections.MIME_TYPE] = mimeType(); + return row; + } + + public abstract Builder toBuilder(); +} -- cgit v1.2.3