AllContactsFragment.java revision c16ea5ad67bf454158b364dec2f26c95a879c350
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
196144d027255568a76adf8c36b96af8e283460622Yorke Leeimport android.database.Cursor;
206144d027255568a76adf8c36b96af8e283460622Yorke Leeimport android.net.Uri;
2174eb4ecc5df272f681b427760d46deafce8ed0b2Brian Attwellimport android.provider.ContactsContract.CommonDataKinds.Phone;
226144d027255568a76adf8c36b96af8e283460622Yorke Leeimport android.provider.ContactsContract.QuickContact;
238dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Leeimport android.view.LayoutInflater;
248dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Leeimport android.view.View;
258dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Leeimport android.view.ViewGroup;
26931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Leeimport android.widget.AdapterView;
278dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee
28931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Leeimport com.android.contacts.common.list.ContactEntryListAdapter;
29931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Leeimport com.android.contacts.common.list.ContactEntryListFragment;
30931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Leeimport com.android.contacts.common.list.ContactListFilter;
31931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Leeimport com.android.contacts.common.list.DefaultContactListAdapter;
32c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Leeimport com.android.contacts.common.util.PermissionsUtil;
33781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Leeimport com.android.contacts.common.util.ViewUtil;
348dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Leeimport com.android.dialer.R;
350a4327e6bfeedc23ddefb4df9f6e8041ebc87b59Andrew Leeimport com.android.dialer.util.DialerUtils;
368dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee
378dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee/**
388dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee * Fragments to show all contacts with phone numbers.
398dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee */
40931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Leepublic class AllContactsFragment extends ContactEntryListFragment<ContactEntryListAdapter> {
418dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee
42931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee    public AllContactsFragment() {
436144d027255568a76adf8c36b96af8e283460622Yorke Lee        setQuickContactEnabled(false);
44331f457e9ac7b41fc8c43000ed989a3c09d68f62Andrew Lee        setAdjustSelectionBoundsEnabled(true);
45931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee        setPhotoLoaderEnabled(true);
46931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee        setSectionHeaderDisplayEnabled(true);
478dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee        setDarkTheme(false);
4853845dc94a78d3efe4f8ea76a5e9a60dbc79aa16Yorke Lee        setVisibleScrollbarEnabled(true);
49931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee    }
50931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee
51931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee    @Override
52781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Lee    public void onViewCreated(View view, android.os.Bundle savedInstanceState) {
53781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Lee        super.onViewCreated(view, savedInstanceState);
540a4327e6bfeedc23ddefb4df9f6e8041ebc87b59Andrew Lee
550a4327e6bfeedc23ddefb4df9f6e8041ebc87b59Andrew Lee        View emptyListView = view.findViewById(R.id.empty_list_view);
560a4327e6bfeedc23ddefb4df9f6e8041ebc87b59Andrew Lee        DialerUtils.configureEmptyListView(emptyListView, R.drawable.empty_contacts,
5739f773e8a64ec1b770b2679871b7c44cac7243d2Andrew Lee                R.string.all_contacts_empty, getResources());
580a4327e6bfeedc23ddefb4df9f6e8041ebc87b59Andrew Lee        getListView().setEmptyView(emptyListView);
590a4327e6bfeedc23ddefb4df9f6e8041ebc87b59Andrew Lee
60781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Lee        ViewUtil.addBottomPaddingToListViewForFab(getListView(), getResources());
61781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Lee    }
62781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Lee
63781ee24f91f6eb6a1687d803971196f2bf71c02bYorke Lee    @Override
64c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee    protected void startLoading() {
65c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee        if (PermissionsUtil.hasContactsPermissions(getActivity())) {
66c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee            super.startLoading();
67c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee        }
68c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee    }
69c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee
70c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee    @Override
71931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee    protected ContactEntryListAdapter createListAdapter() {
72c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee        if (!PermissionsUtil.hasContactsPermissions(getActivity())) {
73c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee            return new EmptyContactsListAdapter(getActivity());
74c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee        }
75c16ea5ad67bf454158b364dec2f26c95a879c350Yorke Lee
766144d027255568a76adf8c36b96af8e283460622Yorke Lee        final DefaultContactListAdapter adapter = new DefaultContactListAdapter(getActivity()) {
776144d027255568a76adf8c36b96af8e283460622Yorke Lee            @Override
786144d027255568a76adf8c36b96af8e283460622Yorke Lee            protected void bindView(View itemView, int partition, Cursor cursor, int position) {
796144d027255568a76adf8c36b96af8e283460622Yorke Lee                super.bindView(itemView, partition, cursor, position);
806144d027255568a76adf8c36b96af8e283460622Yorke Lee                itemView.setTag(this.getContactUri(partition, cursor));
816144d027255568a76adf8c36b96af8e283460622Yorke Lee            }
826144d027255568a76adf8c36b96af8e283460622Yorke Lee        };
83931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee        adapter.setDisplayPhotos(true);
84931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee        adapter.setFilter(ContactListFilter.createFilterWithType(
853c5b0289eaf92e0b7345321993de12e89d01b8dbYorke Lee                ContactListFilter.FILTER_TYPE_DEFAULT));
86931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee        adapter.setSectionHeaderDisplayEnabled(isSectionHeaderDisplayEnabled());
87931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee        return adapter;
888dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee    }
898dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee
908dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee    @Override
918dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee    protected View inflateView(LayoutInflater inflater, ViewGroup container) {
928dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee        return inflater.inflate(R.layout.show_all_contacts_fragment, null);
938dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee    }
94931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee
95931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee    @Override
96931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
976144d027255568a76adf8c36b96af8e283460622Yorke Lee        final Uri uri = (Uri) view.getTag();
986144d027255568a76adf8c36b96af8e283460622Yorke Lee        if (uri != null) {
9974eb4ecc5df272f681b427760d46deafce8ed0b2Brian Attwell            QuickContact.showQuickContact(getContext(), view, uri, null,
10074eb4ecc5df272f681b427760d46deafce8ed0b2Brian Attwell                    Phone.CONTENT_ITEM_TYPE);
1016144d027255568a76adf8c36b96af8e283460622Yorke Lee        }
102931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee    }
103931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee
104931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee    @Override
105931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee    protected void onItemClick(int position, long id) {
106931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee        // Do nothing. Implemented to satisfy ContactEntryListFragment.
107931075eab957d7ecd7a9e880c0650012e29f05c2Andrew Lee    }
1088dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee}
109