1 /* 2 * Copyright (C) 2013 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.list; 18 19 import android.database.Cursor; 20 import android.net.Uri; 21 import android.provider.ContactsContract.QuickContact; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewGroup; 25 import android.widget.AdapterView; 26 27 import com.android.contacts.common.list.ContactEntryListAdapter; 28 import com.android.contacts.common.list.ContactEntryListFragment; 29 import com.android.contacts.common.list.ContactListFilter; 30 import com.android.contacts.common.list.DefaultContactListAdapter; 31 import com.android.contacts.common.util.ViewUtil; 32 import com.android.dialer.R; 33 import com.android.dialer.util.DialerUtils; 34 35 /** 36 * Fragments to show all contacts with phone numbers. 37 */ 38 public class AllContactsFragment extends ContactEntryListFragment<ContactEntryListAdapter> { 39 AllContactsFragment()40 public AllContactsFragment() { 41 setQuickContactEnabled(false); 42 setAdjustSelectionBoundsEnabled(true); 43 setPhotoLoaderEnabled(true); 44 setSectionHeaderDisplayEnabled(true); 45 setDarkTheme(false); 46 setVisibleScrollbarEnabled(true); 47 } 48 49 @Override onViewCreated(View view, android.os.Bundle savedInstanceState)50 public void onViewCreated(View view, android.os.Bundle savedInstanceState) { 51 super.onViewCreated(view, savedInstanceState); 52 53 View emptyListView = view.findViewById(R.id.empty_list_view); 54 DialerUtils.configureEmptyListView(emptyListView, R.drawable.empty_contacts, 55 R.string.all_contacts_empty, getResources()); 56 getListView().setEmptyView(emptyListView); 57 58 ViewUtil.addBottomPaddingToListViewForFab(getListView(), getResources()); 59 } 60 61 @Override createListAdapter()62 protected ContactEntryListAdapter createListAdapter() { 63 final DefaultContactListAdapter adapter = new DefaultContactListAdapter(getActivity()) { 64 @Override 65 protected void bindView(View itemView, int partition, Cursor cursor, int position) { 66 super.bindView(itemView, partition, cursor, position); 67 itemView.setTag(this.getContactUri(partition, cursor)); 68 } 69 }; 70 adapter.setDisplayPhotos(true); 71 adapter.setFilter(ContactListFilter.createFilterWithType( 72 ContactListFilter.FILTER_TYPE_DEFAULT)); 73 adapter.setSectionHeaderDisplayEnabled(isSectionHeaderDisplayEnabled()); 74 return adapter; 75 } 76 77 @Override inflateView(LayoutInflater inflater, ViewGroup container)78 protected View inflateView(LayoutInflater inflater, ViewGroup container) { 79 return inflater.inflate(R.layout.show_all_contacts_fragment, null); 80 } 81 82 @Override onItemClick(AdapterView<?> parent, View view, int position, long id)83 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 84 final Uri uri = (Uri) view.getTag(); 85 if (uri != null) { 86 QuickContact.showQuickContact(getActivity(), view, uri, QuickContact.MODE_LARGE, null); 87 } 88 } 89 90 @Override onItemClick(int position, long id)91 protected void onItemClick(int position, long id) { 92 // Do nothing. Implemented to satisfy ContactEntryListFragment. 93 } 94 } 95