AllContactsFragment.java revision e35b0efae9406cd5fa5c80b487e4a4846d6e485d
18dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee/* 28dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * Copyright (C) 2013 The Android Open Source Project 38dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * 48dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * Licensed under the Apache License, Version 2.0 (the "License"); 58dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * you may not use this file except in compliance with the License. 68dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * You may obtain a copy of the License at 78dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * 88dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * http://www.apache.org/licenses/LICENSE-2.0 98dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * 108dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * Unless required by applicable law or agreed to in writing, software 118dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * distributed under the License is distributed on an "AS IS" BASIS, 128dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * See the License for the specific language governing permissions and 148dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * limitations under the License. 158dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee */ 168dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee 178dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Leepackage com.android.dialer.list; 188dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee 190284f76fe813c4ebdf1d0d3472060719757fe394Andrew Leeimport android.content.Loader; 206144d027255568a76adf8c36b96af8e283460622Yorke Leeimport android.database.Cursor; 216144d027255568a76adf8c36b96af8e283460622Yorke Leeimport android.net.Uri; 2274eb4ecc5df272f681b427760d46deafce8ed0b2Brian Attwellimport android.provider.ContactsContract.CommonDataKinds.Phone; 236144d027255568a76adf8c36b96af8e283460622Yorke Leeimport android.provider.ContactsContract.QuickContact; 248dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Leeimport android.view.LayoutInflater; 258dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Leeimport android.view.View; 268dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Leeimport android.view.ViewGroup; 27931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Leeimport android.widget.AdapterView; 288dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee 29931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Leeimport com.android.contacts.common.list.ContactEntryListAdapter; 30931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Leeimport com.android.contacts.common.list.ContactEntryListFragment; 31931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Leeimport com.android.contacts.common.list.ContactListFilter; 32931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Leeimport com.android.contacts.common.list.DefaultContactListAdapter; 33c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Leeimport com.android.contacts.common.util.PermissionsUtil; 34781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Leeimport com.android.contacts.common.util.ViewUtil; 358dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Leeimport com.android.dialer.R; 360a4327e6bfeedc23ddefb4df9f6e8041ebc87b59Andrew Leeimport com.android.dialer.util.DialerUtils; 378dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee 388dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee/** 398dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * Fragments to show all contacts with phone numbers. 408dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee */ 41931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Leepublic class AllContactsFragment extends ContactEntryListFragment<ContactEntryListAdapter> { 428dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee 430284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee private View mEmptyListView; 440284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee 45931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee public AllContactsFragment() { 466144d027255568a76adf8c36b96af8e283460622Yorke Lee setQuickContactEnabled(false); 47331f457e9ac7b41fc8c43000ed989a3c09d68f62Andrew Lee setAdjustSelectionBoundsEnabled(true); 48931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee setPhotoLoaderEnabled(true); 49931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee setSectionHeaderDisplayEnabled(true); 508dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee setDarkTheme(false); 5153845dc94a78d3efe4f8ea76a5e9a60dbc79aa16Yorke Lee setVisibleScrollbarEnabled(true); 52931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee } 53931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee 54931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee @Override 55781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Lee public void onViewCreated(View view, android.os.Bundle savedInstanceState) { 56781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Lee super.onViewCreated(view, savedInstanceState); 570a4327e6bfeedc23ddefb4df9f6e8041ebc87b59Andrew Lee 587181205921b0f0914c1802a6c87411c0cf703d4fAndrew Lee mEmptyListView = view.findViewById(R.id.empty_list_view); 590284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee DialerUtils.configureEmptyListView(mEmptyListView, R.drawable.empty_contacts, 6039f773e8a64ec1b770b2679871b7c44cac7243d2Andrew Lee R.string.all_contacts_empty, getResources()); 610284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee getListView().setEmptyView(mEmptyListView); 620284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee mEmptyListView.setVisibility(View.GONE); 630a4327e6bfeedc23ddefb4df9f6e8041ebc87b59Andrew Lee 64781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Lee ViewUtil.addBottomPaddingToListViewForFab(getListView(), getResources()); 65781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Lee } 66781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Lee 67781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Lee @Override 68c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee protected void startLoading() { 69c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee if (PermissionsUtil.hasContactsPermissions(getActivity())) { 70c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee super.startLoading(); 71c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee } 72c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee } 73c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee 74c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee @Override 750284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee public void onLoadFinished(Loader<Cursor> loader, Cursor data) { 760284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee super.onLoadFinished(loader, data); 770284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee 78e35b0efae9406cd5fa5c80b487e4a4846d6e485dYorke Lee if (data == null || data.getCount() == 0) { 790284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee mEmptyListView.setVisibility(View.VISIBLE); 800284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee } 810284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee } 820284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee 830284f76fe813c4ebdf1d0d3472060719757fe394Andrew Lee @Override 84931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee protected ContactEntryListAdapter createListAdapter() { 85c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee if (!PermissionsUtil.hasContactsPermissions(getActivity())) { 86c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee return new EmptyContactsListAdapter(getActivity()); 87c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee } 88c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee 896144d027255568a76adf8c36b96af8e283460622Yorke Lee final DefaultContactListAdapter adapter = new DefaultContactListAdapter(getActivity()) { 906144d027255568a76adf8c36b96af8e283460622Yorke Lee @Override 916144d027255568a76adf8c36b96af8e283460622Yorke Lee protected void bindView(View itemView, int partition, Cursor cursor, int position) { 926144d027255568a76adf8c36b96af8e283460622Yorke Lee super.bindView(itemView, partition, cursor, position); 936144d027255568a76adf8c36b96af8e283460622Yorke Lee itemView.setTag(this.getContactUri(partition, cursor)); 946144d027255568a76adf8c36b96af8e283460622Yorke Lee } 956144d027255568a76adf8c36b96af8e283460622Yorke Lee }; 96931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee adapter.setDisplayPhotos(true); 97931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee adapter.setFilter(ContactListFilter.createFilterWithType( 983c5b0289eaf92e0b7345321993de12e89d01b8dbYorke Lee ContactListFilter.FILTER_TYPE_DEFAULT)); 99931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee adapter.setSectionHeaderDisplayEnabled(isSectionHeaderDisplayEnabled()); 100931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee return adapter; 1018dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee } 1028dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee 1038dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee @Override 1048dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee protected View inflateView(LayoutInflater inflater, ViewGroup container) { 1058dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee return inflater.inflate(R.layout.show_all_contacts_fragment, null); 1068dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee } 107931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee 108931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee @Override 109931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 1106144d027255568a76adf8c36b96af8e283460622Yorke Lee final Uri uri = (Uri) view.getTag(); 1116144d027255568a76adf8c36b96af8e283460622Yorke Lee if (uri != null) { 11274eb4ecc5df272f681b427760d46deafce8ed0b2Brian Attwell QuickContact.showQuickContact(getContext(), view, uri, null, 11374eb4ecc5df272f681b427760d46deafce8ed0b2Brian Attwell Phone.CONTENT_ITEM_TYPE); 1146144d027255568a76adf8c36b96af8e283460622Yorke Lee } 115931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee } 116931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee 117931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee @Override 118931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee protected void onItemClick(int position, long id) { 119931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee // Do nothing. Implemented to satisfy ContactEntryListFragment. 120931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee } 1218dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee} 122