1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.dialer.searchfragment.nearbyplaces; 18 19 import android.content.Context; 20 import android.database.Cursor; 21 import android.net.Uri; 22 import android.provider.ContactsContract; 23 import android.support.v7.widget.RecyclerView; 24 import android.view.View; 25 import android.widget.QuickContactBadge; 26 import android.widget.TextView; 27 import com.android.contacts.common.ContactPhotoManager; 28 import com.android.contacts.common.lettertiles.LetterTileDrawable; 29 import com.android.dialer.callintent.CallInitiationType; 30 import com.android.dialer.callintent.CallIntentBuilder; 31 import com.android.dialer.searchfragment.common.Projections; 32 import com.android.dialer.searchfragment.common.QueryBoldingUtil; 33 import com.android.dialer.searchfragment.common.R; 34 import com.android.dialer.telecom.TelecomUtil; 35 36 /** ViewHolder for a nearby place row. */ 37 public final class NearbyPlaceViewHolder extends RecyclerView.ViewHolder 38 implements View.OnClickListener { 39 40 private final Context context; 41 private final TextView placeName; 42 private final TextView placeAddress; 43 private final QuickContactBadge photo; 44 45 private String number; 46 NearbyPlaceViewHolder(View view)47 public NearbyPlaceViewHolder(View view) { 48 super(view); 49 view.setOnClickListener(this); 50 photo = view.findViewById(R.id.photo); 51 placeName = view.findViewById(R.id.primary); 52 placeAddress = view.findViewById(R.id.secondary); 53 context = view.getContext(); 54 } 55 56 /** 57 * Binds the ViewHolder with a cursor from {@link NearbyPlacesCursorLoader} with the data found at 58 * the cursors set position. 59 */ bind(Cursor cursor, String query)60 public void bind(Cursor cursor, String query) { 61 number = cursor.getString(Projections.PHONE_NUMBER); 62 String name = cursor.getString(Projections.PHONE_DISPLAY_NAME); 63 String address = cursor.getString(Projections.PHONE_LABEL); 64 65 placeName.setText(QueryBoldingUtil.getNameWithQueryBolded(query, name)); 66 placeAddress.setText(QueryBoldingUtil.getNameWithQueryBolded(query, address)); 67 68 String photoUri = cursor.getString(Projections.PHONE_PHOTO_URI); 69 ContactPhotoManager.getInstance(context) 70 .loadDialerThumbnailOrPhoto( 71 photo, 72 getContactUri(cursor), 73 cursor.getLong(Projections.PHONE_PHOTO_ID), 74 photoUri == null ? null : Uri.parse(photoUri), 75 name, 76 LetterTileDrawable.TYPE_DEFAULT); 77 } 78 getContactUri(Cursor cursor)79 private static Uri getContactUri(Cursor cursor) { 80 long contactId = cursor.getLong(Projections.PHONE_ID); 81 String lookupKey = cursor.getString(Projections.PHONE_LOOKUP_KEY); 82 return ContactsContract.Contacts.getLookupUri(contactId, lookupKey); 83 } 84 85 @Override onClick(View v)86 public void onClick(View v) { 87 TelecomUtil.placeCall( 88 context, new CallIntentBuilder(number, CallInitiationType.Type.REGULAR_SEARCH).build()); 89 } 90 } 91